@@ -25,11 +25,11 @@ static uint16_t read_year = 0;
25
25
static int peek_data = -1 ;
26
26
27
27
const auto BCD2DEC = [](uint8_t num) -> uint8_t {
28
- return ((num/ 16 * 10 ) + (num % 16 ));
28
+ return ((num / 16 * 10 ) + (num % 16 ));
29
29
};
30
30
31
31
const auto DEC2BCD = [](uint8_t num) -> uint8_t {
32
- return ((num/ 10 * 16 ) + (num % 10 ));
32
+ return ((num / 10 * 16 ) + (num % 10 ));
33
33
};
34
34
35
35
void reset_read_values () {
@@ -49,7 +49,7 @@ void ds1307_start(void) {
49
49
Wire.write (0x00 );
50
50
Wire.endTransmission ();
51
51
Wire.requestFrom (DS1307_ADDR, 1 );
52
- sec = Wire.read () & 0x7F ; // Seconds without halt bit
52
+ sec = Wire.read () & 0x7F ; // Seconds without halt bit
53
53
54
54
// Set seconds and start clock
55
55
Wire.beginTransmission (DS1307_ADDR);
@@ -66,7 +66,7 @@ void ds1307_stop(void) {
66
66
Wire.write (0x00 );
67
67
Wire.endTransmission ();
68
68
Wire.requestFrom (DS1307_ADDR, 1 );
69
- sec = Wire.read () | 0x80 ; // Seconds with halt bit
69
+ sec = Wire.read () | 0x80 ; // Seconds with halt bit
70
70
71
71
// Set seconds and halt clock
72
72
Wire.beginTransmission (DS1307_ADDR);
@@ -75,8 +75,7 @@ void ds1307_stop(void) {
75
75
Wire.endTransmission ();
76
76
}
77
77
78
- void ds1307_get_time (uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, uint8_t *month, uint16_t *year)
79
- {
78
+ void ds1307_get_time (uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, uint8_t *month, uint16_t *year) {
80
79
// Get time
81
80
Wire.beginTransmission (DS1307_ADDR);
82
81
Wire.write (0x00 );
@@ -89,24 +88,22 @@ void ds1307_get_time(uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, ui
89
88
peek_data = Wire.peek ();
90
89
}
91
90
92
- *sec = BCD2DEC (Wire.read () & 0x7F ); // Seconds without halt bit
91
+ *sec = BCD2DEC (Wire.read () & 0x7F ); // Seconds without halt bit
93
92
*min = BCD2DEC (Wire.read ());
94
93
*hour = BCD2DEC (Wire.read () & 0x3F );
95
- Wire.read (); // Ignore day of week
94
+ Wire.read (); // Ignore day of week
96
95
*day = BCD2DEC (Wire.read ());
97
96
*month = BCD2DEC (Wire.read ());
98
97
*year = BCD2DEC (Wire.read ()) + 2000 ;
99
98
}
100
99
101
-
102
- void ds1307_set_time (uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year)
103
- {
100
+ void ds1307_set_time (uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) {
104
101
Wire.beginTransmission (DS1307_ADDR);
105
102
Wire.write (0x00 );
106
103
Wire.write (DEC2BCD (sec));
107
104
Wire.write (DEC2BCD (min));
108
105
Wire.write (DEC2BCD (hour));
109
- Wire.write (DEC2BCD (0 )); // Ignore day of week
106
+ Wire.write (DEC2BCD (0 )); // Ignore day of week
110
107
Wire.write (DEC2BCD (day));
111
108
Wire.write (DEC2BCD (month));
112
109
Wire.write (DEC2BCD (year - 2000 ));
@@ -157,7 +154,7 @@ void rtc_run_clock() {
157
154
ds1307_get_time (&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
158
155
159
156
// Check time
160
- TEST_ASSERT_UINT8_WITHIN (2 , start_sec+ 5 , read_sec);
157
+ TEST_ASSERT_UINT8_WITHIN (2 , start_sec + 5 , read_sec);
161
158
TEST_ASSERT_EQUAL (start_min, read_min);
162
159
TEST_ASSERT_EQUAL (start_hour, read_hour);
163
160
TEST_ASSERT_EQUAL (start_day, read_day);
@@ -180,7 +177,7 @@ void rtc_run_clock() {
180
177
TEST_ASSERT_EQUAL (start_year, read_year);
181
178
}
182
179
183
- void change_clock (){
180
+ void change_clock () {
184
181
// Get time
185
182
ds1307_get_time (&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
186
183
@@ -209,7 +206,7 @@ void change_clock(){
209
206
TEST_ASSERT_EQUAL (start_year, read_year);
210
207
}
211
208
212
- void swap_pins (){
209
+ void swap_pins () {
213
210
Wire.setPins (SCL, SDA);
214
211
Wire.begin ();
215
212
// Set time
0 commit comments