Skip to content

Commit

Permalink
Lotus.touchpad emulation (#875)
Browse files Browse the repository at this point in the history
* 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 <ktl@frame.work>

* lotus remove sleep in input module check

speed up input module detection so we can shutdown faster on disconnect

Signed-off-by: Kieran Levin <ktl@frame.work>

* lint cleanup

Signed-off-by: Kieran Levin <ktl@frame.work>

---------

Signed-off-by: Kieran Levin <ktl@frame.work>
  • Loading branch information
kiram9 authored Nov 23, 2023
1 parent 750fd0a commit 9d49389
Show file tree
Hide file tree
Showing 7 changed files with 480 additions and 46 deletions.
3 changes: 3 additions & 0 deletions zephyr/program/lotus/include/hid_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
369 changes: 369 additions & 0 deletions zephyr/program/lotus/include/lotus/touchpad_descriptor.h
Original file line number Diff line number Diff line change
@@ -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 */
4 changes: 2 additions & 2 deletions zephyr/program/lotus/lotus/gpio.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit 9d49389

Please sign in to comment.