@@ -235,7 +235,9 @@ void board_kblight_init(void)
235
235
#define FN_PRESSED BIT(0)
236
236
#define FN_LOCKED BIT(1)
237
237
static uint8_t Fn_key ;
238
- static uint8_t keep_fn_key_code ;
238
+ static uint8_t keep_fn_key_F1F12 ;
239
+ static uint8_t keep_fn_key_special ;
240
+ static uint8_t keep_fn_key_functional ;
239
241
240
242
void fnkey_shutdown (void ) {
241
243
uint8_t current_kb = 0 ;
@@ -264,12 +266,20 @@ void fnkey_startup(void) {
264
266
}
265
267
DECLARE_HOOK (HOOK_CHIPSET_STARTUP , fnkey_startup , HOOK_PRIO_DEFAULT );
266
268
267
- static void fn_keep_check (int8_t pressed )
269
+ static void fn_keep_check_F1F12 (int8_t pressed )
268
270
{
269
271
if (pressed )
270
- keep_fn_key_code = 1 ;
272
+ keep_fn_key_F1F12 = 1 ;
271
273
else
272
- keep_fn_key_code = 0 ;
274
+ keep_fn_key_F1F12 = 0 ;
275
+ }
276
+
277
+ static void fn_keep_check_special (int8_t pressed )
278
+ {
279
+ if (pressed )
280
+ keep_fn_key_special = 1 ;
281
+ else
282
+ keep_fn_key_special = 0 ;
273
283
}
274
284
275
285
int hotkey_F1_F12 (uint16_t * key_code , uint16_t lock , int8_t pressed )
@@ -278,12 +288,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
278
288
279
289
if (!(Fn_key & FN_LOCKED ) &&
280
290
(lock & FN_PRESSED ) &&
281
- !keep_fn_key_code )
291
+ !keep_fn_key_F1F12 )
282
292
return EC_SUCCESS ;
283
293
else if (Fn_key & FN_LOCKED &&
284
294
!(lock & FN_PRESSED ))
285
295
return EC_SUCCESS ;
286
- else if (!pressed && !keep_fn_key_code )
296
+ else if (!pressed && !keep_fn_key_F1F12 )
287
297
return EC_SUCCESS ;
288
298
289
299
switch (prss_key ) {
@@ -307,10 +317,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
307
317
break ;
308
318
case SCANCODE_F7 : /* TODO: DIM_SCREEN */
309
319
update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_DN , pressed );
320
+ fn_keep_check_F1F12 (pressed );
310
321
return EC_ERROR_UNIMPLEMENTED ;
311
322
break ;
312
323
case SCANCODE_F8 : /* TODO: BRIGHTEN_SCREEN */
313
324
update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_UP , pressed );
325
+ fn_keep_check_F1F12 (pressed );
314
326
return EC_ERROR_UNIMPLEMENTED ;
315
327
break ;
316
328
case SCANCODE_F9 : /* EXTERNAL_DISPLAY */
@@ -321,10 +333,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
321
333
simulate_keyboard (SCANCODE_P , 0 );
322
334
simulate_keyboard (SCANCODE_LEFT_WIN , 0 );
323
335
}
336
+ fn_keep_check_F1F12 (pressed );
324
337
return EC_ERROR_UNIMPLEMENTED ;
325
338
break ;
326
339
case SCANCODE_F10 : /* FLIGHT_MODE */
327
340
update_hid_key (HID_KEY_AIRPLANE_MODE , pressed );
341
+ fn_keep_check_F1F12 (pressed );
328
342
return EC_ERROR_UNIMPLEMENTED ;
329
343
break ;
330
344
case SCANCODE_F11 :
@@ -343,12 +357,12 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
343
357
default :
344
358
return EC_SUCCESS ;
345
359
}
346
- fn_keep_check (pressed );
360
+ fn_keep_check_F1F12 (pressed );
347
361
return EC_SUCCESS ;
348
362
}
349
363
350
364
351
- int hotkey_special_key (uint16_t * key_code )
365
+ int hotkey_special_key (uint16_t * key_code , int8_t pressed )
352
366
{
353
367
const uint16_t prss_key = * key_code ;
354
368
@@ -374,29 +388,36 @@ int hotkey_special_key(uint16_t *key_code)
374
388
case SCANCODE_DOWN : /* PAGE_DOWN */
375
389
* key_code = 0xe07a ;
376
390
break ;
391
+ default :
392
+ return EC_SUCCESS ;
377
393
}
394
+ fn_keep_check_special (pressed );
378
395
return EC_SUCCESS ;
379
396
}
380
397
381
- int functional_hotkey (uint16_t * key_code )
398
+ int functional_hotkey (uint16_t * key_code , int8_t pressed )
382
399
{
383
400
const uint16_t prss_key = * key_code ;
384
401
uint8_t bl_brightness = 0 ;
385
402
403
+ /* don't send break key if last time doesn't send make key */
404
+ if (!pressed && keep_fn_key_functional ) {
405
+ keep_fn_key_functional = 0 ;
406
+ return EC_ERROR_UNKNOWN ;
407
+ }
408
+
386
409
switch (prss_key ) {
387
410
case SCANCODE_ESC : /* TODO: FUNCTION_LOCK */
388
411
if (Fn_key & FN_LOCKED )
389
412
Fn_key &= ~FN_LOCKED ;
390
413
else
391
414
Fn_key |= FN_LOCKED ;
392
- return EC_ERROR_UNIMPLEMENTED ;
393
415
break ;
394
416
case SCANCODE_B :
395
417
/* BREAK_KEY */
396
418
simulate_keyboard (0xe07e , 1 );
397
419
simulate_keyboard (0xe0 , 1 );
398
420
simulate_keyboard (0x7e , 0 );
399
- return EC_ERROR_UNIMPLEMENTED ;
400
421
break ;
401
422
case SCANCODE_P :
402
423
/* PAUSE_KEY */
@@ -405,7 +426,6 @@ int functional_hotkey(uint16_t *key_code)
405
426
simulate_keyboard (0xe1 , 1 );
406
427
simulate_keyboard (0x14 , 0 );
407
428
simulate_keyboard (0x77 , 0 );
408
- return EC_ERROR_UNIMPLEMENTED ;
409
429
break ;
410
430
case SCANCODE_SPACE : /* TODO: TOGGLE_KEYBOARD_BACKLIGHT */
411
431
bl_brightness = kblight_get ();
@@ -428,10 +448,12 @@ int functional_hotkey(uint16_t *key_code)
428
448
}
429
449
kblight_set (bl_brightness );
430
450
/* we dont want to pass the space key event to the OS */
431
- return EC_ERROR_UNKNOWN ;
432
451
break ;
452
+ default :
453
+ return EC_SUCCESS ;
433
454
}
434
- return EC_SUCCESS ;
455
+ keep_fn_key_functional = 1 ;
456
+ return EC_ERROR_UNIMPLEMENTED ;
435
457
}
436
458
437
459
enum ec_error_list keyboard_scancode_callback (uint16_t * make_code ,
@@ -464,21 +486,23 @@ enum ec_error_list keyboard_scancode_callback(uint16_t *make_code,
464
486
/*
465
487
* If the function key is not held then
466
488
* we pass through all events without modifying them
489
+ * but if last time have press FN still need keep that
467
490
*/
468
- if (!Fn_key )
491
+ if (!Fn_key && ! keep_fn_key_special && ! keep_fn_key_functional )
469
492
return EC_SUCCESS ;
470
493
471
494
if (Fn_key & FN_LOCKED && !(Fn_key & FN_PRESSED ))
472
495
return EC_SUCCESS ;
473
496
474
- r = hotkey_special_key (make_code );
497
+ r = hotkey_special_key (make_code , pressed );
475
498
if (r != EC_SUCCESS )
476
499
return r ;
477
500
478
- if (!pressed || pressed_key != * make_code )
501
+ if ((!pressed && !keep_fn_key_functional ) ||
502
+ pressed_key != * make_code )
479
503
return EC_SUCCESS ;
480
504
481
- r = functional_hotkey (make_code );
505
+ r = functional_hotkey (make_code , pressed );
482
506
if (r != EC_SUCCESS )
483
507
return r ;
484
508
0 commit comments