mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-13 05:53:06 +01:00
Use I2C FRAM module if available to store page voltage state
This commit is contained in:
@@ -61,6 +61,10 @@ GxEPD2_BW<GxEPD2_420_SE0420NQ04, GxEPD2_420_SE0420NQ04::HEIGHT> & getdisplay(){r
|
||||
// Horter I2C moduls
|
||||
PCF8574 pcf8574_Out(PCF8574_I2C_ADDR1); // First digital output modul PCF8574 from Horter
|
||||
|
||||
// FRAM
|
||||
Adafruit_FRAM_I2C fram;
|
||||
bool hasFRAM = false;
|
||||
|
||||
// Global vars
|
||||
bool blinkingLED = false; // Enable / disable blinking flash LED
|
||||
bool statusLED = false; // Actual status of flash LED on/off
|
||||
@@ -70,7 +74,7 @@ int uvDuration = 0; // Under voltage duration in n x 100ms
|
||||
|
||||
LedTaskData *ledTaskData=nullptr;
|
||||
|
||||
void hardwareInit()
|
||||
void hardwareInit(GwApi *api)
|
||||
{
|
||||
Wire.begin();
|
||||
// Init PCF8574 digital outputs
|
||||
@@ -78,7 +82,27 @@ void hardwareInit()
|
||||
if(pcf8574_Out.begin()){ // Initialize PCF8574
|
||||
pcf8574_Out.write8(255); // Clear all outputs
|
||||
}
|
||||
|
||||
fram = Adafruit_FRAM_I2C();
|
||||
if (esp_reset_reason() == ESP_RST_POWERON) {
|
||||
// help initialize FRAM
|
||||
api->getLogger()->logDebug(GwLog::LOG,"Delaying I2C init for 250ms due to cold boot");
|
||||
delay(250);
|
||||
}
|
||||
// FRAM (e.g. MB85RC256V)
|
||||
if (fram.begin(FRAM_I2C_ADDR)) {
|
||||
hasFRAM = true;
|
||||
uint16_t manufacturerID;
|
||||
uint16_t productID;
|
||||
fram.getDeviceID(&manufacturerID, &productID);
|
||||
// Boot counter
|
||||
uint8_t framcounter = fram.read(0x0000);
|
||||
fram.write(0x0000, framcounter+1);
|
||||
api->getLogger()->logDebug(GwLog::LOG,"FRAM detected: 0x%04x/0x%04x (counter=%d)", manufacturerID, productID, framcounter);
|
||||
}
|
||||
else {
|
||||
hasFRAM = false;
|
||||
api->getLogger()->logDebug(GwLog::LOG,"NO FRAM detected");
|
||||
}
|
||||
}
|
||||
|
||||
void startLedTask(GwApi *api){
|
||||
|
||||
Reference in New Issue
Block a user