From e85874cccfb9c5dbb2ac26c75ee0fccfb3a3b5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Tue, 15 Aug 2023 22:11:47 +0200 Subject: [PATCH] Add functions to read and write the RAM byte --- esphome/components/pcf85063/pcf85063.cpp | 10 ++++++++++ esphome/components/pcf85063/pcf85063.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/esphome/components/pcf85063/pcf85063.cpp b/esphome/components/pcf85063/pcf85063.cpp index debc007..941278d 100644 --- a/esphome/components/pcf85063/pcf85063.cpp +++ b/esphome/components/pcf85063/pcf85063.cpp @@ -81,6 +81,16 @@ void PCF85063Component::write_time() { this->write_rtc_(); } +void PCF85063Component::write_nvram(uint8_t data) { + this->pcf85063_.reg.nvram = data; + this->write_bytes(0x03, &this->pcf85063_.raw[0x03], 1); +} + +uint8_t PCF85063Component::read_nvram() { + this->read_bytes(0x03, &this->pcf85063_.raw[0x03], 1); + return this->pcf85063_.reg.nvram; +} + bool PCF85063Component::read_rtc_() { if (!this->read_bytes(0, this->pcf85063_.raw, sizeof(this->pcf85063_.raw))) { ESP_LOGE(TAG, "Can't read I2C data."); diff --git a/esphome/components/pcf85063/pcf85063.h b/esphome/components/pcf85063/pcf85063.h index cbe9e2a..3d3589c 100644 --- a/esphome/components/pcf85063/pcf85063.h +++ b/esphome/components/pcf85063/pcf85063.h @@ -27,6 +27,8 @@ class PCF85063Component : public time::RealTimeClock, public i2c::I2CDevice { float get_setup_priority() const override; void read_time(); void write_time(); + void write_nvram(uint8_t); + uint8_t read_nvram(); protected: bool read_rtc_();