COSA
An Object-Oriented Platform for Arduino Programming
PCF8563.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_PCF8563_HH
22 #define COSA_PCF8563_HH
23 
24 #include "Cosa/TWI.hh"
25 #include "Cosa/Time.hh"
26 #include "Cosa/IOStream.hh"
27 
35 class PCF8563 : private TWI::Driver {
36 public:
40  PCF8563() :
41  TWI::Driver(0x51)
42  {}
43 
50  bool get_time(time_t& now);
51 
58  bool set_time(time_t& now);
59 
63  struct alarm_t {
64  uint8_t minutes;
65  uint8_t hours;
66  uint8_t date;
67  uint8_t day;
68 
70  static const uint8_t DISABLE = 0x80;
71 
77  {
78  minutes = DISABLE;
79  hours = DISABLE;
80  date = DISABLE;
81  day = DISABLE;
82  }
83  };
84 
91  bool set_alarm(alarm_t& alarm);
92 
99  bool get_alarm(alarm_t& alarm);
100 
106  bool clear_alarm();
107 
113  bool pending_alarm();
114 
115 protected:
120  uint8_t as_uint8;
121  struct {
122  uint8_t N1:3;
123  uint8_t TESTC:1;
124  uint8_t N2:1;
125  uint8_t STOP:1;
126  uint8_t N3:1;
127  uint8_t TEST1:1;
128  };
129  control_status_1_t(uint8_t value = 0)
130  {
131  as_uint8 = value;
132  }
133  };
134 
139  uint8_t as_uint8;
140  struct {
141  uint8_t TIE:1;
142  uint8_t AIE:1;
143  uint8_t TF:1;
144  uint8_t AF:1;
145  uint8_t TI_TP:1;
146  uint8_t N:3;
147  };
148  control_status_2_t(uint8_t value = 0)
149  {
150  as_uint8 = value;
151  }
152  };
153 
158  uint8_t as_uint8;
159  struct {
160  uint8_t FD:2;
161  uint8_t unused1:5;
162  uint8_t FE:1;
163  };
164  clock_control_t(uint8_t value = 0)
165  {
166  as_uint8 = value;
167  }
168  };
169 
173  enum {
178  } __attribute__((packed));
179 
184  uint8_t as_uint8;
185  struct {
186  uint8_t TD:2;
187  uint8_t unused1:5;
188  uint8_t TE:1;
189  };
190  timer_control_t(uint8_t value = 0)
191  {
192  as_uint8 = value;
193  }
194  };
195 
199  enum {
204  } __attribute__((packed));
205 
209  struct rtcc_t {
216  uint8_t timer;
217  };
218 
227  int read(void* regs, uint8_t size, uint8_t pos = 0);
228 
237  int write(void* regs, uint8_t size, uint8_t pos = 0);
238 };
239 
247 
248 #endif
Definition: TWI.hh:51
control_status_2_t cs2
Control Status 2.
Definition: PCF8563.hh:211
control_status_1_t cs1
Control Status 1.
Definition: PCF8563.hh:210
time_t clock
Real-Time Clock.
Definition: PCF8563.hh:212
int read(void *regs, uint8_t size, uint8_t pos=0)
Definition: PCF8563.cpp:24
int write(void *regs, uint8_t size, uint8_t pos=0)
Definition: PCF8563.cpp:34
uint8_t hours
00-23 Hours (BCD).
Definition: PCF8563.hh:65
timer_control_t tc
Timer Control.
Definition: PCF8563.hh:215
uint8_t timer
Timer Period.
Definition: PCF8563.hh:216
control_status_1_t(uint8_t value=0)
Definition: PCF8563.hh:129
bool clear_alarm()
Definition: PCF8563.cpp:118
clock_control_t(uint8_t value=0)
Definition: PCF8563.hh:164
bool set_alarm(alarm_t &alarm)
Definition: PCF8563.cpp:90
control_status_2_t(uint8_t value=0)
Definition: PCF8563.hh:148
bool set_time(time_t &now)
Definition: PCF8563.cpp:62
static const uint8_t DISABLE
Definition: PCF8563.hh:70
uint8_t date
01-31 Date (BCD).
Definition: PCF8563.hh:66
bool get_alarm(alarm_t &alarm)
Definition: PCF8563.cpp:77
uint8_t as_uint8
Unsigned byte access.
Definition: PCF8563.hh:120
uint8_t as_uint8
Unsigned byte access.
Definition: PCF8563.hh:158
bool pending_alarm()
Definition: PCF8563.cpp:107
uint8_t as_uint8
Unsigned byte access.
Definition: PCF8563.hh:139
Definition: Time.hh:102
uint8_t as_uint8
Unsigned byte access.
Definition: PCF8563.hh:184
timer_control_t(uint8_t value=0)
Definition: PCF8563.hh:190
Driver(uint8_t addr)
Definition: TWI.hh:70
PCF8563()
Definition: PCF8563.hh:40
IOStream & operator<<(IOStream &cout, PCF8563::alarm_t &alarm)
Definition: PCF8563.cpp:132
alarm_t alarm
Alarm Function.
Definition: PCF8563.hh:213
bool get_time(time_t &now)
Definition: PCF8563.cpp:43
uint8_t minutes
00-59 Minutes (BCD).
Definition: PCF8563.hh:64
clock_control_t cc
Clock Output Control.
Definition: PCF8563.hh:214
uint8_t day
00-06 Day (BCD).
Definition: PCF8563.hh:67