48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#pragma once
|
|
#include <stdint.h>
|
|
|
|
class DS1302
|
|
{
|
|
public:
|
|
typedef struct Timeval
|
|
{
|
|
uint8_t sec;
|
|
uint8_t min;
|
|
uint8_t hour;
|
|
uint8_t day;
|
|
uint8_t month;
|
|
uint16_t year;
|
|
} Timeval;
|
|
|
|
private:
|
|
|
|
static constexpr uint16_t EPOCH = 2000;
|
|
|
|
static constexpr uint8_t REG_SEC = 0x80;
|
|
static constexpr uint8_t REG_MIN = 0x82;
|
|
static constexpr uint8_t REG_HOUR = 0x84;
|
|
static constexpr uint8_t REG_DAY = 0x86;
|
|
static constexpr uint8_t REG_MONTH= 0x88;
|
|
static constexpr uint8_t REG_YEAR = 0x8C;
|
|
static constexpr uint8_t REG_WP = 0x8E;
|
|
|
|
static constexpr int8_t writeRegisterOffset = -1;
|
|
|
|
volatile unsigned char *_port;
|
|
volatile unsigned char *_pinReg;
|
|
volatile unsigned char *_ddrReg;
|
|
const unsigned char _pinIO;
|
|
const unsigned char _pinCE;
|
|
const unsigned char _pinSCLK;
|
|
|
|
|
|
public:
|
|
DS1302(volatile unsigned char *port, volatile unsigned char *pinReg, volatile unsigned char *ddrReg, const unsigned char pinIO, const unsigned char pinCE, const unsigned char pinSCLK);
|
|
|
|
void write(const uint8_t addr,const uint8_t value);
|
|
uint8_t read(const uint8_t addr);
|
|
|
|
Timeval getTime();
|
|
void setTime(const Timeval& in);
|
|
};
|