Initial working USB communication
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
#include "common.h"
|
||||
#include "usb.h"
|
||||
|
||||
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_HID * TUD_HID_DESC_LEN)
|
||||
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
|
||||
|
||||
static const char *TAG = "valconomy-usb";
|
||||
|
||||
@@ -38,13 +38,9 @@ const tusb_desc_device_t val_usb_dev_descriptor = {
|
||||
.bNumConfigurations = 0x01,
|
||||
};
|
||||
|
||||
const uint8_t val_hid_report_descriptor[] = {
|
||||
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)),
|
||||
};
|
||||
|
||||
char val_dev_serial[13];
|
||||
const char* val_hid_string_descriptor[5] = {
|
||||
// 0: is supported language is English (0x0409)
|
||||
const char* val_usb_string_descriptor[5] = {
|
||||
// 0: supported language is English (0x0409)
|
||||
(char[]){0x09, 0x04},
|
||||
// 1: Manufacturer
|
||||
"/dev/player0",
|
||||
@@ -56,12 +52,18 @@ const char* val_hid_string_descriptor[5] = {
|
||||
"Valconomy HID interface",
|
||||
};
|
||||
|
||||
static const uint8_t val_hid_conf_descriptor[] = {
|
||||
const uint8_t val_hid_report_descriptor[] = {
|
||||
TUD_HID_REPORT_DESC_GENERIC_INOUT(USB_EP_BUFSIZE),
|
||||
};
|
||||
|
||||
const uint8_t val_hid_conf_descriptor[] = {
|
||||
// Configuration number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, 1, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||
|
||||
// Interface number, string index, boot protocol, report descriptor len, EP In address, size & polling interval
|
||||
TUD_HID_DESCRIPTOR(0, 4, false, sizeof(val_hid_report_descriptor), 0x81, 16, 10),
|
||||
// HID requires an IN endpoint even if we don't care about it
|
||||
// Interface number, string index, protocol, report descriptor len, EP Out & In address, size & polling interval (ms)
|
||||
// 0x80 in endpoint address indicates IN
|
||||
TUD_HID_INOUT_DESCRIPTOR(0, 4, HID_ITF_PROTOCOL_NONE, sizeof(val_hid_report_descriptor), EPNUM_HID, 0x80 | EPNUM_HID, USB_EP_BUFSIZE, 100)
|
||||
};
|
||||
|
||||
// TinyUSB callbacks
|
||||
@@ -88,7 +90,13 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_t
|
||||
|
||||
// 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 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) {
|
||||
assert(report_id == 0 && report_type == HID_REPORT_TYPE_OUTPUT);
|
||||
ESP_LOGI(TAG, "Got %hu bytes report %hhu", bufsize, report_id);
|
||||
for (uint16_t i = 0; i < bufsize; i++) {
|
||||
ESP_LOGI(TAG, "b: %02hhx", buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void val_usb_init(void) {
|
||||
ESP_LOGI(TAG, "Initializing USB");
|
||||
@@ -102,8 +110,8 @@ void val_usb_init(void) {
|
||||
|
||||
const tinyusb_config_t cfg = {
|
||||
.device_descriptor = &val_usb_dev_descriptor,
|
||||
.string_descriptor = val_hid_string_descriptor,
|
||||
.string_descriptor_count = sizeof(val_hid_string_descriptor) / sizeof(char *),
|
||||
.string_descriptor = val_usb_string_descriptor,
|
||||
.string_descriptor_count = sizeof(val_usb_string_descriptor) / sizeof(char *),
|
||||
.external_phy = false,
|
||||
|
||||
#if (TUD_OPT_HIGH_SPEED)
|
||||
|
@@ -2,4 +2,7 @@
|
||||
|
||||
#include "tinyusb_types.h"
|
||||
|
||||
#define EPNUM_HID 0x01
|
||||
#define USB_EP_BUFSIZE 64
|
||||
|
||||
void val_usb_init(void);
|
||||
|
Reference in New Issue
Block a user