inital version
This commit is contained in:
47
ds1302.h
Normal file
47
ds1302.h
Normal file
@ -0,0 +1,47 @@
|
||||
#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);
|
||||
};
|
Reference in New Issue
Block a user