Update all demos, projects and bootloaders to indent all function parameters, one...
[pub/lufa.git] / Projects / TempDataLogger / Lib / DS1307.h
1 /*
2 Copyright (C) Dean Camera, 2010.
3
4 dean [at] fourwalledcubicle [dot] com
5 www.fourwalledcubicle.com
6 */
7
8 #ifndef _DS1307_H_
9 #define _DS1307_H_
10
11 /* Includes: */
12 #include <avr/io.h>
13
14 #include <LUFA/Drivers/Peripheral/TWI.h>
15
16 /* Type Defines: */
17 typedef struct
18 {
19 union
20 {
21 struct
22 {
23 unsigned int Sec : 4;
24 unsigned int TenSec : 3;
25 unsigned int CH : 1;
26 } Fields;
27
28 uint8_t IntVal;
29 } Byte1;
30
31 union
32 {
33 struct
34 {
35 unsigned int Min : 4;
36 unsigned int TenMin : 3;
37 unsigned int _RESERVED : 1;
38 } Fields;
39
40 uint8_t IntVal;
41 } Byte2;
42
43 union
44 {
45 struct
46 {
47 unsigned int Hour : 4;
48 unsigned int TenHour : 2;
49 unsigned int TwelveHourMode : 1;
50 unsigned int _RESERVED : 1;
51 } Fields;
52
53 uint8_t IntVal;
54 } Byte3;
55 } DS1307_TimeRegs_t;
56
57 typedef struct
58 {
59 union
60 {
61 struct
62 {
63 unsigned int Day : 4;
64 unsigned int TenDay : 2;
65 unsigned int _RESERVED : 2;
66 } Fields;
67
68 uint8_t IntVal;
69 } Byte1;
70
71 union
72 {
73 struct
74 {
75 unsigned int Month : 4;
76 unsigned int TenMonth : 1;
77 unsigned int _RESERVED : 3;
78 } Fields;
79
80 uint8_t IntVal;
81 } Byte2;
82
83 union
84 {
85 struct
86 {
87 unsigned int Year : 4;
88 unsigned int TenYear : 4;
89 } Fields;
90
91 uint8_t IntVal;
92 } Byte3;
93 } DS1307_DateRegs_t;
94
95 /* Macros: */
96 #define DS1307_TIMEREG_START 0x00
97 #define DS1307_DATEREG_START 0x04
98
99 #define DS1307_ADDRESS_READ 0b11010001
100 #define DS1307_ADDRESS_WRITE 0b11010000
101
102 /* Function Prototypes: */
103 void DS1307_SetDate(const uint8_t Day,
104 const uint8_t Month,
105 const uint8_t Year);
106 void DS1307_SetTime(const uint8_t Hour,
107 const uint8_t Minute,
108 const uint8_t Second);
109 void DS1307_GetDate(uint8_t* const Day,
110 uint8_t* const Month,
111 uint8_t* const Year);
112 void DS1307_GetTime(uint8_t* const Hour,
113 uint8_t* const Minute,
114 uint8_t* const Second);
115
116 #endif