Skip to content

Commit 69d6edc

Browse files
ccli8adbridge
authored andcommitted
Support USB device/host
1 parent 7cf2675 commit 69d6edc

File tree

9 files changed

+1654
-36
lines changed

9 files changed

+1654
-36
lines changed

features/unsupported/USBDevice/USBDevice/USBEndpoints.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ typedef enum {
5757
#include "USBEndpoints_NUC472.h"
5858
#elif defined(TARGET_NUMAKER_PFM_M453)
5959
#include "USBEndpoints_M453.h"
60+
#elif defined(TARGET_M480)
61+
#include "USBEndpoints_M480.h"
6062
#else
6163
#error "Unknown target type"
6264
#endif

features/unsupported/USBDevice/USBDevice/USBHAL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class USBHAL {
132132
bool (USBHAL::*epCallback[8 - 2])(void);
133133
#elif defined(TARGET_STM)
134134
PCD_HandleTypeDef hpcd;
135-
#elif defined(TARGET_NUMAKER_PFM_NUC472)
135+
#elif defined(TARGET_NUMAKER_PFM_NUC472) || defined(TARGET_M480)
136136
bool (USBHAL::*epCallback[14 - 2])(void);
137137
#else
138138
bool (USBHAL::*epCallback[32 - 2])(void);
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 0)
3+
#define NU_MAX_EPX_BUFSIZE 4096
4+
#else
5+
#define NU_MAX_EPX_BUFSIZE 4096
6+
#endif
7+
8+
#define NU_EP2EPL(ep) ((ep) >> 1)
9+
10+
#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 0)
11+
#define NU_EP2EPH(ep) (((ep) >> 1) + 1)
12+
#define NU_EPL2EPH(ep) ((ep) + 1)
13+
#define NU_EPH2EPL(ep) ((ep) - 1)
14+
#define NUMBER_OF_PHYSICAL_ENDPOINTS 8
15+
#else
16+
#define NU_EP2EPH(ep) (((ep) >> 1) - 1)
17+
#define NU_EPX2EP(ep) ((ep == CEP) ? EP0OUT : ((ep) - EPA + EP1OUT))
18+
#define NU_EPL2EPH(ep) ((ep) - 1)
19+
#define NU_EPH2EPL(ep) ((ep) + 1)
20+
#define NUMBER_OF_PHYSICAL_ENDPOINTS 12
21+
#endif
22+
23+
#define NU_EP_DIR_Pos 0
24+
#define NU_EP_DIR_Msk (1 << NU_EP_DIR_Pos)
25+
#define NU_EP_DIR_OUT 0
26+
#define NU_EP_DIR_IN 1
27+
28+
#define NU_EP_TYPE(ep) (((ep) & NU_EP_TYPE_Msk) >> NU_EP_TYPE_Pos)
29+
#define NU_EP_NUM(ep) (((ep) & NU_EP_NUM_Msk) >> NU_EP_NUM_Pos)
30+
#define NU_EP_DIR(ep) (((ep) & NU_EP_DIR_Msk) >> NU_EP_DIR_Pos)
31+
#define NU_EP_NUM_DIR(ep) ((NU_EP_NUM(ep) << 1) | NU_EP_DIR(ep))
32+
33+
#define EP0OUT (0)
34+
#define EP0IN (1)
35+
#define EP1OUT (2)
36+
#define EP1IN (3)
37+
#define EP2OUT (4)
38+
#define EP2IN (5)
39+
#define EP3OUT (6)
40+
#define EP3IN (7)
41+
#define EP4OUT (8)
42+
#define EP4IN (9)
43+
#define EP5OUT (10)
44+
#define EP5IN (11)
45+
#define EP6OUT (12)
46+
#define EP6IN (13)
47+
48+
/* Maximum Packet sizes */
49+
#define MAX_PACKET_SIZE_EP0 64
50+
#define MAX_PACKET_SIZE_EP1 64
51+
#define MAX_PACKET_SIZE_EP2 64
52+
#define MAX_PACKET_SIZE_EP3 0x60
53+
#define MAX_PACKET_SIZE_EP4 64
54+
#define MAX_PACKET_SIZE_EP5 64
55+
#define MAX_PACKET_SIZE_EP6 64
56+
#define MAX_PACKET_SIZE_EP7 64
57+
58+
#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 1)
59+
#define MAX_PACKET_SIZE_EP8 64
60+
#define MAX_PACKET_SIZE_EP9 64
61+
#define MAX_PACKET_SIZE_EP10 64
62+
#define MAX_PACKET_SIZE_EP11 64
63+
#endif
64+
65+
/* Generic endpoints - intended to be portable accross devices */
66+
/* and be suitable for simple USB devices. */
67+
68+
/* Bulk endpoints */
69+
#define EPBULK_OUT EP5OUT
70+
#define EPBULK_IN EP6IN
71+
#define EPBULK_OUT_callback EP5_OUT_callback
72+
#define EPBULK_IN_callback EP6_IN_callback
73+
/* Interrupt endpoints */
74+
#define EPINT_OUT EP1OUT
75+
#define EPINT_IN EP2IN
76+
#define EPINT_OUT_callback EP1_OUT_callback
77+
#define EPINT_IN_callback EP2_IN_callback
78+
/* Isochronous endpoints */
79+
#define EPISO_OUT EP3OUT
80+
#define EPISO_IN EP4IN
81+
#define EPISO_OUT_callback EP3_OUT_callback
82+
#define EPISO_IN_callback EP4_IN_callback
83+
84+
#define MAX_PACKET_SIZE_EPBULK 64
85+
#define MAX_PACKET_SIZE_EPINT 64
86+
#define MAX_PACKET_SIZE_EPISO 1023
87+
88+
#if (MBED_CONF_TARGET_USB_DEVICE_HSUSBD == 1)
89+
#define HSUSBD_GET_EP_MAX_PAYLOAD(ep) HSUSBD->EP[ep].EPMPS
90+
#define HSUSBD_GET_EP_DATA_COUNT(ep) (HSUSBD->EP[ep].EPDATCNT & 0xFFFFF)
91+
#define HSUSBD_SET_EP_SHORT_PACKET(ep) HSUSBD->EP[ep].EPRSPCTL = ((HSUSBD->EP[ep].EPRSPCTL & 0x10) | 0x40)
92+
#define HSUSBD_GET_EP_INT_EN(ep) HSUSBD->EP[ep].EPINTEN
93+
#endif

0 commit comments

Comments
 (0)