From 9cf01192336253ca7c09f4547dbffb2acd2dc652 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Fri, 30 Sep 2022 09:38:58 +0200 Subject: [PATCH] pkg/tinyusb: add tinyusb_hw_defaults.h for platform specific defaults --- boards/stm32f429i-disc1/include/periph_conf.h | 16 --- cpu/stm32/include/tinyusb_hw_defaults.h | 99 +++++++++++++++++++ pkg/tinyusb/contrib/include/tinyusb.h | 1 + pkg/tinyusb/hw/include/tinyusb_hw_defaults.h | 51 ++++++++++ 4 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 cpu/stm32/include/tinyusb_hw_defaults.h create mode 100644 pkg/tinyusb/hw/include/tinyusb_hw_defaults.h diff --git a/boards/stm32f429i-disc1/include/periph_conf.h b/boards/stm32f429i-disc1/include/periph_conf.h index 47e3f7f0dd..0e40a84a47 100644 --- a/boards/stm32f429i-disc1/include/periph_conf.h +++ b/boards/stm32f429i-disc1/include/periph_conf.h @@ -34,22 +34,6 @@ #include "cfg_timer_tim5.h" #include "cfg_usb_otg_hs_fs.h" -#ifdef MODULE_TINYUSB -/** - * @brief tinyUSB device stack uses the USB OTG HS port on this board - */ -#ifndef TINYUSB_TUD_RHPORT -#define TINYUSB_TUD_RHPORT 1 -#endif /* TINYUSB_TUD_RHPORT */ - -/** - * @brief tinyUSB host stack uses the USB OTG HS port on this board - */ -#ifndef TINYUSB_TUH_RHPORT -#define TINYUSB_TUH_RHPORT 1 -#endif /* TINYUSB_TUH_RHPORT */ -#endif /* MODULE_TINYUSB */ - #ifdef __cplusplus extern "C" { #endif diff --git a/cpu/stm32/include/tinyusb_hw_defaults.h b/cpu/stm32/include/tinyusb_hw_defaults.h new file mode 100644 index 0000000000..baa228efce --- /dev/null +++ b/cpu/stm32/include/tinyusb_hw_defaults.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2022 Gunar Schorcht + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @ingroup pkg_tinyusb + * @ingroup cpu_stm32 + * @{ + * + * @file + * @brief STM32 specific default configurations for tinyUSB + * + * @author Gunar Schorcht + */ + +#ifndef TINYUSB_HW_DEFAULTS_H +#define TINYUSB_HW_DEFAULTS_H + +#include "periph_conf.h" + +#if !DOXYGEN + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name Definition of ports used by tinyUSB host and device stack + * + * The tinyUSB device driver used for the STM32 USB-OTG controller supposes + * that the USB-OTG-FS port is port 0 and the USB-OTG-HS port is port 1. + * Therefore, the following default definitions can be used: + * + * - If both USB OTG FS and USB OTG HS ports are used, the device stack uses + * port 0 and the host stack uses port 1. + * - If only USB OTG HS is used, both the device and the host stack use port 1. + * - In all other cases, both the device and the host stack use port 0. + * This also applies if only the USB FS controller is used. + * + * @{ + */ +#if defined(DWC2_USB_OTG_HS_ENABLED) && defined(DWC2_USB_OTG_FS_ENABLED) + +#ifndef TINYUSB_TUD_RHPORT +#define TINYUSB_TUD_RHPORT 0 +#endif + +#ifndef TINYUSB_TUH_RHPORT +#define TINYUSB_TUH_RHPORT 1 +#endif + +#elif defined(DWC2_USB_OTG_HS_ENABLED) + +#ifndef TINYUSB_TUD_RHPORT +#define TINYUSB_TUD_RHPORT 1 +#endif + +#ifndef TINYUSB_TUH_RHPORT +#define TINYUSB_TUH_RHPORT 1 +#endif + +#else + +#ifndef TINYUSB_TUD_RHPORT +#define TINYUSB_TUD_RHPORT 0 +#endif + +#ifndef TINYUSB_TUH_RHPORT +#define TINYUSB_TUH_RHPORT 0 +#endif + +#endif +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* !DOXYGEN */ +#endif /* TINYUSB_HW_DEFAULTS_H */ +/** @} */ diff --git a/pkg/tinyusb/contrib/include/tinyusb.h b/pkg/tinyusb/contrib/include/tinyusb.h index e6a62e44fa..7919add266 100644 --- a/pkg/tinyusb/contrib/include/tinyusb.h +++ b/pkg/tinyusb/contrib/include/tinyusb.h @@ -20,6 +20,7 @@ #define TINYUSB_H #include "periph_conf.h" +#include "tinyusb_hw_defaults.h" #ifndef TINYUSB_THREAD_STACKSIZE_MAIN /** Stack size used for the tinyUSB thread */ diff --git a/pkg/tinyusb/hw/include/tinyusb_hw_defaults.h b/pkg/tinyusb/hw/include/tinyusb_hw_defaults.h new file mode 100644 index 0000000000..99f0dcd8f0 --- /dev/null +++ b/pkg/tinyusb/hw/include/tinyusb_hw_defaults.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 Gunar Schorcht + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/** + * @ingroup pkg_tinyusb + * @{ + * + * @file + * @brief Hardware specific default configurations for tinyUSB + * + * The platform or the board can define a file `tinyusb_hw_defaults.h` + * to define default values for tinyUSB such as `TINYUSB_TUD_RHORT` + * or `TINYUSB_TUH_RHPORT` according to the given hardware. In case + * the platform or board does not define such a file, this dummy file + * is used instead. + * + * @author Gunar Schorcht + */ + +#ifndef TINYUSB_HW_DEFAULTS_H +#define TINYUSB_HW_DEFAULTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* TINYUSB_HW_DEFAULTS_H */ +/** @} */