1 /*
2  * Copyright (c) 2024, sakumisu
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include "usb_config.h"
7 #include "stdint.h"
8 #include "usb_dwc2_reg.h"
9 
10 #if 1
11 #error you need to modify some usb register values then use this chip
12 #endif
13 
14 #if CONFIG_USBDEV_EP_NUM != 4 && CONFIG_USBDEV_EP_NUM != 6
15 #error "gd32 only has 4 endpoints for pa11/pa12 and 6 endpoints for pb14/pb15"
16 #endif
17 
18 /* you can find this config in function:usb_core_init, file:drv_usb_core.c, for example:
19  *
20  *  usb_regs->gr->GCCFG |= GCCFG_PWRON | GCCFG_VBUSACEN | GCCFG_VBUSBCEN;
21  *
22 */
23 
usbd_get_dwc2_gccfg_conf(uint32_t reg_base)24 uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
25 {
26 #ifdef CONFIG_USB_HS
27     return 0;
28 #else
29     return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
30 #endif
31 }
32 
usbh_get_dwc2_gccfg_conf(uint32_t reg_base)33 uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
34 {
35 #ifdef CONFIG_USB_HS
36     return 0;
37 #else
38     return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
39 #endif
40 }
41 
42 extern uint32_t SystemCoreClock;
43 
usbd_dwc2_delay_ms(uint8_t ms)44 void usbd_dwc2_delay_ms(uint8_t ms)
45 {
46     uint32_t count = SystemCoreClock / 1000 * ms;
47     while (count--) {
48         __asm volatile("nop");
49     }
50 }
51