|
32 | 32 | * @brief Number of the available endpoints.
|
33 | 33 | * @details This value does not include the endpoint 0 which is always present.
|
34 | 34 | */
|
35 |
| -#define HAL_MAX_ENDPOINTS 6 |
| 35 | +#define HAL_MAX_ENDPOINTS 7 |
36 | 36 | #if (defined(SN32F240B) || defined(SN32F260))
|
37 |
| -#define USB_ENDPOINTS_NUMBER 4 |
38 |
| -#define SN32_USB_PMA_SIZE 256 |
39 |
| -#elif (defined(SN32F280) || defined(SN32F290)) |
40 |
| -#define USB_ENDPOINTS_NUMBER HAL_MAX_ENDPOINTS |
41 |
| -#define SN32_USB_PMA_SIZE 512 |
| 37 | +# define USB_ENDPOINTS_NUMBER 4 |
| 38 | +# define SN32_USB_PMA_SIZE 256 |
| 39 | +#elif defined(SN32F240C) |
| 40 | +# define USB_ENDPOINTS_NUMBER HAL_MAX_ENDPOINTS |
| 41 | +# define SN32_USB_PMA_SIZE 512 |
| 42 | +#elif (defined(SN32F240) || defined(SN32F280) || defined(SN32F290)) |
| 43 | +# define USB_ENDPOINTS_NUMBER 6 |
| 44 | +# define SN32_USB_PMA_SIZE 512 |
42 | 45 | #else
|
43 |
| -#error "USB driver not supported in the selected device" |
| 46 | +# error "USB driver not supported in the selected device" |
44 | 47 | #endif
|
45 | 48 |
|
46 | 49 | /**
|
47 | 50 | * @brief USB registers block.
|
48 | 51 | */
|
49 | 52 | typedef struct {
|
50 |
| - volatile uint32_t INTEN; /*!< (@ 0x00000000) Offset:0x00 USB Interrupt Enable Register */ |
51 |
| - volatile uint32_t INSTS; /*!< (@ 0x00000004) Offset:0x04 USB Interrupt Event Status Register */ |
52 |
| - volatile uint32_t INSTSC; /*!< (@ 0x00000008) Offset:0x08 USB Interrupt Event Status Clear Register */ |
53 |
| - volatile uint32_t ADDR; /*!< (@ 0x0000000C) Offset:0x0C USB Device Address Register */ |
54 |
| - volatile uint32_t CFG; /*!< (@ 0x00000010) Offset:0x10 USB Configuration Register */ |
55 |
| - volatile uint32_t SGCTL; /*!< (@ 0x00000014) Offset:0x14 USB Signal Control Register */ |
56 |
| - volatile uint32_t EPCTL[HAL_MAX_ENDPOINTS +1]; /*!< (@ 0x00000018) Offset:0x18 USB Endpoint 0-6 Control Registers */ |
57 |
| - volatile uint32_t RESERVED[2]; |
58 |
| - volatile uint32_t EPTOGGLE; /*!< (@ 0x0000003C) Offset:0x3C USB Endpoint Data Toggle Register */ |
59 |
| - volatile uint32_t RESERVED1[2]; |
60 |
| - volatile uint32_t EPBUFOS[HAL_MAX_ENDPOINTS]; /*!< (@ 0x00000048) Offset:0x48 USB Endpoint 1-6 Buffer Offset Registers */ |
61 |
| - volatile uint32_t FRMNO; /*!< (@ 0x00000060) Offset:0x60 USB Frame Number Register */ |
62 |
| - volatile uint32_t PHYPRM; /*!< (@ 0x00000064) Offset:0x64 USB PHY Parameter Register */ |
63 |
| - volatile uint32_t RESERVED3; |
64 |
| - volatile uint32_t PHYPRM2; /*!< (@ 0x0000006C) Offset:0x6C USB PHY Parameter 2 Register */ |
65 |
| - volatile uint32_t PS2CTL; /*!< (@ 0x00000070) Offset:0x70 PS/2 Control Register */ |
66 |
| - volatile uint32_t RESERVED4; |
67 |
| - volatile uint32_t RWADDR; /*!< (@ 0x00000078) Offset:0x78 USB Read/Write Address Register */ |
68 |
| - volatile uint32_t RWDATA; /*!< (@ 0x0000007C) Offset:0x7C USB Read/Write Data Register */ |
69 |
| - volatile uint32_t RWSTATUS; /*!< (@ 0x00000080) Offset:0x80 USB Read/Write Status Register */ |
70 |
| - volatile uint32_t RWADDR2; /*!< (@ 0x00000084) Offset:0x84 USB Read/Write Address Register 2 */ |
71 |
| - volatile uint32_t RWDATA2; /*!< (@ 0x00000088) Offset:0x88 USB Read/Write Data Register 2 */ |
72 |
| - volatile uint32_t RWSTATUS2; /*!< (@ 0x0000008C) Offset:0x8C USB Read/Write Status Register 2 */ |
73 |
| -} sn32_usb_t; /*!< Size = 144 (0x90) */ |
| 53 | + volatile uint32_t INTEN; /*!< (@ 0x00000000) Offset:0x00 USB Interrupt Enable Register */ |
| 54 | + volatile const uint32_t INSTS; /*!< (@ 0x00000004) Offset:0x04 USB Interrupt Event Status Register */ |
| 55 | + volatile uint32_t INSTSC; /*!< (@ 0x00000008) Offset:0x08 USB Interrupt Event Status Clear Register */ |
| 56 | + volatile uint32_t ADDR; /*!< (@ 0x0000000C) Offset:0x0C USB Device Address Register */ |
| 57 | + volatile uint32_t CFG; /*!< (@ 0x00000010) Offset:0x10 USB Configuration Register */ |
| 58 | + volatile uint32_t SGCTL; /*!< (@ 0x00000014) Offset:0x14 USB Signal Control Register */ |
| 59 | + volatile uint32_t EPCTL[USB_ENDPOINTS_NUMBER +1]; /*!< (@ 0x00000018) Offset:0x18 USB Endpoint 0-7 Control Registers */ |
| 60 | + volatile const uint32_t RESERVED[HAL_MAX_ENDPOINTS - USB_ENDPOINTS_NUMBER + 1]; |
| 61 | + volatile uint32_t EPTOGGLE; /*!< (@ 0x0000003C) Offset:0x3C USB Endpoint Data Toggle Register */ |
| 62 | + volatile const uint32_t RESERVED1[2]; |
| 63 | + volatile uint32_t EPBUFOS[USB_ENDPOINTS_NUMBER]; /*!< (@ 0x00000048) Offset:0x48 USB Endpoint 1-7 Buffer Offset Registers */ |
| 64 | +#if (USB_ENDPOINTS_NUMBER != HAL_MAX_ENDPOINTS) |
| 65 | + volatile uint32_t RESERVED2[HAL_MAX_ENDPOINTS - USB_ENDPOINTS_NUMBER - 1]; |
| 66 | +#endif |
| 67 | + volatile const uint32_t FRMNO; /*!< (@ 0x00000060) Offset:0x60 USB Frame Number Register */ |
| 68 | + volatile uint32_t PHYPRM; /*!< (@ 0x00000064) Offset:0x64 USB PHY Parameter Register */ |
| 69 | + volatile const uint32_t RESERVED3; |
| 70 | + volatile uint32_t PHYPRM2; /*!< (@ 0x0000006C) Offset:0x6C USB PHY Parameter 2 Register */ |
| 71 | + volatile uint32_t PS2CTL; /*!< (@ 0x00000070) Offset:0x70 PS/2 Control Register */ |
| 72 | + volatile const uint32_t RESERVED4; |
| 73 | + volatile uint32_t RWADDR; /*!< (@ 0x00000078) Offset:0x78 USB Read/Write Address Register */ |
| 74 | + volatile uint32_t RWDATA; /*!< (@ 0x0000007C) Offset:0x7C USB Read/Write Data Register */ |
| 75 | + volatile uint32_t RWSTATUS; /*!< (@ 0x00000080) Offset:0x80 USB Read/Write Status Register */ |
| 76 | + volatile uint32_t RWADDR2; /*!< (@ 0x00000084) Offset:0x84 USB Read/Write Address Register 2 */ |
| 77 | + volatile uint32_t RWDATA2; /*!< (@ 0x00000088) Offset:0x88 USB Read/Write Data Register 2 */ |
| 78 | + volatile uint32_t RWSTATUS2; /*!< (@ 0x0000008C) Offset:0x8C USB Read/Write Status Register 2 */ |
| 79 | +} sn32_usb_t; /*!< Size = 144 (0x90) */ |
74 | 80 |
|
75 | 81 | /** @} */
|
76 | 82 |
|
|
93 | 99 | * @brief Pointer to the USB RAM.
|
94 | 100 | */
|
95 | 101 | #define SN32_USBRAM ((sn32_usb_pma_t *)SN32_USBRAM_BASE)
|
96 |
| -#define mskEPn_NAK(ep) (0x1<<(ep -1)) |
97 |
| -#define mskEPn_ACK(ep) (0x1<<(8+(ep-1))) |
98 |
| -#define mskEPn_DIR(ep) (0x1<<(ep-1)) |
99 |
| -#define mskEPn_DATA_TOGGLE(ep) (0x1<<(ep-1)) |
| 102 | +/** |
| 103 | + * @brief USB EP handling. |
| 104 | + */ |
| 105 | +/* USB Interrupt Event Status Bit Definitions <USB_INSTS/USB_INSTSC> */ |
| 106 | +#define mskEPn_NAK(ep) (0x1<<(ep -1)) |
| 107 | +#define mskEPn_ACK(ep) (0x1<<(8+(ep-1))) |
| 108 | +/* USB Configuration Bit Definitions <USB_CFG> */ |
| 109 | +#define mskEPn_DIR(ep) (0x1<<(ep-1)) |
| 110 | +/* USB Endpoint Data Toggle Bit Definitions <USB_EPTOGGLE> */ |
| 111 | +#define mskEPn_DATA_TOGGLE(ep) (0x1<<(ep-1)) |
| 112 | +/* USB Interrupt Enable Bit Definitions <USB_INTEN> */ |
| 113 | +#define mskEPn_NAK_EN(ep) mskEPn_NAK(ep) |
| 114 | +#define mskEPnACK_EN (0x1<<USB_ENDPOINTS_NUMBER) |
100 | 115 |
|
101 | 116 | #define EPCTL_SET_STAT_ACK(ep, bBytecnt) \
|
102 | 117 | SN32_USB->EPCTL[ep] = (mskEPn_ENDP_EN|mskEPn_ENDP_STATE_ACK|bBytecnt)
|
|
0 commit comments