From e5e17e9ff6c5858e9ea4ff40bc719820cda7e3b1 Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Mon, 17 Jun 2024 12:50:28 -0700 Subject: [PATCH 01/12] Added beginning of webconfig-side I2C bus scanning. Added experimental wrapper class for ADS1219 to handle device auto-detection. --- CMakeLists.txt | 1 + headers/addons/i2canalog1219.h | 4 ++-- headers/interfaces/i2c/ads1219/ads1219_dev.h | 19 +++++++++++++++++++ lib/PicoPeripherals/peripheral_i2c.cpp | 18 ++++++++++++++++++ lib/PicoPeripherals/peripheral_i2c.h | 3 +++ src/addons/i2canalog1219.cpp | 2 +- 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 headers/interfaces/i2c/ads1219/ads1219_dev.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0455165e1..4ba060187 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,7 @@ headers/configs headers/drivers headers/interfaces headers/interfaces/i2c +headers/interfaces/i2c/ads1219 headers/interfaces/i2c/pcf8575 headers/interfaces/i2c/ssd1306 headers/gamepad diff --git a/headers/addons/i2canalog1219.h b/headers/addons/i2canalog1219.h index f411dc1f3..b2132b3a6 100644 --- a/headers/addons/i2canalog1219.h +++ b/headers/addons/i2canalog1219.h @@ -1,7 +1,7 @@ #ifndef _I2CAnalog_H #define _I2CAnalog_H -#include +#include "ads1219_dev.h" #include "gpaddon.h" @@ -47,7 +47,7 @@ class I2CAnalog1219Input : public GPAddon { virtual void process(); // Analog Process virtual std::string name() { return I2CAnalog1219Name; } private: - ADS1219 * ads; + ADS1219Device * ads; ADS_PINS pins; int channelHop; uint32_t uIntervalMS; // ADS1219 Interval diff --git a/headers/interfaces/i2c/ads1219/ads1219_dev.h b/headers/interfaces/i2c/ads1219/ads1219_dev.h new file mode 100644 index 000000000..fcf00d28a --- /dev/null +++ b/headers/interfaces/i2c/ads1219/ads1219_dev.h @@ -0,0 +1,19 @@ +#ifndef _ADS1219DEVICE_H_ +#define _ADS1219DEVICE_H_ + +#include + +#include "i2cdevicebase.h" +#include "ads1219.h" + +class ADS1219Device : public ADS1219, public I2CDeviceBase { + public: + // Constructor + ADS1219Device(PeripheralI2C *i2cController, uint8_t addr = 0x40) : ADS1219(i2cController, addr) {} + + std::vector getDeviceAddresses() const override { + return {0x40}; + } +}; + +#endif diff --git a/lib/PicoPeripherals/peripheral_i2c.cpp b/lib/PicoPeripherals/peripheral_i2c.cpp index 681bca6fb..1e93145ac 100644 --- a/lib/PicoPeripherals/peripheral_i2c.cpp +++ b/lib/PicoPeripherals/peripheral_i2c.cpp @@ -84,4 +84,22 @@ uint8_t PeripheralI2C::test(uint8_t address) { void PeripheralI2C::clear() { // reset the bus test(0xFF); +} + +std::map PeripheralI2C::scan() { + std::map result; + + for (uint8_t addr = 0; addr < (1 << 7); ++addr) { + int8_t ret; + uint8_t rxdata; + ret = i2c_read_blocking(_I2C, addr, &rxdata, 1, false); + + if (ret >= 0) { + result.insert({addr,(ret >= 0)}); + } + } + + printf("%d\n", result.size()); + + return result; } \ No newline at end of file diff --git a/lib/PicoPeripherals/peripheral_i2c.h b/lib/PicoPeripherals/peripheral_i2c.h index c999b6ed6..d5b91524a 100644 --- a/lib/PicoPeripherals/peripheral_i2c.h +++ b/lib/PicoPeripherals/peripheral_i2c.h @@ -1,6 +1,7 @@ #ifndef _PERIPHERAL_I2C_H_ #define _PERIPHERAL_I2C_H_ +#include #include #include #include @@ -57,6 +58,8 @@ class PeripheralI2C { uint8_t test(uint8_t address); void clear(); + + std::map scan(); private: const uint32_t DEFAULT_SPEED = 400000; diff --git a/src/addons/i2canalog1219.cpp b/src/addons/i2canalog1219.cpp index 355933850..38da0309d 100644 --- a/src/addons/i2canalog1219.cpp +++ b/src/addons/i2canalog1219.cpp @@ -22,7 +22,7 @@ void I2CAnalog1219Input::setup() { nextTimer = getMillis(); // Init our ADS1219 library - ads = new ADS1219(i2c, options.i2cAddress); + ads = new ADS1219Device(i2c, options.i2cAddress); ads->begin(); // setup I2C and chip start ads->setChannel(0); // Start on Channel 0 ads->setConversionMode(CONTINUOUS); // Read analog continuously From 1202d4aa1c72cffe20e8e3169b2e639edc25eb9b Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Mon, 17 Jun 2024 12:51:10 -0700 Subject: [PATCH 02/12] Added scanner to webconfig. --- src/configs/webconfig.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index 8dc0bc135..7143ad15a 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -5,6 +5,7 @@ #include "storagemanager.h" #include "configmanager.h" #include "layoutmanager.h" +#include "peripheralmanager.h" #include "AnimationStorage.hpp" #include "system.h" #include "config_utils.h" @@ -215,6 +216,8 @@ static int32_t cleanPin(int32_t pin) { return isValidPin(pin) ? pin : -1; } void WebConfig::setup() { rndis_init(); + + stdio_init_all(); } void WebConfig::loop() { @@ -1196,6 +1199,29 @@ std::string getPeripheralOptions() return serialize_json(doc); } +std::string getI2CPeripheralMap() { + DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN); + + PeripheralOptions& peripheralOptions = Storage::getInstance().getPeripheralOptions(); + + + if (peripheralOptions.blockI2C0.enabled && PeripheralManager::getInstance().isI2CEnabled(0)) { + std::map result = PeripheralManager::getInstance().getI2C(0)->scan(); + for (std::map::iterator it = result.begin(); it != result.end(); ++it) { + writeDoc(doc, "i2c0", std::to_string(it->first), it->second); + } + } + + if (peripheralOptions.blockI2C1.enabled && PeripheralManager::getInstance().isI2CEnabled(1)) { + std::map result = PeripheralManager::getInstance().getI2C(1)->scan(); + for (std::map::iterator it = result.begin(); it != result.end(); ++it) { + writeDoc(doc, "i2c1", std::to_string(it->first), it->second); + } + } + + return serialize_json(doc); +} + std::string setPeripheralOptions() { DynamicJsonDocument doc = get_post_data(); @@ -2180,6 +2206,7 @@ static const std::pair handlerFuncs[] = { "/api/setProfileOptions", setProfileOptions }, { "/api/setPeripheralOptions", setPeripheralOptions }, { "/api/getPeripheralOptions", getPeripheralOptions }, + { "/api/getI2CPeripheralMap", getI2CPeripheralMap }, { "/api/setExpansionPins", setExpansionPins }, { "/api/getExpansionPins", getExpansionPins }, { "/api/setKeyMappings", setKeyMappings }, From 5e778ccb14379291705bdfc84a85a21fa0cd88fb Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Mon, 17 Jun 2024 12:55:25 -0700 Subject: [PATCH 03/12] Case sensitivity fix --- headers/interfaces/i2c/ads1219/ads1219_dev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/headers/interfaces/i2c/ads1219/ads1219_dev.h b/headers/interfaces/i2c/ads1219/ads1219_dev.h index fcf00d28a..7d357fb52 100644 --- a/headers/interfaces/i2c/ads1219/ads1219_dev.h +++ b/headers/interfaces/i2c/ads1219/ads1219_dev.h @@ -4,7 +4,7 @@ #include #include "i2cdevicebase.h" -#include "ads1219.h" +#include "ADS1219.h" class ADS1219Device : public ADS1219, public I2CDeviceBase { public: From e2c5c03300619f5f490c4cd2c9e89675d213d4ba Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Mon, 17 Jun 2024 22:42:53 -0700 Subject: [PATCH 04/12] All current I2C addons except Display updated to do auto device detection rather than rely on I2C block options. Added address range to ADS1219 addon to allow scanning across full range. --- CMakeLists.txt | 1 + headers/addons/wiiext.h | 8 ++---- headers/interfaces/i2c/ads1219/ads1219_dev.h | 3 ++- headers/interfaces/i2c/i2cdevicebase.h | 4 --- headers/interfaces/i2c/pcf8575/pcf8575.h | 9 +++++-- .../i2c/wiiextension/wiiextension_dev.h | 20 ++++++++++++++ headers/peripheralmanager.h | 8 ++++++ lib/ADS1219/ADS1219.h | 13 +++++++--- lib/WiiExtension/WiiExtension.h | 11 ++++++-- src/addons/i2c_gpio_pcf8575.cpp | 17 ++++++------ src/addons/i2canalog1219.cpp | 15 ++++++++--- src/addons/wiiext.cpp | 25 +++++++++++------- src/configs/webconfig.cpp | 2 -- src/interfaces/i2c/i2cdevicebase.cpp | 12 --------- src/peripheralmanager.cpp | 26 +++++++++++++++++++ 15 files changed, 120 insertions(+), 54 deletions(-) create mode 100644 headers/interfaces/i2c/wiiextension/wiiextension_dev.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ba060187..4016b628d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,6 +266,7 @@ headers/interfaces/i2c headers/interfaces/i2c/ads1219 headers/interfaces/i2c/pcf8575 headers/interfaces/i2c/ssd1306 +headers/interfaces/i2c/wiiextension headers/gamepad headers/display headers/display/fonts diff --git a/headers/addons/wiiext.h b/headers/addons/wiiext.h index 56db630f3..b4f3a2535 100644 --- a/headers/addons/wiiext.h +++ b/headers/addons/wiiext.h @@ -13,7 +13,7 @@ #include "gamepad.h" #include "storagemanager.h" #include "peripheralmanager.h" -#include "WiiExtension.h" +#include "wiiextension_dev.h" // WiiExtension Module Name #define WiiExtensionName "WiiExtension" @@ -22,10 +22,6 @@ #define WII_EXTENSION_ENABLED 0 #endif -#ifndef WII_EXTENSION_I2C_ADDR -#define WII_EXTENSION_I2C_ADDR 0x52 -#endif - #ifndef WII_EXTENSION_I2C_SDA_PIN #define WII_EXTENSION_I2C_SDA_PIN -1 #endif @@ -90,7 +86,7 @@ class WiiExtensionInput : public GPAddon { virtual void preprocess() {} virtual std::string name() { return WiiExtensionName; } private: - WiiExtension * wii; + WiiExtensionDevice * wii; uint32_t uIntervalMS; uint32_t nextTimer; diff --git a/headers/interfaces/i2c/ads1219/ads1219_dev.h b/headers/interfaces/i2c/ads1219/ads1219_dev.h index 7d357fb52..36290de8f 100644 --- a/headers/interfaces/i2c/ads1219/ads1219_dev.h +++ b/headers/interfaces/i2c/ads1219/ads1219_dev.h @@ -9,10 +9,11 @@ class ADS1219Device : public ADS1219, public I2CDeviceBase { public: // Constructor + ADS1219Device() {} ADS1219Device(PeripheralI2C *i2cController, uint8_t addr = 0x40) : ADS1219(i2cController, addr) {} std::vector getDeviceAddresses() const override { - return {0x40}; + return {0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F}; } }; diff --git a/headers/interfaces/i2c/i2cdevicebase.h b/headers/interfaces/i2c/i2cdevicebase.h index 4c13e3485..84f928116 100644 --- a/headers/interfaces/i2c/i2cdevicebase.h +++ b/headers/interfaces/i2c/i2cdevicebase.h @@ -12,10 +12,6 @@ class I2CDeviceBase : public DeviceBase { ~I2CDeviceBase() {} virtual std::vector getDeviceAddresses() const = 0; - - int8_t scanForDevice(); - protected: - PeripheralI2C* i2c; }; #endif \ No newline at end of file diff --git a/headers/interfaces/i2c/pcf8575/pcf8575.h b/headers/interfaces/i2c/pcf8575/pcf8575.h index 2dd56886c..7aa9d21c6 100644 --- a/headers/interfaces/i2c/pcf8575/pcf8575.h +++ b/headers/interfaces/i2c/pcf8575/pcf8575.h @@ -14,6 +14,7 @@ class PCF8575 : public I2CDeviceBase { public: // Constructor + PCF8575() {} PCF8575(PeripheralI2C *i2cController, uint8_t addr = 0x20) { this->i2c = i2cController; this->address = addr; @@ -28,6 +29,9 @@ class PCF8575 : public I2CDeviceBase { void reset(); //void start(); + void setI2C(PeripheralI2C *i2cController) { this->i2c = i2cController; } + void setAddress(uint8_t addr) { this->address = addr; } + void send(uint16_t value); uint16_t receive(); @@ -35,14 +39,15 @@ class PCF8575 : public I2CDeviceBase { void setPin(uint8_t pinNumber, uint8_t value); bool getPin(uint8_t pinNumber); - protected: - uint8_t address; private: const uint16_t initialValue = 0xFFFF; uint8_t uc[128]; uint16_t dataSent; uint16_t dataReceived = initialValue; + protected: + PeripheralI2C* i2c = nullptr; + uint8_t address = 0; }; #endif diff --git a/headers/interfaces/i2c/wiiextension/wiiextension_dev.h b/headers/interfaces/i2c/wiiextension/wiiextension_dev.h new file mode 100644 index 000000000..e388337d4 --- /dev/null +++ b/headers/interfaces/i2c/wiiextension/wiiextension_dev.h @@ -0,0 +1,20 @@ +#ifndef _WIIEXTDEVICE_H_ +#define _WIIEXTDEVICE_H_ + +#include + +#include "i2cdevicebase.h" +#include + +class WiiExtensionDevice : public WiiExtension, public I2CDeviceBase { + public: + // Constructor + WiiExtensionDevice() {} + WiiExtensionDevice(PeripheralI2C *i2cController, uint8_t addr = WII_EXTENSION_I2C_ADDR) : WiiExtension(i2cController, addr) {} + + std::vector getDeviceAddresses() const override { + return {WII_EXTENSION_I2C_ADDR}; + } +}; + +#endif diff --git a/headers/peripheralmanager.h b/headers/peripheralmanager.h index 482a05401..c2a7358c4 100644 --- a/headers/peripheralmanager.h +++ b/headers/peripheralmanager.h @@ -4,9 +4,15 @@ #include "peripheral_i2c.h" #include "peripheral_spi.h" #include "peripheral_usb.h" +#include "i2cdevicebase.h" #define PMGR PeripheralManager::getInstance() +typedef struct { + int8_t address; + uint8_t block; +} PeripheralI2CScanResult; + class PeripheralManager { public: PeripheralManager(PeripheralManager const&) = delete; @@ -28,6 +34,8 @@ class PeripheralManager { bool isI2CEnabled(uint8_t block); bool isSPIEnabled(uint8_t block); bool isUSBEnabled(uint8_t block); + + PeripheralI2CScanResult scanForI2CDevice(std::vector addressList); private: PeripheralManager(){} diff --git a/lib/ADS1219/ADS1219.h b/lib/ADS1219/ADS1219.h index 251fc82de..14f96d832 100644 --- a/lib/ADS1219/ADS1219.h +++ b/lib/ADS1219/ADS1219.h @@ -77,8 +77,10 @@ typedef enum{ class ADS1219 { protected: uint8_t address; + PeripheralI2C* i2c; public: // Constructor + ADS1219() {} ADS1219(PeripheralI2C *i2cController, uint8_t addr = 0x40); // Methods @@ -97,14 +99,17 @@ class ADS1219 { void setChannel(int channel); void powerDown(); uint8_t readRegister(adsRegister_t reg); - void start(); + void start(); uint32_t readConversionResult(); + + void setI2C(PeripheralI2C *i2cController) { this->i2c = i2cController; } + void setAddress(uint8_t addr) { this->address = addr; } + private: void writeRegister(uint8_t data); - PeripheralI2C* i2c; - uint8_t config; - bool singleShot; + uint8_t config = 0x00; + bool singleShot = true; int data_ready; unsigned char uc[128]; }; diff --git a/lib/WiiExtension/WiiExtension.h b/lib/WiiExtension/WiiExtension.h index 914865cce..80a55860e 100644 --- a/lib/WiiExtension/WiiExtension.h +++ b/lib/WiiExtension/WiiExtension.h @@ -76,6 +76,10 @@ typedef enum { #define WII_EXTENSION_CALIBRATION true #endif +#ifndef WII_EXTENSION_I2C_ADDR +#define WII_EXTENSION_I2C_ADDR 0x52 +#endif + #define WII_ALARM_NUM 0 #define WII_ALARM_IRQ TIMER_IRQ_0 @@ -102,6 +106,7 @@ static volatile bool WiiExtension_alarmFired; class WiiExtension { protected: uint8_t address; + PeripheralI2C* i2c; public: int8_t extensionType = WII_EXTENSION_NONE; int8_t dataType = WII_DATA_TYPE_0; @@ -109,6 +114,7 @@ class WiiExtension { bool isReady = false; // Constructor + WiiExtension() {} WiiExtension(PeripheralI2C *i2cController, uint8_t addr); // Methods @@ -117,12 +123,13 @@ class WiiExtension { void start(); void poll(); + void setI2C(PeripheralI2C *i2cController) { this->i2c = i2cController; } + void setAddress(uint8_t addr) { this->address = addr; } + ExtensionBase* getController() { return extensionController; }; private: ExtensionBase *extensionController = NULL; - PeripheralI2C* i2c; - #if WII_EXTENSION_DEBUG==true uint8_t _lastRead[16] = {0xFF}; #endif diff --git a/src/addons/i2c_gpio_pcf8575.cpp b/src/addons/i2c_gpio_pcf8575.cpp index aeb2e2ff2..e86822d5a 100644 --- a/src/addons/i2c_gpio_pcf8575.cpp +++ b/src/addons/i2c_gpio_pcf8575.cpp @@ -6,17 +6,18 @@ bool PCF8575Addon::available() { const DisplayOptions& displayOptions = Storage::getInstance().getDisplayOptions(); const PCF8575Options& options = Storage::getInstance().getAddonOptions().pcf8575Options; - if (options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock)) { - if (displayOptions.enabled && (displayOptions.i2cBlock == options.i2cBlock)) { - return false; + if (options.enabled) { + pcf = new PCF8575(); + PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(pcf->getDeviceAddresses()); + if (result.address > -1) { + pcf->setAddress(result.address); + pcf->setI2C(PeripheralManager::getInstance().getI2C(result.block)); + return true; } else { - PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock); - pcf = new PCF8575(i2c); - return (pcf->scanForDevice() > -1); + delete pcf; } - } else { - return false; } + return false; } void PCF8575Addon::setup() { diff --git a/src/addons/i2canalog1219.cpp b/src/addons/i2canalog1219.cpp index 38da0309d..b7d823752 100644 --- a/src/addons/i2canalog1219.cpp +++ b/src/addons/i2canalog1219.cpp @@ -8,12 +8,22 @@ bool I2CAnalog1219Input::available() { const AnalogADS1219Options& options = Storage::getInstance().getAddonOptions().analogADS1219Options; - return (options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock)); + if (options.enabled) { + ads = new ADS1219Device(); + PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(ads->getDeviceAddresses()); + if (result.address > -1) { + ads->setAddress(result.address); + ads->setI2C(PeripheralManager::getInstance().getI2C(result.block)); + return true; + } else { + delete ads; + } + } + return false; } void I2CAnalog1219Input::setup() { const AnalogADS1219Options& options = Storage::getInstance().getAddonOptions().analogADS1219Options; - PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock); memset(&pins, 0, sizeof(ADS_PINS)); channelHop = 0; @@ -22,7 +32,6 @@ void I2CAnalog1219Input::setup() { nextTimer = getMillis(); // Init our ADS1219 library - ads = new ADS1219Device(i2c, options.i2cAddress); ads->begin(); // setup I2C and chip start ads->setChannel(0); // Start on Channel 0 ads->setConversionMode(CONTINUOUS); // Read analog continuously diff --git a/src/addons/wiiext.cpp b/src/addons/wiiext.cpp index 64099ceb2..c86c8adeb 100644 --- a/src/addons/wiiext.cpp +++ b/src/addons/wiiext.cpp @@ -6,19 +6,24 @@ #include "config.pb.h" bool WiiExtensionInput::available() { - const DisplayOptions& displayOptions = Storage::getInstance().getDisplayOptions(); const WiiOptions& options = Storage::getInstance().getAddonOptions().wiiOptions; - bool result = (options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock)); - if (result && (displayOptions.enabled && (displayOptions.i2cBlock == options.i2cBlock))) { - // display check - result = false; + if (options.enabled) { + // addon is enabled. let's scan available blocks. + wii = new WiiExtensionDevice(); + PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(wii->getDeviceAddresses()); + if (result.address > -1) { + wii->setAddress(result.address); + wii->setI2C(PeripheralManager::getInstance().getI2C(result.block)); + return true; + } else { + delete wii; + } } - return result; + return false; } void WiiExtensionInput::setup() { const WiiOptions& options = Storage::getInstance().getAddonOptions().wiiOptions; - PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock); nextTimer = getMillis(); #if WII_EXTENSION_DEBUG==true @@ -29,9 +34,9 @@ void WiiExtensionInput::setup() { currentConfig = NULL; - wii = new WiiExtension( - i2c, - WII_EXTENSION_I2C_ADDR); + //wii = new WiiExtensionDevice( + // i2c, + // WII_EXTENSION_I2C_ADDR); wii->begin(); wii->start(); diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index 7143ad15a..2ec26e523 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -216,8 +216,6 @@ static int32_t cleanPin(int32_t pin) { return isValidPin(pin) ? pin : -1; } void WebConfig::setup() { rndis_init(); - - stdio_init_all(); } void WebConfig::loop() { diff --git a/src/interfaces/i2c/i2cdevicebase.cpp b/src/interfaces/i2c/i2cdevicebase.cpp index 02d2f4c2b..d340d5b38 100644 --- a/src/interfaces/i2c/i2cdevicebase.cpp +++ b/src/interfaces/i2c/i2cdevicebase.cpp @@ -1,14 +1,2 @@ #include #include "i2cdevicebase.h" - -int8_t I2CDeviceBase::scanForDevice() { - if (i2c != nullptr) { - std::vector addressList = getDeviceAddresses(); - for (uint8_t i = 0; i < addressList.size(); i++) { - uint8_t result = i2c->test(addressList[i]); - - if (result) return addressList[i]; - } - } - return -1; -} \ No newline at end of file diff --git a/src/peripheralmanager.cpp b/src/peripheralmanager.cpp index 1c4663cba..4ec17befa 100644 --- a/src/peripheralmanager.cpp +++ b/src/peripheralmanager.cpp @@ -59,3 +59,29 @@ bool PeripheralManager::isUSBEnabled(uint8_t block) { } return false; } + +PeripheralI2CScanResult PeripheralManager::scanForI2CDevice(std::vector addressList) { + PeripheralI2CScanResult scanResult = { + .address = -1, + .block = 0 + }; + + for (uint8_t block = 0; block < NUM_I2CS; block++) { + if (isI2CEnabled(block)) { + PeripheralI2C* i2c = getI2C(block); + + for (uint8_t i = 0; i < addressList.size(); i++) { + if (!((addressList[i] & 0x78) == 0 || (addressList[i] & 0x78) == 0x78)) { + uint8_t result = i2c->test(addressList[i]); + + if (result) { + scanResult.address = addressList[i]; + scanResult.block = block; + return scanResult; + } + } + } + } + } + return scanResult; +} \ No newline at end of file From c1b1c7dd9b544a5414d8178b6a215003d7d0d54f Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Tue, 18 Jun 2024 18:54:03 -0700 Subject: [PATCH 05/12] Fixed I2C/USB peripheral configuration check to reject negative pin values. --- lib/PicoPeripherals/peripheral_i2c.cpp | 4 ++-- lib/PicoPeripherals/peripheral_i2c.h | 2 +- lib/PicoPeripherals/peripheral_usb.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/PicoPeripherals/peripheral_i2c.cpp b/lib/PicoPeripherals/peripheral_i2c.cpp index 1e93145ac..a82ba566e 100644 --- a/lib/PicoPeripherals/peripheral_i2c.cpp +++ b/lib/PicoPeripherals/peripheral_i2c.cpp @@ -10,8 +10,8 @@ PeripheralI2C::PeripheralI2C() { #endif } -void PeripheralI2C::setConfig(uint8_t block, uint8_t sda, uint8_t scl, uint32_t speed) { - if (block < NUM_I2CS) { +void PeripheralI2C::setConfig(uint8_t block, int8_t sda, int8_t scl, uint32_t speed) { + if ((block < NUM_I2CS) && (sda > -1) && (scl > -1)) { _I2C = _hardwareBlocks[block]; _SDA = sda; _SCL = scl; diff --git a/lib/PicoPeripherals/peripheral_i2c.h b/lib/PicoPeripherals/peripheral_i2c.h index d5b91524a..e1569bcbe 100644 --- a/lib/PicoPeripherals/peripheral_i2c.h +++ b/lib/PicoPeripherals/peripheral_i2c.h @@ -49,7 +49,7 @@ class PeripheralI2C { i2c_inst_t* getController() { return _I2C; } - void setConfig(uint8_t block, uint8_t sda, uint8_t scl, uint32_t speed); + void setConfig(uint8_t block, int8_t sda, int8_t scl, uint32_t speed); int16_t read(uint8_t address, uint8_t *data, uint16_t len, bool isBlock=false); int16_t readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len); diff --git a/lib/PicoPeripherals/peripheral_usb.cpp b/lib/PicoPeripherals/peripheral_usb.cpp index 3dcd9dbcf..53242ef5f 100644 --- a/lib/PicoPeripherals/peripheral_usb.cpp +++ b/lib/PicoPeripherals/peripheral_usb.cpp @@ -20,7 +20,7 @@ void PeripheralUSB::setConfig(uint8_t block, int8_t dp, int8_t enable5v, uint8_t } void PeripheralUSB::setup() { - if (_DP != -1) { + if (_DP > -1) { if (_Enable5v != -1) { // Feather USB-A's require this gpio_init(_Enable5v); gpio_set_dir(_Enable5v, GPIO_IN); From da4ea4dcabd126524390b0158a38da200ae0ace1 Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Tue, 18 Jun 2024 19:04:05 -0700 Subject: [PATCH 06/12] Added autodetection of I2C displays. This currently does not disable the usage of other devices on the same block. --- headers/addons/display.h | 2 + headers/display/GPGFX.h | 2 + headers/display/GPGFX_types.h | 5 ++- headers/interfaces/i2c/displaybase.h | 15 ++++++- headers/interfaces/i2c/ssd1306/obd_ssd1306.h | 13 ++++++ headers/interfaces/i2c/ssd1306/tiny_ssd1306.h | 12 ++++++ src/addons/display.cpp | 20 +++++---- src/display/GPGFX.cpp | 41 +++++++++++++++++-- 8 files changed, 93 insertions(+), 17 deletions(-) diff --git a/headers/addons/display.h b/headers/addons/display.h index 4e8eeb4da..7cbb19906 100644 --- a/headers/addons/display.h +++ b/headers/addons/display.h @@ -209,6 +209,8 @@ class DisplayAddon : public GPAddon DisplayMode currDisplayMode; DisplayMode prevDisplayMode; bool turnOffWhenSuspended; + + GPGFX_DisplayTypeOptions gpOptions; }; #endif diff --git a/headers/display/GPGFX.h b/headers/display/GPGFX.h index 94a9cd8e3..99b964803 100644 --- a/headers/display/GPGFX.h +++ b/headers/display/GPGFX.h @@ -12,6 +12,8 @@ class GPGFX { void init(GPGFX_DisplayTypeOptions options); + GPGFX_DisplayTypeOptions getAvailableDisplay(); + GPGFX_DisplayBase* getDriver() { return displayDriver; } // drawing methods diff --git a/headers/display/GPGFX_types.h b/headers/display/GPGFX_types.h index 0634f8ccc..4ca5004e7 100644 --- a/headers/display/GPGFX_types.h +++ b/headers/display/GPGFX_types.h @@ -17,8 +17,9 @@ typedef enum { } GPGFX_DisplaySize; typedef enum { - TYPE_NONE, - TYPE_SSD1306 + DISPLAY_TYPE_NONE, + DISPLAY_TYPE_SSD1306, + DISPLAY_TYPE_COUNT } GPGFX_DisplayType; typedef struct { diff --git a/headers/interfaces/i2c/displaybase.h b/headers/interfaces/i2c/displaybase.h index 9be03fd79..2b620e9dd 100644 --- a/headers/interfaces/i2c/displaybase.h +++ b/headers/interfaces/i2c/displaybase.h @@ -5,9 +5,13 @@ #include #include "pico/stdlib.h" #include "GPGFX_types.h" +#include "i2cdevicebase.h" -class GPGFX_DisplayBase { +class GPGFX_DisplayBase : public I2CDeviceBase { public: + GPGFX_DisplayBase() {} + ~GPGFX_DisplayBase() {} + virtual void init(GPGFX_DisplayTypeOptions options) {} virtual void setPower(bool isPowered) {} @@ -34,7 +38,14 @@ class GPGFX_DisplayBase { void setMetrics(GPGFX_DisplayMetrics* metrics) { this->_metrics = metrics; } GPGFX_DisplayMetrics* getMetrics() { return this->_metrics; } - protected: + + std::vector getDeviceAddresses() const override { + return {}; + } + + virtual bool isSPI() { return false; } + virtual bool isI2C() { return false; } + private: GPGFX_DisplayMetrics* _metrics; }; diff --git a/headers/interfaces/i2c/ssd1306/obd_ssd1306.h b/headers/interfaces/i2c/ssd1306/obd_ssd1306.h index ee8f80aac..38a62a7c3 100644 --- a/headers/interfaces/i2c/ssd1306/obd_ssd1306.h +++ b/headers/interfaces/i2c/ssd1306/obd_ssd1306.h @@ -8,6 +8,9 @@ class GPGFX_OBD_SSD1306 : public GPGFX_DisplayBase { public: + GPGFX_OBD_SSD1306() {} + ~GPGFX_OBD_SSD1306() {} + void init(GPGFX_DisplayTypeOptions options); void setPower(bool isPowered); @@ -27,6 +30,13 @@ class GPGFX_OBD_SSD1306 : public GPGFX_DisplayBase { void drawSprite(uint8_t* spriteData, uint16_t width, uint16_t height, uint16_t pitch, uint16_t x, uint16_t y, uint8_t priority); void drawBuffer(uint8_t *pBuffer); + + std::vector getDeviceAddresses() const override { + return {0x3C, 0x3D}; + } + + bool isSPI() { return this->_isSPI; } + bool isI2C() { return this->_isI2C; } private: OBDISP obd; GPGFX_DisplayTypeOptions _options; @@ -36,6 +46,9 @@ class GPGFX_OBD_SSD1306 : public GPGFX_DisplayBase { void clearScreen(int render); uint8_t ucBackBuffer[1024]; + + bool _isSPI = false; + bool _isI2C = true; }; #endif diff --git a/headers/interfaces/i2c/ssd1306/tiny_ssd1306.h b/headers/interfaces/i2c/ssd1306/tiny_ssd1306.h index ff5b57279..6e6633e14 100644 --- a/headers/interfaces/i2c/ssd1306/tiny_ssd1306.h +++ b/headers/interfaces/i2c/ssd1306/tiny_ssd1306.h @@ -7,6 +7,9 @@ class GPGFX_TinySSD1306 : public GPGFX_DisplayBase { public: + GPGFX_TinySSD1306() {} + ~GPGFX_TinySSD1306() {} + void init(GPGFX_DisplayTypeOptions options); void setPower(bool isPowered); @@ -32,6 +35,13 @@ class GPGFX_TinySSD1306 : public GPGFX_DisplayBase { void drawBuffer(uint8_t *pBuffer); bool isSH1106(int detectedDisplay); + + std::vector getDeviceAddresses() const override { + return {0x3C, 0x3D}; + } + + bool isSPI() { return this->_isSPI; } + bool isI2C() { return this->_isI2C; } private: typedef enum { SET_LOW_COLUMN = 0x00, @@ -84,6 +94,8 @@ class GPGFX_TinySSD1306 : public GPGFX_DisplayBase { uint8_t framePage = 0; uint8_t screenType; + bool _isSPI = false; + bool _isI2C = true; }; #endif diff --git a/src/addons/display.cpp b/src/addons/display.cpp index c503cf4a4..de5e45746 100644 --- a/src/addons/display.cpp +++ b/src/addons/display.cpp @@ -18,31 +18,33 @@ bool DisplayAddon::available() { const DisplayOptions& options = Storage::getInstance().getDisplayOptions(); - return options.enabled && PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock); + bool result = false; + if (options.enabled) { + // create the gfx interface + gpDisplay = new GPGFX(); + gpOptions = gpDisplay->getAvailableDisplay(); + result = (gpOptions.displayType != GPGFX_DisplayType::DISPLAY_TYPE_NONE); + if (!result) delete gpDisplay; + } + return result; } void DisplayAddon::setup() { const DisplayOptions& options = Storage::getInstance().getDisplayOptions(); - PeripheralI2C* i2c = PeripheralManager::getInstance().getI2C(options.i2cBlock); // Setup GPGFX Options - GPGFX_DisplayTypeOptions gpOptions; - if (PeripheralManager::getInstance().isI2CEnabled(options.i2cBlock)) { - gpOptions.displayType = GPGFX_DisplayType::TYPE_SSD1306; - gpOptions.i2c = i2c; + if (gpOptions.displayType != GPGFX_DisplayType::DISPLAY_TYPE_NONE) { gpOptions.size = options.size; - gpOptions.address = options.i2cAddress; gpOptions.orientation = options.flip; gpOptions.inverted = options.invert; gpOptions.font.fontData = GP_Font_Standard; gpOptions.font.width = 6; gpOptions.font.height = 8; } else { - return; // Do not run our display + return; } // Setup GPGFX - gpDisplay = new GPGFX(); gpDisplay->init(gpOptions); gamepad = Storage::getInstance().GetGamepad(); diff --git a/src/display/GPGFX.cpp b/src/display/GPGFX.cpp index 0373c5a2c..25cc92ed3 100644 --- a/src/display/GPGFX.cpp +++ b/src/display/GPGFX.cpp @@ -1,13 +1,15 @@ #include "GPGFX.h" #include +#include +#include "peripheralmanager.h" #include "obd_ssd1306.h" #include "tiny_ssd1306.h" std::map> GPGFX_DisplayModes = { { - {TYPE_SSD1306}, + {DISPLAY_TYPE_SSD1306}, { {SIZE_128x32,{128,32,1}}, {SIZE_128x64,{128,64,1}}, @@ -21,20 +23,51 @@ GPGFX::GPGFX() { void GPGFX::init(GPGFX_DisplayTypeOptions options) { switch (options.displayType) { - case GPGFX_DisplayType::TYPE_SSD1306: + case GPGFX_DisplayType::DISPLAY_TYPE_SSD1306: //this->displayDriver = new GPGFX_OBD_SSD1306(); this->displayDriver = new GPGFX_TinySSD1306(); break; default: - options.displayType = GPGFX_DisplayType::TYPE_NONE; + options.displayType = GPGFX_DisplayType::DISPLAY_TYPE_NONE; } - if (options.displayType != GPGFX_DisplayType::TYPE_NONE) { + if (options.displayType != GPGFX_DisplayType::DISPLAY_TYPE_NONE) { this->displayDriver->setMetrics(&GPGFX_DisplayModes[options.displayType][(GPGFX_DisplaySize)options.size]); this->displayDriver->init(options); } } +GPGFX_DisplayTypeOptions GPGFX::getAvailableDisplay() { + GPGFX_DisplayBase* driver = nullptr; + GPGFX_DisplayTypeOptions display; + + display.displayType = GPGFX_DisplayType::DISPLAY_TYPE_NONE; + + for (uint16_t i = GPGFX_DisplayType::DISPLAY_TYPE_NONE; i < GPGFX_DisplayType::DISPLAY_TYPE_COUNT; i++) { + if (i == GPGFX_DisplayType::DISPLAY_TYPE_SSD1306) { + driver = new GPGFX_TinySSD1306(); + } else { + driver = nullptr; + } + if ((driver != nullptr) && (display.displayType == GPGFX_DisplayType::DISPLAY_TYPE_NONE)) { + if (driver->isI2C()) { + PeripheralI2CScanResult result = PeripheralManager::getInstance().scanForI2CDevice(driver->getDeviceAddresses()); + if (result.address > -1) { + display.displayType = (GPGFX_DisplayType)i; + display.address = result.address; + display.i2c = PeripheralManager::getInstance().getI2C(result.block); + return display; + } + } + if (driver->isSPI()) { + // NYI: check if SPI display exists + } + delete driver; + } + } + return display; +} + void GPGFX::clearScreen() { this->displayDriver->clear(); } From d824e65df41ca7cdebaf968dc82492e4b29ca7ad Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Tue, 18 Jun 2024 22:45:42 -0700 Subject: [PATCH 07/12] Deprecating I2C addon block and address fields. --- proto/config.proto | 12 +++---- src/config_legacy.cpp | 10 +++--- src/config_utils.cpp | 72 +++++++++++++++++++-------------------- src/configs/webconfig.cpp | 12 ------- 4 files changed, 47 insertions(+), 59 deletions(-) diff --git a/proto/config.proto b/proto/config.proto index a32b31923..b08b3be79 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -206,10 +206,10 @@ message DisplayOptions { optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; - optional int32 i2cAddress = 5; + optional int32 deprecatedI2cAddress = 5 [deprecated = true]; optional int32 deprecatedI2cSpeed = 6 [deprecated = true]; optional ButtonLayout buttonLayout = 7; @@ -418,10 +418,10 @@ message AnalogADS1219Options { optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; - optional int32 i2cAddress = 5; + optional int32 deprecatedI2cAddress = 5 [deprecated = true]; optional int32 deprecatedI2cSpeed = 6 [deprecated = true]; } @@ -640,7 +640,7 @@ message WiiOptions } optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; optional int32 deprecatedI2cSpeed = 5 [deprecated = true]; @@ -734,7 +734,7 @@ message RotaryOptions message PCF8575Options { optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; repeated GpioMappingInfo pins = 3 [(nanopb).max_count = 16]; } diff --git a/src/config_legacy.cpp b/src/config_legacy.cpp index c19db6f86..da4033664 100644 --- a/src/config_legacy.cpp +++ b/src/config_legacy.cpp @@ -800,10 +800,10 @@ bool ConfigUtils::fromLegacyStorage(Config& config) DisplayOptions& displayOptions = config.displayOptions; config.has_displayOptions = true; SET_PROPERTY(displayOptions, enabled, legacyBoardOptions.hasI2CDisplay); - SET_PROPERTY(displayOptions, i2cBlock, legacyBoardOptions.i2cBlock); + SET_PROPERTY(displayOptions, deprecatedI2cBlock, legacyBoardOptions.i2cBlock); SET_PROPERTY(displayOptions, deprecatedI2cSDAPin, legacyBoardOptions.i2cSDAPin); SET_PROPERTY(displayOptions, deprecatedI2cSCLPin, legacyBoardOptions.i2cSCLPin); - SET_PROPERTY(displayOptions, i2cAddress, legacyBoardOptions.displayI2CAddress); + SET_PROPERTY(displayOptions, deprecatedI2cAddress, legacyBoardOptions.displayI2CAddress); SET_PROPERTY(displayOptions, deprecatedI2cSpeed, legacyBoardOptions.i2cSpeed); if (isValidButtonLayout(legacyBoardOptions.buttonLayout)) { @@ -999,10 +999,10 @@ bool ConfigUtils::fromLegacyStorage(Config& config) AnalogADS1219Options& analogADS1219Options = config.addonOptions.analogADS1219Options; config.addonOptions.has_analogADS1219Options = true; SET_PROPERTY(analogADS1219Options, enabled, legacyAddonOptions.I2CAnalog1219InputEnabled); - SET_PROPERTY(analogADS1219Options, i2cBlock, legacyAddonOptions.i2cAnalog1219Block); + SET_PROPERTY(analogADS1219Options, deprecatedI2cBlock, legacyAddonOptions.i2cAnalog1219Block); SET_PROPERTY(analogADS1219Options, deprecatedI2cSDAPin, bytePinToIntPin(legacyAddonOptions.i2cAnalog1219SDAPin)); SET_PROPERTY(analogADS1219Options, deprecatedI2cSCLPin, bytePinToIntPin(legacyAddonOptions.i2cAnalog1219SCLPin)); - SET_PROPERTY(analogADS1219Options, i2cAddress, legacyAddonOptions.i2cAnalog1219Address); + SET_PROPERTY(analogADS1219Options, deprecatedI2cAddress, legacyAddonOptions.i2cAnalog1219Address); SET_PROPERTY(analogADS1219Options, deprecatedI2cSpeed, legacyAddonOptions.i2cAnalog1219Speed); SliderOptions& sliderOptions = config.addonOptions.sliderOptions; @@ -1080,7 +1080,7 @@ bool ConfigUtils::fromLegacyStorage(Config& config) WiiOptions& wiiOptions = config.addonOptions.wiiOptions; config.addonOptions.has_wiiOptions = true; SET_PROPERTY(wiiOptions, enabled, legacyAddonOptions.WiiExtensionAddonEnabled); - SET_PROPERTY(wiiOptions, i2cBlock, legacyAddonOptions.wiiExtensionBlock); + SET_PROPERTY(wiiOptions, deprecatedI2cBlock, legacyAddonOptions.wiiExtensionBlock); SET_PROPERTY(wiiOptions, deprecatedI2cSDAPin, bytePinToIntPin(legacyAddonOptions.wiiExtensionSDAPin)); SET_PROPERTY(wiiOptions, deprecatedI2cSCLPin, bytePinToIntPin(legacyAddonOptions.wiiExtensionSCLPin)); SET_PROPERTY(wiiOptions, deprecatedI2cSpeed, legacyAddonOptions.wiiExtensionSpeed); diff --git a/src/config_utils.cpp b/src/config_utils.cpp index bca144e41..ffa83fbd6 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -363,10 +363,10 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // displayOptions INIT_UNSET_PROPERTY(config.displayOptions, enabled, !!HAS_I2C_DISPLAY); - INIT_UNSET_PROPERTY(config.displayOptions, i2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSCLPin, -1); - INIT_UNSET_PROPERTY(config.displayOptions, i2cAddress, DISPLAY_I2C_ADDR); + INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cAddress, DISPLAY_I2C_ADDR); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSpeed, I2C_SPEED); INIT_UNSET_PROPERTY(config.displayOptions, buttonLayout, BUTTON_LAYOUT); INIT_UNSET_PROPERTY(config.displayOptions, buttonLayoutRight, BUTTON_LAYOUT_RIGHT); @@ -583,10 +583,10 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.analogADS1219Options INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, enabled, !!I2C_ANALOG1219_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, i2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1) + INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1) INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSCLPin, -1); - INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, i2cAddress, I2C_ANALOG1219_ADDRESS); + INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cAddress, I2C_ANALOG1219_ADDRESS); INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSpeed, I2C_ANALOG1219_SPEED); // addonOptions.analogADS1256Options @@ -659,7 +659,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.wiiOptions INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, enabled, WII_EXTENSION_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, i2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSCLPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSpeed, WII_EXTENSION_I2C_SPEED); @@ -672,7 +672,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.pcf8575Options INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, enabled, I2C_PCF8575_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, i2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, deprecatedI2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1); GpioAction pcf8575Actions[PCF8575_PIN_COUNT] = { PCF8575_PIN00_ACTION,PCF8575_PIN01_ACTION,PCF8575_PIN02_ACTION,PCF8575_PIN03_ACTION, @@ -1012,27 +1012,27 @@ void gpioMappingsMigrationCore(Config& config) // migrate I2C addons to use peripheral manager if (!peripheralOptions.blockI2C0.enabled && ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) || - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) || - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) || + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) || + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0)) ) ) { peripheralOptions.blockI2C0.enabled = ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) | - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) | - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) | + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) | + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) | + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0)) | (!!I2C0_ENABLED) ); // pin configuration peripheralOptions.blockI2C0.sda = ( - isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 0) ? config.displayOptions.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSDAPin : I2C0_PIN_SDA ) @@ -1041,13 +1041,13 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(peripheralOptions.blockI2C0.sda); peripheralOptions.blockI2C0.scl = ( - isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 0) ? config.displayOptions.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSCLPin : I2C0_PIN_SCL ) @@ -1057,13 +1057,13 @@ void gpioMappingsMigrationCore(Config& config) // option configuration peripheralOptions.blockI2C0.speed = ( - isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 0) ? config.displayOptions.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSpeed : I2C0_SPEED ) @@ -1072,27 +1072,27 @@ void gpioMappingsMigrationCore(Config& config) } if (!peripheralOptions.blockI2C1.enabled && ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) || - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) || - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) || + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) || + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1)) ) ) { peripheralOptions.blockI2C1.enabled = ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) | - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) | - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) | + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) | + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) | + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1)) | (!!I2C1_ENABLED) ); // pin configuration peripheralOptions.blockI2C1.sda = ( - isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 1) ? config.displayOptions.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSDAPin : I2C1_PIN_SDA ) @@ -1101,13 +1101,13 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(peripheralOptions.blockI2C1.sda); peripheralOptions.blockI2C1.scl = ( - isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 1) ? config.displayOptions.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSCLPin : I2C1_PIN_SCL ) @@ -1117,13 +1117,13 @@ void gpioMappingsMigrationCore(Config& config) // option configuration peripheralOptions.blockI2C1.speed = ( - isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 1) ? config.displayOptions.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSpeed : I2C1_SPEED ) diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index 2ec26e523..cd85c47cd 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -437,8 +437,6 @@ std::string setDisplayOptions(DisplayOptions& displayOptions) { DynamicJsonDocument doc = get_post_data(); readDoc(displayOptions.enabled, doc, "enabled"); - readDoc(displayOptions.i2cAddress, doc, "i2cAddress"); - readDoc(displayOptions.i2cBlock, doc, "i2cBlock"); readDoc(displayOptions.flip, doc, "flipDisplay"); readDoc(displayOptions.invert, doc, "invertDisplay"); readDoc(displayOptions.buttonLayout, doc, "buttonLayout"); @@ -481,8 +479,6 @@ std::string getDisplayOptions() // Manually set Document Attributes for the disp DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN); const DisplayOptions& displayOptions = Storage::getInstance().getDisplayOptions(); writeDoc(doc, "enabled", displayOptions.enabled ? 1 : 0); - writeDoc(doc, "i2cAddress", displayOptions.i2cAddress); - writeDoc(doc, "i2cBlock", displayOptions.i2cBlock); writeDoc(doc, "flipDisplay", displayOptions.flip); writeDoc(doc, "invertDisplay", displayOptions.invert ? 1 : 0); writeDoc(doc, "buttonLayout", displayOptions.buttonLayout); @@ -1414,8 +1410,6 @@ std::string setAddonOptions() docToValue(focusModeOptions.enabled, doc, "FocusModeAddonEnabled"); AnalogADS1219Options& analogADS1219Options = Storage::getInstance().getAddonOptions().analogADS1219Options; - docToValue(analogADS1219Options.i2cBlock, doc, "i2cAnalog1219Block"); - docToValue(analogADS1219Options.i2cAddress, doc, "i2cAnalog1219Address"); docToValue(analogADS1219Options.enabled, doc, "I2CAnalog1219InputEnabled"); SliderOptions& sliderOptions = Storage::getInstance().getAddonOptions().sliderOptions; @@ -1464,7 +1458,6 @@ std::string setAddonOptions() docToValue(turboOptions.enabled, doc, "TurboInputEnabled"); WiiOptions& wiiOptions = Storage::getInstance().getAddonOptions().wiiOptions; - docToValue(wiiOptions.i2cBlock, doc, "wiiExtensionBlock"); docToValue(wiiOptions.enabled, doc, "WiiExtensionAddonEnabled"); SNESOptions& snesOptions = Storage::getInstance().getAddonOptions().snesOptions; @@ -1520,7 +1513,6 @@ std::string setAddonOptions() docToValue(rotaryOptions.encoderTwo.multiplier, doc, "encoderTwoMultiplier"); PCF8575Options& pcf8575Options = Storage::getInstance().getAddonOptions().pcf8575Options; - docToValue(pcf8575Options.i2cBlock, doc, "pcf8575Block"); docToValue(pcf8575Options.enabled, doc, "PCF8575AddonEnabled"); Storage::getInstance().save(); @@ -1823,8 +1815,6 @@ std::string getAddonOptions() writeDoc(doc, "TiltInputEnabled", tiltOptions.enabled); const AnalogADS1219Options& analogADS1219Options = Storage::getInstance().getAddonOptions().analogADS1219Options; - writeDoc(doc, "i2cAnalog1219Block", analogADS1219Options.i2cBlock); - writeDoc(doc, "i2cAnalog1219Address", analogADS1219Options.i2cAddress); writeDoc(doc, "I2CAnalog1219InputEnabled", analogADS1219Options.enabled); const SliderOptions& sliderOptions = Storage::getInstance().getAddonOptions().sliderOptions; @@ -1873,7 +1863,6 @@ std::string getAddonOptions() writeDoc(doc, "TurboInputEnabled", turboOptions.enabled); const WiiOptions& wiiOptions = Storage::getInstance().getAddonOptions().wiiOptions; - writeDoc(doc, "wiiExtensionBlock", wiiOptions.i2cBlock); writeDoc(doc, "WiiExtensionAddonEnabled", wiiOptions.enabled); const SNESOptions& snesOptions = Storage::getInstance().getAddonOptions().snesOptions; @@ -1944,7 +1933,6 @@ std::string getAddonOptions() writeDoc(doc, "encoderTwoMultiplier", rotaryOptions.encoderTwo.multiplier); PCF8575Options& pcf8575Options = Storage::getInstance().getAddonOptions().pcf8575Options; - writeDoc(doc, "pcf8575Block", pcf8575Options.i2cBlock); writeDoc(doc, "PCF8575AddonEnabled", pcf8575Options.enabled); return serialize_json(doc); From 60cc658217dd780d3a87cb8f77b3a3577999f589 Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Tue, 18 Jun 2024 23:15:33 -0700 Subject: [PATCH 08/12] Remove deprecated Block and Address fields from Display and several Addons. --- www/server/app.js | 6 ----- www/src/Addons/I2CAnalog1219.tsx | 43 -------------------------------- www/src/Addons/PCF8575.tsx | 28 --------------------- www/src/Addons/Wii.tsx | 31 ----------------------- www/src/Pages/DisplayConfig.jsx | 40 ----------------------------- www/src/Services/WebApi.js | 4 --- 6 files changed, 152 deletions(-) diff --git a/www/server/app.js b/www/server/app.js index 3d734e02c..93d4bf05e 100644 --- a/www/server/app.js +++ b/www/server/app.js @@ -45,8 +45,6 @@ app.get('/api/resetSettings', (req, res) => { app.get('/api/getDisplayOptions', (req, res) => { const data = { enabled: 1, - i2cAddress: 61, - i2cBlock: 0, flipDisplay: 0, invertDisplay: 1, buttonLayout: 0, @@ -396,8 +394,6 @@ app.get('/api/getAddonsOptions', (req, res) => { reverseActionDown: 1, reverseActionLeft: 1, reverseActionRight: 1, - i2cAnalog1219Block: 0, - i2cAnalog1219Address: 0x40, onBoardLedMode: 0, dualDirDpadMode: 0, dualDirCombineMode: 0, @@ -457,7 +453,6 @@ app.get('/api/getAddonsOptions', (req, res) => { shmupBtnMask4: 0, pinShmupDial: -1, sliderSOCDModeDefault: 1, - wiiExtensionBlock: 0, snesPadClockPin: -1, snesPadLatchPin: -1, snesPadDataPin: -1, @@ -506,7 +501,6 @@ app.get('/api/getAddonsOptions', (req, res) => { encoderTwoAllowWrapAround: false, encoderTwoMultiplier: 1, RotaryAddonEnabled: 1, - pcf8575Block: 0, PCF8575AddonEnabled: 1, usedPins: Object.values(picoController), }); diff --git a/www/src/Addons/I2CAnalog1219.tsx b/www/src/Addons/I2CAnalog1219.tsx index c40515d29..6bd427643 100644 --- a/www/src/Addons/I2CAnalog1219.tsx +++ b/www/src/Addons/I2CAnalog1219.tsx @@ -13,20 +13,10 @@ import { I2C_BLOCKS } from '../Data/Peripherals'; export const i2cAnalogScheme = { I2CAnalog1219InputEnabled: yup.number().label('I2C Analog1219 Input Enabled'), - i2cAnalog1219Block: yup - .number() - .label('I2C Analog1219 Block') - .validateSelectionWhenValue('I2CAnalog1219InputEnabled', I2C_BLOCKS), - i2cAnalog1219Address: yup - .number() - .label('I2C Analog1219 Address') - .validateNumberWhenValue('I2CAnalog1219InputEnabled'), }; export const i2cAnalogState = { I2CAnalog1219InputEnabled: 0, - i2cAnalog1219Block: 0, - i2cAnalog1219Address: 0x40, }; const I2CAnalog1219 = ({ values, errors, handleChange, handleCheckbox }) => { @@ -47,39 +37,6 @@ const I2CAnalog1219 = ({ values, errors, handleChange, handleCheckbox }) => { !(values.I2CAnalog1219InputEnabled && getAvailablePeripherals('i2c')) } > - - {getAvailablePeripherals('i2c') ? ( - - {getAvailablePeripherals('i2c').map((o, i) => ( - - ))} - - ) : ( - '' - )} - - {getAvailablePeripherals('i2c') ? ( { @@ -265,28 +259,6 @@ const PCF8575 = ({ values, errors, handleChange, handleCheckbox }) => { id="PCF8575AddonOptions" hidden={!(values.PCF8575AddonEnabled && getAvailablePeripherals('i2c'))} > - - {getAvailablePeripherals('i2c') ? ( - - {getAvailablePeripherals('i2c').map((o, i) => ( - - ))} - - ) : ( - '' - )} - - - {getAvailablePeripherals('i2c') ? ( - - {getAvailablePeripherals('i2c').map((o, i) => ( - - ))} - - ) : ( - '' - )} - o.value)) - .label('I2C Block'), flipDisplay: yup .number() .oneOf(DISPLAY_FLIP_MODES.map((o) => o.value)) @@ -157,7 +147,6 @@ const FormContext = () => { useEffect(() => { async function setDisplayOptions() { if (!!values.enabled) values.enabled = parseInt(values.enabled); - if (!!values.i2cBlock) values.i2cBlock = parseInt(values.i2cBlock); if (!!values.flipDisplay) values.flipDisplay = parseInt(values.flipDisplay); if (!!values.invertDisplay) @@ -183,7 +172,6 @@ const FormContext = () => { useEffect(() => { async function setSplashImage() { if (!!values.enabled) values.enabled = parseInt(values.enabled); - if (!!values.i2cBlock) values.i2cBlock = parseInt(values.i2cBlock); if (!!values.flipDisplay) values.flipDisplay = parseInt(values.flipDisplay); if (!!values.invertDisplay) @@ -298,34 +286,6 @@ export default function DisplayConfigPage() { ))} - - {getAvailablePeripherals('i2c').map((o, i) => ( - - ))} - -

{t('DisplayConfig:section.screen-header')}

diff --git a/www/src/Services/WebApi.js b/www/src/Services/WebApi.js index 1990f4d18..57d052d7c 100644 --- a/www/src/Services/WebApi.js +++ b/www/src/Services/WebApi.js @@ -205,9 +205,6 @@ async function getDisplayOptions() { try { const response = await Http.get(`${baseUrl}/api/getDisplayOptions`); - if (response.data.i2cAddress) { - response.data.i2cAddress = '0x' + response.data.i2cAddress.toString(16); - } response.data.splashDuration = response.data.splashDuration / 1000; // milliseconds to seconds response.data.displaySaverTimeout = response.data.displaySaverTimeout / 60000; // milliseconds to minutes @@ -220,7 +217,6 @@ async function getDisplayOptions() { async function setDisplayOptions(options, isPreview) { let newOptions = sanitizeRequest(options); - newOptions.i2cAddress = parseInt(options.i2cAddress); newOptions.buttonLayout = parseInt(options.buttonLayout); newOptions.buttonLayoutRight = parseInt(options.buttonLayoutRight); newOptions.splashMode = parseInt(options.splashMode); From 3977ddb5b3cfbc369b5c67575ef861970e9e846e Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Fri, 21 Jun 2024 21:02:48 -0700 Subject: [PATCH 09/12] Added exclusive mode for I2C peripherals to allow data-hungry devices like Display to take full control of the bus. --- lib/PicoPeripherals/peripheral_i2c.cpp | 8 ++++++++ lib/PicoPeripherals/peripheral_i2c.h | 5 +++++ src/display/GPGFX.cpp | 1 + 3 files changed, 14 insertions(+) diff --git a/lib/PicoPeripherals/peripheral_i2c.cpp b/lib/PicoPeripherals/peripheral_i2c.cpp index a82ba566e..e0eb7d9e3 100644 --- a/lib/PicoPeripherals/peripheral_i2c.cpp +++ b/lib/PicoPeripherals/peripheral_i2c.cpp @@ -39,6 +39,8 @@ void PeripheralI2C::setup() { } int16_t PeripheralI2C::read(uint8_t address, uint8_t *data, uint16_t len, bool isBlock) { + if ((_exclusiveAddress > -1) && (_exclusiveAddress != address)) return -1; + int16_t result = i2c_read_blocking(_I2C, address, data, len, isBlock); #ifdef DEBUG_PERIPHERALI2C printf("PeripheralI2C::write %d:%d (blocking? %d)\n", address, len, isBlock); @@ -52,6 +54,8 @@ int16_t PeripheralI2C::read(uint8_t address, uint8_t *data, uint16_t len, bool i } int16_t PeripheralI2C::readRegister(uint8_t address, uint8_t reg, uint8_t *data, uint16_t len) { + if ((_exclusiveAddress > -1) && (_exclusiveAddress != address)) return -1; + int16_t registerCheck; registerCheck = i2c_write_blocking(_I2C, address, ®, 1, true); if (registerCheck >= 0) { @@ -61,6 +65,8 @@ int16_t PeripheralI2C::readRegister(uint8_t address, uint8_t reg, uint8_t *data, } int16_t PeripheralI2C::write(uint8_t address, uint8_t *data, uint16_t len, bool isBlock) { + if ((_exclusiveAddress > -1) && (_exclusiveAddress != address)) return -1; + #ifdef DEBUG_PERIPHERALI2C printf("PeripheralI2C::write %d:%d (blocking? %d)\n", address, len, isBlock); for (int i = 0; i < len; i++) { @@ -99,7 +105,9 @@ std::map PeripheralI2C::scan() { } } +#ifdef DEBUG_PERIPHERALI2C printf("%d\n", result.size()); +#endif return result; } \ No newline at end of file diff --git a/lib/PicoPeripherals/peripheral_i2c.h b/lib/PicoPeripherals/peripheral_i2c.h index e1569bcbe..73042aee2 100644 --- a/lib/PicoPeripherals/peripheral_i2c.h +++ b/lib/PicoPeripherals/peripheral_i2c.h @@ -60,6 +60,9 @@ class PeripheralI2C { void clear(); std::map scan(); + + // if this is set to anything other than -1, any r/w operations against the address other than test()/scan() will not be processed + void setExclusiveUse(int8_t address = -1) { _exclusiveAddress = address; } private: const uint32_t DEFAULT_SPEED = 400000; @@ -70,6 +73,8 @@ class PeripheralI2C { i2c_inst_t* _hardwareBlocks[NUM_I2CS] = {i2c0,i2c1}; + int8_t _exclusiveAddress = -1; + void setup(); }; diff --git a/src/display/GPGFX.cpp b/src/display/GPGFX.cpp index 25cc92ed3..8b0c8aee4 100644 --- a/src/display/GPGFX.cpp +++ b/src/display/GPGFX.cpp @@ -56,6 +56,7 @@ GPGFX_DisplayTypeOptions GPGFX::getAvailableDisplay() { display.displayType = (GPGFX_DisplayType)i; display.address = result.address; display.i2c = PeripheralManager::getInstance().getI2C(result.block); + display.i2c->setExclusiveUse(result.address); return display; } } From 14dd7fe873728cd6004dac23b838fc7fd509ce57 Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Wed, 31 Jul 2024 12:07:12 -0700 Subject: [PATCH 10/12] Revert deprecatedi2cBlock to i2cBlock --- proto/config.proto | 8 +++--- src/config_utils.cpp | 68 ++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/proto/config.proto b/proto/config.proto index b08b3be79..918ad9ce6 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -206,7 +206,7 @@ message DisplayOptions { optional bool enabled = 1; - optional int32 deprecatedI2cBlock = 2 [deprecated = true]; + optional int32 i2cBlock = 2; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; optional int32 deprecatedI2cAddress = 5 [deprecated = true]; @@ -418,7 +418,7 @@ message AnalogADS1219Options { optional bool enabled = 1; - optional int32 deprecatedI2cBlock = 2 [deprecated = true]; + optional int32 i2cBlock = 2; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; optional int32 deprecatedI2cAddress = 5 [deprecated = true]; @@ -640,7 +640,7 @@ message WiiOptions } optional bool enabled = 1; - optional int32 deprecatedI2cBlock = 2 [deprecated = true]; + optional int32 i2cBlock = 2; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; optional int32 deprecatedI2cSpeed = 5 [deprecated = true]; @@ -734,7 +734,7 @@ message RotaryOptions message PCF8575Options { optional bool enabled = 1; - optional int32 deprecatedI2cBlock = 2 [deprecated = true]; + optional int32 i2cBlock = 2; repeated GpioMappingInfo pins = 3 [(nanopb).max_count = 16]; } diff --git a/src/config_utils.cpp b/src/config_utils.cpp index ffa83fbd6..7ea976542 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -363,7 +363,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // displayOptions INIT_UNSET_PROPERTY(config.displayOptions, enabled, !!HAS_I2C_DISPLAY); - INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.displayOptions, i2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSCLPin, -1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cAddress, DISPLAY_I2C_ADDR); @@ -583,7 +583,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.analogADS1219Options INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, enabled, !!I2C_ANALOG1219_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1) + INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, i2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1) INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSCLPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cAddress, I2C_ANALOG1219_ADDRESS); @@ -659,7 +659,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.wiiOptions INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, enabled, WII_EXTENSION_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, i2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSCLPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSpeed, WII_EXTENSION_I2C_SPEED); @@ -672,7 +672,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.pcf8575Options INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, enabled, I2C_PCF8575_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, deprecatedI2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, i2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1); GpioAction pcf8575Actions[PCF8575_PIN_COUNT] = { PCF8575_PIN00_ACTION,PCF8575_PIN01_ACTION,PCF8575_PIN02_ACTION,PCF8575_PIN03_ACTION, @@ -1012,27 +1012,27 @@ void gpioMappingsMigrationCore(Config& config) // migrate I2C addons to use peripheral manager if (!peripheralOptions.blockI2C0.enabled && ( - (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) || - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) || - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0)) + (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) || + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) || + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) ) ) { peripheralOptions.blockI2C0.enabled = ( - (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) | - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) | - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0)) | + (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) | + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) | + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) | (!!I2C0_ENABLED) ); // pin configuration peripheralOptions.blockI2C0.sda = ( - isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 0) ? config.displayOptions.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSDAPin : I2C0_PIN_SDA ) @@ -1041,13 +1041,13 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(peripheralOptions.blockI2C0.sda); peripheralOptions.blockI2C0.scl = ( - isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 0) ? config.displayOptions.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSCLPin : I2C0_PIN_SCL ) @@ -1057,13 +1057,13 @@ void gpioMappingsMigrationCore(Config& config) // option configuration peripheralOptions.blockI2C0.speed = ( - isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 0) ? config.displayOptions.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSpeed : I2C0_SPEED ) @@ -1072,27 +1072,27 @@ void gpioMappingsMigrationCore(Config& config) } if (!peripheralOptions.blockI2C1.enabled && ( - (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) || - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) || - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1)) + (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) || + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) || + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) ) ) { peripheralOptions.blockI2C1.enabled = ( - (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) | - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) | - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1)) | + (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) | + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) | + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) | (!!I2C1_ENABLED) ); // pin configuration peripheralOptions.blockI2C1.sda = ( - isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 1) ? config.displayOptions.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSDAPin : I2C1_PIN_SDA ) @@ -1101,13 +1101,13 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(peripheralOptions.blockI2C1.sda); peripheralOptions.blockI2C1.scl = ( - isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 1) ? config.displayOptions.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSCLPin : I2C1_PIN_SCL ) @@ -1117,13 +1117,13 @@ void gpioMappingsMigrationCore(Config& config) // option configuration peripheralOptions.blockI2C1.speed = ( - isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 1) ? config.displayOptions.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSpeed : I2C1_SPEED ) From cbce5a5082b9309dda4824228c4121b19bbd759d Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Wed, 31 Jul 2024 12:18:38 -0700 Subject: [PATCH 11/12] Reinstated deprecatedI2cBlock --- proto/config.proto | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/proto/config.proto b/proto/config.proto index 918ad9ce6..b08b3be79 100644 --- a/proto/config.proto +++ b/proto/config.proto @@ -206,7 +206,7 @@ message DisplayOptions { optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; optional int32 deprecatedI2cAddress = 5 [deprecated = true]; @@ -418,7 +418,7 @@ message AnalogADS1219Options { optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; optional int32 deprecatedI2cAddress = 5 [deprecated = true]; @@ -640,7 +640,7 @@ message WiiOptions } optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; optional int32 deprecatedI2cSDAPin = 3 [deprecated = true]; optional int32 deprecatedI2cSCLPin = 4 [deprecated = true]; optional int32 deprecatedI2cSpeed = 5 [deprecated = true]; @@ -734,7 +734,7 @@ message RotaryOptions message PCF8575Options { optional bool enabled = 1; - optional int32 i2cBlock = 2; + optional int32 deprecatedI2cBlock = 2 [deprecated = true]; repeated GpioMappingInfo pins = 3 [(nanopb).max_count = 16]; } From 113d4abbe55e119f416f7171ecdeba9505dfdc17 Mon Sep 17 00:00:00 2001 From: Mike Parks Date: Wed, 31 Jul 2024 12:19:57 -0700 Subject: [PATCH 12/12] Reinstated usage of deprecatedI2cBlock --- src/config_utils.cpp | 68 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/config_utils.cpp b/src/config_utils.cpp index 7ea976542..ffa83fbd6 100644 --- a/src/config_utils.cpp +++ b/src/config_utils.cpp @@ -363,7 +363,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // displayOptions INIT_UNSET_PROPERTY(config.displayOptions, enabled, !!HAS_I2C_DISPLAY); - INIT_UNSET_PROPERTY(config.displayOptions, i2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cBlock, (DISPLAY_I2C_BLOCK == i2c0) ? 0 : 1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cSCLPin, -1); INIT_UNSET_PROPERTY(config.displayOptions, deprecatedI2cAddress, DISPLAY_I2C_ADDR); @@ -583,7 +583,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.analogADS1219Options INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, enabled, !!I2C_ANALOG1219_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, i2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1) + INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cBlock, (I2C_ANALOG1219_BLOCK == i2c0) ? 0 : 1) INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cSCLPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.analogADS1219Options, deprecatedI2cAddress, I2C_ANALOG1219_ADDRESS); @@ -659,7 +659,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.wiiOptions INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, enabled, WII_EXTENSION_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, i2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cBlock, (WII_EXTENSION_I2C_BLOCK == i2c0) ? 0 : 1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSDAPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSCLPin, -1); INIT_UNSET_PROPERTY(config.addonOptions.wiiOptions, deprecatedI2cSpeed, WII_EXTENSION_I2C_SPEED); @@ -672,7 +672,7 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config) // addonOptions.pcf8575Options INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, enabled, I2C_PCF8575_ENABLED); - INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, i2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1); + INIT_UNSET_PROPERTY(config.addonOptions.pcf8575Options, deprecatedI2cBlock, (I2C_PCF8575_BLOCK == i2c0) ? 0 : 1); GpioAction pcf8575Actions[PCF8575_PIN_COUNT] = { PCF8575_PIN00_ACTION,PCF8575_PIN01_ACTION,PCF8575_PIN02_ACTION,PCF8575_PIN03_ACTION, @@ -1012,27 +1012,27 @@ void gpioMappingsMigrationCore(Config& config) // migrate I2C addons to use peripheral manager if (!peripheralOptions.blockI2C0.enabled && ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) || - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) || - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) || + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) || + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0)) ) ) { peripheralOptions.blockI2C0.enabled = ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 0)) | - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 0)) | - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 0)) | + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 0)) | + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0)) | + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0)) | (!!I2C0_ENABLED) ); // pin configuration peripheralOptions.blockI2C0.sda = ( - isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 0) ? config.displayOptions.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSDAPin : I2C0_PIN_SDA ) @@ -1041,13 +1041,13 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(peripheralOptions.blockI2C0.sda); peripheralOptions.blockI2C0.scl = ( - isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 0) ? config.displayOptions.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSCLPin : I2C0_PIN_SCL ) @@ -1057,13 +1057,13 @@ void gpioMappingsMigrationCore(Config& config) // option configuration peripheralOptions.blockI2C0.speed = ( - isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 0) ? + isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 0) ? config.displayOptions.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 0) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 0) ? config.addonOptions.analogADS1219Options.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 0) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 0) ? config.addonOptions.wiiOptions.deprecatedI2cSpeed : I2C0_SPEED ) @@ -1072,27 +1072,27 @@ void gpioMappingsMigrationCore(Config& config) } if (!peripheralOptions.blockI2C1.enabled && ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) || - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) || - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) || + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) || + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1)) ) ) { peripheralOptions.blockI2C1.enabled = ( - (config.displayOptions.enabled && (config.displayOptions.i2cBlock == 1)) | - (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.i2cBlock == 1)) | - (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.i2cBlock == 1)) | + (config.displayOptions.enabled && (config.displayOptions.deprecatedI2cBlock == 1)) | + (config.addonOptions.analogADS1219Options.enabled && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1)) | + (config.addonOptions.wiiOptions.enabled && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1)) | (!!I2C1_ENABLED) ); // pin configuration peripheralOptions.blockI2C1.sda = ( - isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.i2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSDAPin) && (config.displayOptions.deprecatedI2cBlock == 1) ? config.displayOptions.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSDAPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSDAPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSDAPin : I2C1_PIN_SDA ) @@ -1101,13 +1101,13 @@ void gpioMappingsMigrationCore(Config& config) markAddonPinIfUsed(peripheralOptions.blockI2C1.sda); peripheralOptions.blockI2C1.scl = ( - isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.i2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSCLPin) && (config.displayOptions.deprecatedI2cBlock == 1) ? config.displayOptions.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSCLPin : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSCLPin) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSCLPin : I2C1_PIN_SCL ) @@ -1117,13 +1117,13 @@ void gpioMappingsMigrationCore(Config& config) // option configuration peripheralOptions.blockI2C1.speed = ( - isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.i2cBlock == 1) ? + isValidPin(config.displayOptions.deprecatedI2cSpeed) && (config.displayOptions.deprecatedI2cBlock == 1) ? config.displayOptions.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.i2cBlock == 1) ? + isValidPin(config.addonOptions.analogADS1219Options.deprecatedI2cSpeed) && (config.addonOptions.analogADS1219Options.deprecatedI2cBlock == 1) ? config.addonOptions.analogADS1219Options.deprecatedI2cSpeed : ( - isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.i2cBlock == 1) ? + isValidPin(config.addonOptions.wiiOptions.deprecatedI2cSpeed) && (config.addonOptions.wiiOptions.deprecatedI2cBlock == 1) ? config.addonOptions.wiiOptions.deprecatedI2cSpeed : I2C1_SPEED )