From b0a26486c36a21d52df34ddc183497d467c49618 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 16 Apr 2022 17:43:10 +0200 Subject: [PATCH] Prep RTC chip memory use if present --- tasmota/my_user_config.h | 9 ++--- tasmota/tasmota_configurations.h | 8 +++-- tasmota/tasmota_configurations_ESP32.h | 18 ++++++---- tasmota/xdrv_56_rtc_chips.ino | 50 +++++++++++++++++++++++--- 4 files changed, 68 insertions(+), 17 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index ff9a11c26..f7c1d6368 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -613,8 +613,6 @@ // #define USE_CCS811_V2 // [I2cDriver24] Enable CCS811 sensor (I2C addresses 0x5A and 0x5B) (+2k8 code) // #define USE_MPU6050 // [I2cDriver25] Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+3K3 of code and 188 Bytes of RAM) // #define USE_MPU6050_DMP // Enable in MPU6050 to use the DMP on the chip, should create better results (+8k6 of code) -// #define USE_DS3231 // [I2cDriver26] Enable DS3231 external RTC in case no Wi-Fi is avaliable. See docs in the source file (+1k2 code) -// #define DS3231_ADDRESS 0x68 // Default I2C address 0x68 // #define USE_MGC3130 // [I2cDriver27] Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem) // #define USE_MAX44009 // [I2cDriver28] Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code) // #define USE_SCD30 // [I2cDriver29] Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code) @@ -665,7 +663,6 @@ // #define USE_EZOPMP // [I2cDriver55] Enable support for EZO's PMP sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code) // #define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code) // #define USE_MPU_ACCEL // [I2cDriver58] Enable MPU6886/MPU9250 - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x68) (+2k code) -// #define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2k5 code) // #define USE_AM2320 // [I2cDriver60] Enable AM2320 temperature and humidity Sensor (I2C address 0x5C) (+1k code) // #define USE_T67XX // [I2cDriver61] Enable Telaire T67XX CO2 sensor (I2C address 0x15) (+1k3 code) // #define USE_HM330X // [I2cDriver63] Enable support for SeedStudio Grove Particule sensor (I2C address 0x40) (+1k5 code) @@ -673,9 +670,13 @@ // #define HM330X_WARMUP_DELAY 30 // Option: change warmup delay during which data are not read from sensor after a power up // #define HM330X_HIDE_OUT_OF_DATE false // Option: change to true to hide data from web GUI and SENSOR while sensor is asleep // #define USE_HDC2010 // [I2cDriver64] Enable HDC2010 temperature/humidity sensor (I2C address 0x40) (+1k5 code) -// #define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC (I2C address 0x51) (+0k7 code) // #define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code) +// #define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one +// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code) +// #define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2.5k code) +// #define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC - found Shelly 3EM (I2C address 0x51) (+0k7 code) + // #define USE_DISPLAY // Add I2C Display Support (+2k code) #define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0 #define USE_DISPLAY_LCD // [DisplayModel 1] [I2cDriver3] Enable Lcd display (I2C addresses 0x27 and 0x3F) (+6k code) diff --git a/tasmota/tasmota_configurations.h b/tasmota/tasmota_configurations.h index 7da082738..d97569395 100644 --- a/tasmota/tasmota_configurations.h +++ b/tasmota/tasmota_configurations.h @@ -103,7 +103,6 @@ #define USE_CCS811 // [I2cDriver24] Enable CCS811 sensor (I2C address 0x5A) (+2k2 code) //#define USE_CCS811_V2 // [I2cDriver24] Enable CCS811 sensor (I2C addresses 0x5A and 0x5B) (+2k8 code) //#define USE_MPU6050 // [I2cDriver25] Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+3K3 of code and 188 Bytes of RAM) -//#define USE_DS3231 // [I2cDriver26] Enable DS3231 external RTC in case no Wifi is avaliable. See docs in the source file (+1k2 code) //#define USE_MGC3130 // [I2cDriver27] Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem) //#define USE_MAX44009 // [I2cDriver28] Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code) #define USE_SCD30 // [I2cDriver29] Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code) @@ -146,13 +145,16 @@ //#define USE_EZOPMP // [I2cDriver55] Enable support for EZO's PMP sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code) //#define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code) //#define USE_MPU_ACCEL // [I2cDriver58] Enable MPU6886/MPU9250 - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x68) (+2k code) -//#define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2k5 code) //#define USE_AM2320 // [I2cDriver60] Enable AM2320 temperature and humidity Sensor (I2C address 0x5C) (+1k code) //#define USE_T67XX // [I2cDriver61] Enable Telaire T67XX CO2 sensor (I2C address 0x15) (+1k3 code) //#define USE_HDC2010 // [I2cDriver64] Enable HDC2010 temperature/humidity sensor (I2C address 0x40) (+1k5 code) -//#define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC (I2C address 0x51) (+0k7 code) //#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code) +//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one +// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code) +// #define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2.5k code) +// #define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC - found Shelly 3EM (I2C address 0x51) (+0k7 code) + //#define USE_SPI // Hardware SPI using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK) in addition to two user selectable GPIOs(CS and DC) //#define USE_RC522 // Add support for MFRC522 13.56Mhz Rfid reader (+6k code) diff --git a/tasmota/tasmota_configurations_ESP32.h b/tasmota/tasmota_configurations_ESP32.h index d0b8a0d3e..c6234dd8e 100644 --- a/tasmota/tasmota_configurations_ESP32.h +++ b/tasmota/tasmota_configurations_ESP32.h @@ -123,7 +123,8 @@ #define USE_XPT2046 #define USE_FT5206 #define USE_MPU_ACCEL -#define USE_BM8563 +#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one + #define USE_BM8563 #define USE_MLX90614 #define USE_UNIVERSAL_DISPLAY #define USE_DISPLAY_LVGL_ONLY @@ -197,7 +198,6 @@ //#define USE_CCS811 // [I2cDriver24] Enable CCS811 sensor (I2C address 0x5A) (+2k2 code) //#define USE_CCS811_V2 // [I2cDriver24] Enable CCS811 sensor (I2C addresses 0x5A and 0x5B) (+2k8 code) //#define USE_MPU6050 // [I2cDriver25] Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+3K3 of code and 188 Bytes of RAM) -//#define USE_DS3231 // [I2cDriver26] Enable DS3231 external RTC in case no Wifi is avaliable. See docs in the source file (+1k2 code) //#define USE_MGC3130 // [I2cDriver27] Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem) //#define USE_MAX44009 // [I2cDriver28] Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code) //#define USE_SCD30 // [I2cDriver29] Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code) @@ -239,12 +239,15 @@ //#define USE_EZOPMP // [I2cDriver55] Enable support for EZO's PMP sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code) //#define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code) //#define USE_MPU_ACCEL // [I2cDriver58] Enable MPU6886/MPU9250 - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x68) (+2k code) -//#define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2k5 code) //#define USE_AM2320 // [I2cDriver60] Enable AM2320 temperature and humidity Sensor (I2C address 0x5C) (+1k code) //#define USE_T67XX // [I2cDriver61] Enable Telaire T67XX CO2 sensor (I2C address 0x15) (+1k3 code) -//#define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC (I2C address 0x51) (+0k7 code) //#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code) +//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one +// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code) +// #define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2.5k code) +// #define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC - found Shelly 3EM (I2C address 0x51) (+0k7 code) + //#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code) //#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code) //#define USE_CM110x // Add support for CM110x CO2 sensors (+2k7 code) @@ -337,7 +340,6 @@ #define USE_CCS811_V2 // [I2cDriver24] Enable CCS811 sensor (I2C addresses 0x5A and 0x5B) (+2k8 code) #define USE_MPU_ACCEL // [I2cDriver58] Enable MPU6886, MPU9250 6-axis MotionTracking sensor (I2C address 0x68) //#define USE_MPU6050 // [I2cDriver25] Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+3K3 of code and 188 Bytes of RAM) -//#define USE_DS3231 // [I2cDriver26] Enable DS3231 external RTC in case no Wifi is avaliable. See docs in the source file (+1k2 code) //#define USE_MGC3130 // [I2cDriver27] Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem) //#define USE_MAX44009 // [I2cDriver28] Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code) #define USE_SCD30 // [I2cDriver29] Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code) @@ -378,9 +380,13 @@ //#define USE_EZORGB // [I2cDriver55] Enable support for EZO's RGB sensor (+0k5 code) - Shared EZO code required for any EZO device (+1k2 code) //#define USE_EZOPMP // [I2cDriver55] Enable support for EZO's PMP sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code) //#define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code) -//#define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC (I2C address 0x51) (+0k7 code) //#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code) +//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one +// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code) +// #define USE_BM8563 // [I2cDriver59] Enable BM8563 RTC - found in M5Stack - support both I2C buses on ESP32 (I2C address 0x51) (+2.5k code) +// #define USE_PCF85363 // [I2cDriver66] Enable PCF85363 RTC - found Shelly 3EM (I2C address 0x51) (+0k7 code) + #define USE_SPI // Hardware SPI using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK) in addition to two user selectable GPIOs(CS and DC) //#define USE_RC522 // Add support for MFRC522 13.56Mhz Rfid reader (+6k code) diff --git a/tasmota/xdrv_56_rtc_chips.ino b/tasmota/xdrv_56_rtc_chips.ino index d4f54f6c2..ac3c31c2d 100644 --- a/tasmota/xdrv_56_rtc_chips.ino +++ b/tasmota/xdrv_56_rtc_chips.ino @@ -6,8 +6,6 @@ SPDX-License-Identifier: GPL-3.0-only */ -#define USE_RTC_CHIPS - #ifdef USE_I2C #ifdef USE_RTC_CHIPS /*********************************************************************************************\ @@ -23,7 +21,10 @@ struct { uint32_t (* ReadTime)(void); void (* SetTime)(uint32_t); + int32_t (* MemRead)(uint8_t *, uint32_t); + int32_t (* MemWrite)(uint8_t *, uint32_t); bool detected; + int8_t mem_size = -1; uint8_t address; uint8_t bus; char name[10]; @@ -38,9 +39,7 @@ struct { #define XI2C_26 26 // See I2CDEVICES.md -#ifndef DS3231_ADDRESS #define DS3231_ADDRESS 0x68 // DS3231 I2C Address -#endif // DS3231 Register Addresses #define DS3231_SECONDS 0x00 @@ -98,6 +97,9 @@ void DS3231SetTime(uint32_t epoch_time) { I2cWrite8(RtcChip.address, DS3231_STATUS, I2cRead8(RtcChip.address, DS3231_STATUS) & ~_BV(DS3231_OSF)); // Clear the Oscillator Stop Flag } +/*-------------------------------------------------------------------------------------------*\ + * Detection +\*-------------------------------------------------------------------------------------------*/ void DS3231Detected(void) { if (!RtcChip.detected && I2cEnabled(XI2C_26)) { RtcChip.address = DS3231_ADDRESS; @@ -107,6 +109,7 @@ void DS3231Detected(void) { strcpy_P(RtcChip.name, PSTR("DS3231")); RtcChip.ReadTime = &DS3231ReadTime; RtcChip.SetTime = &DS3231SetTime; + RtcChip.mem_size = -1; } } } @@ -164,6 +167,9 @@ void BM8563SetUtc(uint32_t epoch_time) { bm8563_driver.Rtc.SetDate(&RTCdate); } +/*-------------------------------------------------------------------------------------------*\ + * Detection +\*-------------------------------------------------------------------------------------------*/ void BM8563Detected(void) { if (!RtcChip.detected && I2cEnabled(XI2C_59)) { RtcChip.address = BM8563_ADRESS; @@ -182,6 +188,7 @@ void BM8563Detected(void) { strcpy_P(RtcChip.name, PSTR("BM8563")); RtcChip.ReadTime = &BM8563GetUtc; RtcChip.SetTime = &BM8563SetUtc; + RtcChip.mem_size = -1; } } } @@ -289,6 +296,20 @@ void Pcf85363Dump(void) { } */ +/*-------------------------------------------------------------------------------------------*\ + * Memory block functions +\*-------------------------------------------------------------------------------------------*/ +int32_t Pcf8563MemRead(uint8_t *buffer, uint32_t size) { + return I2cReadBuffer(RtcChip.address, 0x40, buffer, size); +} + +int32_t Pcf8563MemWrite(uint8_t *buffer, uint32_t size) { + return I2cWriteBuffer(RtcChip.address, 0x40, (uint8_t *)buffer, size); +} + +/*-------------------------------------------------------------------------------------------*\ + * Detection +\*-------------------------------------------------------------------------------------------*/ void Pcf85363Detected(void) { if (!RtcChip.detected && I2cEnabled(XI2C_66)) { RtcChip.address = PCF85363_ADDRESS; @@ -297,6 +318,9 @@ void Pcf85363Detected(void) { strcpy_P(RtcChip.name, PSTR("PCF85363")); RtcChip.ReadTime = &Pcf85363ReadTime; RtcChip.SetTime = &Pcf85363SetTime; + RtcChip.mem_size = 64; + RtcChip.MemRead = &Pcf8563MemRead; + RtcChip.MemWrite = &Pcf8563MemWrite; } } } @@ -341,6 +365,24 @@ void RtcChipTimeSynced(void) { } } +int32_t RtcChipMemSize(void) { + return RtcChip.mem_size; // Not supported or max size +} + +int32_t RtcChipMemRead(uint8_t *buffer, uint32_t size) { + if (size <= RtcChip.mem_size) { + return RtcChip.MemRead(buffer, size); + } + return -1; // Not supported or too large +} + +int32_t RtcChipMemWrite(uint8_t *buffer, uint32_t size) { + if (size <= RtcChip.mem_size) { + return RtcChip.MemWrite(buffer, size); + } + return -1; // Not supported or too large +} + /*********************************************************************************************\ * NTP server functions \*********************************************************************************************/