2010-05-08 05:12:14 +02:00
|
|
|
/*
|
2011-01-01 14:00:56 +01:00
|
|
|
Copyright (C) Dean Camera, 2011.
|
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>
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int Sec : 4;
|
|
|
|
unsigned int TenSec : 3;
|
|
|
|
unsigned int 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
|
|
|
|
{
|
|
|
|
unsigned int Min : 4;
|
|
|
|
unsigned int TenMin : 3;
|
2010-07-26 09:28:40 +02:00
|
|
|
unsigned int 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
|
|
|
|
{
|
|
|
|
unsigned int Hour : 4;
|
|
|
|
unsigned int TenHour : 2;
|
|
|
|
unsigned int TwelveHourMode : 1;
|
2010-07-26 09:28:40 +02:00
|
|
|
unsigned int 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;
|
|
|
|
} DS1307_TimeRegs_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int Day : 4;
|
|
|
|
unsigned int TenDay : 2;
|
2010-07-26 09:28:40 +02:00
|
|
|
unsigned int 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;
|
|
|
|
} Byte1;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int Month : 4;
|
|
|
|
unsigned int TenMonth : 1;
|
2010-07-26 09:28:40 +02:00
|
|
|
unsigned int 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;
|
|
|
|
} Byte2;
|
2010-10-13 16:05:35 +02:00
|
|
|
|
2010-05-08 05:12:14 +02:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int Year : 4;
|
|
|
|
unsigned int 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;
|
|
|
|
} Byte3;
|
|
|
|
} DS1307_DateRegs_t;
|
|
|
|
|
|
|
|
/* Macros: */
|
2010-12-26 15:25:34 +01:00
|
|
|
#define DS1307_ADDRESS_READ (0xD0 | TWI_ADDRESS_READ)
|
|
|
|
#define DS1307_ADDRESS_WRITE (0xD0 | TWI_ADDRESS_WRITE)
|
2010-05-08 05:12:14 +02:00
|
|
|
|
|
|
|
/* Function Prototypes: */
|
2011-01-13 20:14:38 +01:00
|
|
|
void DS1307_SetTimeDate(const TimeDate_t* NewTimeDate);
|
|
|
|
void DS1307_GetTimeDate(TimeDate_t* const TimeDate);
|
2010-05-08 05:12:14 +02:00
|
|
|
|
|
|
|
#endif
|
2010-10-13 16:05:35 +02:00
|
|
|
|