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