support multi port api for device
This commit is contained in:
@@ -146,6 +146,8 @@
|
||||
|
||||
/* ================ USB Device Port Configuration ================*/
|
||||
|
||||
#define CONFIG_USBDEV_MAX_BUS 1 // for now, bus num must be 1 except hpm ip
|
||||
|
||||
#define USBD_IRQHandler USBD_IRQHandler
|
||||
#define USBD_BASE (0)
|
||||
#define CONFIG_USBDEV_EP_NUM 4
|
||||
|
||||
@@ -17,9 +17,9 @@ struct usbd_audio_priv {
|
||||
struct audio_entity_info *table;
|
||||
uint8_t num;
|
||||
uint16_t uac_version;
|
||||
} g_usbd_audio;
|
||||
} g_usbd_audio[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
static int audio_class_endpoint_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int audio_class_endpoint_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint8_t control_selector;
|
||||
uint32_t sampling_freq = 0;
|
||||
@@ -34,13 +34,13 @@ static int audio_class_endpoint_request_handler(struct usb_setup_packet *setup,
|
||||
case AUDIO_REQUEST_SET_CUR:
|
||||
memcpy((uint8_t *)&sampling_freq, *data, *len);
|
||||
USB_LOG_DBG("Set ep:0x%02x %d Hz\r\n", ep, (int)sampling_freq);
|
||||
usbd_audio_set_sampling_freq(ep, sampling_freq);
|
||||
usbd_audio_set_sampling_freq(busid, ep, sampling_freq);
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_CUR:
|
||||
case AUDIO_REQUEST_GET_MIN:
|
||||
case AUDIO_REQUEST_GET_MAX:
|
||||
case AUDIO_REQUEST_GET_RES:
|
||||
sampling_freq = usbd_audio_get_sampling_freq(ep);
|
||||
sampling_freq = usbd_audio_get_sampling_freq(busid, ep);
|
||||
memcpy(*data, &sampling_freq, 3);
|
||||
USB_LOG_DBG("Get ep:0x%02x %d Hz\r\n", ep, (int)sampling_freq);
|
||||
*len = 3;
|
||||
@@ -55,7 +55,7 @@ static int audio_class_endpoint_request_handler(struct usb_setup_packet *setup,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int audio_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int audio_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("Audio Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -79,10 +79,10 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
|
||||
ARG_UNUSED(mute_string);
|
||||
|
||||
for (uint8_t i = 0; i < g_usbd_audio.num; i++) {
|
||||
if (g_usbd_audio.table[i].bEntityId == entity_id) {
|
||||
subtype = g_usbd_audio.table[i].bDescriptorSubtype;
|
||||
ep = g_usbd_audio.table[i].ep;
|
||||
for (uint8_t i = 0; i < g_usbd_audio[busid].num; i++) {
|
||||
if (g_usbd_audio[busid].table[i].bEntityId == entity_id) {
|
||||
subtype = g_usbd_audio[busid].table[i].bDescriptorSubtype;
|
||||
ep = g_usbd_audio[busid].table[i].ep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -98,14 +98,14 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
case AUDIO_CONTROL_FEATURE_UNIT:
|
||||
switch (control_selector) {
|
||||
case AUDIO_FU_CONTROL_MUTE:
|
||||
if (g_usbd_audio.uac_version < 0x0200) {
|
||||
if (g_usbd_audio[busid].uac_version < 0x0200) {
|
||||
switch (setup->bRequest) {
|
||||
case AUDIO_REQUEST_SET_CUR:
|
||||
mute = (*data)[0];
|
||||
usbd_audio_set_mute(ep, ch, mute);
|
||||
usbd_audio_set_mute(busid, ep, ch, mute);
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_CUR:
|
||||
(*data)[0] = usbd_audio_get_mute(ep, ch);
|
||||
(*data)[0] = usbd_audio_get_mute(busid, ep, ch);
|
||||
*len = 1;
|
||||
break;
|
||||
default:
|
||||
@@ -116,11 +116,11 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
switch (setup->bRequest) {
|
||||
case AUDIO_REQUEST_CUR:
|
||||
if (setup->bmRequestType & USB_REQUEST_DIR_MASK) {
|
||||
(*data)[0] = usbd_audio_get_mute(ep, ch);
|
||||
(*data)[0] = usbd_audio_get_mute(busid, ep, ch);
|
||||
*len = 1;
|
||||
} else {
|
||||
mute = (*data)[0];
|
||||
usbd_audio_set_mute(ep, ch, mute);
|
||||
usbd_audio_set_mute(busid, ep, ch, mute);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -130,7 +130,7 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
}
|
||||
break;
|
||||
case AUDIO_FU_CONTROL_VOLUME:
|
||||
if (g_usbd_audio.uac_version < 0x0200) {
|
||||
if (g_usbd_audio[busid].uac_version < 0x0200) {
|
||||
switch (setup->bRequest) {
|
||||
case AUDIO_REQUEST_SET_CUR:
|
||||
memcpy(&volume, *data, *len);
|
||||
@@ -141,10 +141,10 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
}
|
||||
volume_db += 128; /* 0 ~ 255 */
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d volume:0x%04x\r\n", ep, ch, volume);
|
||||
usbd_audio_set_volume(ep, ch, volume_db);
|
||||
usbd_audio_set_volume(busid, ep, ch, volume_db);
|
||||
break;
|
||||
case AUDIO_REQUEST_GET_CUR:
|
||||
volume_db = usbd_audio_get_volume(ep, ch);
|
||||
volume_db = usbd_audio_get_volume(busid, ep, ch);
|
||||
volume_db -= 128;
|
||||
if (volume_db >= 0) {
|
||||
volume = volume_db * 256;
|
||||
@@ -177,7 +177,7 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
switch (setup->bRequest) {
|
||||
case AUDIO_REQUEST_CUR:
|
||||
if (setup->bmRequestType & USB_REQUEST_DIR_MASK) {
|
||||
volume_db = usbd_audio_get_volume(ep, ch);
|
||||
volume_db = usbd_audio_get_volume(busid, ep, ch);
|
||||
volume = volume_db;
|
||||
memcpy(*data, &volume, 2);
|
||||
*len = 2;
|
||||
@@ -185,7 +185,7 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
memcpy(&volume, *data, *len);
|
||||
volume_db = volume;
|
||||
USB_LOG_DBG("Set ep:0x%02x ch:%d volume:0x%02x\r\n", ep, ch, volume);
|
||||
usbd_audio_set_volume(ep, ch, volume_db);
|
||||
usbd_audio_set_volume(busid, ep, ch, volume_db);
|
||||
}
|
||||
break;
|
||||
case AUDIO_REQUEST_RANGE:
|
||||
@@ -216,14 +216,14 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
switch (setup->bRequest) {
|
||||
case AUDIO_REQUEST_CUR:
|
||||
if (setup->bmRequestType & USB_REQUEST_DIR_MASK) {
|
||||
sampling_freq = usbd_audio_get_sampling_freq(ep);
|
||||
sampling_freq = usbd_audio_get_sampling_freq(busid, ep);
|
||||
memcpy(*data, &sampling_freq, 4);
|
||||
USB_LOG_DBG("Get ep:0x%02x %d Hz\r\n", ep, (int)sampling_freq);
|
||||
*len = 4;
|
||||
} else {
|
||||
memcpy(&sampling_freq, *data, setup->wLength);
|
||||
USB_LOG_DBG("Set ep:0x%02x %d Hz\r\n", ep, (int)sampling_freq);
|
||||
usbd_audio_set_sampling_freq(ep, sampling_freq);
|
||||
usbd_audio_set_sampling_freq(busid, ep, sampling_freq);
|
||||
}
|
||||
break;
|
||||
case AUDIO_REQUEST_RANGE:
|
||||
@@ -231,7 +231,7 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
uint8_t *sampling_freq_table = NULL;
|
||||
uint16_t num;
|
||||
|
||||
usbd_audio_get_sampling_freq_table(ep, &sampling_freq_table);
|
||||
usbd_audio_get_sampling_freq_table(busid, ep, &sampling_freq_table);
|
||||
num = (uint16_t)((uint16_t)(sampling_freq_table[1] << 8) | ((uint16_t)sampling_freq_table[0]));
|
||||
memcpy(*data, sampling_freq_table, (12 * num + 2));
|
||||
*len = (12 * num + 2);
|
||||
@@ -264,7 +264,7 @@ static int audio_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void audio_notify_handler(uint8_t event, void *arg)
|
||||
static void audio_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -274,9 +274,9 @@ static void audio_notify_handler(uint8_t event, void *arg)
|
||||
case USBD_EVENT_SET_INTERFACE: {
|
||||
struct usb_interface_descriptor *intf = (struct usb_interface_descriptor *)arg;
|
||||
if (intf->bAlternateSetting) {
|
||||
usbd_audio_open(intf->bInterfaceNumber);
|
||||
usbd_audio_open(busid, intf->bInterfaceNumber);
|
||||
} else {
|
||||
usbd_audio_close(intf->bInterfaceNumber);
|
||||
usbd_audio_close(busid, intf->bInterfaceNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +287,8 @@ static void audio_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_audio_init_intf(struct usbd_interface *intf,
|
||||
struct usbd_interface *usbd_audio_init_intf(uint8_t busid,
|
||||
struct usbd_interface *intf,
|
||||
uint16_t uac_version,
|
||||
struct audio_entity_info *table,
|
||||
uint8_t num)
|
||||
@@ -304,40 +305,40 @@ struct usbd_interface *usbd_audio_init_intf(struct usbd_interface *intf,
|
||||
intf->notify_handler = audio_notify_handler;
|
||||
}
|
||||
|
||||
g_usbd_audio.uac_version = uac_version;
|
||||
g_usbd_audio.table = table;
|
||||
g_usbd_audio.num = num;
|
||||
g_usbd_audio[busid].uac_version = uac_version;
|
||||
g_usbd_audio[busid].table = table;
|
||||
g_usbd_audio[busid].num = num;
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_volume(uint8_t ep, uint8_t ch, int volume)
|
||||
__WEAK void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK int usbd_audio_get_volume(uint8_t ep, uint8_t ch)
|
||||
__WEAK int usbd_audio_get_volume(uint8_t busid, uint8_t ep, uint8_t ch)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_mute(uint8_t ep, uint8_t ch, bool mute)
|
||||
__WEAK void usbd_audio_set_mute(uint8_t busid, uint8_t ep, uint8_t ch, bool mute)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK bool usbd_audio_get_mute(uint8_t ep, uint8_t ch)
|
||||
__WEAK bool usbd_audio_get_mute(uint8_t busid, uint8_t ep, uint8_t ch)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_sampling_freq(uint8_t ep, uint32_t sampling_freq)
|
||||
__WEAK void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK uint32_t usbd_audio_get_sampling_freq(uint8_t ep)
|
||||
__WEAK uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_get_sampling_freq_table(uint8_t ep, uint8_t **sampling_freq_table)
|
||||
__WEAK void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ struct audio_entity_info {
|
||||
};
|
||||
|
||||
/* Init audio interface driver */
|
||||
struct usbd_interface *usbd_audio_init_intf(struct usbd_interface *intf,
|
||||
struct usbd_interface *usbd_audio_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||
uint16_t uac_version,
|
||||
struct audio_entity_info *table,
|
||||
uint8_t num);
|
||||
|
||||
void usbd_audio_open(uint8_t intf);
|
||||
void usbd_audio_close(uint8_t intf);
|
||||
void usbd_audio_open(uint8_t busid, uint8_t intf);
|
||||
void usbd_audio_close(uint8_t busid, uint8_t intf);
|
||||
|
||||
void usbd_audio_set_volume(uint8_t ep, uint8_t ch, int volume);
|
||||
int usbd_audio_get_volume(uint8_t ep, uint8_t ch);
|
||||
void usbd_audio_set_mute(uint8_t ep, uint8_t ch, bool mute);
|
||||
bool usbd_audio_get_mute(uint8_t ep, uint8_t ch);
|
||||
void usbd_audio_set_sampling_freq(uint8_t ep, uint32_t sampling_freq);
|
||||
uint32_t usbd_audio_get_sampling_freq(uint8_t ep);
|
||||
void usbd_audio_set_volume(uint8_t busid, uint8_t ep, uint8_t ch, int volume);
|
||||
int usbd_audio_get_volume(uint8_t busid, uint8_t ep, uint8_t ch);
|
||||
void usbd_audio_set_mute(uint8_t busid, uint8_t ep, uint8_t ch, bool mute);
|
||||
bool usbd_audio_get_mute(uint8_t busid, uint8_t ep, uint8_t ch);
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq);
|
||||
uint32_t usbd_audio_get_sampling_freq(uint8_t busid, uint8_t ep);
|
||||
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t ep, uint8_t **sampling_freq_table);
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
const char *stop_name[] = { "1", "1.5", "2" };
|
||||
const char *parity_name[] = { "N", "O", "E", "M", "S" };
|
||||
|
||||
static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int cdc_acm_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("CDC Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -47,7 +47,7 @@ static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setu
|
||||
parity_name[line_coding.bParityType],
|
||||
stop_name[line_coding.bCharFormat]);
|
||||
|
||||
usbd_cdc_acm_set_line_coding(intf_num, &line_coding);
|
||||
usbd_cdc_acm_set_line_coding(busid, intf_num, &line_coding);
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_SET_CONTROL_LINE_STATE:
|
||||
@@ -57,12 +57,12 @@ static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setu
|
||||
intf_num,
|
||||
dtr,
|
||||
rts);
|
||||
usbd_cdc_acm_set_dtr(intf_num, dtr);
|
||||
usbd_cdc_acm_set_rts(intf_num, rts);
|
||||
usbd_cdc_acm_set_dtr(busid, intf_num, dtr);
|
||||
usbd_cdc_acm_set_rts(busid, intf_num, rts);
|
||||
break;
|
||||
|
||||
case CDC_REQUEST_GET_LINE_CODING:
|
||||
usbd_cdc_acm_get_line_coding(intf_num, &line_coding);
|
||||
usbd_cdc_acm_get_line_coding(busid, intf_num, &line_coding);
|
||||
memcpy(*data, &line_coding, 7);
|
||||
*len = 7;
|
||||
USB_LOG_DBG("Get intf:%d linecoding %d %d %d %d\r\n",
|
||||
@@ -73,7 +73,7 @@ static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setu
|
||||
line_coding.bDataBits);
|
||||
break;
|
||||
case CDC_REQUEST_SEND_BREAK:
|
||||
usbd_cdc_acm_send_break(intf_num);
|
||||
usbd_cdc_acm_send_break(busid, intf_num);
|
||||
break;
|
||||
default:
|
||||
USB_LOG_WRN("Unhandled CDC Class bRequest 0x%02x\r\n", setup->bRequest);
|
||||
@@ -83,7 +83,7 @@ static int cdc_acm_class_interface_request_handler(struct usb_setup_packet *setu
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_cdc_acm_init_intf(struct usbd_interface *intf)
|
||||
struct usbd_interface *usbd_cdc_acm_init_intf(uint8_t busid, struct usbd_interface *intf)
|
||||
{
|
||||
intf->class_interface_handler = cdc_acm_class_interface_request_handler;
|
||||
intf->class_endpoint_handler = NULL;
|
||||
@@ -93,11 +93,11 @@ struct usbd_interface *usbd_cdc_acm_init_intf(struct usbd_interface *intf)
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_line_coding(uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
__WEAK void usbd_cdc_acm_set_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_get_line_coding(uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
__WEAK void usbd_cdc_acm_get_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding)
|
||||
{
|
||||
line_coding->dwDTERate = 2000000;
|
||||
line_coding->bDataBits = 8;
|
||||
@@ -105,14 +105,14 @@ __WEAK void usbd_cdc_acm_get_line_coding(uint8_t intf, struct cdc_line_coding *l
|
||||
line_coding->bCharFormat = 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr)
|
||||
__WEAK void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_rts(uint8_t intf, bool rts)
|
||||
__WEAK void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_send_break(uint8_t intf)
|
||||
__WEAK void usbd_cdc_acm_send_break(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Init cdc acm interface driver */
|
||||
struct usbd_interface *usbd_cdc_acm_init_intf(struct usbd_interface *intf);
|
||||
struct usbd_interface *usbd_cdc_acm_init_intf(uint8_t busid, struct usbd_interface *intf);
|
||||
|
||||
/* Setup request command callback api */
|
||||
void usbd_cdc_acm_set_line_coding(uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_get_line_coding(uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr);
|
||||
void usbd_cdc_acm_set_rts(uint8_t intf, bool rts);
|
||||
void usbd_cdc_acm_send_break(uint8_t intf);
|
||||
void usbd_cdc_acm_set_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_get_line_coding(uint8_t busid, uint8_t intf, struct cdc_line_coding *line_coding);
|
||||
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr);
|
||||
void usbd_cdc_acm_set_rts(uint8_t busid, uint8_t intf, bool rts);
|
||||
void usbd_cdc_acm_send_break(uint8_t busid, uint8_t intf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -75,11 +75,11 @@ void usbd_cdc_ecm_send_notify(uint8_t notifycode, uint8_t value, uint32_t *speed
|
||||
}
|
||||
|
||||
if (bytes2send) {
|
||||
usbd_ep_start_write(cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_addr, g_cdc_ecm_notify_buf, bytes2send);
|
||||
usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_addr, g_cdc_ecm_notify_buf, bytes2send);
|
||||
}
|
||||
}
|
||||
|
||||
static int cdc_ecm_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int cdc_ecm_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("CDC ECM Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -109,7 +109,7 @@ static int cdc_ecm_class_interface_request_handler(struct usb_setup_packet *setu
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cdc_ecm_notify_handler(uint8_t event, void *arg)
|
||||
void cdc_ecm_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -119,7 +119,7 @@ void cdc_ecm_notify_handler(uint8_t event, void *arg)
|
||||
g_cdc_ecm_rx_data_buffer = NULL;
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
usbd_ep_start_read(cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], CDC_ECM_MAX_PACKET_SIZE);
|
||||
usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], CDC_ECM_MAX_PACKET_SIZE);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -127,29 +127,29 @@ void cdc_ecm_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_ecm_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void cdc_ecm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
g_cdc_ecm_rx_data_length += nbytes;
|
||||
|
||||
if (nbytes < CDC_ECM_MAX_PACKET_SIZE) {
|
||||
g_cdc_ecm_rx_data_buffer = g_cdc_ecm_rx_buffer;
|
||||
usbd_cdc_ecm_data_recv_done();
|
||||
usbd_cdc_ecm_data_recv_done(g_cdc_ecm_rx_buffer, g_cdc_ecm_rx_data_length);
|
||||
} else {
|
||||
usbd_ep_start_read(ep, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], CDC_ECM_MAX_PACKET_SIZE);
|
||||
usbd_ep_start_read(0, ep, &g_cdc_ecm_rx_buffer[g_cdc_ecm_rx_data_length], CDC_ECM_MAX_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_ecm_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void cdc_ecm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
if ((nbytes % CDC_ECM_MAX_PACKET_SIZE) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(ep, NULL, 0);
|
||||
usbd_ep_start_write(0, ep, NULL, 0);
|
||||
} else {
|
||||
g_cdc_ecm_tx_data_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_ecm_int_in(uint8_t ep, uint32_t nbytes)
|
||||
void cdc_ecm_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
if (g_current_net_status == 1) {
|
||||
g_current_net_status = 2;
|
||||
@@ -157,28 +157,23 @@ void cdc_ecm_int_in(uint8_t ep, uint32_t nbytes)
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *usbd_cdc_ecm_get_tx_buffer(void)
|
||||
{
|
||||
return g_cdc_ecm_tx_buffer;
|
||||
}
|
||||
|
||||
int usbd_cdc_ecm_start_write(uint32_t length)
|
||||
int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
if (g_cdc_ecm_tx_data_length > 0) {
|
||||
return -USB_ERR_BUSY;
|
||||
}
|
||||
|
||||
g_cdc_ecm_tx_data_length = length;
|
||||
g_cdc_ecm_tx_data_length = len;
|
||||
|
||||
USB_LOG_DBG("txlen:%d\r\n", g_cdc_ecm_tx_data_length);
|
||||
return usbd_ep_start_write(cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX].ep_addr, g_cdc_ecm_tx_buffer, g_cdc_ecm_tx_data_length);
|
||||
return usbd_ep_start_write(0, cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX].ep_addr, buf, g_cdc_ecm_tx_data_length);
|
||||
}
|
||||
|
||||
void usbd_cdc_ecm_start_read_next(void)
|
||||
{
|
||||
g_cdc_ecm_rx_data_length = 0;
|
||||
g_cdc_ecm_rx_data_buffer = NULL;
|
||||
usbd_ep_start_read(cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, g_cdc_ecm_rx_buffer, CDC_ECM_MAX_PACKET_SIZE);
|
||||
usbd_ep_start_read(0, cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX].ep_addr, g_cdc_ecm_rx_buffer, CDC_ECM_MAX_PACKET_SIZE);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USBDEV_CDC_ECM_USING_LWIP
|
||||
@@ -223,7 +218,7 @@ int usbd_cdc_ecm_eth_tx(struct pbuf *p)
|
||||
|
||||
g_cdc_ecm_tx_data_length = p->tot_len;
|
||||
|
||||
return usbd_cdc_ecm_start_write(g_cdc_ecm_tx_data_length);
|
||||
return usbd_cdc_ecm_start_write(g_cdc_ecm_tx_buffer, g_cdc_ecm_tx_data_length);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -241,9 +236,9 @@ struct usbd_interface *usbd_cdc_ecm_init_intf(struct usbd_interface *intf, const
|
||||
cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_addr = int_ep;
|
||||
cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX].ep_cb = cdc_ecm_int_in;
|
||||
|
||||
usbd_add_endpoint(&cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX]);
|
||||
usbd_add_endpoint(&cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX]);
|
||||
usbd_add_endpoint(&cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX]);
|
||||
usbd_add_endpoint(0, &cdc_ecm_ep_data[CDC_ECM_OUT_EP_IDX]);
|
||||
usbd_add_endpoint(0, &cdc_ecm_ep_data[CDC_ECM_IN_EP_IDX]);
|
||||
usbd_add_endpoint(0, &cdc_ecm_ep_data[CDC_ECM_INT_EP_IDX]);
|
||||
|
||||
return intf;
|
||||
}
|
||||
@@ -253,6 +248,6 @@ void usbd_cdc_ecm_set_connect_speed(uint32_t speed[2])
|
||||
memcpy(g_connect_speed_table, speed, 8);
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_ecm_data_recv_done(void)
|
||||
__WEAK void usbd_cdc_ecm_data_recv_done(uint8_t *buf, uint32_t len)
|
||||
{
|
||||
}
|
||||
@@ -24,7 +24,7 @@ void usbd_cdc_ecm_set_connect_speed(uint32_t speed[2]);
|
||||
/* Api for eth only without any net stack */
|
||||
uint8_t *usbd_cdc_ecm_get_tx_buffer(void);
|
||||
void usbd_cdc_ecm_send_done(void);
|
||||
int usbd_cdc_ecm_start_write(uint32_t length);
|
||||
int usbd_cdc_ecm_start_write(uint8_t *buf, uint32_t len);
|
||||
void usbd_cdc_ecm_data_recv_done(uint8_t *buf, uint32_t len);
|
||||
void usbd_cdc_ecm_start_read_next(void);
|
||||
|
||||
|
||||
@@ -428,7 +428,7 @@ void dfu_request_abort(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int dfu_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int dfu_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("DFU Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -464,7 +464,7 @@ static int dfu_class_interface_request_handler(struct usb_setup_packet *setup, u
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dfu_notify_handler(uint8_t event, void *arg)
|
||||
static void dfu_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
static int hid_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int hid_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -17,27 +17,27 @@ static int hid_class_interface_request_handler(struct usb_setup_packet *setup, u
|
||||
switch (setup->bRequest) {
|
||||
case HID_REQUEST_GET_REPORT:
|
||||
/* report id ,report type */
|
||||
usbd_hid_get_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), data, len);
|
||||
usbd_hid_get_report(busid, intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), data, len);
|
||||
break;
|
||||
case HID_REQUEST_GET_IDLE:
|
||||
(*data)[0] = usbd_hid_get_idle(intf_num, LO_BYTE(setup->wValue));
|
||||
(*data)[0] = usbd_hid_get_idle(busid, intf_num, LO_BYTE(setup->wValue));
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_GET_PROTOCOL:
|
||||
(*data)[0] = usbd_hid_get_protocol(intf_num);
|
||||
(*data)[0] = usbd_hid_get_protocol(busid, intf_num);
|
||||
*len = 1;
|
||||
break;
|
||||
case HID_REQUEST_SET_REPORT:
|
||||
/* report id ,report type, report, report len */
|
||||
usbd_hid_set_report(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), *data, *len);
|
||||
usbd_hid_set_report(busid, intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue), *data, *len);
|
||||
break;
|
||||
case HID_REQUEST_SET_IDLE:
|
||||
/* report id, duration */
|
||||
usbd_hid_set_idle(intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue));
|
||||
usbd_hid_set_idle(busid, intf_num, LO_BYTE(setup->wValue), HI_BYTE(setup->wValue));
|
||||
break;
|
||||
case HID_REQUEST_SET_PROTOCOL:
|
||||
/* protocol */
|
||||
usbd_hid_set_protocol(intf_num, LO_BYTE(setup->wValue));
|
||||
usbd_hid_set_protocol(busid, intf_num, LO_BYTE(setup->wValue));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -48,7 +48,7 @@ static int hid_class_interface_request_handler(struct usb_setup_packet *setup, u
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_hid_init_intf(struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len)
|
||||
struct usbd_interface *usbd_hid_init_intf(uint8_t busid, struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
intf->class_interface_handler = hid_class_interface_request_handler;
|
||||
intf->class_endpoint_handler = NULL;
|
||||
@@ -60,30 +60,30 @@ struct usbd_interface *usbd_hid_init_intf(struct usbd_interface *intf, const uin
|
||||
return intf;
|
||||
}
|
||||
|
||||
__WEAK void usbd_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len)
|
||||
__WEAK void usbd_hid_get_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
(*data[0]) = 0;
|
||||
*len = 1;
|
||||
}
|
||||
|
||||
__WEAK uint8_t usbd_hid_get_idle(uint8_t intf, uint8_t report_id)
|
||||
__WEAK uint8_t usbd_hid_get_idle(uint8_t busid, uint8_t intf, uint8_t report_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK uint8_t usbd_hid_get_protocol(uint8_t intf)
|
||||
__WEAK uint8_t usbd_hid_get_protocol(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
__WEAK void usbd_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len)
|
||||
__WEAK void usbd_hid_set_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbd_hid_set_idle(uint8_t intf, uint8_t report_id, uint8_t duration)
|
||||
__WEAK void usbd_hid_set_idle(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t duration)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbd_hid_set_protocol(uint8_t intf, uint8_t protocol)
|
||||
__WEAK void usbd_hid_set_protocol(uint8_t busid, uint8_t intf, uint8_t protocol)
|
||||
{
|
||||
}
|
||||
@@ -13,19 +13,19 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Init hid interface driver */
|
||||
struct usbd_interface *usbd_hid_init_intf(struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len);
|
||||
struct usbd_interface *usbd_hid_init_intf(uint8_t busid, struct usbd_interface *intf, const uint8_t *desc, uint32_t desc_len);
|
||||
|
||||
/* Register desc api */
|
||||
void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc);
|
||||
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len);
|
||||
void usbd_hid_descriptor_register(uint8_t busid, uint8_t intf_num, const uint8_t *desc);
|
||||
void usbd_hid_report_descriptor_register(uint8_t busid, uint8_t intf_num, const uint8_t *desc, uint32_t desc_len);
|
||||
|
||||
/* Setup request command callback api */
|
||||
void usbd_hid_get_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len);
|
||||
uint8_t usbd_hid_get_idle(uint8_t intf, uint8_t report_id);
|
||||
uint8_t usbd_hid_get_protocol(uint8_t intf);
|
||||
void usbd_hid_set_report(uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len);
|
||||
void usbd_hid_set_idle(uint8_t intf, uint8_t report_id, uint8_t duration);
|
||||
void usbd_hid_set_protocol(uint8_t intf, uint8_t protocol);
|
||||
void usbd_hid_get_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t **data, uint32_t *len);
|
||||
uint8_t usbd_hid_get_idle(uint8_t busid, uint8_t intf, uint8_t report_id);
|
||||
uint8_t usbd_hid_get_protocol(uint8_t busid, uint8_t intf);
|
||||
void usbd_hid_set_report(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t report_type, uint8_t *report, uint32_t report_len);
|
||||
void usbd_hid_set_idle(uint8_t busid, uint8_t intf, uint8_t report_id, uint8_t duration);
|
||||
void usbd_hid_set_protocol(uint8_t busid, uint8_t intf, uint8_t protocol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,16 +14,16 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Init msc interface driver */
|
||||
struct usbd_interface *usbd_msc_init_intf(struct usbd_interface *intf,
|
||||
struct usbd_interface *usbd_msc_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||
const uint8_t out_ep,
|
||||
const uint8_t in_ep);
|
||||
|
||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint32_t *block_size);
|
||||
int usbd_msc_sector_read(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||
int usbd_msc_sector_write(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size);
|
||||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length);
|
||||
|
||||
void usbd_msc_set_readonly(bool readonly);
|
||||
bool usbd_msc_set_popup(void);
|
||||
void usbd_msc_set_readonly(uint8_t busid, bool readonly);
|
||||
bool usbd_msc_set_popup(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_xxx.h"
|
||||
|
||||
static int xxx_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int xxx_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_WRN("XXX Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -16,7 +16,7 @@ static int xxx_class_interface_request_handler(struct usb_setup_packet *setup, u
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void xxx_notify_handler(uint8_t event, void *arg)
|
||||
static void xxx_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -28,7 +28,7 @@ static void xxx_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_xxx_init_intf(struct usbd_interface *intf)
|
||||
struct usbd_interface *usbd_xxx_init_intf(uint8_t busid, struct usbd_interface *intf)
|
||||
{
|
||||
intf->class_interface_handler = xxx_class_interface_request_handler;
|
||||
intf->class_endpoint_handler = NULL;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct usbd_interface *usbd_xxx_init_intf(struct usbd_interface *intf);
|
||||
struct usbd_interface *usbd_xxx_init_intf(uint8_t busid, struct usbd_interface *intf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ struct usbd_video_priv {
|
||||
uint8_t power_mode;
|
||||
uint8_t error_code;
|
||||
struct video_entity_info info[3];
|
||||
} g_usbd_video;
|
||||
} g_usbd_video[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
static int usbd_video_control_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int usbd_video_control_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint8_t control_selector = (uint8_t)(setup->wValue >> 8);
|
||||
|
||||
@@ -60,13 +60,13 @@ static int usbd_video_control_request_handler(struct usb_setup_packet *setup, ui
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbd_video_control_unit_terminal_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int usbd_video_control_unit_terminal_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint8_t entity_id = (uint8_t)(setup->wIndex >> 8);
|
||||
uint8_t control_selector = (uint8_t)(setup->wValue >> 8);
|
||||
|
||||
for (uint8_t i = 0; i < 3; i++) {
|
||||
struct video_entity_info *entity_info = &g_usbd_video.info[i];
|
||||
struct video_entity_info *entity_info = &g_usbd_video[busid].info[i];
|
||||
if (entity_info->bEntityId == entity_id) {
|
||||
switch (entity_info->bDescriptorSubtype) {
|
||||
case VIDEO_VC_HEADER_DESCRIPTOR_SUBTYPE:
|
||||
@@ -546,7 +546,7 @@ static int usbd_video_control_unit_terminal_request_handler(struct usb_setup_pac
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_usbd_video.error_code = 0x06;
|
||||
g_usbd_video[busid].error_code = 0x06;
|
||||
USB_LOG_WRN("Unhandled Video Class control selector 0x%02x\r\n", control_selector);
|
||||
return -1;
|
||||
}
|
||||
@@ -564,7 +564,7 @@ static int usbd_video_control_unit_terminal_request_handler(struct usb_setup_pac
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int usbd_video_stream_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int usbd_video_stream_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
uint8_t control_selector = (uint8_t)(setup->wValue >> 8);
|
||||
|
||||
@@ -572,10 +572,10 @@ static int usbd_video_stream_request_handler(struct usb_setup_packet *setup, uin
|
||||
case VIDEO_VS_PROBE_CONTROL:
|
||||
switch (setup->bRequest) {
|
||||
case VIDEO_REQUEST_SET_CUR:
|
||||
//memcpy((uint8_t *)&g_usbd_video.probe, *data, setup->wLength);
|
||||
//memcpy((uint8_t *)&g_usbd_video[busid].probe, *data, setup->wLength);
|
||||
break;
|
||||
case VIDEO_REQUEST_GET_CUR:
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video.probe, setup->wLength);
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video[busid].probe, setup->wLength);
|
||||
*len = sizeof(struct video_probe_and_commit_controls);
|
||||
break;
|
||||
|
||||
@@ -583,7 +583,7 @@ static int usbd_video_stream_request_handler(struct usb_setup_packet *setup, uin
|
||||
case VIDEO_REQUEST_GET_MAX:
|
||||
case VIDEO_REQUEST_GET_RES:
|
||||
case VIDEO_REQUEST_GET_DEF:
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video.probe, setup->wLength);
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video[busid].probe, setup->wLength);
|
||||
*len = sizeof(struct video_probe_and_commit_controls);
|
||||
break;
|
||||
case VIDEO_REQUEST_GET_LEN:
|
||||
@@ -604,17 +604,17 @@ static int usbd_video_stream_request_handler(struct usb_setup_packet *setup, uin
|
||||
case VIDEO_VS_COMMIT_CONTROL:
|
||||
switch (setup->bRequest) {
|
||||
case VIDEO_REQUEST_SET_CUR:
|
||||
//memcpy((uint8_t *)&g_usbd_video.commit, *data, setup->wLength);
|
||||
//memcpy((uint8_t *)&g_usbd_video[busid].commit, *data, setup->wLength);
|
||||
break;
|
||||
case VIDEO_REQUEST_GET_CUR:
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video.commit, setup->wLength);
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video[busid].commit, setup->wLength);
|
||||
*len = sizeof(struct video_probe_and_commit_controls);
|
||||
break;
|
||||
case VIDEO_REQUEST_GET_MIN:
|
||||
case VIDEO_REQUEST_GET_MAX:
|
||||
case VIDEO_REQUEST_GET_RES:
|
||||
case VIDEO_REQUEST_GET_DEF:
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video.commit, setup->wLength);
|
||||
memcpy(*data, (uint8_t *)&g_usbd_video[busid].commit, setup->wLength);
|
||||
*len = sizeof(struct video_probe_and_commit_controls);
|
||||
break;
|
||||
|
||||
@@ -636,7 +636,7 @@ static int usbd_video_stream_request_handler(struct usb_setup_packet *setup, uin
|
||||
case VIDEO_VS_STREAM_ERROR_CODE_CONTROL:
|
||||
switch (setup->bRequest) {
|
||||
case VIDEO_REQUEST_GET_CUR:
|
||||
(*data)[0] = g_usbd_video.error_code;
|
||||
(*data)[0] = g_usbd_video[busid].error_code;
|
||||
*len = 1;
|
||||
break;
|
||||
case VIDEO_REQUEST_GET_INFO:
|
||||
@@ -655,7 +655,7 @@ static int usbd_video_stream_request_handler(struct usb_setup_packet *setup, uin
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int video_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int video_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("Video Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -666,30 +666,30 @@ static int video_class_interface_request_handler(struct usb_setup_packet *setup,
|
||||
|
||||
if (intf_num == 0) { /* Video Control Interface */
|
||||
if (entity_id == 0) {
|
||||
return usbd_video_control_request_handler(setup, data, len); /* Interface Control Requests */
|
||||
return usbd_video_control_request_handler(busid, setup, data, len); /* Interface Control Requests */
|
||||
} else {
|
||||
return usbd_video_control_unit_terminal_request_handler(setup, data, len); /* Unit and Terminal Requests */
|
||||
return usbd_video_control_unit_terminal_request_handler(busid, setup, data, len); /* Unit and Terminal Requests */
|
||||
}
|
||||
} else if (intf_num == 1) { /* Video Stream Inteface */
|
||||
return usbd_video_stream_request_handler(setup, data, len); /* Interface Stream Requests */
|
||||
return usbd_video_stream_request_handler(busid, setup, data, len); /* Interface Stream Requests */
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void video_notify_handler(uint8_t event, void *arg)
|
||||
static void video_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
g_usbd_video.error_code = 0;
|
||||
g_usbd_video.power_mode = 0;
|
||||
g_usbd_video[busid].error_code = 0;
|
||||
g_usbd_video[busid].power_mode = 0;
|
||||
break;
|
||||
|
||||
case USBD_EVENT_SET_INTERFACE: {
|
||||
struct usb_interface_descriptor *intf = (struct usb_interface_descriptor *)arg;
|
||||
if (intf->bAlternateSetting == 1) {
|
||||
usbd_video_open(intf->bInterfaceNumber);
|
||||
usbd_video_open(busid, intf->bInterfaceNumber);
|
||||
} else {
|
||||
usbd_video_close(intf->bInterfaceNumber);
|
||||
usbd_video_close(busid, intf->bInterfaceNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -699,46 +699,46 @@ static void video_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
void usbd_video_probe_and_commit_controls_init(uint8_t busid, uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize)
|
||||
{
|
||||
g_usbd_video.probe.hintUnion.bmHint = 0x01;
|
||||
g_usbd_video.probe.hintUnion1.bmHint = 0;
|
||||
g_usbd_video.probe.bFormatIndex = 1;
|
||||
g_usbd_video.probe.bFrameIndex = 1;
|
||||
g_usbd_video.probe.dwFrameInterval = dwFrameInterval;
|
||||
g_usbd_video.probe.wKeyFrameRate = 0;
|
||||
g_usbd_video.probe.wPFrameRate = 0;
|
||||
g_usbd_video.probe.wCompQuality = 0;
|
||||
g_usbd_video.probe.wCompWindowSize = 0;
|
||||
g_usbd_video.probe.wDelay = 0;
|
||||
g_usbd_video.probe.dwMaxVideoFrameSize = dwMaxVideoFrameSize;
|
||||
g_usbd_video.probe.dwMaxPayloadTransferSize = dwMaxPayloadTransferSize;
|
||||
g_usbd_video.probe.dwClockFrequency = 0;
|
||||
g_usbd_video.probe.bmFramingInfo = 0;
|
||||
g_usbd_video.probe.bPreferedVersion = 0;
|
||||
g_usbd_video.probe.bMinVersion = 0;
|
||||
g_usbd_video.probe.bMaxVersion = 0;
|
||||
g_usbd_video[busid].probe.hintUnion.bmHint = 0x01;
|
||||
g_usbd_video[busid].probe.hintUnion1.bmHint = 0;
|
||||
g_usbd_video[busid].probe.bFormatIndex = 1;
|
||||
g_usbd_video[busid].probe.bFrameIndex = 1;
|
||||
g_usbd_video[busid].probe.dwFrameInterval = dwFrameInterval;
|
||||
g_usbd_video[busid].probe.wKeyFrameRate = 0;
|
||||
g_usbd_video[busid].probe.wPFrameRate = 0;
|
||||
g_usbd_video[busid].probe.wCompQuality = 0;
|
||||
g_usbd_video[busid].probe.wCompWindowSize = 0;
|
||||
g_usbd_video[busid].probe.wDelay = 0;
|
||||
g_usbd_video[busid].probe.dwMaxVideoFrameSize = dwMaxVideoFrameSize;
|
||||
g_usbd_video[busid].probe.dwMaxPayloadTransferSize = dwMaxPayloadTransferSize;
|
||||
g_usbd_video[busid].probe.dwClockFrequency = 0;
|
||||
g_usbd_video[busid].probe.bmFramingInfo = 0;
|
||||
g_usbd_video[busid].probe.bPreferedVersion = 0;
|
||||
g_usbd_video[busid].probe.bMinVersion = 0;
|
||||
g_usbd_video[busid].probe.bMaxVersion = 0;
|
||||
|
||||
g_usbd_video.commit.hintUnion.bmHint = 0x01;
|
||||
g_usbd_video.commit.hintUnion1.bmHint = 0;
|
||||
g_usbd_video.commit.bFormatIndex = 1;
|
||||
g_usbd_video.commit.bFrameIndex = 1;
|
||||
g_usbd_video.commit.dwFrameInterval = dwFrameInterval;
|
||||
g_usbd_video.commit.wKeyFrameRate = 0;
|
||||
g_usbd_video.commit.wPFrameRate = 0;
|
||||
g_usbd_video.commit.wCompQuality = 0;
|
||||
g_usbd_video.commit.wCompWindowSize = 0;
|
||||
g_usbd_video.commit.wDelay = 0;
|
||||
g_usbd_video.commit.dwMaxVideoFrameSize = dwMaxVideoFrameSize;
|
||||
g_usbd_video.commit.dwMaxPayloadTransferSize = dwMaxPayloadTransferSize;
|
||||
g_usbd_video.commit.dwClockFrequency = 0;
|
||||
g_usbd_video.commit.bmFramingInfo = 0;
|
||||
g_usbd_video.commit.bPreferedVersion = 0;
|
||||
g_usbd_video.commit.bMinVersion = 0;
|
||||
g_usbd_video.commit.bMaxVersion = 0;
|
||||
g_usbd_video[busid].commit.hintUnion.bmHint = 0x01;
|
||||
g_usbd_video[busid].commit.hintUnion1.bmHint = 0;
|
||||
g_usbd_video[busid].commit.bFormatIndex = 1;
|
||||
g_usbd_video[busid].commit.bFrameIndex = 1;
|
||||
g_usbd_video[busid].commit.dwFrameInterval = dwFrameInterval;
|
||||
g_usbd_video[busid].commit.wKeyFrameRate = 0;
|
||||
g_usbd_video[busid].commit.wPFrameRate = 0;
|
||||
g_usbd_video[busid].commit.wCompQuality = 0;
|
||||
g_usbd_video[busid].commit.wCompWindowSize = 0;
|
||||
g_usbd_video[busid].commit.wDelay = 0;
|
||||
g_usbd_video[busid].commit.dwMaxVideoFrameSize = dwMaxVideoFrameSize;
|
||||
g_usbd_video[busid].commit.dwMaxPayloadTransferSize = dwMaxPayloadTransferSize;
|
||||
g_usbd_video[busid].commit.dwClockFrequency = 0;
|
||||
g_usbd_video[busid].commit.bmFramingInfo = 0;
|
||||
g_usbd_video[busid].commit.bPreferedVersion = 0;
|
||||
g_usbd_video[busid].commit.bMinVersion = 0;
|
||||
g_usbd_video[busid].commit.bMaxVersion = 0;
|
||||
}
|
||||
|
||||
struct usbd_interface *usbd_video_init_intf(struct usbd_interface *intf,
|
||||
struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||
uint32_t dwFrameInterval,
|
||||
uint32_t dwMaxVideoFrameSize,
|
||||
uint32_t dwMaxPayloadTransferSize)
|
||||
@@ -748,39 +748,39 @@ struct usbd_interface *usbd_video_init_intf(struct usbd_interface *intf,
|
||||
intf->vendor_handler = NULL;
|
||||
intf->notify_handler = video_notify_handler;
|
||||
|
||||
g_usbd_video.info[0].bDescriptorSubtype = VIDEO_VC_INPUT_TERMINAL_DESCRIPTOR_SUBTYPE;
|
||||
g_usbd_video.info[0].bEntityId = 0x01;
|
||||
g_usbd_video.info[0].wTerminalType = VIDEO_ITT_CAMERA;
|
||||
g_usbd_video.info[1].bDescriptorSubtype = VIDEO_VC_OUTPUT_TERMINAL_DESCRIPTOR_SUBTYPE;
|
||||
g_usbd_video.info[1].bEntityId = 0x03;
|
||||
g_usbd_video.info[1].wTerminalType = 0x00;
|
||||
g_usbd_video.info[2].bDescriptorSubtype = VIDEO_VC_PROCESSING_UNIT_DESCRIPTOR_SUBTYPE;
|
||||
g_usbd_video.info[2].bEntityId = 0x02;
|
||||
g_usbd_video.info[2].wTerminalType = 0x00;
|
||||
g_usbd_video[busid].info[0].bDescriptorSubtype = VIDEO_VC_INPUT_TERMINAL_DESCRIPTOR_SUBTYPE;
|
||||
g_usbd_video[busid].info[0].bEntityId = 0x01;
|
||||
g_usbd_video[busid].info[0].wTerminalType = VIDEO_ITT_CAMERA;
|
||||
g_usbd_video[busid].info[1].bDescriptorSubtype = VIDEO_VC_OUTPUT_TERMINAL_DESCRIPTOR_SUBTYPE;
|
||||
g_usbd_video[busid].info[1].bEntityId = 0x03;
|
||||
g_usbd_video[busid].info[1].wTerminalType = 0x00;
|
||||
g_usbd_video[busid].info[2].bDescriptorSubtype = VIDEO_VC_PROCESSING_UNIT_DESCRIPTOR_SUBTYPE;
|
||||
g_usbd_video[busid].info[2].bEntityId = 0x02;
|
||||
g_usbd_video[busid].info[2].wTerminalType = 0x00;
|
||||
|
||||
usbd_video_probe_and_commit_controls_init(dwFrameInterval, dwMaxVideoFrameSize, dwMaxPayloadTransferSize);
|
||||
usbd_video_probe_and_commit_controls_init(busid, dwFrameInterval, dwMaxVideoFrameSize, dwMaxPayloadTransferSize);
|
||||
return intf;
|
||||
}
|
||||
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len)
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len)
|
||||
{
|
||||
uint32_t packets;
|
||||
uint32_t last_packet_size;
|
||||
uint32_t picture_pos = 0;
|
||||
static uint8_t uvc_header[2] = { 0x02, 0x80 };
|
||||
|
||||
packets = (input_len + (g_usbd_video.probe.dwMaxPayloadTransferSize - 2) ) / (g_usbd_video.probe.dwMaxPayloadTransferSize - 2);
|
||||
last_packet_size = input_len - ((packets - 1) * (g_usbd_video.probe.dwMaxPayloadTransferSize - 2));
|
||||
packets = (input_len + (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2) ) / (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2);
|
||||
last_packet_size = input_len - ((packets - 1) * (g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2));
|
||||
|
||||
for (size_t i = 0; i < packets; i++) {
|
||||
output[g_usbd_video.probe.dwMaxPayloadTransferSize * i] = uvc_header[0];
|
||||
output[g_usbd_video.probe.dwMaxPayloadTransferSize * i + 1] = uvc_header[1];
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i] = uvc_header[0];
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i + 1] = uvc_header[1];
|
||||
if (i == (packets - 1)) {
|
||||
memcpy(&output[2 + g_usbd_video.probe.dwMaxPayloadTransferSize * i], &input[picture_pos], last_packet_size);
|
||||
output[g_usbd_video.probe.dwMaxPayloadTransferSize * i + 1] |= (1 << 1);
|
||||
memcpy(&output[2 + g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i], &input[picture_pos], last_packet_size);
|
||||
output[g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i + 1] |= (1 << 1);
|
||||
} else {
|
||||
memcpy(&output[2 + g_usbd_video.probe.dwMaxPayloadTransferSize * i], &input[picture_pos], g_usbd_video.probe.dwMaxPayloadTransferSize - 2);
|
||||
picture_pos += g_usbd_video.probe.dwMaxPayloadTransferSize - 2;
|
||||
memcpy(&output[2 + g_usbd_video[busid].probe.dwMaxPayloadTransferSize * i], &input[picture_pos], g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2);
|
||||
picture_pos += g_usbd_video[busid].probe.dwMaxPayloadTransferSize - 2;
|
||||
}
|
||||
}
|
||||
uvc_header[1] ^= 1;
|
||||
|
||||
@@ -13,14 +13,14 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* Init video interface driver */
|
||||
struct usbd_interface *usbd_video_init_intf(struct usbd_interface *intf,
|
||||
struct usbd_interface *usbd_video_init_intf(uint8_t busid, struct usbd_interface *intf,
|
||||
uint32_t dwFrameInterval,
|
||||
uint32_t dwMaxVideoFrameSize,
|
||||
uint32_t dwMaxPayloadTransferSize);
|
||||
|
||||
void usbd_video_open(uint8_t intf);
|
||||
void usbd_video_close(uint8_t intf);
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||
void usbd_video_open(uint8_t busid, uint8_t intf);
|
||||
void usbd_video_close(uint8_t busid, uint8_t intf);
|
||||
uint32_t usbd_video_mjpeg_payload_fill(uint8_t busid, uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -105,10 +105,10 @@ static void rndis_notify_rsp(void)
|
||||
{
|
||||
memset(NOTIFY_RESPONSE_AVAILABLE, 0, 8);
|
||||
NOTIFY_RESPONSE_AVAILABLE[0] = 0x01;
|
||||
usbd_ep_start_write(rndis_ep_data[RNDIS_INT_EP_IDX].ep_addr, NOTIFY_RESPONSE_AVAILABLE, 8);
|
||||
usbd_ep_start_write(0, rndis_ep_data[RNDIS_INT_EP_IDX].ep_addr, NOTIFY_RESPONSE_AVAILABLE, 8);
|
||||
}
|
||||
|
||||
static int rndis_class_interface_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int rndis_class_interface_request_handler(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
switch (setup->bRequest) {
|
||||
case CDC_REQUEST_SEND_ENCAPSULATED_COMMAND:
|
||||
@@ -426,7 +426,7 @@ static int rndis_keepalive_cmd_handler(uint8_t *data, uint32_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void rndis_notify_handler(uint8_t event, void *arg)
|
||||
static void rndis_notify_handler(uint8_t busid, uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -436,7 +436,7 @@ static void rndis_notify_handler(uint8_t event, void *arg)
|
||||
g_rndis_rx_data_length = 0;
|
||||
g_rndis_tx_data_length = 0;
|
||||
g_usbd_rndis.link_status = NDIS_MEDIA_STATE_CONNECTED;
|
||||
usbd_ep_start_read(rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
usbd_ep_start_read(0, rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -444,14 +444,14 @@ static void rndis_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void rndis_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void rndis_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
rndis_data_packet_t *hdr;
|
||||
|
||||
hdr = (rndis_data_packet_t *)g_rndis_rx_buffer;
|
||||
g_rndis_rx_data_buffer = g_rndis_rx_buffer;
|
||||
if ((hdr->MessageType != NDIS_PACKET_TYPE_DIRECTED) || (nbytes != hdr->MessageLength)) {
|
||||
usbd_ep_start_read(rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
usbd_ep_start_read(0, rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -462,17 +462,17 @@ void rndis_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
usbd_rndis_data_recv_done();
|
||||
}
|
||||
|
||||
void rndis_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void rndis_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
if ((nbytes % RNDIS_MAX_PACKET_SIZE) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(ep, NULL, 0);
|
||||
usbd_ep_start_write(0, ep, NULL, 0);
|
||||
} else {
|
||||
g_rndis_tx_data_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void rndis_int_in(uint8_t ep, uint32_t nbytes)
|
||||
void rndis_int_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
//USB_LOG_DBG("len:%d\r\n", nbytes);
|
||||
}
|
||||
@@ -496,7 +496,7 @@ struct pbuf *usbd_rndis_eth_rx(void)
|
||||
|
||||
USB_LOG_DBG("rxlen:%d\r\n", g_rndis_rx_data_length);
|
||||
g_rndis_rx_data_length = 0;
|
||||
usbd_ep_start_read(rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
usbd_ep_start_read(0, rndis_ep_data[RNDIS_OUT_EP_IDX].ep_addr, g_rndis_rx_buffer, sizeof(g_rndis_rx_buffer));
|
||||
|
||||
return p;
|
||||
}
|
||||
@@ -536,7 +536,7 @@ int usbd_rndis_eth_tx(struct pbuf *p)
|
||||
g_rndis_tx_data_length = sizeof(rndis_data_packet_t) + p->tot_len;
|
||||
|
||||
USB_LOG_DBG("txlen:%d\r\n", g_rndis_tx_data_length);
|
||||
return usbd_ep_start_write(rndis_ep_data[RNDIS_IN_EP_IDX].ep_addr, g_rndis_tx_buffer, g_rndis_tx_data_length);
|
||||
return usbd_ep_start_write(0, rndis_ep_data[RNDIS_IN_EP_IDX].ep_addr, g_rndis_tx_buffer, g_rndis_tx_data_length);
|
||||
}
|
||||
#endif
|
||||
struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||
@@ -557,9 +557,9 @@ struct usbd_interface *usbd_rndis_init_intf(struct usbd_interface *intf,
|
||||
rndis_ep_data[RNDIS_INT_EP_IDX].ep_addr = int_ep;
|
||||
rndis_ep_data[RNDIS_INT_EP_IDX].ep_cb = rndis_int_in;
|
||||
|
||||
usbd_add_endpoint(&rndis_ep_data[RNDIS_OUT_EP_IDX]);
|
||||
usbd_add_endpoint(&rndis_ep_data[RNDIS_IN_EP_IDX]);
|
||||
usbd_add_endpoint(&rndis_ep_data[RNDIS_INT_EP_IDX]);
|
||||
usbd_add_endpoint(0, &rndis_ep_data[RNDIS_OUT_EP_IDX]);
|
||||
usbd_add_endpoint(0, &rndis_ep_data[RNDIS_IN_EP_IDX]);
|
||||
usbd_add_endpoint(0, &rndis_ep_data[RNDIS_INT_EP_IDX]);
|
||||
|
||||
intf->class_interface_handler = rndis_class_interface_request_handler;
|
||||
intf->class_endpoint_handler = NULL;
|
||||
|
||||
@@ -16,13 +16,13 @@ extern "C" {
|
||||
* @brief init device controller registers.
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usb_dc_init(void);
|
||||
int usb_dc_init(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief deinit device controller registers.
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usb_dc_deinit(void);
|
||||
int usb_dc_deinit(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief Set USB device address
|
||||
@@ -31,7 +31,7 @@ int usb_dc_deinit(void);
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbd_set_address(const uint8_t addr);
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr);
|
||||
|
||||
/**
|
||||
* @brief Get USB device speed
|
||||
@@ -40,7 +40,7 @@ int usbd_set_address(const uint8_t addr);
|
||||
*
|
||||
* @return port speed, USB_SPEED_LOW or USB_SPEED_FULL or USB_SPEED_HIGH
|
||||
*/
|
||||
uint8_t usbd_get_port_speed(const uint8_t port);
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port);
|
||||
|
||||
/**
|
||||
* @brief configure and enable endpoint.
|
||||
@@ -49,7 +49,7 @@ uint8_t usbd_get_port_speed(const uint8_t port);
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep);
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep);
|
||||
|
||||
/**
|
||||
* @brief Disable the selected endpoint
|
||||
@@ -58,7 +58,7 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep);
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbd_ep_close(const uint8_t ep);
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep);
|
||||
|
||||
/**
|
||||
* @brief Set stall condition for the selected endpoint
|
||||
@@ -68,7 +68,7 @@ int usbd_ep_close(const uint8_t ep);
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbd_ep_set_stall(const uint8_t ep);
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep);
|
||||
|
||||
/**
|
||||
* @brief Clear stall condition for the selected endpoint
|
||||
@@ -78,7 +78,7 @@ int usbd_ep_set_stall(const uint8_t ep);
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbd_ep_clear_stall(const uint8_t ep);
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep);
|
||||
|
||||
/**
|
||||
* @brief Check if the selected endpoint is stalled
|
||||
@@ -89,7 +89,7 @@ int usbd_ep_clear_stall(const uint8_t ep);
|
||||
*
|
||||
* @return On success will return 0, and others indicate fail.
|
||||
*/
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled);
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled);
|
||||
|
||||
/**
|
||||
* @brief Setup in ep transfer setting and start transfer.
|
||||
@@ -108,7 +108,7 @@ int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled);
|
||||
* be zero for a zero length status packet.
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len);
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len);
|
||||
|
||||
/**
|
||||
* @brief Setup out ep transfer setting and start transfer.
|
||||
@@ -127,40 +127,40 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len);
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len);
|
||||
|
||||
/* usb dcd irq callback */
|
||||
|
||||
/**
|
||||
* @brief Usb connect irq callback.
|
||||
*/
|
||||
void usbd_event_connect_handler(void);
|
||||
void usbd_event_connect_handler(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief Usb disconnect irq callback.
|
||||
*/
|
||||
void usbd_event_disconnect_handler(void);
|
||||
void usbd_event_disconnect_handler(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief Usb resume irq callback.
|
||||
*/
|
||||
void usbd_event_resume_handler(void);
|
||||
void usbd_event_resume_handler(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief Usb suspend irq callback.
|
||||
*/
|
||||
void usbd_event_suspend_handler(void);
|
||||
void usbd_event_suspend_handler(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief Usb reset irq callback.
|
||||
*/
|
||||
void usbd_event_reset_handler(void);
|
||||
void usbd_event_reset_handler(uint8_t busid);
|
||||
|
||||
/**
|
||||
* @brief Usb setup packet recv irq callback.
|
||||
* @param[in] psetup setup packet.
|
||||
*/
|
||||
void usbd_event_ep0_setup_complete_handler(uint8_t *psetup);
|
||||
void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup);
|
||||
|
||||
/**
|
||||
* @brief In ep transfer complete irq callback.
|
||||
@@ -168,7 +168,7 @@ void usbd_event_ep0_setup_complete_handler(uint8_t *psetup);
|
||||
* listed in the device configuration table
|
||||
* @param[in] nbytes How many nbytes have transferred.
|
||||
*/
|
||||
void usbd_event_ep_in_complete_handler(uint8_t ep, uint32_t nbytes);
|
||||
void usbd_event_ep_in_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||
|
||||
/**
|
||||
* @brief Out ep transfer complete irq callback.
|
||||
@@ -176,7 +176,7 @@ void usbd_event_ep_in_complete_handler(uint8_t ep, uint32_t nbytes);
|
||||
* listed in the device configuration table
|
||||
* @param[in] nbytes How many nbytes have transferred.
|
||||
*/
|
||||
void usbd_event_ep_out_complete_handler(uint8_t ep, uint32_t nbytes);
|
||||
void usbd_event_ep_out_complete_handler(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
495
core/usbd_core.c
495
core/usbd_core.c
File diff suppressed because it is too large
Load Diff
@@ -43,9 +43,9 @@ enum usbd_event_type {
|
||||
USBD_EVENT_UNKNOWN
|
||||
};
|
||||
|
||||
typedef int (*usbd_request_handler)(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len);
|
||||
typedef void (*usbd_endpoint_callback)(uint8_t ep, uint32_t nbytes);
|
||||
typedef void (*usbd_notify_handler)(uint8_t event, void *arg);
|
||||
typedef int (*usbd_request_handler)(uint8_t busid, struct usb_setup_packet *setup, uint8_t **data, uint32_t *len);
|
||||
typedef void (*usbd_endpoint_callback)(uint8_t busid, uint8_t ep, uint32_t nbytes);
|
||||
typedef void (*usbd_notify_handler)(uint8_t busid, uint8_t event, void *arg);
|
||||
|
||||
struct usbd_endpoint {
|
||||
uint8_t ep_addr;
|
||||
@@ -75,22 +75,20 @@ struct usb_descriptor {
|
||||
};
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
void usbd_desc_register(const struct usb_descriptor *desc);
|
||||
void usbd_desc_register(uint8_t busid, const struct usb_descriptor *desc);
|
||||
#else
|
||||
void usbd_desc_register(const uint8_t *desc);
|
||||
void usbd_msosv1_desc_register(struct usb_msosv1_descriptor *desc);
|
||||
void usbd_msosv2_desc_register(struct usb_msosv2_descriptor *desc);
|
||||
void usbd_bos_desc_register(struct usb_bos_descriptor *desc);
|
||||
void usbd_desc_register(uint8_t busid, const uint8_t *desc);
|
||||
void usbd_msosv1_desc_register(uint8_t busid, struct usb_msosv1_descriptor *desc);
|
||||
void usbd_msosv2_desc_register(uint8_t busid, struct usb_msosv2_descriptor *desc);
|
||||
void usbd_bos_desc_register(uint8_t busid, struct usb_bos_descriptor *desc);
|
||||
#endif
|
||||
|
||||
void usbd_add_interface(struct usbd_interface *intf);
|
||||
void usbd_add_endpoint(struct usbd_endpoint *ep);
|
||||
void usbd_add_interface(uint8_t busid, struct usbd_interface *intf);
|
||||
void usbd_add_endpoint(uint8_t busid, struct usbd_endpoint *ep);
|
||||
|
||||
bool usb_device_is_configured(void);
|
||||
int usbd_initialize(void);
|
||||
int usbd_deinitialize(void);
|
||||
|
||||
void usbd_event_handler(uint8_t event);
|
||||
bool usb_device_is_configured(uint8_t busid);
|
||||
int usbd_initialize(uint8_t busid, void (*event_handler)(uint8_t event));
|
||||
int usbd_deinitialize(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
@@ -148,7 +150,7 @@ const uint8_t audio_v1_descriptor[] = {
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -173,19 +175,19 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_open(uint8_t intf)
|
||||
void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
tx_flag = 1;
|
||||
USB_LOG_RAW("OPEN\r\n");
|
||||
}
|
||||
|
||||
void usbd_audio_close(uint8_t intf)
|
||||
void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
USB_LOG_RAW("CLOSE\r\n");
|
||||
tx_flag = 0;
|
||||
}
|
||||
|
||||
void usbd_audio_iso_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_audio_iso_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
ep_tx_busy_flag = false;
|
||||
@@ -207,12 +209,12 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v1_init(void)
|
||||
{
|
||||
usbd_desc_register(audio_v1_descriptor);
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf0, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf1, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_endpoint(&audio_in_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, audio_v1_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &audio_in_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET];
|
||||
@@ -223,7 +225,7 @@ void audio_test()
|
||||
if (tx_flag) {
|
||||
memset(write_buffer, 'a', AUDIO_IN_PACKET);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
while (ep_tx_busy_flag) {
|
||||
if (tx_flag == false) {
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
@@ -147,7 +149,7 @@ volatile bool tx_flag = 0;
|
||||
volatile bool rx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -172,12 +174,12 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_open(uint8_t intf)
|
||||
void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
if (intf == 1) {
|
||||
rx_flag = 1;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
printf("OPEN1\r\n");
|
||||
} else {
|
||||
tx_flag = 1;
|
||||
@@ -185,7 +187,7 @@ void usbd_audio_open(uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_close(uint8_t intf)
|
||||
void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
if (intf == 1) {
|
||||
rx_flag = 1;
|
||||
@@ -196,13 +198,13 @@ void usbd_audio_close(uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_out_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_audio_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
usbd_ep_start_read(AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
void usbd_audio_in_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_audio_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
ep_tx_busy_flag = false;
|
||||
@@ -233,14 +235,14 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v1_init(void)
|
||||
{
|
||||
usbd_desc_register(audio_v1_descriptor);
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf0, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf1, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf2, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_endpoint(&audio_in_ep);
|
||||
usbd_add_endpoint(&audio_out_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, audio_v1_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf2, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &audio_in_ep);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &audio_out_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v1_test(void)
|
||||
@@ -248,7 +250,7 @@ void audio_v1_test(void)
|
||||
if (tx_flag) {
|
||||
memset(write_buffer, 'a', AUDIO_IN_PACKET);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
while (ep_tx_busy_flag) {
|
||||
if (tx_flag == false) {
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
@@ -159,7 +161,7 @@ static const uint8_t mic_default_sampling_freq_table[] = {
|
||||
|
||||
volatile bool tx_flag = 0;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -184,26 +186,26 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_open(uint8_t intf)
|
||||
void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
tx_flag = 1;
|
||||
USB_LOG_RAW("OPEN\r\n");
|
||||
}
|
||||
|
||||
void usbd_audio_close(uint8_t intf)
|
||||
void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
USB_LOG_RAW("CLOSE\r\n");
|
||||
tx_flag = 0;
|
||||
}
|
||||
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t ep, uint8_t **sampling_freq_table)
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
if (ep == AUDIO_IN_EP) {
|
||||
*sampling_freq_table = (uint8_t *)mic_default_sampling_freq_table;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_iso_in_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_audio_iso_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -226,12 +228,12 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v2_init(void)
|
||||
{
|
||||
usbd_desc_register(audio_v2_descriptor);
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(&audio_in_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, audio_v2_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &audio_in_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v2_test(void)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
@@ -229,7 +231,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET];
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool rx_flag = 0;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -254,12 +256,12 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_open(uint8_t intf)
|
||||
void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
if (intf == 1) {
|
||||
rx_flag = 1;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
USB_LOG_RAW("OPEN1\r\n");
|
||||
} else {
|
||||
tx_flag = 1;
|
||||
@@ -267,7 +269,7 @@ void usbd_audio_open(uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_close(uint8_t intf)
|
||||
void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
if (intf == 1) {
|
||||
rx_flag = 1;
|
||||
@@ -278,7 +280,7 @@ void usbd_audio_close(uint8_t intf)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t ep, uint8_t **sampling_freq_table)
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
*sampling_freq_table = (uint8_t *)speaker_default_sampling_freq_table;
|
||||
@@ -288,7 +290,7 @@ void usbd_audio_get_sampling_freq_table(uint8_t ep, uint8_t **sampling_freq_tabl
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_set_sampling_freq(uint8_t ep, uint32_t sampling_freq)
|
||||
void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_freq)
|
||||
{
|
||||
uint16_t packet_size = 0;
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
@@ -302,13 +304,13 @@ void usbd_audio_set_sampling_freq(uint8_t ep, uint32_t sampling_freq)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_iso_out_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_audio_iso_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
usbd_ep_start_read(AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
void usbd_audio_iso_in_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_audio_iso_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -343,14 +345,14 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v2_init(void)
|
||||
{
|
||||
usbd_desc_register(audio_v2_descriptor);
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf0, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf1, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf2, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_endpoint(&audio_in_ep);
|
||||
usbd_add_endpoint(&audio_out_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, audio_v2_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf2, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &audio_in_ep);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &audio_out_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v2_test(void)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
@@ -173,7 +175,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[AUDIO_OUT_PACKET];
|
||||
|
||||
volatile bool rx_flag = 0;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -198,31 +200,31 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_open(uint8_t intf)
|
||||
void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
rx_flag = 1;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
USB_LOG_RAW("OPEN\r\n");
|
||||
}
|
||||
|
||||
void usbd_audio_close(uint8_t intf)
|
||||
void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
USB_LOG_RAW("CLOSE\r\n");
|
||||
rx_flag = 0;
|
||||
}
|
||||
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t ep, uint8_t **sampling_freq_table)
|
||||
void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sampling_freq_table)
|
||||
{
|
||||
if (ep == AUDIO_OUT_EP) {
|
||||
*sampling_freq_table = (uint8_t *)default_sampling_freq_table;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_audio_iso_out_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_audio_iso_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
usbd_ep_start_read(AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
static struct usbd_endpoint audio_out_ep = {
|
||||
@@ -244,12 +246,12 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
|
||||
void audio_v2_init(void)
|
||||
{
|
||||
usbd_desc_register(audio_v2_descriptor);
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(usbd_audio_init_intf(&intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(&audio_out_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, audio_v2_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_audio_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &audio_out_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v2_test(void)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include "usbd_cdc.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
@@ -216,7 +218,7 @@ static struct hid_mouse mouse_cfg;
|
||||
static volatile uint8_t hid_state = HID_STATE_IDLE;
|
||||
|
||||
/* function ------------------------------------------------------------------*/
|
||||
static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes)
|
||||
static void usbd_hid_int_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
hid_state = HID_STATE_IDLE;
|
||||
}
|
||||
@@ -238,7 +240,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -253,7 +255,7 @@ void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@@ -265,20 +267,20 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
|
||||
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CDC_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@@ -302,17 +304,17 @@ struct usbd_interface intf3;
|
||||
|
||||
void cdc_acm_hid_msc_descriptor_init(void)
|
||||
{
|
||||
usbd_desc_register(cdc_acm_hid_msc_descriptor);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, cdc_acm_hid_msc_descriptor);
|
||||
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf0));
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf1));
|
||||
usbd_add_endpoint(&cdc_out_ep);
|
||||
usbd_add_endpoint(&cdc_in_ep);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_out_ep);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep);
|
||||
|
||||
usbd_add_interface(usbd_msc_init_intf(&intf2, MSC_OUT_EP, MSC_IN_EP));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_msc_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf2, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_add_interface(usbd_hid_init_intf(&intf3, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(&hid_in_ep);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_hid_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf3, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &hid_in_ep);
|
||||
|
||||
/*!< init mouse report data */
|
||||
mouse_cfg.buttons = 0;
|
||||
@@ -320,7 +322,7 @@ void cdc_acm_hid_msc_descriptor_init(void)
|
||||
mouse_cfg.x = 0;
|
||||
mouse_cfg.y = 0;
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -334,7 +336,7 @@ void hid_mouse_test(void)
|
||||
/*!< move mouse pointer */
|
||||
mouse_cfg.x += 10;
|
||||
mouse_cfg.y = 0;
|
||||
int ret = usbd_ep_start_write(HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
int ret = usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
@@ -345,7 +347,7 @@ void hid_mouse_test(void)
|
||||
|
||||
volatile uint8_t dtr_enable = 0;
|
||||
|
||||
void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr)
|
||||
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
{
|
||||
if (dtr) {
|
||||
dtr_enable = 1;
|
||||
@@ -359,7 +361,7 @@ void cdc_acm_data_send_with_dtr_test(void)
|
||||
if (dtr_enable) {
|
||||
memset(&write_buffer[10], 'a', 2038);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CDC_IN_EP, write_buffer, 2048);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, write_buffer, 2048);
|
||||
while (ep_tx_busy_flag) {
|
||||
}
|
||||
}
|
||||
@@ -375,19 +377,19 @@ typedef struct
|
||||
|
||||
BLOCK_TYPE mass_block[BLOCK_COUNT];
|
||||
|
||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
{
|
||||
*block_num = 1000; //Pretend having so many buffer,not has actually.
|
||||
*block_size = BLOCK_SIZE;
|
||||
}
|
||||
int usbd_msc_sector_read(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
if (sector < 10)
|
||||
memcpy(buffer, mass_block[sector].BlockSpace, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_write(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
if (sector < 10)
|
||||
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "usbd_cdc.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
@@ -249,7 +251,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -264,7 +266,7 @@ void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@@ -276,20 +278,20 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
|
||||
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CDC_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@@ -313,22 +315,22 @@ struct usbd_interface intf2;
|
||||
void cdc_acm_msc_init(void)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(&cdc_msc_descriptor);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, &cdc_msc_descriptor);
|
||||
#else
|
||||
usbd_desc_register(cdc_msc_descriptor);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, cdc_msc_descriptor);
|
||||
#endif
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf0));
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf1));
|
||||
usbd_add_endpoint(&cdc_out_ep);
|
||||
usbd_add_endpoint(&cdc_in_ep);
|
||||
usbd_add_interface(usbd_msc_init_intf(&intf2, MSC_OUT_EP, MSC_IN_EP));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_out_ep);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_msc_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf2, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
volatile uint8_t dtr_enable = 0;
|
||||
|
||||
void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr)
|
||||
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
{
|
||||
if (dtr) {
|
||||
dtr_enable = 1;
|
||||
@@ -342,7 +344,7 @@ void cdc_acm_data_send_with_dtr_test(void)
|
||||
if (dtr_enable) {
|
||||
memset(&write_buffer[10], 'a', 2038);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CDC_IN_EP, write_buffer, 2048);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, write_buffer, 2048);
|
||||
while (ep_tx_busy_flag) {
|
||||
}
|
||||
}
|
||||
@@ -358,19 +360,19 @@ typedef struct
|
||||
|
||||
BLOCK_TYPE mass_block[BLOCK_COUNT];
|
||||
|
||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
{
|
||||
*block_num = 1000; //Pretend having so many buffer,not has actually.
|
||||
*block_size = BLOCK_SIZE;
|
||||
}
|
||||
int usbd_msc_sector_read(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
if (sector < 10)
|
||||
memcpy(buffer, mass_block[sector].BlockSpace, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_write(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
if (sector < 10)
|
||||
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x01
|
||||
@@ -125,7 +127,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -140,10 +142,10 @@ void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CDC_OUT_EP2, read_buffer, 2048);
|
||||
usbd_ep_start_read(CDC_OUT_EP3, read_buffer, 2048);
|
||||
usbd_ep_start_read(CDC_OUT_EP4, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP2, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP3, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP4, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@@ -155,14 +157,14 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
|
||||
@@ -225,27 +227,27 @@ struct usbd_interface intf7;
|
||||
|
||||
void cdc_acm_multi_init(void)
|
||||
{
|
||||
usbd_desc_register(cdc_descriptor);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, cdc_descriptor);
|
||||
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf0));
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf1));
|
||||
usbd_add_endpoint(&cdc_out_ep1);
|
||||
usbd_add_endpoint(&cdc_in_ep1);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_out_ep1);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep1);
|
||||
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf2));
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf3));
|
||||
usbd_add_endpoint(&cdc_out_ep2);
|
||||
usbd_add_endpoint(&cdc_in_ep2);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf2));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf3));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_out_ep2);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep2);
|
||||
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf4));
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf5));
|
||||
usbd_add_endpoint(&cdc_out_ep3);
|
||||
usbd_add_endpoint(&cdc_in_ep3);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf4));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf5));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_out_ep3);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep3);
|
||||
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf6));
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf7));
|
||||
usbd_add_endpoint(&cdc_out_ep4);
|
||||
usbd_add_endpoint(&cdc_in_ep4);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf6));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf7));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_out_ep4);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep4);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
@@ -110,7 +112,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -125,7 +127,7 @@ void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@@ -137,7 +139,7 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
@@ -145,16 +147,16 @@ void usbd_cdc_acm_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
// }
|
||||
// printf("\r\n");
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
|
||||
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CDC_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@@ -181,17 +183,17 @@ void cdc_acm_init(void)
|
||||
memcpy(&write_buffer[0], data, 10);
|
||||
memset(&write_buffer[10], 'a', 2038);
|
||||
|
||||
usbd_desc_register(cdc_descriptor);
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf0));
|
||||
usbd_add_interface(usbd_cdc_acm_init_intf(&intf1));
|
||||
usbd_add_endpoint(&cdc_out_ep);
|
||||
usbd_add_endpoint(&cdc_in_ep);
|
||||
usbd_initialize();
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, cdc_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_cdc_acm_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_out_ep);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep);
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
volatile uint8_t dtr_enable = 0;
|
||||
|
||||
void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr)
|
||||
void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
{
|
||||
if (dtr) {
|
||||
dtr_enable = 1;
|
||||
@@ -204,7 +206,7 @@ void cdc_acm_data_send_with_dtr_test(void)
|
||||
{
|
||||
if (dtr_enable) {
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CDC_IN_EP, write_buffer, 2048);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, write_buffer, 2048);
|
||||
while (ep_tx_busy_flag) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ void cdc_ecm_input_poll(void)
|
||||
cdc_ecm_if_input(&cdc_ecm_netif);
|
||||
}
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -267,8 +267,8 @@ void cdc_ecm_init(void)
|
||||
{
|
||||
cdc_ecm_lwip_init();
|
||||
|
||||
usbd_desc_register(cdc_ecm_descriptor);
|
||||
usbd_add_interface(usbd_cdc_ecm_init_intf(&intf0, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_add_interface(usbd_cdc_ecm_init_intf(&intf1, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_initialize();
|
||||
usbd_desc_register(0, cdc_ecm_descriptor);
|
||||
usbd_add_interface(0, usbd_cdc_ecm_init_intf(0, &intf0, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_add_interface(0, usbd_cdc_ecm_init_intf(0, &intf1, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_initialize(0, usbd_event_handler);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ void rndis_input_poll(void)
|
||||
}
|
||||
#endif /* RT_USING_LWIP */
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -301,8 +301,8 @@ void cdc_rndis_init(void)
|
||||
#else
|
||||
rndis_lwip_init();
|
||||
#endif
|
||||
usbd_desc_register(cdc_descriptor);
|
||||
usbd_add_interface(usbd_rndis_init_intf(&intf0, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_add_interface(usbd_rndis_init_intf(&intf1, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_initialize();
|
||||
usbd_desc_register(0, cdc_descriptor);
|
||||
usbd_add_interface(0, usbd_rndis_init_intf(&intf0, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_add_interface(0, usbd_rndis_init_intf(&intf1, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_initialize(0, usbd_event_handler);
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ const uint8_t dfu_flash_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -166,7 +166,7 @@ struct usbd_interface intf0;
|
||||
|
||||
void dfu_flash_init(void)
|
||||
{
|
||||
usbd_desc_register(dfu_flash_descriptor);
|
||||
usbd_add_interface(usbd_dfu_init_intf(&intf0));
|
||||
usbd_initialize();
|
||||
usbd_desc_register(0, dfu_flash_descriptor);
|
||||
usbd_add_interface(0, usbd_dfu_init_intf(&intf0));
|
||||
usbd_initialize(0, usbd_event_handler);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
/*!< hidraw in endpoint */
|
||||
#define HIDRAW_IN_EP 0x81
|
||||
#define HIDRAW_IN_EP_SIZE 64
|
||||
@@ -169,7 +171,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t send_buffer[HIDRAW_IN_EP_SIZE];
|
||||
/*!< hid state ! Data can be sent only when state is idle */
|
||||
static volatile uint8_t custom_state;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -184,7 +186,7 @@ void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(HIDRAW_OUT_EP, read_buffer, HIDRAW_OUT_EP_SIZE);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, HIDRAW_OUT_EP, read_buffer, HIDRAW_OUT_EP_SIZE);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@@ -196,18 +198,18 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
static void usbd_hid_custom_in_callback(uint8_t ep, uint32_t nbytes)
|
||||
static void usbd_hid_custom_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
custom_state = HID_STATE_IDLE;
|
||||
}
|
||||
|
||||
static void usbd_hid_custom_out_callback(uint8_t ep, uint32_t nbytes)
|
||||
static void usbd_hid_custom_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
usbd_ep_start_read(HIDRAW_OUT_EP, read_buffer, 64);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, HIDRAW_OUT_EP, read_buffer, 64);
|
||||
read_buffer[0] = 0x02; /* IN: report id */
|
||||
usbd_ep_start_write(HIDRAW_IN_EP, read_buffer, nbytes);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, HIDRAW_IN_EP, read_buffer, nbytes);
|
||||
}
|
||||
|
||||
static struct usbd_endpoint custom_in_ep = {
|
||||
@@ -231,10 +233,10 @@ struct usbd_interface intf0;
|
||||
|
||||
void hid_custom_init(void)
|
||||
{
|
||||
usbd_desc_register(hid_descriptor);
|
||||
usbd_add_interface(usbd_hid_init_intf(&intf0, hid_custom_report_desc, HID_CUSTOM_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(&custom_in_ep);
|
||||
usbd_add_endpoint(&custom_out_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, hid_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_hid_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, hid_custom_report_desc, HID_CUSTOM_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &custom_in_ep);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &custom_out_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define USBD_VID 0xffff
|
||||
#define USBD_PID 0xffff
|
||||
#define USBD_MAX_POWER 100
|
||||
@@ -172,7 +174,7 @@ static const uint8_t hid_keyboard_report_desc[HID_KEYBOARD_REPORT_DESC_SIZE] = {
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -203,7 +205,7 @@ void usbd_event_handler(uint8_t event)
|
||||
/*!< hid state ! Data can be sent only when state is idle */
|
||||
static volatile uint8_t hid_state = HID_STATE_IDLE;
|
||||
|
||||
void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_hid_int_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
hid_state = HID_STATE_IDLE;
|
||||
}
|
||||
@@ -217,11 +219,11 @@ struct usbd_interface intf0;
|
||||
|
||||
void hid_keyboard_init(void)
|
||||
{
|
||||
usbd_desc_register(hid_descriptor);
|
||||
usbd_add_interface(usbd_hid_init_intf(&intf0, hid_keyboard_report_desc, HID_KEYBOARD_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(&hid_in_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, hid_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_hid_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, hid_keyboard_report_desc, HID_KEYBOARD_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &hid_in_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[64];
|
||||
@@ -231,7 +233,7 @@ void hid_keyboard_test(void)
|
||||
const uint8_t sendbuffer[8] = { 0x00, 0x00, HID_KBD_USAGE_A, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
memcpy(write_buffer, sendbuffer, 8);
|
||||
int ret = usbd_ep_start_write(HID_INT_EP, write_buffer, 8);
|
||||
int ret = usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, HID_INT_EP, write_buffer, 8);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_hid.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
/*!< endpoint address */
|
||||
#define HID_INT_EP 0x81
|
||||
#define HID_INT_EP_SIZE 4
|
||||
@@ -194,7 +196,7 @@ static USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct hid_mouse mouse_cfg;
|
||||
/*!< hid state ! Data can be sent only when state is idle */
|
||||
static volatile uint8_t hid_state = HID_STATE_IDLE;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -220,7 +222,7 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
|
||||
/* function ------------------------------------------------------------------*/
|
||||
static void usbd_hid_int_callback(uint8_t ep, uint32_t nbytes)
|
||||
static void usbd_hid_int_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
hid_state = HID_STATE_IDLE;
|
||||
}
|
||||
@@ -235,11 +237,11 @@ struct usbd_interface intf0;
|
||||
|
||||
void hid_mouse_init(void)
|
||||
{
|
||||
usbd_desc_register(hid_descriptor);
|
||||
usbd_add_interface(usbd_hid_init_intf(&intf0, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(&hid_in_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, hid_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_hid_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &hid_in_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
|
||||
/*!< init mouse report data */
|
||||
mouse_cfg.buttons = 0;
|
||||
@@ -262,7 +264,7 @@ void hid_mouse_test(void)
|
||||
mouse_cfg.x += 40;
|
||||
mouse_cfg.y += 0;
|
||||
|
||||
int ret = usbd_ep_start_write(HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
int ret = usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usb_midi.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define MIDI_OUT_EP 0x02
|
||||
#define MIDI_IN_EP 0x81
|
||||
|
||||
@@ -146,7 +148,7 @@ const uint8_t midi_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -171,11 +173,11 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_midi_bulk_out(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_midi_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
}
|
||||
|
||||
void usbd_midi_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_midi_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -194,11 +196,11 @@ struct usbd_endpoint midi_in_ep = {
|
||||
|
||||
void midi_init(void)
|
||||
{
|
||||
usbd_desc_register(midi_descriptor);
|
||||
usbd_add_interface(&intf0);
|
||||
usbd_add_interface(&intf1);
|
||||
usbd_add_endpoint(&midi_out_ep);
|
||||
usbd_add_endpoint(&midi_in_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, midi_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, &intf0);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, &intf1);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &midi_out_ep);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &midi_in_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define MSC_IN_EP 0x81
|
||||
#define MSC_OUT_EP 0x02
|
||||
|
||||
@@ -95,7 +97,7 @@ const uint8_t msc_ram_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -130,19 +132,19 @@ typedef struct
|
||||
|
||||
BLOCK_TYPE mass_block[BLOCK_COUNT];
|
||||
|
||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
{
|
||||
*block_num = 1000; //Pretend having so many buffer,not has actually.
|
||||
*block_size = BLOCK_SIZE;
|
||||
}
|
||||
int usbd_msc_sector_read(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
if (sector < BLOCK_COUNT)
|
||||
memcpy(buffer, mass_block[sector].BlockSpace, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_write(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
if (sector < BLOCK_COUNT)
|
||||
memcpy(mass_block[sector].BlockSpace, buffer, length);
|
||||
@@ -153,8 +155,8 @@ struct usbd_interface intf0;
|
||||
|
||||
void msc_ram_init(void)
|
||||
{
|
||||
usbd_desc_register(msc_ram_descriptor);
|
||||
usbd_add_interface(usbd_msc_init_intf(&intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, msc_ram_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_msc_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
|
||||
#define MSC_IN_EP 0x81
|
||||
@@ -106,7 +108,7 @@ struct usbd_interface intf0;
|
||||
#define BLOCK_COUNT 0x1024U * 0x1024U
|
||||
static rt_device_t blk_dev = RT_NULL;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -131,19 +133,19 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_msc_get_cap(uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
void usbd_msc_get_cap(uint8_t busid, uint8_t lun, uint32_t *block_num, uint32_t *block_size)
|
||||
{
|
||||
*block_num = BLOCK_COUNT;
|
||||
*block_size = BLOCK_SIZE;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_read(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_read(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
rt_device_read(blk_dev, sector, buffer, length / BLOCK_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_msc_sector_write(uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
rt_device_write(blk_dev, sector, buffer, length / BLOCK_SIZE);
|
||||
return 0;
|
||||
@@ -159,9 +161,9 @@ void msc_storage_init(void)
|
||||
res = rt_device_open(blk_dev, RT_DEVICE_OFLAG_RDWR);
|
||||
RT_ASSERT(res == RT_EOK);
|
||||
|
||||
usbd_desc_register(msc_storage_descriptor);
|
||||
usbd_add_interface(usbd_msc_init_intf(&intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, msc_storage_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_msc_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
#endif
|
||||
@@ -2,6 +2,8 @@
|
||||
#include "usbd_video.h"
|
||||
#include "pic_data.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define VIDEO_IN_EP 0x81
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
@@ -141,7 +143,7 @@ const uint8_t video_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -169,20 +171,20 @@ void usbd_event_handler(uint8_t event)
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool iso_tx_busy = false;
|
||||
|
||||
void usbd_video_open(uint8_t intf)
|
||||
void usbd_video_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
tx_flag = 1;
|
||||
USB_LOG_RAW("OPEN\r\n");
|
||||
iso_tx_busy = false;
|
||||
}
|
||||
void usbd_video_close(uint8_t intf)
|
||||
void usbd_video_close(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
USB_LOG_RAW("CLOSE\r\n");
|
||||
tx_flag = 0;
|
||||
iso_tx_busy = false;
|
||||
}
|
||||
|
||||
void usbd_video_iso_callback(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_video_iso_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
iso_tx_busy = false;
|
||||
@@ -198,12 +200,12 @@ struct usbd_interface intf1;
|
||||
|
||||
void video_init()
|
||||
{
|
||||
usbd_desc_register(video_descriptor);
|
||||
usbd_add_interface(usbd_video_init_intf(&intf0, INTERVAL, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
|
||||
usbd_add_interface(usbd_video_init_intf(&intf1, INTERVAL, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
|
||||
usbd_add_endpoint(&video_in_ep);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, video_descriptor);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_video_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf0, INTERVAL, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, usbd_video_init_intf(CONFIG_USBDEV_DEMO_BUS, &intf1, INTERVAL, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &video_in_ep);
|
||||
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t packet_buffer[10 * 1024];
|
||||
@@ -215,10 +217,10 @@ void video_test()
|
||||
memset(packet_buffer, 0, 10 * 1024);
|
||||
while (1) {
|
||||
if (tx_flag) {
|
||||
packets = usbd_video_mjpeg_payload_fill((uint8_t *)jpeg_data, sizeof(jpeg_data), packet_buffer, &out_len);
|
||||
packets = usbd_video_mjpeg_payload_fill(CONFIG_USBDEV_DEMO_BUS, (uint8_t *)jpeg_data, sizeof(jpeg_data), packet_buffer, &out_len);
|
||||
#if 0
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(VIDEO_IN_EP, packet_buffer, out_len);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, VIDEO_IN_EP, packet_buffer, out_len);
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
@@ -229,7 +231,7 @@ void video_test()
|
||||
for (uint32_t i = 0; i < packets; i++) {
|
||||
if (i == (packets - 1)) {
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], out_len - (packets - 1) * MAX_PAYLOAD_SIZE);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], out_len - (packets - 1) * MAX_PAYLOAD_SIZE);
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
@@ -237,7 +239,7 @@ void video_test()
|
||||
}
|
||||
} else {
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE);
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define WCID_VENDOR_CODE 0x17
|
||||
|
||||
#define DOUBLE_WINUSB 0
|
||||
@@ -334,7 +336,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
|
||||
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -349,9 +351,9 @@ void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(WINUSB_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP, read_buffer, 2048);
|
||||
#if DOUBLE_WINUSB == 1
|
||||
usbd_ep_start_read(WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
#endif
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
@@ -364,25 +366,25 @@ void usbd_event_handler(uint8_t event)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_winusb_out(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_winusb_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
// printf("%02x ", read_buffer[i]);
|
||||
// }
|
||||
// printf("\r\n");
|
||||
usbd_ep_start_write(WINUSB_IN_EP, read_buffer, nbytes);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP, read_buffer, nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(WINUSB_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_winusb_in(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_winusb_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
|
||||
if ((nbytes % WINUSB_EP_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(WINUSB_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@@ -402,25 +404,25 @@ struct usbd_interface intf0;
|
||||
|
||||
#if DOUBLE_WINUSB == 1
|
||||
|
||||
void usbd_winusb_out2(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_winusb_out2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual out len:%d\r\n", nbytes);
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
// printf("%02x ", read_buffer[i]);
|
||||
// }
|
||||
// printf("\r\n");
|
||||
usbd_ep_start_write(WINUSB_IN_EP2, read_buffer, nbytes);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP2, read_buffer, nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_winusb_in2(uint8_t ep, uint32_t nbytes)
|
||||
void usbd_winusb_in2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
|
||||
if ((nbytes % WINUSB_EP_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(WINUSB_IN_EP2, NULL, 0);
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP2, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@@ -442,15 +444,15 @@ struct usbd_interface intf1;
|
||||
|
||||
void winusb_init(void)
|
||||
{
|
||||
usbd_desc_register(winusb_descriptor);
|
||||
usbd_msosv1_desc_register(&msosv1_desc);
|
||||
usbd_add_interface(&intf0);
|
||||
usbd_add_endpoint(&winusb_out_ep1);
|
||||
usbd_add_endpoint(&winusb_in_ep1);
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, winusb_descriptor);
|
||||
usbd_msosv1_desc_register(CONFIG_USBDEV_DEMO_BUS, &msosv1_desc);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, &intf0);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &winusb_out_ep1);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &winusb_in_ep1);
|
||||
#if DOUBLE_WINUSB == 1
|
||||
usbd_add_interface(&intf1);
|
||||
usbd_add_endpoint(&winusb_out_ep2);
|
||||
usbd_add_endpoint(&winusb_in_ep2);
|
||||
usbd_add_interface(CONFIG_USBDEV_DEMO_BUS, &intf1);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &winusb_out_ep2);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &winusb_in_ep2);
|
||||
#endif
|
||||
usbd_initialize();
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
}
|
||||
@@ -3,10 +3,3 @@
|
||||
## Support Chip List
|
||||
|
||||
- CH32V30x
|
||||
|
||||
## Before Use
|
||||
|
||||
Your should implement `usb_dc_low_level_init` and `usb_dc_low_level_deinit`.
|
||||
- Enable or disable USB clock and set USB clock for 48M.
|
||||
- Enable or disable gpio and gpio clk for usb dp and dm.
|
||||
- Enable or disable usb irq
|
||||
@@ -120,249 +120,13 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set address
|
||||
* @pre None
|
||||
* @param[in] address :8-bit valid address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_set_address(const uint8_t address)
|
||||
{
|
||||
if (address == 0) {
|
||||
CH58x_USBFS_DEV->USB_DEV_AD = (CH58x_USBFS_DEV->USB_DEV_AD & 0x80) | address;
|
||||
}
|
||||
usb_dc_cfg.address = address;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
{
|
||||
return USB_SPEED_FULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Open endpoint
|
||||
* @pre None
|
||||
* @param[in] ep_cfg : Endpoint configuration structure pointer
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
/*!< ep id */
|
||||
uint8_t epid = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
if (epid > (USB_NUM_BIDIR_ENDPOINTS - 1)) {
|
||||
/**
|
||||
* If you use ch58x, you can change the EP_NUMS set to 8
|
||||
*/
|
||||
USB_LOG_ERR("Ep addr %02x overflow\r\n", ep->bEndpointAddress);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!< ep max packet length */
|
||||
uint8_t mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
/*!< update ep max packet length */
|
||||
if (USB_EP_DIR_IS_IN(ep->bEndpointAddress)) {
|
||||
/*!< in */
|
||||
usb_dc_cfg.ep_in[epid].ep_enable = true;
|
||||
usb_dc_cfg.ep_in[epid].mps = mps;
|
||||
usb_dc_cfg.ep_in[epid].eptype = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
} else if (USB_EP_DIR_IS_OUT(ep->bEndpointAddress)) {
|
||||
/*!< out */
|
||||
usb_dc_cfg.ep_out[epid].ep_enable = true;
|
||||
usb_dc_cfg.ep_out[epid].mps = mps;
|
||||
usb_dc_cfg.ep_out[epid].eptype = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Close endpoint
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
{
|
||||
/*!< ep id */
|
||||
uint8_t epid = USB_EP_GET_IDX(ep);
|
||||
if (USB_EP_DIR_IS_IN(ep)) {
|
||||
/*!< in */
|
||||
usb_dc_cfg.ep_in[epid].ep_enable = false;
|
||||
} else if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
/*!< out */
|
||||
usb_dc_cfg.ep_out[epid].ep_enable = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup in ep transfer setting and start transfer.
|
||||
*
|
||||
* This function is asynchronous.
|
||||
* This function is similar to uart with tx dma.
|
||||
*
|
||||
* This function is called to write data to the specified endpoint. The
|
||||
* supplied usbd_endpoint_callback function will be called when data is transmitted
|
||||
* out.
|
||||
*
|
||||
* @param[in] ep Endpoint address corresponding to the one
|
||||
* listed in the device configuration table
|
||||
* @param[in] data Pointer to data to write
|
||||
* @param[in] data_len Length of the data requested to write. This may
|
||||
* be zero for a zero length status packet.
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!usb_dc_cfg.ep_in[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
if ((uint32_t)data & 0x03) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
usb_dc_cfg.ep_in[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
usb_dc_cfg.ep_in[ep_idx].xfer_len = data_len;
|
||||
usb_dc_cfg.ep_in[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
if (data_len == 0) {
|
||||
/*!< write 0 len data */
|
||||
EPn_SET_TX_LEN(ep_idx, 0);
|
||||
/*!< enable tx */
|
||||
if (usb_dc_cfg.ep_in[ep_idx].eptype != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
EPn_SET_TX_VALID(ep_idx);
|
||||
} else {
|
||||
EPn_SET_TX_ISO_VALID(ep_idx);
|
||||
}
|
||||
/*!< return */
|
||||
return 0;
|
||||
} else {
|
||||
/*!< Not zlp */
|
||||
data_len = MIN(data_len, usb_dc_cfg.ep_in[ep_idx].mps);
|
||||
/*!< write buff */
|
||||
memcpy(usb_dc_cfg.ep_in[ep_idx].ep_ram_addr, data, data_len);
|
||||
/*!< write real_wt_nums len data */
|
||||
EPn_SET_TX_LEN(ep_idx, data_len);
|
||||
/*!< enable tx */
|
||||
if (usb_dc_cfg.ep_in[ep_idx].eptype != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
EPn_SET_TX_VALID(ep_idx);
|
||||
} else {
|
||||
EPn_SET_TX_ISO_VALID(ep_idx);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup out ep transfer setting and start transfer.
|
||||
*
|
||||
* This function is asynchronous.
|
||||
* This function is similar to uart with rx dma.
|
||||
*
|
||||
* This function is called to read data to the specified endpoint. The
|
||||
* supplied usbd_endpoint_callback function will be called when data is received
|
||||
* in.
|
||||
*
|
||||
* @param[in] ep Endpoint address corresponding to the one
|
||||
* listed in the device configuration table
|
||||
* @param[in] data Pointer to data to read
|
||||
* @param[in] data_len Max length of the data requested to read.
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!usb_dc_cfg.ep_out[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
if ((uint32_t)data & 0x03) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
usb_dc_cfg.ep_out[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
usb_dc_cfg.ep_out[ep_idx].xfer_len = data_len;
|
||||
usb_dc_cfg.ep_out[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
if (data_len == 0) {
|
||||
} else {
|
||||
data_len = MIN(data_len, usb_dc_cfg.ep_out[ep_idx].mps);
|
||||
}
|
||||
|
||||
if (usb_dc_cfg.ep_out[ep_idx].eptype != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
EPn_SET_RX_VALID(ep_idx);
|
||||
} else {
|
||||
EPn_SET_RX_ISO_VALID(ep_idx);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Endpoint setting stall
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
{
|
||||
/*!< ep id */
|
||||
uint8_t epid = USB_EP_GET_IDX(ep);
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
EPn_SET_RX_STALL(epid);
|
||||
} else {
|
||||
EPn_SET_TX_STALL(epid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Endpoint clear stall
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
{
|
||||
uint8_t epid = USB_EP_GET_IDX(ep);
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
EPn_CLR_RX_STALL(epid);
|
||||
} else {
|
||||
EPn_CLR_TX_STALL(epid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check endpoint status
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @param[out] stalled : Outgoing endpoint status
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
} else {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USB initialization
|
||||
* @pre None
|
||||
* @param[in] None
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
usb_dc_cfg.ep_in[0].ep_ram_addr = ep0_data_buff;
|
||||
usb_dc_cfg.ep_out[0].ep_ram_addr = ep0_data_buff;
|
||||
@@ -434,6 +198,248 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set address
|
||||
* @pre None
|
||||
* @param[in] address :8-bit valid address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_set_address(uint8_t busid, const uint8_t address)
|
||||
{
|
||||
if (address == 0) {
|
||||
CH58x_USBFS_DEV->USB_DEV_AD = (CH58x_USBFS_DEV->USB_DEV_AD & 0x80) | address;
|
||||
}
|
||||
usb_dc_cfg.address = address;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
return USB_SPEED_FULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Open endpoint
|
||||
* @pre None
|
||||
* @param[in] ep_cfg : Endpoint configuration structure pointer
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
/*!< ep id */
|
||||
uint8_t epid = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
if (epid > (USB_NUM_BIDIR_ENDPOINTS - 1)) {
|
||||
/**
|
||||
* If you use ch58x, you can change the EP_NUMS set to 8
|
||||
*/
|
||||
USB_LOG_ERR("Ep addr %02x overflow\r\n", ep->bEndpointAddress);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!< ep max packet length */
|
||||
uint8_t mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
/*!< update ep max packet length */
|
||||
if (USB_EP_DIR_IS_IN(ep->bEndpointAddress)) {
|
||||
/*!< in */
|
||||
usb_dc_cfg.ep_in[epid].ep_enable = true;
|
||||
usb_dc_cfg.ep_in[epid].mps = mps;
|
||||
usb_dc_cfg.ep_in[epid].eptype = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
} else if (USB_EP_DIR_IS_OUT(ep->bEndpointAddress)) {
|
||||
/*!< out */
|
||||
usb_dc_cfg.ep_out[epid].ep_enable = true;
|
||||
usb_dc_cfg.ep_out[epid].mps = mps;
|
||||
usb_dc_cfg.ep_out[epid].eptype = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Close endpoint
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
/*!< ep id */
|
||||
uint8_t epid = USB_EP_GET_IDX(ep);
|
||||
if (USB_EP_DIR_IS_IN(ep)) {
|
||||
/*!< in */
|
||||
usb_dc_cfg.ep_in[epid].ep_enable = false;
|
||||
} else if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
/*!< out */
|
||||
usb_dc_cfg.ep_out[epid].ep_enable = false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Endpoint setting stall
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
/*!< ep id */
|
||||
uint8_t epid = USB_EP_GET_IDX(ep);
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
EPn_SET_RX_STALL(epid);
|
||||
} else {
|
||||
EPn_SET_TX_STALL(epid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Endpoint clear stall
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t epid = USB_EP_GET_IDX(ep);
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
EPn_CLR_RX_STALL(epid);
|
||||
} else {
|
||||
EPn_CLR_TX_STALL(epid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check endpoint status
|
||||
* @pre None
|
||||
* @param[in] ep : Endpoint address
|
||||
* @param[out] stalled : Outgoing endpoint status
|
||||
* @retval >=0 success otherwise failure
|
||||
*/
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
} else {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup in ep transfer setting and start transfer.
|
||||
*
|
||||
* This function is asynchronous.
|
||||
* This function is similar to uart with tx dma.
|
||||
*
|
||||
* This function is called to write data to the specified endpoint. The
|
||||
* supplied usbd_endpoint_callback function will be called when data is transmitted
|
||||
* out.
|
||||
*
|
||||
* @param[in] ep Endpoint address corresponding to the one
|
||||
* listed in the device configuration table
|
||||
* @param[in] data Pointer to data to write
|
||||
* @param[in] data_len Length of the data requested to write. This may
|
||||
* be zero for a zero length status packet.
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!usb_dc_cfg.ep_in[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
if ((uint32_t)data & 0x03) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
usb_dc_cfg.ep_in[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
usb_dc_cfg.ep_in[ep_idx].xfer_len = data_len;
|
||||
usb_dc_cfg.ep_in[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
if (data_len == 0) {
|
||||
/*!< write 0 len data */
|
||||
EPn_SET_TX_LEN(ep_idx, 0);
|
||||
/*!< enable tx */
|
||||
if (usb_dc_cfg.ep_in[ep_idx].eptype != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
EPn_SET_TX_VALID(ep_idx);
|
||||
} else {
|
||||
EPn_SET_TX_ISO_VALID(ep_idx);
|
||||
}
|
||||
/*!< return */
|
||||
return 0;
|
||||
} else {
|
||||
/*!< Not zlp */
|
||||
data_len = MIN(data_len, usb_dc_cfg.ep_in[ep_idx].mps);
|
||||
/*!< write buff */
|
||||
memcpy(usb_dc_cfg.ep_in[ep_idx].ep_ram_addr, data, data_len);
|
||||
/*!< write real_wt_nums len data */
|
||||
EPn_SET_TX_LEN(ep_idx, data_len);
|
||||
/*!< enable tx */
|
||||
if (usb_dc_cfg.ep_in[ep_idx].eptype != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
EPn_SET_TX_VALID(ep_idx);
|
||||
} else {
|
||||
EPn_SET_TX_ISO_VALID(ep_idx);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Setup out ep transfer setting and start transfer.
|
||||
*
|
||||
* This function is asynchronous.
|
||||
* This function is similar to uart with rx dma.
|
||||
*
|
||||
* This function is called to read data to the specified endpoint. The
|
||||
* supplied usbd_endpoint_callback function will be called when data is received
|
||||
* in.
|
||||
*
|
||||
* @param[in] ep Endpoint address corresponding to the one
|
||||
* listed in the device configuration table
|
||||
* @param[in] data Pointer to data to read
|
||||
* @param[in] data_len Max length of the data requested to read.
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!usb_dc_cfg.ep_out[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
if ((uint32_t)data & 0x03) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
usb_dc_cfg.ep_out[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
usb_dc_cfg.ep_out[ep_idx].xfer_len = data_len;
|
||||
usb_dc_cfg.ep_out[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
if (data_len == 0) {
|
||||
} else {
|
||||
data_len = MIN(data_len, usb_dc_cfg.ep_out[ep_idx].mps);
|
||||
}
|
||||
|
||||
if (usb_dc_cfg.ep_out[ep_idx].eptype != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
EPn_SET_RX_VALID(ep_idx);
|
||||
} else {
|
||||
EPn_SET_RX_ISO_VALID(ep_idx);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USB interrupt processing function
|
||||
* @pre None
|
||||
@@ -471,11 +477,11 @@ USBD_IRQHandler(void)
|
||||
if (usb_dc_cfg.ep_in[0].xfer_len > usb_dc_cfg.ep_in[0].mps) {
|
||||
usb_dc_cfg.ep_in[0].xfer_len -= usb_dc_cfg.ep_in[0].mps;
|
||||
usb_dc_cfg.ep_in[0].actual_xfer_len += usb_dc_cfg.ep_in[0].mps;
|
||||
usbd_event_ep_in_complete_handler(0 | 0x80, usb_dc_cfg.ep_in[0].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, 0 | 0x80, usb_dc_cfg.ep_in[0].actual_xfer_len);
|
||||
} else {
|
||||
usb_dc_cfg.ep_in[0].actual_xfer_len += usb_dc_cfg.ep_in[0].xfer_len;
|
||||
usb_dc_cfg.ep_in[0].xfer_len = 0;
|
||||
usbd_event_ep_in_complete_handler(0 | 0x80, usb_dc_cfg.ep_in[0].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, 0 | 0x80, usb_dc_cfg.ep_in[0].actual_xfer_len);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
@@ -526,7 +532,7 @@ USBD_IRQHandler(void)
|
||||
} else {
|
||||
usb_dc_cfg.ep_in[epid].actual_xfer_len += usb_dc_cfg.ep_in[epid].xfer_len;
|
||||
usb_dc_cfg.ep_in[epid].xfer_len = 0;
|
||||
usbd_event_ep_in_complete_handler(epid | 0x80, usb_dc_cfg.ep_in[epid].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, epid | 0x80, usb_dc_cfg.ep_in[epid].actual_xfer_len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -539,7 +545,7 @@ USBD_IRQHandler(void)
|
||||
|
||||
usb_dc_cfg.ep_out[0].actual_xfer_len += read_count;
|
||||
usb_dc_cfg.ep_out[0].xfer_len -= read_count;
|
||||
usbd_event_ep_out_complete_handler(0x00, usb_dc_cfg.ep_out[0].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, 0x00, usb_dc_cfg.ep_out[0].actual_xfer_len);
|
||||
if (read_count == 0) {
|
||||
/*!< Out status, start reading setup */
|
||||
EPn_SET_RX_VALID(0);
|
||||
@@ -556,7 +562,7 @@ USBD_IRQHandler(void)
|
||||
usb_dc_cfg.ep_out[epid].xfer_len -= read_count;
|
||||
|
||||
if ((read_count < usb_dc_cfg.ep_out[epid].mps) || (usb_dc_cfg.ep_out[epid].xfer_len == 0)) {
|
||||
usbd_event_ep_out_complete_handler(((epid)&0x7f), usb_dc_cfg.ep_out[epid].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ((epid)&0x7f), usb_dc_cfg.ep_out[epid].actual_xfer_len);
|
||||
} else {
|
||||
if (usb_dc_cfg.ep_out[epid].eptype != USB_ENDPOINT_TYPE_ISOCHRONOUS) {
|
||||
EPn_SET_RX_VALID(epid);
|
||||
@@ -596,13 +602,13 @@ USBD_IRQHandler(void)
|
||||
EPn_SET_TX_VALID(0);
|
||||
}
|
||||
EPn_SET_RX_NAK(0);
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)&(usb_dc_cfg.setup));
|
||||
usbd_event_ep0_setup_complete_handler(0, (uint8_t *)&(usb_dc_cfg.setup));
|
||||
CH58x_USBFS_DEV->USB_INT_FG = RB_UIF_TRANSFER;
|
||||
}
|
||||
} else if (intflag & RB_UIF_BUS_RST) {
|
||||
/*!< Reset */
|
||||
CH58x_USBFS_DEV->USB_DEV_AD = 0;
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
/*!< Set ep0 rx vaild to start receive setup packet */
|
||||
EPn_SET_RX_VALID(0);
|
||||
CH58x_USBFS_DEV->USB_INT_FG = RB_UIF_BUS_RST;
|
||||
|
||||
@@ -54,7 +54,7 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_init();
|
||||
|
||||
@@ -82,12 +82,12 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
if (addr == 0) {
|
||||
USBFS_DEVICE->DEV_ADDR = (USBFS_DEVICE->DEV_ADDR & USBFS_UDA_GP_BIT) | 0;
|
||||
@@ -96,12 +96,12 @@ int usbd_set_address(const uint8_t addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
return USB_SPEED_FULL;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
|
||||
@@ -118,11 +118,11 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -147,7 +147,7 @@ int usbd_ep_set_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -163,12 +163,12 @@ int usbd_ep_clear_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -215,7 +215,7 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -265,7 +265,7 @@ void USBD_IRQHandler(void)
|
||||
switch (token) {
|
||||
case USBFS_UIS_TOKEN_SETUP:
|
||||
USB_SET_RX_CTRL(ep_idx, USBFS_UEP_R_RES_NAK);
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)&g_ch32_usbfs_udc.setup);
|
||||
usbd_event_ep0_setup_complete_handler(0, (uint8_t *)&g_ch32_usbfs_udc.setup);
|
||||
break;
|
||||
|
||||
case USBFS_UIS_TOKEN_IN:
|
||||
@@ -280,7 +280,7 @@ void USBD_IRQHandler(void)
|
||||
ep0_tx_data_toggle = true;
|
||||
}
|
||||
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_ch32_usbfs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_ch32_usbfs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
|
||||
if (g_ch32_usbfs_udc.dev_addr > 0) {
|
||||
USBFS_DEVICE->DEV_ADDR = (USBFS_DEVICE->DEV_ADDR & USBFS_UDA_GP_BIT) | g_ch32_usbfs_udc.dev_addr;
|
||||
@@ -315,7 +315,7 @@ void USBD_IRQHandler(void)
|
||||
} else {
|
||||
g_ch32_usbfs_udc.in_ep[ep_idx].actual_xfer_len += g_ch32_usbfs_udc.in_ep[ep_idx].xfer_len;
|
||||
g_ch32_usbfs_udc.in_ep[ep_idx].xfer_len = 0;
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_ch32_usbfs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_ch32_usbfs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -328,7 +328,7 @@ void USBD_IRQHandler(void)
|
||||
g_ch32_usbfs_udc.out_ep[ep_idx].actual_xfer_len += read_count;
|
||||
g_ch32_usbfs_udc.out_ep[ep_idx].xfer_len -= read_count;
|
||||
|
||||
usbd_event_ep_out_complete_handler(0x00, g_ch32_usbfs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, 0x00, g_ch32_usbfs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
|
||||
if (read_count == 0) {
|
||||
/* Out status, start reading setup */
|
||||
@@ -351,7 +351,7 @@ void USBD_IRQHandler(void)
|
||||
g_ch32_usbfs_udc.out_ep[ep_idx].xfer_len -= read_count;
|
||||
|
||||
if ((read_count < g_ch32_usbfs_udc.out_ep[ep_idx].ep_mps) || (g_ch32_usbfs_udc.out_ep[ep_idx].xfer_len == 0)) {
|
||||
usbd_event_ep_out_complete_handler(ep_idx, g_ch32_usbfs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ep_idx, g_ch32_usbfs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
USB_SET_RX_CTRL(ep_idx, (USB_GET_RX_CTRL(ep_idx) & ~USBFS_UEP_R_RES_MASK) | USBFS_UEP_R_RES_ACK);
|
||||
}
|
||||
@@ -383,7 +383,7 @@ void USBD_IRQHandler(void)
|
||||
ep0_rx_data_toggle = true;
|
||||
|
||||
memset(&g_ch32_usbfs_udc, 0, sizeof(struct ch32_usbfs_udc));
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
USB_SET_DMA(ep_idx, (uint32_t)&g_ch32_usbfs_udc.setup);
|
||||
USB_SET_RX_CTRL(ep_idx, USBFS_UEP_R_RES_ACK);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_init();
|
||||
|
||||
@@ -82,12 +82,12 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
if (addr == 0) {
|
||||
USBHS_DEVICE->DEV_AD = addr & 0xff;
|
||||
@@ -96,12 +96,12 @@ int usbd_set_address(const uint8_t addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
return USB_SPEED_HIGH;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
|
||||
@@ -122,12 +122,12 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -148,7 +148,7 @@ int usbd_ep_set_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -160,12 +160,12 @@ int usbd_ep_clear_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint32_t tmp;
|
||||
@@ -211,7 +211,7 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -268,7 +268,7 @@ void USBD_IRQHandler(void)
|
||||
ep0_tx_data_toggle = true;
|
||||
}
|
||||
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_ch32_usbhs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_ch32_usbhs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
|
||||
if (g_ch32_usbhs_udc.dev_addr > 0) {
|
||||
USBHS_DEVICE->DEV_AD = g_ch32_usbhs_udc.dev_addr & 0xff;
|
||||
@@ -309,7 +309,7 @@ void USBD_IRQHandler(void)
|
||||
g_ch32_usbhs_udc.in_ep[ep_idx].actual_xfer_len += g_ch32_usbhs_udc.in_ep[ep_idx].xfer_len;
|
||||
g_ch32_usbhs_udc.in_ep[ep_idx].xfer_len = 0;
|
||||
epx_tx_data_toggle[ep_idx - 1] ^= 1;
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_ch32_usbhs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_ch32_usbhs_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
}
|
||||
}
|
||||
} else if (token == PID_OUT) {
|
||||
@@ -319,7 +319,7 @@ void USBD_IRQHandler(void)
|
||||
g_ch32_usbhs_udc.out_ep[ep_idx].actual_xfer_len += read_count;
|
||||
g_ch32_usbhs_udc.out_ep[ep_idx].xfer_len -= read_count;
|
||||
|
||||
usbd_event_ep_out_complete_handler(0x00, g_ch32_usbhs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, 0x00, g_ch32_usbhs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
|
||||
if (read_count == 0) {
|
||||
/* Out status, start reading setup */
|
||||
@@ -340,7 +340,7 @@ void USBD_IRQHandler(void)
|
||||
g_ch32_usbhs_udc.out_ep[ep_idx].xfer_len -= read_count;
|
||||
|
||||
if ((read_count < g_ch32_usbhs_udc.out_ep[ep_idx].ep_mps) || (g_ch32_usbhs_udc.out_ep[ep_idx].xfer_len == 0)) {
|
||||
usbd_event_ep_out_complete_handler(ep_idx, g_ch32_usbhs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ep_idx, g_ch32_usbhs_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
USB_SET_RX_DMA(ep_idx, (uint32_t)g_ch32_usbhs_udc.out_ep[ep_idx].xfer_buf);
|
||||
USB_SET_RX_CTRL(ep_idx, (USB_GET_RX_CTRL(ep_idx) & ~USBHS_EP_R_RES_MASK) | USBHS_EP_R_RES_ACK);
|
||||
@@ -350,7 +350,7 @@ void USBD_IRQHandler(void)
|
||||
}
|
||||
USBHS_DEVICE->INT_FG = USBHS_TRANSFER_FLAG;
|
||||
} else if (intflag & USBHS_SETUP_FLAG) {
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)&g_ch32_usbhs_udc.setup);
|
||||
usbd_event_ep0_setup_complete_handler(0, (uint8_t *)&g_ch32_usbhs_udc.setup);
|
||||
USBHS_DEVICE->INT_FG = USBHS_SETUP_FLAG;
|
||||
} else if (intflag & USBHS_DETECT_FLAG) {
|
||||
USBHS_DEVICE->ENDP_CONFIG = USBHS_EP0_T_EN | USBHS_EP0_R_EN;
|
||||
@@ -369,7 +369,7 @@ void USBD_IRQHandler(void)
|
||||
}
|
||||
|
||||
memset(&g_ch32_usbhs_udc, 0, sizeof(struct ch32_usbhs_udc));
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
USBHS_DEVICE->UEP0_DMA = (uint32_t)&g_ch32_usbhs_udc.setup;
|
||||
USBHS_DEVICE->UEP0_RX_CTRL = USBHS_EP_R_RES_ACK;
|
||||
USBHS_DEVICE->INT_FG = USBHS_DETECT_FLAG;
|
||||
|
||||
@@ -29,10 +29,3 @@
|
||||
## Espressif
|
||||
|
||||
- ESP32S2、ESP32S3
|
||||
|
||||
## Before Use
|
||||
|
||||
Your should implement `usb_dc_low_level_init` and `usb_dc_low_level_deinit`.
|
||||
- Enable or disable USB clock and set USB clock for 48M.
|
||||
- Enable or disable gpio and gpio clk for usb dp and dm.
|
||||
- Enable or disable usb irq
|
||||
@@ -515,7 +515,7 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
int ret;
|
||||
uint8_t fsphy_type;
|
||||
@@ -676,7 +676,7 @@ int usb_dc_init(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
/* Clear Pending interrupt */
|
||||
for (uint8_t i = 0U; i < 15U; i++) {
|
||||
@@ -699,14 +699,14 @@ int usb_dc_deinit(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
USB_OTG_DEV->DCFG &= ~(USB_OTG_DCFG_DAD);
|
||||
USB_OTG_DEV->DCFG |= ((uint32_t)addr << 4) & USB_OTG_DCFG_DAD;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
uint8_t speed;
|
||||
uint32_t DevEnumSpeed = USB_OTG_DEV->DSTS & USB_OTG_DSTS_ENUMSPD;
|
||||
@@ -723,7 +723,7 @@ uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
return speed;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
|
||||
@@ -761,7 +761,7 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
volatile uint32_t count = 0U;
|
||||
@@ -810,7 +810,7 @@ int usbd_ep_close(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -833,7 +833,7 @@ int usbd_ep_set_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -853,7 +853,7 @@ int usbd_ep_clear_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
} else {
|
||||
@@ -861,7 +861,7 @@ int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint32_t pktcnt = 0;
|
||||
@@ -934,7 +934,7 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint32_t pktcnt = 0;
|
||||
@@ -1048,17 +1048,17 @@ void USBD_IRQHandler(void)
|
||||
} else {
|
||||
g_dwc2_udc.out_ep[ep_idx].actual_xfer_len = g_dwc2_udc.out_ep[ep_idx].xfer_len - ((USB_OTG_OUTEP(ep_idx)->DOEPTSIZ) & USB_OTG_DOEPTSIZ_XFRSIZ);
|
||||
g_dwc2_udc.out_ep[ep_idx].xfer_len = 0;
|
||||
usbd_event_ep_out_complete_handler(0x00, g_dwc2_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, 0x00, g_dwc2_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
}
|
||||
} else {
|
||||
g_dwc2_udc.out_ep[ep_idx].actual_xfer_len = g_dwc2_udc.out_ep[ep_idx].xfer_len - ((USB_OTG_OUTEP(ep_idx)->DOEPTSIZ) & USB_OTG_DOEPTSIZ_XFRSIZ);
|
||||
g_dwc2_udc.out_ep[ep_idx].xfer_len = 0;
|
||||
usbd_event_ep_out_complete_handler(ep_idx, g_dwc2_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ep_idx, g_dwc2_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
}
|
||||
}
|
||||
|
||||
if ((epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP) {
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)&g_dwc2_udc.setup);
|
||||
usbd_event_ep0_setup_complete_handler(0, (uint8_t *)&g_dwc2_udc.setup);
|
||||
}
|
||||
}
|
||||
ep_intr >>= 1U;
|
||||
@@ -1078,7 +1078,7 @@ void USBD_IRQHandler(void)
|
||||
if (ep_idx == 0) {
|
||||
g_dwc2_udc.in_ep[ep_idx].actual_xfer_len = g_dwc2_udc.in_ep[ep_idx].xfer_len - ((USB_OTG_INEP(ep_idx)->DIEPTSIZ) & USB_OTG_DIEPTSIZ_XFRSIZ);
|
||||
g_dwc2_udc.in_ep[ep_idx].xfer_len = 0;
|
||||
usbd_event_ep_in_complete_handler(0x80, g_dwc2_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, 0x80, g_dwc2_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
|
||||
if (g_dwc2_udc.setup.wLength && ((g_dwc2_udc.setup.bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_OUT)) {
|
||||
/* In status, start reading setup */
|
||||
@@ -1090,7 +1090,7 @@ void USBD_IRQHandler(void)
|
||||
} else {
|
||||
g_dwc2_udc.in_ep[ep_idx].actual_xfer_len = g_dwc2_udc.in_ep[ep_idx].xfer_len - ((USB_OTG_INEP(ep_idx)->DIEPTSIZ) & USB_OTG_DIEPTSIZ_XFRSIZ);
|
||||
g_dwc2_udc.in_ep[ep_idx].xfer_len = 0;
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_dwc2_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_dwc2_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
}
|
||||
}
|
||||
if ((epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE) {
|
||||
@@ -1138,7 +1138,7 @@ void USBD_IRQHandler(void)
|
||||
USB_OTG_DEV->DIEPMSK = USB_OTG_DIEPMSK_XFRCM;
|
||||
|
||||
memset(&g_dwc2_udc, 0, sizeof(struct dwc2_udc));
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
/* Start reading setup */
|
||||
dwc2_ep0_start_read_setup((uint8_t *)&g_dwc2_udc.setup);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,4 @@
|
||||
|
||||
### Intel
|
||||
|
||||
Intel 6 Series Chipset and Intel C200 Series Chipset
|
||||
|
||||
## Before Use
|
||||
|
||||
Your should implement `usb_hc_low_level_init`.
|
||||
- Enable USB PHY、USB clock and set USB clock for 48M.
|
||||
- Enable usb irq
|
||||
- Config EHCI BASE and other macros in `cherryusb_config_tempate.h`
|
||||
- Intel 6 Series Chipset and Intel C200 Series Chipset
|
||||
|
||||
@@ -31,11 +31,3 @@
|
||||
## CH32
|
||||
|
||||
- CH32F10x、CH32V10x
|
||||
|
||||
|
||||
## Before Use
|
||||
|
||||
Your should implement `usb_dc_low_level_init` and `usb_dc_low_level_deinit`.
|
||||
- Enable or disable USB clock and set USB clock for 48M.
|
||||
- Enable or disable gpio and gpio clk for usb dp and dm.
|
||||
- Enable or disable usb irq
|
||||
@@ -60,7 +60,7 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_init();
|
||||
|
||||
@@ -94,7 +94,7 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
/* disable all interrupts and force USB reset */
|
||||
USB->CNTR = (uint16_t)USB_CNTR_FRES;
|
||||
@@ -109,7 +109,7 @@ int usb_dc_deinit(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
if (addr == 0U) {
|
||||
/* set device address and enable function */
|
||||
@@ -120,12 +120,12 @@ int usbd_set_address(const uint8_t addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
return USB_SPEED_FULL;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
|
||||
@@ -207,7 +207,7 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -225,7 +225,7 @@ int usbd_ep_close(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -237,7 +237,7 @@ int usbd_ep_set_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -256,7 +256,7 @@ int usbd_ep_clear_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
if (USB_EP_DIR_IS_OUT(ep)) {
|
||||
} else {
|
||||
@@ -264,7 +264,7 @@ int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -289,7 +289,7 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -335,14 +335,14 @@ void USBD_IRQHandler(void)
|
||||
g_fsdev_udc.in_ep[ep_idx].xfer_len -= write_count;
|
||||
g_fsdev_udc.in_ep[ep_idx].actual_xfer_len += write_count;
|
||||
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_fsdev_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_fsdev_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
|
||||
if (g_fsdev_udc.setup.wLength == 0) {
|
||||
/* In status, start reading setup */
|
||||
usbd_ep_start_read(0x00, NULL, 0);
|
||||
usbd_ep_start_read(0, 0x00, NULL, 0);
|
||||
} else if (g_fsdev_udc.setup.wLength && ((g_fsdev_udc.setup.bmRequestType & USB_REQUEST_DIR_MASK) == USB_REQUEST_DIR_OUT)) {
|
||||
/* In status, start reading setup */
|
||||
usbd_ep_start_read(0x00, NULL, 0);
|
||||
usbd_ep_start_read(0, 0x00, NULL, 0);
|
||||
}
|
||||
|
||||
if ((g_fsdev_udc.dev_addr > 0U) && (write_count == 0U)) {
|
||||
@@ -359,7 +359,7 @@ void USBD_IRQHandler(void)
|
||||
read_count = PCD_GET_EP_RX_CNT(USB, ep_idx);
|
||||
fsdev_read_pma(USB, (uint8_t *)&g_fsdev_udc.setup, g_fsdev_udc.out_ep[ep_idx].ep_pma_addr, (uint16_t)read_count);
|
||||
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)&g_fsdev_udc.setup);
|
||||
usbd_event_ep0_setup_complete_handler(0, (uint8_t *)&g_fsdev_udc.setup);
|
||||
|
||||
} else if ((wEPVal & USB_EP_CTR_RX) != 0U) {
|
||||
PCD_CLEAR_RX_EP_CTR(USB, ep_idx);
|
||||
@@ -372,11 +372,11 @@ void USBD_IRQHandler(void)
|
||||
g_fsdev_udc.out_ep[ep_idx].xfer_len -= read_count;
|
||||
g_fsdev_udc.out_ep[ep_idx].actual_xfer_len += read_count;
|
||||
|
||||
usbd_event_ep_out_complete_handler(ep_idx, g_fsdev_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ep_idx, g_fsdev_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
|
||||
if (read_count == 0) {
|
||||
/* Out status, start reading setup */
|
||||
usbd_ep_start_read(0x00, NULL, 0);
|
||||
usbd_ep_start_read(0, 0x00, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,7 +393,7 @@ void USBD_IRQHandler(void)
|
||||
|
||||
if ((read_count < g_fsdev_udc.out_ep[ep_idx].ep_mps) ||
|
||||
(g_fsdev_udc.out_ep[ep_idx].xfer_len == 0)) {
|
||||
usbd_event_ep_out_complete_handler(ep_idx, g_fsdev_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ep_idx, g_fsdev_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
PCD_SET_EP_RX_STATUS(USB, ep_idx, USB_EP_RX_VALID);
|
||||
}
|
||||
@@ -408,7 +408,7 @@ void USBD_IRQHandler(void)
|
||||
g_fsdev_udc.in_ep[ep_idx].actual_xfer_len += write_count;
|
||||
|
||||
if (g_fsdev_udc.in_ep[ep_idx].xfer_len == 0) {
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_fsdev_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_fsdev_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
write_count = MIN(g_fsdev_udc.in_ep[ep_idx].xfer_len, g_fsdev_udc.in_ep[ep_idx].ep_mps);
|
||||
fsdev_write_pma(USB, g_fsdev_udc.in_ep[ep_idx].xfer_buf, g_fsdev_udc.in_ep[ep_idx].ep_pma_addr, (uint16_t)write_count);
|
||||
@@ -422,7 +422,7 @@ void USBD_IRQHandler(void)
|
||||
if (wIstr & USB_ISTR_RESET) {
|
||||
memset(&g_fsdev_udc, 0, sizeof(struct fsdev_udc));
|
||||
g_fsdev_udc.pma_offset = USB_BTABLE_SIZE;
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
/* start reading setup packet */
|
||||
PCD_SET_EP_RX_STATUS(USB, 0, USB_EP_RX_VALID);
|
||||
USB->ISTR &= (uint16_t)(~USB_ISTR_RESET);
|
||||
|
||||
@@ -2,18 +2,10 @@
|
||||
#include "hpm_usb_device.h"
|
||||
#include "board.h"
|
||||
|
||||
#ifndef USBD_IRQHandler
|
||||
#define USBD_IRQHandler USBD_IRQHandler // use actual usb irq name instead
|
||||
#endif
|
||||
|
||||
#ifndef USB_NUM_BIDIR_ENDPOINTS
|
||||
#define USB_NUM_BIDIR_ENDPOINTS USB_SOC_DCD_MAX_ENDPOINT_COUNT
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_HPM_USBD_BASE) || !defined(CONFIG_HPM_USBD_IRQn)
|
||||
#error "hpm dcd must config CONFIG_HPM_USBD_BASE and CONFIG_HPM_USBD_IRQn"
|
||||
#endif
|
||||
|
||||
/* USBSTS, USBINTR */
|
||||
enum {
|
||||
intr_usb = HPM_BITSMASK(1, 0),
|
||||
@@ -41,66 +33,86 @@ struct hpm_udc {
|
||||
usb_device_handle_t *handle;
|
||||
struct hpm_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/
|
||||
struct hpm_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */
|
||||
} g_hpm_udc;
|
||||
} g_hpm_udc[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
static ATTR_PLACE_AT_NONCACHEABLE_WITH_ALIGNMENT(USB_SOC_DCD_DATA_RAM_ADDRESS_ALIGNMENT) dcd_data_t _dcd_data;
|
||||
static ATTR_PLACE_AT_NONCACHEABLE_WITH_ALIGNMENT(USB_SOC_DCD_DATA_RAM_ADDRESS_ALIGNMENT) dcd_data_t _dcd_data[USB_SOC_MAX_COUNT];
|
||||
static ATTR_PLACE_AT_NONCACHEABLE usb_device_handle_t usb_device_handle[USB_SOC_MAX_COUNT];
|
||||
|
||||
/*---------------------------------------------------------------------*
|
||||
* Macro Typedef Declaration
|
||||
*---------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
USB_Type* regs; /* register base*/
|
||||
const uint32_t irqnum; /* IRQ number */
|
||||
const uint8_t ep_count; /* Max bi-directional Endpoints */
|
||||
} dcd_controller_t;
|
||||
|
||||
/*---------------------------------------------------------------------*
|
||||
* Variable Definitions
|
||||
*---------------------------------------------------------------------*/
|
||||
static const dcd_controller_t _dcd_controller[] =
|
||||
{
|
||||
{ .regs = (USB_Type*) HPM_USB0_BASE, .irqnum = IRQn_USB0, .ep_count = USB_SOC_DCD_MAX_ENDPOINT_COUNT },
|
||||
#ifdef HPM_USB1_BASE
|
||||
{ .regs = (USB_Type*) HPM_USB1_BASE, .irqnum = IRQn_USB1, .ep_count = USB_SOC_DCD_MAX_ENDPOINT_COUNT }
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Index to bit position in register */
|
||||
static inline uint8_t ep_idx2bit(uint8_t ep_idx)
|
||||
{
|
||||
return ep_idx / 2 + ((ep_idx % 2) ? 16 : 0);
|
||||
}
|
||||
|
||||
__WEAK void usb_dc_low_level_init(void)
|
||||
__WEAK void usb_dc_low_level_init(uint8_t busid)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usb_dc_low_level_deinit(void)
|
||||
__WEAK void usb_dc_low_level_deinit(uint8_t busid)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_init();
|
||||
usb_dc_low_level_init(busid);
|
||||
|
||||
memset(&g_hpm_udc, 0, sizeof(struct hpm_udc));
|
||||
g_hpm_udc.handle = &usb_device_handle[0];
|
||||
g_hpm_udc.handle->regs = (USB_Type *)CONFIG_HPM_USBD_BASE;
|
||||
g_hpm_udc.handle->dcd_data = &_dcd_data;
|
||||
memset(&g_hpm_udc[busid], 0, sizeof(struct hpm_udc));
|
||||
g_hpm_udc[busid].handle = &usb_device_handle[busid];
|
||||
g_hpm_udc[busid].handle->regs = _dcd_controller[busid].regs;
|
||||
g_hpm_udc[busid].handle->dcd_data = &_dcd_data[busid];
|
||||
|
||||
uint32_t int_mask;
|
||||
int_mask = (USB_USBINTR_UE_MASK | USB_USBINTR_UEE_MASK |
|
||||
USB_USBINTR_PCE_MASK | USB_USBINTR_URE_MASK);
|
||||
|
||||
usb_device_init(g_hpm_udc.handle, int_mask);
|
||||
usb_device_init(g_hpm_udc[busid].handle, int_mask);
|
||||
|
||||
intc_m_enable_irq(CONFIG_HPM_USBD_IRQn);
|
||||
intc_m_enable_irq(_dcd_controller[busid].irqnum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
intc_m_disable_irq(CONFIG_HPM_USBD_IRQn);
|
||||
intc_m_disable_irq(_dcd_controller[busid].irqnum);
|
||||
|
||||
usb_device_deinit(g_hpm_udc.handle);
|
||||
usb_device_deinit(g_hpm_udc[busid].handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
usb_dcd_set_address(handle->regs, addr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
(void)port;
|
||||
uint8_t speed;
|
||||
|
||||
speed = usb_get_port_speed(g_hpm_udc.handle->regs);
|
||||
speed = usb_get_port_speed(g_hpm_udc[busid].handle->regs);
|
||||
|
||||
if (speed == 0x00) {
|
||||
return USB_SPEED_FULL;
|
||||
@@ -115,21 +127,21 @@ uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
usb_endpoint_config_t tmp_ep_cfg;
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(ep->bEndpointAddress)) {
|
||||
g_hpm_udc.out_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
g_hpm_udc.out_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
g_hpm_udc.out_ep[ep_idx].ep_enable = true;
|
||||
g_hpm_udc[busid].out_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
g_hpm_udc[busid].out_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
g_hpm_udc[busid].out_ep[ep_idx].ep_enable = true;
|
||||
} else {
|
||||
g_hpm_udc.in_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
g_hpm_udc.in_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
g_hpm_udc.in_ep[ep_idx].ep_enable = true;
|
||||
g_hpm_udc[busid].in_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
|
||||
g_hpm_udc[busid].in_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
g_hpm_udc[busid].in_ep[ep_idx].ep_enable = true;
|
||||
}
|
||||
|
||||
tmp_ep_cfg.xfer = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
|
||||
@@ -140,84 +152,84 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
|
||||
usb_device_edpt_close(handle, ep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
|
||||
usb_device_edpt_stall(handle, ep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
|
||||
usb_device_edpt_clear_stall(handle, ep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
|
||||
*stalled = usb_device_edpt_check_stall(handle, ep);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!g_hpm_udc.in_ep[ep_idx].ep_enable) {
|
||||
if (!g_hpm_udc[busid].in_ep[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
g_hpm_udc.in_ep[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
g_hpm_udc.in_ep[ep_idx].xfer_len = data_len;
|
||||
g_hpm_udc.in_ep[ep_idx].actual_xfer_len = 0;
|
||||
g_hpm_udc[busid].in_ep[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
g_hpm_udc[busid].in_ep[ep_idx].xfer_len = data_len;
|
||||
g_hpm_udc[busid].in_ep[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
usb_device_edpt_xfer(handle, ep, (uint8_t *)data, data_len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
|
||||
if (!data && data_len) {
|
||||
return -1;
|
||||
}
|
||||
if (!g_hpm_udc.out_ep[ep_idx].ep_enable) {
|
||||
if (!g_hpm_udc[busid].out_ep[ep_idx].ep_enable) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
g_hpm_udc.out_ep[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
g_hpm_udc.out_ep[ep_idx].xfer_len = data_len;
|
||||
g_hpm_udc.out_ep[ep_idx].actual_xfer_len = 0;
|
||||
g_hpm_udc[busid].out_ep[ep_idx].xfer_buf = (uint8_t *)data;
|
||||
g_hpm_udc[busid].out_ep[ep_idx].xfer_len = data_len;
|
||||
g_hpm_udc[busid].out_ep[ep_idx].actual_xfer_len = 0;
|
||||
|
||||
usb_device_edpt_xfer(handle, ep, data, data_len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(void)
|
||||
void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint32_t int_status;
|
||||
usb_device_handle_t *handle = g_hpm_udc.handle;
|
||||
usb_device_handle_t *handle = g_hpm_udc[busid].handle;
|
||||
uint32_t transfer_len = 0;
|
||||
|
||||
/* Acknowledge handled interrupt */
|
||||
@@ -231,9 +243,9 @@ void USBD_IRQHandler(void)
|
||||
}
|
||||
|
||||
if (int_status & intr_reset) {
|
||||
memset(g_hpm_udc.in_ep, 0, sizeof(struct hpm_ep_state) * USB_NUM_BIDIR_ENDPOINTS);
|
||||
memset(g_hpm_udc.out_ep, 0, sizeof(struct hpm_ep_state) * USB_NUM_BIDIR_ENDPOINTS);
|
||||
usbd_event_reset_handler();
|
||||
memset(g_hpm_udc[busid].in_ep, 0, sizeof(struct hpm_ep_state) * USB_NUM_BIDIR_ENDPOINTS);
|
||||
memset(g_hpm_udc[busid].out_ep, 0, sizeof(struct hpm_ep_state) * USB_NUM_BIDIR_ENDPOINTS);
|
||||
usbd_event_reset_handler(busid);
|
||||
usb_device_bus_reset(handle, 64);
|
||||
}
|
||||
|
||||
@@ -263,7 +275,7 @@ void USBD_IRQHandler(void)
|
||||
/*------------- Set up Received -------------*/
|
||||
usb_device_clear_setup_status(handle, edpt_setup_status);
|
||||
dcd_qhd_t *qhd0 = usb_device_qhd_get(handle, 0);
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)&qhd0->setup_request);
|
||||
usbd_event_ep0_setup_complete_handler(busid, (uint8_t *)&qhd0->setup_request);
|
||||
}
|
||||
|
||||
if (edpt_complete) {
|
||||
@@ -288,9 +300,9 @@ void USBD_IRQHandler(void)
|
||||
|
||||
uint8_t const ep_addr = (ep_idx / 2) | ((ep_idx & 0x01) ? 0x80 : 0);
|
||||
if (ep_addr & 0x80) {
|
||||
usbd_event_ep_in_complete_handler(ep_addr, transfer_len);
|
||||
usbd_event_ep_in_complete_handler(busid, ep_addr, transfer_len);
|
||||
} else {
|
||||
usbd_event_ep_out_complete_handler(ep_addr, transfer_len);
|
||||
usbd_event_ep_out_complete_handler(busid, ep_addr, transfer_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,8 +310,16 @@ void USBD_IRQHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
void isr_usbd(void)
|
||||
void isr_usbd0(void)
|
||||
{
|
||||
USBD_IRQHandler();
|
||||
USBD_IRQHandler(0);
|
||||
}
|
||||
SDK_DECLARE_EXT_ISR_M(CONFIG_HPM_USBD_IRQn, isr_usbd)
|
||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbd0)
|
||||
|
||||
#ifdef HPM_USB1_BASE
|
||||
void isr_usbd1(void)
|
||||
{
|
||||
USBD_IRQHandler(1);
|
||||
}
|
||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbd1)
|
||||
#endif
|
||||
@@ -16,11 +16,4 @@
|
||||
|
||||
### AllwinnerTech
|
||||
|
||||
- F1Cxxx
|
||||
|
||||
## Before Use
|
||||
|
||||
Your should implement `usb_dc_low_level_init` and `usb_dc_low_level_deinit`.
|
||||
- Enable or disable USB clock and set USB clock for 48M.
|
||||
- Enable or disable gpio and gpio clk for usb dp and dm.
|
||||
- Enable or disable usb irq
|
||||
- F1Cxxx, F2Cxxx
|
||||
|
||||
@@ -221,7 +221,7 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_init();
|
||||
|
||||
@@ -245,12 +245,12 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
if (addr == 0) {
|
||||
HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = 0;
|
||||
@@ -260,7 +260,7 @@ int usbd_set_address(const uint8_t addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
uint8_t speed = USB_SPEED_UNKNOWN;
|
||||
|
||||
@@ -280,7 +280,7 @@ uint8_t usbd_force_full_speed(const uint8_t port)
|
||||
return (HWREGB(USB_BASE + MUSB_POWER_OFFSET) & USB_POWER_HSENAB);
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint16_t used = 0;
|
||||
uint16_t fifo_size = 0;
|
||||
@@ -410,12 +410,12 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint8_t old_ep_idx;
|
||||
@@ -443,7 +443,7 @@ int usbd_ep_set_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint8_t old_ep_idx;
|
||||
@@ -475,7 +475,7 @@ int usbd_ep_clear_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -604,7 +604,7 @@ int usbd_write_packet(uint8_t ep_addr, uint8_t *buffer, uint16_t len)
|
||||
return cnt;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint8_t old_ep_idx;
|
||||
@@ -663,7 +663,7 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint8_t old_ep_idx;
|
||||
@@ -734,7 +734,7 @@ static void handle_ep0(void)
|
||||
HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_RXRDYC | USB_CSRL0_DATAEND);
|
||||
}
|
||||
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)&g_musb_udc.setup);
|
||||
usbd_event_ep0_setup_complete_handler(0, (uint8_t *)&g_musb_udc.setup);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -747,7 +747,7 @@ static void handle_ep0(void)
|
||||
g_musb_udc.in_ep[0].xfer_len = 0;
|
||||
}
|
||||
|
||||
usbd_event_ep_in_complete_handler(0x80, g_musb_udc.in_ep[0].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, 0x80, g_musb_udc.in_ep[0].actual_xfer_len);
|
||||
|
||||
break;
|
||||
case USB_EP0_STATE_OUT_DATA:
|
||||
@@ -759,7 +759,7 @@ static void handle_ep0(void)
|
||||
g_musb_udc.out_ep[0].actual_xfer_len += read_count;
|
||||
|
||||
if (read_count < g_musb_udc.out_ep[0].ep_mps) {
|
||||
usbd_event_ep_out_complete_handler(0x00, g_musb_udc.out_ep[0].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, 0x00, g_musb_udc.out_ep[0].actual_xfer_len);
|
||||
HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_RXRDYC | USB_CSRL0_DATAEND);
|
||||
usb_ep0_state = USB_EP0_STATE_IN_STATUS;
|
||||
} else {
|
||||
@@ -770,7 +770,7 @@ static void handle_ep0(void)
|
||||
case USB_EP0_STATE_IN_STATUS:
|
||||
case USB_EP0_STATE_IN_ZLP:
|
||||
usb_ep0_state = USB_EP0_STATE_SETUP;
|
||||
usbd_event_ep_in_complete_handler(0x80, 0);
|
||||
usbd_event_ep_in_complete_handler(0, 0x80, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -849,7 +849,7 @@ void USBD_IRQHandler(void)
|
||||
|
||||
if (g_musb_udc.in_ep[ep_idx].xfer_len == 0) {
|
||||
HWREGH(USB_BASE + MUSB_TXIE_OFFSET) &= ~(1 << ep_idx);
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_musb_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_musb_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
write_count = MIN(g_musb_udc.in_ep[ep_idx].xfer_len, g_musb_udc.in_ep[ep_idx].ep_mps);
|
||||
|
||||
@@ -880,7 +880,7 @@ void USBD_IRQHandler(void)
|
||||
|
||||
if ((read_count < g_musb_udc.out_ep[ep_idx].ep_mps) || (g_musb_udc.out_ep[ep_idx].xfer_len == 0)) {
|
||||
HWREGH(USB_BASE + MUSB_RXIE_OFFSET) &= ~(1 << ep_idx);
|
||||
usbd_event_ep_out_complete_handler(ep_idx, g_musb_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ep_idx, g_musb_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,3 @@
|
||||
- M032 Series
|
||||
- M480 Series
|
||||
|
||||
## Before Use
|
||||
|
||||
Configure USBD_EPNUM.
|
||||
Your should implement `usb_dc_low_level_init` and `usb_dc_low_level_deinit`.
|
||||
- Enable or disable USB clock and set USB clock for 48M.
|
||||
- Enable or disable gpio and gpio clk for usb dp and dm.
|
||||
- Enable or disable usb irq
|
||||
|
||||
@@ -97,7 +97,7 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
memset(&g_nuvoton_udc, 0, sizeof(g_nuvoton_udc));
|
||||
|
||||
@@ -149,7 +149,7 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
USBD->ATTR = 0x00000040;
|
||||
/* Force SE0 */
|
||||
@@ -158,7 +158,7 @@ int usb_dc_deinit(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
uint8_t usbd_addr = USBD_GET_ADDR();
|
||||
if ((usbd_addr == 0) && (usbd_addr != addr)) {
|
||||
@@ -169,12 +169,12 @@ int usbd_set_address(const uint8_t addr)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t usbd_get_port_speed(const uint8_t port)
|
||||
uint8_t usbd_get_port_speed(uint8_t busid, const uint8_t port)
|
||||
{
|
||||
return USB_SPEED_FULL;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
|
||||
@@ -209,31 +209,31 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
USBD->EP[USBD_EPNUM_FROM_EPADDR(ep)].CFG &= ~USBD_CFG_STATE_Msk; // disable endpoint
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
USBD_SET_EP_STALL(USBD_EPNUM_FROM_EPADDR(ep));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
USBD_CLR_EP_STALL(USBD_EPNUM_FROM_EPADDR(ep));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
*stalled = USBD_GET_EP_STALL(USBD_EPNUM_FROM_EPADDR(ep)) > 0 ? 1 : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -264,7 +264,7 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
@@ -304,11 +304,11 @@ void USBD_IRQHandler(void)
|
||||
if (USBD_IS_ATTACHED()) {
|
||||
/* USB Plug In */
|
||||
USBD_ENABLE_USB();
|
||||
usbd_event_connect_handler();
|
||||
usbd_event_connect_handler(0);
|
||||
} else {
|
||||
/* USB Un-plug */
|
||||
USBD_DISABLE_USB();
|
||||
usbd_event_disconnect_handler();
|
||||
usbd_event_disconnect_handler(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,18 +330,18 @@ void USBD_IRQHandler(void)
|
||||
USBD_SET_ADDR(0ul);
|
||||
g_nuvoton_udc.dev_addr = 0;
|
||||
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
}
|
||||
|
||||
if (bus_state & USBD_STATE_SUSPEND) {
|
||||
/* Enable USB but disable PHY */
|
||||
USBD_DISABLE_PHY();
|
||||
usbd_event_suspend_handler();
|
||||
usbd_event_suspend_handler(0);
|
||||
}
|
||||
if (bus_state & USBD_STATE_RESUME) {
|
||||
/* Enable USB and enable PHY */
|
||||
USBD_ENABLE_USB();
|
||||
usbd_event_resume_handler();
|
||||
usbd_event_resume_handler(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,7 +363,7 @@ void USBD_IRQHandler(void)
|
||||
USBD_STOP_TRANSACTION(EP1);
|
||||
|
||||
usbd_out_toggle[0] = 0;
|
||||
usbd_event_ep0_setup_complete_handler((uint8_t *)(USBD_BUF_BASE));
|
||||
usbd_event_ep0_setup_complete_handler(0, (uint8_t *)(USBD_BUF_BASE));
|
||||
}
|
||||
|
||||
if (int_flag & USBD_INTSTS_EP0) {
|
||||
@@ -416,7 +416,7 @@ void USBD_IRQHandler(void)
|
||||
|
||||
if ((recv_count < g_nuvoton_udc.out_ep[ep_idx].ep_mps) ||
|
||||
(g_nuvoton_udc.out_ep[ep_idx].xfer_len == 0)) {
|
||||
usbd_event_ep_out_complete_handler(ep_idx, g_nuvoton_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_out_complete_handler(0, ep_idx, g_nuvoton_udc.out_ep[ep_idx].actual_xfer_len);
|
||||
} else {
|
||||
if (g_nuvoton_udc.out_ep[ep_idx].xfer_len < g_nuvoton_udc.out_ep[ep_idx].ep_mps) {
|
||||
g_nuvoton_udc.out_ep[ep_idx].mps_xfer_len = g_nuvoton_udc.out_ep[ep_idx].xfer_len;
|
||||
@@ -445,7 +445,7 @@ void USBD_IRQHandler(void)
|
||||
g_nuvoton_udc.in_ep[ep_idx].actual_xfer_len += g_nuvoton_udc.in_ep[ep_idx].xfer_len;
|
||||
g_nuvoton_udc.in_ep[ep_idx].xfer_len = 0;
|
||||
|
||||
usbd_event_ep_in_complete_handler(ep_idx | 0x80, g_nuvoton_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
usbd_event_ep_in_complete_handler(0, ep_idx | 0x80, g_nuvoton_udc.in_ep[ep_idx].actual_xfer_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ static void pusb2_dc_connect_handler(FPUsb2DcController *instance)
|
||||
|
||||
USB_LOG_DBG("%s \n", __func__);
|
||||
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
|
||||
/* update speed and max packet size when connect */
|
||||
g_pusb2_udc.speed = dc_dev->speed;
|
||||
@@ -116,7 +116,7 @@ static uint32_t pusb2_dc_receive_steup_handler(FPUsb2DcController *instance, FUs
|
||||
setup->wLength,
|
||||
setup->wValue);
|
||||
|
||||
usbd_event_ep0_setup_complete_handler((u8 *)setup);
|
||||
usbd_event_ep0_setup_complete_handler(0, (u8 *)setup);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ static void pusb2_dc_prepare_ctrl_config(FPUsb2Config *config)
|
||||
return;
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
memset(&g_pusb2_udc, 0, sizeof(struct pusb2_udc));
|
||||
|
||||
@@ -222,7 +222,7 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
usb_dc_low_level_deinit();
|
||||
|
||||
@@ -230,7 +230,7 @@ int usb_dc_deinit(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
g_pusb2_udc.dev_addr = addr;
|
||||
return 0;
|
||||
@@ -251,7 +251,7 @@ static struct usb_endpoint_descriptor *usbd_get_ep0_desc(const struct usb_endpoi
|
||||
return &ep0_desc;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
struct pusb2_dc_ep_state *ep_state;
|
||||
@@ -283,7 +283,7 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
struct pusb2_dc_ep_state *ep_state;
|
||||
@@ -304,7 +304,7 @@ int usbd_ep_close(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
struct pusb2_dc_ep_state *ep_state;
|
||||
@@ -325,7 +325,7 @@ int usbd_ep_set_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
struct pusb2_dc_ep_state *ep_state;
|
||||
@@ -346,7 +346,7 @@ int usbd_ep_clear_stall(const uint8_t ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
struct pusb2_dc_ep_state *ep_state;
|
||||
@@ -406,9 +406,9 @@ void pusb2_dc_callback_complete(FPUsb2DcEp *priv_ep, FPUsb2DcReq *priv_request)
|
||||
request = priv_request->context;
|
||||
|
||||
if (USB_EP_DIR_IS_OUT(priv_ep->address)) {
|
||||
usbd_event_ep_out_complete_handler(priv_ep->address, priv_request->actual);
|
||||
usbd_event_ep_out_complete_handler(0, priv_ep->address, priv_request->actual);
|
||||
} else {
|
||||
usbd_event_ep_in_complete_handler(priv_ep->address, priv_request->actual);
|
||||
usbd_event_ep_in_complete_handler(0, priv_ep->address, priv_request->actual);
|
||||
}
|
||||
|
||||
request->status = priv_request->status;
|
||||
@@ -458,12 +458,12 @@ int pusb2_dc_ep_read_write(const uint8_t ep, uintptr data, uint32_t data_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
return pusb2_dc_ep_read_write(ep, (uintptr)data, data_len);
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
return pusb2_dc_ep_read_write(ep, (uintptr)data, data_len);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ __WEAK void usb_dc_low_level_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
int usb_dc_init(void)
|
||||
int usb_dc_init(uint8_t busid)
|
||||
{
|
||||
memset(&g_xxx_udc, 0, sizeof(struct xxx_udc));
|
||||
|
||||
@@ -41,17 +41,17 @@ int usb_dc_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usb_dc_deinit(void)
|
||||
int usb_dc_deinit(uint8_t busid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_set_address(const uint8_t addr)
|
||||
int usbd_set_address(uint8_t busid, const uint8_t addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
|
||||
|
||||
@@ -65,27 +65,27 @@ int usbd_ep_open(const struct usb_endpoint_descriptor *ep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_close(const uint8_t ep)
|
||||
int usbd_ep_close(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_set_stall(const uint8_t ep)
|
||||
int usbd_ep_set_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_clear_stall(const uint8_t ep)
|
||||
int usbd_ep_clear_stall(uint8_t busid, const uint8_t ep)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_is_stalled(const uint8_t ep, uint8_t *stalled)
|
||||
int usbd_ep_is_stalled(uint8_t busid, const uint8_t ep, uint8_t *stalled)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_write(uint8_t busid, const uint8_t ep, const uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
uint32_t tmp;
|
||||
@@ -101,7 +101,7 @@ int usbd_ep_start_write(const uint8_t ep, const uint8_t *data, uint32_t data_len
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbd_ep_start_read(const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t data_len)
|
||||
{
|
||||
uint8_t ep_idx = USB_EP_GET_IDX(ep);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user