2024-10-16 23:51:49 -07:00
|
|
|
/*
|
|
|
|
* rtc.h
|
|
|
|
*
|
|
|
|
* Created on: Oct 16, 2024
|
|
|
|
* Author: true
|
|
|
|
*/
|
|
|
|
|
2024-11-06 19:15:40 -08:00
|
|
|
#ifndef USER_PERIPH_RTC_H_
|
|
|
|
#define USER_PERIPH_RTC_H_
|
2024-10-16 23:51:49 -07:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-22 23:06:18 -07:00
|
|
|
/* a small note about backup registers:
|
|
|
|
*
|
|
|
|
* the datasheet clearly states there are 42 16-bit registers.
|
|
|
|
* it does not cut out any exception for CH32V203 except CH32V203RB.
|
|
|
|
* however, the reference manual states that registers 11-42 are only
|
|
|
|
* for the _D8 chips, and not the _D6 V4B chips like this one.
|
|
|
|
* thus we only have _10_ backup registers, not 42.
|
|
|
|
*/
|
2024-10-16 23:51:49 -07:00
|
|
|
#define RTC_INIT_DR BKP_DR1
|
|
|
|
#define RTC_STATE_DR BKP_DR2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum RTCState {
|
|
|
|
RTC_STATE_UNINITIALIZED = 0,
|
|
|
|
RTC_STATE_CLOCK_NOT_SET,
|
|
|
|
RTC_STATE_OK = 0x7f
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct RTClock {
|
|
|
|
uint16_t year;
|
|
|
|
uint8_t mon;
|
|
|
|
uint8_t day;
|
|
|
|
uint8_t h;
|
|
|
|
uint8_t m;
|
|
|
|
uint8_t s;
|
|
|
|
} RTClock;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-22 23:06:18 -07:00
|
|
|
extern uint8_t rtc_state;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-10-16 23:51:49 -07:00
|
|
|
int8_t rtc_init();
|
|
|
|
|
|
|
|
int8_t rtc_set_clock(struct RTClock *c);
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-06 19:15:40 -08:00
|
|
|
#endif /* USER_PERIPH_RTC_H_ */
|