#ifndef __DS1302_H__
#define __DS1302_H__
#include "stm32f7xx_hal.h"
//IO方向设置
//#define DS1302_IO_IN()  {GPIOC->CRL&=0X0FFFFFFF;GPIOC->CRL|=((unsigned int)8<<28);}

//#define DS1302_IO_OUT() {GPIOC->CRL&=0X0FFFFFFF;GPIOC->CRL|=((unsigned int)3<<28);}
//IO操作函数									   
//#define	DS1302_DATA_OUT PCout(7) //数据端口	Pc7 
//#define	DS1302_DATA_IN  PCin(7)  //数据端口	Pc7 
#define DS1302_SCK   GPIO_PIN_9 
#define	DS1302_RST   GPIO_PIN_1
#define	DS1302_DATA  GPIO_PIN_0
//#define	DS1302_SCK  PCout(8)
//#define	DS1302_RST  PCout(6)
#define	DS1302_RST_1  HAL_GPIO_WritePin(GPIOE, DS1302_RST, GPIO_PIN_SET)
#define	DS1302_RST_0  HAL_GPIO_WritePin(GPIOE, DS1302_RST, GPIO_PIN_RESET)

#define	DS1302_SCK_1  HAL_GPIO_WritePin(GPIOB, DS1302_SCK, GPIO_PIN_SET)
#define	DS1302_SCK_0  HAL_GPIO_WritePin(GPIOB, DS1302_SCK, GPIO_PIN_RESET)

#define	DS1302_DATA_OUT_1  HAL_GPIO_WritePin(GPIOE, DS1302_DATA, GPIO_PIN_SET)
#define	DS1302_DATA_OUT_0  HAL_GPIO_WritePin(GPIOE, DS1302_DATA, GPIO_PIN_RESET)

#define DS1302_DATA_IN()     HAL_GPIO_ReadPin(GPIOE,  DS1302_DATA)
//DS1302地址定义
#define ds1302_sec_add			  0x80		//秒数据地址
#define ds1302_min_add			  0x82		//分数据地址
#define ds1302_hr_add			    0x84		//时数据地址
#define ds1302_date_add			  0x86		//日数据地址
#define ds1302_month_add		  0x88		//月数据地址
#define ds1302_day_add			  0x8a		//星期数据地址
#define ds1302_year_add			  0x8c		//年数据地址
#define ds1302_control_add		0x8e		//控制数据地址
#define ds1302_charger_add		0x90 					 
#define ds1302_clkburst_add		0xbe

extern uint8_t time_buf[7];
extern char tableDS1302[7];

void DS1302_IO_IN(void);
void DS1302_IO_OUT(void);
void ds1302_Init(void);
void ds1302_Write_Byte(uint8_t addr, uint8_t data);
uint8_t ds1302_Read_Byte(uint8_t addr);
void ds1302_Write_Time(uint8_t *Time_buf);
void ds1302_Read_Time(void);
void ds1302_Get_Time(uint8_t *time);
void delay_us(uint32_t us);

//新增函数  李伟修改
void Set_IO_INPUT(void);
void Set_IO_OUT(void);
void ds1302_writeV2(unsigned char time_tx);
void ds1302_initV2(void);
void DS1302_get_all(void);


#endif


