Code quality

This commit is contained in:
Ken Van Hoeylandt 2026-07-16 20:09:19 +02:00
parent 3d125ccd87
commit 387ed31087
3 changed files with 10 additions and 4 deletions

View File

@ -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>;

View File

@ -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);

View File

@ -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;