diff --git a/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp b/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp index a9920628..25cfeb6e 100644 --- a/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp +++ b/Boards/CYD-2432S024C/Source/CYD2432S024C.cpp @@ -22,8 +22,7 @@ const tt::hal::Configuration cyd_2432S024c_config = { .name = "First", .port = I2C_NUM_0, .initMode = tt::hal::i2c::InitMode::ByTactility, - .canReinit = true, - .hasMutableConfiguration = true, + .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_33, @@ -40,8 +39,7 @@ const tt::hal::Configuration cyd_2432S024c_config = { .name = "Second", .port = I2C_NUM_1, .initMode = tt::hal::i2c::InitMode::Disabled, - .canReinit = true, - .hasMutableConfiguration = true, + .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_NC, @@ -76,8 +74,7 @@ const tt::hal::Configuration cyd_2432S024c_config = { .intr_flags = 0 }, .initMode = tt::hal::spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, tt::hal::spi::Configuration { @@ -100,8 +97,7 @@ const tt::hal::Configuration cyd_2432S024c_config = { .intr_flags = 0 }, .initMode = tt::hal::spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = nullptr }, } diff --git a/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp b/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp index 2a3ad72b..acea7d2e 100644 --- a/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp +++ b/Boards/ElecrowCrowpanelAdvance28/Source/CrowPanelAdvance28.cpp @@ -25,8 +25,7 @@ extern const Configuration crowpanel_advance_28 = { .name = "Main", .port = I2C_NUM_0, .initMode = i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_15, @@ -62,8 +61,7 @@ extern const Configuration crowpanel_advance_28 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, // SD card @@ -87,8 +85,7 @@ extern const Configuration crowpanel_advance_28 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = nullptr // No custom lock needed } }, diff --git a/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp b/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp index 1bede9ad..4de415cd 100644 --- a/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp +++ b/Boards/ElecrowCrowpanelAdvance35/Source/CrowPanelAdvance35.cpp @@ -25,8 +25,7 @@ extern const Configuration crowpanel_advance_35 = { .name = "Main", .port = I2C_NUM_0, .initMode = i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_15, @@ -62,8 +61,7 @@ extern const Configuration crowpanel_advance_35 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, // SD card @@ -87,8 +85,7 @@ extern const Configuration crowpanel_advance_35 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = nullptr // No custom lock needed } }, diff --git a/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp b/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp index 26b8a74c..0a74fd81 100644 --- a/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp +++ b/Boards/ElecrowCrowpanelBasic28/Source/CrowPanelBasic28.cpp @@ -27,8 +27,7 @@ extern const Configuration crowpanel_basic_28 = { .name = "Main", .port = I2C_NUM_0, .initMode = i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_22, @@ -64,8 +63,7 @@ extern const Configuration crowpanel_basic_28 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, // SD card @@ -89,8 +87,7 @@ extern const Configuration crowpanel_basic_28 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = nullptr // No custom lock needed } }, diff --git a/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp b/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp index b456cc2c..ebedf67f 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp +++ b/Boards/ElecrowCrowpanelBasic35/Source/CrowPanelBasic35.cpp @@ -27,8 +27,7 @@ extern const Configuration crowpanel_basic_35 = { .name = "Main", .port = I2C_NUM_0, .initMode = i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_22, @@ -64,8 +63,7 @@ extern const Configuration crowpanel_basic_35 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display }, // SD card @@ -89,8 +87,7 @@ extern const Configuration crowpanel_basic_35 = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = nullptr // No custom lock needed } }, diff --git a/Boards/LilygoTdeck/Source/LilygoTdeck.cpp b/Boards/LilygoTdeck/Source/LilygoTdeck.cpp index cfab11ed..4bbab602 100644 --- a/Boards/LilygoTdeck/Source/LilygoTdeck.cpp +++ b/Boards/LilygoTdeck/Source/LilygoTdeck.cpp @@ -24,8 +24,7 @@ extern const Configuration lilygo_tdeck = { .name = "Internal", .port = I2C_NUM_0, .initMode = i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_18, @@ -42,8 +41,7 @@ extern const Configuration lilygo_tdeck = { .name = "External", .port = I2C_NUM_1, .initMode = i2c::InitMode::Disabled, - .canReinit = true, - .hasMutableConfiguration = true, + .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_43, @@ -78,8 +76,7 @@ extern const Configuration lilygo_tdeck = { .intr_flags = 0 }, .initMode = spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } }, diff --git a/Boards/M5stackCore2/Source/M5stackCore2.cpp b/Boards/M5stackCore2/Source/M5stackCore2.cpp index b49330c9..c55506a0 100644 --- a/Boards/M5stackCore2/Source/M5stackCore2.cpp +++ b/Boards/M5stackCore2/Source/M5stackCore2.cpp @@ -19,8 +19,7 @@ extern const tt::hal::Configuration m5stack_core2 = { .name = "Internal", .port = I2C_NUM_0, .initMode = tt::hal::i2c::InitMode::ByTactility, - .canReinit = false, // Might be set to try after trying out what it does AXP and screen - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_21, @@ -37,8 +36,7 @@ extern const tt::hal::Configuration m5stack_core2 = { .name = "External", // (Grove) .port = I2C_NUM_1, .initMode = tt::hal::i2c::InitMode::ByTactility, - .canReinit = true, - .hasMutableConfiguration = true, + .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_32, @@ -73,8 +71,7 @@ extern const tt::hal::Configuration m5stack_core2 = { .intr_flags = 0 }, .initMode = tt::hal::spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } } diff --git a/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp b/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp index e3301a6d..332b885e 100644 --- a/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp +++ b/Boards/M5stackCoreS3/Source/M5stackCoreS3.cpp @@ -18,8 +18,7 @@ const tt::hal::Configuration m5stack_cores3 = { .name = "Internal", .port = I2C_NUM_0, .initMode = tt::hal::i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_12, @@ -36,8 +35,7 @@ const tt::hal::Configuration m5stack_cores3 = { .name = "External", // Grove .port = I2C_NUM_1, .initMode = tt::hal::i2c::InitMode::ByTactility, - .canReinit = true, - .hasMutableConfiguration = true, + .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_2, @@ -72,8 +70,7 @@ const tt::hal::Configuration m5stack_cores3 = { .intr_flags = 0 }, .initMode = tt::hal::spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } } diff --git a/Boards/Simulator/Source/Simulator.cpp b/Boards/Simulator/Source/Simulator.cpp index 07beac0e..2aaad3cf 100644 --- a/Boards/Simulator/Source/Simulator.cpp +++ b/Boards/Simulator/Source/Simulator.cpp @@ -39,8 +39,7 @@ extern const Configuration hardware = { .name = "Internal", .port = I2C_NUM_0, .initMode = i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = 1, @@ -57,8 +56,7 @@ extern const Configuration hardware = { .name = "External", .port = I2C_NUM_1, .initMode = i2c::InitMode::ByTactility, - .canReinit = true, - .hasMutableConfiguration = true, + .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = 3, diff --git a/Boards/UnPhone/Source/UnPhone.cpp b/Boards/UnPhone/Source/UnPhone.cpp index bca4154b..ba3ce1c5 100644 --- a/Boards/UnPhone/Source/UnPhone.cpp +++ b/Boards/UnPhone/Source/UnPhone.cpp @@ -20,8 +20,7 @@ extern const tt::hal::Configuration unPhone = { .name = "Internal", .port = I2C_NUM_0, .initMode = tt::hal::i2c::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_3, @@ -38,8 +37,7 @@ extern const tt::hal::Configuration unPhone = { .name = "Unused", .port = I2C_NUM_1, .initMode = tt::hal::i2c::InitMode::Disabled, - .canReinit = true, - .hasMutableConfiguration = true, + .isMutable = true, .config = (i2c_config_t) { .mode = I2C_MODE_MASTER, .sda_io_num = GPIO_NUM_NC, @@ -74,8 +72,7 @@ extern const tt::hal::Configuration unPhone = { .intr_flags = 0 }, .initMode = tt::hal::spi::InitMode::ByTactility, - .canReinit = false, - .hasMutableConfiguration = false, + .isMutable = false, .lock = tt::lvgl::getSyncLock() // esp_lvgl_port owns the lock for the display } } diff --git a/Tactility/Source/app/i2cscanner/I2cScanner.cpp b/Tactility/Source/app/i2cscanner/I2cScanner.cpp index c048f4c7..943b9282 100644 --- a/Tactility/Source/app/i2cscanner/I2cScanner.cpp +++ b/Tactility/Source/app/i2cscanner/I2cScanner.cpp @@ -239,7 +239,7 @@ void I2cScannerApp::onScanTimer() { for (uint8_t address = 0; address < 128; ++address) { if (hal::i2c::masterHasDeviceAtAddress(port, address, 10 / portTICK_PERIOD_MS)) { - TT_LOG_I(TAG, "Found device at address %d", address); + TT_LOG_I(TAG, "Found device at address 0x%02X", address); if (!shouldStopScanTimer()) { addAddressToList(address); } else { diff --git a/Tactility/Source/app/i2csettings/I2cSettings.cpp b/Tactility/Source/app/i2csettings/I2cSettings.cpp index 7198b95c..08c10bcb 100644 --- a/Tactility/Source/app/i2csettings/I2cSettings.cpp +++ b/Tactility/Source/app/i2csettings/I2cSettings.cpp @@ -40,7 +40,7 @@ static void show(lv_obj_t* parent, const hal::i2c::Configuration& configuration) // On-off switch - if (configuration.canReinit) { + if (configuration.isMutable) { auto* state_switch = lv_switch_create(card); lv_obj_align(state_switch, LV_ALIGN_TOP_RIGHT, 0, 0); diff --git a/TactilityHeadless/Include/Tactility/hal/i2c/I2c.h b/TactilityHeadless/Include/Tactility/hal/i2c/I2c.h index a9f01d5e..f8e773fd 100644 --- a/TactilityHeadless/Include/Tactility/hal/i2c/I2c.h +++ b/TactilityHeadless/Include/Tactility/hal/i2c/I2c.h @@ -24,10 +24,11 @@ struct Configuration { i2c_port_t port; /** Whether this bus should be initialized when device starts up */ InitMode initMode; - /** Whether this bus can stopped and re-started. */ - bool canReinit; - /** Whether configuration can be changed. */ - bool hasMutableConfiguration; + /** + * Whether this bus can be changed after booting. + * If the bus is internal and/or used for core features like touch screen, then it can be declared static. + */ + bool isMutable; /** Configuration that must be valid when initAtBoot is set to true. */ i2c_config_t config; }; @@ -40,8 +41,7 @@ enum class Status { /** * Reconfigure a port with the provided settings. - * @warning This fails when the HAL Configuration does not allow for reinit. - * @warning This fails when the HAL Configuration does not allow for mutation of the device. + * @warning This fails when the HAL Configuration is not mutable. * @param[in] port the port to reconfigure * @param[in] configuration the new configuration * @return true on success diff --git a/TactilityHeadless/Include/Tactility/hal/spi/Spi.h b/TactilityHeadless/Include/Tactility/hal/spi/Spi.h index a21b98cd..501d6b5f 100644 --- a/TactilityHeadless/Include/Tactility/hal/spi/Spi.h +++ b/TactilityHeadless/Include/Tactility/hal/spi/Spi.h @@ -21,10 +21,8 @@ struct Configuration { spi_bus_config_t config; /** Whether this bus should be initialized when device starts up */ InitMode initMode; - /** Whether this bus can stopped and re-started. */ - bool canReinit; /** Whether configuration can be changed. */ - bool hasMutableConfiguration; + bool isMutable; /** Optional custom lock */ std::shared_ptr _Nullable lock; }; diff --git a/TactilityHeadless/Source/hal/i2c/I2c.cpp b/TactilityHeadless/Source/hal/i2c/I2c.cpp index 09b5ff4d..43e43b52 100644 --- a/TactilityHeadless/Source/hal/i2c/I2c.cpp +++ b/TactilityHeadless/Source/hal/i2c/I2c.cpp @@ -21,32 +21,6 @@ struct Data { static const uint8_t ACK_CHECK_EN = 1; static Data dataArray[I2C_NUM_MAX]; -static const char* toString(InitMode mode) { - switch (mode) { - using enum InitMode; - case ByTactility: - return TT_STRINGIFY(InitMode::ByTactility); - case ByExternal: - return TT_STRINGIFY(InitMode::ByExternal); - case Disabled: - return TT_STRINGIFY(InitMode::Disabled); - } - tt_crash("not implemented"); -} - -static void printInfo(const Data& data) { - TT_LOG_D(TAG, "I2C info for port %d", data.configuration.port); - TT_LOG_D(TAG, " isStarted: %d", data.isStarted); - TT_LOG_D(TAG, " isConfigured: %d", data.isConfigured); - TT_LOG_D(TAG, " initMode: %s", toString(data.configuration.initMode)); - TT_LOG_D(TAG, " canReinit: %d", data.configuration.canReinit); - TT_LOG_D(TAG, " hasMutableConfiguration: %d", data.configuration.hasMutableConfiguration); -#ifdef ESP_PLATFORM - TT_LOG_V(TAG, " SDA pin: %d", data.configuration.config.sda_io_num); - TT_LOG_V(TAG, " SCL pin: %d", data.configuration.config.scl_io_num); -#endif // ESP_PLATFORM -} - bool init(const std::vector& configurations) { TT_LOG_I(TAG, "Init"); for (const auto& configuration: configurations) { @@ -62,7 +36,6 @@ bool init(const std::vector& configurations) { } for (const auto& config: configurations) { - printInfo(dataArray[config.port]); if (config.initMode == InitMode::ByTactility) { if (!start(config.port)) { return false; @@ -83,8 +56,8 @@ bool configure(i2c_port_t port, const i2c_config_t& configuration) { if (data.isStarted) { TT_LOG_E(TAG, "(%d) Cannot reconfigure while interface is started", port); return false; - } else if (!data.configuration.hasMutableConfiguration) { - TT_LOG_E(TAG, "(%d) Mutation not allowed by original configuration", port); + } else if (!data.configuration.isMutable) { + TT_LOG_E(TAG, "(%d) Mutation not allowed because configuration is immutable", port); return false; } else { data.configuration.config = configuration; @@ -97,7 +70,6 @@ bool start(i2c_port_t port) { lock.lock(); Data& data = dataArray[port]; - printInfo(data); Configuration& config = data.configuration; if (data.isStarted) { @@ -137,8 +109,8 @@ bool stop(i2c_port_t port) { Data& data = dataArray[port]; Configuration& config = data.configuration; - if (!config.canReinit) { - TT_LOG_E(TAG, "(%d) Stopping: Not allowed to re-init", port); + if (!config.isMutable) { + TT_LOG_E(TAG, "(%d) Stopping: Not allowed for immutable configuration", port); return false; } diff --git a/TactilityHeadless/Source/hal/spi/Spi.cpp b/TactilityHeadless/Source/hal/spi/Spi.cpp index 0b18e1dd..f41abe15 100644 --- a/TactilityHeadless/Source/hal/spi/Spi.cpp +++ b/TactilityHeadless/Source/hal/spi/Spi.cpp @@ -15,31 +15,6 @@ struct Data { static Data dataArray[SPI_HOST_MAX]; -static const char* toString(InitMode mode) { - switch (mode) { - using enum InitMode; - case ByTactility: - return TT_STRINGIFY(InitMode::ByTactility); - case ByExternal: - return TT_STRINGIFY(InitMode::ByExternal); - case Disabled: - return TT_STRINGIFY(InitMode::Disabled); - } - tt_crash("not implemented"); -} - -static void printInfo(const Data& data) { - TT_LOG_D(TAG, "SPI info for device %d", data.configuration.device); - TT_LOG_D(TAG, " isStarted: %d", data.isStarted); - TT_LOG_D(TAG, " isConfigured: %d", data.isConfigured); - TT_LOG_D(TAG, " initMode: %s", toString(data.configuration.initMode)); - TT_LOG_D(TAG, " canReinit: %d", data.configuration.canReinit); - TT_LOG_D(TAG, " hasMutableConfiguration: %d", data.configuration.hasMutableConfiguration); - TT_LOG_D(TAG, " MISO pin: %d", data.configuration.config.miso_io_num); - TT_LOG_D(TAG, " MOSI pin: %d", data.configuration.config.mosi_io_num); - TT_LOG_D(TAG, " SCLK pin: %d", data.configuration.config.sclk_io_num); -} - bool init(const std::vector& configurations) { TT_LOG_I(TAG, "Init"); for (const auto& configuration: configurations) { @@ -54,7 +29,6 @@ bool init(const std::vector& configurations) { } for (const auto& config: configurations) { - printInfo(dataArray[config.device]); if (config.initMode == InitMode::ByTactility) { if (!start(config.device)) { return false; @@ -75,7 +49,7 @@ bool configure(spi_host_device_t device, const spi_bus_config_t& configuration) if (data.isStarted) { TT_LOG_E(TAG, "(%d) Cannot reconfigure while interface is started", device); return false; - } else if (!data.configuration.hasMutableConfiguration) { + } else if (!data.configuration.isMutable) { TT_LOG_E(TAG, "(%d) Mutation not allowed by original configuration", device); return false; } else { @@ -89,7 +63,6 @@ bool start(spi_host_device_t device) { lock.lock(); Data& data = dataArray[device]; - printInfo(data); if (data.isStarted) { TT_LOG_E(TAG, "(%d) Starting: Already started", device); @@ -129,8 +102,8 @@ bool stop(spi_host_device_t device) { Data& data = dataArray[device]; Configuration& config = data.configuration; - if (!config.canReinit) { - TT_LOG_E(TAG, "(%d) Stopping: Not allowed to re-init", device); + if (!config.isMutable) { + TT_LOG_E(TAG, "(%d) Stopping: Not allowed, immutable", device); return false; }