diff options
Diffstat (limited to 'cros_ec/lib/ec_keyboard.c')
-rw-r--r-- | cros_ec/lib/ec_keyboard.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/cros_ec/lib/ec_keyboard.c b/cros_ec/lib/ec_keyboard.c index 4e4b9d91e4..7a5c43e0ef 100644 --- a/cros_ec/lib/ec_keyboard.c +++ b/cros_ec/lib/ec_keyboard.c @@ -12,6 +12,7 @@ static EcKeyboardMatrixCallback matrix_callback; +static enum EcScancodeSet scancode_set = EC_SCANCODE_SET_2; static void KeyboardStateChanged(int row, int col, int is_pressed) { uint8_t scan_code[MAX_SCAN_CODE_LEN]; @@ -23,7 +24,7 @@ static void KeyboardStateChanged(int row, int col, int is_pressed) { EC_ASSERT(matrix_callback); - ret = matrix_callback(row, col, is_pressed, scan_code, &len); + ret = matrix_callback(row, col, is_pressed, scancode_set, scan_code, &len); if (ret == EC_SUCCESS) { EC_ASSERT(len > 0); @@ -36,6 +37,45 @@ static void KeyboardStateChanged(int row, int col, int is_pressed) { } +static int HandleHostCommand( + uint8_t command, + uint8_t data, + uint8_t *output) { + int out_len = 0; + + switch (command) { + case EC_I8042_CMD_GSCANSET: /* also EC_I8042_CMD_SSCANSET */ + if (data == EC_SCANCODE_GET_SET) { + output[out_len++] = scancode_set; + } else if (data == EC_SCANCODE_SET_2) { + scancode_set = data; + } else { + output[out_len++] = EC_I8042_RET_ERR; + } + break; + + case EC_I8042_CMD_SETREP: + case EC_I8042_CMD_ENABLE: + case EC_I8042_CMD_RESET_DIS: + case EC_I8042_CMD_RESET_DEF: + case EC_I8042_CMD_SETALL_MB: + case EC_I8042_CMD_SETALL_MBR: + case EC_I8042_CMD_RESET_BAT: + case EC_I8042_CMD_RESEND: + case EC_I8042_CMD_EX_ENABLE: + case EC_I8042_CMD_EX_SETLEDS: + case EC_I8042_CMD_OK_GETID: + case EC_I8042_CMD_GETID: + case EC_I8042_CMD_SETLEDS: + default: + output[out_len++] = EC_I8042_RET_ERR; + break; + } + + return out_len; +} + + EcError EcKeyboardMatrixRegisterCallback( int8_t row_num, int8_t col_num, EcKeyboardMatrixCallback callback) { @@ -52,5 +92,8 @@ EcError EcKeyboardInit() { ret = EcKeyboardRegisterCallback(KeyboardStateChanged); if (ret != EC_SUCCESS) return ret; + ret = EcI8042RegisterCallback(HandleHostCommand); + if (ret != EC_SUCCESS) return ret; + return EC_SUCCESS; } |