From 9d49389919c36e44e451514b8278b9eb7ee6ed1e Mon Sep 17 00:00:00 2001 From: Kieran Levin Date: Thu, 23 Nov 2023 00:34:28 -0600 Subject: [PATCH] Lotus.touchpad emulation (#875) * fw16 emulate the touchpad if it is removed If win32 boots without a valid device attached. it will cause the device to be disabled forever. Emulate the touchpad when it is disconnected. Signed-off-by: Kieran Levin * lotus remove sleep in input module check speed up input module detection so we can shutdown faster on disconnect Signed-off-by: Kieran Levin * lint cleanup Signed-off-by: Kieran Levin --------- Signed-off-by: Kieran Levin --- zephyr/program/lotus/include/hid_device.h | 3 + .../lotus/include/lotus/touchpad_descriptor.h | 369 ++++++++++++++++++ zephyr/program/lotus/lotus/gpio.dtsi | 4 +- zephyr/program/lotus/lotus/i2c.dtsi | 9 +- zephyr/program/lotus/lotus/src/input_module.c | 39 +- .../program/lotus/lotus/src/power_sequence.c | 1 + zephyr/program/lotus/src/hid_device.c | 101 +++-- 7 files changed, 480 insertions(+), 46 deletions(-) create mode 100644 zephyr/program/lotus/include/lotus/touchpad_descriptor.h diff --git a/zephyr/program/lotus/include/hid_device.h b/zephyr/program/lotus/include/hid_device.h index 1db5e78d5e..13b584cd02 100644 --- a/zephyr/program/lotus/include/hid_device.h +++ b/zephyr/program/lotus/include/hid_device.h @@ -18,5 +18,8 @@ void hid_consumer(uint16_t id, bool pressed); void hid_airplane(bool pressed); +int hid_target_register(const struct device *dev); + +int hid_target_unregister(const struct device *dev); #endif /* __CROS_EC_I2C_HID_DEVICE_H */ diff --git a/zephyr/program/lotus/include/lotus/touchpad_descriptor.h b/zephyr/program/lotus/include/lotus/touchpad_descriptor.h new file mode 100644 index 0000000000..38efae42c1 --- /dev/null +++ b/zephyr/program/lotus/include/lotus/touchpad_descriptor.h @@ -0,0 +1,369 @@ +/* + * Copyright (c) 2023 Framework Computer + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef __CROS_EC_TOUCHPAD_DESCRIPTOR_H +#define __CROS_EC_TOUCHPAD_DESCRIPTOR_H + +#include "hid_device.h" + +/* This exactly mimics the touchpad when it is not physically connected */ +static const uint8_t touchpad_report_desc[] = { + 0x05, 0x01, /* USAGE_PAGE () */ + 0x09, 0x02, + 0xA1, 0x01, + 0x85, 0x01, + 0x05, 0x01, + 0x09, 0x01, + 0xA1, 0x00, + 0x05, 0x09, + 0x19, 0x01, + 0x29, 0x02, + 0x15, 0x00, + 0x25, 0x01, + 0x75, 0x01, + 0x95, 0x02, + 0x81, 0x02, + 0x95, 0x06, + 0x81, 0x03, + 0x05, 0x01, + 0x09, 0x30, + 0x09, 0x31, + 0x09, 0x38, + 0x15, 0x81, + 0x25, 0x7F, + 0x75, 0x08, + 0x95, 0x03, + 0x81, 0x26, + 0x05, 0x0C, + 0x0A, 0x38, + 0x02, 0x95, + 0x01, 0x81, + 0x06, 0x75, + 0x08, 0x95, + 0x03, 0x81, + 0x03, 0xC0, + 0xC0, 0x05, + 0x0D, 0x09, + 0x05, 0xA1, + 0x01, 0x85, + 0x04, 0x05, + 0x09, 0x09, + 0x01, 0x15, + 0x00, 0x25, + 0x01, 0x75, + 0x01, 0x95, + 0x01, 0x81, + 0x02, 0x95, + 0x02, 0x81, + 0x03, 0x06, + 0x01, 0xFF, + 0x09, 0x01, + 0x95, 0x01, + 0x81, 0x02, + 0x05, 0x0D, + 0x09, 0x54, + 0x25, 0x05, + 0x75, 0x04, + 0x95, 0x01, + 0x81, 0x02, + 0x09, 0x56, + 0x55, 0x0C, + 0x66, 0x01, + 0x10, 0x47, + 0xFF, 0xFF, + 0x00, 0x00, + 0x27, 0xFF, + 0xFF, 0x00, + 0x00, 0x75, + 0x10, 0x95, + 0x01, 0x81, + 0x02, 0x05, + 0x0D, 0x09, + 0x22, 0xA1, + 0x02, 0x09, + 0x47, 0x09, + 0x42, 0x15, + 0x00, 0x25, + 0x01, 0x75, + 0x01, 0x95, + 0x02, 0x81, + 0x02, 0x95, + 0x02, 0x81, + 0x03, 0x09, + 0x51, 0x25, + 0x0A, 0x75, + 0x04, 0x95, + 0x01, 0x81, + 0x02, 0x05, + 0x01, 0x09, + 0x30, 0x35, + 0x00, 0x46, + 0xC4, 0x04, + 0x26, 0x01, + 0x0F, 0x55, + 0x0E, 0x65, + 0x11, 0x75, + 0x10, 0x95, + 0x01, 0x81, + 0x02, 0x09, + 0x31, 0x46, + 0xF8, 0x02, + 0x26, 0x58, + 0x09, 0x81, + 0x02, 0xC0, + 0x05, 0x0D, + 0x09, 0x22, + 0xA1, 0x02, + 0x09, 0x47, + 0x09, 0x42, + 0x15, 0x00, + 0x25, 0x01, + 0x75, 0x01, + 0x95, 0x02, + 0x81, 0x02, + 0x95, 0x02, + 0x81, 0x03, + 0x09, 0x51, + 0x25, 0x0A, + 0x75, 0x04, + 0x95, 0x01, + 0x81, 0x02, + 0x05, 0x01, + 0x09, 0x30, + 0x35, 0x00, + 0x46, 0xC4, + 0x04, 0x26, + 0x01, 0x0F, + 0x55, 0x0E, + 0x65, 0x11, + 0x75, 0x10, + 0x95, 0x01, + 0x81, 0x02, + 0x09, 0x31, + 0x46, 0xF8, + 0x02, 0x26, + 0x58, 0x09, + 0x81, 0x02, + 0xC0, 0x05, + 0x0D, 0x09, + 0x22, 0xA1, + 0x02, 0x09, + 0x47, 0x09, + 0x42, 0x15, + 0x00, 0x25, + 0x01, 0x75, + 0x01, 0x95, + 0x02, 0x81, + 0x02, 0x95, + 0x02, 0x81, + 0x03, 0x09, + 0x51, 0x25, + 0x0A, 0x75, + 0x04, 0x95, + 0x01, 0x81, + 0x02, 0x05, + 0x01, 0x09, + 0x30, 0x35, + 0x00, 0x46, + 0xC4, 0x04, + 0x26, 0x01, + 0x0F, 0x55, + 0x0E, 0x65, + 0x11, 0x75, + 0x10, 0x95, + 0x01, 0x81, + 0x02, 0x09, + 0x31, 0x46, + 0xF8, 0x02, + 0x26, 0x58, + 0x09, 0x81, + 0x02, 0xC0, + 0x05, 0x0D, + 0x09, 0x22, + 0xA1, 0x02, + 0x09, 0x47, + 0x09, 0x42, + 0x15, 0x00, + 0x25, 0x01, + 0x75, 0x01, + 0x95, 0x02, + 0x81, 0x02, + 0x95, 0x02, + 0x81, 0x03, + 0x09, 0x51, + 0x25, 0x0A, + 0x75, 0x04, + 0x95, 0x01, + 0x81, 0x02, + 0x05, 0x01, + 0x09, 0x30, + 0x35, 0x00, + 0x46, 0xC4, + 0x04, 0x26, + 0x01, 0x0F, + 0x55, 0x0E, + 0x65, 0x11, + 0x75, 0x10, + 0x95, 0x01, + 0x81, 0x02, + 0x09, 0x31, + 0x46, 0xF8, + 0x02, 0x26, + 0x58, 0x09, + 0x81, 0x02, + 0xC0, 0x05, + 0x0D, 0x09, + 0x22, 0xA1, + 0x02, 0x09, + 0x47, 0x09, + 0x42, 0x15, + 0x00, 0x25, + 0x01, 0x75, + 0x01, 0x95, + 0x02, 0x81, + 0x02, 0x95, + 0x02, 0x81, + 0x03, 0x09, + 0x51, 0x25, + 0x0A, 0x75, + 0x04, 0x95, + 0x01, 0x81, + 0x02, 0x05, + 0x01, 0x09, + 0x30, 0x35, + 0x00, 0x46, + 0xC4, 0x04, + 0x26, 0x01, + 0x0F, 0x55, + 0x0E, 0x65, + 0x11, 0x75, + 0x10, 0x95, + 0x01, 0x81, + 0x02, 0x09, + 0x31, 0x46, + 0xF8, 0x02, + 0x26, 0x58, + 0x09, 0x81, + 0x02, 0xC0, + 0x05, 0x0D, + 0x85, 0x02, + 0x09, 0x55, + 0x15, 0x00, + 0x25, 0x05, + 0x75, 0x08, + 0x95, 0x01, + 0xB1, 0x02, + 0x05, 0x0D, + 0x85, 0x06, + 0x09, 0x59, + 0x15, 0x00, + 0x25, 0x0F, + 0x75, 0x08, + 0x95, 0x01, + 0xB1, 0x02, + 0x05, 0x0D, + 0x85, 0x07, + 0x09, 0x60, + 0x15, 0x00, + 0x25, 0x01, + 0x75, 0x01, + 0x95, 0x01, + 0xB1, 0x02, + 0x95, 0x0F, + 0xB1, 0x03, + 0x06, 0x00, + 0xFF, 0x85, + 0x0B, 0x09, + 0xC5, 0x15, + 0x00, 0x26, + 0xFF, 0x00, + 0x75, 0x08, + 0x96, 0x00, + 0x01, 0xB1, + 0x02, 0xC0, + 0x05, 0x0D, + 0x09, 0x0E, + 0xA1, 0x01, + 0x05, 0x0D, + 0x09, 0x22, + 0xA1, 0x02, + 0x85, 0x03, + 0x09, 0x52, + 0x15, 0x00, + 0x25, 0x0A, + 0x75, 0x08, + 0x95, 0x01, + 0xB1, 0x02, + 0xC0, 0x05, + 0x0D, 0x09, + 0x22, 0xA1, + 0x00, 0x85, + 0x05, 0x09, + 0x57, 0x09, + 0x58, 0x15, + 0x00, 0x25, + 0x01, 0x75, + 0x01, 0x95, + 0x02, 0xB1, + 0x02, 0x95, + 0x06, 0xB1, + 0x03, 0xC0, + 0xC0, 0x06, + 0x00, 0xFF, + 0x09, 0x01, + 0xA1, 0x01, + 0x85, 0x42, + 0x09, 0x06, + 0x15, 0x00, + 0x26, 0xFF, + 0x00, 0x75, + 0x08, 0x95, + 0x03, 0xB1, + 0x02, 0x85, + 0x43, 0x09, + 0x06, 0x15, + 0x00, 0x26, + 0xFF, 0x00, + 0x75, 0x08, + 0x95, 0x03, + 0xB1, 0x02, + 0x06, 0x00, + 0xFF, 0x85, + 0x41, 0x09, + 0x05, 0x15, + 0x00, 0x26, + 0xFF, 0x00, + 0x75, 0x08, + 0x96, 0x00, + 0x01, 0xB1, + 0x02, + 0xC0 /* END_COLLECTION */ +}; +#define I2C_TOUCHPAD_HID_DESC_REGISTER 0x0020 +#define I2C_TOUCHPAD_HID_REPORT_DESC_REGISTER 0x0021 +#define I2C_TOUCHPAD_HID_INPUT_REPORT_REGISTER 0x0024 +#define I2C_TOUCHPAD_HID_OUTPUT_REPORT_REGISTER 0x0025 +#define I2C_TOUCHPAD_HID_COMMAND_REGISTER 0x0022 +#define I2C_TOUCHPAD_HID_DATA_REGISTER 0x0023 +static struct i2c_hid_descriptor touchpad_hid_desc = { + .wHIDDescLength = I2C_HID_DESC_LENGTH, + .bcdVersion = I2C_HID_BCD_VERSION, + .wReportDescLength = sizeof(touchpad_report_desc), + .wReportDescRegister = I2C_TOUCHPAD_HID_REPORT_DESC_REGISTER, + .wInputRegister = I2C_TOUCHPAD_HID_INPUT_REPORT_REGISTER, + /*Note if there are multiple reports wMaxInputLength has to be max*/ + .wMaxInputLength = 0x1F, + .wOutputRegister = I2C_TOUCHPAD_HID_OUTPUT_REPORT_REGISTER, + .wMaxOutputLength = 0, + .wCommandRegister = I2C_TOUCHPAD_HID_COMMAND_REGISTER, + .wDataRegister = I2C_TOUCHPAD_HID_DATA_REGISTER, + .wVendorID = 0x093A, + .wProductID = 0x0274, + .wVersionID = 0x0905, +}; + + + +#endif /* __CROS_EC_TOUCHPAD_DESCRIPTOR_H */ diff --git a/zephyr/program/lotus/lotus/gpio.dtsi b/zephyr/program/lotus/lotus/gpio.dtsi index bf40fd640a..ca5daae27f 100644 --- a/zephyr/program/lotus/lotus/gpio.dtsi +++ b/zephyr/program/lotus/lotus/gpio.dtsi @@ -251,8 +251,8 @@ gpio_apu_aud_pwr_en: apu_aud_pwr_en { gpios = <&gpioa 0 GPIO_OUTPUT_LOW>; }; - i2c_int_tp_1 { - gpios = <&gpioa 4 GPIO_INPUT>; /* HUB board TP module */ + gpio_i2c_int_tp_1: i2c_int_tp_1 { + gpios = <&gpioa 4 GPIO_ODR_HIGH>; /* HUB board TP module */ }; i2c_int_tp_2 { gpios = <&gpio9 6 GPIO_INPUT>; /* HUB board TP module */ diff --git a/zephyr/program/lotus/lotus/i2c.dtsi b/zephyr/program/lotus/lotus/i2c.dtsi index 273e8634bc..c2c900e27b 100644 --- a/zephyr/program/lotus/lotus/i2c.dtsi +++ b/zephyr/program/lotus/lotus/i2c.dtsi @@ -135,7 +135,14 @@ pinctrl-0 = <&i2c4_1_sda_scl_gpf2_f3>; pinctrl-names = "default"; - /* TODO: Add the device on this bus */ + i2chid2: i2chid@2c { + compatible = "cros-ec,i2c-target-hid"; + reg = <0x2c>; + alert_gpios = <&gpioa 4 GPIO_OPEN_DRAIN>; + max_report_size = <32>; + hid_descriptor = "touchpad_hid_desc"; + hid_report_descriptor = "touchpad_report_desc"; + }; }; &i2c_ctrl4 { diff --git a/zephyr/program/lotus/lotus/src/input_module.c b/zephyr/program/lotus/lotus/src/input_module.c index 7806f4b940..41e9226a87 100644 --- a/zephyr/program/lotus/lotus/src/input_module.c +++ b/zephyr/program/lotus/lotus/src/input_module.c @@ -22,10 +22,11 @@ #include "board_adc.h" #include "flash_storage.h" #include "lid_switch.h" +#include "hid_device.h" LOG_MODULE_REGISTER(inputmodule, LOG_LEVEL_INF); - -#define INPUT_MODULE_POWER_ON_DELAY (2) +#define INPUT_MODULE_POLL_INTERVAL 10*MSEC +#define INPUT_MODULE_POWER_ON_DELAY (300*MSEC) #define INPUT_MODULE_MUX_DELAY_US 2 int oc_count; @@ -91,8 +92,10 @@ static void board_input_module_init(void) deck_state = DECK_FORCE_ON; else if (detect_mode == 0x04) deck_state = DECK_FORCE_OFF; - else + else { + hid_target_register(DEVICE_DT_GET(DT_NODELABEL(i2chid2))); deck_state = DECK_OFF; + } } DECLARE_HOOK(HOOK_INIT, board_input_module_init, HOOK_PRIO_DEFAULT + 2); @@ -147,15 +150,25 @@ static void inputdeck_lid_change(void) DECLARE_HOOK(HOOK_LID_CHANGE, inputdeck_lid_change, HOOK_PRIO_DEFAULT); +static void poll_c_deck(void); +DECLARE_DEFERRED(poll_c_deck); static void poll_c_deck(void) { static int turning_on_count; - + static int current_adc_ch = 0; + + hub_board_id[current_adc_ch] = get_hardware_id(ADC_HUB_BOARD_ID); + current_adc_ch = (current_adc_ch + 1) % 8; + set_hub_mux(current_adc_ch); + + if (current_adc_ch != 0) { + hook_call_deferred(&poll_c_deck_data, INPUT_MODULE_POLL_INTERVAL); + return; + } switch (deck_state) { case DECK_OFF: break; case DECK_DISCONNECTED: - scan_c_deck(true); /* TODO only poll touchpad and currently connected B1/C1 modules * if c deck state is ON as these must be removed first */ @@ -166,9 +179,9 @@ static void poll_c_deck(void) break; case DECK_TURNING_ON: turning_on_count++; - scan_c_deck(true); if (input_deck_is_fully_populated() && - turning_on_count > INPUT_MODULE_POWER_ON_DELAY) { + turning_on_count > (INPUT_MODULE_POWER_ON_DELAY / (INPUT_MODULE_POLL_INTERVAL*8))) { + hid_target_unregister(DEVICE_DT_GET(DT_NODELABEL(i2chid2))); gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 1); deck_state = DECK_ON; LOG_INF("Input modules on"); @@ -180,10 +193,10 @@ static void poll_c_deck(void) /* TODO Add lid detection, * if lid is closed input modules cannot be removed */ - - scan_c_deck(true); if (!input_deck_is_fully_populated()) { gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 0); + /* enable TP emulation */ + hid_target_register(DEVICE_DT_GET(DT_NODELABEL(i2chid2))); deck_state = DECK_DISCONNECTED; LOG_INF("Input modules off"); } @@ -193,8 +206,9 @@ static void poll_c_deck(void) default: break; } + + hook_call_deferred(&poll_c_deck_data, INPUT_MODULE_POLL_INTERVAL); } -DECLARE_HOOK(HOOK_TICK, poll_c_deck, HOOK_PRIO_DEFAULT); static void input_modules_powerup(void) { @@ -203,6 +217,7 @@ static void input_modules_powerup(void) else if (deck_state != DECK_FORCE_ON && deck_state != DECK_FORCE_ON) deck_state = DECK_DISCONNECTED; + hook_call_deferred(&poll_c_deck_data, INPUT_MODULE_POLL_INTERVAL); } DECLARE_HOOK(HOOK_CHIPSET_STARTUP, input_modules_powerup, HOOK_PRIO_DEFAULT); @@ -216,6 +231,8 @@ void input_modules_powerdown(void) /* Hub mux input 6 is NC, so lower power draw by disconnecting all PD */ set_hub_mux(TOP_ROW_NOT_CONNECTED); } + + hook_call_deferred(&poll_c_deck_data, -1); } int get_deck_state(void) @@ -237,6 +254,8 @@ static enum ec_status check_deck_state(struct host_cmd_handler_args *args) } else if (p->mode == 0x02) { deck_state = DECK_FORCE_ON; gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 1); + hid_target_unregister(DEVICE_DT_GET(DT_NODELABEL(i2chid2))); + } else if (p->mode == 0x04) { deck_state = DECK_FORCE_OFF; gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 0); diff --git a/zephyr/program/lotus/lotus/src/power_sequence.c b/zephyr/program/lotus/lotus/src/power_sequence.c index e24717d8f4..101a6befe2 100644 --- a/zephyr/program/lotus/lotus/src/power_sequence.c +++ b/zephyr/program/lotus/lotus/src/power_sequence.c @@ -283,6 +283,7 @@ void chipset_reset(enum chipset_shutdown_reason reason) static void chipset_force_g3(void) { + input_modules_powerdown(); gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_sleep_l), 0); gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_hub_b_pwr_en), 0); gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_sys_pwrgd_ec), 0); diff --git a/zephyr/program/lotus/src/hid_device.c b/zephyr/program/lotus/src/hid_device.c index b878e77379..900bbf2317 100644 --- a/zephyr/program/lotus/src/hid_device.c +++ b/zephyr/program/lotus/src/hid_device.c @@ -33,6 +33,10 @@ #include "math_util.h" +#ifdef CONFIG_BOARD_LOTUS +#include "touchpad_descriptor.h" +#endif + #define DT_DRV_COMPAT cros_ec_i2c_target_hid #define LOG_LEVEL CONFIG_I2C_LOG_LEVEL @@ -208,6 +212,7 @@ static struct i2c_hid_descriptor keyboard_hid_desc = { #endif + static struct als_input_report als_sensor; static struct als_feature_report als_feature; @@ -389,7 +394,6 @@ struct i2c_hid_target_data { size_t report_descriptor_size; const struct i2c_hid_descriptor *descriptor; size_t descriptor_size; - }; struct i2c_hid_target_config { @@ -607,35 +611,50 @@ static int hid_target_process_write(struct i2c_target_config *config) break; case I2C_HID_CMD_GET_REPORT: data->report_id = report_id; - switch (report_id) { -#ifdef CONFIG_BOARD_AZALEA - case REPORT_ID_RADIO: - response_size = fill_report(data->buffer, report_id, - &radio_button, - sizeof(struct radio_report)); - break; - case REPORT_ID_CONSUMER: - response_size = fill_report(data->buffer, report_id, - &consumer_button, - sizeof(struct consumer_button_report)); - break; -#endif - case REPORT_ID_SENSOR: - if (report_type == 0x01) { - response_size = fill_report(data->buffer, report_id, - &als_sensor, - sizeof(struct als_input_report)); - } else if (report_type == 0x03) { - response_size = fill_report(data->buffer, report_id, - &als_feature, - sizeof(struct als_feature_report)); +#ifdef CONFIG_BOARD_LOTUS + if (data->descriptor->wCommandRegister == I2C_TOUCHPAD_HID_COMMAND_REGISTER) { + switch (report_id) { + case 2: + static const uint8_t touchpad_feature_2[] = {0x04, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00}; + memcpy(data->buffer, touchpad_feature_2, sizeof(touchpad_feature_2)); + break; + default: + memset(data->buffer, 0, data->buffer_size); + break; + } + } else +#endif /* CONFIG_BOARD_LOTUS */ + { + switch (report_id) { + #ifdef CONFIG_BOARD_AZALEA + case REPORT_ID_RADIO: + response_size = fill_report(data->buffer, report_id, + &radio_button, + sizeof(struct radio_report)); + break; + case REPORT_ID_CONSUMER: + response_size = fill_report(data->buffer, report_id, + &consumer_button, + sizeof(struct consumer_button_report)); + break; + #endif + case REPORT_ID_SENSOR: + if (report_type == 0x01) { + response_size = fill_report(data->buffer, report_id, + &als_sensor, + sizeof(struct als_input_report)); + } else if (report_type == 0x03) { + response_size = fill_report(data->buffer, report_id, + &als_feature, + sizeof(struct als_feature_report)); + } + break; + default: + response_size = fill_report(data->buffer, 0, + NULL, + 0); + break; } - break; - default: - response_size = fill_report(data->buffer, 0, - NULL, - 0); - break; } break; case I2C_HID_CMD_SET_REPORT: @@ -690,6 +709,9 @@ static int hid_target_read_processed(struct i2c_target_config *config, } switch (target_register) { +#ifdef CONFIG_BOARD_LOTUS + case I2C_TOUCHPAD_HID_DESC_REGISTER: +#endif case I2C_HID_MEDIAKEYS_HID_DESC_REGISTER: if (data->buffer_idx < data->descriptor_size) { *val = ((uint8_t *)data->descriptor)[data->buffer_idx++]; @@ -697,6 +719,9 @@ static int hid_target_read_processed(struct i2c_target_config *config, ret = -ENOBUFS; } break; +#ifdef CONFIG_BOARD_LOTUS + case I2C_TOUCHPAD_HID_REPORT_DESC_REGISTER: +#endif case I2C_HID_REPORT_DESC_REGISTER: if (data->buffer_idx < data->report_descriptor_size) { *val = data->report_descriptor[data->buffer_idx++]; @@ -704,6 +729,7 @@ static int hid_target_read_processed(struct i2c_target_config *config, ret = -ENOBUFS; } break; + default: /* Other registers are populated in the write rx*/ if (data->buffer_idx < data->buffer_size) @@ -740,7 +766,12 @@ static int hid_target_read_requested(struct i2c_target_config *config, target_register = I2C_HID_INPUT_REPORT_REGISTER; } - if (target_register == I2C_HID_COMMAND_REGISTER) { + if (target_register == I2C_HID_COMMAND_REGISTER +#ifdef CONFIG_BOARD_LOTUS + || target_register == I2C_TOUCHPAD_HID_COMMAND_REGISTER +#endif + ) + { if (data->buffer_idx) { hid_target_process_write(config); data->buffer_idx = 0; @@ -800,7 +831,11 @@ static int hid_target_stop(struct i2c_target_config *config) /* Clear the interrupt when we have processed the packet */ gpio_pin_set_dt(data->alert_gpio, 1); - if (data->target_register == I2C_HID_COMMAND_REGISTER) { + if (data->target_register == I2C_HID_COMMAND_REGISTER +#ifdef CONFIG_BOARD_LOTUS + || data->target_register == I2C_TOUCHPAD_HID_COMMAND_REGISTER +#endif + ) { if (data->buffer_idx) { hid_target_process_write(config); } @@ -813,7 +848,7 @@ static int hid_target_stop(struct i2c_target_config *config) return 0; } -static int hid_target_register(const struct device *dev) +int hid_target_register(const struct device *dev) { const struct i2c_hid_target_config *cfg = dev->config; struct i2c_hid_target_data *data = dev->data; @@ -821,7 +856,7 @@ static int hid_target_register(const struct device *dev) return i2c_target_register(cfg->bus.bus, &data->config); } -static int hid_target_unregister(const struct device *dev) +int hid_target_unregister(const struct device *dev) { const struct i2c_hid_target_config *cfg = dev->config; struct i2c_hid_target_data *data = dev->data;