Skip to content

Commit

Permalink
remove SDK calls in driver
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonlock2 committed Dec 6, 2023
1 parent 0a526ea commit b6d79e1
Showing 1 changed file with 0 additions and 19 deletions.
19 changes: 0 additions & 19 deletions src/portable/wch/dcd_ch32_usbfs.c
Expand Up @@ -3,7 +3,6 @@
#if CFG_TUD_ENABLED && (CFG_TUSB_MCU == OPT_MCU_CH32V20X)

#include <stdio.h>
#include <ch32v20x_rcc.h>
#include "tusb.h"
#include "device/dcd.h"
#include "ch32_usbfs_reg.h"
Expand Down Expand Up @@ -32,13 +31,6 @@ static struct {
} data;

/* private helpers */
#if (CFG_TUSB_OS != OPT_OS_FREERTOS) // TODO use SDK way
__attribute__((interrupt))
#endif
static void usb_handler(void) {
tud_int_handler(0);
}

static void update_in(uint8_t rhport, uint8_t ep, bool force) {
struct usb_xfer *xfer = &data.xfer[ep][TUSB_DIR_IN];
if (xfer->valid) {
Expand Down Expand Up @@ -91,24 +83,13 @@ static void update_out(uint8_t rhport, uint8_t ep, size_t rx_len) {

/* public functions */
void dcd_init(uint8_t rhport) {
// TODO move into bsp!
// enable clock
switch (SystemCoreClock) {
case 48000000: RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_Div1); break;
case 96000000: RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_Div2); break;
case 144000000: RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_Div3); break;
default: TU_ASSERT(0,); break;
}
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_OTG_FS, ENABLE);

// init registers
USBOTG_FS->BASE_CTRL = USBFS_CTRL_SYS_CTRL | USBFS_CTRL_INT_BUSY | USBFS_CTRL_DMA_EN;
USBOTG_FS->UDEV_CTRL = USBFS_UDEV_CTRL_PD_DIS | USBFS_UDEV_CTRL_PORT_EN;
USBOTG_FS->DEV_ADDR = 0x00;

USBOTG_FS->INT_FG = 0xFF;
USBOTG_FS->INT_EN = USBFS_INT_EN_BUS_RST | USBFS_INT_EN_TRANSFER | USBFS_INT_EN_SUSPEND;
NVIC_SetVector(USBHD_IRQn, usb_handler); // TODO use SDK more directly

// setup endpoint 0
EP_DMA(0) = (uint32_t) &data.buffer[0][0];
Expand Down

0 comments on commit b6d79e1

Please sign in to comment.