Issues Configuring HID and CDC Composite Device on ESP32-S3 with TinyUSB #3045
Unanswered
Talha-Babar
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I'm currently working on a project involving the ESP32-S3. I aim to configure it as a composite USB device supporting both HID and CDC functionalities using the TinyUSB stack. I want to use Gamepad and CDC at the same time.
Development Environment:
Hardware: ESP32-S3
Framework: ESP-IDF v5.0
USB Stack: TinyUSB integrated with ESP-IDF
Here is the code:
`
#define CONFIG_TINYUSB_CDC_COUNT 1
static const char *TAG = "CDC+HID";
static uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE + 1];
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + CFG_TUD_HID * TUD_HID_DESC_LEN)
const uint8_t hid_report_descriptor[] = {
TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(3))
};
/**
*/
const char *hid_string_descriptor[5] = {
// array of pointer to string descriptors
(char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"CDC+HID", // 2: Product
"123456", // 3: Serials, should use chip ID
"HID interface", // 4: HID
};
static const uint8_t hid_configuration_descriptor[] = {
// Configuration Descriptor: 1 configuration, 1 HID interface, 1 CDC interface
TUD_CONFIG_DESCRIPTOR(2, 2, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
};
uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance)
{
// We use only one interface and one HID report descriptor, so we can ignore parameter 'instance'
return hid_report_descriptor;
}
// Invoked when received GET_REPORT control request
// Application must fill buffer report's content and return its length.
// Return zero will cause the stack to STALL request
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)
{
(void)instance;
(void)report_id;
(void)report_type;
(void)buffer;
(void)reqlen;
}
// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
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)
{
}
void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
{
size_t rx_size = 0;
esp_err_t ret = tinyusb_cdcacm_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE, &rx_size);
if (ret == ESP_OK)
{
ESP_LOGI(TAG, "Data from channel %d:", itf);
ESP_LOG_BUFFER_HEXDUMP(TAG, buf, rx_size, ESP_LOG_INFO);
}
else
{
ESP_LOGE(TAG, "Read error");
}
tinyusb_cdcacm_write_queue(itf, buf, rx_size);
tinyusb_cdcacm_write_flush(itf, 0);
}
void tinyusb_cdc_line_state_changed_callback(int itf, cdcacm_event_t *event)
{
int dtr = event->line_state_changed_data.dtr;
int rts = event->line_state_changed_data.rts;
ESP_LOGI(TAG, "Line state changed on channel %d: DTR:%d, RTS:%d", itf, dtr, rts);
}
void app_main(void)
{
ESP_LOGI(TAG, "USB initialization");
const tinyusb_config_t tusb_cfg = {
.device_descriptor = NULL,
.string_descriptor = hid_string_descriptor,
.external_phy = false,
.configuration_descriptor = hid_configuration_descriptor,
};
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
`
ESP_ERROR_CHECK(tusb_cdc_acm_init(&acm_cfg));
}
`
Upon connecting the ESP32-S3 to a host system, the device is not recognized.
Thank you for your time and assistance.
Best regards,
Beta Was this translation helpful? Give feedback.
All reactions