aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/TempDataLogger/Lib/RTC.h
blob: f35b8ff1ecc910f0062d9720b3a89d24f3821a67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
     Copyright (C) Dean Camera, 2017.

  dean [at] fourwalledcubicle [dot] com
           www.lufa-lib.org
*/

#ifndef _RTC_H_
#define _RTC_H_

	/* Includes: */
		#include <avr/io.h>

		#include <LUFA/Drivers/Peripheral/TWI.h>

		#include "Config/AppConfig.h"

	/* Type Defines: */
		typedef struct
		{
			uint8_t Hour;
			uint8_t Minute;
			uint8_t Second;
			uint8_t Day;
			uint8_t Month;
			uint8_t Year;
		} TimeDate_t;

		typedef struct
		{
			union
			{
				struct
				{
					unsigned Sec            : 4;
					unsigned TenSec         : 3;
					unsigned CH             : 1;
				} Fields;

				uint8_t IntVal;
			} Byte1;

			union
			{
				struct
				{
					unsigned Min            : 4;
					unsigned TenMin         : 3;
					unsigned Reserved       : 1;
				} Fields;

				uint8_t IntVal;
			} Byte2;

			union
			{
				struct
				{
					unsigned Hour            : 4;
					unsigned TenHour         : 2;
					unsigned TwelveHourMode  : 1;
					unsigned Reserved        : 1;
				} Fields;

				uint8_t IntVal;
			} Byte3;

			union
			{
				struct
				{
					unsigned DayOfWeek       : 3;
					unsigned Reserved        : 5;
				} Fields;

				uint8_t IntVal;
			} Byte4;

			union
			{
				struct
				{
					unsigned Day             : 4;
					unsigned TenDay          : 2;
					unsigned Reserved        : 2;
				} Fields;

				uint8_t IntVal;
			} Byte5;

			union
			{
				struct
				{
					unsigned Month           : 4;
					unsigned TenMonth        : 1;
					unsigned Reserved        : 3;
				} Fields;

				uint8_t IntVal;
			} Byte6;

			union
			{
				struct
				{
					unsigned Year            : 4;
					unsigned TenYear         : 4;
				} Fields;

				uint8_t IntVal;
			} Byte7;
		} DS1307_DateTimeRegs_t;

	/* Macros: */
		/** TWI address of the DS1307 device on the bus. */
		#define DS1307_ADDRESS       0xD0

	/* Function Prototypes: */
		void RTC_Init(void);
		void RTC_Tick500ms(void);
		bool RTC_SetTimeDate(const TimeDate_t* NewTimeDate);
		bool RTC_GetTimeDate(TimeDate_t* const TimeDate);

#endif