#include "mw_rtc.h" #include "bsp_timer.h" #include "PCF8563.h" // #include "string.h" rtc_drv_str rtc_drv; /************************************************************************************* * @brief rtc gpio 初始化 * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ static void rtc_gpio_init(void) { GPIO_InitTypeDef GPIO_InitStructure; /* GPIO */ RCC_APB2PeriphClockCmd(RCC_GPIO_RTC_SDA, ENABLE); RCC_APB2PeriphClockCmd(RCC_GPIO_RTC_SCL, ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = GPIO_PIN_RTC_SDA; GPIO_Init(GPIO_PORT_RTC_SDA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_PIN_RTC_SCL; GPIO_Init(GPIO_PORT_RTC_SCL, &GPIO_InitStructure); // 空闲 RTC_W_SCL(1); RTC_W_SDA(1); } /************************************************************************************* * @brief SDA是否为开漏输出 * @return uint8_t 【返回值注释】 * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ uint8_t rtc_is_SDA_as_openDrain_output(void) { return ((uint8_t)(GPIO_PORT_RTC_SDA->CRL & 0x000000F) == 0x07); } /************************************************************************************* * @brief SDA是否为浮空输入 * @return uint8_t 【返回值注释】 * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ uint8_t rtc_is_SDA_as_floating_input(void) { return ((uint8_t)(GPIO_PORT_RTC_SDA->CRL & 0x000000F) == 0x04); } /************************************************************************************* * @brief RTC SDA as output * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ void rtc_SDA_as_output(void) { __IO uint32_t tmp_data = GPIO_PORT_RTC_SDA->CRL; DISABLE_INT(); tmp_data &= 0xFFFFFFF0; tmp_data |= (7 << 0); GPIO_PORT_RTC_SDA->CRL = tmp_data; ENABLE_INT(); // GPIO_PORT_RTC_SDA->CRL &= 0xFFFFFFF0; // GPIO_PORT_RTC_SDA->CRL |= 7 << 0; } /************************************************************************************* * @brief RTC SDA as input * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ void rtc_SDA_as_input(void) { __IO uint32_t tmp_data = GPIO_PORT_RTC_SDA->CRL; DISABLE_INT(); tmp_data &= 0xFFFFFFF0; tmp_data |= (4 << 0); GPIO_PORT_RTC_SDA->CRL = tmp_data; ENABLE_INT(); // GPIO_PORT_RTC_SDA->CRL &= 0xFFFFFFF0; // GPIO_PORT_RTC_SDA->CRL |= 4 << 0; } /************************************************************************************* * @brief mw rtc initial * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ void mw_rtc_init(void) { /* 若没有RTC 则直接返回 */ #if RTCTYPE_DEFINE == RTCTYPE_NULL return; #endif /* rtc gpio 初始化 */ rtc_gpio_init(); /* 装载rtc驱动 */ #if RTCTYPE_DEFINE == RTCTYPE_PCF8563 rtc_drv = pcf8563_drv; #endif /* 初始化rtc对应外设内的参数等内容 */ rtc_drv.init(); // /* 初始化 time_infor信息 */ // memset((uint8_t *)&rtc_drv.time_infor, 0x00, sizeof(rtc_drv.time_infor)); } /************************************************************************************* * @brief 修改rtc时间 * @param[in/out] str_rtc_setVal【参数注释】 * @return uint8_t 【返回值注释】 * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ uint8_t mw_set_rtc_time(rtc_time_infor str_rtc_setVal) { return (rtc_drv.set_rtc_time(str_rtc_setVal)); } /************************************************************************************* * @brief 获取rtc时间 * @param[in/out] str_rtc_getVal【参数注释】 * @return uint8_t 【返回值注释】 * * @warning 【不可重入,阻塞等警告】 * @note 【重大修改】 *************************************************************************************/ uint8_t mw_get_rtc_time(rtc_time_infor *str_rtc_getVal) { return (rtc_drv.get_rtc_time(str_rtc_getVal)); }