A hid proxy using ESP32C3 and CH9329/CH9328. ESP32C3 responds for BLE hosting, LED controling and storing connected bluetooth device addr with nvs_flash. And CH9329/CH9328 is used to simulate keyboard.
This was tested on following keyboards:
- zmk based keyboards
- hid proxy for bluetooth keyboard: Scan and connect to BLE keyboards. The code is modified based on the official example: https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/esp_hid_host
Which device will be selected:
- UUID is 0x1812 while parsing with ESP_BLE_AD_TYPE_16SRV_PART
- Apprearence equals to ESP_BLE_APPEARANCE_HID_KEYBOARD (0x03C1)
- The first scanned device will be selected
- No authentication is required
- Remember connected keyboard: Use nvs_flash to store one bluetooth device address. Once this is set, hid host will skip other devices.
- LED signals to illustrate connection mode. There are three LED mode:
- Rapid blink mode: Scan for new device.
- Slow blink mode: Scan for known device.
- Off: Connected.
- Relay the keyboard’s input to CH9328/CH9329
Install esp idf: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/get-started/index.html
set target to esp32c3
idf.py set-target esp32c3
Then, build and flash to your hid proxy using serial port dev/ttyUSB0. With monitor, you can start monitor after flashing, use Ctrl-] to stop monitor and release the port.
idf.py -p /dev/ttyUSB0 -b 115200 flash monitor
- Connect to new device: if no device is stored, esp32c3 will start scanning available keyboards, and led will turn into rapid blink mode. The scanning may take a few seconds. After connecting to the first scanned device, led will tuen into off mode. And the connected device is stored.
- Connect to known device: If no device is connected and there exists a bluetooth device address (esp_bd_addr_t) stored in esp32c3’s nvs_flash. The LED will try scan this recorded device, and tune led into slow blink mode.
- Erase known device: Press the boot button (IO9) for at lease one second, until the led turns into rapid blink mode.
- Crash if the opened keyboard is already connected to another hid_proxy.
- LED mode change delay after pressing the boot button to erase.
- Storing multiple devices and swithing with an extra button
- Support ble mouse with ch9329
- Refactor the code to make it more robust
- start a web server for keyboad connecting, this is useful when you have multiple keyboards or need authentication