diff --git a/TactilityKernel/source/drivers/gpio_backlight.cpp b/TactilityKernel/source/drivers/gpio_backlight.cpp index fdfb89b1e..b9bde8b4d 100644 --- a/TactilityKernel/source/drivers/gpio_backlight.cpp +++ b/TactilityKernel/source/drivers/gpio_backlight.cpp @@ -110,7 +110,10 @@ static error_t start(Device* device) { device_set_driver_data(device, internal); - gpio_backlight_set_brightness_default(device); // Allowed to fail, we don't care about the result + 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; } diff --git a/TactilityKernel/source/drivers/pwm_backlight.cpp b/TactilityKernel/source/drivers/pwm_backlight.cpp index dfb6b5ca2..a2c2cb68e 100644 --- a/TactilityKernel/source/drivers/pwm_backlight.cpp +++ b/TactilityKernel/source/drivers/pwm_backlight.cpp @@ -34,6 +34,10 @@ static error_t apply_brightness(Device* device, uint8_t brightness) { 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) { @@ -97,6 +101,11 @@ static error_t start(Device* device) { if (internal == nullptr) { return ERROR_OUT_OF_MEMORY; } + + if (config->brightness_range.max <= config->brightness_range.min) { + return ERROR_INVALID_ARGUMENT; + } + device_set_driver_data(device, internal); pwm_backlight_set_brightness_default(device); // Allowed to fail, we don't care about the result diff --git a/TactilityKernel/source/drivers/rgb_led_pwm.cpp b/TactilityKernel/source/drivers/rgb_led_pwm.cpp index 1bb8de7a9..814086b1d 100644 --- a/TactilityKernel/source/drivers/rgb_led_pwm.cpp +++ b/TactilityKernel/source/drivers/rgb_led_pwm.cpp @@ -62,19 +62,24 @@ static error_t rgb_led_pwm_get_color(Device* device, RgbLedColor* out_color) { static error_t rgb_led_pwm_enable(Device* device) { const auto* config = GET_CONFIG(device); - GET_INTERNAL(device)->enabled = true; - error_t error = pwm_enable(config->pwm_red); - if (error == ERROR_NONE) { - error = pwm_enable(config->pwm_green); - } - if (error == ERROR_NONE) { - error = pwm_enable(config->pwm_blue); - } if (error != ERROR_NONE) { - LOG_E(TAG, "Failed to enable LED"); + return error; } - 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) {