Skip to content

Commit 3ad4a09

Browse files
Add support for ESP32P4 and add usb
1 parent d97d180 commit 3ad4a09

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

ports/esp32/boards/FireBeetle_2_ESP32_P4/mpconfigboard.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ set(IDF_TARGET esp32p4)
22

33
set(SDKCONFIG_DEFAULTS
44
boards/sdkconfig.base
5+
boards/sdkconfig.p4usb
56
boards/FireBeetle_2_ESP32_P4/sdkconfig.board
67
)
7-
set(MP_DL_FACE_RECOGNITION_ENABLED 1)
8-
set(MP_DL_COCO_DETECTOR_ENABLED 1)
9-
set(MP_DL_PEDESTRISN_DETECTOR_ENABLED 1)
10-
set(MP_DL_IMAGENET_CLS_ENABLED 0)

ports/esp32/boards/sdkconfig.p4usb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_USB_OTG_SUPPORTED=y
2+
CONFIG_TINYUSB_CDC_ENABLED=y
3+
CONFIG_TINYUSB_HID_COUNT=1

ports/esp32/boards/sdkconfig.usb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CONFIG_USB_OTG_SUPPORTED=y
22
CONFIG_TINYUSB_CDC_ENABLED=y
3+
CONFIG_TINYUSB_HID_COUNT=1
34
CONFIG_TINYUSB_CDC_RX_BUFSIZE=256
45
CONFIG_TINYUSB_CDC_TX_BUFSIZE=256

ports/esp32/mpconfigport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@
276276
#define MICROPY_HW_USB_CDC (MICROPY_HW_ENABLE_USBDEV)
277277
#endif
278278

279+
// Enable stdio over native USB peripheral HID via TinyUSB
280+
#ifndef MICROPY_HW_USB_HID
281+
#define MICROPY_HW_USB_HID (MICROPY_HW_USB_CDC)
282+
#endif
283+
279284
// Enable stdio over USB Serial/JTAG peripheral
280285
#ifndef MICROPY_HW_ESP_USB_SERIAL_JTAG
281286
#if !CONFIG_IDF_TARGET_ESP32P4

shared/tinyusb/mp_usbd.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,52 @@ void mp_usbd_hex_str(char *out_str, const uint8_t *bytes, size_t bytes_len) {
6363
}
6464
out_str[hex_len] = 0;
6565
}
66+
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32P4
67+
const uint8_t hid_report_descriptor[] = {
68+
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)),
69+
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE))
70+
};
6671

72+
/**
73+
* @brief String descriptor
74+
*/
75+
const char* hid_string_descriptor[5] = {
76+
// array of pointer to string descriptors
77+
(char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
78+
"TinyUSB", // 1: Manufacturer
79+
"TinyUSB Device", // 2: Product
80+
"123456", // 3: Serials, should use chip ID
81+
"Example HID interface", // 4: HID
82+
};
83+
84+
/********* TinyUSB HID callbacks ***************/
85+
86+
// Invoked when received GET HID REPORT DESCRIPTOR request
87+
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
88+
uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance)
89+
{
90+
// We use only one interface and one HID report descriptor, so we can ignore parameter 'instance'
91+
return hid_report_descriptor;
92+
}
93+
94+
// Invoked when received GET_REPORT control request
95+
// Application must fill buffer report's content and return its length.
96+
// Return zero will cause the stack to STALL request
97+
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
98+
{
99+
(void) instance;
100+
(void) report_id;
101+
(void) report_type;
102+
(void) buffer;
103+
(void) reqlen;
104+
105+
return 0;
106+
}
107+
108+
// Invoked when received SET_REPORT control request or
109+
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
110+
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
111+
{
112+
}
113+
#endif
67114
#endif // MICROPY_HW_ENABLE_USBDEV

shared/tinyusb/tusb_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
#define CFG_TUD_CDC (0)
7474
#endif
7575

76+
#if MICROPY_HW_USB_HID
77+
#define CFG_TUD_HID (1)
78+
#else
79+
#define CFG_TUD_HID (0)
80+
#endif
81+
7682
#if MICROPY_HW_USB_MSC
7783
#define CFG_TUD_MSC (1)
7884
#else

0 commit comments

Comments
 (0)