2026-05-10 21:35:40 +08:00

81 lines
1.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __MW_RTC_DEFINE__
#define __MW_RTC_DEFINE__
#include "public_diy.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#define RTCTYPE_NULL (0u)
#define RTCTYPE_PCF8563 (1u)
#define RTCTYPE_OTHER (2u)
#define RTCTYPE_DEFINE (RTCTYPE_NULL)
/* RTC GPIO definition */
/* RTC SCL */
#define RCC_GPIO_RTC_SCL RCC_APB2Periph_GPIOA
#define GPIO_PORT_RTC_SCL GPIOA
#define GPIO_PIN_RTC_SCL GPIO_Pin_1
/* RTC SDA */
#define RCC_GPIO_RTC_SDA RCC_APB2Periph_GPIOA
#define GPIO_PORT_RTC_SDA GPIOA
#define GPIO_PIN_RTC_SDA GPIO_Pin_0
/* RTC pin control */
/* SCL write pin state */
#define RTC_W_SCL(x) GPIO_WriteBit(GPIO_PORT_RTC_SCL, GPIO_PIN_RTC_SCL, (BitAction)(x))
/* SDA write pin state */
#define RTC_W_SDA(x) GPIO_WriteBit(GPIO_PORT_RTC_SDA, GPIO_PIN_RTC_SDA, (BitAction)(x))
/* get sda pin state */
#define GET_RTC_SDA_STATE() GPIO_ReadInputDataBit(GPIO_PORT_RTC_SDA, GPIO_PIN_RTC_SDA)
// typedef enum
// {
// e_rtcType_pcf8563 = 0,
// // 总个数
// e_rtcType_number
// }rtc_type_enum;
/* rtc时间信息 */
typedef struct
{
uint8_t year; // 年
uint8_t month; // 月
uint8_t day; // 日
uint8_t week; // 星期
uint8_t hour; // 时
uint8_t minute; // 分
uint8_t second; // 秒
}rtc_time_infor;
typedef struct
{
// rtc类型 pcf8563等
uint8_t rtc_type;
// // 时间信息 年月日星期时分秒
// rtc_time_infor time_infor;
// rtc外设初始化程序
uint8_t (*init)(void);
// 重启程序若返回值为0xFF则表示无重启功能无效。
uint8_t (*reboot)(void);
// 获取rtc时间信息
uint8_t (*get_rtc_time)(rtc_time_infor*);
// 设置rtc的时间信息
uint8_t (*set_rtc_time)(rtc_time_infor);
}rtc_drv_str;
// void rtc_gpio_init(void);
void rtc_SDA_as_output(void);
void rtc_SDA_as_input(void);
uint8_t rtc_is_SDA_as_openDrain_output(void);
uint8_t rtc_is_SDA_as_floating_input(void);
#endif