2021-02-06 09:59:27 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2021-02-03 11:49:34 +00:00
|
|
|
/*
|
2021-02-06 09:59:27 +00:00
|
|
|
* Copyright (c) 2021 Álvaro Fernández Rojas <noltari@gmail.com>
|
|
|
|
*
|
2021-02-03 11:49:34 +00:00
|
|
|
* This file is based on a file originally part of the
|
|
|
|
* MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
|
|
|
* Copyright (c) 2019 Damien P. George
|
|
|
|
*/
|
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
#include <tusb.h>
|
2021-02-03 11:49:34 +00:00
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
#define DESC_STR_MAX 20
|
2021-02-03 11:49:34 +00:00
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
#define USBD_VID 0x2E8A /* Raspberry Pi */
|
|
|
|
#define USBD_PID 0x000A /* Raspberry Pi Pico SDK CDC */
|
2021-02-03 11:49:34 +00:00
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
#define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN * CFG_TUD_CDC)
|
|
|
|
#define USBD_MAX_POWER_MA 250
|
|
|
|
|
|
|
|
#define USBD_ITF_CDC_0 0
|
|
|
|
#define USBD_ITF_CDC_1 2
|
|
|
|
#define USBD_ITF_MAX 4
|
|
|
|
|
|
|
|
#define USBD_CDC_0_EP_CMD 0x81
|
|
|
|
#define USBD_CDC_1_EP_CMD 0x84
|
|
|
|
#define USBD_CDC_0_EP_OUT 0x02
|
|
|
|
#define USBD_CDC_1_EP_OUT 0x05
|
|
|
|
#define USBD_CDC_0_EP_IN 0x82
|
|
|
|
#define USBD_CDC_1_EP_IN 0x85
|
|
|
|
#define USBD_CDC_CMD_MAX_SIZE 8
|
|
|
|
#define USBD_CDC_IN_OUT_MAX_SIZE 64
|
|
|
|
|
|
|
|
#define USBD_STR_0 0x00
|
|
|
|
#define USBD_STR_MANUF 0x01
|
|
|
|
#define USBD_STR_PRODUCT 0x02
|
|
|
|
#define USBD_STR_SERIAL 0x03
|
|
|
|
#define USBD_STR_CDC 0x04
|
2021-02-03 11:49:34 +00:00
|
|
|
|
|
|
|
static const tusb_desc_device_t usbd_desc_device = {
|
2021-02-06 09:59:27 +00:00
|
|
|
.bLength = sizeof(tusb_desc_device_t),
|
|
|
|
.bDescriptorType = TUSB_DESC_DEVICE,
|
|
|
|
.bcdUSB = 0x0200,
|
|
|
|
.bDeviceClass = TUSB_CLASS_MISC,
|
|
|
|
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
|
|
|
|
.bDeviceProtocol = MISC_PROTOCOL_IAD,
|
|
|
|
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
|
|
|
|
.idVendor = USBD_VID,
|
|
|
|
.idProduct = USBD_PID,
|
|
|
|
.bcdDevice = 0x0100,
|
|
|
|
.iManufacturer = USBD_STR_MANUF,
|
|
|
|
.iProduct = USBD_STR_PRODUCT,
|
|
|
|
.iSerialNumber = USBD_STR_SERIAL,
|
|
|
|
.bNumConfigurations = 1,
|
2021-02-03 11:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
|
2021-02-06 09:59:27 +00:00
|
|
|
TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_MAX, USBD_STR_0, USBD_DESC_LEN,
|
|
|
|
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA),
|
2021-02-03 11:49:34 +00:00
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC_0, USBD_STR_CDC, USBD_CDC_0_EP_CMD,
|
|
|
|
USBD_CDC_CMD_MAX_SIZE, USBD_CDC_0_EP_OUT, USBD_CDC_0_EP_IN,
|
|
|
|
USBD_CDC_IN_OUT_MAX_SIZE),
|
2021-02-04 08:02:27 +00:00
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC_1, USBD_STR_CDC, USBD_CDC_1_EP_CMD,
|
|
|
|
USBD_CDC_CMD_MAX_SIZE, USBD_CDC_1_EP_OUT, USBD_CDC_1_EP_IN,
|
|
|
|
USBD_CDC_IN_OUT_MAX_SIZE),
|
2021-02-03 11:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *const usbd_desc_str[] = {
|
2021-02-06 09:59:27 +00:00
|
|
|
[USBD_STR_MANUF] = "Raspberry Pi",
|
|
|
|
[USBD_STR_PRODUCT] = "Pico",
|
|
|
|
[USBD_STR_SERIAL] = "000000000000",
|
|
|
|
[USBD_STR_CDC] = "Board CDC",
|
2021-02-03 11:49:34 +00:00
|
|
|
};
|
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
const uint8_t *tud_descriptor_device_cb(void)
|
|
|
|
{
|
|
|
|
return (const uint8_t *) &usbd_desc_device;
|
2021-02-03 11:49:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
const uint8_t *tud_descriptor_configuration_cb(uint8_t index)
|
|
|
|
{
|
|
|
|
return usbd_desc_cfg;
|
2021-02-03 11:49:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-06 09:59:27 +00:00
|
|
|
const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
|
|
|
{
|
|
|
|
static uint16_t desc_str[DESC_STR_MAX];
|
|
|
|
uint8_t len;
|
|
|
|
|
|
|
|
if (index == 0) {
|
|
|
|
desc_str[1] = 0x0409;
|
|
|
|
len = 1;
|
|
|
|
} else {
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
if (index >= sizeof(usbd_desc_str) / sizeof(usbd_desc_str[0]))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
str = usbd_desc_str[index];
|
|
|
|
for (len = 0; len < DESC_STR_MAX - 1 && str[len]; ++len)
|
|
|
|
desc_str[1 + len] = str[len];
|
|
|
|
}
|
|
|
|
|
|
|
|
desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * len + 2);
|
|
|
|
|
|
|
|
return desc_str;
|
2021-02-03 11:49:34 +00:00
|
|
|
}
|