@@ -235,6 +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_F1F12 ;
239
+ static uint8_t keep_fn_key_special ;
240
+ static uint8_t keep_fn_key_functional ;
238
241
239
242
void fnkey_shutdown (void ) {
240
243
uint8_t current_kb = 0 ;
@@ -263,13 +266,34 @@ void fnkey_startup(void) {
263
266
}
264
267
DECLARE_HOOK (HOOK_CHIPSET_STARTUP , fnkey_startup , HOOK_PRIO_DEFAULT );
265
268
269
+ static void fn_keep_check_F1F12 (int8_t pressed )
270
+ {
271
+ if (pressed )
272
+ keep_fn_key_F1F12 = 1 ;
273
+ else
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 ;
283
+ }
284
+
266
285
int hotkey_F1_F12 (uint16_t * key_code , uint16_t lock , int8_t pressed )
267
286
{
268
287
const uint16_t prss_key = * key_code ;
269
288
270
- if (!(Fn_key & FN_LOCKED ) && lock & FN_PRESSED )
289
+ if (!(Fn_key & FN_LOCKED ) &&
290
+ (lock & FN_PRESSED ) &&
291
+ !keep_fn_key_F1F12 )
271
292
return EC_SUCCESS ;
272
- else if (Fn_key & FN_LOCKED && !(Fn_key & FN_PRESSED ))
293
+ else if (Fn_key & FN_LOCKED &&
294
+ !(lock & FN_PRESSED ))
295
+ return EC_SUCCESS ;
296
+ else if (!pressed && !keep_fn_key_F1F12 )
273
297
return EC_SUCCESS ;
274
298
275
299
switch (prss_key ) {
@@ -278,33 +302,28 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
278
302
break ;
279
303
case SCANCODE_F2 : /* VOLUME_DOWN */
280
304
* key_code = SCANCODE_VOLUME_DOWN ;
281
-
282
305
break ;
283
306
case SCANCODE_F3 : /* VOLUME_UP */
284
307
* key_code = SCANCODE_VOLUME_UP ;
285
-
286
308
break ;
287
309
case SCANCODE_F4 : /* PREVIOUS_TRACK */
288
310
* key_code = SCANCODE_PREV_TRACK ;
289
-
290
311
break ;
291
312
case SCANCODE_F5 : /* PLAY_PAUSE */
292
313
* key_code = 0xe034 ;
293
-
294
314
break ;
295
315
case SCANCODE_F6 : /* NEXT_TRACK */
296
316
* key_code = SCANCODE_NEXT_TRACK ;
297
-
298
317
break ;
299
318
case SCANCODE_F7 : /* TODO: DIM_SCREEN */
300
319
update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_DN , pressed );
320
+ fn_keep_check_F1F12 (pressed );
301
321
return EC_ERROR_UNIMPLEMENTED ;
302
-
303
322
break ;
304
323
case SCANCODE_F8 : /* TODO: BRIGHTEN_SCREEN */
305
324
update_hid_key (HID_KEY_DISPLAY_BRIGHTNESS_UP , pressed );
325
+ fn_keep_check_F1F12 (pressed );
306
326
return EC_ERROR_UNIMPLEMENTED ;
307
-
308
327
break ;
309
328
case SCANCODE_F9 : /* EXTERNAL_DISPLAY */
310
329
if (pressed ) {
@@ -314,12 +333,13 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
314
333
simulate_keyboard (SCANCODE_P , 0 );
315
334
simulate_keyboard (SCANCODE_LEFT_WIN , 0 );
316
335
}
336
+ fn_keep_check_F1F12 (pressed );
317
337
return EC_ERROR_UNIMPLEMENTED ;
318
338
break ;
319
339
case SCANCODE_F10 : /* FLIGHT_MODE */
320
340
update_hid_key (HID_KEY_AIRPLANE_MODE , pressed );
341
+ fn_keep_check_F1F12 (pressed );
321
342
return EC_ERROR_UNIMPLEMENTED ;
322
-
323
343
break ;
324
344
case SCANCODE_F11 :
325
345
/*
@@ -333,14 +353,16 @@ int hotkey_F1_F12(uint16_t *key_code, uint16_t lock, int8_t pressed)
333
353
case SCANCODE_F12 : /* TODO: FRAMEWORK */
334
354
/* Media Select scan code */
335
355
* key_code = 0xE050 ;
336
-
337
356
break ;
357
+ default :
358
+ return EC_SUCCESS ;
338
359
}
360
+ fn_keep_check_F1F12 (pressed );
339
361
return EC_SUCCESS ;
340
362
}
341
363
342
364
343
- int hotkey_special_key (uint16_t * key_code )
365
+ int hotkey_special_key (uint16_t * key_code , int8_t pressed )
344
366
{
345
367
const uint16_t prss_key = * key_code ;
346
368
@@ -366,29 +388,36 @@ int hotkey_special_key(uint16_t *key_code)
366
388
case SCANCODE_DOWN : /* PAGE_DOWN */
367
389
* key_code = 0xe07a ;
368
390
break ;
391
+ default :
392
+ return EC_SUCCESS ;
369
393
}
394
+ fn_keep_check_special (pressed );
370
395
return EC_SUCCESS ;
371
396
}
372
397
373
- int functional_hotkey (uint16_t * key_code )
398
+ int functional_hotkey (uint16_t * key_code , int8_t pressed )
374
399
{
375
400
const uint16_t prss_key = * key_code ;
376
401
uint8_t bl_brightness = 0 ;
377
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
+
378
409
switch (prss_key ) {
379
410
case SCANCODE_ESC : /* TODO: FUNCTION_LOCK */
380
411
if (Fn_key & FN_LOCKED )
381
412
Fn_key &= ~FN_LOCKED ;
382
413
else
383
414
Fn_key |= FN_LOCKED ;
384
- return EC_ERROR_UNIMPLEMENTED ;
385
415
break ;
386
416
case SCANCODE_B :
387
417
/* BREAK_KEY */
388
418
simulate_keyboard (0xe07e , 1 );
389
419
simulate_keyboard (0xe0 , 1 );
390
420
simulate_keyboard (0x7e , 0 );
391
- return EC_ERROR_UNIMPLEMENTED ;
392
421
break ;
393
422
case SCANCODE_P :
394
423
/* PAUSE_KEY */
@@ -397,7 +426,6 @@ int functional_hotkey(uint16_t *key_code)
397
426
simulate_keyboard (0xe1 , 1 );
398
427
simulate_keyboard (0x14 , 0 );
399
428
simulate_keyboard (0x77 , 0 );
400
- return EC_ERROR_UNIMPLEMENTED ;
401
429
break ;
402
430
case SCANCODE_SPACE : /* TODO: TOGGLE_KEYBOARD_BACKLIGHT */
403
431
bl_brightness = kblight_get ();
@@ -420,10 +448,12 @@ int functional_hotkey(uint16_t *key_code)
420
448
}
421
449
kblight_set (bl_brightness );
422
450
/* we dont want to pass the space key event to the OS */
423
- return EC_ERROR_UNKNOWN ;
424
451
break ;
452
+ default :
453
+ return EC_SUCCESS ;
425
454
}
426
- return EC_SUCCESS ;
455
+ keep_fn_key_functional = 1 ;
456
+ return EC_ERROR_UNIMPLEMENTED ;
427
457
}
428
458
429
459
enum ec_error_list keyboard_scancode_callback (uint16_t * make_code ,
@@ -456,21 +486,23 @@ enum ec_error_list keyboard_scancode_callback(uint16_t *make_code,
456
486
/*
457
487
* If the function key is not held then
458
488
* we pass through all events without modifying them
489
+ * but if last time have press FN still need keep that
459
490
*/
460
- if (!Fn_key )
491
+ if (!Fn_key && ! keep_fn_key_special && ! keep_fn_key_functional )
461
492
return EC_SUCCESS ;
462
493
463
494
if (Fn_key & FN_LOCKED && !(Fn_key & FN_PRESSED ))
464
495
return EC_SUCCESS ;
465
496
466
- r = hotkey_special_key (make_code );
497
+ r = hotkey_special_key (make_code , pressed );
467
498
if (r != EC_SUCCESS )
468
499
return r ;
469
500
470
- if (!pressed || pressed_key != * make_code )
501
+ if ((!pressed && !keep_fn_key_functional ) ||
502
+ pressed_key != * make_code )
471
503
return EC_SUCCESS ;
472
504
473
- r = functional_hotkey (make_code );
505
+ r = functional_hotkey (make_code , pressed );
474
506
if (r != EC_SUCCESS )
475
507
return r ;
476
508
0 commit comments