Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit c460fe1

Browse files
committed
Added javadoc comments
1 parent b64da1d commit c460fe1

File tree

1 file changed

+135
-3
lines changed

1 file changed

+135
-3
lines changed

src/utility/RTC/PCF8563T.cpp

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define PCF8563T_MONTHS_REG 0x07
2929
#define PCF8563T_YEARS_REG 0x08
3030

31-
// allarm management
31+
// allarm managemet
3232
#define PCF8563T_MINUTE_ALARM_REG 0x09
3333
#define PCF8563T_MINUTE_ALARM_AE_M_MASK 0x80
3434
#define PCF8563T_MINUTE_ALARM_ON 0x7F
@@ -49,10 +49,20 @@
4949
#define PCF8563T_STATUS_2_CLEAR_INT 0xF7
5050
#define PCF8563T_STATUS_2_INT_OFF 0x7d
5151

52+
/**
53+
* Object constructor
54+
*
55+
*/
5256
PCF8563TClass::PCF8563TClass()
5357
{
5458
}
5559

60+
/**
61+
* Start the communication with the RTC
62+
*
63+
* @return true if the RTC Controller is on the I2C bus, false in case it is not in the bus.
64+
*
65+
*/
5666
bool PCF8563TClass::begin()
5767
{
5868
Wire1.begin(); // join i2c bus
@@ -64,12 +74,22 @@ bool PCF8563TClass::begin()
6474
return false;
6575
}
6676

77+
/**
78+
* Set Year number
79+
*
80+
* @param years Year's number
81+
*/
6782
void PCF8563TClass::setYears(uint8_t years) {
6883
uint8_t dec = years / 10;
6984
uint8_t unit = years - (dec * 10);
7085
writeByte(PCF8563T_YEARS_REG, ((dec << 4) + unit));
7186
}
7287

88+
/**
89+
* Set Month number
90+
*
91+
* @param months Month's number (0 to 12)
92+
*/
7393
void PCF8563TClass::setMonths(uint8_t months) {
7494
uint8_t offset = 0;
7595
if (months > 9) {
@@ -78,35 +98,65 @@ void PCF8563TClass::setMonths(uint8_t months) {
7898
writeByte(PCF8563T_MONTHS_REG, months + offset);
7999
}
80100

101+
/**
102+
* Set Day number
103+
*
104+
* @param days day's number
105+
*/
81106
void PCF8563TClass::setDays(uint8_t days) {
82107
uint8_t dec = days / 10;
83108
uint8_t unit = days - (dec * 10);
84109
writeByte(PCF8563T_DAYS_REG, ((dec << 4) + unit));
85110
}
86111

112+
/**
113+
* Set Hour
114+
*
115+
* @param hours hour number
116+
*/
87117
void PCF8563TClass::setHours(uint8_t hours) {
88118
uint8_t dec = hours / 10;
89119
uint8_t unit = hours - (dec * 10);
90120
writeByte(PCF8563T_HOURS_REG, ((dec << 4) + unit)); //check formula on datasheet val + 6 * (val / 10)
91121
}
92122

123+
/**
124+
* Set Minute
125+
*
126+
* @param minutes minute number
127+
*/
93128
void PCF8563TClass::setMinutes(uint8_t minutes) {
94129
uint8_t dec = minutes / 10;
95130
uint8_t unit = minutes - (dec * 10);
96131
writeByte(PCF8563T_MINUTES_REG, ((dec << 4) + unit));
97132
}
98133

134+
/**
135+
* Set Second number
136+
*
137+
* @param seconds Second number
138+
*/
99139
void PCF8563TClass::setSeconds(uint8_t seconds) {
100140
uint8_t dec = seconds / 10;
101141
uint8_t unit = seconds - (dec * 10);
102142
writeByte(PCF8563T_VL_SECONDS_REG, ((dec << 4) + unit));
103143
}
104144

145+
/**
146+
* Get Year number
147+
*
148+
* @return number of years
149+
*/
105150
uint8_t PCF8563TClass::getYears() {
106151
uint8_t years = readByte(PCF8563T_YEARS_REG);
107152
return (years & 0x0F) + ((years >> 4)*10);
108153
}
109154

155+
/**
156+
* Get Month number
157+
*
158+
* @return number of month
159+
*/
110160
uint8_t PCF8563TClass::getMonths() {
111161
uint8_t months = readByte(PCF8563T_MONTHS_REG) & 0x1F;
112162
if(months > 9) {
@@ -116,27 +166,50 @@ uint8_t PCF8563TClass::getMonths() {
116166
}
117167
}
118168

169+
/**
170+
* Get Day number
171+
*
172+
* @return number of days
173+
*/
119174
uint8_t PCF8563TClass::getDays() {
120175
uint8_t days = readByte(PCF8563T_DAYS_REG);
121176
return (days & 0x0F) + ((days >> 4)*10);
122177
}
123178

179+
/**
180+
* Get Hour number
181+
*
182+
* @return number of hours
183+
*/
124184
uint8_t PCF8563TClass::getHours() {
125185
uint8_t hours = readByte(PCF8563T_HOURS_REG) & 0x3F;
126186
return (hours & 0x0F) + ((hours >> 4)*10);
127187
}
128188

189+
/**
190+
* Get Minute number
191+
*
192+
* @return number of minutes
193+
*/
129194
uint8_t PCF8563TClass::getMinutes() {
130195
uint8_t minutes = (readByte(PCF8563T_MINUTES_REG)) & 0x7F ;
131196
return (minutes & 0x0F) + ((minutes >> 4)*10);
132197
}
133198

199+
/**
200+
* Get Second number
201+
*
202+
* @return number of seconds
203+
*/
134204
uint8_t PCF8563TClass::getSeconds() {
135205
uint8_t seconds = readByte(PCF8563T_VL_SECONDS_REG) & 0x7F;
136206
return (seconds & 0x0F) + ((seconds >> 4)*10);
137207
}
138208

139-
209+
/**
210+
* Set time by epoch
211+
*
212+
*/
140213
void PCF8563TClass::setEpoch() {
141214
struct tm time;
142215
time.tm_sec = getSeconds();
@@ -150,6 +223,11 @@ void PCF8563TClass::setEpoch() {
150223
set_time(seconds);
151224
}
152225

226+
/**
227+
* Set time by epoch
228+
*
229+
* @param seconds number of seconds
230+
*/
153231
void PCF8563TClass::setEpoch(time_t seconds) {
154232
struct tm time;
155233
_rtc_localtime(seconds, &time, RTC_FULL_LEAP_YEAR_SUPPORT);
@@ -163,7 +241,16 @@ void PCF8563TClass::setEpoch(time_t seconds) {
163241
set_time(seconds);
164242
}
165243

166-
244+
/**
245+
* Set time by epoch
246+
*
247+
* @param years number of years
248+
* @param mohths number of months
249+
* @param days number of days
250+
* @param hours number of hours
251+
* @param minutes number of minutes
252+
* @param seconds number of seconds
253+
*/
167254
void PCF8563TClass::setEpoch(uint8_t years, uint8_t months, uint8_t days, uint8_t hours, uint8_t minutes, uint8_t seconds) {
168255
struct tm time;
169256
time_t utcsec;
@@ -179,6 +266,11 @@ void PCF8563TClass::setEpoch(uint8_t years, uint8_t months, uint8_t days, uint8_
179266
set_time(utcsec);
180267
}
181268

269+
/**
270+
* Get epoch number, convert real time to difference between actual time and epoch(Unix time)
271+
*
272+
* @return number of seconds after Unix time
273+
*/
182274
time_t PCF8563TClass::getEpoch() {
183275
struct tm time;
184276
time_t seconds;
@@ -194,47 +286,87 @@ time_t PCF8563TClass::getEpoch() {
194286
return seconds;
195287
}
196288

289+
/**
290+
* Enable alarm mode
291+
*
292+
*/
197293
void PCF8563TClass::enableAlarm() {
198294
writeByte(PCF8563T_STATUS_2_REG, (readByte(PCF8563T_STATUS_2_REG) & PCF8563T_STATUS_2_CLEAR_INT) | PCF8563T_STATUS_2_AIE_MASK);
199295
}
200296

297+
/**
298+
* Disable alarm mode
299+
*
300+
*/
201301
void PCF8563TClass::disableAlarm() {
202302
writeByte(PCF8563T_STATUS_2_REG, (readByte(PCF8563T_STATUS_2_REG) & PCF8563T_STATUS_2_INT_OFF));
203303
}
204304

305+
/**
306+
* Clear alarm status
307+
*
308+
*/
205309
void PCF8563TClass::clearAlarm() {
206310
writeByte(PCF8563T_STATUS_2_REG, (readByte(PCF8563T_STATUS_2_REG) & PCF8563T_STATUS_2_CLEAR_INT) | PCF8563T_STATUS_2_AIE_MASK);
207311
}
208312

313+
/**
314+
* Set alarm's minute
315+
*
316+
* @param minutes minute number for the Aarm
317+
* @return none
318+
*/
209319
void PCF8563TClass::setMinuteAlarm(uint8_t minutes) {
210320
uint8_t dec = minutes / 10;
211321
uint8_t unit = minutes - (dec * 10);
212322
uint8_t min_alarm = PCF8563T_MINUTE_ALARM_ON & ((dec << 4) + unit);
213323
writeByte(PCF8563T_MINUTE_ALARM_REG , min_alarm);
214324
}
215325

326+
/**
327+
* Disable and clear the minute of the Alarm
328+
*
329+
*/
216330
void PCF8563TClass::disableMinuteAlarm() {
217331
writeByte(PCF8563T_MINUTE_ALARM_REG, readByte(PCF8563T_MINUTE_ALARM_REG) | PCF8563T_MINUTE_ALARM_AE_M_MASK);
218332
}
219333

334+
/**
335+
* Set Alarm's hour
336+
*
337+
* @param hours hour number for the Alarm
338+
*/
220339
void PCF8563TClass::setHourAlarm(uint8_t hours) {
221340
uint8_t dec = hours / 10;
222341
uint8_t unit = hours - (dec * 10);
223342
uint8_t hour_alarm = PCF8563T_HOUR_ALARM_AE_H_MASK & ((dec << 4) + unit);
224343
writeByte(PCF8563T_HOURS_REG, hour_alarm); //check formula on datasheet val + 6 * (val / 10)
225344
}
226345

346+
/**
347+
* Disable and clear the hour of the Alarm
348+
*
349+
*/
227350
void PCF8563TClass::disableHourAlarm() {
228351
writeByte(PCF8563T_HOUR_ALARM_REG, readByte(PCF8563T_HOUR_ALARM_REG) | PCF8563T_HOUR_ALARM_AE_H_MASK);
229352
}
230353

354+
/**
355+
* Set Alarm's day
356+
*
357+
* @param days day number for the Alarm
358+
*/
231359
void PCF8563TClass::setDayAlarm(uint8_t days) {
232360
uint8_t dec = days / 10;
233361
uint8_t unit = days - (dec * 10);
234362
uint8_t day_alarm = PCF8563T_DAY_ALARM_ON & ((dec << 4) + unit);
235363
writeByte(PCF8563T_DAY_ALARM_REG, day_alarm);
236364
}
237365

366+
/**
367+
* Disable and clear the day of the Alarm
368+
*
369+
*/
238370
void PCF8563TClass::disableDayAlarm() {
239371
writeByte(PCF8563T_DAY_ALARM_REG, readByte(PCF8563T_DAY_ALARM_REG) | PCF8563T_DAY_ALARM_AE_D_MASK );
240372
}

0 commit comments

Comments
 (0)