implement user RAM read/write

This commit is contained in:
King Kévin 2017-02-08 14:26:41 +01:00
parent 5e14d886ac
commit 0853d630e4
2 changed files with 41 additions and 4 deletions

View File

@ -15,8 +15,7 @@
/** library to communicate with the Maxim DS1307 I2C RTC IC (code)
* @file rtc_ds1307.c
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016
* @note user RAM is not handled
* @date 2016-2017
* @note peripherals used: I2C @ref rtc_ds1307_i2c, GPIO & timer @ref rtc_ds1307_square_wave_timer
*/
@ -273,6 +272,18 @@ uint8_t* rtc_ds1307_read_time(void)
return time;
}
bool rtc_ds1307_read_ram(uint8_t* data, uint8_t start, uint8_t length)
{
// sanity checks
if (data==NULL || length==0) { // nothing to read
return false;
}
if (start>55 || start+length>56) { // out of bounds RAM
return false;
}
return rtc_ds1307_read_memory(0x08+start, data, length); // read RAM (starting at 0x08)
}
/** write memory into RTC IC
* @param[in] addr start address for memory to be written
* @param[in] data buffer to for memory to be written
@ -471,6 +482,18 @@ bool rtc_ds1307_write_time(uint8_t seconds, uint8_t minutes, uint8_t hours, uint
return rtc_ds1307_write_memory(0, data, LENGTH(data)); // write time values on RTC
}
bool rtc_ds1307_write_ram(uint8_t* data, uint8_t start, uint8_t length)
{
// sanity checks
if (data==NULL || length==0) { // nothing to read
return false;
}
if (start>55 || start+length>56) { // out of bounds RAM
return false;
}
return rtc_ds1307_write_memory(0x08+start, data, length); // write RAM (starting at 0x08)
}
#if defined(RTC_DS1307_SQUARE_WAVE_TICKS)
/** timer interrupt service routine called when number of ticks have been received */
void RTC_DS1307_SQUARE_WAVE_TIMER_ISR(void)

View File

@ -15,8 +15,7 @@
/** library to communicate with the Maxim DS1307 I2C RTC IC (API)
* @file rtc_ds1307.h
* @author King Kévin <kingkevin@cuvoodoo.info>
* @date 2016
* @note user RAM is not handled
* @date 2016-2017
* @note peripherals used: I2C @ref rtc_ds1307_i2c, GPIO & timer @ref rtc_ds1307_square_wave_timer
*/
#pragma once
@ -70,6 +69,13 @@ uint8_t rtc_ds1307_read_year(void);
* @return array of {seconds, minutes, hours, day, date, month, year} as defined above
*/
uint8_t* rtc_ds1307_read_time(void);
/** read user RAM from RTC IC
* @param[out] data array to store the RAM read
* @param[in] start start of the user RAM to read (0-55)
* @pramr[in] length number of user RAM bytes to read (0-55)
* @return if read succeeded
*/
bool rtc_ds1307_read_ram(uint8_t* data, uint8_t start, uint8_t length);
/** disable RTC IC oscillator
* @return if disabling oscillator succeeded
*/
@ -129,3 +135,11 @@ bool rtc_ds1307_write_year(uint8_t year);
* @return if write succeeded
*/
bool rtc_ds1307_write_time(uint8_t seconds, uint8_t minutes, uint8_t hours, uint8_t day, uint8_t date, uint8_t month, uint8_t year);
/** write user RAM from RTC IC
* @param[in] data array of byte to write in RAM
* @param[in] start start of the user RAM to write (0-55)
* @pramr[in] length number of user RAM bytes to write (0-55)
* @return if write succeeded
*/
bool rtc_ds1307_write_ram(uint8_t* data, uint8_t start, uint8_t length);