Create DTS files for all devices and implement I2C changes (#466)

Devictree changes:
- Create DTS files for all remaining devices
- Update corresponding `devicetree.yaml`
- Remove `i2c` configuration from corresponding `tt::hal::Configuration`

Apps & HAL:
- Removed I2C Settings (we'll make a new one later after I rework that part of the HAL)
- Delete TactilityC GPIO and I2C functionality
- Delete Related SystemEvent types
- Refactor `tt::hal::i2c` to only use `struct Device*` wrapping

Scripting:
- Fix DevicetreeCompiler boolean parsing
- Create `build-all.py`
This commit is contained in:
Ken Van Hoeylandt
2026-01-29 22:01:19 +01:00
committed by GitHub
parent 71f8369377
commit 87ca888bb4
139 changed files with 1226 additions and 1750 deletions
@@ -41,9 +41,6 @@ struct Configuration {
std::function<DeviceVector()> createDevices = [] { return std::vector<std::shared_ptr<Device>>(); };
/** A list of I2C interface configurations */
const std::vector<i2c::Configuration> i2c = {};
/** A list of SPI interface configurations */
const std::vector<spi::Configuration> spi = {};
+1 -24
View File
@@ -12,36 +12,13 @@ namespace tt::hal::i2c {
constexpr TickType_t defaultTimeout = 10 / portTICK_PERIOD_MS;
enum class InitMode {
ByTactility, // Tactility will initialize it in the correct bootup phase
Disabled // Not initialized by default
};
struct Configuration {
std::string name;
/** The port to operate on */
i2c_port_t port;
/** Whether this bus should be initialized when device starts up */
InitMode initMode;
/**
* 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;
};
enum class Status {
Started,
Stopped,
Unknown
};
/**
* Start the bus for the specified port.
* Devices might be started automatically at boot if their HAL configuration requires it.
*/
/** Start the bus for the specified port. */
bool start(i2c_port_t port);
/** Stop the bus for the specified port. */
@@ -8,12 +8,6 @@ namespace tt::kernel {
enum class SystemEvent {
BootInitHalBegin,
BootInitHalEnd,
BootInitI2cBegin,
BootInitI2cEnd,
BootInitSpiBegin,
BootInitSpiEnd,
BootInitUartBegin,
BootInitUartEnd,
BootSplash,
/** Gained IP address */
NetworkConnected,
@@ -1,15 +0,0 @@
#pragma once
#include "Tactility/hal/i2c/I2c.h"
#include <vector>
namespace tt::hal::i2c {
/**
* Called by main HAL init to ready the internal state of the I2C HAL.
* @param[in] configurations HAL configuration for a board
* @return true on success
*/
bool init(const std::vector<i2c::Configuration>& configurations);
}
-2
View File
@@ -87,7 +87,6 @@ namespace app {
namespace fileselection { extern const AppManifest manifest; }
namespace gpssettings { extern const AppManifest manifest; }
namespace i2cscanner { extern const AppManifest manifest; }
namespace i2csettings { extern const AppManifest manifest; }
namespace imageviewer { extern const AppManifest manifest; }
namespace inputdialog { extern const AppManifest manifest; }
namespace launcher { extern const AppManifest manifest; }
@@ -139,7 +138,6 @@ static void registerInternalApps() {
addAppManifest(app::files::manifest);
addAppManifest(app::fileselection::manifest);
addAppManifest(app::i2cscanner::manifest);
addAppManifest(app::i2csettings::manifest);
addAppManifest(app::imageviewer::manifest);
addAppManifest(app::inputdialog::manifest);
addAppManifest(app::launcher::manifest);
@@ -1,103 +0,0 @@
#include "Tactility/lvgl/Style.h"
#include "Tactility/lvgl/Toolbar.h"
#include <Tactility/Assets.h>
#include <Tactility/hal/i2c/I2c.h>
#include <Tactility/Tactility.h>
#include <lvgl.h>
namespace tt::app::i2csettings {
static void onSwitchToggled(lv_event_t* event) {
lv_event_code_t code = lv_event_get_code(event);
auto* state_switch = static_cast<lv_obj_t*>(lv_event_get_target(event));
const hal::i2c::Configuration* configuration = static_cast<hal::i2c::Configuration*>(lv_event_get_user_data(event));
if (code == LV_EVENT_VALUE_CHANGED) {
bool should_enable = lv_obj_get_state(state_switch) & LV_STATE_CHECKED;
bool is_enabled = hal::i2c::isStarted(configuration->port);
if (is_enabled && !should_enable) {
if (!hal::i2c::stop(configuration->port)) {
lv_obj_add_state(state_switch, LV_STATE_CHECKED);
}
} else if (!is_enabled && should_enable) {
if (!hal::i2c::start(configuration->port)) {
lv_obj_remove_state(state_switch, LV_STATE_CHECKED);
}
}
}
}
static void show(lv_obj_t* parent, const hal::i2c::Configuration& configuration) {
auto* card = lv_obj_create(parent);
lv_obj_set_height(card, LV_SIZE_CONTENT);
lv_obj_set_style_margin_hor(card, 16, 0);
lv_obj_set_style_margin_bottom(card, 16, 0);
lv_obj_set_width(card, LV_PCT(100));
auto* port_label = lv_label_create(card);
const char* name = configuration.name.empty() ? "Unnamed" : configuration.name.c_str();
lv_label_set_text_fmt(port_label, "%s (port %d)", name, configuration.port);
// On-off switch
if (configuration.isMutable) {
auto* state_switch = lv_switch_create(card);
lv_obj_align(state_switch, LV_ALIGN_TOP_RIGHT, 0, 0);
if (hal::i2c::isStarted(configuration.port)) {
lv_obj_add_state(state_switch, LV_STATE_CHECKED);
}
lv_obj_add_event_cb(state_switch, onSwitchToggled, LV_EVENT_VALUE_CHANGED, (void*) &configuration);
}
// SDA label
auto* sda_pin_label = lv_label_create(card);
const char* sda_pullup_text = configuration.config.sda_pullup_en ? "yes" : "no";
lv_label_set_text_fmt(sda_pin_label, "SDA: pin %d, pullup: %s", configuration.config.sda_io_num, sda_pullup_text );
lv_obj_align_to(sda_pin_label, port_label, LV_ALIGN_OUT_BOTTOM_LEFT, 16, 8);
// SCL label
auto* scl_pin_label = lv_label_create(card);
const char* scl_pullup_text = configuration.config.scl_pullup_en ? "yes" : "no";
lv_label_set_text_fmt(scl_pin_label, "SCL: pin %d, pullup: %s", configuration.config.scl_io_num, scl_pullup_text);
lv_obj_align_to(scl_pin_label, sda_pin_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
// Frequency:
if (configuration.config.mode == I2C_MODE_MASTER) {
auto* frequency_label = lv_label_create(card);
lv_label_set_text_fmt(frequency_label, "Frequency: %lu Hz", configuration.config.master.clk_speed);
lv_obj_align_to(frequency_label, scl_pin_label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
}
}
class I2cSettingsApp : public App {
void onShow(AppContext& app, lv_obj_t* parent) override {
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_row(parent, 0, LV_STATE_DEFAULT);
lvgl::toolbar_create(parent, app);
auto* wrapper = lv_obj_create(parent);
lv_obj_set_width(wrapper, LV_PCT(100));
lv_obj_set_flex_grow(wrapper, 1);
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_all(wrapper, LV_STATE_DEFAULT, 0);
lv_obj_set_style_pad_gap(wrapper, LV_STATE_DEFAULT, 0);
lvgl::obj_set_style_bg_invisible(wrapper);
for (const auto& configuration: getConfiguration()->hardware->i2c) {
show(wrapper, configuration);
}
}
};
extern const AppManifest manifest = {
.appId = "I2cSettings",
.appName = "I2C",
.appIcon = TT_ASSETS_APP_ICON_I2C_SETTINGS,
.appCategory = Category::Settings,
.createApp = create<I2cSettingsApp>
};
} // namespace
-11
View File
@@ -3,8 +3,6 @@
#include <tactility/check.h>
#include <Tactility/hal/Configuration.h>
#include <Tactility/hal/Device.h>
#include <Tactility/hal/gps/GpsInit.h>
#include <Tactility/hal/i2c/I2cInit.h>
#include <Tactility/hal/power/PowerDevice.h>
#include <Tactility/hal/spi/SpiInit.h>
#include <Tactility/hal/uart/UartInit.h>
@@ -68,17 +66,8 @@ static void startDisplays() {
void init(const Configuration& configuration) {
kernel::publishSystemEvent(kernel::SystemEvent::BootInitHalBegin);
kernel::publishSystemEvent(kernel::SystemEvent::BootInitI2cBegin);
check(i2c::init(configuration.i2c), "I2C init failed");
kernel::publishSystemEvent(kernel::SystemEvent::BootInitI2cEnd);
kernel::publishSystemEvent(kernel::SystemEvent::BootInitSpiBegin);
check(spi::init(configuration.spi), "SPI init failed");
kernel::publishSystemEvent(kernel::SystemEvent::BootInitSpiEnd);
kernel::publishSystemEvent(kernel::SystemEvent::BootInitUartBegin);
check(uart::init(configuration.uart), "UART init failed");
kernel::publishSystemEvent(kernel::SystemEvent::BootInitUartEnd);
if (configuration.initBoot != nullptr) {
check(configuration.initBoot(), "Init boot failed");
+39 -198
View File
@@ -13,49 +13,15 @@
namespace tt::hal::i2c {
static const auto LOGGER = Logger("I2C");
struct Data {
Mutex mutex;
bool isConfigured = false;
Device* device = nullptr;
#ifdef ESP_PLATFORM
Esp32I2cConfig config = {
.port = I2C_NUM_0,
.clockFrequency = 0,
.pinSda = 0,
.pinScl = 0,
.pinSdaPullUp = false,
.pinSclPullUp = false
};
#endif
class NoLock final : public tt::Lock {
bool lock(TickType_t timeout) const override { return true; }
void unlock() const override { /* NO-OP */ }
};
static Data dataArray[I2C_NUM_MAX];
static NoLock NO_LOCK;
Device* findDevice(i2c_port_t port) {
#ifdef ESP_PLATFORM
void registerDriver(Data& data, const Configuration& configuration) {
// Should only be called on init
check(data.device == nullptr);
data.config.port = configuration.port;
data.config.clockFrequency = configuration.config.master.clk_speed;
data.config.pinSda = configuration.config.sda_io_num;
data.config.pinScl = configuration.config.scl_io_num;
data.config.pinSdaPullUp = configuration.config.sda_pullup_en;
data.config.pinSclPullUp = configuration.config.scl_pullup_en;
data.device = new Device();
data.device->name = configuration.name.c_str();
data.device->config = &data.config;
data.device->parent = nullptr;
if (device_construct_add(data.device, "espressif,esp32-i2c") == ERROR_NONE) {
data.isConfigured = true;
}
}
Device* findExistingKernelDevice(i2c_port_t port) {
struct Params {
i2c_port_t port;
Device* device;
@@ -80,192 +46,67 @@ Device* findExistingKernelDevice(i2c_port_t port) {
});
return params.device;
}
#endif
bool init(const std::vector<Configuration>& configurations) {
LOGGER.info("Init");
#ifdef ESP_PLATFORM
bool found_existing = false;
for (int port = 0; port < I2C_NUM_MAX; ++port) {
auto native_port = static_cast<i2c_port_t>(port);
auto existing_device = findExistingKernelDevice(native_port);
if (existing_device != nullptr) {
LOGGER.info("Initialized port {} with existing kernel device", port);
auto& data = dataArray[port];
data.device = existing_device;
data.isConfigured = true;
memcpy(&data.config, existing_device->config, sizeof(Esp32I2cConfig));
// Ensure we don't initialize
found_existing = true;
}
}
// Nothing found in HAL, so try configuration
for (const auto& configuration: configurations) {
check(!found_existing, "hal::Configuration specifies I2C, but I2C was already initialized by devicetree. Remove the hal::Configuration I2C entries!");
if (configuration.config.mode != I2C_MODE_MASTER) {
LOGGER.error("Currently only master mode is supported");
return false;
}
Data& data = dataArray[configuration.port];
registerDriver(data, configuration);
}
if (!found_existing) {
for (const auto& config: configurations) {
if (config.initMode == InitMode::ByTactility) {
if (!start(config.port)) {
return false;
}
}
}
}
#endif
return true;
}
bool start(i2c_port_t port) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
Data& data = dataArray[port];
if (!data.isConfigured) {
LOGGER.error("({}) Starting: Not configured", static_cast<int>(port));
return false;
}
check(data.device);
error_t error = device_start(data.device);
if (error != ERROR_NONE) {
LOGGER.error("Failed to start device {}: {}", data.device->name, error_to_string(error));
return false;
}
return true;
#else
return false;
#endif
}
bool stop(i2c_port_t port) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
Data& data = dataArray[port];
if (!dataArray[port].isConfigured) return false;
return device_stop(data.device) == ERROR_NONE;
#else
return false;
#endif
}
bool isStarted(i2c_port_t port) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return device_is_ready(dataArray[port].device);
#else
return false;
#endif
}
const char* getName(i2c_port_t port) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return nullptr;
return dataArray[port].device->name;
#else
return nullptr;
#endif
}
bool isStarted(i2c_port_t port) {
auto* device = findDevice(port);
if (device == nullptr) return false;
return device_is_ready(device);
}
const char* getName(i2c_port_t port) {
auto* device = findDevice(port);
if (device == nullptr) return nullptr;
return device->name;
}
bool masterRead(i2c_port_t port, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return i2c_controller_read(dataArray[port].device, address, data, dataSize, timeout) == ERROR_NONE;
#else
return false;
#endif
auto* device = findDevice(port);
if (device == nullptr) return false;
return i2c_controller_read(device, address, data, dataSize, timeout) == ERROR_NONE;
}
bool masterReadRegister(i2c_port_t port, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return i2c_controller_read_register(dataArray[port].device, address, reg, data, dataSize, timeout) == ERROR_NONE;
#else
return false;
#endif
auto* device = findDevice(port);
if (device == nullptr) return false;
return i2c_controller_read_register(device, address, reg, data, dataSize, timeout) == ERROR_NONE;
}
bool masterWrite(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return i2c_controller_write(dataArray[port].device, address, data, dataSize, timeout) == ERROR_NONE;
#else
return false;
#endif
auto* device = findDevice(port);
if (device == nullptr) return false;
return i2c_controller_write(device, address, data, dataSize, timeout) == ERROR_NONE;
}
bool masterWriteRegister(i2c_port_t port, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return i2c_controller_write_register(dataArray[port].device, address, reg, data, dataSize, timeout) == ERROR_NONE;
#else
return false;
#endif
auto* device = findDevice(port);
if (device == nullptr) return false;
return i2c_controller_write_register(device, address, reg, data, dataSize, timeout) == ERROR_NONE;
}
bool masterWriteRegisterArray(i2c_port_t port, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return i2c_controller_write_register_array(dataArray[port].device, address, data, dataSize, timeout) == ERROR_NONE;
#else
return false;
#endif
auto* device = findDevice(port);
if (device == nullptr) return false;
return i2c_controller_write_register_array(device, address, data, dataSize, timeout) == ERROR_NONE;
}
bool masterWriteRead(i2c_port_t port, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return i2c_controller_write_read(dataArray[port].device, address, writeData, writeDataSize, readData, readDataSize, timeout) == ERROR_NONE;
#else
return false;
#endif
auto* device = findDevice(port);
if (device == nullptr) return false;
return i2c_controller_write_read(device, address, writeData, writeDataSize, readData, readDataSize, timeout) == ERROR_NONE;
}
bool masterHasDeviceAtAddress(i2c_port_t port, uint8_t address, TickType_t timeout) {
#ifdef ESP_PLATFORM
auto lock = getLock(port).asScopedLock();
lock.lock();
if (!dataArray[port].isConfigured) return false;
return i2c_controller_has_device_at_address(dataArray[port].device, address, timeout) == ERROR_NONE;
#else
return false;
#endif
auto* device = findDevice(port);
if (device == nullptr) return false;
return i2c_controller_has_device_at_address(device, address, timeout) == ERROR_NONE;
}
Lock& getLock(i2c_port_t port) {
return dataArray[port].mutex;
return NO_LOCK;
}
} // namespace
-12
View File
@@ -28,18 +28,6 @@ static const char* getEventName(SystemEvent event) {
return TT_STRINGIFY(BootInitHalBegin);
case BootInitHalEnd:
return TT_STRINGIFY(BootInitHalEnd);
case BootInitI2cBegin:
return TT_STRINGIFY(BootInitI2cBegin);
case BootInitI2cEnd:
return TT_STRINGIFY(BootInitI2cEnd);
case BootInitSpiBegin:
return TT_STRINGIFY(BootInitSpiBegin);
case BootInitSpiEnd:
return TT_STRINGIFY(BootInitSpiEnd);
case BootInitUartBegin:
return TT_STRINGIFY(BootInitUartBegin);
case BootInitUartEnd:
return TT_STRINGIFY(BootInitUartEnd);
case BootSplash:
return TT_STRINGIFY(BootSplash);
case NetworkConnected: