From b6f657f9fcbc4b851a1814cd5061b93b73a8a57a Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 25 Nov 2024 12:51:20 +0000 Subject: [PATCH] pcf85063a: Set PICO_INCLUDE_RTC_DATETIME. And remove set_datetime and get_datetime gracefully when it's not set. This is a temporary work-around for RP2350 lacking an RTC and not requiring the datetime_t type. These functions should be re-implemented in terms of C standards. --- drivers/pcf85063a/pcf85063a.cmake | 6 +++++- drivers/pcf85063a/pcf85063a.cpp | 4 ++++ drivers/pcf85063a/pcf85063a.hpp | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pcf85063a/pcf85063a.cmake b/drivers/pcf85063a/pcf85063a.cmake index e2382cc9..c5c05a44 100644 --- a/drivers/pcf85063a/pcf85063a.cmake +++ b/drivers/pcf85063a/pcf85063a.cmake @@ -6,5 +6,9 @@ target_sources(${DRIVER_NAME} INTERFACE target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) +# Include datetime_t for cross-compatibility with RP2350 (no RTC) boards +# TODO: We should migrate away from using this non-standard type +target_compile_definitions(${DRIVER_NAME} INTERFACE PICO_INCLUDE_RTC_DATETIME=1) + # Pull in pico libraries that we need -target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_i2c pimoroni_i2c) +target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib pico_util hardware_i2c pimoroni_i2c) diff --git a/drivers/pcf85063a/pcf85063a.cpp b/drivers/pcf85063a/pcf85063a.cpp index 6a87c82d..8afe6cf1 100644 --- a/drivers/pcf85063a/pcf85063a.cpp +++ b/drivers/pcf85063a/pcf85063a.cpp @@ -53,6 +53,8 @@ namespace pimoroni { return interrupt; } +#if PICO_INCLUDE_RTC_DATETIME + datetime_t PCF85063A::get_datetime() { uint8_t result[7] = {0}; @@ -85,6 +87,8 @@ namespace pimoroni { i2c->write_bytes(address, Registers::SECONDS, data, 7); } +#endif + void PCF85063A::set_alarm(int second, int minute, int hour, int day) { uint8_t alarm[5] = { uint8_t(second != PARAM_UNUSED ? bcd_encode(second) : 0x80), diff --git a/drivers/pcf85063a/pcf85063a.hpp b/drivers/pcf85063a/pcf85063a.hpp index 12bf7450..647324bd 100644 --- a/drivers/pcf85063a/pcf85063a.hpp +++ b/drivers/pcf85063a/pcf85063a.hpp @@ -108,10 +108,12 @@ namespace pimoroni { int get_scl() const; int get_int() const; +#if PICO_INCLUDE_RTC_DATETIME // Set and get the date and time // Uses datetime_t from pico sdk (hardware/rtc) for compatibility datetime_t get_datetime(); void set_datetime(datetime_t *t); +#endif // Alarm manipulation methods void set_alarm(int second = PARAM_UNUSED, int minute = PARAM_UNUSED,