Skip to content

Commit

Permalink
esp_lvgl_port: Add support for USB HID mouse/keyboard as an input dev…
Browse files Browse the repository at this point in the history
…ice.
  • Loading branch information
espzav committed Nov 24, 2023
1 parent e3b0b94 commit 4571723
Show file tree
Hide file tree
Showing 8 changed files with 710 additions and 21 deletions.
6 changes: 6 additions & 0 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ USE_MDFILE_AS_MAINPAGE = ./README.md
GENERATE_LATEX = NO
GENERATE_HTML = NO
GENERATE_XML = YES
PREDEFINED = \
$(ENV_DOXYGEN_DEFINES) \
ESP_LVGL_PORT_TOUCH_COMPONENT=1 \
ESP_LVGL_PORT_BUTTON_COMPONENT=1 \
ESP_LVGL_PORT_KNOB_COMPONENT=1 \
ESP_LVGL_PORT_USB_HOST_HID_COMPONENT=1
12 changes: 10 additions & 2 deletions components/esp_lvgl_port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
idf_component_register(SRCS "esp_lvgl_port.c" INCLUDE_DIRS "include" REQUIRES "esp_lcd" PRIV_REQUIRES "esp_timer")
file(GLOB_RECURSE IMAGE_SOURCES images/*.c)

idf_component_register(SRCS "esp_lvgl_port.c" ${IMAGE_SOURCES} INCLUDE_DIRS "include" REQUIRES "esp_lcd" PRIV_REQUIRES "esp_timer")

idf_build_get_property(build_components BUILD_COMPONENTS)
if("espressif__button" IN_LIST build_components)
Expand All @@ -18,4 +20,10 @@ if("espressif__knob" IN_LIST build_components)
endif()
if("knob" IN_LIST build_components)
target_link_libraries(${COMPONENT_LIB} PRIVATE idf::knob)
endif()
endif()
if("espressif__usb_host_hid" IN_LIST build_components)
target_link_libraries(${COMPONENT_LIB} PRIVATE idf::espressif__usb_host_hid)
endif()
if("usb_host_hid" IN_LIST build_components)
target_link_libraries(${COMPONENT_LIB} PRIVATE idf::usb_host_hid)
endif()
37 changes: 37 additions & 0 deletions components/esp_lvgl_port/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,43 @@ Add encoder input to the LVGL. It can be called more times for adding more encod

**Note:** When you use encoder for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.

### Add USB HID keyboard and mouse input

Add mouse and keyboard input to the LVGL. This feature is available only when the component [usb_host_hid](https://components.espressif.com/components/espressif/usb_host_hid) was added into the project.

``` c
/* USB initialization */
usb_host_config_t host_config = {
.skip_phy_setup = false,
.intr_flags = ESP_INTR_FLAG_LEVEL1,
};
ESP_ERROR_CHECK(usb_host_install(&host_config));

...

/* Add mouse input device */
const lvgl_port_hid_mouse_cfg_t mouse_cfg = {
.disp = display,
.sensitivity = 1, /* Sensitivity of the mouse moving */
};
lvgl_port_add_usb_hid_mouse_input(&mouse_cfg);

/* Add keyboard input device */
const lvgl_port_hid_keyboard_cfg_t kb_cfg = {
.disp = display,
};
kb_indev = lvgl_port_add_usb_hid_keyboard_input(&kb_cfg);
```
Keyboard special behavior (when objects are in group):
- **TAB**: Select next object
- **SHIFT** + **TAB**: Select previous object
- **ENTER**: Control object (e.g. click to button)
- **ARROWS** or **HOME** or **END**: Move in text area
- **DEL** or **Backspace**: Remove character in textarea
**Note:** When you use keyboard for control LVGL objects, these objects must be added to LVGL groups. See [LVGL documentation](https://docs.lvgl.io/master/overview/indev.html?highlight=lv_indev_get_act#keypad-and-encoder) for more info.
### LVGL API usage
Every LVGL calls must be protected with these lock/unlock commands:
Expand Down
Loading

0 comments on commit 4571723

Please sign in to comment.