File tree 3 files changed +59
-8
lines changed
framework_lib/src/chromium_ec
3 files changed +59
-8
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ pub enum EcCommands {
30
30
FlashProtect = 0x15 ,
31
31
PwmGetKeyboardBacklight = 0x0022 ,
32
32
PwmSetKeyboardBacklight = 0x0023 ,
33
+ PwmSetFanDuty = 0x0024 ,
34
+ PwmSetDuty = 0x0025 ,
35
+ PwmGetDuty = 0x0026 ,
33
36
GpioGet = 0x93 ,
34
37
I2cPassthrough = 0x9e ,
35
38
ConsoleSnapshot = 0x97 ,
Original file line number Diff line number Diff line change @@ -174,12 +174,57 @@ pub struct EcResponsePwmGetKeyboardBacklight {
174
174
pub enabled : u8 ,
175
175
}
176
176
177
+ #[ repr( u8 ) ]
178
+ pub enum PwmType {
179
+ Generic = 0 ,
180
+ KbLight ,
181
+ DisplayLight ,
182
+ }
183
+
177
184
impl EcRequest < EcResponsePwmGetKeyboardBacklight > for EcRequestPwmGetKeyboardBacklight {
178
185
fn command_id ( ) -> EcCommands {
179
186
EcCommands :: PwmGetKeyboardBacklight
180
187
}
181
188
}
182
189
190
+ pub const PWM_MAX_DUTY : u16 = 0xFFFF ;
191
+
192
+ #[ repr( C , packed) ]
193
+ pub struct EcRequestPwmSetDuty {
194
+ /// Duty cycle, min 0, max 0xFFFF
195
+ pub duty : u16 ,
196
+ /// See enum PwmType
197
+ pub pwm_type : u8 ,
198
+ /// Type-specific index, or 0 if unique
199
+ pub index : u8 ,
200
+ }
201
+
202
+ impl EcRequest < ( ) > for EcRequestPwmSetDuty {
203
+ fn command_id ( ) -> EcCommands {
204
+ EcCommands :: PwmSetDuty
205
+ }
206
+ }
207
+
208
+ #[ repr( C , packed) ]
209
+ pub struct EcRequestPwmGetDuty {
210
+ /// See enum PwmType
211
+ pub pwm_type : u8 ,
212
+ /// Type-specific index, or 0 if unique
213
+ pub index : u8 ,
214
+ }
215
+
216
+ #[ repr( C , packed) ]
217
+ pub struct EcResponsePwmGetDuty {
218
+ /// Duty cycle, min 0, max 0xFFFF
219
+ pub duty : u16 ,
220
+ }
221
+
222
+ impl EcRequest < EcResponsePwmGetDuty > for EcRequestPwmGetDuty {
223
+ fn command_id ( ) -> EcCommands {
224
+ EcCommands :: PwmGetDuty
225
+ }
226
+ }
227
+
183
228
#[ repr( C , packed) ]
184
229
pub struct EcRequestGpioGetV0 {
185
230
pub name : [ u8 ; 32 ] ,
Original file line number Diff line number Diff line change @@ -371,22 +371,25 @@ impl CrosEc {
371
371
/// * `percent` - An integer from 0 to 100. 0 being off, 100 being full brightness
372
372
pub fn set_keyboard_backlight ( & self , percent : u8 ) {
373
373
debug_assert ! ( percent <= 100 ) ;
374
- let res = EcRequestPwmSetKeyboardBacklight { percent } . send_command ( self ) ;
374
+ let res = EcRequestPwmSetDuty {
375
+ duty : percent as u16 * ( PWM_MAX_DUTY / 100 ) ,
376
+ pwm_type : PwmType :: KbLight as u8 ,
377
+ index : 0 ,
378
+ }
379
+ . send_command ( self ) ;
375
380
debug_assert ! ( res. is_ok( ) ) ;
376
381
}
377
382
378
383
/// Check the current brightness of the keyboard backlight
379
384
///
380
385
pub fn get_keyboard_backlight ( & self ) -> EcResult < u8 > {
381
- let kblight = EcRequestPwmGetKeyboardBacklight { } . send_command ( self ) ?;
382
-
383
- // The enabled field is deprecated and must always be 1
384
- debug_assert_eq ! ( kblight. enabled, 1 ) ;
385
- if !kblight. enabled == 0 {
386
- error ! ( "Should always be enabled, even if OFF" ) ;
386
+ let kblight = EcRequestPwmGetDuty {
387
+ pwm_type : PwmType :: KbLight as u8 ,
388
+ index : 0 ,
387
389
}
390
+ . send_command ( self ) ?;
388
391
389
- Ok ( kblight. percent )
392
+ Ok ( ( kblight. duty / ( PWM_MAX_DUTY / 100 ) ) as u8 )
390
393
}
391
394
392
395
/// Overwrite RO and RW regions of EC flash
You can’t perform that action at this time.
0 commit comments