Skip to content

Commit

Permalink
Merge branch 'dev/idf-5.2' into develop
Browse files Browse the repository at this point in the history
* dev/idf-5.2:
  Test with rp2040, esp32s2
  Ensure HID device is ready when sendReport called
  Lazy-initialise flush timer
  UsbSerial conditional on CDC
  Don't implement descriptor callbacks unless building for device
  Enable python UTF8 mode for usbconfig tool
  Add CI support
  Move initialisation code into separate Arch source file, fix for ESP32
  Update to tinyusb master
  Revert "ESP32 broken for IDF 5.2"
  • Loading branch information
mikee47 committed Mar 19, 2024
2 parents 8df168d + fa2f8da commit 2e3e524
Show file tree
Hide file tree
Showing 21 changed files with 239 additions and 228 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI Dispatch

on:
workflow_dispatch:
inputs:
sming_repo:
description: 'Full URL for Sming repository'
default: 'https://github.com/SmingHub/Sming'
sming_branch:
description: 'Sming branch to run against'
default: 'develop'

jobs:
build:
uses: SmingHub/Sming/.github/workflows/library.yml@develop
with:
sming_repo: ${{ inputs.sming_repo }}
sming_branch: ${{ inputs.sming_branch }}
alias: USB
9 changes: 9 additions & 0 deletions .github/workflows/ci-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: CI Push

on: [push]

jobs:
build:
uses: SmingHub/Sming/.github/workflows/library.yml@develop
with:
alias: USB
125 changes: 0 additions & 125 deletions .patches/tinyusb/src/portable/template/hcd_template.c

This file was deleted.

9 changes: 3 additions & 6 deletions component.mk
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
COMPONENT_SOC := \
host \
rp2040

ifneq (v5.2,$(IDF_VERSION))
COMPONENT_SOC += \
rp2040 \
esp32s2 \
esp32s3
endif

COMPONENT_SUBMODULES := tinyusb
COMPONENT_LIBNAME :=
Expand Down Expand Up @@ -42,7 +38,7 @@ GLOBAL_CFLAGS += \
COMPONENT_VARS += USB_CONFIG
ifdef USB_CONFIG

USBCONFIG_TOOL := $(PYTHON) $(COMPONENT_PATH)/tools/usbconfig/usbconfig.py
USBCONFIG_TOOL := $(PYTHON) -Xutf8 $(COMPONENT_PATH)/tools/usbconfig/usbconfig.py

USB_OUTPUT_DIR := $(PROJECT_DIR)/$(BUILD_BASE)/USB
USB_CONFIG_H := $(USB_OUTPUT_DIR)/tusb_config.h
Expand All @@ -63,6 +59,7 @@ endif # USB_CONFIG

COMPONENT_APPCODE += \
src \
src/Arch/$(SMING_ARCH) \
$(USB_CLASS_DIRS) \
tinyusb/src \
tinyusb/src/common \
Expand Down
6 changes: 6 additions & 0 deletions samples/Basic_Device/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ C++ classes are provided for some of the standard interfaces
The MIDI device can be tested using the linux ``aplaymidi`` utility.
Type ``aplaymidi -l`` to show available devices.
Play a MIDI file with ``aplaymidi -p 24:0 test.mid``.

.. note::

This sample works as-is for the rp2040.
The esp32s2 has limited endpoints so some of the interfaces need to be commented-out in ``basic_device.usbcfg``.
Perhaps try starting with just ``midi`` interface.
2 changes: 1 addition & 1 deletion samples/Basic_Host/app/xbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

#include "xbox.h"
#include <host/usbh_classdriver.h>
#include <host/usbh_pvt.h>

namespace USB::VENDOR
{
Expand Down
8 changes: 4 additions & 4 deletions samples/CDC_MSC_HID_Host/app/cdc_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ void tuh_cdc_rx_cb(uint8_t idx)

void tuh_cdc_mount_cb(uint8_t idx)
{
tuh_cdc_itf_info_t itf_info = {0};
tuh_itf_info_t itf_info{};
tuh_cdc_itf_get_info(idx, &itf_info);

printf("CDC Interface is mounted: address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.bInterfaceNumber);
debug_i("CDC Interface is mounted: address = %u, itf_num = %u", itf_info.daddr, itf_info.desc.bInterfaceNumber);

#ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
// CFG_TUH_CDC_LINE_CODING_ON_ENUM must be defined for line coding is set by tinyusb in enumeration
Expand All @@ -75,8 +75,8 @@ void tuh_cdc_mount_cb(uint8_t idx)

void tuh_cdc_umount_cb(uint8_t idx)
{
tuh_cdc_itf_info_t itf_info{};
tuh_itf_info_t itf_info{};
tuh_cdc_itf_get_info(idx, &itf_info);

debug_i("CDC Interface is unmounted: address = %u, itf_num = %u", itf_info.daddr, itf_info.bInterfaceNumber);
debug_i("CDC Interface is unmounted: address = %u, itf_num = %u", itf_info.daddr, itf_info.desc.bInterfaceNumber);
}
78 changes: 78 additions & 0 deletions src/Arch/Esp32/init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/****
* USB.cpp
*
* Copyright 2023 mikee47 <mike@sillyhouse.net>
*
* This file is part of the Sming USB Library
*
* This library is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, version 3 or later.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this library.
* If not, see <https://www.gnu.org/licenses/>.
*
* @author: 2018 - Mikee47 <mike@sillyhouse.net>
*
****/

#include <USB.h>

#include <esp_rom_gpio.h>
#include <hal/gpio_ll.h>
#include <soc/periph_defs.h>
#include <driver/periph_ctrl.h>

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
#include <soc/usb_periph.h>
#include <soc/usb_reg.h>
#include <hal/usb_fsls_phy_hal.h>
#include <hal/usb_fsls_phy_ll.h>
#else
#include <hal/usb_ll.h>
#endif

namespace
{
void configure_pins()
{
for(auto iopin = usb_periph_iopins; iopin->pin >= 0; ++iopin) {
if(iopin->ext_phy_only) {
continue;
}
esp_rom_gpio_pad_select_gpio(iopin->pin);
if(iopin->is_output) {
esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
} else {
esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
if((iopin->pin != GPIO_MATRIX_CONST_ZERO_INPUT) && (iopin->pin != GPIO_MATRIX_CONST_ONE_INPUT)) {
gpio_ll_input_enable(&GPIO, gpio_num_t(iopin->pin));
}
}
esp_rom_gpio_pad_unhold(iopin->pin);
}
gpio_ll_set_drive_capability(&GPIO, gpio_num_t(USBPHY_DM_NUM), GPIO_DRIVE_CAP_3);
gpio_ll_set_drive_capability(&GPIO, gpio_num_t(USBPHY_DM_NUM), GPIO_DRIVE_CAP_3);
}

} // namespace

namespace USB
{
void initHardware()
{
periph_module_reset(PERIPH_USB_MODULE);
periph_module_enable(PERIPH_USB_MODULE);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
usb_fsls_phy_ll_usb_wrap_pad_enable(&USB_WRAP, true);
usb_fsls_phy_ll_int_otg_enable(&USB_WRAP);
#else
usb_ll_int_phy_enable();
#endif
configure_pins();
}

} // namespace USB
30 changes: 30 additions & 0 deletions src/Arch/Host/init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/****
* USB.cpp
*
* Copyright 2023 mikee47 <mike@sillyhouse.net>
*
* This file is part of the Sming USB Library
*
* This library is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, version 3 or later.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this library.
* If not, see <https://www.gnu.org/licenses/>.
*
* @author: 2018 - Mikee47 <mike@sillyhouse.net>
*
****/

#include <USB.h>

namespace USB
{
void initHardware()
{
}

} // namespace USB
30 changes: 30 additions & 0 deletions src/Arch/Rp2040/init.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/****
* USB.cpp
*
* Copyright 2023 mikee47 <mike@sillyhouse.net>
*
* This file is part of the Sming USB Library
*
* This library is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, version 3 or later.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this library.
* If not, see <https://www.gnu.org/licenses/>.
*
* @author: 2018 - Mikee47 <mike@sillyhouse.net>
*
****/

#include <USB.h>

namespace USB
{
void initHardware()
{
}

} // namespace USB
Loading

0 comments on commit 2e3e524

Please sign in to comment.