hello_usb_input

Example of the component cube32esp/cube32_bsp v0.0.17
# Hello USB Input Example

This example demonstrates USB HID keyboard and mouse input using the CUBE32 USB Input driver with LVGL graphical user interface.

## Features

- **USB HID Keyboard Support**
  - Full keyboard input with printable characters
  - Special keys: Enter, Backspace, Tab, Escape
  - Real-time key press display
  - Text input buffer with scrolling display

- **USB HID Mouse Support**
  - Mouse cursor control via LVGL pointer input device
  - Left button click detection
  - Visual cursor indicator on screen
  - Screen rotation aware - mouse movement correctly mapped to all rotation settings (0, 90, 180, 270 degrees)

- **LVGL Dark Theme UI**
  - Connection status display
  - Current key press indicator
  - Click counter display
  - Three test buttons for mouse click testing
  - Text input area showing keyboard input

## Configuration Requirements

Enable the following options in `idf.py menuconfig`:

1. **PMU Configuration** (CUBE32 Board Configuration → PMU Configuration)
   - [x] Enable PMU (CONFIG_CUBE32_PMU_ENABLED)

2. **Display Configuration** (CUBE32 Board Configuration → Display Configuration)
   - [x] Enable Display (CONFIG_CUBE32_DISPLAY_ENABLED)
   - Select Display Board Model (CUBE_TFT_TOUCH_154 or CUBE_TFT_TOUCH_200)
   - Set Display Rotation (0, 90, 180, 270)
   - [x] Enable LVGL (CONFIG_CUBE32_LVGL_ENABLED)

3. **USB Input Configuration** (CUBE32 Board Configuration → USB Input Configuration)
   - [x] Enable USB Input (CONFIG_CUBE32_USB_INPUT_ENABLED)
   - [x] Enable USB Keyboard (CONFIG_CUBE32_USB_KEYBOARD_ENABLED)
   - [x] Enable USB Mouse (CONFIG_CUBE32_USB_MOUSE_ENABLED)

4. **Application Selection** (CUBE32 Application Selection)
   - Select "Hello USB Input Example"

## Hardware Setup

- ESP32-S3 with built-in USB OTG port
- Connect USB keyboard or mouse **directly** to the ESP32-S3 USB port
- **USB hubs are NOT supported** - devices must be connected directly
- USB OTG power (5V) is automatically enabled via AXP2101 BLDO2

## How It Works

### USB OTG Power
The AXP2101 PMU's BLDO2 output (set to 3.3V) controls a switch that enables 5V USB OTG power output. This is automatically enabled when the USB Input driver initializes.

### Display Rotation Support
The USB mouse input automatically handles all display rotation settings (0°, 90°, 180°, 270°). Mouse movement is correctly mapped to cursor movement regardless of the rotation configured in Kconfig.

### Screen Resolution
The display resolution is automatically determined by the selected Display Board Model in Kconfig:
- CUBE_TFT_TOUCH_154: 240x240 pixels
- CUBE_TFT_TOUCH_200: 240x320 pixels

## Usage

1. Configure and build the project:
   ```bash
   idf.py menuconfig  # Enable required options
   idf.py build
   idf.py flash monitor
   ```

2. Connect a USB keyboard or mouse to the ESP32-S3 USB port

3. The display will show connection status and respond to input:
   - Type on the keyboard to see characters appear in the text input area
   - Move the mouse to control the red circular cursor
   - Click the test buttons to increment the click counter

## Troubleshooting

- **"Waiting for device..."**: USB device not connected or not recognized
- **No cursor movement**: Ensure USB Mouse is enabled in Kconfig
- **No keyboard input**: Ensure USB Keyboard is enabled in Kconfig
- **Display not working**: Check Display and LVGL are enabled in Kconfig
- **USB power not available**: Check PMU is enabled and AXP2101 is properly initialized

## Related Files

- Driver: `components/cube32/src/drivers/usb/usb_input.cpp`
- Header: `components/cube32/include/drivers/usb/usb_input.h`
- LVGL Mouse Integration: `components/cube32/src/drivers/lvgl/lvgl_driver.cpp`

## Note

This demo cannot be used simultaneously with USB Modem functionality, as both require the ESP32-S3's built-in USB port.

To create a project from this example, run:

idf.py create-project-from-example "cube32esp/cube32_bsp=0.0.17:hello_usb_input"

or download archive (~10.17 KB)