Open FFBoard
Open source force feedback firmware
ch32_usbfs_reg.h
Go to the documentation of this file.
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2024 Matthew Tran
5 * Copyright (c) 2024 hathach
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef USB_CH32_USBFS_REG_H
29#define USB_CH32_USBFS_REG_H
30
31// https://github.com/openwch/ch32v307/pull/90
32// https://github.com/openwch/ch32v20x/pull/12
33#ifdef __GNUC__
34#pragma GCC diagnostic push
35#pragma GCC diagnostic ignored "-Wstrict-prototypes"
36#endif
37
38#if CFG_TUSB_MCU == OPT_MCU_CH32F20X
39 #include <ch32f20x.h>
40#elif CFG_TUSB_MCU == OPT_MCU_CH32V103
41 #include <ch32v10x.h>
42 typedef struct
43 {
44 __IO uint8_t BASE_CTRL;
45 __IO uint8_t UDEV_CTRL;
46 __IO uint8_t INT_EN;
47 __IO uint8_t DEV_ADDR;
48 __IO uint8_t Reserve0;
49 __IO uint8_t MIS_ST;
50 __IO uint8_t INT_FG;
51 __IO uint8_t INT_ST;
52 __IO uint32_t RX_LEN;
53 __IO uint8_t UEP4_1_MOD;
54 __IO uint8_t UEP2_3_MOD;
55 __IO uint8_t UEP5_6_MOD;
56 __IO uint8_t UEP7_MOD;
57 __IO uint32_t UEP0_DMA;
58 __IO uint32_t UEP1_DMA;
59 __IO uint32_t UEP2_DMA;
60 __IO uint32_t UEP3_DMA;
61 __IO uint32_t UEP4_DMA;
62 __IO uint32_t UEP5_DMA;
63 __IO uint32_t UEP6_DMA;
64 __IO uint32_t UEP7_DMA;
65 __IO uint16_t UEP0_TX_LEN;
66 __IO uint8_t UEP0_TX_CTRL;
67 __IO uint8_t UEP0_RX_CTRL;
68 __IO uint16_t UEP1_TX_LEN;
69 __IO uint8_t UEP1_TX_CTRL;
70 __IO uint8_t UEP1_RX_CTRL;
71 __IO uint16_t UEP2_TX_LEN;
72 __IO uint8_t UEP2_TX_CTRL;
73 __IO uint8_t UEP2_RX_CTRL;
74 __IO uint16_t UEP3_TX_LEN;
75 __IO uint8_t UEP3_TX_CTRL;
76 __IO uint8_t UEP3_RX_CTRL;
77 __IO uint16_t UEP4_TX_LEN;
78 __IO uint8_t UEP4_TX_CTRL;
79 __IO uint8_t UEP4_RX_CTRL;
80 __IO uint16_t UEP5_TX_LEN;
81 __IO uint8_t UEP5_TX_CTRL;
82 __IO uint8_t UEP5_RX_CTRL;
83 __IO uint16_t UEP6_TX_LEN;
84 __IO uint8_t UEP6_TX_CTRL;
85 __IO uint8_t UEP6_RX_CTRL;
86 __IO uint16_t UEP7_TX_LEN;
87 __IO uint8_t UEP7_TX_CTRL;
88 __IO uint8_t UEP7_RX_CTRL;
89 __IO uint32_t Reserve1;
90 __IO uint32_t OTG_CR;
91 __IO uint32_t OTG_SR;
93
94 #define USBOTG_FS ((USBOTG_FS_TypeDef *) 0x40023400)
95#elif CFG_TUSB_MCU == OPT_MCU_CH32V20X
96 #include <ch32v20x.h>
97#elif CFG_TUSB_MCU == OPT_MCU_CH32V307
98 #include <ch32v30x.h>
99 #define USBHD_IRQn OTG_FS_IRQn
100#endif
101
102#ifdef __GNUC__
103#pragma GCC diagnostic pop
104#endif
105
106// CTRL
107#define USBFS_CTRL_DMA_EN (1 << 0)
108#define USBFS_CTRL_CLR_ALL (1 << 1)
109#define USBFS_CTRL_RESET_SIE (1 << 2)
110#define USBFS_CTRL_INT_BUSY (1 << 3)
111#define USBFS_CTRL_SYS_CTRL (1 << 4)
112#define USBFS_CTRL_DEV_PUEN (1 << 5)
113#define USBFS_CTRL_LOW_SPEED (1 << 6)
114#define USBFS_CTRL_HOST_MODE (1 << 7)
115
116// INT_EN
117#define USBFS_INT_EN_BUS_RST (1 << 0)
118#define USBFS_INT_EN_DETECT (1 << 0)
119#define USBFS_INT_EN_TRANSFER (1 << 1)
120#define USBFS_INT_EN_SUSPEND (1 << 2)
121#define USBFS_INT_EN_HST_SOF (1 << 3)
122#define USBFS_INT_EN_FIFO_OV (1 << 4)
123#define USBFS_INT_EN_DEV_NAK (1 << 6)
124#define USBFS_INT_EN_DEV_SOF (1 << 7)
125
126// INT_FG
127#define USBFS_INT_FG_BUS_RST (1 << 0)
128#define USBFS_INT_FG_DETECT (1 << 0)
129#define USBFS_INT_FG_TRANSFER (1 << 1)
130#define USBFS_INT_FG_SUSPEND (1 << 2)
131#define USBFS_INT_FG_HST_SOF (1 << 3)
132#define USBFS_INT_FG_FIFO_OV (1 << 4)
133#define USBFS_INT_FG_SIE_FREE (1 << 5)
134#define USBFS_INT_FG_TOG_OK (1 << 6)
135#define USBFS_INT_FG_IS_NAK (1 << 7)
136
137// INT_ST
138#define USBFS_INT_ST_MASK_UIS_ENDP(x) (((x) >> 0) & 0x0F)
139#define USBFS_INT_ST_MASK_UIS_TOKEN(x) (((x) >> 4) & 0x03)
140
141// UDEV_CTRL
142#define USBFS_UDEV_CTRL_PORT_EN (1 << 0)
143#define USBFS_UDEV_CTRL_GP_BIT (1 << 1)
144#define USBFS_UDEV_CTRL_LOW_SPEED (1 << 2)
145#define USBFS_UDEV_CTRL_DM_PIN (1 << 4)
146#define USBFS_UDEV_CTRL_DP_PIN (1 << 5)
147#define USBFS_UDEV_CTRL_PD_DIS (1 << 7)
148
149// TX_CTRL
150#define USBFS_EP_T_RES_MASK (3 << 0)
151#define USBFS_EP_T_TOG (1 << 2)
152#define USBFS_EP_T_AUTO_TOG (1 << 3)
153
154#define USBFS_EP_T_RES_ACK (0 << 0)
155#define USBFS_EP_T_RES_NYET (1 << 0)
156#define USBFS_EP_T_RES_NAK (2 << 0)
157#define USBFS_EP_T_RES_STALL (3 << 0)
158
159// RX_CTRL
160#define USBFS_EP_R_RES_MASK (3 << 0)
161#define USBFS_EP_R_TOG (1 << 2)
162#define USBFS_EP_R_AUTO_TOG (1 << 3)
163
164#define USBFS_EP_R_RES_ACK (0 << 0)
165#define USBFS_EP_R_RES_NYET (1 << 0)
166#define USBFS_EP_R_RES_NAK (2 << 0)
167#define USBFS_EP_R_RES_STALL (3 << 0)
168
169// token PID
170#define PID_OUT 0
171#define PID_SOF 1
172#define PID_IN 2
173#define PID_SETUP 3
174
175#endif // USB_CH32_USBFS_REG_H
__IO uint32_t UEP5_DMA
__IO uint8_t UEP1_RX_CTRL
__IO uint8_t UEP3_RX_CTRL
__IO uint32_t UEP3_DMA
__IO uint8_t UEP4_1_MOD
__IO uint32_t UEP6_DMA
__IO uint8_t UEP5_TX_CTRL
__IO uint32_t OTG_CR
__IO uint8_t UDEV_CTRL
__IO uint8_t Reserve0
__IO uint8_t UEP2_3_MOD
__IO uint16_t UEP4_TX_LEN
__IO uint8_t UEP6_RX_CTRL
__IO uint8_t BASE_CTRL
__IO uint16_t UEP3_TX_LEN
__IO uint16_t UEP6_TX_LEN
__IO uint8_t MIS_ST
__IO uint16_t UEP7_TX_LEN
__IO uint8_t UEP2_RX_CTRL
__IO uint8_t INT_ST
__IO uint8_t UEP5_RX_CTRL
__IO uint32_t RX_LEN
__IO uint32_t OTG_SR
__IO uint8_t DEV_ADDR
__IO uint32_t UEP1_DMA
__IO uint8_t UEP5_6_MOD
__IO uint32_t UEP7_DMA
__IO uint8_t UEP2_TX_CTRL
__IO uint16_t UEP5_TX_LEN
__IO uint32_t UEP2_DMA
__IO uint8_t UEP1_TX_CTRL
__IO uint8_t UEP7_TX_CTRL
__IO uint8_t UEP7_RX_CTRL
__IO uint8_t INT_EN
__IO uint8_t UEP0_TX_CTRL
__IO uint8_t INT_FG
__IO uint32_t Reserve1
__IO uint16_t UEP0_TX_LEN
__IO uint8_t UEP0_RX_CTRL
__IO uint16_t UEP1_TX_LEN
__IO uint8_t UEP4_TX_CTRL
__IO uint32_t UEP4_DMA
__IO uint8_t UEP3_TX_CTRL
__IO uint8_t UEP4_RX_CTRL
__IO uint32_t UEP0_DMA
__IO uint16_t UEP2_TX_LEN
__IO uint8_t UEP6_TX_CTRL
__IO uint8_t UEP7_MOD