This commit is contained in:
Ken Van Hoeylandt 2026-07-16 20:14:03 +02:00
parent 387ed31087
commit 822a7a2fd4
3 changed files with 28 additions and 11 deletions

View File

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

View File

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

View File

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