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