/* Baremetal Risc-V USB <=> Amiga Joystick/Mouse HID converter. * March 2026 - Anders Holck * This software has no license. If you choose to use, please include my name :) */ #ifndef USB_DWC2_H #define USB_DWC2_H #include /* System Control Registers */ #define SYS_CTRL_BASE 0x03000000 #define CLK_EN_1 (SYS_CTRL_BASE + 0x2004) #define USB_PHY_CTRL (SYS_CTRL_BASE + 0x7000) /* USB DWC2 Register Base */ #define USB_DWC2_BASE 0x04340000 /* Global Registers */ #define GOTGCTL (USB_DWC2_BASE + 0x000) #define GOTGINT (USB_DWC2_BASE + 0x004) #define GAHBCFG (USB_DWC2_BASE + 0x008) #define GUSBCFG (USB_DWC2_BASE + 0x00C) #define GRSTCTL (USB_DWC2_BASE + 0x010) #define GINTSTS (USB_DWC2_BASE + 0x014) #define GINTMSK (USB_DWC2_BASE + 0x018) #define GRXSTSR (USB_DWC2_BASE + 0x01C) #define GRXSTSP (USB_DWC2_BASE + 0x020) #define GRXFSIZ (USB_DWC2_BASE + 0x024) #define GNPTXFSIZ (USB_DWC2_BASE + 0x028) #define GSNPSID (USB_DWC2_BASE + 0x040) #define GHWCFG1 (USB_DWC2_BASE + 0x044) #define GHWCFG2 (USB_DWC2_BASE + 0x048) #define GHWCFG3 (USB_DWC2_BASE + 0x04C) #define GHWCFG4 (USB_DWC2_BASE + 0x050) /* Device Registers */ #define DCFG (USB_DWC2_BASE + 0x800) #define DCTL (USB_DWC2_BASE + 0x804) #define DSTS (USB_DWC2_BASE + 0x808) #define DIEPMSK (USB_DWC2_BASE + 0x810) #define DOEPMSK (USB_DWC2_BASE + 0x814) #define DAINT (USB_DWC2_BASE + 0x818) #define DAINTMSK (USB_DWC2_BASE + 0x81C) /* Endpoints (EP0 is at 0x900/0xB00) */ #define DIEPCTL0 (USB_DWC2_BASE + 0x900) #define DOEPCTL0 (USB_DWC2_BASE + 0xB00) /* Register Helpers */ static inline void write32(uintptr_t addr, uint32_t val) { *(volatile uint32_t *)addr = val; } static inline uint32_t read32(uintptr_t addr) { return *(volatile uint32_t *)addr; } /* Driver Functions */ void dwc2_poll(); void dwc2_send_packet(uint8_t ep_num, const uint8_t *data, uint32_t len); #endif /* USB_DWC2_H */