@@ -770,22 +770,47 @@ impl CrosEc {
770770 /// * `percent` - An integer from 0 to 100. 0 being off, 100 being full brightness
771771 pub fn set_keyboard_backlight ( & self , percent : u8 ) {
772772 debug_assert ! ( percent <= 100 ) ;
773+ let duty = percent as u16 * ( PWM_MAX_DUTY / 100 ) ;
774+
773775 let res = EcRequestPwmSetDuty {
774- duty : percent as u16 * ( PWM_MAX_DUTY / 100 ) ,
776+ duty,
775777 pwm_type : PwmType :: KbLight as u8 ,
776778 index : 0 ,
777779 }
778780 . send_command ( self ) ;
781+
782+ // Early systems (hx20/hx30) don't enable CONFIG_PWM_KBLIGHT in their EC firmware;
783+ // keyboard backlight is at generic PWM channel index 1.
784+ let res = match res {
785+ Err ( EcError :: Response ( EcResponseStatus :: InvalidParameter ) ) => EcRequestPwmSetDuty {
786+ duty,
787+ pwm_type : PwmType :: Generic as u8 ,
788+ index : 1 ,
789+ }
790+ . send_command ( self ) ,
791+ other => other,
792+ } ;
779793 debug_assert ! ( res. is_ok( ) ) ;
780794 }
781795
782796 /// Check the current brightness of the keyboard backlight
783797 pub fn get_keyboard_backlight ( & self ) -> EcResult < u8 > {
784- let kblight = EcRequestPwmGetDuty {
798+ let res = EcRequestPwmGetDuty {
785799 pwm_type : PwmType :: KbLight as u8 ,
786800 index : 0 ,
787801 }
788- . send_command ( self ) ?;
802+ . send_command ( self ) ;
803+
804+ // Early systems (hx20/hx30) don't enable CONFIG_PWM_KBLIGHT in their EC firmware;
805+ // keyboard backlight is at generic PWM channel index 1.
806+ let kblight = match res {
807+ Err ( EcError :: Response ( EcResponseStatus :: InvalidParameter ) ) => EcRequestPwmGetDuty {
808+ pwm_type : PwmType :: Generic as u8 ,
809+ index : 1 ,
810+ }
811+ . send_command ( self ) ?,
812+ other => other?,
813+ } ;
789814
790815 Ok ( ( kblight. duty / ( PWM_MAX_DUTY / 100 ) ) as u8 )
791816 }
0 commit comments