ds3231.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef __FW_DS3231_H__
  15. #define __FW_DS3231_H__
  16. #include "fw_hal.h"
  17. #define DS3231_I2C_ADDR 0xD0 /**< iic device address */
  18. #define DS3231_REG_SECOND 0x00 /**< second register */
  19. #define DS3231_REG_MINUTE 0x01 /**< minute register */
  20. #define DS3231_REG_HOUR 0x02 /**< hour register */
  21. #define DS3231_REG_WEEK 0x03 /**< week register */
  22. #define DS3231_REG_DATE 0x04 /**< date register */
  23. #define DS3231_REG_MONTH 0x05 /**< month register */
  24. #define DS3231_REG_YEAR 0x06 /**< year register */
  25. #define DS3231_REG_ALARM1_SECOND 0x07 /**< alarm1 second register */
  26. #define DS3231_REG_ALARM1_MINUTE 0x08 /**< alarm1 minute register */
  27. #define DS3231_REG_ALARM1_HOUR 0x09 /**< alarm1 hour register */
  28. #define DS3231_REG_ALARM1_WEEK 0x0A /**< alarm1 week register */
  29. #define DS3231_REG_ALARM2_MINUTE 0x0B /**< alarm2 minute register */
  30. #define DS3231_REG_ALARM2_HOUR 0x0C /**< alarm2 hour register */
  31. #define DS3231_REG_ALARM2_WEEK 0x0D /**< alarm2 week register */
  32. #define DS3231_REG_CONTROL 0x0E /**< control register */
  33. #define DS3231_REG_STATUS 0x0F /**< status register */
  34. #define DS3231_REG_XTAL 0x10 /**< xtal register */
  35. #define DS3231_REG_TEMPERATUREH 0x11 /**< temperature high register */
  36. #define DS3231_REG_TEMPERATUREL 0x12 /**< temperature low register */
  37. typedef enum
  38. {
  39. DS3231_ALARM_1 = 0x00, /**< alarm 1 */
  40. DS3231_ALARM_2 = 0x01, /**< alarm 2 */
  41. } DS3231_Alarm_t;
  42. typedef enum
  43. {
  44. DS3231_AM = 0x00, /**< am */
  45. DS3231_PM = 0x01, /**< pm */
  46. } DS3231_AmPm_t;
  47. typedef enum
  48. {
  49. DS3231_PIN_SQUARE_WAVE = 0x00, /**< square wave pin */
  50. DS3231_PIN_INTERRUPT = 0x01, /**< interrupt pin */
  51. } DS3231_PinType_t;
  52. typedef enum
  53. {
  54. DS3231_FORMAT_12H = 0x01, /**< 12h format */
  55. DS3231_FORMAT_24H = 0x00, /**< 24h format */
  56. } DS3231_HourFormat_t;
  57. typedef enum
  58. {
  59. DS3231_STATUS_ALARM_2 = (1 << 1), /**< alarm 2 status */
  60. DS3231_STATUS_ALARM_1 = (1 << 0), /**< alarm 1 status */
  61. } DS3231_AlarmStatus_t;
  62. typedef enum
  63. {
  64. DS3231_ALARM1_MODE_ONCE_A_SECOND = 0x0F, /**< interrupt once a second */
  65. DS3231_ALARM1_MODE_SECOND_MATCH = 0x0E, /**< interrupt second match */
  66. DS3231_ALARM1_MODE_MINUTE_SECOND_MATCH = 0x0C, /**< interrupt minute second match */
  67. DS3231_ALARM1_MODE_HOUR_MINUTE_SECOND_MATCH = 0x08, /**< interrupt hour minute second match */
  68. DS3231_ALARM1_MODE_DATE_HOUR_MINUTE_SECOND_MATCH = 0x00, /**< interrupt date hour minute second match */
  69. DS3231_ALARM1_MODE_WEEK_HOUR_MINUTE_SECOND_MATCH = 0x10, /**< interrupt week hour minute second match */
  70. } DS3231_Alarm1Mode_t;
  71. typedef enum
  72. {
  73. DS3231_ALARM2_MODE_ONCE_A_MINUTE = 0x07, /**< interrupt once a minute */
  74. DS3231_ALARM2_MODE_MINUTE_MATCH = 0x06, /**< interrupt minute match */
  75. DS3231_ALARM2_MODE_HOUR_MINUTE_MATCH = 0x04, /**< interrupt hour minute match */
  76. DS3231_ALARM2_MODE_DATE_HOUR_MINUTE_MATCH = 0x00, /**< interrupt data hour minute match */
  77. DS3231_ALARM2_MODE_WEEK_HOUR_MINUTE_MATCH = 0x10, /**< interrupt week hour minute match */
  78. } DS3231_Alarm2Mode_t;
  79. uint8_t DS3231_GetStatus(void);
  80. /**
  81. * @brief
  82. *
  83. * @param t format
  84. * uint8_t year;
  85. uint8_t month;
  86. uint8_t week;
  87. uint8_t date;
  88. uint8_t hour;
  89. uint8_t minute;
  90. uint8_t second;
  91. DS3231_HourFormat_t format;
  92. DS3231_AmPm_t am_pm;
  93. * @return uint8_t
  94. */
  95. uint8_t DS3231_GetTime(uint8_t *t);
  96. uint8_t DS3231_SetTime(uint8_t *t);
  97. uint8_t DS3231_GetPin(DS3231_PinType_t *pin);
  98. uint8_t DS3231_SetPin(DS3231_PinType_t *pin);
  99. uint8_t ds3231_GetSquareOutputState(HAL_State_t *state);
  100. uint8_t DS3231_SetSquareOutputState(HAL_State_t state);
  101. uint8_t DS3231_GetAlarmInterrupt(DS3231_Alarm_t alarm, HAL_State_t *state);
  102. uint8_t DS3231_SetAlarmInterrupt(DS3231_Alarm_t alarm, HAL_State_t state);
  103. uint8_t DS3231_GetAlarm1(uint8_t *t, DS3231_Alarm1Mode_t *mode);
  104. uint8_t DS3231_SetAlarm1(uint8_t *t, DS3231_Alarm1Mode_t mode);
  105. uint8_t DS3231_GetAlarm2(uint8_t *t, DS3231_Alarm2Mode_t *mode);
  106. uint8_t DS3231_SetAlarm2(uint8_t *t, DS3231_Alarm2Mode_t mode);
  107. uint8_t DS3231_ClearAlarm(DS3231_Alarm_t alarm);
  108. #endif