Skip to content

Commit 7d35797

Browse files
quinchou77JohnAZoidberg
authored andcommitted
--kblight: Fix on some early systems
I tested on Laptop 13 Intel 13th gen and kblight didn't work. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent deb7c7a commit 7d35797

File tree

1 file changed

+32
-7
lines changed
  • framework_lib/src/chromium_ec

1 file changed

+32
-7
lines changed

framework_lib/src/chromium_ec/mod.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -723,26 +723,51 @@ impl CrosEc {
723723
Ok(InputDeckStatus::from(status))
724724
}
725725

726+
fn has_pwmtype_kblight(&self) -> bool {
727+
// Returns EcError::Response(EcResponseStatus::InvalidParameter) on some early systems
728+
EcRequestPwmGetDuty {
729+
pwm_type: PwmType::KbLight as u8,
730+
index: 0,
731+
}
732+
.send_command(self)
733+
.is_ok()
734+
}
735+
726736
/// Change the keyboard baclight brightness
727737
///
728738
/// # Arguments
729739
/// * `percent` - An integer from 0 to 100. 0 being off, 100 being full brightness
730740
pub fn set_keyboard_backlight(&self, percent: u8) {
731741
debug_assert!(percent <= 100);
732-
let res = EcRequestPwmSetDuty {
733-
duty: percent as u16 * (PWM_MAX_DUTY / 100),
734-
pwm_type: PwmType::KbLight as u8,
735-
index: 0,
742+
let res = if self.has_pwmtype_kblight() {
743+
EcRequestPwmSetDuty {
744+
duty: percent as u16 * (PWM_MAX_DUTY / 100),
745+
pwm_type: PwmType::KbLight as u8,
746+
index: 0,
747+
}
748+
} else {
749+
EcRequestPwmSetDuty {
750+
duty: percent as u16 * (PWM_MAX_DUTY / 100),
751+
pwm_type: PwmType::Generic as u8,
752+
index: 1,
753+
}
736754
}
737755
.send_command(self);
738756
debug_assert!(res.is_ok());
739757
}
740758

741759
/// Check the current brightness of the keyboard backlight
742760
pub fn get_keyboard_backlight(&self) -> EcResult<u8> {
743-
let kblight = EcRequestPwmGetDuty {
744-
pwm_type: PwmType::KbLight as u8,
745-
index: 0,
761+
let kblight = if self.has_pwmtype_kblight() {
762+
EcRequestPwmGetDuty {
763+
pwm_type: PwmType::KbLight as u8,
764+
index: 0,
765+
}
766+
} else {
767+
EcRequestPwmGetDuty {
768+
pwm_type: PwmType::Generic as u8,
769+
index: 1,
770+
}
746771
}
747772
.send_command(self)?;
748773

0 commit comments

Comments
 (0)