Skip to content

Commit

Permalink
Merge pull request #2639 from Rbb666/rtthread
Browse files Browse the repository at this point in the history
[osal]add usb host script of RT-Thread to USB HOST.
  • Loading branch information
HiFiPhile authored May 11, 2024
2 parents 3e2ea77 + 4cecb75 commit d707ea5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 20 deletions.
52 changes: 32 additions & 20 deletions lib/rt-thread/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,44 @@ cwd = GetCurrentDir()
src = Split("""
../../src/tusb.c
../../src/common/tusb_fifo.c
../../src/device/usbd.c
../../src/device/usbd_control.c
./tusb_rt_thread_port.c
""")
path = [cwd, cwd + "/../../src"]

# BSP
if GetDepend(["SOC_FAMILY_STM32"]):
src += ["../../src/portable/synopsys/dwc2/dcd_dwc2.c",
"../../src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c"]

if GetDepend(["SOC_NRF52840"]):
src += ["../../src/portable/nordic/nrf5x/dcd_nrf5x.c"]

if GetDepend(["SOC_FAMILY_RENESAS"]):
src += ["../../src/portable/renesas/rusb2/dcd_rusb2.c",
"../../src/portable/renesas/rusb2/rusb2_common.c"]

# Device class
if GetDepend(["PKG_TINYUSB_DEVICE_CDC"]):
src += ["../../src/class/cdc/cdc_device.c"]
LOCAL_CFLAGS = ''

if GetDepend(["PKG_TINYUSB_DEVICE_MSC"]):
src += ["../../src/class/msc/msc_device.c", "port/msc_device_port.c"]
# for device stack
if GetDepend(["PKG_TINYUSB_DEVICE_ENABLE"]):
src += ["../../src/device/usbd.c",
"../../src/device/usbd_control.c"]
# BSP
if GetDepend(["SOC_FAMILY_STM32"]):
src += ["../../src/portable/synopsys/dwc2/dcd_dwc2.c",
"../../src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c"]

if GetDepend(["SOC_NRF52840"]):
src += ["../../src/portable/nordic/nrf5x/dcd_nrf5x.c"]

if GetDepend(["SOC_FAMILY_RENESAS"]):
src += ["../../src/portable/renesas/rusb2/dcd_rusb2.c",
"../../src/portable/renesas/rusb2/rusb2_common.c"]

# Device class
if GetDepend(["PKG_TINYUSB_DEVICE_UVC"]):
src += ["../../src/class/video/video_device.c"]
if GetDepend(["PKG_TINYUSB_DEVICE_CDC"]):
src += ["../../src/class/cdc/cdc_device.c"]
if GetDepend(["PKG_TINYUSB_DEVICE_MSC"]):
src += ["../../src/class/msc/msc_device.c", "port/msc_device_port.c"]

# for host stack
if GetDepend(["PKG_TINYUSB_HOST_ENABLE"]):
src += ["../../src/host/usbh.c", "../../src/host/hub.c"]

if GetDepend(["SOC_FAMILY_RENESAS"]):
src += ["../../src/portable/renesas/rusb2/hcd_rusb2.c",
"../../src/portable/renesas/rusb2/rusb2_common.c"]

LOCAL_CFLAGS = ''

if rtconfig.PLATFORM == 'gcc' or rtconfig.PLATFORM == 'armclang': # GCC or Keil AC6
LOCAL_CFLAGS += ' -std=c99'
Expand Down
71 changes: 71 additions & 0 deletions lib/rt-thread/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ extern "C" {
//--------------------------------------------------------------------
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
#if defined(PKG_TINYUSB_DEVICE_ENABLE)
#define CFG_TUD_ENABLED (1)
#else
#define CFG_TUD_ENABLED (0)
#endif

#ifndef CFG_TUD_ENDPOINT0_SIZE
#define CFG_TUD_ENDPOINT0_SIZE PKG_TINYUSB_EDPT0_SIZE
Expand All @@ -138,6 +143,72 @@ extern "C" {
#define PKG_TINYUSB_DEVICE_HID_STRING ""
#endif

//--------------------------------------------------------------------
// HOST CONFIGURATION
//--------------------------------------------------------------------
#if defined(PKG_TINYUSB_HOST_ENABLE)
#define CFG_TUH_ENABLED (1)
#else
#define CFG_TUH_ENABLED (0)
#endif

#if (PKG_TINYUSB_HOST_PORT == 0)
#undef CFG_TUSB_RHPORT0_MODE
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | PKG_TINYUSB_HOST_PORT_SPEED)
#endif

#if (PKG_TINYUSB_HOST_PORT == 1)
#undef CFG_TUSB_RHPORT1_MODE
#define CFG_TUSB_RHPORT1_MODE (OPT_MODE_HOST | PKG_TINYUSB_HOST_PORT_SPEED)
#endif

#define BOARD_TUH_RHPORT PKG_TINYUSB_HOST_PORT // FULL SPEED
#define BOARD_TUH_MAX_SPEED PKG_TINYUSB_HOST_PORT_SPEED
// Default is max speed that hardware controller could support with on-chip PHY
#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED

//------------------------- Board Specific --------------------------

// RHPort number used for host can be defined by board.mk, default to port 0
#ifndef BOARD_TUH_RHPORT
#define BOARD_TUH_RHPORT 0
#endif

// RHPort max operational speed can defined by board.mk
#ifndef BOARD_TUH_MAX_SPEED
#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
#endif

// Size of buffer to hold descriptors and other data used for enumeration
#define CFG_TUH_ENUMERATION_BUFSIZE 256

#define CFG_TUH_HUB 2 // number of supported hubs
#define CFG_TUH_CDC 0 // CDC ACM
#define CFG_TUH_CDC_FTDI 0 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_CP210X 0 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_CH34X 0 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_HID 0 // typical keyboard + mouse device can have 3-4 HID interfaces
#define CFG_TUH_MSC 0
//#define CFG_TUH_VENDOR 3

// max device support (excluding hub device): 1 hub typically has 4 ports
#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1)

//------------- HID -------------//
#define CFG_TUH_HID_EPIN_BUFSIZE 64
#define CFG_TUH_HID_EPOUT_BUFSIZE 64

//------------- CDC -------------//

// Set Line Control state on enumeration/mounted:
// DTR ( bit 0), RTS (bit 1)
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03

// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
#define CFG_TUH_CDC_LINE_CODING_ON_ENUM { 115200, CDC_LINE_CODING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }



#ifdef __cplusplus
}
Expand Down
5 changes: 5 additions & 0 deletions lib/rt-thread/tusb_rt_thread_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ static void tusb_thread_entry(void *parameter)
(void) parameter;
while (1)
{
#if CFG_TUH_ENABLED
tuh_task();
#endif
#if CFG_TUD_ENABLED
tud_task();
#endif
}
}

Expand Down

0 comments on commit d707ea5

Please sign in to comment.