1 #ifndef LIBPROPELLER_PCF8523_H_
2 #define LIBPROPELLER_PCF8523_H_
68 if (status_ ==
false) {
73 bus_->
Put(kDeviceAddress, kCONTROL_1, 0b10000000);
74 bus_->
Put(kDeviceAddress, kCONTROL_2, 0b00000000);
75 bus_->
Put(kDeviceAddress, kCONTROL_3, 0b00000000);
87 status_ = bus_->
Ping(kDeviceAddress);
109 bool SetClock(
const int year,
const int month,
const int day,
110 const int hour,
const int minute,
const int second,
const int weekday = 0) {
116 clock[0] = ConvertToBCD(second);
117 clock[1] = ConvertToBCD(minute);
118 clock[2] = ConvertToBCD(hour);
119 clock[3] = ConvertToBCD(day);
120 clock[4] = ConvertToBCD(weekday);
121 clock[5] = ConvertToBCD(month);
122 clock[6] = ConvertToBCD(year);
124 clock[0] &= 0b01111111;
126 bus_->
Put(kDeviceAddress, kSECONDS, clock, 7);
145 int & hour,
int & minute,
int & second,
int & weekday) {
151 bus_->
Get(kDeviceAddress, kSECONDS, clock, 7);
152 second = ConvertFromBCD(clock[0]);
153 minute = ConvertFromBCD(clock[1]);
154 hour = ConvertFromBCD(clock[2]);
155 day = ConvertFromBCD(clock[3]);
156 weekday = ConvertFromBCD(clock[4]);
157 month = ConvertFromBCD(clock[5]);
158 year = ConvertFromBCD(clock[6]);
176 int & hour,
int & minute,
int & second) {
178 return GetClock(year, month, day, hour, minute, second, temp);
187 const static unsigned char kDeviceAddress = 0b11010000;
189 const static unsigned char kCONTROL_1 = 0x00;
190 const static unsigned char kCONTROL_2 = 0x01;
191 const static unsigned char kCONTROL_3 = 0x02;
192 const static unsigned char kSECONDS = 0x03;
203 char ConvertToBCD(
const int number)
const {
204 int unit = number % 10;
205 int tens = (number % 100) / 10;
207 return (tens << 4) | unit;
218 int ConvertFromBCD(
const unsigned char bcd)
const {
219 return ((bcd >> 4) * 10) + (bcd & 0xF);
223 friend class UnityTests;
227 #endif // LIBPROPELLER_PCF8523_H_