mirror of
https://github.com/sakumisu/CherryUSB.git
synced 2025-05-09 00:21:44 +08:00
config busid and regbase in usbh_initialize and usbd_initialize
This commit is contained in:
parent
31fa2b99c5
commit
e0551b3e7b
@ -148,8 +148,6 @@
|
||||
|
||||
#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
|
||||
|
||||
/* ================ USB Host Port Configuration ==================*/
|
||||
|
@ -62,9 +62,11 @@ USB_NOCACHE_RAM_SECTION struct usbd_core_priv {
|
||||
struct usbd_tx_rx_msg tx_msg[USB_EP_IN_NUM];
|
||||
struct usbd_tx_rx_msg rx_msg[USB_EP_OUT_NUM];
|
||||
|
||||
void (*event_handler)(uint8_t event);
|
||||
void (*event_handler)(uint8_t busid, uint8_t event);
|
||||
} g_usbd_core[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
struct usbd_bus g_usbdev_bus[CONFIG_USBDEV_MAX_BUS];
|
||||
|
||||
static void usbd_class_event_notify_handler(uint8_t busid, uint8_t event, void *arg);
|
||||
|
||||
static void usbd_print_setup(struct usb_setup_packet *setup)
|
||||
@ -493,9 +495,9 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
case USB_REQUEST_SET_FEATURE:
|
||||
if (value == USB_FEATURE_REMOTE_WAKEUP) {
|
||||
if (setup->bRequest == USB_REQUEST_SET_FEATURE) {
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_SET_REMOTE_WAKEUP);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_SET_REMOTE_WAKEUP);
|
||||
} else {
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_CLR_REMOTE_WAKEUP);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_CLR_REMOTE_WAKEUP);
|
||||
}
|
||||
} else if (value == USB_FEATURE_TEST_MODE) {
|
||||
#ifdef CONFIG_USBDEV_TEST_MODE
|
||||
@ -532,7 +534,7 @@ static bool usbd_std_device_req_handler(uint8_t busid, struct usb_setup_packet *
|
||||
} else {
|
||||
g_usbd_core[busid].configuration = value;
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_CONFIGURED, NULL);
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_CONFIGURED);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_CONFIGURED);
|
||||
}
|
||||
*len = 0;
|
||||
break;
|
||||
@ -952,22 +954,22 @@ static void usbd_class_event_notify_handler(uint8_t busid, uint8_t event, void *
|
||||
|
||||
void usbd_event_connect_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_CONNECTED);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_CONNECTED);
|
||||
}
|
||||
|
||||
void usbd_event_disconnect_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_DISCONNECTED);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_DISCONNECTED);
|
||||
}
|
||||
|
||||
void usbd_event_resume_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_RESUME);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_RESUME);
|
||||
}
|
||||
|
||||
void usbd_event_suspend_handler(uint8_t busid)
|
||||
{
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_SUSPEND);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_SUSPEND);
|
||||
}
|
||||
|
||||
void usbd_event_reset_handler(uint8_t busid)
|
||||
@ -992,7 +994,7 @@ void usbd_event_reset_handler(uint8_t busid)
|
||||
usbd_ep_open(busid, &ep0);
|
||||
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_RESET, NULL);
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_RESET);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_RESET);
|
||||
}
|
||||
|
||||
void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
|
||||
@ -1199,14 +1201,24 @@ bool usb_device_is_configured(uint8_t busid)
|
||||
return g_usbd_core[busid].configuration;
|
||||
}
|
||||
|
||||
int usbd_initialize(uint8_t busid, void (*event_handler)(uint8_t event))
|
||||
int usbd_initialize(uint8_t busid, uint32_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event))
|
||||
{
|
||||
int ret;
|
||||
struct usbd_bus *bus;
|
||||
|
||||
if (busid > CONFIG_USBDEV_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
bus = &g_usbdev_bus[busid];
|
||||
bus->reg_base = reg_base;
|
||||
|
||||
g_usbd_core[busid].event_handler = event_handler;
|
||||
ret = usb_dc_init(busid);
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_INIT, NULL);
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_INIT);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_INIT);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1215,6 +1227,6 @@ int usbd_deinitialize(uint8_t busid)
|
||||
g_usbd_core[busid].intf_offset = 0;
|
||||
usb_dc_deinit(busid);
|
||||
usbd_class_event_notify_handler(busid, USBD_EVENT_DEINIT, NULL);
|
||||
g_usbd_core[busid].event_handler(USBD_EVENT_DEINIT);
|
||||
g_usbd_core[busid].event_handler(busid, USBD_EVENT_DEINIT);
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,6 +74,17 @@ struct usb_descriptor {
|
||||
const struct usb_bos_descriptor *bos_descriptor;
|
||||
};
|
||||
|
||||
struct usbd_bus {
|
||||
uint8_t busid;
|
||||
uint32_t reg_base;
|
||||
};
|
||||
|
||||
extern struct usbd_bus g_usbdev_bus[];
|
||||
|
||||
#ifdef USBD_IRQHandler
|
||||
#error USBD_IRQHandler is obsolete, please call USBD_IRQHandler(xxx) in your irq
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
void usbd_desc_register(uint8_t busid, const struct usb_descriptor *desc);
|
||||
#else
|
||||
@ -87,7 +98,7 @@ 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(uint8_t busid);
|
||||
int usbd_initialize(uint8_t busid, void (*event_handler)(uint8_t event));
|
||||
int usbd_initialize(uint8_t busid, uint32_t reg_base, void (*event_handler)(uint8_t busid, uint8_t event));
|
||||
int usbd_deinitialize(uint8_t busid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -17,6 +17,8 @@ usb_slist_t g_bus_head = USB_SLIST_OBJECT_INIT(g_bus_head);
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t ep0_request_buffer[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_REQUEST_BUFFER_LEN];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX struct usb_setup_packet g_setup_buffer[CONFIG_USBHOST_MAX_BUS][CONFIG_USBHOST_MAX_EXTHUBS + 1][CONFIG_USBHOST_MAX_EHPORTS];
|
||||
|
||||
struct usbh_bus g_usbhost_bus[CONFIG_USBHOST_MAX_BUS];
|
||||
|
||||
/* general descriptor field offsets */
|
||||
#define DESC_bLength 0 /** Length offset */
|
||||
#define DESC_bDescriptorType 1 /** Descriptor type offset */
|
||||
@ -633,24 +635,10 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct usbh_bus *usbh_alloc_bus(uint8_t busid, uint32_t reg_base)
|
||||
static void usbh_bus_init(struct usbh_bus *bus, uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
struct usbh_bus *bus;
|
||||
struct usbh_hub *hub;
|
||||
|
||||
if (busid > CONFIG_USBHOST_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
bus = usb_malloc(sizeof(struct usbh_bus));
|
||||
if (bus == NULL) {
|
||||
USB_LOG_ERR("No memory to alloc bus\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
memset(bus, 0, sizeof(struct usbh_bus));
|
||||
bus->busid = busid;
|
||||
bus->hcd.hcd_id = busid;
|
||||
@ -674,12 +662,22 @@ struct usbh_bus *usbh_alloc_bus(uint8_t busid, uint32_t reg_base)
|
||||
usb_slist_init(&bus->hub_list);
|
||||
usb_slist_add_tail(&bus->hub_list, &hub->list);
|
||||
usb_slist_add_tail(&g_bus_head, &bus->list);
|
||||
|
||||
return bus;
|
||||
}
|
||||
|
||||
int usbh_initialize(struct usbh_bus *bus)
|
||||
int usbh_initialize(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
struct usbh_bus *bus;
|
||||
|
||||
if (busid > CONFIG_USBHOST_MAX_BUS) {
|
||||
USB_LOG_ERR("bus overflow\r\n");
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
|
||||
usbh_bus_init(bus, busid, reg_base);
|
||||
|
||||
#ifdef __ARMCC_VERSION /* ARM C Compiler */
|
||||
extern const int usbh_class_info$$Base;
|
||||
extern const int usbh_class_info$$Limit;
|
||||
@ -698,14 +696,17 @@ int usbh_initialize(struct usbh_bus *bus)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbh_deinitialize(struct usbh_bus *bus)
|
||||
int usbh_deinitialize(uint8_t busid)
|
||||
{
|
||||
struct usbh_bus *bus;
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
|
||||
usbh_hub_deinitialize(bus);
|
||||
|
||||
usb_slist_init(&bus->hub_list);
|
||||
usb_slist_remove(&g_bus_head, &bus->list);
|
||||
|
||||
usb_free(bus);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -216,6 +216,11 @@ static inline void usbh_int_urb_fill(struct usbh_urb *urb,
|
||||
urb->arg = arg;
|
||||
}
|
||||
|
||||
extern struct usbh_bus g_usbhost_bus[];
|
||||
#ifdef USBH_IRQHandler
|
||||
#error USBH_IRQHandler is obsolete, please call USBH_IRQHandler(xxx) in your irq
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Submit an control transfer to an endpoint.
|
||||
* This is a blocking method; this method will not return until the transfer has completed.
|
||||
@ -256,9 +261,8 @@ int usbh_get_string_desc(struct usbh_hubport *hport, uint8_t index, uint8_t *out
|
||||
*/
|
||||
int usbh_set_interface(struct usbh_hubport *hport, uint8_t intf, uint8_t altsetting);
|
||||
|
||||
struct usbh_bus *usbh_alloc_bus(uint8_t busid, uint32_t reg_base);
|
||||
int usbh_initialize(struct usbh_bus *bus);
|
||||
int usbh_deinitialize(struct usbh_bus *bus);
|
||||
int usbh_initialize(uint8_t busid, uint32_t reg_base);
|
||||
int usbh_deinitialize(uint8_t busid);
|
||||
void *usbh_find_class_instance(const char *devname);
|
||||
|
||||
int lsusb(int argc, char **argv);
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -150,7 +148,7 @@ const uint8_t audio_v1_descriptor[] = {
|
||||
volatile bool tx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -207,25 +205,25 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
.ep = AUDIO_IN_EP },
|
||||
};
|
||||
|
||||
void audio_v1_init(void)
|
||||
void audio_v1_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, audio_v1_descriptor);
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0100, audio_entity_table, 1));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[AUDIO_IN_PACKET];
|
||||
|
||||
void audio_test()
|
||||
void audio_test(uint8_t busid)
|
||||
{
|
||||
while (1) {
|
||||
if (tx_flag) {
|
||||
memset(write_buffer, 'a', AUDIO_IN_PACKET);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
usbd_ep_start_write(busid, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
while (ep_tx_busy_flag) {
|
||||
if (tx_flag == false) {
|
||||
break;
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -149,7 +147,7 @@ volatile bool tx_flag = 0;
|
||||
volatile bool rx_flag = 0;
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -179,7 +177,7 @@ 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(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
printf("OPEN1\r\n");
|
||||
} else {
|
||||
tx_flag = 1;
|
||||
@ -201,7 +199,7 @@ void usbd_audio_close(uint8_t busid, uint8_t intf)
|
||||
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(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
void usbd_audio_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -233,24 +231,24 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
.ep = AUDIO_OUT_EP },
|
||||
};
|
||||
|
||||
void audio_v1_init(void)
|
||||
void audio_v1_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, audio_v1_descriptor);
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf2, 0x0100, audio_entity_table, 2));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
usbd_add_endpoint(busid, &audio_out_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v1_test(void)
|
||||
void audio_v1_test(uint8_t busid)
|
||||
{
|
||||
if (tx_flag) {
|
||||
memset(write_buffer, 'a', AUDIO_IN_PACKET);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
usbd_ep_start_write(busid, AUDIO_IN_EP, write_buffer, AUDIO_IN_PACKET);
|
||||
while (ep_tx_busy_flag) {
|
||||
if (tx_flag == false) {
|
||||
break;
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -161,7 +159,7 @@ static const uint8_t mic_default_sampling_freq_table[] = {
|
||||
|
||||
volatile bool tx_flag = 0;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -226,17 +224,17 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
.ep = AUDIO_IN_EP },
|
||||
};
|
||||
|
||||
void audio_v2_init(void)
|
||||
void audio_v2_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, audio_v2_descriptor);
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v2_test(void)
|
||||
void audio_v2_test(uint8_t busid)
|
||||
{
|
||||
if (tx_flag) {
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -231,7 +229,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;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -261,7 +259,7 @@ 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(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
USB_LOG_RAW("OPEN1\r\n");
|
||||
} else {
|
||||
tx_flag = 1;
|
||||
@ -307,7 +305,7 @@ void usbd_audio_set_sampling_freq(uint8_t busid, uint8_t ep, uint32_t sampling_f
|
||||
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(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
void usbd_audio_iso_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -343,19 +341,19 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
.ep = AUDIO_IN_EP },
|
||||
};
|
||||
|
||||
void audio_v2_init(void)
|
||||
void audio_v2_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, audio_v2_descriptor);
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf2, 0x0200, audio_entity_table, 4));
|
||||
usbd_add_endpoint(busid, &audio_in_ep);
|
||||
usbd_add_endpoint(busid, &audio_out_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v2_test(void)
|
||||
void audio_v2_test(uint8_t busid)
|
||||
{
|
||||
if (tx_flag) {
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -175,7 +173,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[AUDIO_OUT_PACKET];
|
||||
|
||||
volatile bool rx_flag = 0;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -204,7 +202,7 @@ void usbd_audio_open(uint8_t busid, uint8_t intf)
|
||||
{
|
||||
rx_flag = 1;
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
USB_LOG_RAW("OPEN\r\n");
|
||||
}
|
||||
|
||||
@ -224,7 +222,7 @@ void usbd_audio_get_sampling_freq_table(uint8_t busid, uint8_t ep, uint8_t **sam
|
||||
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(CONFIG_USBDEV_DEMO_BUS, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
usbd_ep_start_read(busid, AUDIO_OUT_EP, read_buffer, AUDIO_OUT_PACKET);
|
||||
}
|
||||
|
||||
static struct usbd_endpoint audio_out_ep = {
|
||||
@ -244,17 +242,17 @@ struct audio_entity_info audio_entity_table[] = {
|
||||
.ep = AUDIO_OUT_EP },
|
||||
};
|
||||
|
||||
void audio_v2_init(void)
|
||||
void audio_v2_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, audio_v2_descriptor);
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf0, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_interface(busid, usbd_audio_init_intf(busid, &intf1, 0x0200, audio_entity_table, 2));
|
||||
usbd_add_endpoint(busid, &audio_out_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
void audio_v2_test(void)
|
||||
void audio_v2_test(uint8_t busid)
|
||||
{
|
||||
if (rx_flag) {
|
||||
}
|
||||
|
@ -3,8 +3,6 @@
|
||||
#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
|
||||
@ -240,7 +238,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -255,7 +253,7 @@ static void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@ -271,7 +269,7 @@ 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(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -280,7 +278,7 @@ void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(busid, CDC_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@ -302,19 +300,19 @@ struct usbd_interface intf1;
|
||||
struct usbd_interface intf2;
|
||||
struct usbd_interface intf3;
|
||||
|
||||
void cdc_acm_hid_msc_descriptor_init(void)
|
||||
void cdc_acm_hid_msc_descriptor_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, cdc_acm_hid_msc_descriptor);
|
||||
usbd_desc_register(busid, cdc_acm_hid_msc_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_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf0));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf1));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep);
|
||||
usbd_add_endpoint(busid, &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_add_interface(busid, usbd_msc_init_intf(busid, &intf2, MSC_OUT_EP, MSC_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);
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf3, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &hid_in_ep);
|
||||
|
||||
/*!< init mouse report data */
|
||||
mouse_cfg.buttons = 0;
|
||||
@ -322,7 +320,7 @@ void cdc_acm_hid_msc_descriptor_init(void)
|
||||
mouse_cfg.x = 0;
|
||||
mouse_cfg.y = 0;
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -331,12 +329,12 @@ void cdc_acm_hid_msc_descriptor_init(void)
|
||||
* @param[in] none
|
||||
* @retval none
|
||||
*/
|
||||
void hid_mouse_test(void)
|
||||
void hid_mouse_test(uint8_t busid)
|
||||
{
|
||||
/*!< move mouse pointer */
|
||||
mouse_cfg.x += 10;
|
||||
mouse_cfg.y = 0;
|
||||
int ret = usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
@ -356,12 +354,12 @@ void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_acm_data_send_with_dtr_test(void)
|
||||
void cdc_acm_data_send_with_dtr_test(uint8_t busid)
|
||||
{
|
||||
if (dtr_enable) {
|
||||
memset(&write_buffer[10], 'a', 2038);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, write_buffer, 2048);
|
||||
usbd_ep_start_write(busid, CDC_IN_EP, write_buffer, 2048);
|
||||
while (ep_tx_busy_flag) {
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
#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
|
||||
@ -251,7 +249,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -266,7 +264,7 @@ static void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@ -282,7 +280,7 @@ 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(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -291,7 +289,7 @@ void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(busid, CDC_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@ -312,20 +310,20 @@ struct usbd_interface intf0;
|
||||
struct usbd_interface intf1;
|
||||
struct usbd_interface intf2;
|
||||
|
||||
void cdc_acm_msc_init(void)
|
||||
void cdc_acm_msc_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_ADVANCE_DESC
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, &cdc_msc_descriptor);
|
||||
usbd_desc_register(busid, &cdc_msc_descriptor);
|
||||
#else
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, cdc_msc_descriptor);
|
||||
usbd_desc_register(busid, cdc_msc_descriptor);
|
||||
#endif
|
||||
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_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf0));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf1));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep);
|
||||
usbd_add_endpoint(busid, &cdc_in_ep);
|
||||
usbd_add_interface(busid, usbd_msc_init_intf(busid, &intf2, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
volatile uint8_t dtr_enable = 0;
|
||||
@ -339,12 +337,12 @@ void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_acm_data_send_with_dtr_test(void)
|
||||
void cdc_acm_data_send_with_dtr_test(uint8_t busid)
|
||||
{
|
||||
if (dtr_enable) {
|
||||
memset(&write_buffer[10], 'a', 2038);
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, write_buffer, 2048);
|
||||
usbd_ep_start_write(busid, CDC_IN_EP, write_buffer, 2048);
|
||||
while (ep_tx_busy_flag) {
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -127,7 +125,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -142,10 +140,10 @@ static void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
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);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP2, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP3, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP4, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@ -161,7 +159,7 @@ 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(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -225,29 +223,29 @@ struct usbd_interface intf5;
|
||||
struct usbd_interface intf6;
|
||||
struct usbd_interface intf7;
|
||||
|
||||
void cdc_acm_multi_init(void)
|
||||
void cdc_acm_multi_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
usbd_desc_register(CONFIG_USBDEV_DEMO_BUS, cdc_descriptor);
|
||||
usbd_desc_register(busid, 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_ep1);
|
||||
usbd_add_endpoint(CONFIG_USBDEV_DEMO_BUS, &cdc_in_ep1);
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf0));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf1));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep1);
|
||||
usbd_add_endpoint(busid, &cdc_in_ep1);
|
||||
|
||||
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(busid, usbd_cdc_acm_init_intf(busid, &intf2));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf3));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep2);
|
||||
usbd_add_endpoint(busid, &cdc_in_ep2);
|
||||
|
||||
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(busid, usbd_cdc_acm_init_intf(busid, &intf4));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf5));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep3);
|
||||
usbd_add_endpoint(busid, &cdc_in_ep3);
|
||||
|
||||
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_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf6));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf7));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep4);
|
||||
usbd_add_endpoint(busid, &cdc_in_ep4);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -112,7 +110,7 @@ volatile bool ep_tx_busy_flag = false;
|
||||
#define CDC_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -127,7 +125,7 @@ static void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@ -147,7 +145,7 @@ void usbd_cdc_acm_bulk_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
// }
|
||||
// printf("\r\n");
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, CDC_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, CDC_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -156,7 +154,7 @@ void usbd_cdc_acm_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
if ((nbytes % CDC_MAX_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(busid, CDC_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@ -176,19 +174,19 @@ struct usbd_endpoint cdc_in_ep = {
|
||||
static struct usbd_interface intf0;
|
||||
static struct usbd_interface intf1;
|
||||
|
||||
void cdc_acm_init(void)
|
||||
void cdc_acm_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
const uint8_t data[10] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30 };
|
||||
|
||||
memcpy(&write_buffer[0], data, 10);
|
||||
memset(&write_buffer[10], 'a', 2038);
|
||||
|
||||
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);
|
||||
usbd_desc_register(busid, cdc_descriptor);
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf0));
|
||||
usbd_add_interface(busid, usbd_cdc_acm_init_intf(busid, &intf1));
|
||||
usbd_add_endpoint(busid, &cdc_out_ep);
|
||||
usbd_add_endpoint(busid, &cdc_in_ep);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
volatile uint8_t dtr_enable = 0;
|
||||
@ -202,11 +200,11 @@ void usbd_cdc_acm_set_dtr(uint8_t busid, uint8_t intf, bool dtr)
|
||||
}
|
||||
}
|
||||
|
||||
void cdc_acm_data_send_with_dtr_test(void)
|
||||
void cdc_acm_data_send_with_dtr_test(uint8_t busid)
|
||||
{
|
||||
if (dtr_enable) {
|
||||
ep_tx_busy_flag = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, CDC_IN_EP, write_buffer, 2048);
|
||||
usbd_ep_start_write(busid, 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);
|
||||
}
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -263,12 +263,12 @@ struct usbd_interface intf1;
|
||||
* sudo ifconfig enxaabbccddeeff up
|
||||
* sudo dhcpclient enxaabbccddeeff
|
||||
*/
|
||||
void cdc_ecm_init(void)
|
||||
void cdc_ecm_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
cdc_ecm_lwip_init();
|
||||
|
||||
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);
|
||||
usbd_desc_register(busid, cdc_ecm_descriptor);
|
||||
usbd_add_interface(busid, usbd_cdc_ecm_init_intf(&intf0, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_add_interface(busid, usbd_cdc_ecm_init_intf(&intf1, CDC_INT_EP, CDC_OUT_EP, CDC_IN_EP));
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
@ -263,7 +263,7 @@ void rndis_input_poll(void)
|
||||
}
|
||||
#endif /* RT_USING_LWIP */
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -294,15 +294,15 @@ static void usbd_event_handler(uint8_t event)
|
||||
struct usbd_interface intf0;
|
||||
struct usbd_interface intf1;
|
||||
|
||||
void cdc_rndis_init(void)
|
||||
void cdc_rndis_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
#ifdef RT_USING_LWIP
|
||||
rt_usbd_rndis_init();
|
||||
#else
|
||||
rndis_lwip_init();
|
||||
#endif
|
||||
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);
|
||||
usbd_desc_register(busid, cdc_descriptor);
|
||||
usbd_add_interface(busid, usbd_rndis_init_intf(&intf0, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_add_interface(busid, usbd_rndis_init_intf(&intf1, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, mac));
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ const uint8_t dfu_flash_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -164,9 +164,9 @@ static void usbd_event_handler(uint8_t event)
|
||||
|
||||
struct usbd_interface intf0;
|
||||
|
||||
void dfu_flash_init(void)
|
||||
void dfu_flash_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
usbd_desc_register(0, dfu_flash_descriptor);
|
||||
usbd_add_interface(0, usbd_dfu_init_intf(&intf0));
|
||||
usbd_initialize(0, usbd_event_handler);
|
||||
usbd_desc_register(busid, dfu_flash_descriptor);
|
||||
usbd_add_interface(busid, usbd_dfu_init_intf(&intf0));
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -171,7 +169,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;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -186,7 +184,7 @@ static void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, HIDRAW_OUT_EP, read_buffer, HIDRAW_OUT_EP_SIZE);
|
||||
usbd_ep_start_read(busid, HIDRAW_OUT_EP, read_buffer, HIDRAW_OUT_EP_SIZE);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
@ -207,9 +205,9 @@ static void usbd_hid_custom_in_callback(uint8_t busid, uint8_t ep, uint32_t nbyt
|
||||
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(CONFIG_USBDEV_DEMO_BUS, HIDRAW_OUT_EP, read_buffer, 64);
|
||||
usbd_ep_start_read(busid, HIDRAW_OUT_EP, read_buffer, 64);
|
||||
read_buffer[0] = 0x02; /* IN: report id */
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, HIDRAW_IN_EP, read_buffer, nbytes);
|
||||
usbd_ep_start_write(busid, HIDRAW_IN_EP, read_buffer, nbytes);
|
||||
}
|
||||
|
||||
static struct usbd_endpoint custom_in_ep = {
|
||||
@ -231,12 +229,12 @@ static struct usbd_endpoint custom_out_ep = {
|
||||
*/
|
||||
struct usbd_interface intf0;
|
||||
|
||||
void hid_custom_init(void)
|
||||
void hid_custom_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, hid_descriptor);
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf0, hid_custom_report_desc, HID_CUSTOM_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &custom_in_ep);
|
||||
usbd_add_endpoint(busid, &custom_out_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, usbd_event_handler);
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -174,7 +172,7 @@ static const uint8_t hid_keyboard_report_desc[HID_KEYBOARD_REPORT_DESC_SIZE] = {
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -217,23 +215,23 @@ static struct usbd_endpoint hid_in_ep = {
|
||||
|
||||
struct usbd_interface intf0;
|
||||
|
||||
void hid_keyboard_init(void)
|
||||
void hid_keyboard_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, hid_descriptor);
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf0, hid_keyboard_report_desc, HID_KEYBOARD_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &hid_in_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[64];
|
||||
|
||||
void hid_keyboard_test(void)
|
||||
void hid_keyboard_test(uint8_t busid)
|
||||
{
|
||||
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(CONFIG_USBDEV_DEMO_BUS, HID_INT_EP, write_buffer, 8);
|
||||
int ret = usbd_ep_start_write(busid, HID_INT_EP, write_buffer, 8);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#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
|
||||
@ -196,7 +194,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;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -235,13 +233,13 @@ static struct usbd_endpoint hid_in_ep = {
|
||||
|
||||
struct usbd_interface intf0;
|
||||
|
||||
void hid_mouse_init(void)
|
||||
void hid_mouse_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, hid_descriptor);
|
||||
usbd_add_interface(busid, usbd_hid_init_intf(busid, &intf0, hid_mouse_report_desc, HID_MOUSE_REPORT_DESC_SIZE));
|
||||
usbd_add_endpoint(busid, &hid_in_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
|
||||
/*!< init mouse report data */
|
||||
mouse_cfg.buttons = 0;
|
||||
@ -256,7 +254,7 @@ void hid_mouse_init(void)
|
||||
* @param[in] none
|
||||
* @retval none
|
||||
*/
|
||||
void hid_mouse_test(void)
|
||||
void hid_mouse_test(uint8_t busid)
|
||||
{
|
||||
int counter = 0;
|
||||
while (counter < 1000) {
|
||||
@ -264,7 +262,7 @@ void hid_mouse_test(void)
|
||||
mouse_cfg.x += 40;
|
||||
mouse_cfg.y += 0;
|
||||
|
||||
int ret = usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
int ret = usbd_ep_start_write(busid, HID_INT_EP, (uint8_t *)&mouse_cfg, 4);
|
||||
if (ret < 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usb_midi.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define MIDI_OUT_EP 0x02
|
||||
#define MIDI_IN_EP 0x81
|
||||
|
||||
@ -148,7 +146,7 @@ const uint8_t midi_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -194,13 +192,13 @@ struct usbd_endpoint midi_in_ep = {
|
||||
.ep_cb = usbd_midi_bulk_in
|
||||
};
|
||||
|
||||
void midi_init(void)
|
||||
void midi_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, midi_descriptor);
|
||||
usbd_add_interface(busid, &intf0);
|
||||
usbd_add_interface(busid, &intf1);
|
||||
usbd_add_endpoint(busid, &midi_out_ep);
|
||||
usbd_add_endpoint(busid, &midi_in_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define MSC_IN_EP 0x81
|
||||
#define MSC_OUT_EP 0x02
|
||||
|
||||
@ -97,7 +95,7 @@ const uint8_t msc_ram_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -153,10 +151,10 @@ int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *
|
||||
|
||||
struct usbd_interface intf0;
|
||||
|
||||
void msc_ram_init(void)
|
||||
void msc_ram_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, msc_ram_descriptor);
|
||||
usbd_add_interface(busid, usbd_msc_init_intf(busid, &intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_msc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#ifdef __RT_THREAD_H__
|
||||
|
||||
#define MSC_IN_EP 0x81
|
||||
@ -108,7 +106,7 @@ struct usbd_interface intf0;
|
||||
#define BLOCK_COUNT 0x1024U * 0x1024U
|
||||
static rt_device_t blk_dev = RT_NULL;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -151,7 +149,7 @@ int usbd_msc_sector_write(uint8_t busid, uint8_t lun, uint32_t sector, uint8_t *
|
||||
return 0;
|
||||
}
|
||||
|
||||
void msc_storage_init(void)
|
||||
void msc_storage_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
rt_err_t res;
|
||||
|
||||
@ -161,9 +159,9 @@ void msc_storage_init(void)
|
||||
res = rt_device_open(blk_dev, RT_DEVICE_OFLAG_RDWR);
|
||||
RT_ASSERT(res == RT_EOK);
|
||||
|
||||
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_desc_register(busid, msc_storage_descriptor);
|
||||
usbd_add_interface(busid, usbd_msc_init_intf(busid, &intf0, MSC_OUT_EP, MSC_IN_EP));
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
#endif
|
@ -1,193 +0,0 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_mtp.h"
|
||||
|
||||
#define WCID_VENDOR_CODE 0x01
|
||||
|
||||
__ALIGN_BEGIN const uint8_t WCID_StringDescriptor_MSOS[18] __ALIGN_END = {
|
||||
///////////////////////////////////////
|
||||
/// MS OS string descriptor
|
||||
///////////////////////////////////////
|
||||
0x12, /* bLength */
|
||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||
/* MSFT100 */
|
||||
'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00, /* wcChar_7 */
|
||||
'1', 0x00, '0', 0x00, '0', 0x00, /* wcChar_7 */
|
||||
WCID_VENDOR_CODE, /* bVendorCode */
|
||||
0x00, /* bReserved */
|
||||
};
|
||||
|
||||
__ALIGN_BEGIN const uint8_t WINUSB_WCIDDescriptor[40] __ALIGN_END = {
|
||||
///////////////////////////////////////
|
||||
/// WCID descriptor
|
||||
///////////////////////////////////////
|
||||
0x28, 0x00, 0x00, 0x00, /* dwLength */
|
||||
0x00, 0x01, /* bcdVersion */
|
||||
0x04, 0x00, /* wIndex */
|
||||
0x01, /* bCount */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_7 */
|
||||
|
||||
///////////////////////////////////////
|
||||
/// WCID function descriptor
|
||||
///////////////////////////////////////
|
||||
0x00, /* bFirstInterfaceNumber */
|
||||
0x01, /* bReserved */
|
||||
/* MTP */
|
||||
'M', 'T', 'P', 0x00, 0x00, 0x00, 0x00, 0x00, /* cCID_8 */
|
||||
/* */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* cSubCID_8 */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* bReserved_6 */
|
||||
};
|
||||
|
||||
struct usb_msosv1_descriptor msosv1_desc = {
|
||||
.string = (uint8_t *)WCID_StringDescriptor_MSOS,
|
||||
.string_len = 18,
|
||||
.vendor_code = WCID_VENDOR_CODE,
|
||||
.compat_id = (uint8_t *)WINUSB_WCIDDescriptor,
|
||||
.compat_id_len = sizeof(WINUSB_WCIDDescriptor),
|
||||
.comp_id_property = NULL,
|
||||
.comp_id_property_len = 0,
|
||||
};
|
||||
|
||||
/*!< endpoint address */
|
||||
#define CDC_IN_EP 0x81
|
||||
#define CDC_OUT_EP 0x02
|
||||
#define CDC_INT_EP 0x83
|
||||
|
||||
#define USBD_VID 0xFFFE
|
||||
#define USBD_PID 0xFFFF
|
||||
#define USBD_MAX_POWER 100
|
||||
#define USBD_LANGID_STRING 1033
|
||||
|
||||
/*!< config descriptor size */
|
||||
#define USB_CONFIG_SIZE (9 + MTP_DESCRIPTOR_LEN)
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
#define MTP_MAX_MPS 512
|
||||
#else
|
||||
#define MTP_MAX_MPS 64
|
||||
#endif
|
||||
|
||||
const uint8_t mtp_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_1, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0201, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_BUS_POWERED, USBD_MAX_POWER),
|
||||
MTP_DESCRIPTOR_INIT(0x00, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP, MTP_MAX_MPS, 0x02),
|
||||
///////////////////////////////////////
|
||||
/// string0 descriptor
|
||||
///////////////////////////////////////
|
||||
USB_LANGID_INIT(USBD_LANGID_STRING),
|
||||
///////////////////////////////////////
|
||||
/// string1 descriptor
|
||||
///////////////////////////////////////
|
||||
0x14, /* bLength */
|
||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||
'C', 0x00, /* wcChar0 */
|
||||
'h', 0x00, /* wcChar1 */
|
||||
'e', 0x00, /* wcChar2 */
|
||||
'r', 0x00, /* wcChar3 */
|
||||
'r', 0x00, /* wcChar4 */
|
||||
'y', 0x00, /* wcChar5 */
|
||||
'U', 0x00, /* wcChar6 */
|
||||
'S', 0x00, /* wcChar7 */
|
||||
'B', 0x00, /* wcChar8 */
|
||||
///////////////////////////////////////
|
||||
/// string2 descriptor
|
||||
///////////////////////////////////////
|
||||
0x26, /* bLength */
|
||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||
'C', 0x00, /* wcChar0 */
|
||||
'h', 0x00, /* wcChar1 */
|
||||
'e', 0x00, /* wcChar2 */
|
||||
'r', 0x00, /* wcChar3 */
|
||||
'r', 0x00, /* wcChar4 */
|
||||
'y', 0x00, /* wcChar5 */
|
||||
'U', 0x00, /* wcChar6 */
|
||||
'S', 0x00, /* wcChar7 */
|
||||
'B', 0x00, /* wcChar8 */
|
||||
' ', 0x00, /* wcChar9 */
|
||||
'M', 0x00, /* wcChar10 */
|
||||
'T', 0x00, /* wcChar11 */
|
||||
'P', 0x00, /* wcChar12 */
|
||||
' ', 0x00, /* wcChar13 */
|
||||
'D', 0x00, /* wcChar14 */
|
||||
'E', 0x00, /* wcChar15 */
|
||||
'M', 0x00, /* wcChar16 */
|
||||
'O', 0x00, /* wcChar17 */
|
||||
///////////////////////////////////////
|
||||
/// string3 descriptor
|
||||
///////////////////////////////////////
|
||||
0x16, /* bLength */
|
||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||
'2', 0x00, /* wcChar0 */
|
||||
'0', 0x00, /* wcChar1 */
|
||||
'2', 0x00, /* wcChar2 */
|
||||
'1', 0x00, /* wcChar3 */
|
||||
'0', 0x00, /* wcChar4 */
|
||||
'3', 0x00, /* wcChar5 */
|
||||
'1', 0x00, /* wcChar6 */
|
||||
'0', 0x00, /* wcChar7 */
|
||||
'0', 0x00, /* wcChar8 */
|
||||
'0', 0x00, /* wcChar9 */
|
||||
#ifdef CONFIG_USB_HS
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
|
||||
const uint8_t bos_descriptor[] = {
|
||||
0x05, 0x0f, 0x16, 0x00, 0x02,
|
||||
0x07, 0x10, 0x02, 0x06, 0x00, 0x00, 0x00,
|
||||
0x0a, 0x10, 0x03, 0x00, 0x0f, 0x00, 0x01, 0x01, 0xf4, 0x01
|
||||
};
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
break;
|
||||
case USBD_EVENT_CONNECTED:
|
||||
break;
|
||||
case USBD_EVENT_DISCONNECTED:
|
||||
break;
|
||||
case USBD_EVENT_RESUME:
|
||||
break;
|
||||
case USBD_EVENT_SUSPEND:
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
case USBD_EVENT_CLR_REMOTE_WAKEUP:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
struct usbd_interface intf0;
|
||||
|
||||
struct usb_bos_descriptor bos_desc = {
|
||||
.string = bos_descriptor,
|
||||
.string_len = 22
|
||||
};
|
||||
|
||||
void mtp_init(void)
|
||||
{
|
||||
usbd_desc_register(mtp_descriptor);
|
||||
usbd_msosv1_desc_register(&msosv1_desc);
|
||||
usbd_bos_desc_register(&bos_desc);
|
||||
usbd_add_interface(usbd_mtp_init_intf(&intf0, CDC_OUT_EP, CDC_IN_EP, CDC_INT_EP));
|
||||
usbd_initialize();
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usb_printer.h"
|
||||
|
||||
/*!< endpoint address */
|
||||
#define PRINTER_IN_EP 0x81
|
||||
#define PRINTER_IN_EP_SIZE 0x40
|
||||
#define PRINTER_OUT_EP 0x02
|
||||
#define PRINTER_OUT_EP_SIZE 0x40
|
||||
|
||||
#define USBD_VID 0x5A5A
|
||||
#define USBD_PID 0xA5A5
|
||||
#define USBD_MAX_POWER 100
|
||||
#define USBD_LANGID_STRING 0x0409
|
||||
|
||||
/*!< config descriptor size */
|
||||
#define USB_CONFIG_SIZE (32)
|
||||
|
||||
/*!< global descriptor */
|
||||
static const uint8_t printer_descriptor[] = {
|
||||
USB_DEVICE_DESCRIPTOR_INIT(USB_2_0, 0x00, 0x00, 0x00, USBD_VID, USBD_PID, 0x0000, 0x01),
|
||||
USB_CONFIG_DESCRIPTOR_INIT(USB_CONFIG_SIZE, 0x01, 0x01, USB_CONFIG_SELF_POWERED, USBD_MAX_POWER),
|
||||
USB_INTERFACE_DESCRIPTOR_INIT(0x00, 0x00, 0x02, 0x07, 0x01, 0x02, 0x00),
|
||||
USB_ENDPOINT_DESCRIPTOR_INIT(PRINTER_IN_EP, 0x02, PRINTER_IN_EP_SIZE, 0x00),
|
||||
USB_ENDPOINT_DESCRIPTOR_INIT(PRINTER_OUT_EP, 0x02, PRINTER_OUT_EP_SIZE, 0x00),
|
||||
///////////////////////////////////////
|
||||
/// string0 descriptor
|
||||
///////////////////////////////////////
|
||||
USB_LANGID_INIT(USBD_LANGID_STRING),
|
||||
///////////////////////////////////////
|
||||
/// string1 descriptor
|
||||
///////////////////////////////////////
|
||||
0x14, /* bLength */
|
||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||
'C', 0x00, /* wcChar0 */
|
||||
'h', 0x00, /* wcChar1 */
|
||||
'e', 0x00, /* wcChar2 */
|
||||
'r', 0x00, /* wcChar3 */
|
||||
'r', 0x00, /* wcChar4 */
|
||||
'y', 0x00, /* wcChar5 */
|
||||
'U', 0x00, /* wcChar6 */
|
||||
'S', 0x00, /* wcChar7 */
|
||||
'B', 0x00, /* wcChar8 */
|
||||
///////////////////////////////////////
|
||||
/// string2 descriptor
|
||||
///////////////////////////////////////
|
||||
0x2A, /* bLength */
|
||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||
'C', 0x00, /* wcChar0 */
|
||||
'h', 0x00, /* wcChar1 */
|
||||
'e', 0x00, /* wcChar2 */
|
||||
'r', 0x00, /* wcChar3 */
|
||||
'r', 0x00, /* wcChar4 */
|
||||
'y', 0x00, /* wcChar5 */
|
||||
'U', 0x00, /* wcChar6 */
|
||||
'S', 0x00, /* wcChar7 */
|
||||
'B', 0x00, /* wcChar8 */
|
||||
' ', 0x00, /* wcChar9 */
|
||||
'P', 0x00, /* wcChar10 */
|
||||
'R', 0x00, /* wcChar11 */
|
||||
'I', 0x00, /* wcChar12 */
|
||||
'N', 0x00, /* wcChar13 */
|
||||
'T', 0x00, /* wcChar14 */
|
||||
' ', 0x00, /* wcChar15 */
|
||||
'D', 0x00, /* wcChar16 */
|
||||
'E', 0x00, /* wcChar17 */
|
||||
'M', 0x00, /* wcChar18 */
|
||||
'O', 0x00, /* wcChar19 */
|
||||
///////////////////////////////////////
|
||||
/// string3 descriptor
|
||||
///////////////////////////////////////
|
||||
0x16, /* bLength */
|
||||
USB_DESCRIPTOR_TYPE_STRING, /* bDescriptorType */
|
||||
'2', 0x00, /* wcChar0 */
|
||||
'0', 0x00, /* wcChar1 */
|
||||
'2', 0x00, /* wcChar2 */
|
||||
'2', 0x00, /* wcChar3 */
|
||||
'1', 0x00, /* wcChar4 */
|
||||
'2', 0x00, /* wcChar5 */
|
||||
'3', 0x00, /* wcChar6 */
|
||||
'4', 0x00, /* wcChar7 */
|
||||
'5', 0x00, /* wcChar8 */
|
||||
'6', 0x00, /* wcChar9 */
|
||||
#ifdef CONFIG_USB_HS
|
||||
///////////////////////////////////////
|
||||
/// device qualifier descriptor
|
||||
///////////////////////////////////////
|
||||
0x0a,
|
||||
USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x02,
|
||||
0x02,
|
||||
0x01,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
#endif
|
||||
0x00
|
||||
};
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[PRINTER_OUT_EP_SIZE];
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[PRINTER_IN_EP_SIZE];
|
||||
|
||||
void usbd_event_handler(uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
break;
|
||||
case USBD_EVENT_CONNECTED:
|
||||
break;
|
||||
case USBD_EVENT_DISCONNECTED:
|
||||
break;
|
||||
case USBD_EVENT_RESUME:
|
||||
break;
|
||||
case USBD_EVENT_SUSPEND:
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(PRINTER_OUT_EP, read_buffer, PRINTER_OUT_EP_SIZE);
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
break;
|
||||
case USBD_EVENT_CLR_REMOTE_WAKEUP:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_printer_bulk_out(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");
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(PRINTER_OUT_EP, read_buffer, PRINTER_OUT_EP_SIZE);
|
||||
}
|
||||
|
||||
void usbd_printer_bulk_in(uint8_t ep, uint32_t nbytes)
|
||||
{
|
||||
USB_LOG_RAW("actual in len:%d\r\n", nbytes);
|
||||
|
||||
if ((nbytes % PRINTER_IN_EP_SIZE) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(PRINTER_IN_EP, NULL, 0);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
/*!< endpoint call back */
|
||||
struct usbd_endpoint printer_out_ep = {
|
||||
.ep_addr = PRINTER_OUT_EP,
|
||||
.ep_cb = usbd_printer_bulk_out
|
||||
};
|
||||
|
||||
struct usbd_endpoint printer_in_ep = {
|
||||
.ep_addr = PRINTER_IN_EP,
|
||||
.ep_cb = usbd_printer_bulk_in
|
||||
};
|
||||
|
||||
struct usbd_interface intf0;
|
||||
|
||||
static const uint8_t printer_device_id[] =
|
||||
{
|
||||
0x00, 51,
|
||||
'M','F','G',':','C','B','M',';',
|
||||
'C','M','D',':','G','D','I',';',
|
||||
'M','D','L',':','C','B','M','1','0','0','0',';',
|
||||
'C','L','S',':','P','R','I','N','T','E','R',';',
|
||||
'M','O','D','E',':','G','D','I',';'
|
||||
};
|
||||
|
||||
void printer_init(void)
|
||||
{
|
||||
usbd_desc_register(printer_descriptor);
|
||||
usbd_add_interface(usbd_printer_init_intf(&intf0, printer_device_id, sizeof(printer_device_id)));
|
||||
usbd_add_endpoint(&printer_out_ep);
|
||||
usbd_add_endpoint(&printer_in_ep);
|
||||
|
||||
usbd_initialize();
|
||||
}
|
@ -2,8 +2,6 @@
|
||||
#include "usbd_video.h"
|
||||
#include "pic_data.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define VIDEO_IN_EP 0x81
|
||||
|
||||
#ifdef CONFIG_USB_HS
|
||||
@ -143,7 +141,7 @@ const uint8_t video_descriptor[] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -198,29 +196,29 @@ static struct usbd_endpoint video_in_ep = {
|
||||
struct usbd_interface intf0;
|
||||
struct usbd_interface intf1;
|
||||
|
||||
void video_init()
|
||||
void video_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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_desc_register(busid, video_descriptor);
|
||||
usbd_add_interface(busid, usbd_video_init_intf(busid, &intf0, INTERVAL, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
|
||||
usbd_add_interface(busid, usbd_video_init_intf(busid, &intf1, INTERVAL, MAX_FRAME_SIZE, MAX_PAYLOAD_SIZE));
|
||||
usbd_add_endpoint(busid, &video_in_ep);
|
||||
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
||||
|
||||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t packet_buffer[10 * 1024];
|
||||
|
||||
void video_test()
|
||||
void video_test(uint8_t busid)
|
||||
{
|
||||
uint32_t out_len;
|
||||
uint32_t packets;
|
||||
memset(packet_buffer, 0, 10 * 1024);
|
||||
while (1) {
|
||||
if (tx_flag) {
|
||||
packets = usbd_video_mjpeg_payload_fill(CONFIG_USBDEV_DEMO_BUS, (uint8_t *)jpeg_data, sizeof(jpeg_data), packet_buffer, &out_len);
|
||||
packets = usbd_video_mjpeg_payload_fill(busid, (uint8_t *)jpeg_data, sizeof(jpeg_data), packet_buffer, &out_len);
|
||||
#if 0
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, VIDEO_IN_EP, packet_buffer, out_len);
|
||||
usbd_ep_start_write(busid, VIDEO_IN_EP, packet_buffer, out_len);
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
@ -231,7 +229,7 @@ void video_test()
|
||||
for (uint32_t i = 0; i < packets; i++) {
|
||||
if (i == (packets - 1)) {
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], out_len - (packets - 1) * MAX_PAYLOAD_SIZE);
|
||||
usbd_ep_start_write(busid, 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;
|
||||
@ -239,7 +237,7 @@ void video_test()
|
||||
}
|
||||
} else {
|
||||
iso_tx_busy = true;
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE);
|
||||
usbd_ep_start_write(busid, VIDEO_IN_EP, &packet_buffer[i * MAX_PAYLOAD_SIZE], MAX_PAYLOAD_SIZE);
|
||||
while (iso_tx_busy) {
|
||||
if (tx_flag == 0) {
|
||||
break;
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_cdc.h"
|
||||
|
||||
#define CONFIG_USBDEV_DEMO_BUS 0
|
||||
|
||||
#define WCID_VENDOR_CODE 0x17
|
||||
|
||||
#define DOUBLE_WINUSB 0
|
||||
@ -336,7 +334,7 @@ USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[2048];
|
||||
|
||||
volatile bool ep_tx_busy_flag = false;
|
||||
|
||||
static void usbd_event_handler(uint8_t event)
|
||||
static void usbd_event_handler(uint8_t busid, uint8_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@ -351,9 +349,9 @@ static void usbd_event_handler(uint8_t event)
|
||||
break;
|
||||
case USBD_EVENT_CONFIGURED:
|
||||
/* setup first out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
||||
#if DOUBLE_WINUSB == 1
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
#endif
|
||||
break;
|
||||
case USBD_EVENT_SET_REMOTE_WAKEUP:
|
||||
@ -373,9 +371,9 @@ void usbd_winusb_out(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
// printf("%02x ", read_buffer[i]);
|
||||
// }
|
||||
// printf("\r\n");
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP, read_buffer, nbytes);
|
||||
usbd_ep_start_write(busid, WINUSB_IN_EP, read_buffer, nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, WINUSB_OUT_EP, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_winusb_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -384,7 +382,7 @@ void usbd_winusb_in(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
if ((nbytes % WINUSB_EP_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP, NULL, 0);
|
||||
usbd_ep_start_write(busid, WINUSB_IN_EP, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@ -411,9 +409,9 @@ void usbd_winusb_out2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
// printf("%02x ", read_buffer[i]);
|
||||
// }
|
||||
// printf("\r\n");
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP2, read_buffer, nbytes);
|
||||
usbd_ep_start_write(busid, WINUSB_IN_EP2, read_buffer, nbytes);
|
||||
/* setup next out ep read transfer */
|
||||
usbd_ep_start_read(CONFIG_USBDEV_DEMO_BUS, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
usbd_ep_start_read(busid, WINUSB_OUT_EP2, read_buffer, 2048);
|
||||
}
|
||||
|
||||
void usbd_winusb_in2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
@ -422,7 +420,7 @@ void usbd_winusb_in2(uint8_t busid, uint8_t ep, uint32_t nbytes)
|
||||
|
||||
if ((nbytes % WINUSB_EP_MPS) == 0 && nbytes) {
|
||||
/* send zlp */
|
||||
usbd_ep_start_write(CONFIG_USBDEV_DEMO_BUS, WINUSB_IN_EP2, NULL, 0);
|
||||
usbd_ep_start_write(busid, WINUSB_IN_EP2, NULL, 0);
|
||||
} else {
|
||||
ep_tx_busy_flag = false;
|
||||
}
|
||||
@ -442,17 +440,17 @@ struct usbd_interface intf1;
|
||||
|
||||
#endif
|
||||
|
||||
void winusb_init(void)
|
||||
void winusb_init(uint8_t busid, uint32_t reg_base)
|
||||
{
|
||||
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);
|
||||
usbd_desc_register(busid, winusb_descriptor);
|
||||
usbd_msosv1_desc_register(busid, &msosv1_desc);
|
||||
usbd_add_interface(busid, &intf0);
|
||||
usbd_add_endpoint(busid, &winusb_out_ep1);
|
||||
usbd_add_endpoint(busid, &winusb_in_ep1);
|
||||
#if DOUBLE_WINUSB == 1
|
||||
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);
|
||||
usbd_add_interface(busid, &intf1);
|
||||
usbd_add_endpoint(busid, &winusb_out_ep2);
|
||||
usbd_add_endpoint(busid, &winusb_in_ep2);
|
||||
#endif
|
||||
usbd_initialize(CONFIG_USBDEV_DEMO_BUS, usbd_event_handler);
|
||||
usbd_initialize(busid, reg_base, usbd_event_handler);
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 41 KiB |
Binary file not shown.
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 36 KiB |
Binary file not shown.
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 43 KiB |
@ -99,8 +99,6 @@ USB Device 移植要点
|
||||
.. code-block:: C
|
||||
|
||||
// 以下细节如有出入,请对照 stm32xxx.h 文件修改
|
||||
#define USBD_IRQHandler OTG_HS_IRQHandler // pa11/pa12 引脚使用 OTG_FS_IRQHandler
|
||||
#define USBD_BASE (0x40040000UL) // pa11/pa12 引脚一般使用 50000000UL,STM32F7/H7 使用 0x40080000UL
|
||||
#define CONFIG_USBDEV_EP_NUM 6 // pa11/pa12 引脚使用 4
|
||||
#define CONFIG_USB_DWC2_RAM_SIZE 4096 // pa11/pa12 引脚使用 1280
|
||||
|
||||
@ -108,8 +106,6 @@ USB Device 移植要点
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#define USBD_IRQHandler USB_LP_CAN1_RX0_IRQHandler
|
||||
#define USBD_BASE (0x40005C00UL)
|
||||
#define CONFIG_USBDEV_EP_NUM 8
|
||||
#define CONFIG_USBDEV_FSDEV_PMA_ACCESS 2
|
||||
|
||||
@ -118,13 +114,16 @@ USB Device 移植要点
|
||||
.. figure:: img/stm32_10.png
|
||||
.. figure:: img/stm32_11.png
|
||||
|
||||
- 拷贝 **xxx_msp.c** 中的 **HAL_PCD_MspInit** 函数中的内容到 **usb_dc_low_level_init** 函数中,屏蔽 st 生成的 usb 中断函数和 usb 初始化
|
||||
- 拷贝 **xxx_msp.c** 中的 **HAL_PCD_MspInit** 函数中的内容到 **usb_dc_low_level_init** 函数中,屏蔽 st 生成的 usb 初始化
|
||||
|
||||
.. figure:: img/stm32_12.png
|
||||
.. figure:: img/stm32_13.png
|
||||
.. figure:: img/stm32_14.png
|
||||
|
||||
- 调用 template 的内容初始化,就可以使用了
|
||||
- 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`
|
||||
|
||||
.. figure:: img/stm32_13.png
|
||||
|
||||
- 调用 template 的内容初始化,并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
|
||||
|
||||
.. figure:: img/stm32_15.png
|
||||
|
||||
@ -152,9 +151,8 @@ USB Host 移植要点
|
||||
#define CONFIG_USBHOST_PIPE_NUM 12
|
||||
|
||||
- 拷贝 **xxx_msp.c** 中的 `HAL_HCD_MspInit` 函数中的内容到 `usb_hc_low_level_init` 函数中,屏蔽 st 生成的 usb 初始化
|
||||
- 在中断函数中调用 `USBH_IRQHandler`,并传入 bus 句柄
|
||||
- 调用 `usbh_alloc_bus` 创建 bus, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
|
||||
- 调用 `usbh_initialize` 即可
|
||||
- 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`
|
||||
- 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
|
||||
- 启动线程
|
||||
|
||||
.. figure:: img/stm32_18.png
|
||||
|
@ -8,15 +8,11 @@ USB Device 移植要点
|
||||
|
||||
- 拷贝 CherryUSB 源码到工程目录下,并按需添加源文件和头文件路径,其中 `usbd_core.c` 和 `usb_dc_xxx.c` 为必须添加项。而 `usb_dc_xxx.c` 是芯片所对应的 USB IP dcd 部分驱动,如果不知道自己芯片属于那个 USB IP,参考 **port** 目录下的不同 USB IP 的 readme。如果使用的 USB IP 没有支持,只能自己实现了
|
||||
- 拷贝 `cherryusb_config_template.h` 文件到自己工程目录下,命名为 `usb_config.h`,并添加相应的目录头文件路径
|
||||
- 在 `usb_config.h` 中添加 `USBD_IRQHandler=xxxx` 、 `CONFIG_USBDEV_EP_NUM=x` 以及 `USBD_BASE=0xxxxx` 三个常规 porting 需要的宏
|
||||
|
||||
.. note:: 上述三个宏仅对 fsdev、musb、dwc2 有效,因为这 3 个是通用 IP
|
||||
|
||||
.. note:: 为了适配后续多 port,建议中断名称不要使用宏来替换,自行在真实的中断中调用 `USBD_IRQHandler`
|
||||
|
||||
- 实现 `usb_dc_low_level_init` 函数(该函数主要负责 USB 时钟、引脚、中断的初始化)。该函数可以放在你想要放的任何参与编译的 c 文件中。如何进行 USB 的时钟、引脚、中断等初始化,请自行根据你使用的芯片原厂提供的源码中进行添加。
|
||||
- 描述符的注册、class的注册、接口的注册、端点中断的注册。不会的参考 demo 下的 template
|
||||
- 调用 `usbd_initialize` 初始化 usb 硬件
|
||||
- 调用 `usbd_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBDEV_MAX_BUS`
|
||||
- 在中断函数中调用 `USBD_IRQHandler`,并传入 `busid`, 如果你的 SDK 中中断入口已经存在 `USBD_IRQHandler` ,请更改 USB 协议栈中的名称
|
||||
- 编译使用。各个 class 如何使用,参考 demo 下的 template
|
||||
|
||||
USB Host 移植要点
|
||||
@ -27,9 +23,8 @@ USB Host 移植要点
|
||||
- 拷贝 CherryUSB 源码到工程目录下,并按需添加源文件和头文件路径,其中 `usbh_core.c` 、 `usb_hc_xxx.c` 以及 **osal** 目录下源文件(根据不同的 os 选择对应的源文件)为必须添加项。而 `usb_hc_xxx.c` 是芯片所对应的 USB IP dcd 部分驱动,如果不知道自己芯片属于那个 USB IP,参考 **port** 目录下的不同 USB IP 的 readme。如果使用的 USB IP 没有支持,只能自己实现了
|
||||
- 拷贝 `cherryusb_config_template.h` 文件到自己工程目录下,命名为 `usb_config.h`,并添加相应的目录头文件路径
|
||||
- 实现 `usb_hc_low_level_init` 函数(该函数主要负责 USB 时钟、引脚、中断的初始化)。该函数可以放在你想要放的任何参与编译的 c 文件中。如何进行 USB 的时钟、引脚、中断等初始化,请自行根据你使用的芯片原厂提供的源码中进行添加。
|
||||
- 调用 `usbh_alloc_bus` 创建 bus,填入 USB IP 的基地址, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
|
||||
- 在中断函数中调用 `USBH_IRQHandler`,并传入 bus 句柄, 如果你的 SDK 中中断入口已经存在 `USBH_IRQHandler` ,请更改 USB 协议栈中的名称
|
||||
- 调用 `usbh_initialize`
|
||||
- 调用 `usbh_initialize` 并填入 `busid` 和 USB IP 的 `reg base`, `busid` 从 0 开始,不能超过 `CONFIG_USBHOST_MAX_BUS`
|
||||
- 在中断函数中调用 `USBH_IRQHandler`,并传入 `busid`, 如果你的 SDK 中中断入口已经存在 `USBH_IRQHandler` ,请更改 USB 协议栈中的名称
|
||||
- 如果使用的是 GCC ,需要在链接脚本(ld)中添加如下代码:
|
||||
|
||||
.. code-block:: C
|
||||
|
@ -51,14 +51,6 @@
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#ifndef USBD_IRQHandler
|
||||
#error "please define USBD_IRQHandler in usb_config.h"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_BASE
|
||||
#error "please define USBD_BASE in usb_config.h"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USB_DWC2_RAM_SIZE
|
||||
#error "please define CONFIG_USB_DWC2_RAM_SIZE in usb_config.h, only support 1280 or 4096"
|
||||
#endif
|
||||
@ -142,6 +134,8 @@
|
||||
#error "Unsupported CONFIG_USB_DWC2_RAM_SIZE value"
|
||||
#endif
|
||||
|
||||
#define USBD_BASE (g_usbdev_bus[0].reg_base)
|
||||
|
||||
#define USB_OTG_GLB ((USB_OTG_GlobalTypeDef *)(USBD_BASE))
|
||||
#define USB_OTG_DEV ((USB_OTG_DeviceTypeDef *)(USBD_BASE + USB_OTG_DEVICE_BASE))
|
||||
#define USB_OTG_PCGCCTL *(__IO uint32_t *)((uint32_t)USBD_BASE + USB_OTG_PCGCCTL_BASE)
|
||||
@ -581,7 +575,7 @@ int usb_dc_init(uint8_t busid)
|
||||
USB_OTG_GLB->GAHBCFG &= ~USB_OTG_GAHBCFG_GINT;
|
||||
|
||||
/* This is vendor register */
|
||||
USB_OTG_GLB->GCCFG = usbd_get_dwc2_gccfg_conf();
|
||||
USB_OTG_GLB->GCCFG = usbd_get_dwc2_gccfg_conf(USBD_BASE);
|
||||
|
||||
ret = dwc2_core_init();
|
||||
|
||||
@ -997,7 +991,7 @@ int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(void)
|
||||
void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint32_t gint_status, temp, ep_idx, ep_intr, epint, read_count, daintmask;
|
||||
gint_status = dwc2_get_glb_intstatus();
|
||||
|
@ -1706,6 +1706,6 @@ typedef struct
|
||||
#define USB_UNMASK_HALT_HC_INT(chnum) (USB_OTG_HC(chnum)->HCINTMSK |= USB_OTG_HCINTMSK_CHHM)
|
||||
#define CLEAR_HC_INT(chnum, __INTERRUPT__) (USB_OTG_HC(chnum)->HCINT = (__INTERRUPT__))
|
||||
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(void);
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(void);
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base);
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base);
|
||||
#endif
|
||||
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(void)
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USB_HS
|
||||
return ((1 << 16) | (1 << 21));
|
||||
@ -28,7 +28,7 @@ uint32_t usbd_get_dwc2_gccfg_conf(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(void)
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USB_DWC2_ULPI_PHY
|
||||
return ((1 << 16) | (1 << 21));
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(void)
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USB_HS
|
||||
return 0;
|
||||
@ -17,7 +17,7 @@ uint32_t usbd_get_dwc2_gccfg_conf(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(void)
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USB_DWC2_ULPI_PHY
|
||||
return 0;
|
||||
|
@ -11,13 +11,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(void)
|
||||
uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USB_HS
|
||||
return 0;
|
||||
#else
|
||||
#if __has_include("stm32h7xx.h") || __has_include("stm32f7xx.h") || __has_include("stm32l4xx.h")
|
||||
#define USB_OTG_GLB ((USB_OTG_GlobalTypeDef *)(USBD_BASE))
|
||||
#define USB_OTG_GLB ((USB_OTG_GlobalTypeDef *)(reg_base))
|
||||
/* B-peripheral session valid override enable */
|
||||
USB_OTG_GLB->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
|
||||
USB_OTG_GLB->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
|
||||
@ -28,13 +28,13 @@ uint32_t usbd_get_dwc2_gccfg_conf(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(void)
|
||||
uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
|
||||
{
|
||||
#ifdef CONFIG_USB_DWC2_ULPI_PHY
|
||||
return 0;
|
||||
#else
|
||||
#if __has_include("stm32h7xx.h") || __has_include("stm32f7xx.h") || __has_include("stm32l4xx.h")
|
||||
#define USB_OTG_GLB ((USB_OTG_GlobalTypeDef *)(USBD_BASE))
|
||||
#define USB_OTG_GLB ((USB_OTG_GlobalTypeDef *)(reg_base))
|
||||
/* B-peripheral session valid override enable */
|
||||
USB_OTG_GLB->GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOEN;
|
||||
USB_OTG_GLB->GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOVAL;
|
||||
|
@ -472,7 +472,7 @@ int usb_hc_init(struct usbh_bus *bus)
|
||||
USB_OTG_GLB->GAHBCFG &= ~USB_OTG_GAHBCFG_GINT;
|
||||
|
||||
/* This is vendor register */
|
||||
USB_OTG_GLB->GCCFG = usbh_get_dwc2_gccfg_conf();
|
||||
USB_OTG_GLB->GCCFG = usbh_get_dwc2_gccfg_conf(bus->hcd.reg_base);
|
||||
|
||||
ret = dwc2_core_init(bus);
|
||||
|
||||
@ -1115,9 +1115,12 @@ static void dwc2_port_irq_handler(struct usbh_bus *bus)
|
||||
USB_OTG_HPRT = hprt0_dup;
|
||||
}
|
||||
|
||||
void USBH_IRQHandler(struct usbh_bus *bus)
|
||||
void USBH_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint32_t gint_status, chan_int;
|
||||
struct usbh_bus *bus;
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
gint_status = dwc2_get_glb_intstatus(bus);
|
||||
if ((USB_OTG_GLB->GINTSTS & 0x1U) == USB_OTG_MODE_HOST) {
|
||||
/* Avoid spurious interrupt */
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "usbh_core.h"
|
||||
#include "usb_ehci_priv.h"
|
||||
|
||||
extern void USBH_IRQHandler(struct usbh_bus *bus);
|
||||
extern void USBH_IRQHandler(uint8_t busid);
|
||||
|
||||
const uint8_t aic_irq_table[] = {
|
||||
USB_HOST0_EHCI_IRQn,
|
||||
@ -63,7 +63,7 @@ void usb_hc_low_level_init(struct usbh_bus *bus)
|
||||
|
||||
/* register interrupt callback */
|
||||
aicos_request_irq(aic_irq_table[bus->hcd.hcd_id], (irq_handler_t)USBH_IRQHandler,
|
||||
0, "usb_host_ehci", bus);
|
||||
0, "usb_host_ehci", bus->hcd.hcd_id);
|
||||
aicos_irq_enable(aic_irq_table[bus->hcd.hcd_id]);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
#define USB_SOF_TIMER_MASK_AFTER_RESET_HS (0x44C)
|
||||
#define USB_SOF_TIMER_MASK_AFTER_RESET_FS (0x2710)
|
||||
|
||||
extern void USBH_IRQHandler(struct usbh_bus *bus);
|
||||
extern void USBH_IRQHandler(uint8_t busid);
|
||||
|
||||
static void bflb_usb_phy_init(void)
|
||||
{
|
||||
@ -89,7 +89,7 @@ void usb_hc_low_level_init(struct usbh_bus *bus)
|
||||
|
||||
bflb_usb_phy_init();
|
||||
|
||||
bflb_irq_attach(37, USBH_IRQHandler, NULL);
|
||||
bflb_irq_attach(37, USBH_IRQHandler, 0);
|
||||
bflb_irq_enable(37);
|
||||
|
||||
/* enable device-A for host */
|
||||
|
@ -11,14 +11,8 @@
|
||||
#error "hpm ehci must config CONFIG_USB_EHCI_HCOR_OFFSET to 0x140"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_USB_EHCI_PRINT_HW_PARAM) || !defined(CONFIG_USB_EHCI_PORT_POWER)
|
||||
#error "hpm ehci must enable CONFIG_USB_EHCI_PORT_POWER and disable CONFIG_USB_EHCI_PRINT_HW_PARAM"
|
||||
#endif
|
||||
|
||||
struct usbh_bus *hpm_usb_bus0;
|
||||
|
||||
#ifdef HPM_USB1_BASE
|
||||
struct usbh_bus *hpm_usb_bus1;
|
||||
#if !defined(CONFIG_USB_EHCI_PORT_POWER)
|
||||
#error "hpm ehci must enable CONFIG_USB_EHCI_PORT_POWER"
|
||||
#endif
|
||||
|
||||
const uint8_t hpm_irq_table[] = {
|
||||
@ -78,18 +72,18 @@ uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern void USBH_IRQHandler(struct usbh_bus *bus);
|
||||
extern void USBH_IRQHandler(uint8_t busid);
|
||||
|
||||
void isr_usbh0(void)
|
||||
{
|
||||
USBH_IRQHandler(hpm_usb_bus0);
|
||||
USBH_IRQHandler(0);
|
||||
}
|
||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
|
||||
|
||||
#ifdef HPM_USB1_BASE
|
||||
void isr_usbh1(void)
|
||||
{
|
||||
USBH_IRQHandler(hpm_usb_bus1);
|
||||
USBH_IRQHandler(1);
|
||||
}
|
||||
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbh1)
|
||||
#endif
|
||||
|
@ -11,7 +11,7 @@ static int ehci_slot;
|
||||
static int ehci_function;
|
||||
static int ehci_vector;
|
||||
|
||||
extern void USBH_IRQHandler(struct usbh_bus *bus);
|
||||
extern void USBH_IRQHandler(uint8_t busid);
|
||||
|
||||
void ehci_pci_scan(int bus, int slot, int fun, int vector)
|
||||
{
|
||||
@ -38,7 +38,7 @@ void usb_hc_low_level_init(struct usbh_bus *bus)
|
||||
"USBirq",
|
||||
RTEMS_INTERRUPT_SHARED,
|
||||
USBH_IRQHandler,
|
||||
(void *)bus);
|
||||
(void *)0);
|
||||
|
||||
if (sc != RTEMS_SUCCESSFUL) {
|
||||
printf("USB install isr falied,%s\n", rtems_status_text(sc));
|
||||
|
@ -1309,10 +1309,13 @@ static void ehci_scan_periodic_list(struct usbh_bus *bus)
|
||||
}
|
||||
}
|
||||
|
||||
void USBH_IRQHandler(struct usbh_bus *bus)
|
||||
void USBH_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint32_t usbsts;
|
||||
struct usbh_bus *bus;
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
|
||||
usbsts = EHCI_HCOR->usbsts & EHCI_HCOR->usbintr;
|
||||
EHCI_HCOR->usbsts = usbsts;
|
||||
|
||||
|
@ -7,14 +7,6 @@
|
||||
#define PMA_ACCESS CONFIG_USBDEV_FSDEV_PMA_ACCESS
|
||||
#include "usb_fsdev_reg.h"
|
||||
|
||||
#ifndef USBD_IRQHandler
|
||||
#error "please define USBD_IRQHandler in usb_config.h"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_BASE
|
||||
#error "please define USBD_BASE in usb_config.h"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_USB_FSDEV_RAM_SIZE
|
||||
#define CONFIG_USB_FSDEV_RAM_SIZE 512
|
||||
#endif
|
||||
@ -23,7 +15,7 @@
|
||||
#define CONFIG_USBDEV_EP_NUM 8
|
||||
#endif
|
||||
|
||||
#define USB ((USB_TypeDef *)USBD_BASE)
|
||||
#define USB ((USB_TypeDef *)g_usbdev_bus[0].reg_base)
|
||||
|
||||
#define USB_BTABLE_SIZE (8 * CONFIG_USBDEV_EP_NUM)
|
||||
|
||||
@ -309,7 +301,7 @@ int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(void)
|
||||
void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint16_t wIstr, wEPVal;
|
||||
uint8_t ep_idx;
|
||||
|
@ -13,15 +13,7 @@
|
||||
#define HWREGB(x) \
|
||||
(*((volatile uint8_t *)(x)))
|
||||
|
||||
#ifndef USBD_IRQHandler
|
||||
#error "please define USBD_IRQHandler in usb_config.h"
|
||||
#endif
|
||||
|
||||
#ifndef USBD_BASE
|
||||
#error "please define USBD_BASE in usb_config.h"
|
||||
#endif
|
||||
|
||||
#define USB_BASE USBD_BASE
|
||||
#define USB_BASE (g_usbdev_bus[0].reg_base)
|
||||
|
||||
#if defined(CONFIG_USB_MUSB_SUNXI)
|
||||
#define MUSB_FADDR_OFFSET 0x98
|
||||
@ -775,7 +767,7 @@ static void handle_ep0(void)
|
||||
}
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(void)
|
||||
void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint32_t is;
|
||||
uint32_t txis;
|
||||
@ -796,7 +788,7 @@ void USBD_IRQHandler(void)
|
||||
if (is & USB_IS_RESET) {
|
||||
memset(&g_musb_udc, 0, sizeof(struct musb_udc));
|
||||
g_musb_udc.fifo_size_offset = USB_CTRL_EP_MPS;
|
||||
usbd_event_reset_handler();
|
||||
usbd_event_reset_handler(0);
|
||||
HWREGH(USB_BASE + MUSB_TXIE_OFFSET) = USB_TXIE_EP0;
|
||||
HWREGH(USB_BASE + MUSB_RXIE_OFFSET) = 0;
|
||||
|
||||
|
@ -850,7 +850,7 @@ void handle_ep0(struct usbh_bus *bus)
|
||||
}
|
||||
}
|
||||
|
||||
void USBH_IRQHandler(struct usbh_bus *bus)
|
||||
void USBH_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint32_t is;
|
||||
uint32_t txis;
|
||||
@ -861,7 +861,10 @@ void USBH_IRQHandler(struct usbh_bus *bus)
|
||||
struct usbh_urb *urb;
|
||||
uint8_t ep_idx;
|
||||
uint8_t old_ep_idx;
|
||||
struct usbh_bus *bus;
|
||||
|
||||
bus = &g_usbhost_bus[busid];
|
||||
|
||||
is = HWREGB(USB_BASE + MUSB_IS_OFFSET);
|
||||
txis = HWREGH(USB_BASE + MUSB_TXIS_OFFSET);
|
||||
rxis = HWREGH(USB_BASE + MUSB_RXIS_OFFSET);
|
||||
|
@ -2,10 +2,6 @@
|
||||
#include "NuMicro.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
#ifndef USBD_IRQHandler
|
||||
#define USBD_IRQHandler USBD_IRQHandler
|
||||
#endif
|
||||
|
||||
#ifndef USBD_EPNUM
|
||||
#define USBD_EPNUM 8
|
||||
#endif
|
||||
@ -292,7 +288,7 @@ int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t
|
||||
return 0;
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(void)
|
||||
void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
uint32_t int_flag = USBD_GET_INT_FLAG();
|
||||
uint32_t bus_state = USBD_GET_BUS_STATE();
|
||||
|
@ -468,7 +468,7 @@ int usbd_ep_start_read(uint8_t busid, const uint8_t ep, uint8_t *data, uint32_t
|
||||
return pusb2_dc_ep_read_write(ep, (uintptr)data, data_len);
|
||||
}
|
||||
|
||||
void USBD_IRQHandler(void)
|
||||
void USBD_IRQHandler(uint8_t busid)
|
||||
{
|
||||
FPUsb2InterruptHandler(&g_pusb2_udc.pusb2);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user