From 3749017575bddb5bec3ef44045245084e9e33665 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Fri, 6 Feb 2026 00:23:58 +0100 Subject: [PATCH] Fixes and improvements --- Buildscripts/DevicetreeCompiler/source/generator.py | 1 + Modules/hal-device-module/Source/drivers/hal_device.cpp | 6 ++++-- Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp | 2 +- Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Buildscripts/DevicetreeCompiler/source/generator.py b/Buildscripts/DevicetreeCompiler/source/generator.py index 8a85e1fc..8425a2cf 100644 --- a/Buildscripts/DevicetreeCompiler/source/generator.py +++ b/Buildscripts/DevicetreeCompiler/source/generator.py @@ -134,6 +134,7 @@ def write_device_structs(file, device: Device, parent_device: Device, bindings: file.write(f"\t.name = \"{device.node_name}\",\n") # Use original name file.write(f"\t.config = &{config_variable_name},\n") file.write(f"\t.parent = {parent_value},\n") + file.write(f"\t.internal = NULL\n") file.write("};\n\n") # Child devices for child_device in device.devices: diff --git a/Modules/hal-device-module/Source/drivers/hal_device.cpp b/Modules/hal-device-module/Source/drivers/hal_device.cpp index a1fde2d5..e51ba3ea 100644 --- a/Modules/hal-device-module/Source/drivers/hal_device.cpp +++ b/Modules/hal-device-module/Source/drivers/hal_device.cpp @@ -14,7 +14,7 @@ struct HalDevicePrivate { std::shared_ptr halDevice; }; -#define GET_DATA(device) ((struct HalDevicePrivate*)device->internal.driver_data) +#define GET_DATA(device) ((HalDevicePrivate*)device_get_driver_data(device)) static enum HalDeviceType getHalDeviceType(tt::hal::Device::Type type) { switch (type) { @@ -94,7 +94,9 @@ void hal_device_set_device(::Device* kernelDevice, std::shared_ptr halDe static error_t start(Device* device) { LOG_I(TAG, "start %s", device->name); - device->internal.driver_data = new HalDevicePrivate(); + auto hal_device_data = new(std::nothrow) HalDevicePrivate(); + if (hal_device_data == nullptr) return ERROR_OUT_OF_MEMORY; + device_set_driver_data(device, hal_device_data); return ERROR_NONE; } diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp index 9f578b48..b6992805 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp @@ -25,7 +25,7 @@ struct InternalData { }; #define GET_CONFIG(device) ((Esp32I2cConfig*)device->config) -#define GET_DATA(device) ((InternalData*)device->internal.driver_data) +#define GET_DATA(device) ((InternalData*)device_get_driver_data(device)) #define lock(data) mutex_lock(&data->mutex); #define unlock(data) mutex_unlock(&data->mutex); diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp index 84c8f34e..5082dd24 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2s.cpp @@ -31,7 +31,7 @@ struct InternalData { }; #define GET_CONFIG(device) ((Esp32I2sConfig*)device->config) -#define GET_DATA(device) ((InternalData*)device->internal.driver_data) +#define GET_DATA(device) ((InternalData*)device_get_driver_data(device)) #define lock(data) mutex_lock(&data->mutex); #define unlock(data) mutex_unlock(&data->mutex);