feat(platform/lvgl): enable hid boot protocol

Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
sakumisu
2025-04-17 11:28:53 +08:00
parent 73c8062518
commit 947f8530ef

View File

@@ -10,7 +10,6 @@
#include "usbh_hid.h" #include "usbh_hid.h"
#include "usbh_hid_lvgl.h" #include "usbh_hid_lvgl.h"
/* LVGL image of cursor */ /* LVGL image of cursor */
LV_IMG_DECLARE(img_cursor) LV_IMG_DECLARE(img_cursor)
@@ -63,22 +62,22 @@ static void usbh_hid_lvgl_read_mouse(lv_indev_t *indev_drv, lv_indev_data_t *dat
/* Get coordinates by rotation with sensitivity */ /* Get coordinates by rotation with sensitivity */
switch (lv_display_get_rotation(disp)) { switch (lv_display_get_rotation(disp)) {
case LV_DISPLAY_ROTATION_0: case LV_DISPLAY_ROTATION_0:
data->point.x = ctx->mouse.x / ctx->mouse.sensitivity; data->point.x = ctx->mouse.x / ctx->mouse.sensitivity;
data->point.y = ctx->mouse.y / ctx->mouse.sensitivity; data->point.y = ctx->mouse.y / ctx->mouse.sensitivity;
break; break;
case LV_DISPLAY_ROTATION_90: case LV_DISPLAY_ROTATION_90:
data->point.y = width - ctx->mouse.x / ctx->mouse.sensitivity; data->point.y = width - ctx->mouse.x / ctx->mouse.sensitivity;
data->point.x = ctx->mouse.y / ctx->mouse.sensitivity; data->point.x = ctx->mouse.y / ctx->mouse.sensitivity;
break; break;
case LV_DISPLAY_ROTATION_180: case LV_DISPLAY_ROTATION_180:
data->point.x = width - ctx->mouse.x / ctx->mouse.sensitivity; data->point.x = width - ctx->mouse.x / ctx->mouse.sensitivity;
data->point.y = height - ctx->mouse.y / ctx->mouse.sensitivity; data->point.y = height - ctx->mouse.y / ctx->mouse.sensitivity;
break; break;
case LV_DISPLAY_ROTATION_270: case LV_DISPLAY_ROTATION_270:
data->point.y = ctx->mouse.x / ctx->mouse.sensitivity; data->point.y = ctx->mouse.x / ctx->mouse.sensitivity;
data->point.x = height - ctx->mouse.y / ctx->mouse.sensitivity; data->point.x = height - ctx->mouse.y / ctx->mouse.sensitivity;
break; break;
} }
if (ctx->mouse.left_button) { if (ctx->mouse.left_button) {
@@ -178,64 +177,65 @@ static char usb_hid_get_keyboard_char(uint8_t key, uint8_t shift)
{ {
char ret_key = 0; char ret_key = 0;
const uint8_t keycode2ascii [57][2] = { const uint8_t keycode2ascii[57][2] = {
{0, 0}, /* HID_KEY_NO_PRESS */ { 0, 0 }, /* HID_KEY_NO_PRESS */
{0, 0}, /* HID_KEY_ROLLOVER */ { 0, 0 }, /* HID_KEY_ROLLOVER */
{0, 0}, /* HID_KEY_POST_FAIL */ { 0, 0 }, /* HID_KEY_POST_FAIL */
{0, 0}, /* HID_KEY_ERROR_UNDEFINED */ { 0, 0 }, /* HID_KEY_ERROR_UNDEFINED */
{'a', 'A'}, /* HID_KEY_A */ { 'a', 'A' }, /* HID_KEY_A */
{'b', 'B'}, /* HID_KEY_B */ { 'b', 'B' }, /* HID_KEY_B */
{'c', 'C'}, /* HID_KEY_C */ { 'c', 'C' }, /* HID_KEY_C */
{'d', 'D'}, /* HID_KEY_D */ { 'd', 'D' }, /* HID_KEY_D */
{'e', 'E'}, /* HID_KEY_E */ { 'e', 'E' }, /* HID_KEY_E */
{'f', 'F'}, /* HID_KEY_F */ { 'f', 'F' }, /* HID_KEY_F */
{'g', 'G'}, /* HID_KEY_G */ { 'g', 'G' }, /* HID_KEY_G */
{'h', 'H'}, /* HID_KEY_H */ { 'h', 'H' }, /* HID_KEY_H */
{'i', 'I'}, /* HID_KEY_I */ { 'i', 'I' }, /* HID_KEY_I */
{'j', 'J'}, /* HID_KEY_J */ { 'j', 'J' }, /* HID_KEY_J */
{'k', 'K'}, /* HID_KEY_K */ { 'k', 'K' }, /* HID_KEY_K */
{'l', 'L'}, /* HID_KEY_L */ { 'l', 'L' }, /* HID_KEY_L */
{'m', 'M'}, /* HID_KEY_M */ { 'm', 'M' }, /* HID_KEY_M */
{'n', 'N'}, /* HID_KEY_N */ { 'n', 'N' }, /* HID_KEY_N */
{'o', 'O'}, /* HID_KEY_O */ { 'o', 'O' }, /* HID_KEY_O */
{'p', 'P'}, /* HID_KEY_P */ { 'p', 'P' }, /* HID_KEY_P */
{'q', 'Q'}, /* HID_KEY_Q */ { 'q', 'Q' }, /* HID_KEY_Q */
{'r', 'R'}, /* HID_KEY_R */ { 'r', 'R' }, /* HID_KEY_R */
{'s', 'S'}, /* HID_KEY_S */ { 's', 'S' }, /* HID_KEY_S */
{'t', 'T'}, /* HID_KEY_T */ { 't', 'T' }, /* HID_KEY_T */
{'u', 'U'}, /* HID_KEY_U */ { 'u', 'U' }, /* HID_KEY_U */
{'v', 'V'}, /* HID_KEY_V */ { 'v', 'V' }, /* HID_KEY_V */
{'w', 'W'}, /* HID_KEY_W */ { 'w', 'W' }, /* HID_KEY_W */
{'x', 'X'}, /* HID_KEY_X */ { 'x', 'X' }, /* HID_KEY_X */
{'y', 'Y'}, /* HID_KEY_Y */ { 'y', 'Y' }, /* HID_KEY_Y */
{'z', 'Z'}, /* HID_KEY_Z */ { 'z', 'Z' }, /* HID_KEY_Z */
{'1', '!'}, /* HID_KEY_1 */ { '1', '!' }, /* HID_KEY_1 */
{'2', '@'}, /* HID_KEY_2 */ { '2', '@' }, /* HID_KEY_2 */
{'3', '#'}, /* HID_KEY_3 */ { '3', '#' }, /* HID_KEY_3 */
{'4', '$'}, /* HID_KEY_4 */ { '4', '$' }, /* HID_KEY_4 */
{'5', '%'}, /* HID_KEY_5 */ { '5', '%' }, /* HID_KEY_5 */
{'6', '^'}, /* HID_KEY_6 */ { '6', '^' }, /* HID_KEY_6 */
{'7', '&'}, /* HID_KEY_7 */ { '7', '&' }, /* HID_KEY_7 */
{'8', '*'}, /* HID_KEY_8 */ { '8', '*' }, /* HID_KEY_8 */
{'9', '('}, /* HID_KEY_9 */ { '9', '(' }, /* HID_KEY_9 */
{'0', ')'}, /* HID_KEY_0 */ { '0', ')' }, /* HID_KEY_0 */
{'\r', '\r'}, /* HID_KEY_ENTER */ { '\r', '\r' }, /* HID_KEY_ENTER */
{0, 0}, /* HID_KEY_ESC */ { 0, 0 }, /* HID_KEY_ESC */
{'\b', 0}, /* HID_KEY_DEL */ { '\b', 0 }, /* HID_KEY_DEL */
{0, 0}, /* HID_KEY_TAB */ { 0, 0 }, /* HID_KEY_TAB */
{' ', ' '}, /* HID_KEY_SPACE */ { ' ', ' ' }, /* HID_KEY_SPACE */
{'-', '_'}, /* HID_KEY_MINUS */ { '-', '_' }, /* HID_KEY_MINUS */
{'=', '+'}, /* HID_KEY_EQUAL */ { '=', '+' }, /* HID_KEY_EQUAL */
{'[', '{'}, /* HID_KEY_OPEN_BRACKET */ { '[', '{' }, /* HID_KEY_OPEN_BRACKET */
{']', '}'}, /* HID_KEY_CLOSE_BRACKET */ { ']', '}' }, /* HID_KEY_CLOSE_BRACKET */
{'\\', '|'}, /* HID_KEY_BACK_SLASH */ { '\\', '|' }, /* HID_KEY_BACK_SLASH */
{'\\', '|'}, /* HID_KEY_SHARP */ // HOTFIX: for NonUS Keyboards repeat HID_KEY_BACK_SLASH { '\\', '|' },
{';', ':'}, /* HID_KEY_COLON */ /* HID_KEY_SHARP */ // HOTFIX: for NonUS Keyboards repeat HID_KEY_BACK_SLASH
{'\'', '"'}, /* HID_KEY_QUOTE */ { ';', ':' }, /* HID_KEY_COLON */
{'`', '~'}, /* HID_KEY_TILDE */ { '\'', '"' }, /* HID_KEY_QUOTE */
{',', '<'}, /* HID_KEY_LESS */ { '`', '~' }, /* HID_KEY_TILDE */
{'.', '>'}, /* HID_KEY_GREATER */ { ',', '<' }, /* HID_KEY_LESS */
{'/', '?'} /* HID_KEY_SLASH */ { '.', '>' }, /* HID_KEY_GREATER */
{ '/', '?' } /* HID_KEY_SLASH */
}; };
if (shift > 1) { if (shift > 1) {
@@ -310,6 +310,8 @@ void usbh_hid_keyboard_callback(void *arg, int nbytes)
void usbh_hid_run(struct usbh_hid *hid_class) void usbh_hid_run(struct usbh_hid *hid_class)
{ {
usbh_hid_set_protocol(hid_class, 0);
if (hid_class->hport->config.intf[hid_class->intf].altsetting[0].intf_desc.bInterfaceProtocol == HID_PROTOCOL_KEYBOARD) { if (hid_class->hport->config.intf[hid_class->intf].altsetting[0].intf_desc.bInterfaceProtocol == HID_PROTOCOL_KEYBOARD) {
usbh_int_urb_fill(&hid_class->intin_urb, hid_class->hport, hid_class->intin, hid_keyboard_buffer, hid_class->intin->wMaxPacketSize, 0, usbh_int_urb_fill(&hid_class->intin_urb, hid_class->hport, hid_class->intin, hid_keyboard_buffer, hid_class->intin->wMaxPacketSize, 0,
usbh_hid_keyboard_callback, hid_class); usbh_hid_keyboard_callback, hid_class);