2010-05-08 03:12:14 +00:00
|
|
|
/*
|
2013-01-03 11:37:33 +00:00
|
|
|
Copyright (C) Dean Camera, 2013.
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
dean [at] fourwalledcubicle [dot] com
|
2010-10-28 06:08:58 +00:00
|
|
|
www.lufa-lib.org
|
2010-05-08 03:12:14 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-07-20 10:35:28 +02:00
|
|
|
#ifndef _RTC_H_
|
|
|
|
|
#define _RTC_H_
|
2010-05-08 03:12:14 +00:00
|
|
|
|
|
|
|
|
/* Includes: */
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
|
|
|
|
|
#include <LUFA/Drivers/Peripheral/TWI.h>
|
2013-07-20 10:35:28 +02:00
|
|
|
|
2012-05-10 20:28:39 +00:00
|
|
|
#include "Config/AppConfig.h"
|
2010-05-08 03:12:14 +00:00
|
|
|
|
|
|
|
|
/* Type Defines: */
|
2011-01-13 19:14:38 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
uint8_t Hour;
|
|
|
|
|
uint8_t Minute;
|
|
|
|
|
uint8_t Second;
|
|
|
|
|
uint8_t Day;
|
|
|
|
|
uint8_t Month;
|
|
|
|
|
uint8_t Year;
|
|
|
|
|
} TimeDate_t;
|
2011-12-23 01:51:39 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2011-04-10 06:43:02 +00:00
|
|
|
unsigned Sec : 4;
|
|
|
|
|
unsigned TenSec : 3;
|
|
|
|
|
unsigned CH : 1;
|
2010-07-18 07:31:57 +00:00
|
|
|
} Fields;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
uint8_t IntVal;
|
|
|
|
|
} Byte1;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2011-04-10 06:43:02 +00:00
|
|
|
unsigned Min : 4;
|
|
|
|
|
unsigned TenMin : 3;
|
|
|
|
|
unsigned Reserved : 1;
|
2010-07-18 07:31:57 +00:00
|
|
|
} Fields;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
uint8_t IntVal;
|
|
|
|
|
} Byte2;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2011-04-10 06:43:02 +00:00
|
|
|
unsigned Hour : 4;
|
|
|
|
|
unsigned TenHour : 2;
|
|
|
|
|
unsigned TwelveHourMode : 1;
|
|
|
|
|
unsigned Reserved : 1;
|
2010-07-18 07:31:57 +00:00
|
|
|
} Fields;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
uint8_t IntVal;
|
|
|
|
|
} Byte3;
|
|
|
|
|
|
2011-01-13 21:01:05 +00:00
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2011-04-10 06:43:02 +00:00
|
|
|
unsigned DayOfWeek : 3;
|
|
|
|
|
unsigned Reserved : 5;
|
2011-01-13 21:01:05 +00:00
|
|
|
} Fields;
|
|
|
|
|
|
|
|
|
|
uint8_t IntVal;
|
|
|
|
|
} Byte4;
|
2011-12-23 01:51:39 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2011-04-10 06:43:02 +00:00
|
|
|
unsigned Day : 4;
|
|
|
|
|
unsigned TenDay : 2;
|
|
|
|
|
unsigned Reserved : 2;
|
2010-07-18 07:31:57 +00:00
|
|
|
} Fields;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
uint8_t IntVal;
|
2011-01-13 21:01:05 +00:00
|
|
|
} Byte5;
|
2010-05-08 03:12:14 +00:00
|
|
|
|
|
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2011-04-10 06:43:02 +00:00
|
|
|
unsigned Month : 4;
|
|
|
|
|
unsigned TenMonth : 1;
|
|
|
|
|
unsigned Reserved : 3;
|
2010-07-18 07:31:57 +00:00
|
|
|
} Fields;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
uint8_t IntVal;
|
2011-01-13 21:01:05 +00:00
|
|
|
} Byte6;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
union
|
|
|
|
|
{
|
|
|
|
|
struct
|
|
|
|
|
{
|
2011-04-10 06:43:02 +00:00
|
|
|
unsigned Year : 4;
|
|
|
|
|
unsigned TenYear : 4;
|
2010-07-18 07:31:57 +00:00
|
|
|
} Fields;
|
2010-10-13 14:05:35 +00:00
|
|
|
|
2010-05-08 03:12:14 +00:00
|
|
|
uint8_t IntVal;
|
2011-01-13 21:01:05 +00:00
|
|
|
} Byte7;
|
|
|
|
|
} DS1307_DateTimeRegs_t;
|
2010-05-08 03:12:14 +00:00
|
|
|
|
|
|
|
|
/* Macros: */
|
2012-05-10 20:28:39 +00:00
|
|
|
/** TWI address of the DS1307 device on the bus. */
|
2011-01-13 22:56:49 +00:00
|
|
|
#define DS1307_ADDRESS 0xD0
|
2010-05-08 03:12:14 +00:00
|
|
|
|
|
|
|
|
/* Function Prototypes: */
|
2013-07-20 10:35:28 +02:00
|
|
|
void RTC_Init(void);
|
|
|
|
|
void RTC_Tick500ms(void);
|
|
|
|
|
bool RTC_SetTimeDate(const TimeDate_t* NewTimeDate);
|
|
|
|
|
bool RTC_GetTimeDate(TimeDate_t* const TimeDate);
|
2010-05-08 03:12:14 +00:00
|
|
|
|
|
|
|
|
#endif
|
2010-10-13 14:05:35 +00:00
|
|
|
|