From 81b26a2df76c4672a3b30ff22cfcb6f5b04fdc37 Mon Sep 17 00:00:00 2001 From: Michal Lenc Date: Tue, 28 May 2024 10:16:48 +0200 Subject: [PATCH] timers/mcp794xx: add possibility to store datetime in UTC This commit adds configuration option CONFIG_MCP794XX_DATETIME_UTC. If set, the datetime is stored in UTC instead of local time. The default value is kept at local time to keep backwards compatibility with devices currently using the RTC. Signed-off-by: Michal Lenc --- drivers/timers/Kconfig | 7 +++++++ drivers/timers/mcp794xx.c | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/timers/Kconfig b/drivers/timers/Kconfig index 37a8561c8ae55..0fd4074727aef 100644 --- a/drivers/timers/Kconfig +++ b/drivers/timers/Kconfig @@ -339,6 +339,13 @@ config RTC_MCP794XX if RTC_MCP794XX +config MCP794XX_DATETIME_UTC + bool "Store datetime in UTC" + default n + ---help--- + If set, the datetime is stored in UTC timezone instead of timezone + defined by local time. + config MCP794XX_I2C_FREQUENCY int "MCP794XX I2C frequency" default 400000 diff --git a/drivers/timers/mcp794xx.c b/drivers/timers/mcp794xx.c index 71881a9d432f0..54953a0c735d3 100644 --- a/drivers/timers/mcp794xx.c +++ b/drivers/timers/mcp794xx.c @@ -407,11 +407,23 @@ int up_rtc_settime(FAR const struct timespec *tp) newtime++; } +#ifndef CONFIG_MCP794XX_DATETIME_UTC + /* Save datetime in local time. */ + if (localtime_r(&newtime, &newtm) == NULL) { rtcerr("ERROR: localtime_r failed\n"); return -EINVAL; } +#else + /* Save datetime in UTC time. */ + + if (gmtime_r(&newtime, &newtm) == NULL) + { + rtcerr("ERROR: gmtime_r failed\n"); + return -EINVAL; + } +#endif rtc_dumptime(&newtm, "New time");