summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2024-05-20 17:26:04 +0700
committerhathach <[email protected]>2024-05-20 17:26:04 +0700
commitb19295c1c15de676e7cebd5bd5b6aa53887c6a56 (patch)
tree9ebb74af76ea517ba4c48225bef83861783cd693 /src
parent4a5fee503b1e3783301cde9b605ef30052623327 (diff)
use correct wch usbhs, usbfs for ch32v307 using CFG_TUD_MAX_SPEED
Diffstat (limited to 'src')
-rw-r--r--src/common/tusb_mcu.h16
-rw-r--r--src/portable/wch/ch32_usbhs_reg.h4
-rw-r--r--src/portable/wch/dcd_ch32_usbfs.c3
-rw-r--r--src/portable/wch/dcd_ch32_usbhs.c6
4 files changed, 19 insertions, 10 deletions
diff --git a/src/common/tusb_mcu.h b/src/common/tusb_mcu.h
index e313fea05..d928e44e8 100644
--- a/src/common/tusb_mcu.h
+++ b/src/common/tusb_mcu.h
@@ -404,14 +404,22 @@
//------------- WCH -------------//
#elif TU_CHECK_MCU(OPT_MCU_CH32V307)
- #define TUP_DCD_ENDPOINT_MAX 8
-// #define TUP_RHPORT_HIGHSPEED 1
+ // v307 support both FS and HS
+ #define TUP_USBIP_WCH_USBHS
+ #define TUP_USBIP_WCH_USBFS
+
+ #define TUP_RHPORT_HIGHSPEED 1 // default to highspeed
+ #define TUP_DCD_ENDPOINT_MAX (CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED ? 16 : 8)
#elif TU_CHECK_MCU(OPT_MCU_CH32F20X)
- #define TUP_DCD_ENDPOINT_MAX 16
- #define TUP_RHPORT_HIGHSPEED 1
+ #define TUP_USBIP_WCH_USBHS
+ #define TUP_USBIP_WCH_USBFS
+
+ #define TUP_RHPORT_HIGHSPEED 1 // default to highspeed
+ #define TUP_DCD_ENDPOINT_MAX (CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED ? 16 : 8)
#elif TU_CHECK_MCU(OPT_MCU_CH32V20X)
+ #define TUP_USBIP_WCH_USBFS
#define TUP_DCD_ENDPOINT_MAX 8
#endif
diff --git a/src/portable/wch/ch32_usbhs_reg.h b/src/portable/wch/ch32_usbhs_reg.h
index 9b956231f..6ae91ec71 100644
--- a/src/portable/wch/ch32_usbhs_reg.h
+++ b/src/portable/wch/ch32_usbhs_reg.h
@@ -2,9 +2,9 @@
#define _USB_CH32_USBHS_REG_H
#if (CFG_TUSB_MCU == OPT_MCU_CH32V307)
-#include <ch32v30x.h>
+ #include <ch32v30x.h>
#elif (CFG_TUSB_MCU == OPT_MCU_CH32F20X)
-#include <ch32f20x.h>
+ #include <ch32f20x.h>
#endif
/******************* GLOBAL ******************/
diff --git a/src/portable/wch/dcd_ch32_usbfs.c b/src/portable/wch/dcd_ch32_usbfs.c
index 3e4b6cae5..413fe92c9 100644
--- a/src/portable/wch/dcd_ch32_usbfs.c
+++ b/src/portable/wch/dcd_ch32_usbfs.c
@@ -1,6 +1,7 @@
#include "tusb_option.h"
-#if CFG_TUD_ENABLED && (CFG_TUSB_MCU == OPT_MCU_CH32V20X || CFG_TUSB_MCU == OPT_MCU_CH32V307)
+// Note: CH32 can have both USB FS and HS, only use this driver if CFG_TUD_MAX_SPEED is full speed
+#if CFG_TUD_ENABLED && defined(TUP_USBIP_WCH_USBFS) && (CFG_TUD_MAX_SPEED == OPT_MODE_FULL_SPEED)
#include <stdio.h>
#include "device/dcd.h"
diff --git a/src/portable/wch/dcd_ch32_usbhs.c b/src/portable/wch/dcd_ch32_usbhs.c
index 68e2179e9..9a12fc97f 100644
--- a/src/portable/wch/dcd_ch32_usbhs.c
+++ b/src/portable/wch/dcd_ch32_usbhs.c
@@ -26,11 +26,11 @@
#include "tusb_option.h"
-#if CFG_TUD_ENABLED && ((CFG_TUSB_MCU == OPT_MCU_CH32V307) || (CFG_TUSB_MCU == OPT_MCU_CH32F20X))
-#include "device/dcd.h"
-
+// Note: CH32 can have both USB FS and HS, only use this driver if CFG_TUD_MAX_SPEED is high speed
+#if CFG_TUD_ENABLED && defined(TUP_USBIP_WCH_USBHS) && (CFG_TUD_MAX_SPEED == OPT_MODE_HIGH_SPEED)
#include "ch32_usbhs_reg.h"
+#include "device/dcd.h"
// Max number of bi-directional endpoints including EP0
#define EP_MAX 16