diff --git a/.github/workflows/release-offline.yml b/.github/workflows/release-offline.yml index b429ddddc..8e3c8808d 100644 --- a/.github/workflows/release-offline.yml +++ b/.github/workflows/release-offline.yml @@ -7,6 +7,9 @@ on: branches: - offline-mode - offline-mode-* + pull_request: + branches: + - offline-mode release: types: [published] branches: diff --git a/src/components/i2c/controller.cpp b/src/components/i2c/controller.cpp index 1eaf24238..6f3e02959 100644 --- a/src/components/i2c/controller.cpp +++ b/src/components/i2c/controller.cpp @@ -862,11 +862,39 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) { */ /***********************************************************************/ bool I2cController::ScanI2cBus(bool default_bus = true) { - _i2c_bus_default->InitBus(default_bus); + // zero-out the scan I2cBusScanned message before attempting a scan _scan_results = wippersnapper_i2c_I2cBusScanned_init_zero; - if (!default_bus) + + // Scan the desired i2c bus + if (default_bus) { + if (_i2c_bus_default->GetBusStatus() != + wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_SUCCESS) { + _i2c_bus_default->InitBus(default_bus); + } + return _i2c_bus_default->ScanBus(&_scan_results); + } else { + if (_i2c_bus_alt->GetBusStatus() != + wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_SUCCESS) { + _i2c_bus_alt->InitBus(default_bus); + } return _i2c_bus_alt->ScanBus(&_scan_results); - return _i2c_bus_default->ScanBus(&_scan_results); + } +} + +/***********************************************************************/ +/*! + @brief Returns the I2C bus object. + @param is_alt_bus + True if the alternative I2C bus is being used, False + otherwise. + @returns A pointer to the I2C bus object. +*/ +/***********************************************************************/ +TwoWire *I2cController::GetI2cBus(bool is_alt_bus) { + if (is_alt_bus) { + return _i2c_bus_alt->GetBus(); + } + return _i2c_bus_default->GetBus(); } /***********************************************************************/ diff --git a/src/components/i2c/controller.h b/src/components/i2c/controller.h index 04e4b4662..5e7b28bb2 100644 --- a/src/components/i2c/controller.h +++ b/src/components/i2c/controller.h @@ -109,6 +109,7 @@ class I2cController { size_t GetScanDeviceCount(); bool IsDriverInitialized(wippersnapper_i2c_I2cDeviceDescriptor &device_descriptor); + TwoWire *GetI2cBus(bool is_alt_bus = false); private: I2cModel *_i2c_model; ///< Pointer to an I2C model object diff --git a/src/provisioning/sdcard/ws_sdcard.cpp b/src/provisioning/sdcard/ws_sdcard.cpp index 45f04e278..82a3913d4 100644 --- a/src/provisioning/sdcard/ws_sdcard.cpp +++ b/src/provisioning/sdcard/ws_sdcard.cpp @@ -7,7 +7,7 @@ * please support Adafruit and open-source hardware by purchasing * products from Adafruit! * - * Copyright (c) Brent Rubell 2024 for Adafruit Industries. + * Copyright (c) Brent Rubell 2024-2025 for Adafruit Industries. * * BSD license, all text here must be included in any redistribution. * @@ -121,9 +121,10 @@ void ws_sdcard::ConfigureSDCard() { /**************************************************************************/ bool ws_sdcard::InitDS1307() { _rtc_ds1307 = new RTC_DS1307(); - if (!_rtc_ds1307->begin()) { - if (!_rtc_ds1307->begin(&Wire1)) { - WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS1307 RTC"); + if (!_rtc_ds1307->begin(WsV2._i2c_controller->GetI2cBus())) { + WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS1307 RTC on WIRE"); + if (!_rtc_ds1307->begin(WsV2._i2c_controller->GetI2cBus(true))) { + WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS1307 RTC on WIRE1"); delete _rtc_ds1307; return false; } @@ -144,9 +145,10 @@ bool ws_sdcard::InitDS1307() { bool ws_sdcard::InitDS3231() { WS_DEBUG_PRINTLN("Begin DS3231 init"); _rtc_ds3231 = new RTC_DS3231(); - if (!_rtc_ds3231->begin(&Wire)) { - if (!_rtc_ds3231->begin(&Wire1)) { - WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS3231 RTC"); + if (!_rtc_ds3231->begin(WsV2._i2c_controller->GetI2cBus())) { + WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS3231 RTC on WIRE"); + if (!_rtc_ds3231->begin(WsV2._i2c_controller->GetI2cBus(true))) { + WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS3231 RTC on WIRE1"); delete _rtc_ds3231; return false; } @@ -166,9 +168,9 @@ bool ws_sdcard::InitDS3231() { /**************************************************************************/ bool ws_sdcard::InitPCF8523() { _rtc_pcf8523 = new RTC_PCF8523(); - if (!_rtc_pcf8523->begin(&Wire)) { + if (!_rtc_pcf8523->begin(WsV2._i2c_controller->GetI2cBus())) { WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize PCF8523 RTC on WIRE"); - if (!_rtc_pcf8523->begin(&Wire1)) { + if (!_rtc_pcf8523->begin(WsV2._i2c_controller->GetI2cBus(true))) { WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize PCF8523 RTC on WIRE1"); delete _rtc_pcf8523; return false; @@ -701,6 +703,7 @@ bool ws_sdcard::ParseExportedFromDevice(JsonDocument &doc) { WS_DEBUG_PRINTLN("[SD] Error: Failed to to configure a RTC!"); return false; } + return true; } diff --git a/src/provisioning/tinyusb/Wippersnapper_FS.cpp b/src/provisioning/tinyusb/Wippersnapper_FS.cpp index c0398b02d..7f6daa614 100644 --- a/src/provisioning/tinyusb/Wippersnapper_FS.cpp +++ b/src/provisioning/tinyusb/Wippersnapper_FS.cpp @@ -381,13 +381,12 @@ void Wippersnapper_FS::CreateFileConfig() { File32 file_cfg = wipperFatFs_v2.open("/config.json", FILE_READ); if (file_cfg) { DeserializationError error = deserializeJson(_doc_cfg, file_cfg); - // if (error) - // HaltFilesystem("Error unable to parse config.json on WIPPER drive!"); - // Remove config from the filesystem + if (error) { + // If we can't deserialize, just raise + HaltFilesystem( + "[fs] Error: Unable to deserialize config.json, is it corrupted?"); + } file_cfg.close(); - wipperFatFs_v2.remove("/config.json"); - flash_v2.syncBlocks(); - // Check if the config.json file has the required keys if (!_doc_cfg.containsKey("exportedFromDevice")) { // Build exportedFromDevice object @@ -404,8 +403,10 @@ void Wippersnapper_FS::CreateFileConfig() { // Build components array _doc_cfg["components"].to(); } + return; } + file_cfg.close(); } // Create a default configConfig structure in a new doc @@ -472,6 +473,14 @@ void Wippersnapper_FS::AddI2cDeviceToFileConfig( */ /**************************************************************************/ bool Wippersnapper_FS::WriteFileConfig() { + // If it exists, remove the existing config.json file + // as we're about to write the new one into memory + if (wipperFatFs_v2.exists("/config.json")) { + wipperFatFs_v2.remove("/config.json"); + flash_v2.syncBlocks(); + delay(500); + } + // Write the document to the filesystem File32 file_cfg = wipperFatFs_v2.open("/config.json", FILE_WRITE); if (!file_cfg) {