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
|
src/edmfd/vendor.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
pico_enable_stdio_uart(edmfd 1)
|
pico_enable_stdio_usb(edmfd 1)
|
||||||
pico_enable_stdio_uart(edmfd 0)
|
pico_enable_stdio_uart(edmfd 0)
|
||||||
pico_add_extra_outputs(edmfd)
|
pico_add_extra_outputs(edmfd)
|
||||||
target_link_libraries(edmfd PUBLIC
|
target_link_libraries(edmfd PUBLIC
|
||||||
|
|||||||
@@ -82,22 +82,25 @@ void test_irq_handler(unsigned pin, uint32_t events) {
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
setup_default_uart();
|
board_init();
|
||||||
stdio_init_all();
|
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");
|
puts("\n");
|
||||||
|
|
||||||
gpio_init(PICO_DEFAULT_LED_PIN);
|
gpio_init(PICO_DEFAULT_LED_PIN);
|
||||||
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
|
||||||
|
|
||||||
board_init();
|
|
||||||
log::info("board initialized");
|
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);
|
i2c::init(i2c_baud);
|
||||||
|
|
||||||
// set up interrupt handlers
|
// set up interrupt handlers
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ char16_t const *string_desc_arr[size_t(strings::_count)] = {
|
|||||||
u"EDMFD", // 2: Product
|
u"EDMFD", // 2: Product
|
||||||
nullptr, // 3: Serials will use unique ID if possible
|
nullptr, // 3: Serials will use unique ID if possible
|
||||||
u"EDMFD Screen", // 4: screen interface
|
u"EDMFD Screen", // 4: screen interface
|
||||||
|
u"EDMFD CDC stdio", // 5: stdio serial port interface
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr size_t desc_len = 32;
|
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
|
// 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
|
// 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),
|
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
|
// HID descriptor
|
||||||
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),
|
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
|
// vendor descriptor
|
||||||
TUD_VENDOR_DESCRIPTOR(uint8_t(interface::vendor), uint8_t(strings::interface), uint8_t(endpoint::vendor_out), uint8_t(endpoint::vendor_in), 64),
|
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.
|
// CDC (serial) descriptor
|
||||||
//TUD_CDC_DESCRIPTOR(uint8_t(interface::CDC), 4, uint8_t(endpoint::CDCnotify), 8, uint8_t(endpoint::CDCout), uint8_t(endpoint::CDCin), 64)
|
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
|
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||||
// Application return pointer to 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 * 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
|
// Set header
|
||||||
U16_TO_U8S_LE(0x000A), // length
|
U16_TO_U8S_LE(0x000A), // length
|
||||||
U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), // type
|
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");
|
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,
|
product,
|
||||||
serial,
|
serial,
|
||||||
interface,
|
interface,
|
||||||
|
stdio,
|
||||||
_count
|
_count
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class interface : uint8_t { HID, vendor, _count };
|
enum class interface : uint8_t {
|
||||||
enum class endpoint : uint8_t { HID = 0x81, vendor_out = 0x02, vendor_in = 0x83 };
|
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 {
|
enum class vendor_req : uint8_t {
|
||||||
microsoft = 1,
|
microsoft = 1,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
// TinyUSB callbacks
|
// 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_rx_cb(uint8_t, uint8_t const*, uint16_t);
|
||||||
void tud_vendor_tx_cb(uint8_t, uint32_t);
|
void tud_vendor_tx_cb(uint8_t, uint32_t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
|
|
||||||
//------------- CLASS -------------//
|
//------------- CLASS -------------//
|
||||||
#define CFG_TUD_HID 1
|
#define CFG_TUD_HID 1
|
||||||
#define CFG_TUD_CDC 0
|
#define CFG_TUD_CDC 1
|
||||||
#define CFG_TUD_MSC 0
|
#define CFG_TUD_MSC 0
|
||||||
#define CFG_TUD_MIDI 0
|
#define CFG_TUD_MIDI 0
|
||||||
#define CFG_TUD_VENDOR 1
|
#define CFG_TUD_VENDOR 1
|
||||||
@@ -100,6 +100,9 @@
|
|||||||
// HID buffer size Should be sufficient to hold ID (if any) + Data
|
// HID buffer size Should be sufficient to hold ID (if any) + Data
|
||||||
#define CFG_TUD_HID_EP_BUFSIZE 16
|
#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_TX_BUFSIZE 64
|
||||||
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
|
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user