Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RTC.h 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Copyright (C) Dean Camera, 2014.
  3. dean [at] fourwalledcubicle [dot] com
  4. www.lufa-lib.org
  5. */
  6. #ifndef _RTC_H_
  7. #define _RTC_H_
  8. /* Includes: */
  9. #include <avr/io.h>
  10. #include <LUFA/Drivers/Peripheral/TWI.h>
  11. #include "Config/AppConfig.h"
  12. /* Type Defines: */
  13. typedef struct
  14. {
  15. uint8_t Hour;
  16. uint8_t Minute;
  17. uint8_t Second;
  18. uint8_t Day;
  19. uint8_t Month;
  20. uint8_t Year;
  21. } TimeDate_t;
  22. typedef struct
  23. {
  24. union
  25. {
  26. struct
  27. {
  28. unsigned Sec : 4;
  29. unsigned TenSec : 3;
  30. unsigned CH : 1;
  31. } Fields;
  32. uint8_t IntVal;
  33. } Byte1;
  34. union
  35. {
  36. struct
  37. {
  38. unsigned Min : 4;
  39. unsigned TenMin : 3;
  40. unsigned Reserved : 1;
  41. } Fields;
  42. uint8_t IntVal;
  43. } Byte2;
  44. union
  45. {
  46. struct
  47. {
  48. unsigned Hour : 4;
  49. unsigned TenHour : 2;
  50. unsigned TwelveHourMode : 1;
  51. unsigned Reserved : 1;
  52. } Fields;
  53. uint8_t IntVal;
  54. } Byte3;
  55. union
  56. {
  57. struct
  58. {
  59. unsigned DayOfWeek : 3;
  60. unsigned Reserved : 5;
  61. } Fields;
  62. uint8_t IntVal;
  63. } Byte4;
  64. union
  65. {
  66. struct
  67. {
  68. unsigned Day : 4;
  69. unsigned TenDay : 2;
  70. unsigned Reserved : 2;
  71. } Fields;
  72. uint8_t IntVal;
  73. } Byte5;
  74. union
  75. {
  76. struct
  77. {
  78. unsigned Month : 4;
  79. unsigned TenMonth : 1;
  80. unsigned Reserved : 3;
  81. } Fields;
  82. uint8_t IntVal;
  83. } Byte6;
  84. union
  85. {
  86. struct
  87. {
  88. unsigned Year : 4;
  89. unsigned TenYear : 4;
  90. } Fields;
  91. uint8_t IntVal;
  92. } Byte7;
  93. } DS1307_DateTimeRegs_t;
  94. /* Macros: */
  95. /** TWI address of the DS1307 device on the bus. */
  96. #define DS1307_ADDRESS 0xD0
  97. /* Function Prototypes: */
  98. void RTC_Init(void);
  99. void RTC_Tick500ms(void);
  100. bool RTC_SetTimeDate(const TimeDate_t* NewTimeDate);
  101. bool RTC_GetTimeDate(TimeDate_t* const TimeDate);
  102. #endif