From 387ed310870fb0a77157b73a6b8e23135194d278 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Thu, 16 Jul 2026 20:09:19 +0200 Subject: [PATCH] Code quality --- Devices/guition-jc2432w328c/guition,jc2432w328c.dts | 1 - .../platform-esp32/source/drivers/esp32_pwm_ledc.cpp | 3 ++- TactilityKernel/source/drivers/rgb_led_gpio.cpp | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index b36ee0432..8f9c2dd4d 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -76,7 +76,6 @@ pin-rx = <&gpio0 21 GPIO_FLAG_NONE>; }; - rgb_led_channel_red { compatible = "espressif,esp32-pwm-ledc"; pin = <&gpio0 4 GPIO_FLAG_NONE>; diff --git a/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp b/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp index 41af027d8..0c55e0aa1 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp @@ -25,10 +25,11 @@ struct Esp32PwmLedcInternal { // region Helpers static uint32_t compute_freq_hz(uint32_t period_ns) { - return (uint32_t)(1000000000ULL / period_ns); + return period_ns > 0 ? (uint32_t)(1000000000ULL / period_ns) : 0; } static uint32_t compute_raw_duty(uint32_t duty_ns, uint32_t period_ns, ledc_timer_bit_t duty_resolution) { + if (period_ns == 0) return 0; uint64_t max_duty = 1ULL << duty_resolution; uint64_t raw_duty = ((uint64_t)duty_ns * max_duty) / period_ns; return (uint32_t)(raw_duty > max_duty ? max_duty : raw_duty); diff --git a/TactilityKernel/source/drivers/rgb_led_gpio.cpp b/TactilityKernel/source/drivers/rgb_led_gpio.cpp index a9ff58ca9..49efc83a7 100644 --- a/TactilityKernel/source/drivers/rgb_led_gpio.cpp +++ b/TactilityKernel/source/drivers/rgb_led_gpio.cpp @@ -126,9 +126,15 @@ static error_t start(Device* device) { device_set_driver_data(device, internal); if (config->enabled) { - rgb_led_gpio_enable(device); // Allowed to fail, we don't care about the result + 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 { - apply_levels(device); // Allowed to fail, we don't care about the result + 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;