ds1302drv.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef __DS1302DRV_H__
  2. #define __DS1302DRV_H__
  3. #include "stm32f7xx_hal.h"
  4. #include "stm32f7xx_hal.h"
  5. #define DEF_true 1
  6. #define DEF_false 0
  7. #define kRamSize 31
  8. #define DS1302_SCLK_GPIO_Port GPIOB
  9. #define DS1302_SCLK_Pin GPIO_PIN_9
  10. //DS1302_CE_GPIO_Port, DS1302_CE_Pin
  11. #define DS1302_CE_GPIO_Port GPIOE
  12. #define DS1302_CE_Pin GPIO_PIN_1
  13. //DS1302_IO_GPIO_Port, DS1302_IO_Pin
  14. #define DS1302_IO_GPIO_Port GPIOE
  15. #define DS1302_IO_Pin GPIO_PIN_0
  16. typedef enum
  17. {
  18. kSecondReg = 0,
  19. kMinuteReg = 1,
  20. kHourReg = 2,
  21. kDateReg = 3,
  22. kMonthReg = 4,
  23. kDayReg = 5,
  24. kYearReg = 6,
  25. kWriteProtectReg = 7,
  26. kChargeReg = 8,
  27. // The RAM register space follows the clock register space.
  28. kRamAddress0 = 32
  29. } DS1302_Register;
  30. typedef enum
  31. {
  32. kClockBurstRead = 0xBF,
  33. kClockBurstWrite = 0xBE,
  34. kRamBurstRead = 0xFF,
  35. kRamBurstWrite = 0xFE
  36. } DS1302_Command;
  37. typedef enum
  38. {
  39. kSunday = 1,
  40. kMonday = 2,
  41. kTuesday = 3,
  42. kWednesday = 4,
  43. kThursday = 5,
  44. kFriday = 6,
  45. kSaturday = 7
  46. } DS1302_Day;
  47. extern uint8_t time_buf_reg[8];
  48. uint8_t bcdToDec(const uint8_t bcd) ;
  49. uint8_t decToBcd(const uint8_t dec) ;
  50. uint8_t hourFromRegisterValue(const uint8_t value);
  51. void DS1302_writeOut(const uint8_t value, uint8_t readAfter) ;
  52. uint8_t DS1302_readIn(void) ;
  53. uint8_t DS1302_readRegister(const uint8_t reg) ;
  54. void DS1302_writeRegister(const uint8_t reg, const uint8_t value) ;
  55. void DS1302_writeProtect(const uint8_t enable) ;
  56. void DS1302_halt(const uint8_t enable) ;
  57. void DS1302_writeRam(const uint8_t address, const uint8_t value) ;
  58. uint8_t DS1302_readRam(const uint8_t address) ;
  59. void DS1302_writeRamBulk(const uint8_t* const data, int len) ;
  60. void DS1302_readRamBulk(uint8_t* const data, int len) ;
  61. //Top layer function
  62. void DS1302_timeRead(void) ;
  63. void DS1302_timeWrite(void) ;
  64. #endif /* __DS1302DRV_H__ */