|
@@ -4,14 +4,14 @@
|
|
|
* SPDX-License-Identifier: GPL-2.0-only
|
|
|
*/
|
|
|
|
|
|
-#include "driver/i2c.h"
|
|
|
+#include <driver/i2c.h>
|
|
|
+#include <sys/time.h>
|
|
|
|
|
|
-#include "esp_err.h"
|
|
|
+#include <esp_err.h>
|
|
|
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
-#include "datetime.h"
|
|
|
#include "bcd.h"
|
|
|
|
|
|
#define DS3231_ADDRESS 0x68
|
|
@@ -115,7 +115,7 @@ static esp_err_t read_month_value(uint8_t* month_value) {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-esp_err_t ds3231_read_date_time(date_time* date_time) {
|
|
|
+esp_err_t ds3231_read_date_time(struct tm* date_time) {
|
|
|
esp_err_t ret;
|
|
|
uint8_t seconds, minutes, hours, dow, day, month, year;
|
|
|
ret = read_value(SECONDS_REGISTER_ADDRESS, &seconds);
|
|
@@ -126,27 +126,28 @@ esp_err_t ds3231_read_date_time(date_time* date_time) {
|
|
|
ret &= read_month_value(&month);
|
|
|
ret &= read_value(YEAR_REGISTER_ADDRESS, &year);
|
|
|
|
|
|
- date_time->seconds = bcd2bin(seconds);
|
|
|
- date_time->minutes = bcd2bin(minutes);
|
|
|
- date_time->hours = hours;
|
|
|
- date_time->dow = bcd2bin(dow);
|
|
|
- date_time->day = bcd2bin(day);
|
|
|
- date_time->month = month;
|
|
|
- date_time->year = bcd2bin(year);
|
|
|
+ date_time->tm_sec = bcd2bin(seconds);
|
|
|
+ date_time->tm_min = bcd2bin(minutes);
|
|
|
+ date_time->tm_hour = hours;
|
|
|
+ date_time->tm_wday = bcd2bin(dow);
|
|
|
+ date_time->tm_mday = bcd2bin(day);
|
|
|
+ date_time->tm_mon = month;
|
|
|
+ date_time->tm_year = bcd2bin(year);
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
-esp_err_t ds3231_write_date_time(date_time date_time) {
|
|
|
+esp_err_t ds3231_write_date_time(struct tm date_time) {
|
|
|
esp_err_t ret;
|
|
|
- ret = write_value(SECONDS_REGISTER_ADDRESS, bin2bcd(date_time.seconds));
|
|
|
- ret &= write_value(MINUTES_REGISTER_ADDRESS, bin2bcd(date_time.minutes));
|
|
|
- ret &= write_value(HOURS_REGISTER_ADDRESS, bin2bcd(date_time.hours));
|
|
|
- ret &= write_value(DOW_REGISTER_ADDRESS, bin2bcd(date_time.dow));
|
|
|
- ret &= write_value(DAY_REGISTER_ADDRESS, bin2bcd(date_time.day));
|
|
|
- ret &= write_value(MONTH_REGISTER_ADDRESS, bin2bcd(date_time.month) | 0x80);
|
|
|
- ret &= write_value(YEAR_REGISTER_ADDRESS, bin2bcd(date_time.year));
|
|
|
+ ret = write_value(SECONDS_REGISTER_ADDRESS, bin2bcd(date_time.tm_sec));
|
|
|
+ ret &= write_value(MINUTES_REGISTER_ADDRESS, bin2bcd(date_time.tm_min));
|
|
|
+ ret &= write_value(HOURS_REGISTER_ADDRESS, bin2bcd(date_time.tm_hour));
|
|
|
+ ret &= write_value(DOW_REGISTER_ADDRESS, bin2bcd(date_time.tm_wday));
|
|
|
+ ret &= write_value(DAY_REGISTER_ADDRESS, bin2bcd(date_time.tm_mday));
|
|
|
+ ret &= write_value(MONTH_REGISTER_ADDRESS, bin2bcd(date_time.tm_mon) | 0x80);
|
|
|
+ ret &= write_value(YEAR_REGISTER_ADDRESS, bin2bcd(date_time.tm_year));
|
|
|
+ ret &= write_value(YEAR_REGISTER_ADDRESS, bin2bcd(date_time.tm_year));
|
|
|
|
|
|
return ret;
|
|
|
|