mirror of
https://github.com/justinian/edmfd_firmware.git
synced 2025-12-09 16:24:31 -08:00
Switch to serial over USB CDC
This commit is contained in:
@@ -57,7 +57,7 @@ target_sources(edmfd PUBLIC
|
||||
src/edmfd/vendor.cc
|
||||
)
|
||||
|
||||
pico_enable_stdio_uart(edmfd 1)
|
||||
pico_enable_stdio_usb(edmfd 1)
|
||||
pico_enable_stdio_uart(edmfd 0)
|
||||
pico_add_extra_outputs(edmfd)
|
||||
target_link_libraries(edmfd PUBLIC
|
||||
|
||||
@@ -82,22 +82,25 @@ void test_irq_handler(unsigned pin, uint32_t events) {
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setup_default_uart();
|
||||
stdio_init_all();
|
||||
board_init();
|
||||
tud_init(BOARD_TUD_RHPORT);
|
||||
|
||||
if (board_init_after_tusb)
|
||||
board_init_after_tusb();
|
||||
|
||||
stdio_usb_init();
|
||||
while(!tud_cdc_connected()) {
|
||||
tud_task();
|
||||
sleep_ms(10);
|
||||
}
|
||||
|
||||
puts("\n");
|
||||
|
||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||
|
||||
board_init();
|
||||
log::info("board initialized");
|
||||
|
||||
tud_init(BOARD_TUD_RHPORT);
|
||||
|
||||
if (board_init_after_tusb)
|
||||
board_init_after_tusb();
|
||||
log::info("tinyusb initialized");
|
||||
|
||||
i2c::init(i2c_baud);
|
||||
|
||||
// set up interrupt handlers
|
||||
|
||||
@@ -81,6 +81,7 @@ char16_t const *string_desc_arr[size_t(strings::_count)] = {
|
||||
u"EDMFD", // 2: Product
|
||||
nullptr, // 3: Serials will use unique ID if possible
|
||||
u"EDMFD Screen", // 4: screen interface
|
||||
u"EDMFD CDC stdio", // 5: stdio serial port interface
|
||||
};
|
||||
|
||||
static constexpr size_t desc_len = 32;
|
||||
@@ -117,22 +118,47 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
//--------------------------------------------------------------------+
|
||||
// Configuration Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
static constexpr size_t config_total_len = TUD_CONFIG_DESC_LEN + TUD_HID_DESC_LEN + TUD_VENDOR_DESC_LEN;
|
||||
static constexpr size_t config_total_len =
|
||||
TUD_CONFIG_DESC_LEN +
|
||||
TUD_HID_DESC_LEN +
|
||||
TUD_VENDOR_DESC_LEN +
|
||||
TUD_CDC_DESC_LEN +
|
||||
0;
|
||||
|
||||
uint8_t const desc_configuration[config_total_len] = {
|
||||
uint8_t const desc_configuration[] = {
|
||||
// Config number, interface count, string index, total length, attribute, power in mA
|
||||
TUD_CONFIG_DESCRIPTOR(1, uint8_t(interface::_count), 0, config_total_len, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||
|
||||
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
|
||||
TUD_HID_DESCRIPTOR(uint8_t(interface::HID), 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), uint8_t(endpoint::HID), CFG_TUD_HID_EP_BUFSIZE, 5),
|
||||
// HID descriptor
|
||||
TUD_HID_DESCRIPTOR(
|
||||
uint8_t(interface::HID), // interface number
|
||||
0, // string index
|
||||
HID_ITF_PROTOCOL_NONE, // protocol
|
||||
sizeof(desc_hid_report), // report descriptor len
|
||||
uint8_t(endpoint::HID), // input endpoint address
|
||||
CFG_TUD_HID_EP_BUFSIZE, // buffer size
|
||||
5), // polling interval
|
||||
|
||||
// Interface number, string index, EP Out & IN address, EP size
|
||||
TUD_VENDOR_DESCRIPTOR(uint8_t(interface::vendor), uint8_t(strings::interface), uint8_t(endpoint::vendor_out), uint8_t(endpoint::vendor_in), 64),
|
||||
// vendor descriptor
|
||||
TUD_VENDOR_DESCRIPTOR(
|
||||
uint8_t(interface::vendor), // interface number
|
||||
uint8_t(strings::interface), // string index
|
||||
uint8_t(endpoint::vendor_out), // output endpoint address
|
||||
uint8_t(endpoint::vendor_in), // input endpoint address
|
||||
64), // endpoint size
|
||||
|
||||
// CDC: Interface number, string index, EP notification address and size, EP data address (out, in) and size.
|
||||
//TUD_CDC_DESCRIPTOR(uint8_t(interface::CDC), 4, uint8_t(endpoint::CDCnotify), 8, uint8_t(endpoint::CDCout), uint8_t(endpoint::CDCin), 64)
|
||||
// CDC (serial) descriptor
|
||||
TUD_CDC_DESCRIPTOR(
|
||||
uint8_t(interface::CDC), // interface number
|
||||
uint8_t(strings::stdio), // string index
|
||||
uint8_t(endpoint::CDC_notify), // notify endpoint address
|
||||
8, // notify endpoint size
|
||||
uint8_t(endpoint::CDC_out), // data output endpoint address
|
||||
uint8_t(endpoint::CDC_in), // data input endpoint address
|
||||
64), // data endpoint size
|
||||
};
|
||||
|
||||
static_assert(sizeof(desc_configuration) == config_total_len, "Incorrect Configuration Desc size");
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
@@ -161,7 +187,7 @@ static_assert(sizeof(desc_bos) == bos_total_len, "Incorrect BOS length");
|
||||
|
||||
uint8_t const * tud_descriptor_bos_cb() { return desc_bos; }
|
||||
|
||||
uint8_t const desc_ms_os_20[ms_os_20_desc_len] = {
|
||||
uint8_t const desc_ms_os_20[] = {
|
||||
// Set header
|
||||
U16_TO_U8S_LE(0x000A), // length
|
||||
U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), // type
|
||||
@@ -205,4 +231,3 @@ uint8_t const desc_ms_os_20[ms_os_20_desc_len] = {
|
||||
};
|
||||
|
||||
static_assert(sizeof(desc_ms_os_20) == ms_os_20_desc_len, "Incorrect MS OS Desc size");
|
||||
|
||||
|
||||
@@ -11,11 +11,26 @@ enum class strings : uint8_t {
|
||||
product,
|
||||
serial,
|
||||
interface,
|
||||
stdio,
|
||||
_count
|
||||
};
|
||||
|
||||
enum class interface : uint8_t { HID, vendor, _count };
|
||||
enum class endpoint : uint8_t { HID = 0x81, vendor_out = 0x02, vendor_in = 0x83 };
|
||||
enum class interface : uint8_t {
|
||||
HID, // 0
|
||||
vendor, // 1
|
||||
CDC, // 2
|
||||
CDC_data, // 3
|
||||
_count // 4
|
||||
};
|
||||
|
||||
enum class endpoint : uint8_t {
|
||||
HID = 0x81,
|
||||
vendor_out = 0x02,
|
||||
vendor_in = 0x82,
|
||||
CDC_notify = 0x83,
|
||||
CDC_out = 0x04,
|
||||
CDC_in = 0x84,
|
||||
};
|
||||
|
||||
enum class vendor_req : uint8_t {
|
||||
microsoft = 1,
|
||||
@@ -23,4 +38,4 @@ enum class vendor_req : uint8_t {
|
||||
};
|
||||
|
||||
extern uint8_t const desc_ms_os_20[];
|
||||
static constexpr size_t ms_os_20_desc_len = 0xb2;
|
||||
static constexpr size_t ms_os_20_desc_len = 0xb2;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
extern "C" {
|
||||
// TinyUSB callbacks
|
||||
bool tud_Ivendor_control_xfer_cb(uint8_t, uint8_t, tusb_control_request_t const*);
|
||||
bool tud_vendor_control_xfer_cb(uint8_t, uint8_t, tusb_control_request_t const*);
|
||||
void tud_vendor_rx_cb(uint8_t, uint8_t const*, uint16_t);
|
||||
void tud_vendor_tx_cb(uint8_t, uint32_t);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
|
||||
//------------- CLASS -------------//
|
||||
#define CFG_TUD_HID 1
|
||||
#define CFG_TUD_CDC 0
|
||||
#define CFG_TUD_CDC 1
|
||||
#define CFG_TUD_MSC 0
|
||||
#define CFG_TUD_MIDI 0
|
||||
#define CFG_TUD_VENDOR 1
|
||||
@@ -100,6 +100,9 @@
|
||||
// HID buffer size Should be sufficient to hold ID (if any) + Data
|
||||
#define CFG_TUD_HID_EP_BUFSIZE 16
|
||||
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE 64
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 64
|
||||
|
||||
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
|
||||
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
|
||||
|
||||
@@ -107,4 +110,4 @@
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_CONFIG_H_ */
|
||||
#endif /* _TUSB_CONFIG_H_ */
|
||||
|
||||
Reference in New Issue
Block a user