Device migrations, new drivers, cleanup (#567)

* **New Features**
  * Added native display support for ST7796, ILI9341, and ST7789 panels across supported boards.
  * Added FT5x06 and FT6x36 touchscreen support.
  * Generic PWM driver
  * ESP32 PWM driver
  * Generic RGB LED driver
  * RGB PWM LED driver
  * RGB GPIO LED driver
  * Implementation of RGB LED for various boards

* **Improvements**
  * Updated board hardware descriptions to use explicit display/touch/backlight device-tree bindings and disabled deprecated HAL usage.
  * Improved display and touch-driver cleanup to prevent stale resources and improve shutdown reliability.
  * Pinned esp-hosted library to a fixed version
 
* **Deletions**
  * Obsolete placeholder display
  * Legacy ILI9488 support.
  * ESP32-specific LEDC PWM implementation
This commit is contained in:
Ken Van Hoeylandt
2026-07-16 22:47:26 +02:00
committed by GitHub
parent 6fb2bb736c
commit 3b5a401594
175 changed files with 4218 additions and 1462 deletions
@@ -0,0 +1,147 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/gpio_backlight.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/backlight.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/drivers/gpio_descriptor.h>
#include <tactility/log.h>
#include <tactility/module.h>
#include <new>
#define TAG "GpioBacklight"
#define GET_CONFIG(device) (static_cast<const GpioBacklightConfig*>((device)->config))
#define GET_INTERNAL(device) (static_cast<GpioBacklightInternal*>(device_get_driver_data(device)))
extern "C" {
struct GpioBacklightInternal {
GpioDescriptor* descriptor;
bool enabled;
};
// region GpioBacklightApi
static error_t enable(Device* device) {
auto* internal = GET_INTERNAL(device);
error_t error = gpio_descriptor_set_level(internal->descriptor, true);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable backlight");
return error;
}
internal->enabled = true;
return ERROR_NONE;
}
static error_t disable(Device* device) {
auto* internal = GET_INTERNAL(device);
error_t error = gpio_descriptor_set_level(internal->descriptor, false);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to disable backlight");
return error;
}
internal->enabled = false;
return ERROR_NONE;
}
// endregion
// region BacklightApi
static error_t gpio_backlight_set_brightness(Device* device, uint8_t brightness) {
return brightness > 0 ? enable(device) : disable(device);
}
static error_t gpio_backlight_set_brightness_default(Device* device) {
return GET_CONFIG(device)->enabled ? enable(device) : disable(device);
}
static error_t gpio_backlight_get_brightness(Device* device, uint8_t* out_brightness) {
*out_brightness = GET_INTERNAL(device)->enabled ? 1 : 0;
return ERROR_NONE;
}
static uint8_t gpio_backlight_get_min_brightness(Device*) {
return 0;
}
static uint8_t gpio_backlight_get_max_brightness(Device*) {
return 1;
}
// endregion
static constexpr BacklightApi GPIO_BACKLIGHT_API = {
.set_brightness = gpio_backlight_set_brightness,
.set_brightness_default = gpio_backlight_set_brightness_default,
.get_brightness = gpio_backlight_get_brightness,
.get_min_brightness = gpio_backlight_get_min_brightness,
.get_max_brightness = gpio_backlight_get_max_brightness,
};
// region Driver lifecycle
static error_t start(Device* device) {
const auto* config = GET_CONFIG(device);
auto* descriptor = gpio_descriptor_acquire(config->pin.gpio_controller, config->pin.pin, GPIO_OWNER_GPIO);
if (descriptor == nullptr) {
LOG_E(TAG, "Failed to acquire GPIO descriptor");
return ERROR_RESOURCE;
}
if (gpio_descriptor_set_flags(descriptor, config->pin.flags | GPIO_FLAG_DIRECTION_OUTPUT) != ERROR_NONE) {
LOG_E(TAG, "Failed to configure backlight pin as output");
gpio_descriptor_release(descriptor);
return ERROR_RESOURCE;
}
auto* internal = new(std::nothrow) GpioBacklightInternal { .descriptor = descriptor, .enabled = false };
if (internal == nullptr) {
gpio_descriptor_release(descriptor);
return ERROR_OUT_OF_MEMORY;
}
device_set_driver_data(device, internal);
if (gpio_backlight_set_brightness_default(device) != ERROR_NONE) {
// Allowed to fail, we don't care about the result
LOG_W(TAG, "gpio_backlight_set_brightness_default(%s) failed", device->name);
}
return ERROR_NONE;
}
static error_t stop(Device* device) {
disable(device); // Allowed to fail, we don't care about the result
auto* internal = GET_INTERNAL(device);
gpio_descriptor_release(internal->descriptor);
device_set_driver_data(device, nullptr);
delete internal;
return ERROR_NONE;
}
// endregion
extern Module root_module;
Driver gpio_backlight_driver = {
.name = "gpio_backlight",
.compatible = (const char*[]) { "gpio-backlight", nullptr },
.start_device = start,
.stop_device = stop,
.api = &GPIO_BACKLIGHT_API,
.device_type = &BACKLIGHT_TYPE,
.owner = &root_module,
.internal = nullptr
};
}
+1 -1
View File
@@ -62,7 +62,7 @@ extern Module root_module;
Driver gpio_hog_driver = {
.name = "gpio_hog",
.compatible = (const char*[]) { "tactility,gpio-hog", nullptr },
.compatible = (const char*[]) { "gpio-hog", nullptr },
.start_device = start,
.stop_device = stop,
.api = nullptr,
@@ -1,26 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/pointer_placeholder.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/pointer.h>
#include <tactility/module.h>
extern "C" {
static error_t start(Device*) { return ERROR_NONE; }
static error_t stop(Device*) { return ERROR_NONE; }
extern Module root_module;
Driver pointer_placeholder_driver = {
.name = "pointer_placeholder",
.compatible = (const char*[]) { "pointer-placeholder", nullptr },
.start_device = start,
.stop_device = stop,
.api = nullptr,
.device_type = &POINTER_TYPE,
.owner = &root_module,
.internal = nullptr
};
}
+58
View File
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/pwm.h>
#include <tactility/device.h>
#define PWM_DRIVER_API(driver) ((struct PwmApi*)driver->api)
extern "C" {
error_t pwm_set_period(Device* device, uint32_t period_ns) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->set_period(device, period_ns);
}
error_t pwm_get_period(Device* device, uint32_t* period_ns) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->get_period(device, period_ns);
}
error_t pwm_set_duty(Device* device, uint32_t duty_ns) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->set_duty(device, duty_ns);
}
error_t pwm_get_duty(Device* device, uint32_t* duty_ns) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->get_duty(device, duty_ns);
}
error_t pwm_set_inverted(Device* device, bool inverted) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->set_inverted(device, inverted);
}
error_t pwm_is_inverted(Device* device, bool* inverted) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->is_inverted(device, inverted);
}
error_t pwm_enable(Device* device) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->enable(device);
}
error_t pwm_disable(Device* device) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->disable(device);
}
error_t pwm_is_enabled(Device* device, bool* enabled) {
const auto* driver = device_get_driver(device);
return PWM_DRIVER_API(driver)->is_enabled(device, enabled);
}
const DeviceType PWM_TYPE {
.name = "pwm"
};
}
@@ -0,0 +1,142 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/pwm_backlight.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/backlight.h>
#include <tactility/drivers/pwm.h>
#include <tactility/log.h>
#include <tactility/module.h>
#include <new>
#define TAG "PwmBacklight"
#define GET_CONFIG(device) (static_cast<const PwmBacklightConfig*>((device)->config))
#define GET_INTERNAL(device) (static_cast<PwmBacklightInternal*>(device_get_driver_data(device)))
extern "C" {
struct PwmBacklightInternal {
uint8_t brightness;
};
// region BacklightApi
static error_t apply_brightness(Device* device, uint8_t brightness) {
const auto* config = GET_CONFIG(device);
if (brightness <= config->brightness_range.min) {
error_t error = pwm_disable(config->pwm);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to disable PWM");
return error;
}
return ERROR_NONE;
}
if (brightness > config->brightness_range.max) {
brightness = config->brightness_range.max;
}
uint32_t period_ns;
error_t error = pwm_get_period(config->pwm, &period_ns);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to get PWM period");
return error;
}
uint8_t level = brightness - config->brightness_range.min;
uint8_t range = config->brightness_range.max - config->brightness_range.min;
uint32_t duty_ns = (uint32_t)(((uint64_t)level * period_ns) / range);
error = pwm_set_duty(config->pwm, duty_ns);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to set PWM duty");
return error;
}
return pwm_enable(config->pwm);
}
static error_t pwm_backlight_set_brightness(Device* device, uint8_t brightness) {
error_t error = apply_brightness(device, brightness);
if (error != ERROR_NONE) {
return error;
}
GET_INTERNAL(device)->brightness = brightness;
return ERROR_NONE;
}
static error_t pwm_backlight_set_brightness_default(Device* device) {
return pwm_backlight_set_brightness(device, GET_CONFIG(device)->brightness_default);
}
static error_t pwm_backlight_get_brightness(Device* device, uint8_t* out_brightness) {
*out_brightness = GET_INTERNAL(device)->brightness;
return ERROR_NONE;
}
static uint8_t pwm_backlight_get_min_brightness(Device* device) {
return GET_CONFIG(device)->brightness_range.min;
}
static uint8_t pwm_backlight_get_max_brightness(Device* device) {
return GET_CONFIG(device)->brightness_range.max;
}
// endregion
static constexpr BacklightApi PWM_BACKLIGHT_API = {
.set_brightness = pwm_backlight_set_brightness,
.set_brightness_default = pwm_backlight_set_brightness_default,
.get_brightness = pwm_backlight_get_brightness,
.get_min_brightness = pwm_backlight_get_min_brightness,
.get_max_brightness = pwm_backlight_get_max_brightness,
};
// region Driver lifecycle
static error_t start(Device* device) {
const auto* config = GET_CONFIG(device);
if (config->brightness_range.max <= config->brightness_range.min) {
return ERROR_INVALID_ARGUMENT;
}
auto* internal = new(std::nothrow) PwmBacklightInternal { .brightness = GET_CONFIG(device)->brightness_range.min };
if (internal == nullptr) {
return ERROR_OUT_OF_MEMORY;
}
device_set_driver_data(device, internal);
pwm_backlight_set_brightness_default(device); // Allowed to fail, we don't care about the result
return ERROR_NONE;
}
static error_t stop(Device* device) {
pwm_backlight_set_brightness(device, GET_CONFIG(device)->brightness_range.min); // Allowed to fail, we don't care about the result
auto* internal = GET_INTERNAL(device);
device_set_driver_data(device, nullptr);
delete internal;
return ERROR_NONE;
}
// endregion
extern Module root_module;
Driver pwm_backlight_driver = {
.name = "pwm_backlight",
.compatible = (const char*[]) { "pwm-backlight", nullptr },
.start_device = start,
.stop_device = stop,
.api = &PWM_BACKLIGHT_API,
.device_type = &BACKLIGHT_TYPE,
.owner = &root_module,
.internal = nullptr
};
}
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/rgb_led.h>
#include <tactility/device.h>
#define RGB_LED_DRIVER_API(driver) ((struct RgbLedApi*)driver->api)
extern "C" {
error_t rgb_led_set_color(Device* device, RgbLedColor color) {
const auto* driver = device_get_driver(device);
return RGB_LED_DRIVER_API(driver)->set_color(device, color);
}
error_t rgb_led_get_color(Device* device, RgbLedColor* out_color) {
const auto* driver = device_get_driver(device);
return RGB_LED_DRIVER_API(driver)->get_color(device, out_color);
}
error_t rgb_led_enable(Device* device) {
const auto* driver = device_get_driver(device);
return RGB_LED_DRIVER_API(driver)->enable(device);
}
void rgb_led_disable(Device* device) {
const auto* driver = device_get_driver(device);
RGB_LED_DRIVER_API(driver)->disable(device);
}
const DeviceType RGB_LED_TYPE {
.name = "rgb_led"
};
}
@@ -0,0 +1,171 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/rgb_led_gpio.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/drivers/gpio_descriptor.h>
#include <tactility/log.h>
#include <tactility/module.h>
#include <new>
#define TAG "RgbLedGpio"
#define GET_CONFIG(device) (static_cast<const RgbLedGpioConfig*>((device)->config))
#define GET_INTERNAL(device) (static_cast<RgbLedGpioInternal*>(device_get_driver_data(device)))
extern "C" {
struct RgbLedGpioInternal {
GpioDescriptor* descriptor_red;
GpioDescriptor* descriptor_green;
GpioDescriptor* descriptor_blue;
RgbLedColor color;
bool enabled;
};
// region RgbLedApi
static error_t apply_levels(Device* device) {
auto* internal = GET_INTERNAL(device);
bool on = internal->enabled;
error_t error = gpio_descriptor_set_level(internal->descriptor_red, on && internal->color.r > 0);
if (error == ERROR_NONE) {
error = gpio_descriptor_set_level(internal->descriptor_green, on && internal->color.g > 0);
}
if (error == ERROR_NONE) {
error = gpio_descriptor_set_level(internal->descriptor_blue, on && internal->color.b > 0);
}
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to apply LED levels");
}
return error;
}
static error_t rgb_led_gpio_set_color(Device* device, RgbLedColor color) {
GET_INTERNAL(device)->color = color;
return apply_levels(device);
}
static error_t rgb_led_gpio_get_color(Device* device, RgbLedColor* out_color) {
*out_color = GET_INTERNAL(device)->color;
return ERROR_NONE;
}
static error_t rgb_led_gpio_enable(Device* device) {
GET_INTERNAL(device)->enabled = true;
return apply_levels(device);
}
static void rgb_led_gpio_disable(Device* device) {
GET_INTERNAL(device)->enabled = false;
apply_levels(device); // Allowed to fail, we don't care about the result
}
// endregion
static constexpr RgbLedApi RGB_LED_GPIO_API = {
.set_color = rgb_led_gpio_set_color,
.get_color = rgb_led_gpio_get_color,
.enable = rgb_led_gpio_enable,
.disable = rgb_led_gpio_disable,
};
// region Driver lifecycle
static error_t start(Device* device) {
const auto* config = GET_CONFIG(device);
auto* descriptor_red = gpio_descriptor_acquire(config->pin_red.gpio_controller, config->pin_red.pin, GPIO_OWNER_GPIO);
if (descriptor_red == nullptr) {
LOG_E(TAG, "Failed to acquire red GPIO descriptor");
return ERROR_RESOURCE;
}
auto* descriptor_green = gpio_descriptor_acquire(config->pin_green.gpio_controller, config->pin_green.pin, GPIO_OWNER_GPIO);
if (descriptor_green == nullptr) {
LOG_E(TAG, "Failed to acquire green GPIO descriptor");
gpio_descriptor_release(descriptor_red);
return ERROR_RESOURCE;
}
auto* descriptor_blue = gpio_descriptor_acquire(config->pin_blue.gpio_controller, config->pin_blue.pin, GPIO_OWNER_GPIO);
if (descriptor_blue == nullptr) {
LOG_E(TAG, "Failed to acquire blue GPIO descriptor");
gpio_descriptor_release(descriptor_red);
gpio_descriptor_release(descriptor_green);
return ERROR_RESOURCE;
}
bool ok = gpio_descriptor_set_flags(descriptor_red, config->pin_red.flags | GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE &&
gpio_descriptor_set_flags(descriptor_green, config->pin_green.flags | GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE &&
gpio_descriptor_set_flags(descriptor_blue, config->pin_blue.flags | GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE;
if (!ok) {
LOG_E(TAG, "Failed to configure LED pins as outputs");
gpio_descriptor_release(descriptor_red);
gpio_descriptor_release(descriptor_green);
gpio_descriptor_release(descriptor_blue);
return ERROR_RESOURCE;
}
auto* internal = new(std::nothrow) RgbLedGpioInternal {
.descriptor_red = descriptor_red,
.descriptor_green = descriptor_green,
.descriptor_blue = descriptor_blue,
.color = config->default_color,
.enabled = false
};
if (internal == nullptr) {
gpio_descriptor_release(descriptor_red);
gpio_descriptor_release(descriptor_green);
gpio_descriptor_release(descriptor_blue);
return ERROR_OUT_OF_MEMORY;
}
device_set_driver_data(device, internal);
if (config->enabled) {
if (rgb_led_gpio_enable(device) != ERROR_NONE) {
// Allowed to fail, we don't care about the result
LOG_W(TAG, "led_gpio_enable(%s) failed", device->name);
}
} else {
if (apply_levels(device) != ERROR_NONE) {
// Allowed to fail, we don't care about the result
LOG_W(TAG, "led_gpio_apply_levels(%s) failed", device->name);
}
}
return ERROR_NONE;
}
static error_t stop(Device* device) {
rgb_led_gpio_disable(device);
auto* internal = GET_INTERNAL(device);
gpio_descriptor_release(internal->descriptor_red);
gpio_descriptor_release(internal->descriptor_green);
gpio_descriptor_release(internal->descriptor_blue);
device_set_driver_data(device, nullptr);
delete internal;
return ERROR_NONE;
}
// endregion
extern Module root_module;
Driver rgb_led_gpio_driver = {
.name = "rgb_led_gpio",
.compatible = (const char*[]) { "rgb-led-gpio", nullptr },
.start_device = start,
.stop_device = stop,
.api = &RGB_LED_GPIO_API,
.device_type = &RGB_LED_TYPE,
.owner = &root_module,
.internal = nullptr
};
}
@@ -0,0 +1,157 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/rgb_led_pwm.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/pwm.h>
#include <tactility/log.h>
#include <tactility/module.h>
#include <new>
#define TAG "RgbLedPwm"
#define GET_CONFIG(device) (static_cast<const RgbLedPwmConfig*>((device)->config))
#define GET_INTERNAL(device) (static_cast<RgbLedPwmInternal*>(device_get_driver_data(device)))
extern "C" {
struct RgbLedPwmInternal {
RgbLedColor color;
bool enabled;
};
// region RgbLedApi
static error_t apply_channel(Device* pwm_device, uint8_t component) {
uint32_t period_ns;
error_t error = pwm_get_period(pwm_device, &period_ns);
if (error != ERROR_NONE) {
return error;
}
uint32_t duty_ns = (uint32_t)(((uint64_t)component * period_ns) / 255);
return pwm_set_duty(pwm_device, duty_ns);
}
static error_t apply_color(Device* device) {
const auto* config = GET_CONFIG(device);
const auto* internal = GET_INTERNAL(device);
error_t error = apply_channel(config->pwm_red, internal->color.r);
if (error == ERROR_NONE) {
error = apply_channel(config->pwm_green, internal->color.g);
}
if (error == ERROR_NONE) {
error = apply_channel(config->pwm_blue, internal->color.b);
}
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to apply LED color");
}
return error;
}
static error_t rgb_led_pwm_set_color(Device* device, RgbLedColor color) {
GET_INTERNAL(device)->color = color;
return apply_color(device);
}
static error_t rgb_led_pwm_get_color(Device* device, RgbLedColor* out_color) {
*out_color = GET_INTERNAL(device)->color;
return ERROR_NONE;
}
static error_t rgb_led_pwm_enable(Device* device) {
const auto* config = GET_CONFIG(device);
error_t error = pwm_enable(config->pwm_red);
if (error != ERROR_NONE) {
return error;
}
error = pwm_enable(config->pwm_green);
if (error != ERROR_NONE) {
pwm_disable(config->pwm_red);
return error;
}
error = pwm_enable(config->pwm_blue);
if (error != ERROR_NONE) {
pwm_disable(config->pwm_green);
pwm_disable(config->pwm_red);
LOG_E(TAG, "Failed to enable LED");
return error;
}
GET_INTERNAL(device)->enabled = true;
return ERROR_NONE;
}
static void rgb_led_pwm_disable(Device* device) {
const auto* config = GET_CONFIG(device);
GET_INTERNAL(device)->enabled = false;
pwm_disable(config->pwm_red);
pwm_disable(config->pwm_green);
pwm_disable(config->pwm_blue);
}
// endregion
static constexpr RgbLedApi RGB_LED_PWM_API = {
.set_color = rgb_led_pwm_set_color,
.get_color = rgb_led_pwm_get_color,
.enable = rgb_led_pwm_enable,
.disable = rgb_led_pwm_disable,
};
// region Driver lifecycle
static error_t start(Device* device) {
const auto* config = GET_CONFIG(device);
auto* internal = new(std::nothrow) RgbLedPwmInternal {
.color = config->default_color,
.enabled = false
};
if (internal == nullptr) {
return ERROR_OUT_OF_MEMORY;
}
device_set_driver_data(device, internal);
error_t error = apply_color(device);
if (error != ERROR_NONE) {
device_set_driver_data(device, nullptr);
delete internal;
return error;
}
if (config->enabled) {
rgb_led_pwm_enable(device); // Allowed to fail, we don't care about the result
}
return ERROR_NONE;
}
static error_t stop(Device* device) {
rgb_led_pwm_disable(device);
auto* internal = GET_INTERNAL(device);
device_set_driver_data(device, nullptr);
delete internal;
return ERROR_NONE;
}
// endregion
extern Module root_module;
Driver rgb_led_pwm_driver = {
.name = "rgb_led_pwm",
.compatible = (const char*[]) { "rgb-led-pwm", nullptr },
.start_device = start,
.stop_device = stop,
.api = &RGB_LED_PWM_API,
.device_type = &RGB_LED_TYPE,
.owner = &root_module,
.internal = nullptr
};
}
@@ -1,28 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/spi_peripheral.h>
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
static error_t start(Device*) { return ERROR_NONE; }
static error_t stop(Device*) { return ERROR_NONE; }
const DeviceType SPI_PERIPHERAL_TYPE = {
.name = "spi_peripheral"
};
extern Module root_module;
Driver spi_peripheral_driver = {
.name = "spi_peripheral",
.compatible = (const char*[]) { "spi-peripheral", nullptr },
.start_device = start,
.stop_device = stop,
.api = nullptr,
.device_type = &SPI_PERIPHERAL_TYPE,
.owner = &root_module,
.internal = nullptr
};
}