Changed TempDataLogger project's DS1307 driver to simplify the function interface...
[pub/USBasp.git] / Projects / TempDataLogger / Lib / DS1307.h
1 /*
2 Copyright (C) Dean Camera, 2011.
3
4 dean [at] fourwalledcubicle [dot] com
5 www.lufa-lib.org
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 uint8_t Hour;
20 uint8_t Minute;
21 uint8_t Second;
22 uint8_t Day;
23 uint8_t Month;
24 uint8_t Year;
25 } TimeDate_t;
26
27 typedef struct
28 {
29 union
30 {
31 struct
32 {
33 unsigned int Sec : 4;
34 unsigned int TenSec : 3;
35 unsigned int CH : 1;
36 } Fields;
37
38 uint8_t IntVal;
39 } Byte1;
40
41 union
42 {
43 struct
44 {
45 unsigned int Min : 4;
46 unsigned int TenMin : 3;
47 unsigned int Reserved : 1;
48 } Fields;
49
50 uint8_t IntVal;
51 } Byte2;
52
53 union
54 {
55 struct
56 {
57 unsigned int Hour : 4;
58 unsigned int TenHour : 2;
59 unsigned int TwelveHourMode : 1;
60 unsigned int Reserved : 1;
61 } Fields;
62
63 uint8_t IntVal;
64 } Byte3;
65 } DS1307_TimeRegs_t;
66
67 typedef struct
68 {
69 union
70 {
71 struct
72 {
73 unsigned int Day : 4;
74 unsigned int TenDay : 2;
75 unsigned int Reserved : 2;
76 } Fields;
77
78 uint8_t IntVal;
79 } Byte1;
80
81 union
82 {
83 struct
84 {
85 unsigned int Month : 4;
86 unsigned int TenMonth : 1;
87 unsigned int Reserved : 3;
88 } Fields;
89
90 uint8_t IntVal;
91 } Byte2;
92
93 union
94 {
95 struct
96 {
97 unsigned int Year : 4;
98 unsigned int TenYear : 4;
99 } Fields;
100
101 uint8_t IntVal;
102 } Byte3;
103 } DS1307_DateRegs_t;
104
105 /* Macros: */
106 #define DS1307_ADDRESS_READ (0xD0 | TWI_ADDRESS_READ)
107 #define DS1307_ADDRESS_WRITE (0xD0 | TWI_ADDRESS_WRITE)
108
109 /* Function Prototypes: */
110 void DS1307_SetTimeDate(const TimeDate_t* NewTimeDate);
111 void DS1307_GetTimeDate(TimeDate_t* const TimeDate);
112
113 #endif
114