├── CMakeLists.txt ├── LICENSE ├── README.md ├── build ├── bootloader │ └── bootloader.bin ├── esp32_s2_dmx.bin └── partition_table │ └── partition-table.bin ├── components └── tinyusb │ ├── CMakeLists.txt │ ├── Kconfig │ ├── additions │ ├── include │ │ ├── tinyusb.h │ │ ├── tinyusb_types.h │ │ ├── tusb_cdc_acm.h │ │ ├── tusb_config.h │ │ ├── tusb_console.h │ │ ├── tusb_hid_gamepad.h │ │ ├── tusb_tasks.h │ │ └── vfs_tinyusb.h │ ├── include_private │ │ ├── cdc.h │ │ ├── descriptors_control.h │ │ └── usb_descriptors.h │ └── src │ │ ├── cdc.c │ │ ├── descriptors_control.c │ │ ├── tinyusb.c │ │ ├── tusb_cdc_acm.c │ │ ├── tusb_console.c │ │ ├── tusb_hid_gamepad.c │ │ ├── tusb_tasks.c │ │ ├── usb_descriptors.c │ │ └── vfs_tinyusb.c │ ├── sdkconfig.rename │ └── tinyusb │ ├── .gitattributes │ ├── .github │ ├── ISSUE_TEMPLATE │ │ ├── bug_report.md │ │ ├── config.yml │ │ └── feature_request.md │ ├── pull_request_template.md │ └── workflows │ │ ├── build.yml │ │ └── trigger.yml │ ├── .gitignore │ ├── .gitmodules │ ├── CODE_OF_CONDUCT.md │ ├── CONTRIBUTORS.md │ ├── LICENSE │ ├── README.md │ ├── docs │ ├── boards.md │ ├── changelog.md │ ├── concurrency.md │ ├── getting_started.md │ └── porting.md │ ├── hw │ └── bsp │ │ ├── esp32s2 │ │ ├── boards │ │ │ ├── CMakeLists.txt │ │ │ ├── adafruit_feather_esp32s2 │ │ │ │ ├── board.cmake │ │ │ │ └── board.h │ │ │ ├── adafruit_magtag_29gray │ │ │ │ ├── board.cmake │ │ │ │ └── board.h │ │ │ ├── adafruit_metro_esp32s2 │ │ │ │ ├── board.cmake │ │ │ │ └── board.h │ │ │ ├── esp32s2.c │ │ │ ├── espressif_kaluga_1 │ │ │ │ ├── board.cmake │ │ │ │ └── board.h │ │ │ └── espressif_saola_1 │ │ │ │ ├── board.cmake │ │ │ │ └── board.h │ │ ├── family.cmake │ │ └── family.mk │ │ └── esp32s3 │ │ ├── boards │ │ ├── CMakeLists.txt │ │ ├── esp32s3.c │ │ └── espressif_addax_1 │ │ │ ├── board.cmake │ │ │ └── board.h │ │ ├── family.cmake │ │ └── family.mk │ ├── lib │ ├── SEGGER_RTT │ │ ├── License.txt │ │ ├── README.txt │ │ ├── RTT │ │ │ ├── SEGGER_RTT.c │ │ │ ├── SEGGER_RTT.h │ │ │ ├── SEGGER_RTT_ASM_ARMv7M.S │ │ │ ├── SEGGER_RTT_Conf.h │ │ │ └── SEGGER_RTT_printf.c │ │ └── Syscalls │ │ │ ├── SEGGER_RTT_Syscalls_GCC.c │ │ │ ├── SEGGER_RTT_Syscalls_IAR.c │ │ │ ├── SEGGER_RTT_Syscalls_KEIL.c │ │ │ └── SEGGER_RTT_Syscalls_SES.c │ ├── fatfs │ │ ├── 00readme.txt │ │ ├── ccsbcs.c │ │ ├── diskio.c │ │ ├── diskio.h │ │ ├── ff.c │ │ ├── ff.h │ │ ├── ffconf.h │ │ └── integer.h │ └── networking │ │ ├── dhserver.c │ │ ├── dhserver.h │ │ ├── dnserver.c │ │ ├── dnserver.h │ │ ├── ndis.h │ │ ├── rndis_protocol.h │ │ └── rndis_reports.c │ ├── pkg.yml │ ├── repository.yml │ ├── src │ ├── class │ │ ├── audio │ │ │ ├── audio.h │ │ │ ├── audio_device.c │ │ │ └── audio_device.h │ │ ├── bth │ │ │ ├── bth_device.c │ │ │ └── bth_device.h │ │ ├── cdc │ │ │ ├── cdc.h │ │ │ ├── cdc_device.c │ │ │ ├── cdc_device.h │ │ │ ├── cdc_host.c │ │ │ ├── cdc_host.h │ │ │ ├── cdc_rndis.h │ │ │ ├── cdc_rndis_host.c │ │ │ └── cdc_rndis_host.h │ │ ├── dfu │ │ │ ├── dfu_rt_device.c │ │ │ └── dfu_rt_device.h │ │ ├── hid │ │ │ ├── hid.h │ │ │ ├── hid_device.c │ │ │ ├── hid_device.h │ │ │ ├── hid_host.c │ │ │ └── hid_host.h │ │ ├── midi │ │ │ ├── midi.h │ │ │ ├── midi_device.c │ │ │ └── midi_device.h │ │ ├── msc │ │ │ ├── msc.h │ │ │ ├── msc_device.c │ │ │ ├── msc_device.h │ │ │ ├── msc_host.c │ │ │ └── msc_host.h │ │ ├── net │ │ │ ├── net_device.c │ │ │ └── net_device.h │ │ ├── usbtmc │ │ │ ├── usbtmc.h │ │ │ ├── usbtmc_device.c │ │ │ └── usbtmc_device.h │ │ └── vendor │ │ │ ├── vendor_device.c │ │ │ ├── vendor_device.h │ │ │ ├── vendor_host.c │ │ │ └── vendor_host.h │ ├── common │ │ ├── tusb_common.h │ │ ├── tusb_compiler.h │ │ ├── tusb_error.h │ │ ├── tusb_fifo.c │ │ ├── tusb_fifo.h │ │ ├── tusb_timeout.h │ │ ├── tusb_types.h │ │ └── tusb_verify.h │ ├── device │ │ ├── dcd.h │ │ ├── usbd.c │ │ ├── usbd.h │ │ ├── usbd_control.c │ │ └── usbd_pvt.h │ ├── host │ │ ├── hcd.h │ │ ├── hub.c │ │ ├── hub.h │ │ ├── usbh.c │ │ ├── usbh.h │ │ ├── usbh_control.c │ │ └── usbh_hcd.h │ ├── osal │ │ ├── osal.h │ │ ├── osal_freertos.h │ │ ├── osal_mynewt.h │ │ ├── osal_none.h │ │ ├── osal_pico.h │ │ └── osal_rtthread.h │ ├── portable │ │ └── espressif │ │ │ └── esp32sx │ │ │ └── dcd_esp32sx.c │ ├── tusb.c │ ├── tusb.h │ └── tusb_option.h │ ├── tinyusb.Doxyfile │ ├── tools │ ├── build_board.py │ ├── build_esp32sx.py │ ├── build_family.py │ ├── top.mk │ └── usb_drivers │ │ └── tinyusb_win_usbser.inf │ └── version.yml ├── main ├── CMakeLists.txt └── main.c ├── sdkconfig └── testapp ├── Makefile ├── dmx512testapp.c ├── hidapi.c └── hidapi.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | # set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/system/console/advanced/components) 6 | set(EXTRA_COMPONENT_DIRS components) 7 | 8 | 9 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 10 | project(esp32_s2_dmx) 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 CNLohr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP32-S2 USB DMX-512 Controller 2 | 3 | Designed for non-admin use from Linux or Windows. 4 | 5 | Maps as a MAGFest Swadge. 6 | 7 | D+ is on GPIO17 and D- is on GPIO18. 8 | 9 | See demo on how to send DMX-512 frames in the testapp folder. 10 | 11 | Note that this has a unique "serial" and that should be what is `hid_open`ed. 12 | 13 | ## Build 14 | 15 | Build against IDF v4.4.1 16 | 17 | ## Flash 18 | 19 | (From build folder) 20 | ``` 21 | esptool.py esp32s2 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=hard_reset write_flash --flash_mode dio --flash_freq 80m --flash_size 2MB 0x1000 bootloader/bootloader.bin 0x10000 esp32_s2_dmx.bin 0x8000 partition_table/partition-table.bin 22 | ``` 23 | 24 | 25 | -------------------------------------------------------------------------------- /build/bootloader/bootloader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cnlohr/esp32s2_dmx512_usb/8a7962e2aa3ab2450d48b570219491455aee2f08/build/bootloader/bootloader.bin -------------------------------------------------------------------------------- /build/esp32_s2_dmx.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cnlohr/esp32s2_dmx512_usb/8a7962e2aa3ab2450d48b570219491455aee2f08/build/esp32_s2_dmx.bin -------------------------------------------------------------------------------- /build/partition_table/partition-table.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cnlohr/esp32s2_dmx512_usb/8a7962e2aa3ab2450d48b570219491455aee2f08/build/partition_table/partition-table.bin -------------------------------------------------------------------------------- /components/tinyusb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_build_get_property(target IDF_TARGET) 2 | 3 | set(srcs) 4 | set(includes_public) 5 | set(includes_private) 6 | set(compile_options) 7 | 8 | if(CONFIG_TINYUSB) 9 | if(target STREQUAL "esp32s3") 10 | set(tusb_mcu "OPT_MCU_ESP32S3") 11 | set(tusb_family "esp32sx") 12 | elseif(target STREQUAL "esp32s2") 13 | set(tusb_mcu "OPT_MCU_ESP32S2") 14 | set(tusb_family "esp32sx") 15 | else() 16 | # CONFIG_TINYUSB dependency has been garanteed by Kconfig logic, 17 | # So it's not possible that cmake goes here 18 | message(FATAL_ERROR "TinyUSB is not support on ${target}.") 19 | return() 20 | endif() 21 | 22 | list(APPEND compile_options 23 | "-DCFG_TUSB_MCU=${tusb_mcu}" 24 | "-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}" 25 | ) 26 | 27 | idf_component_get_property(freertos_component_dir freertos COMPONENT_DIR) 28 | 29 | list(APPEND includes_private 30 | "tinyusb/hw/bsp/" 31 | "tinyusb/src/" 32 | "tinyusb/src/device" 33 | "additions/include_private" 34 | ) 35 | 36 | list(APPEND includes_public 37 | "tinyusb/src/" 38 | "additions/include" 39 | # The FreeRTOS API include convention in tinyusb is different from esp-idf 40 | "${freertos_component_dir}/include/freertos" 41 | ) 42 | 43 | list(APPEND srcs 44 | "tinyusb/src/portable/espressif/${tusb_family}/dcd_${tusb_family}.c" 45 | "tinyusb/src/class/cdc/cdc_device.c" 46 | "tinyusb/src/class/hid/hid_device.c" 47 | "tinyusb/src/class/midi/midi_device.c" 48 | "tinyusb/src/class/msc/msc_device.c" 49 | "tinyusb/src/class/vendor/vendor_device.c" 50 | "tinyusb/src/common/tusb_fifo.c" 51 | "tinyusb/src/device/usbd_control.c" 52 | "tinyusb/src/device/usbd.c" 53 | "tinyusb/src/tusb.c" 54 | "additions/src/descriptors_control.c" 55 | "additions/src/tinyusb.c" 56 | "additions/src/tusb_tasks.c" 57 | "additions/src/usb_descriptors.c" 58 | ) 59 | 60 | # when no builtin class driver is enabled, an uint8_t data compared with `BUILTIN_DRIVER_COUNT` will always be false 61 | set_source_files_properties("tinyusb/src/device/usbd.c" PROPERTIES COMPILE_FLAGS "-Wno-type-limits") 62 | 63 | if(CONFIG_TINYUSB_CDC_ENABLED) 64 | list(APPEND srcs 65 | "additions/src/cdc.c" 66 | "additions/src/tusb_cdc_acm.c" 67 | "additions/src/tusb_console.c" 68 | "additions/src/vfs_tinyusb.c" 69 | ) 70 | endif() # CONFIG_TINYUSB_CDC_ENABLED 71 | 72 | if(CONFIG_TINYUSB_HID_ENABLED) 73 | list(APPEND srcs 74 | "additions/src/tusb_hid_gamepad.c" 75 | ) 76 | endif() # CONFIG_TINYUSB_CDC_ENABLED 77 | 78 | endif() # CONFIG_TINYUSB 79 | 80 | idf_component_register(SRCS ${srcs} 81 | INCLUDE_DIRS ${includes_public} 82 | PRIV_INCLUDE_DIRS ${includes_private} 83 | PRIV_REQUIRES "vfs" "usb" 84 | REQUIRES "freertos" 85 | ) 86 | 87 | if(CONFIG_TINYUSB) 88 | target_compile_options(${COMPONENT_LIB} PRIVATE ${compile_options}) 89 | endif() 90 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include/tinyusb.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "tusb.h" 19 | #include "tusb_option.h" 20 | #include "tusb_config.h" 21 | #include "tinyusb_types.h" 22 | 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | /* tinyusb uses buffers with type of uint8_t[] but in our driver we are reading them as a 32-bit word */ 30 | #if (CFG_TUD_ENDPOINT0_SIZE < 4) 31 | # define CFG_TUD_ENDPOINT0_SIZE 4 32 | # warning "CFG_TUD_ENDPOINT0_SIZE was too low and was set to 4" 33 | #endif 34 | 35 | #if TUSB_OPT_DEVICE_ENABLED 36 | 37 | # if CFG_TUD_HID 38 | # if (CFG_TUD_HID_BUFSIZE < 4) 39 | # define CFG_TUD_HID_BUFSIZE 4 40 | # warning "CFG_TUD_HID_BUFSIZE was too low and was set to 4" 41 | # endif 42 | # endif 43 | 44 | # if CFG_TUD_CDC 45 | # if (CFG_TUD_CDC_EP_BUFSIZE < 4) 46 | # define CFG_TUD_CDC_EP_BUFSIZE 4 47 | # warning "CFG_TUD_CDC_EP_BUFSIZE was too low and was set to 4" 48 | # endif 49 | # endif 50 | 51 | # if CFG_TUD_MSC 52 | # if (CFG_TUD_MSC_BUFSIZE < 4) 53 | # define CFG_TUD_MSC_BUFSIZE 4 54 | # warning "CFG_TUD_MSC_BUFSIZE was too low and was set to 4" 55 | # endif 56 | # endif 57 | 58 | # if CFG_TUD_MIDI 59 | # if (CFG_TUD_MIDI_EPSIZE < 4) 60 | # define CFG_TUD_MIDI_EPSIZE 4 61 | # warning "CFG_TUD_MIDI_EPSIZE was too low and was set to 4" 62 | # endif 63 | # endif 64 | 65 | # if CFG_TUD_CUSTOM_CLASS 66 | # warning "Please check that the buffer is more then 4 bytes" 67 | # endif 68 | #endif 69 | 70 | /** 71 | * @brief Configuration structure of the tinyUSB core 72 | */ 73 | typedef struct { 74 | tusb_desc_device_t *descriptor; /*!< Pointer to a device descriptor */ 75 | const char **string_descriptor; /*!< Pointer to an array of string descriptors */ 76 | bool external_phy; /*!< Should USB use an external PHY */ 77 | } tinyusb_config_t; 78 | 79 | /** 80 | * @brief This is an all-in-one helper function, including: 81 | * 1. USB device driver initialization 82 | * 2. Descriptors preparation 83 | * 3. TinyUSB stack initialization 84 | * 4. Creates and start a task to handle usb events 85 | * 86 | * @note Don't change Custom descriptor, but if it has to be done, 87 | * Suggest to define as follows in order to match the Interface Association Descriptor (IAD): 88 | * bDeviceClass = TUSB_CLASS_MISC, 89 | * bDeviceSubClass = MISC_SUBCLASS_COMMON, 90 | * 91 | * @param config tinyusb stack specific configuration 92 | * @retval ESP_ERR_INVALID_ARG Install driver and tinyusb stack failed because of invalid argument 93 | * @retval ESP_FAIL Install driver and tinyusb stack failed because of internal error 94 | * @retval ESP_OK Install driver and tinyusb stack successfully 95 | */ 96 | esp_err_t tinyusb_driver_install(const tinyusb_config_t *config); 97 | 98 | // TODO esp_err_t tinyusb_driver_uninstall(void); (IDF-1474) 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include/tinyusb_types.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) Co. Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #define USB_ESPRESSIF_VID 0x303A 22 | #define USB_STRING_DESCRIPTOR_ARRAY_SIZE 7 23 | 24 | typedef enum{ 25 | TINYUSB_USBDEV_0, 26 | } tinyusb_usbdev_t; 27 | 28 | typedef const char *tusb_desc_strarray_device_t[USB_STRING_DESCRIPTOR_ARRAY_SIZE]; 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include/tusb_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org), 5 | * Additions Copyright (c) 2020, Espressif Systems (Shanghai) PTE LTD 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "tusb_option.h" 30 | #include "sdkconfig.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifndef CONFIG_TINYUSB_CDC_ENABLED 37 | # define CONFIG_TINYUSB_CDC_ENABLED 0 38 | #endif 39 | 40 | #ifndef CONFIG_TINYUSB_MSC_ENABLED 41 | # define CONFIG_TINYUSB_MSC_ENABLED 0 42 | #endif 43 | 44 | #ifndef CONFIG_TINYUSB_HID_ENABLED 45 | # define CONFIG_TINYUSB_HID_ENABLED 0 46 | #endif 47 | 48 | #ifndef CONFIG_TINYUSB_MIDI_ENABLED 49 | # define CONFIG_TINYUSB_MIDI_ENABLED 0 50 | #endif 51 | 52 | #ifndef CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 53 | # define CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 0 54 | #endif 55 | 56 | #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE | OPT_MODE_FULL_SPEED 57 | #define CFG_TUSB_OS OPT_OS_FREERTOS 58 | 59 | /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. 60 | * Tinyusb use follows macros to declare transferring memory so that they can be put 61 | * into those specific section. 62 | * e.g 63 | * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) 64 | * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) 65 | */ 66 | #ifndef CFG_TUSB_MEM_SECTION 67 | # define CFG_TUSB_MEM_SECTION 68 | #endif 69 | 70 | #ifndef CFG_TUSB_MEM_ALIGN 71 | # define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4) 72 | #endif 73 | 74 | #ifndef CFG_TUD_ENDPOINT0_SIZE 75 | #define CFG_TUD_ENDPOINT0_SIZE 64 76 | #endif 77 | 78 | // CDC FIFO size of TX and RX 79 | #define CFG_TUD_CDC_RX_BUFSIZE CONFIG_TINYUSB_CDC_RX_BUFSIZE 80 | #define CFG_TUD_CDC_TX_BUFSIZE CONFIG_TINYUSB_CDC_TX_BUFSIZE 81 | 82 | // MSC Buffer size of Device Mass storage 83 | #define CFG_TUD_MSC_BUFSIZE CONFIG_TINYUSB_MSC_BUFSIZE 84 | 85 | // HID buffer size Should be sufficient to hold ID (if any) + Data 86 | #define CFG_TUD_HID_BUFSIZE CONFIG_TINYUSB_HID_BUFSIZE 87 | 88 | // Enabled device class driver 89 | #define CFG_TUD_CDC CONFIG_TINYUSB_CDC_ENABLED 90 | #define CFG_TUD_MSC CONFIG_TINYUSB_MSC_ENABLED 91 | #define CFG_TUD_HID CONFIG_TINYUSB_HID_ENABLED 92 | #define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_ENABLED 93 | #define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include/tusb_console.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) Co. Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include "esp_err.h" 22 | 23 | /** 24 | * @brief Redirect output to the USB serial 25 | * @param cdc_intf - interface number of TinyUSB's CDC 26 | * 27 | * @return esp_err_t - ESP_OK, ESP_FAIL or an error code 28 | */ 29 | esp_err_t esp_tusb_init_console(int cdc_intf); 30 | 31 | /** 32 | * @brief Switch log to the default output 33 | * @param cdc_intf - interface number of TinyUSB's CDC 34 | * 35 | * @return esp_err_t 36 | */ 37 | esp_err_t esp_tusb_deinit_console(int cdc_intf); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include/tusb_hid_gamepad.h: -------------------------------------------------------------------------------- 1 | #ifndef _TUSB_HID_GAMEPAD_H_ 2 | #define _TUSB_HID_GAMEPAD_H_ 3 | 4 | #include "class/hid/hid_device.h" 5 | 6 | void tud_gamepad_report(hid_gamepad_report_t * report); 7 | void tud_gamepad_ns_report(hid_gamepad_ns_report_t * report); 8 | 9 | #endif /* _TUSB_HID_GAMEPAD_H_ */ -------------------------------------------------------------------------------- /components/tinyusb/additions/include/tusb_tasks.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "esp_err.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * @brief This helper function creates and starts a task which wraps `tud_task()`. 25 | * 26 | * The wrapper function basically wraps tud_task and some log. 27 | * Default parameters: stack size and priority as configured, argument = NULL, not pinned to any core. 28 | * If you have more requirements for this task, you can create your own task which calls tud_task as the last step. 29 | * 30 | * @retval ESP_OK run tinyusb main task successfully 31 | * @retval ESP_FAIL run tinyusb main task failed of internal error 32 | * @retval ESP_ERR_INVALID_STATE tinyusb main task has been created before 33 | */ 34 | esp_err_t tusb_run_task(void); 35 | 36 | /** 37 | * @brief This helper function stops and destroys the task created by `tusb_run_task()` 38 | * 39 | * @retval ESP_OK stop and destory tinyusb main task successfully 40 | * @retval ESP_ERR_INVALID_STATE tinyusb main task hasn't been created yet 41 | */ 42 | esp_err_t tusb_stop_task(void); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include/vfs_tinyusb.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) Co. Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "esp_err.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * @brief Register TinyUSB CDC at VFS with path 25 | * @param cdc_intf - interface number of TinyUSB's CDC 26 | * @param path - path where the CDC will be registered, `/dev/tusb_cdc` will be used if left NULL. 27 | * 28 | * @return esp_err_t ESP_OK or ESP_FAIL 29 | */ 30 | esp_err_t esp_vfs_tusb_cdc_register(int cdc_intf, char const *path); 31 | 32 | /** 33 | * @brief Unregister TinyUSB CDC from VFS 34 | * @param path - path where the CDC will be unregistered if NULL will be used `/dev/tusb_cdc` 35 | * 36 | * @return esp_err_t ESP_OK or ESP_FAIL 37 | */ 38 | esp_err_t esp_vfs_tusb_cdc_unregister(char const *path); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include_private/cdc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) Co. Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include 22 | #include "freertos/FreeRTOS.h" 23 | #include "freertos/ringbuf.h" 24 | #include "freertos/semphr.h" 25 | #include "freertos/timers.h" 26 | #include "tusb.h" 27 | #include "tinyusb_types.h" 28 | 29 | /* CDC classification 30 | ********************************************************************* */ 31 | typedef enum { 32 | TINYUSB_CDC_DATA = 0x00, 33 | } cdc_data_sublcass_type_t; // CDC120 specification 34 | 35 | /* Note:other classification is represented in the file components\tinyusb\tinyusb\src\class\cdc\cdc.h */ 36 | 37 | /*********************************************************************** CDC classification*/ 38 | /* Structs 39 | ********************************************************************* */ 40 | typedef struct { 41 | tinyusb_usbdev_t usb_dev; /*!< USB device to set up */ 42 | tusb_class_code_t cdc_class; /*!< CDC device class : Communications or Data device */ 43 | union { 44 | cdc_comm_sublcass_type_t comm_subclass; /*!< Communications device subclasses: AMC, ECM, etc. */ 45 | cdc_data_sublcass_type_t data_subclass; /*!< Data device has only one subclass.*/ 46 | } cdc_subclass; /*!< CDC device subclass according to Class Definitions for Communications Devices the CDC v.1.20 */ 47 | } tinyusb_config_cdc_t; /*!< Main configuration structure of a CDC device */ 48 | 49 | typedef struct { 50 | tinyusb_usbdev_t usb_dev; /*!< USB device used for the instance */ 51 | tusb_class_code_t type; 52 | union { 53 | cdc_comm_sublcass_type_t comm_subclass; /*!< Communications device subclasses: AMC, ECM, etc. */ 54 | cdc_data_sublcass_type_t data_subclass; /*!< Data device has only one subclass.*/ 55 | } cdc_subclass; /*!< CDC device subclass according to Class Definitions for Communications Devices the CDC v.1.20 */ 56 | void *subclass_obj; /*!< Dynamically allocated subclass specific object */ 57 | } esp_tusb_cdc_t; 58 | /*********************************************************************** Structs*/ 59 | /* Functions 60 | ********************************************************************* */ 61 | /** 62 | * @brief Initializing CDC basic object 63 | * @param itf - number of a CDC object 64 | * @param cfg - CDC configuration structure 65 | * 66 | * @return esp_err_t ESP_OK or ESP_FAIL 67 | */ 68 | esp_err_t tinyusb_cdc_init(int itf, const tinyusb_config_cdc_t *cfg); 69 | 70 | 71 | /** 72 | * @brief De-initializing CDC. Clean its objects 73 | * @param itf - number of a CDC object 74 | * @return esp_err_t ESP_OK, ESP_ERR_INVALID_ARG, ESP_ERR_INVALID_STATE 75 | * 76 | */ 77 | esp_err_t tinyusb_cdc_deinit(int itf); 78 | 79 | 80 | /** 81 | * @brief Checks if the CDC initialized and ready to interaction 82 | * 83 | * @return true or false 84 | */ 85 | bool tinyusb_cdc_initialized(int itf); 86 | 87 | 88 | /** 89 | * @brief Return interface of a CDC device 90 | * 91 | * @param itf_num 92 | * @return esp_tusb_cdc_t* pointer to the interface or (NULL) on error 93 | */ 94 | esp_tusb_cdc_t *tinyusb_cdc_get_intf(int itf_num); 95 | /*********************************************************************** Functions*/ 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include_private/descriptors_control.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "usb_descriptors.h" 19 | 20 | 21 | /* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug. 22 | * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC. 23 | * 24 | * Auto ProductID layout's Bitmap: 25 | * [MSB] HID | MSC | CDC [LSB] 26 | */ 27 | #define EPNUM_MSC 0x03 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | //------------- HID Report Descriptor -------------// 33 | #if CFG_TUD_HID 34 | enum { 35 | REPORT_ID_KEYBOARD = 1, 36 | REPORT_ID_MOUSE, 37 | REPORT_ID_GAMEPAD 38 | }; 39 | #endif 40 | 41 | //------------- Configuration Descriptor -------------// 42 | enum { 43 | # if CFG_TUD_CDC 44 | ITF_NUM_CDC = 0, 45 | ITF_NUM_CDC_DATA, 46 | # endif 47 | 48 | # if CFG_TUD_MSC 49 | ITF_NUM_MSC, 50 | # endif 51 | 52 | # if CFG_TUD_HID 53 | ITF_NUM_HID, 54 | # endif 55 | 56 | ITF_NUM_TOTAL 57 | }; 58 | 59 | enum { 60 | TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC * TUD_CDC_DESC_LEN + CFG_TUD_MSC * TUD_MSC_DESC_LEN + 61 | CFG_TUD_HID * TUD_HID_DESC_LEN 62 | }; 63 | 64 | bool tusb_desc_set; 65 | void tusb_set_descriptor(tusb_desc_device_t *desc, const char **str_desc); 66 | tusb_desc_device_t *tusb_get_active_desc(void); 67 | char **tusb_get_active_str_desc(void); 68 | void tusb_clear_descriptor(void); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | -------------------------------------------------------------------------------- /components/tinyusb/additions/include_private/usb_descriptors.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "tusb.h" 18 | #include "tinyusb_types.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #define _PID_MAP(itf, n) ((CFG_TUD_##itf) << (n)) 25 | 26 | extern tusb_desc_device_t descriptor_tinyusb; 27 | extern tusb_desc_strarray_device_t descriptor_str_tinyusb; 28 | 29 | extern tusb_desc_device_t descriptor_kconfig; 30 | extern tusb_desc_strarray_device_t descriptor_str_kconfig; 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /components/tinyusb/additions/src/tinyusb.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sdkconfig.h" 16 | #include "esp_log.h" 17 | #include "esp_check.h" 18 | #include "esp_err.h" 19 | #include "esp_private/usb_phy.h" 20 | #include "soc/usb_pins.h" 21 | #include "tinyusb.h" 22 | #include "descriptors_control.h" 23 | #include "tusb.h" 24 | #include "tusb_tasks.h" 25 | 26 | const static char *TAG = "TinyUSB"; 27 | static usb_phy_handle_t phy_hdl; 28 | 29 | esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) 30 | { 31 | tusb_desc_device_t *dev_descriptor; 32 | const char **string_descriptor; 33 | ESP_RETURN_ON_FALSE(config, ESP_ERR_INVALID_ARG, TAG, "invalid argument"); 34 | 35 | // Configure USB PHY 36 | usb_phy_config_t phy_conf = { 37 | .controller = USB_PHY_CTRL_OTG, 38 | .otg_mode = USB_OTG_MODE_DEVICE, 39 | }; 40 | if (config->external_phy) { 41 | phy_conf.target = USB_PHY_TARGET_EXT; 42 | usb_phy_gpio_conf_t gpio_conf = { 43 | .vp_io_num = USBPHY_VP_NUM, 44 | .vm_io_num = USBPHY_VM_NUM, 45 | .rcv_io_num = USBPHY_RCV_NUM, 46 | .oen_io_num = USBPHY_OEN_NUM, 47 | .vpo_io_num = USBPHY_VPO_NUM, 48 | .vmo_io_num = USBPHY_VMO_NUM, 49 | }; 50 | phy_conf.gpio_conf = &gpio_conf; 51 | } else { 52 | phy_conf.target = USB_PHY_TARGET_INT; 53 | } 54 | ESP_RETURN_ON_ERROR(usb_new_phy(&phy_conf, &phy_hdl), TAG, "Install USB PHY failed"); 55 | 56 | dev_descriptor = config->descriptor ? config->descriptor : &descriptor_kconfig; 57 | string_descriptor = config->string_descriptor ? config->string_descriptor : descriptor_str_kconfig; 58 | 59 | tusb_set_descriptor(dev_descriptor, string_descriptor); 60 | 61 | ESP_RETURN_ON_FALSE(tusb_init(), ESP_FAIL, TAG, "Init TinyUSB stack failed"); 62 | #if !CONFIG_TINYUSB_NO_DEFAULT_TASK 63 | ESP_RETURN_ON_ERROR(tusb_run_task(), TAG, "Run TinyUSB task failed"); 64 | #endif 65 | ESP_LOGI(TAG, "TinyUSB Driver installed"); 66 | return ESP_OK; 67 | } 68 | -------------------------------------------------------------------------------- /components/tinyusb/additions/src/tusb_console.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) Co. Ltd. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | #include 17 | #include 18 | #include "esp_log.h" 19 | #include "cdc.h" 20 | #include "tusb_console.h" 21 | #include "tinyusb.h" 22 | #include "vfs_tinyusb.h" 23 | 24 | #define STRINGIFY(s) STRINGIFY2(s) 25 | #define STRINGIFY2(s) #s 26 | 27 | static const char *TAG = "tusb_console"; 28 | 29 | typedef struct { 30 | FILE *in; 31 | FILE *out; 32 | FILE *err; 33 | } console_handle_t; 34 | 35 | static console_handle_t con; 36 | 37 | 38 | /** 39 | * @brief Reopen standard streams using a new path 40 | * 41 | * @param f_in - pointer to a pointer holding a file for in or NULL to don't change stdin 42 | * @param f_out - pointer to a pointer holding a file for out or NULL to don't change stdout 43 | * @param f_err - pointer to a pointer holding a file for err or NULL to don't change stderr 44 | * @param path - mount point 45 | * @return esp_err_t ESP_FAIL or ESP_OK 46 | */ 47 | static esp_err_t redirect_std_streams_to(FILE **f_in, FILE **f_out, FILE **f_err, const char *path) 48 | { 49 | if (f_in) { 50 | *f_in = freopen(path, "r", stdin); 51 | if (*f_in == NULL) { 52 | ESP_LOGE(TAG, "Failed to reopen in!"); 53 | return ESP_FAIL; 54 | } 55 | } 56 | if (f_out) { 57 | *f_out = freopen(path, "w", stdout); 58 | if (*f_out == NULL) { 59 | ESP_LOGE(TAG, "Failed to reopen out!"); 60 | return ESP_FAIL; 61 | } 62 | } 63 | if (f_err) { 64 | *f_err = freopen(path, "w", stderr); 65 | if (*f_err == NULL) { 66 | ESP_LOGE(TAG, "Failed to reopen err!"); 67 | return ESP_FAIL; 68 | } 69 | } 70 | 71 | return ESP_OK; 72 | } 73 | 74 | /** 75 | * @brief Restore output to default 76 | * 77 | * @param f_in - pointer to a pointer of an in file updated with `redirect_std_streams_to` or NULL to don't change stdin 78 | * @param f_out - pointer to a pointer of an out file updated with `redirect_std_streams_to` or NULL to don't change stdout 79 | * @param f_err - pointer to a pointer of an err file updated with `redirect_std_streams_to` or NULL to don't change stderr 80 | * @return esp_err_t ESP_FAIL or ESP_OK 81 | */ 82 | static esp_err_t restore_std_streams(FILE **f_in, FILE **f_out, FILE **f_err) 83 | { 84 | const char *default_uart_dev = "/dev/uart/" STRINGIFY(CONFIG_ESP_CONSOLE_UART_NUM); 85 | if (f_in) { 86 | stdin = freopen(default_uart_dev, "r", *f_in); 87 | if (stdin == NULL) { 88 | ESP_LOGE(TAG, "Failed to reopen stdin!"); 89 | return ESP_FAIL; 90 | } 91 | } 92 | if (f_out) { 93 | stdout = freopen(default_uart_dev, "w", *f_out); 94 | if (stdout == NULL) { 95 | ESP_LOGE(TAG, "Failed to reopen stdout!"); 96 | return ESP_FAIL; 97 | } 98 | } 99 | if (f_err) { 100 | stderr = freopen(default_uart_dev, "w", *f_err); 101 | if (stderr == NULL) { 102 | ESP_LOGE(TAG, "Failed to reopen stderr!"); 103 | return ESP_FAIL; 104 | } 105 | } 106 | return ESP_OK; 107 | } 108 | 109 | esp_err_t esp_tusb_init_console(int cdc_intf) 110 | { 111 | if (!tinyusb_cdc_initialized(cdc_intf)) { 112 | ESP_LOGE(TAG, "Can't init the console because TinyUSB's CDC is not initialized!"); 113 | return ESP_ERR_INVALID_STATE; 114 | } 115 | /* Registering TUSB at VFS */ 116 | int res = esp_vfs_tusb_cdc_register(cdc_intf, NULL); 117 | if (res != ESP_OK) { 118 | return res; 119 | } 120 | 121 | res = redirect_std_streams_to(&con.in, &con.out, &con.err, "/dev/tusb_cdc"); 122 | if (res != ESP_OK) { 123 | return res; 124 | } 125 | 126 | return ESP_OK; 127 | } 128 | 129 | esp_err_t esp_tusb_deinit_console(int cdc_intf) 130 | { 131 | if (!tinyusb_cdc_initialized(cdc_intf)) { 132 | ESP_LOGE(TAG, "Can't deinit the console because TinyUSB's CDC is not initialized!"); 133 | return ESP_ERR_INVALID_STATE; 134 | } 135 | 136 | int res = restore_std_streams(&con.in, &con.out, &con.err); 137 | if (res != ESP_OK) { 138 | return res; 139 | } 140 | esp_vfs_tusb_cdc_unregister(NULL); 141 | return ESP_OK; 142 | } 143 | -------------------------------------------------------------------------------- /components/tinyusb/additions/src/tusb_hid_gamepad.c: -------------------------------------------------------------------------------- 1 | #include "tusb_hid_gamepad.h" 2 | #include "descriptors_control.h" 3 | 4 | void tud_gamepad_report(hid_gamepad_report_t * report) 5 | { 6 | tud_hid_report(REPORT_ID_GAMEPAD, report, sizeof(hid_gamepad_report_t)); 7 | } 8 | 9 | void tud_gamepad_ns_report(hid_gamepad_ns_report_t * report) 10 | { 11 | tud_hid_report(0, report, sizeof(hid_gamepad_ns_report_t)); 12 | } -------------------------------------------------------------------------------- /components/tinyusb/additions/src/tusb_tasks.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sdkconfig.h" 16 | #include "freertos/FreeRTOS.h" 17 | #include "freertos/task.h" 18 | #include "esp_log.h" 19 | #include "esp_check.h" 20 | #include "tinyusb.h" 21 | #include "tusb_tasks.h" 22 | 23 | const static char *TAG = "tusb_tsk"; 24 | static TaskHandle_t s_tusb_tskh; 25 | 26 | /** 27 | * @brief This top level thread processes all usb events and invokes callbacks 28 | */ 29 | static void tusb_device_task(void *arg) 30 | { 31 | ESP_LOGD(TAG, "tinyusb task started"); 32 | while (1) { // RTOS forever loop 33 | tud_task(); 34 | } 35 | } 36 | 37 | esp_err_t tusb_run_task(void) 38 | { 39 | // This function is not garanteed to be thread safe, if invoked multiple times without calling `tusb_stop_task`, will cause memory leak 40 | // doing a sanity check anyway 41 | ESP_RETURN_ON_FALSE(!s_tusb_tskh, ESP_ERR_INVALID_STATE, TAG, "TinyUSB main task already started"); 42 | // Create a task for tinyusb device stack: 43 | xTaskCreate(tusb_device_task, "TinyUSB", CONFIG_TINYUSB_TASK_STACK_SIZE, NULL, CONFIG_TINYUSB_TASK_PRIORITY, &s_tusb_tskh); 44 | ESP_RETURN_ON_FALSE(s_tusb_tskh, ESP_FAIL, TAG, "create TinyUSB main task failed"); 45 | return ESP_OK; 46 | } 47 | 48 | esp_err_t tusb_stop_task(void) 49 | { 50 | ESP_RETURN_ON_FALSE(s_tusb_tskh, ESP_ERR_INVALID_STATE, TAG, "TinyUSB main task not started yet"); 51 | vTaskDelete(s_tusb_tskh); 52 | s_tusb_tskh = NULL; 53 | return ESP_OK; 54 | } 55 | -------------------------------------------------------------------------------- /components/tinyusb/additions/src/usb_descriptors.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "usb_descriptors.h" 16 | #include "sdkconfig.h" 17 | 18 | #define USB_TUSB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | _PID_MAP(MIDI, 3)) 19 | 20 | /**** TinyUSB default ****/ 21 | tusb_desc_device_t descriptor_tinyusb = { 22 | .bLength = sizeof(descriptor_tinyusb), 23 | .bDescriptorType = TUSB_DESC_DEVICE, 24 | .bcdUSB = 0x0200, 25 | 26 | #if CFG_TUD_CDC 27 | // Use Interface Association Descriptor (IAD) for CDC 28 | // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1) 29 | .bDeviceClass = TUSB_CLASS_MISC, 30 | .bDeviceSubClass = MISC_SUBCLASS_COMMON, 31 | .bDeviceProtocol = MISC_PROTOCOL_IAD, 32 | #else 33 | .bDeviceClass = 0x00, 34 | .bDeviceSubClass = 0x00, 35 | .bDeviceProtocol = 0x00, 36 | #endif 37 | 38 | .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, 39 | 40 | .idVendor = 0xCafe, 41 | .idProduct = USB_TUSB_PID, 42 | .bcdDevice = 0x0100, 43 | 44 | .iManufacturer = 0x01, 45 | .iProduct = 0x02, 46 | .iSerialNumber = 0x03, 47 | 48 | .bNumConfigurations = 0x01 49 | }; 50 | 51 | tusb_desc_strarray_device_t descriptor_str_tinyusb = { 52 | // array of pointer to string descriptors 53 | (char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) 54 | "TinyUSB", // 1: Manufacturer 55 | "TinyUSB Device", // 2: Product 56 | "123456", // 3: Serials, should use chip ID 57 | "TinyUSB CDC", // 4: CDC Interface 58 | "TinyUSB MSC", // 5: MSC Interface 59 | "TinyUSB HID" // 6: HID 60 | }; 61 | /* End of TinyUSB default */ 62 | 63 | /**** Kconfig driven Descriptor ****/ 64 | tusb_desc_device_t descriptor_kconfig = { 65 | .bLength = sizeof(descriptor_kconfig), 66 | .bDescriptorType = TUSB_DESC_DEVICE, 67 | .bcdUSB = 0x0200, 68 | 69 | #if CFG_TUD_CDC 70 | // Use Interface Association Descriptor (IAD) for CDC 71 | // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1) 72 | .bDeviceClass = TUSB_CLASS_MISC, 73 | .bDeviceSubClass = MISC_SUBCLASS_COMMON, 74 | .bDeviceProtocol = MISC_PROTOCOL_IAD, 75 | #else 76 | .bDeviceClass = 0x00, 77 | .bDeviceSubClass = 0x00, 78 | .bDeviceProtocol = 0x00, 79 | #endif 80 | 81 | .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, 82 | 83 | #if CONFIG_TINYUSB_DESC_USE_ESPRESSIF_VID 84 | .idVendor = USB_ESPRESSIF_VID, 85 | #else 86 | .idVendor = CONFIG_TINYUSB_DESC_CUSTOM_VID, 87 | #endif 88 | 89 | #if CONFIG_TINYUSB_DESC_USE_DEFAULT_PID 90 | .idProduct = USB_TUSB_PID, 91 | #else 92 | .idProduct = CONFIG_TINYUSB_DESC_CUSTOM_PID, 93 | #endif 94 | 95 | .bcdDevice = CONFIG_TINYUSB_DESC_BCD_DEVICE, 96 | 97 | .iManufacturer = 0x01, 98 | .iProduct = 0x02, 99 | .iSerialNumber = 0x03, 100 | 101 | .bNumConfigurations = 0x01 102 | }; 103 | 104 | tusb_desc_strarray_device_t descriptor_str_kconfig = { 105 | // array of pointer to string descriptors 106 | (char[]){0x09, 0x04}, // 0: is supported language is English (0x0409) 107 | CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, // 1: Manufacturer 108 | CONFIG_TINYUSB_DESC_PRODUCT_STRING, // 2: Product 109 | CONFIG_TINYUSB_DESC_SERIAL_STRING, // 3: Serials, should use chip ID 110 | 111 | #if CONFIG_TINYUSB_CDC_ENABLED 112 | CONFIG_TINYUSB_DESC_CDC_STRING, // 4: CDC Interface 113 | #else 114 | "", 115 | #endif 116 | 117 | #if CONFIG_TINYUSB_MSC_ENABLED 118 | CONFIG_TINYUSB_DESC_MSC_STRING, // 5: MSC Interface 119 | #else 120 | "", 121 | #endif 122 | 123 | #if CONFIG_TINYUSB_HID_ENABLED 124 | CONFIG_TINYUSB_DESC_HID_STRING // 6: HIDs 125 | #else 126 | "", 127 | #endif 128 | 129 | }; 130 | /* End of Kconfig driven Descriptor */ 131 | -------------------------------------------------------------------------------- /components/tinyusb/sdkconfig.rename: -------------------------------------------------------------------------------- 1 | # sdkconfig replacement configurations for deprecated options formatted as 2 | # CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION 3 | CONFIG_USB_ENABLED CONFIG_TINYUSB 4 | CONFIG_USB_DO_NOT_CREATE_TASK CONFIG_TINYUSB_NO_DEFAULT_TASK 5 | CONFIG_USB_TASK_PRIORITY CONFIG_TINYUSB_TASK_PRIORITY 6 | CONFIG_USB_DESC_USE_ESPRESSIF_VID CONFIG_TINYUSB_DESC_USE_ESPRESSIF_VID 7 | CONFIG_USB_DESC_CUSTOM_VID CONFIG_TINYUSB_DESC_CUSTOM_VID 8 | CONFIG_USB_DESC_USE_DEFAULT_PID CONFIG_TINYUSB_DESC_USE_DEFAULT_PID 9 | CONFIG_USB_DESC_CUSTOM_PID CONFIG_TINYUSB_DESC_CUSTOM_PID 10 | CONFIG_USB_DESC_BCDDEVICE CONFIG_TINYUSB_DESC_BCD_DEVICE 11 | CONFIG_USB_DESC_MANUFACTURER_STRING CONFIG_TINYUSB_DESC_MANUFACTURER_STRING 12 | CONFIG_USB_DESC_PRODUCT_STRING CONFIG_TINYUSB_DESC_PRODUCT_STRING 13 | CONFIG_USB_DESC_SERIAL_STRING CONFIG_TINYUSB_DESC_SERIAL_STRING 14 | CONFIG_USB_DESC_CDC_STRING CONFIG_TINYUSB_DESC_CDC_STRING 15 | CONFIG_USB_DESC_MSC_STRING CONFIG_TINYUSB_DESC_MSC_STRING 16 | CONFIG_USB_DESC_HID_STRING CONFIG_TINYUSB_DESC_HID_STRING 17 | CONFIG_USB_MSC_ENABLED CONFIG_TINYUSB_MSC_ENABLED 18 | CONFIG_USB_MSC_BUFSIZE CONFIG_TINYUSB_MSC_BUFSIZE 19 | CONFIG_USB_CDC_ENABLED CONFIG_TINYUSB_CDC_ENABLED 20 | CONFIG_USB_CDC_RX_BUFSIZE CONFIG_TINYUSB_CDC_RX_BUFSIZE 21 | CONFIG_USB_CDC_TX_BUFSIZE CONFIG_TINYUSB_CDC_TX_BUFSIZE 22 | CONFIG_USB_HID_ENABLED CONFIG_TINYUSB_HID_ENABLED 23 | CONFIG_USB_HID_BUFSIZE CONFIG_TINYUSB_HID_BUFSIZE 24 | CONFIG_USB_DEBUG_LEVEL CONFIG_TINYUSB_DEBUG_LEVEL 25 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | *.c text 5 | *.cpp text 6 | *.h text 7 | *.icf text 8 | *.js text 9 | *.json text 10 | *.ld text 11 | *.md text 12 | *.mk text 13 | *.py text 14 | *.rst text 15 | *.s text 16 | *.txt text 17 | *.xml text 18 | *.yml text 19 | 20 | Makefile text 21 | 22 | # Windows-only Visual Studio things 23 | 24 | *.sln text eol=crlf 25 | *.csproj text eol=crlf 26 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a report to help us improve 4 | title: 'Please provide all details at least for Setup/Describe/Reproduce' 5 | labels: Bug 🐞 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Set Up** 11 | 12 | - **PC OS** e.g Ubuntu 20.04 / Windows 10/ macOS 10.15 13 | - **Board** e.g Feather nRF52840 Express (if custom specify your MCUs) 14 | - **Firmware** e.g examples/device/cdc_msc 15 | 16 | **Describe The Bug** 17 | 18 | A clear and concise description of what the bug is. 19 | 20 | **To Reproduce** 21 | 22 | Steps to reproduce the behavior: 23 | 1. Go to '...' 24 | 2. Click on '....' 25 | 3. See error 26 | 27 | **Screenshots** 28 | 29 | If applicable, add screenshots, bus capture to help explain your problem. 30 | 31 | **Log** 32 | 33 | If applicable, provide the stack's log (uart/rtt/swo) where the issue occurred, best with comments to explain the actual events. If the log is too long, attach it as txt file instead. 34 | 35 | Note: To enable logging, add `LOG=2` to to the make command if building with stock examples or set `CFG_TUSB_DEBUG=2` in your tusb_config.h. More information can be found at [example's readme](/docs/getting_started.md) 36 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: TinyUSB Discussion 3 | url: https://github.com/hathach/tinyusb/discussions 4 | about: If you have other questions or need help, post it here. 5 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: Feature 💡 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | **Describe the PR** 2 | A clear and concise description of what this PR solve. 3 | 4 | **Additional context** 5 | If applicable, add any other context about the PR and/or screenshots here. 6 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.github/workflows/trigger.yml: -------------------------------------------------------------------------------- 1 | name: Trigger Repos 2 | 3 | on: 4 | push: 5 | branches: master 6 | release: 7 | types: 8 | - created 9 | 10 | jobs: 11 | trigger-mynewt: 12 | if: github.repository == 'hathach/tinyusb' 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Trigger mynewt-tinyusb-example 16 | shell: bash 17 | run: | 18 | curl -X POST -H "Authorization: token ${{ secrets.API_TOKEN_GITHUB }}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" --data '{"event_type": "rebuild"}' https://api.github.com/repos/hathach/mynewt-tinyusb-example/dispatches 19 | 20 | mirror-tinyusb-src: 21 | if: github.repository == 'hathach/tinyusb' 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout code 25 | uses: actions/checkout@v2 26 | 27 | - name: Push to tinyusb_src 28 | run: | 29 | # clone tinyusb_src with PAT 30 | git config --global user.email "thach@tinyusb.org" 31 | git config --global user.name "hathach" 32 | git clone --depth 1 --single-branch --branch main "https://${{ secrets.API_TOKEN_GITHUB }}@github.com/hathach/tinyusb_src.git" tinyusb_src 33 | 34 | # Remove all files 35 | rm -rf tinyusb_src/* 36 | 37 | # Copy src and other files 38 | cp -r src tinyusb_src/ 39 | cp LICENSE tinyusb_src/ 40 | cd tinyusb_src 41 | 42 | # Commit if there is changes 43 | if [ -n "$(git status --porcelain)" ]; then 44 | git add . 45 | git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" 46 | git push 47 | fi 48 | 49 | - name: Create tinyusb_src Release 50 | if: ${{ github.event_name == 'release' }} 51 | run: | 52 | # Push tag 53 | cd tinyusb_src 54 | git tag ${{ github.event.release.tag_name }} 55 | git push origin ${{ github.event.release.tag_name }} 56 | 57 | # Send POST reqwuest to release https://docs.github.com/en/rest/reference/repos#create-a-release 58 | curl -X POST -H "Authorization: token ${{ secrets.API_TOKEN_GITHUB }}" -H "Accept: application/vnd.github.v3+json" --data '{"tag_name": "${{ github.event.release.tag_name }}", "name": "${{ github.event.release.name }}", "body": "${{ github.event.release.body }}", "draft": ${{ github.event.release.draft }}, "prerelease": ${{ github.event.release.prerelease }}}' https://api.github.com/repos/hathach/tinyusb_src/releases 59 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.gitignore: -------------------------------------------------------------------------------- 1 | html 2 | latex 3 | *.d 4 | *.o 5 | *.P 6 | *.map 7 | *.axf 8 | *.bin 9 | *.jlink 10 | *.emSession 11 | *.elf 12 | *.ind 13 | .env 14 | .settings/ 15 | .idea/ 16 | .gdb_history 17 | /examples/*/*/build* 18 | test_old/ 19 | tests_obsolete/ 20 | _build 21 | /examples/*/*/ses 22 | /examples/*/*/ozone 23 | /examples/obsolete 24 | # coverity intermediate files 25 | cov-int 26 | # cppcheck build directories 27 | *-build-dir 28 | /_bin/ 29 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cnlohr/esp32s2_dmx512_usb/8a7962e2aa3ab2450d48b570219491455aee2f08/components/tinyusb/tinyusb/.gitmodules -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at thach@tinyusb.org. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # TinyUSB contributors (sorted alphabetically) 2 | 3 | - **[Adafruit Team](https://github.com/adafruit)** 4 | - Main supporter and sponsor for hardware boards and kits 5 | - Discussion and suggestion for feature and improvement 6 | - Design the project logo 7 | 8 | - **[Ha Thach](https://github.com/hathach)** 9 | - *Author and maintainer* 10 | - Most features development 11 | 12 | - **[Hristo Gochkov](https://github.com/me-no-dev)** 13 | - Improve ESP32s2 DCD 14 | 15 | - **[Jan Dümpelmann](https://github.com/duempel)** 16 | - Improve transfer performance for Synopsys DCD for STM32 MCUs 17 | 18 | - **[Jeff Epler](https://github.com/jepler)** 19 | - Improve MIDI class driver 20 | 21 | - **[Jerzy Kasenberg](https://github.com/kasjer)** 22 | - Add new DCD port for **Dialog DA1469x** 23 | - Add new class driver for **Bluetooth HCI** 24 | - Add ISO transfer for STM32 Synopsys, Nordic nRF, Dialog DA1469x 25 | - Improve Audio driver and add uac2_headset example 26 | - Improve STM32 Synopsys DCD with various PRs 27 | 28 | - **[Kamil Tomaszewski](https://github.com/kamtom480)** 29 | - Add new DCD port for **Sony CXD56** (spresnese board) 30 | 31 | - **[Kay Sievers](https://github.com/kaysievers)** 32 | - Improve MIDI driver with packet API 33 | 34 | - **[Koji KITAYAMA](https://github.com/kkitayam)** 35 | - Add new DCD port for **NXP Kinetis KL25** 36 | - Add new DCD port for **Renesas RX63n** with GR-CITRUS board 37 | 38 | - **[Nathan Conrad](https://github.com/pigrew)** 39 | - Add new DCD port for **STM32 fsdev** Fullspeed device for STM32 L0, F0, F1, F3 etc ... 40 | - Add new class driver for **USB Test and Measurement Class (USBTMC)** 41 | - Various improvement e.g Zero-length packet, Lint setup 42 | - Board support for STM32F070RB Nucleo, STM32F303 Discovery 43 | 44 | - **[Peter Lawrence](https://github.com/majbthrd)** 45 | - Add new DCD port for **Nuvoton NUC 120, 121, 125, 126, 505** 46 | - Add new class driver for **USBNET RNDIS, CDC-ECM** 47 | - Add *net_lwip_webserver* example for demonstration of usbnet with lwip 48 | - Board support for NuTiny NUC120, NUC121s, NUC125s, NUC126V, NUC505 49 | - Improve multiple cdc interfaces API & add cdc_dual_ports example 50 | 51 | - **[Rafael Silva](https://github.com/perigoso)** 52 | - Add new DCD port for **Silabs EFM32GG12** with SLTB009A board 53 | 54 | - **[Raspberry Pi Team](https://github.com/raspberrypi)** 55 | - Add new DCD port for **Raspberry Pi RP2040** 56 | 57 | - **[Reinhard Panhuber](https://github.com/PanRe)** 58 | - Add new class driver for **USB Audio Class 2.0 (UAC2)** 59 | - Enhance tu_fifo with unmasked pointer, which better support DMA 60 | 61 | - **[Scott Shawcroft](https://github.com/tannewt)** 62 | - Add new DCD port for **SAMD21 and SAMD51** 63 | - Add new class driver for **Musical Instrument Digital Interface (MIDI)** 64 | - Improve USBD control transfer, MSC, CDC class driver 65 | - Board support for Metro M0 & M4 express 66 | - Write the excellent porting.md documentation 67 | - Add initial Makefile 68 | 69 | - **[Sean Cross](https://github.com/xobs)** 70 | - Add new DCD port for **ValentyUSB eptri** (fomu board) 71 | 72 | - **[Sylvain "tnt" Munaut](https://github.com/smunaut)** 73 | - Add new class driver for DFU Runtime 74 | 75 | - **[Timon Skerutsch](https://github.com/PTS93)** 76 | - Add hid_test.js script and extensive test for bi-directional raw HID 77 | 78 | - **[Tod E. Kurt](https://github.com/todbot)** 79 | - Add hid_test.js script and extensive test for bi-directional raw HID 80 | 81 | - **[Uwe Bonnes](https://github.com/UweBonnes)** 82 | - Improve STM32 Synopsys highspeed DCD 83 | 84 | - **[William D. Jones](https://github.com/cr1901)** 85 | - Add new DCD port for **Synopsys DesignWare** for STM32 L4, F2, F4, F7, H7 etc ... 86 | - Add new DCD port for **TI MSP430** 87 | - Board support for STM32F407 Discovery, STM32H743 Nucleo, pyboard v1.1, msp_exp430f5529lp etc ... 88 | 89 | **[Full contributors list](https://github.com/hathach/tinyusb/contributors).** 90 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018, hathach (tinyusb.org) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/README.md: -------------------------------------------------------------------------------- 1 | # TinyUSB 2 | 3 | ![TinyUSB](https://user-images.githubusercontent.com/2847802/108847382-a0a6a580-75ad-11eb-96d9-280c79389281.png) 4 | 5 | [![Build Status](https://github.com/hathach/tinyusb/workflows/Build/badge.svg)](https://github.com/hathach/tinyusb/actions) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) 6 | 7 | TinyUSB is an open-source cross-platform USB Host/Device stack for embedded system, designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events are deferred then handled in the non-ISR task function. 8 | 9 | ![tinyusb](https://user-images.githubusercontent.com/249515/49858616-f60c9700-fe27-11e8-8627-e76936352ff7.png) 10 | 11 | ``` 12 | . 13 | ├── docs # Documentation 14 | ├── examples # Sample with Makefile build support 15 | ├── hw 16 | │   ├── bsp # Supported boards source files 17 | │   └── mcu # Low level mcu core & peripheral drivers 18 | ├── lib # Sources from 3rd party such as freeRTOS, fatfs ... 19 | ├── src # All sources files for TinyUSB stack itself. 20 | ├── test # Unit tests for the stack 21 | └── tools # Files used internally 22 | ``` 23 | 24 | ## Contributors 25 | 26 | Special thanks to all the people who spent their precious time and effort to help this project so far. Check out the 27 | [CONTRIBUTORS.md](CONTRIBUTORS.md) file for the list of all contributors and their awesome work for the stack. 28 | 29 | ## Supported MCUs 30 | 31 | The stack supports the following MCUs: 32 | 33 | - **Dialog:** DA1469x 34 | - **Espressif:** ESP32-S2, ESP32-S3 35 | - **MicroChip:** SAMD11, SAMD21, SAMD51, SAME5x, SAMG55 36 | - **NordicSemi:** nRF52833, nRF52840 37 | - **Nuvoton:** NUC120, NUC121/NUC125, NUC126, NUC505 38 | - **NXP:** 39 | - iMX RT Series: RT1011, RT1015, RT1021, RT1052, RT1062, RT1064 40 | - Kinetis: KL25 41 | - LPC Series: 11Uxx, 13xx, 175x_6x, 177x_8x, 18xx, 40xx, 43xx, 51Uxx, 54xxx, 55xx 42 | - **Raspberry Pi:** RP2040 43 | - **Renesas:** RX63N 44 | - **Silabs:** EFM32GG12 45 | - **Sony:** CXD56 46 | - **ST:** STM32 series: L0, F0, F1, F2, F3, F4, F7, H7 both FullSpeed and HighSpeed 47 | - **TI:** MSP430 48 | - **[ValentyUSB](https://github.com/im-tomu/valentyusb)** eptri 49 | 50 | [Here is the list of supported Boards](docs/boards.md) that can be used with provided examples. 51 | 52 | ## Device Stack 53 | 54 | Supports multiple device configurations by dynamically changing usb descriptors. Low power functions such like suspend, resume, and remote wakeup. Following device classes are supported: 55 | 56 | - USB Audio Class 2.0 (UAC2) still work in progress 57 | - Bluetooth Host Controller Interface (BTH HCI) 58 | - Communication Class (CDC) 59 | - Device Firmware Update (DFU): only Runtinme 60 | - Human Interface Device (HID): Generic (In & Out), Keyboard, Mouse, Gamepad etc ... 61 | - Mass Storage Class (MSC): with multiple LUNs 62 | - Musical Instrument Digital Interface (MIDI) 63 | - Network with RNDIS, CDC-ECM (work in progress) 64 | - USB Test and Measurement Class (USBTMC) 65 | - Vendor-specific class support with generic In & Out endpoints. Can be used with MS OS 2.0 compatible descriptor to load winUSB driver without INF file. 66 | - [WebUSB](https://github.com/WICG/webusb) with vendor-specific class 67 | 68 | ## Host Stack 69 | 70 | **Most active development is on the Device stack. The Host stack is under rework and largely untested.** 71 | 72 | - Human Interface Device (HID): Keyboard, Mouse, Generic 73 | - Mass Storage Class (MSC) 74 | - Hub currently only supports 1 level of hub (due to my laziness) 75 | 76 | ## OS Abstraction layer 77 | 78 | TinyUSB is completely thread-safe by pushing all ISR events into a central queue, then process it later in the non-ISR context task function. It also uses semaphore/mutex to access shared resources such as CDC FIFO. Therefore the stack needs to use some of OS's basic APIs. Following OSes are already supported out of the box. 79 | 80 | - **No OS** : Disabling USB IRQ is used as way to provide mutex 81 | - **FreeRTOS** 82 | - **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its [own repo](https://github.com/hathach/mynewt-tinyusb-example) 83 | 84 | ## Getting Started 85 | 86 | [Here are the details for getting started](docs/getting_started.md) with the stack. 87 | 88 | ## Porting 89 | 90 | Want to help add TinyUSB support for a new MCU? Read [here](docs/porting.md) for an explanation on the low-level API needed by TinyUSB. 91 | 92 | ## License 93 | 94 | MIT license for all TinyUSB sources `src` folder, [Full license is here](LICENSE). However, each file is individually licensed especially those in `lib` and `hw/mcu` folder. Please make sure you understand all the license term for files you use in your project. 95 | 96 | ## Uses 97 | 98 | TinyUSB is currently used by these other projects: 99 | 100 | - [Adafruit nRF52 Arduino](https://github.com/adafruit/Adafruit_nRF52_Arduino) 101 | - [Adafruit nRF52 Bootloader](https://github.com/adafruit/Adafruit_nRF52_Bootloader) 102 | - [Adafruit SAMD Arduino](https://github.com/adafruit/ArduinoCore-samd) 103 | - [CircuitPython](https://github.com/adafruit/circuitpython) 104 | - [Espressif IDF](https://github.com/espressif/esp-idf) 105 | - [MicroPython](https://github.com/micropython/micropython) 106 | - [mynewt](https://mynewt.apache.org) 107 | - [Raspberry Pi Pico SDK](https://github.com/raspberrypi/pico-sdk) 108 | - [TinyUF2 Bootloader](https://github.com/adafruit/tinyuf2) 109 | - [TinyUSB Arduino Library](https://github.com/adafruit/Adafruit_TinyUSB_Arduino) 110 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/docs/concurrency.md: -------------------------------------------------------------------------------- 1 | # Concurrency 2 | 3 | The TinyUSB library is designed to operate on single-core MCUs with multi-threaded applications in mind. Interaction with interrupts is especially important to pay attention to. 4 | It is compatible with optionally using a RTOS. 5 | 6 | ## General 7 | 8 | When writing code, keep in mind that the OS (if using a RTOS) may swap out your code at any time. Also, your code can be preempted by an interrupt at any time. 9 | 10 | ## Application Code 11 | 12 | The USB core does not execute application callbacks while in an interrupt context. Calls to application code are from within the USB core task context. Note that the application core will call class drivers from within their own task. 13 | 14 | ## Class Drivers 15 | 16 | Class driver code should never be called from an interrupt context by the USB core, though the application is allowed to call class driver functions from interrupts. USB core functions may be called simultaneously by multiple tasks. Use care that proper locking is used to guard the USBD core functions from this case. 17 | 18 | Class drivers are allowed to call `usbd_*` functions, but not `dcd_*` functions. 19 | 20 | ## USB Core 21 | 22 | All functions that may be called from an (USB core) interrupt context have a `bool in_isr` parameter to remind the implementer that special care must be taken. 23 | 24 | Interrupt handlers must not directly call class driver code, they must pass a message to the USB core's task. 25 | 26 | `usbd_*` functions may be called from interrupts without any notice. They may also be called simultaneously by multiple tasks. 27 | 28 | ## Device Drivers 29 | 30 | Much of the processing of the USB stack is done in an interrupt context, and care must be taken in order to ensure variables are handled in the appropriate ways by the compiler and optimizer. 31 | 32 | In particular: 33 | 34 | - Ensure that all memory-mapped registers (including packet memory) are marked as volatile. GCC's optimizer will even combine memory access (like two 16-bit to be a 32-bit) if you don't mark the pointers as volatile. On some architectures, this can use macros like `_I`, `_O`, or `_IO'. 35 | - All defined global variables are marked as `static`. 36 | 37 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS esp32s2.c 2 | INCLUDE_DIRS "." "${BOARD}" 3 | PRIV_REQUIRES "driver" 4 | REQUIRES freertos src led_strip) 5 | 6 | # Apply board specific content 7 | include("${BOARD}/board.cmake") 8 | 9 | idf_component_get_property( FREERTOS_ORIG_INCLUDE_PATH freertos ORIG_INCLUDE_PATH) 10 | target_include_directories(${COMPONENT_TARGET} PUBLIC 11 | "${FREERTOS_ORIG_INCLUDE_PATH}" 12 | "${TOP}/hw" 13 | "${TOP}/src" 14 | ) 15 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/adafruit_feather_esp32s2/board.cmake: -------------------------------------------------------------------------------- 1 | # Apply board specific content here 2 | target_include_directories(${COMPONENT_LIB} PRIVATE .) 3 | 4 | idf_build_get_property(idf_target IDF_TARGET) 5 | 6 | message(STATUS "Apply ${BOARD}(${idf_target}) specific options for component: ${COMPONENT_TARGET}") 7 | 8 | if(NOT ${idf_target} STREQUAL "esp32s2") 9 | message(FATAL_ERROR "Incorrect target for board ${BOARD}: $ENV{IDF_TARGET}(${idf_target}), try to clean the build first." ) 10 | endif() 11 | 12 | set(IDF_TARGET "esp32s2" FORCE) 13 | 14 | target_compile_options(${COMPONENT_TARGET} PUBLIC 15 | "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" 16 | "-DCFG_TUSB_OS=OPT_OS_FREERTOS" 17 | ) -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/adafruit_feather_esp32s2/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef BOARD_H_ 28 | #define BOARD_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define NEOPIXEL_PIN 33 35 | #define NEOPIXEL_POWER_PIN 21 36 | #define NEOPIXEL_POWER_STATE 1 37 | 38 | #define BUTTON_PIN 0 39 | #define BUTTON_STATE_ACTIVE 0 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* BOARD_H_ */ 46 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/adafruit_magtag_29gray/board.cmake: -------------------------------------------------------------------------------- 1 | # Apply board specific content here 2 | target_include_directories(${COMPONENT_LIB} PRIVATE .) 3 | 4 | idf_build_get_property(idf_target IDF_TARGET) 5 | 6 | message(STATUS "Apply ${BOARD}(${idf_target}) specific options for component: ${COMPONENT_TARGET}") 7 | 8 | if(NOT ${idf_target} STREQUAL "esp32s2") 9 | message(FATAL_ERROR "Incorrect target for board ${BOARD}: $ENV{IDF_TARGET}(${idf_target}), try to clean the build first." ) 10 | endif() 11 | 12 | set(IDF_TARGET "esp32s2" FORCE) 13 | 14 | target_compile_options(${COMPONENT_TARGET} PUBLIC 15 | "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" 16 | "-DCFG_TUSB_OS=OPT_OS_FREERTOS" 17 | ) -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/adafruit_magtag_29gray/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef BOARD_H_ 28 | #define BOARD_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define NEOPIXEL_PIN 1 35 | #define NEOPIXEL_POWER_PIN 21 36 | #define NEOPIXEL_POWER_STATE 0 37 | 38 | #define BUTTON_PIN 0 39 | #define BUTTON_STATE_ACTIVE 0 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* BOARD_H_ */ 46 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/adafruit_metro_esp32s2/board.cmake: -------------------------------------------------------------------------------- 1 | # Apply board specific content here 2 | target_include_directories(${COMPONENT_LIB} PRIVATE .) 3 | 4 | idf_build_get_property(idf_target IDF_TARGET) 5 | 6 | message(STATUS "Apply ${BOARD}(${idf_target}) specific options for component: ${COMPONENT_TARGET}") 7 | 8 | if(NOT ${idf_target} STREQUAL "esp32s2") 9 | message(FATAL_ERROR "Incorrect target for board ${BOARD}: (${idf_target}), try to clean the build first." ) 10 | endif() 11 | 12 | set(IDF_TARGET "esp32s2" FORCE) 13 | 14 | target_compile_options(${COMPONENT_TARGET} PUBLIC 15 | "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" 16 | "-DCFG_TUSB_OS=OPT_OS_FREERTOS" 17 | ) -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/adafruit_metro_esp32s2/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef BOARD_H_ 28 | #define BOARD_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define NEOPIXEL_PIN 45 35 | 36 | #define BUTTON_PIN 0 37 | #define BUTTON_STATE_ACTIVE 0 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* BOARD_H_ */ 44 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/esp32s2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #include "../../board.h" 28 | #include "board.h" 29 | 30 | #include "esp_rom_gpio.h" 31 | #include "hal/gpio_ll.h" 32 | #include "hal/usb_hal.h" 33 | #include "soc/usb_periph.h" 34 | 35 | #include "driver/periph_ctrl.h" 36 | #include "driver/rmt.h" 37 | 38 | #ifdef NEOPIXEL_PIN 39 | #include "led_strip.h" 40 | static led_strip_t *strip; 41 | #endif 42 | 43 | //--------------------------------------------------------------------+ 44 | // MACRO TYPEDEF CONSTANT ENUM DECLARATION 45 | //--------------------------------------------------------------------+ 46 | 47 | static void configure_pins(usb_hal_context_t *usb); 48 | 49 | // Initialize on-board peripherals : led, button, uart and USB 50 | void board_init(void) 51 | { 52 | 53 | #ifdef NEOPIXEL_PIN 54 | #ifdef NEOPIXEL_POWER_PIN 55 | gpio_reset_pin(NEOPIXEL_POWER_PIN); 56 | gpio_set_direction(NEOPIXEL_POWER_PIN, GPIO_MODE_OUTPUT); 57 | gpio_set_level(NEOPIXEL_POWER_PIN, NEOPIXEL_POWER_STATE); 58 | #endif 59 | 60 | // WS2812 Neopixel driver with RMT peripheral 61 | rmt_config_t config = RMT_DEFAULT_CONFIG_TX(NEOPIXEL_PIN, RMT_CHANNEL_0); 62 | config.clk_div = 2; // set counter clock to 40MHz 63 | 64 | rmt_config(&config); 65 | rmt_driver_install(config.channel, 0, 0); 66 | 67 | led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t) config.channel); 68 | strip = led_strip_new_rmt_ws2812(&strip_config); 69 | strip->clear(strip, 100); // off led 70 | #endif 71 | 72 | // Button 73 | gpio_pad_select_gpio(BUTTON_PIN); 74 | gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT); 75 | gpio_set_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY); 76 | 77 | // USB Controller Hal init 78 | periph_module_reset(PERIPH_USB_MODULE); 79 | periph_module_enable(PERIPH_USB_MODULE); 80 | 81 | usb_hal_context_t hal = { 82 | .use_external_phy = false // use built-in PHY 83 | }; 84 | usb_hal_init(&hal); 85 | configure_pins(&hal); 86 | } 87 | 88 | static void configure_pins(usb_hal_context_t *usb) 89 | { 90 | /* usb_periph_iopins currently configures USB_OTG as USB Device. 91 | * Introduce additional parameters in usb_hal_context_t when adding support 92 | * for USB Host. 93 | */ 94 | for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) { 95 | if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) { 96 | esp_rom_gpio_pad_select_gpio(iopin->pin); 97 | if (iopin->is_output) { 98 | esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false); 99 | } else { 100 | esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false); 101 | if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) { 102 | gpio_ll_input_enable(&GPIO, iopin->pin); 103 | } 104 | } 105 | esp_rom_gpio_pad_unhold(iopin->pin); 106 | } 107 | } 108 | if (!usb->use_external_phy) { 109 | gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3); 110 | gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); 111 | } 112 | } 113 | 114 | // Turn LED on or off 115 | void board_led_write(bool state) 116 | { 117 | #ifdef NEOPIXEL_PIN 118 | strip->set_pixel(strip, 0, (state ? 0x88 : 0x00), 0x00, 0x00); 119 | strip->refresh(strip, 100); 120 | #endif 121 | } 122 | 123 | // Get the current state of button 124 | // a '1' means active (pressed), a '0' means inactive. 125 | uint32_t board_button_read(void) 126 | { 127 | return gpio_get_level(BUTTON_PIN) == BUTTON_STATE_ACTIVE; 128 | } 129 | 130 | // Get characters from UART 131 | int board_uart_read(uint8_t* buf, int len) 132 | { 133 | (void) buf; (void) len; 134 | return 0; 135 | } 136 | 137 | // Send characters to UART 138 | int board_uart_write(void const * buf, int len) 139 | { 140 | (void) buf; (void) len; 141 | return 0; 142 | } 143 | 144 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/espressif_kaluga_1/board.cmake: -------------------------------------------------------------------------------- 1 | # Apply board specific content here 2 | target_include_directories(${COMPONENT_LIB} PRIVATE .) 3 | 4 | idf_build_get_property(idf_target IDF_TARGET) 5 | 6 | message(STATUS "Apply ${BOARD}(${idf_target}) specific options for component: ${COMPONENT_TARGET}") 7 | 8 | if(NOT ${idf_target} STREQUAL "esp32s2") 9 | message(FATAL_ERROR "Incorrect target for board ${BOARD}: (${idf_target}), try to clean the build first." ) 10 | endif() 11 | 12 | set(IDF_TARGET "esp32s2" FORCE) 13 | 14 | target_compile_options(${COMPONENT_TARGET} PUBLIC 15 | "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" 16 | "-DCFG_TUSB_OS=OPT_OS_FREERTOS" 17 | ) -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/espressif_kaluga_1/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef BOARD_H_ 28 | #define BOARD_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | // Note: need to insert jumper next to WS2812 pixel 35 | #define NEOPIXEL_PIN 45 36 | 37 | #define BUTTON_PIN 0 38 | #define BUTTON_STATE_ACTIVE 0 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* BOARD_H_ */ 45 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/espressif_saola_1/board.cmake: -------------------------------------------------------------------------------- 1 | # Apply board specific content here 2 | target_include_directories(${COMPONENT_LIB} PRIVATE .) 3 | 4 | idf_build_get_property(idf_target IDF_TARGET) 5 | 6 | message(STATUS "Apply ${BOARD}(${idf_target}) specific options for component: ${COMPONENT_TARGET}") 7 | 8 | if(NOT ${idf_target} STREQUAL "esp32s2") 9 | message(FATAL_ERROR "Incorrect target for board ${BOARD}: (${idf_target}), try to clean the build first." ) 10 | endif() 11 | 12 | set(IDF_TARGET "esp32s2" FORCE) 13 | 14 | target_compile_options(${COMPONENT_TARGET} PUBLIC 15 | "-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" 16 | "-DCFG_TUSB_OS=OPT_OS_FREERTOS" 17 | ) -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/boards/espressif_saola_1/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef BOARD_H_ 28 | #define BOARD_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | // Note: On the production version (v1.2) WS2812 is connected to GPIO 18, 35 | // however earlier revision v1.1 WS2812 is connected to GPIO 17 36 | #define NEOPIXEL_PIN 18 37 | 38 | #define BUTTON_PIN 0 39 | #define BUTTON_STATE_ACTIVE 0 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* BOARD_H_ */ 46 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/family.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # Add example src and bsp directories 4 | set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s2/boards" "${TOP}/hw/bsp/esp32s2/components") 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | set(SUPPORTED_TARGETS esp32s2) 7 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s2/family.mk: -------------------------------------------------------------------------------- 1 | #DEPS_SUBMODULES += 2 | 3 | .PHONY: all clean flash bootloader-flash app-flash erase monitor dfu-flash dfu 4 | 5 | all: 6 | idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) -DIDF_TARGET=esp32s2 build 7 | 8 | build: all 9 | 10 | clean: 11 | idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) clean 12 | 13 | fullclean: 14 | if test -f sdkconfig; then $(RM) -f sdkconfig ; fi 15 | if test -d $(BUILD); then $(RM) -rf $(BUILD) ; fi 16 | 17 | flash bootloader-flash app-flash erase monitor dfu-flash dfu: 18 | idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) $@ 19 | 20 | uf2: $(BUILD)/$(PROJECT).uf2 21 | 22 | UF2_FAMILY_ID = 0xbfdd4eee 23 | $(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).bin 24 | @echo CREATE $@ 25 | $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -b 0x0 -c -o $@ $^ 26 | 27 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s3/boards/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS esp32s3.c 2 | INCLUDE_DIRS "." "${BOARD}" 3 | PRIV_REQUIRES "driver" 4 | REQUIRES freertos src led_strip) 5 | 6 | # Apply board specific content 7 | include("${BOARD}/board.cmake") 8 | 9 | idf_component_get_property( FREERTOS_ORIG_INCLUDE_PATH freertos ORIG_INCLUDE_PATH) 10 | target_include_directories(${COMPONENT_TARGET} PUBLIC 11 | "${FREERTOS_ORIG_INCLUDE_PATH}" 12 | "${TOP}/hw" 13 | "${TOP}/src" 14 | ) 15 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s3/boards/esp32s3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #include "../../board.h" 28 | #include "board.h" 29 | 30 | #include "esp_rom_gpio.h" 31 | #include "hal/gpio_ll.h" 32 | #include "hal/usb_hal.h" 33 | #include "soc/usb_periph.h" 34 | 35 | #include "driver/periph_ctrl.h" 36 | #include "driver/rmt.h" 37 | 38 | #ifdef NEOPIXEL_PIN 39 | #include "led_strip.h" 40 | static led_strip_t *strip; 41 | #endif 42 | 43 | //--------------------------------------------------------------------+ 44 | // MACRO TYPEDEF CONSTANT ENUM DECLARATION 45 | //--------------------------------------------------------------------+ 46 | 47 | static void configure_pins(usb_hal_context_t *usb); 48 | 49 | // Initialize on-board peripherals : led, button, uart and USB 50 | void board_init(void) 51 | { 52 | 53 | #ifdef NEOPIXEL_PIN 54 | #ifdef NEOPIXEL_POWER_PIN 55 | gpio_reset_pin(NEOPIXEL_POWER_PIN); 56 | gpio_set_direction(NEOPIXEL_POWER_PIN, GPIO_MODE_OUTPUT); 57 | gpio_set_level(NEOPIXEL_POWER_PIN, NEOPIXEL_POWER_STATE); 58 | #endif 59 | 60 | // WS2812 Neopixel driver with RMT peripheral 61 | rmt_config_t config = RMT_DEFAULT_CONFIG_TX(NEOPIXEL_PIN, RMT_CHANNEL_0); 62 | config.clk_div = 2; // set counter clock to 40MHz 63 | 64 | rmt_config(&config); 65 | rmt_driver_install(config.channel, 0, 0); 66 | 67 | led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t) config.channel); 68 | strip = led_strip_new_rmt_ws2812(&strip_config); 69 | strip->clear(strip, 100); // off led 70 | #endif 71 | 72 | // Button 73 | gpio_pad_select_gpio(BUTTON_PIN); 74 | gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT); 75 | gpio_set_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY); 76 | 77 | // USB Controller Hal init 78 | periph_module_reset(PERIPH_USB_MODULE); 79 | periph_module_enable(PERIPH_USB_MODULE); 80 | 81 | usb_hal_context_t hal = { 82 | .use_external_phy = false // use built-in PHY 83 | }; 84 | usb_hal_init(&hal); 85 | configure_pins(&hal); 86 | } 87 | 88 | static void configure_pins(usb_hal_context_t *usb) 89 | { 90 | /* usb_periph_iopins currently configures USB_OTG as USB Device. 91 | * Introduce additional parameters in usb_hal_context_t when adding support 92 | * for USB Host. 93 | */ 94 | for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) { 95 | if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) { 96 | esp_rom_gpio_pad_select_gpio(iopin->pin); 97 | if (iopin->is_output) { 98 | esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false); 99 | } else { 100 | esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false); 101 | if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) { 102 | gpio_ll_input_enable(&GPIO, iopin->pin); 103 | } 104 | } 105 | esp_rom_gpio_pad_unhold(iopin->pin); 106 | } 107 | } 108 | if (!usb->use_external_phy) { 109 | gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3); 110 | gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3); 111 | } 112 | } 113 | 114 | // Turn LED on or off 115 | void board_led_write(bool state) 116 | { 117 | #ifdef NEOPIXEL_PIN 118 | strip->set_pixel(strip, 0, (state ? 0x88 : 0x00), 0x00, 0x00); 119 | strip->refresh(strip, 100); 120 | #endif 121 | } 122 | 123 | // Get the current state of button 124 | // a '1' means active (pressed), a '0' means inactive. 125 | uint32_t board_button_read(void) 126 | { 127 | return gpio_get_level(BUTTON_PIN) == BUTTON_STATE_ACTIVE; 128 | } 129 | 130 | // Get characters from UART 131 | int board_uart_read(uint8_t* buf, int len) 132 | { 133 | (void) buf; (void) len; 134 | return 0; 135 | } 136 | 137 | // Send characters to UART 138 | int board_uart_write(void const * buf, int len) 139 | { 140 | (void) buf; (void) len; 141 | return 0; 142 | } 143 | 144 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s3/boards/espressif_addax_1/board.cmake: -------------------------------------------------------------------------------- 1 | # Apply board specific content here 2 | target_include_directories(${COMPONENT_LIB} PRIVATE .) 3 | 4 | idf_build_get_property(idf_target IDF_TARGET) 5 | 6 | message(STATUS "Apply ${BOARD}(${idf_target}) specific options for component: ${COMPONENT_TARGET}") 7 | 8 | if(NOT ${idf_target} STREQUAL "esp32s3") 9 | message(FATAL_ERROR "Incorrect target for board ${BOARD}: (${idf_target}), try to clean the build first." ) 10 | endif() 11 | 12 | set(IDF_TARGET "esp32s3" FORCE) 13 | 14 | target_compile_options(${COMPONENT_TARGET} PUBLIC 15 | "-DCFG_TUSB_MCU=OPT_MCU_ESP32S3" 16 | "-DCFG_TUSB_OS=OPT_OS_FREERTOS" 17 | ) -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s3/boards/espressif_addax_1/board.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef BOARD_H_ 28 | #define BOARD_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | // Note: On the production version (v1.1) WS2812 is connected to GPIO 47 35 | #define NEOPIXEL_PIN 47 36 | 37 | #define BUTTON_PIN 0 38 | #define BUTTON_STATE_ACTIVE 0 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* BOARD_H_ */ 45 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s3/family.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # Add example src and bsp directories 4 | set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/esp32s3/boards" "${TOP}/hw/bsp/esp32s3/components") 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | set(SUPPORTED_TARGETS esp32s3) 7 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/hw/bsp/esp32s3/family.mk: -------------------------------------------------------------------------------- 1 | #DEPS_SUBMODULES += 2 | 3 | .PHONY: all clean flash bootloader-flash app-flash erase monitor dfu-flash dfu 4 | 5 | all: 6 | idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) -DIDF_TARGET=esp32s3 build 7 | 8 | build: all 9 | 10 | clean: 11 | idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) clean 12 | 13 | fullclean: 14 | if test -f sdkconfig; then $(RM) -f sdkconfig ; fi 15 | if test -d $(BUILD); then $(RM) -rf $(BUILD) ; fi 16 | 17 | flash bootloader-flash app-flash erase monitor dfu-flash dfu: 18 | idf.py -B$(BUILD) -DFAMILY=$(FAMILY) -DBOARD=$(BOARD) $(CMAKE_DEFSYM) $@ 19 | 20 | uf2: $(BUILD)/$(PROJECT).uf2 21 | 22 | UF2_FAMILY_ID = 0xc47e5767 23 | $(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).bin 24 | @echo CREATE $@ 25 | $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -b 0x0 -c -o $@ $^ 26 | 27 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/SEGGER_RTT/License.txt: -------------------------------------------------------------------------------- 1 | Important - Read carefully: 2 | 3 | SEGGER RTT - Real Time Transfer for embedded targets 4 | 5 | All rights reserved. 6 | 7 | SEGGER strongly recommends to not make any changes 8 | to or modify the source code of this software in order to stay 9 | compatible with the RTT protocol and J-Link. 10 | 11 | Redistribution and use in source and binary forms, with or 12 | without modification, are permitted provided that the following 13 | condition is met: 14 | 15 | o Redistributions of source code must retain the above copyright 16 | notice, this condition and the following disclaimer. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 25 | OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 29 | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 30 | DAMAGE. 31 | 32 | 33 | (c) 2014 - 2016 SEGGER Microcontroller GmbH 34 | www.segger.com 35 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/SEGGER_RTT/README.txt: -------------------------------------------------------------------------------- 1 | README.txt for the SEGGER RTT Implementation Pack. 2 | 3 | Included files: 4 | =============== 5 | Root Directory 6 | - Examples 7 | - Main_RTT_InputEchoApp.c - Sample application which echoes input on Channel 0. 8 | - Main_RTT_MenuApp.c - Sample application to demonstrate RTT bi-directional functionality. 9 | - Main_RTT_PrintfTest.c - Sample application to test RTT small printf implementation. 10 | - Main_RTT_SpeedTestApp.c - Sample application for measuring RTT performance. embOS needed. 11 | - RTT 12 | - SEGGER_RTT.c - The RTT implementation. 13 | - SEGGER_RTT.h - Header for RTT implementation. 14 | - SEGGER_RTT_Conf.h - Pre-processor configuration for the RTT implementation. 15 | - SEGGER_RTT_Printf.c - Simple implementation of printf to write formatted strings via RTT. 16 | - Syscalls 17 | - RTT_Syscalls_GCC.c - Low-level syscalls to retarget printf() to RTT with GCC / Newlib. 18 | - RTT_Syscalls_IAR.c - Low-level syscalls to retarget printf() to RTT with IAR compiler. 19 | - RTT_Syscalls_KEIL.c - Low-level syscalls to retarget printf() to RTT with KEIL/uVision compiler. 20 | - RTT_Syscalls_SES.c - Low-level syscalls to retarget printf() to RTT with SEGGER Embedded Studio. 21 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/SEGGER_RTT/Syscalls/SEGGER_RTT_Syscalls_GCC.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * condition is met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this condition and the following disclaimer. * 28 | * * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 30 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 31 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 32 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 33 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 34 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 36 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 37 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 38 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 40 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 41 | * DAMAGE. * 42 | * * 43 | ********************************************************************** 44 | ---------------------------END-OF-HEADER------------------------------ 45 | File : SEGGER_RTT_Syscalls_GCC.c 46 | Purpose : Low-level functions for using printf() via RTT in GCC. 47 | To use RTT for printf output, include this file in your 48 | application. 49 | Revision: $Rev: 17697 $ 50 | ---------------------------------------------------------------------- 51 | */ 52 | #if (defined __GNUC__) && !(defined __SES_ARM) && !(defined __CROSSWORKS_ARM) 53 | 54 | #include // required for _write_r 55 | #include "SEGGER_RTT.h" 56 | 57 | 58 | /********************************************************************* 59 | * 60 | * Types 61 | * 62 | ********************************************************************** 63 | */ 64 | // 65 | // If necessary define the _reent struct 66 | // to match the one passed by the used standard library. 67 | // 68 | struct _reent; 69 | 70 | /********************************************************************* 71 | * 72 | * Function prototypes 73 | * 74 | ********************************************************************** 75 | */ 76 | int _write(int file, char *ptr, int len); 77 | int _write_r(struct _reent *r, int file, const void *ptr, int len); 78 | 79 | /********************************************************************* 80 | * 81 | * Global functions 82 | * 83 | ********************************************************************** 84 | */ 85 | 86 | /********************************************************************* 87 | * 88 | * _write() 89 | * 90 | * Function description 91 | * Low-level write function. 92 | * libc subroutines will use this system routine for output to all files, 93 | * including stdout. 94 | * Write data via RTT. 95 | */ 96 | int _write(int file, char *ptr, int len) { 97 | (void) file; /* Not used, avoid warning */ 98 | SEGGER_RTT_Write(0, ptr, len); 99 | return len; 100 | } 101 | 102 | /********************************************************************* 103 | * 104 | * _write_r() 105 | * 106 | * Function description 107 | * Low-level reentrant write function. 108 | * libc subroutines will use this system routine for output to all files, 109 | * including stdout. 110 | * Write data via RTT. 111 | */ 112 | int _write_r(struct _reent *r, int file, const void *ptr, int len) { 113 | (void) file; /* Not used, avoid warning */ 114 | (void) r; /* Not used, avoid warning */ 115 | SEGGER_RTT_Write(0, ptr, len); 116 | return len; 117 | } 118 | 119 | #endif 120 | /****** End Of File *************************************************/ 121 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/SEGGER_RTT/Syscalls/SEGGER_RTT_Syscalls_IAR.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | * SEGGER Microcontroller GmbH * 3 | * The Embedded Experts * 4 | ********************************************************************** 5 | * * 6 | * (c) 1995 - 2019 SEGGER Microcontroller GmbH * 7 | * * 8 | * www.segger.com Support: support@segger.com * 9 | * * 10 | ********************************************************************** 11 | * * 12 | * SEGGER RTT * Real Time Transfer for embedded targets * 13 | * * 14 | ********************************************************************** 15 | * * 16 | * All rights reserved. * 17 | * * 18 | * SEGGER strongly recommends to not make any changes * 19 | * to or modify the source code of this software in order to stay * 20 | * compatible with the RTT protocol and J-Link. * 21 | * * 22 | * Redistribution and use in source and binary forms, with or * 23 | * without modification, are permitted provided that the following * 24 | * condition is met: * 25 | * * 26 | * o Redistributions of source code must retain the above copyright * 27 | * notice, this condition and the following disclaimer. * 28 | * * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * 30 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * 31 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * 32 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * 33 | * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * 34 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * 35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * 36 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * 37 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * 38 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * 40 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 41 | * DAMAGE. * 42 | * * 43 | ********************************************************************** 44 | ---------------------------END-OF-HEADER------------------------------ 45 | File : SEGGER_RTT_Syscalls_IAR.c 46 | Purpose : Low-level functions for using printf() via RTT in IAR. 47 | To use RTT for printf output, include this file in your 48 | application and set the Library Configuration to Normal. 49 | Revision: $Rev: 17697 $ 50 | ---------------------------------------------------------------------- 51 | */ 52 | #ifdef __IAR_SYSTEMS_ICC__ 53 | 54 | // 55 | // Since IAR EWARM V8 and EWRX V4, yfuns.h is considered as deprecated and LowLevelIOInterface.h 56 | // shall be used instead. To not break any compatibility with older compiler versions, we have a 57 | // version check in here. 58 | // 59 | #if ((defined __ICCARM__) && (__VER__ >= 8000000)) || ((defined __ICCRX__) && (__VER__ >= 400)) 60 | #include 61 | #else 62 | #include 63 | #endif 64 | 65 | #include "SEGGER_RTT.h" 66 | #pragma module_name = "?__write" 67 | 68 | /********************************************************************* 69 | * 70 | * Function prototypes 71 | * 72 | ********************************************************************** 73 | */ 74 | size_t __write(int handle, const unsigned char * buffer, size_t size); 75 | 76 | /********************************************************************* 77 | * 78 | * Global functions 79 | * 80 | ********************************************************************** 81 | */ 82 | /********************************************************************* 83 | * 84 | * __write() 85 | * 86 | * Function description 87 | * Low-level write function. 88 | * Standard library subroutines will use this system routine 89 | * for output to all files, including stdout. 90 | * Write data via RTT. 91 | */ 92 | size_t __write(int handle, const unsigned char * buffer, size_t size) { 93 | (void) handle; /* Not used, avoid warning */ 94 | SEGGER_RTT_Write(0, (const char*)buffer, size); 95 | return size; 96 | } 97 | 98 | /********************************************************************* 99 | * 100 | * __write_buffered() 101 | * 102 | * Function description 103 | * Low-level write function. 104 | * Standard library subroutines will use this system routine 105 | * for output to all files, including stdout. 106 | * Write data via RTT. 107 | */ 108 | size_t __write_buffered(int handle, const unsigned char * buffer, size_t size) { 109 | (void) handle; /* Not used, avoid warning */ 110 | SEGGER_RTT_Write(0, (const char*)buffer, size); 111 | return size; 112 | } 113 | 114 | #endif 115 | /****** End Of File *************************************************/ 116 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/fatfs/diskio.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file (C)ChaN, 2013 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #define _USE_WRITE 1 /* 1: Enable disk_write function */ 13 | #define _USE_IOCTL 1 /* 1: Enable disk_ioctl fucntion */ 14 | 15 | #include "integer.h" 16 | #include 17 | 18 | /* Status of Disk Functions */ 19 | typedef BYTE DSTATUS; 20 | 21 | /* Results of Disk Functions */ 22 | typedef enum { 23 | RES_OK = 0, /* 0: Successful */ 24 | RES_ERROR, /* 1: R/W Error */ 25 | RES_WRPRT, /* 2: Write Protected */ 26 | RES_NOTRDY, /* 3: Not Ready */ 27 | RES_PARERR /* 4: Invalid Parameter */ 28 | } DRESULT; 29 | 30 | 31 | /* Disk Status Bits (DSTATUS) */ 32 | #define STA_NOINIT 0x01 /* Drive not initialized */ 33 | #define STA_NODISK 0x02 /* No medium in the drive */ 34 | #define STA_PROTECT 0x04 /* Write protected */ 35 | 36 | 37 | /* Command code for disk_ioctrl fucntion */ 38 | 39 | /* Generic command (used by FatFs) */ 40 | #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */ 41 | #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */ 42 | #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */ 43 | #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */ 44 | #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */ 45 | 46 | /* Generic command (not used by FatFs) */ 47 | #define CTRL_POWER 5 /* Get/Set power status */ 48 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 49 | #define CTRL_EJECT 7 /* Eject media */ 50 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 51 | 52 | /* MMC/SDC specific ioctl command */ 53 | #define MMC_GET_TYPE 10 /* Get card type */ 54 | #define MMC_GET_CSD 11 /* Get CSD */ 55 | #define MMC_GET_CID 12 /* Get CID */ 56 | #define MMC_GET_OCR 13 /* Get OCR */ 57 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 58 | 59 | /* ATA/CF specific ioctl command */ 60 | #define ATA_GET_REV 20 /* Get F/W revision */ 61 | #define ATA_GET_MODEL 21 /* Get model name */ 62 | #define ATA_GET_SN 22 /* Get serial number */ 63 | 64 | 65 | /* MMC card type flags (MMC_GET_TYPE) */ 66 | #define CT_MMC 0x01 /* MMC ver 3 */ 67 | #define CT_SD1 0x02 /* SD ver 1 */ 68 | #define CT_SD2 0x04 /* SD ver 2 */ 69 | #define CT_SDC (CT_SD1|CT_SD2) /* SD */ 70 | #define CT_BLOCK 0x08 /* Block addressing */ 71 | 72 | /*---------------------------------------*/ 73 | /* Prototypes for disk control functions */ 74 | 75 | void diskio_init(void); 76 | void disk_deinitialize ( BYTE pdrv ); 77 | DSTATUS disk_initialize (BYTE pdrv); 78 | DSTATUS disk_status (BYTE pdrv); 79 | DRESULT disk_read (BYTE pdrv, BYTE*buff, DWORD sector, BYTE count); 80 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, BYTE count); 81 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 82 | 83 | static inline bool disk_is_ready(BYTE pdrv); 84 | static inline bool disk_is_ready(BYTE pdrv) 85 | { 86 | return (pdrv < CFG_TUSB_HOST_DEVICE_MAX) && 87 | ( (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0 ); 88 | } 89 | 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif 96 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/fatfs/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef unsigned char UCHAR; 21 | typedef unsigned char BYTE; 22 | 23 | /* These types must be 16-bit integer */ 24 | typedef short SHORT; 25 | typedef unsigned short USHORT; 26 | typedef unsigned short WORD; 27 | typedef unsigned short WCHAR; 28 | 29 | /* These types must be 32-bit integer */ 30 | typedef long LONG; 31 | typedef unsigned long ULONG; 32 | typedef unsigned long DWORD; 33 | 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/networking/dhserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 by Sergey Fetisov 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* 26 | * version: 1.0 demo (7.02.2015) 27 | * brief: tiny dhcp ipv4 server using lwip (pcb) 28 | * ref: https://lists.gnu.org/archive/html/lwip-users/2012-12/msg00016.html 29 | */ 30 | 31 | #ifndef DHSERVER_H 32 | #define DHSERVER_H 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "lwip/err.h" 39 | #include "lwip/udp.h" 40 | #include "netif/etharp.h" 41 | 42 | typedef struct dhcp_entry 43 | { 44 | uint8_t mac[6]; 45 | ip_addr_t addr; 46 | uint32_t lease; 47 | } dhcp_entry_t; 48 | 49 | typedef struct dhcp_config 50 | { 51 | ip_addr_t router; 52 | uint16_t port; 53 | ip_addr_t dns; 54 | const char *domain; 55 | int num_entry; 56 | dhcp_entry_t *entries; 57 | } dhcp_config_t; 58 | 59 | err_t dhserv_init(const dhcp_config_t *config); 60 | void dhserv_free(void); 61 | 62 | #endif /* DHSERVER_H */ 63 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/lib/networking/dnserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 by Sergey Fetisov 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* 26 | * version: 1.0 demo (7.02.2015) 27 | * brief: tiny dns ipv4 server using lwip (pcb) 28 | */ 29 | 30 | #ifndef DNSERVER 31 | #define DNSERVER 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "lwip/def.h" 38 | #include "lwip/err.h" 39 | #include "lwip/udp.h" 40 | #include "netif/etharp.h" 41 | 42 | typedef bool (*dns_query_proc_t)(const char *name, ip_addr_t *addr); 43 | 44 | err_t dnserv_init(const ip_addr_t *bind, uint16_t port, dns_query_proc_t query_proc); 45 | void dnserv_free(void); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/pkg.yml: -------------------------------------------------------------------------------- 1 | pkg.name: tinyusb 2 | pkg.description: A silly USB stack for embedded 3 | pkg.author: "Ha Thach " 4 | pkg.homepage: "https://github.com/hathach/tinyusb" 5 | pkg.keywords: 6 | - usb 7 | 8 | pkg.type: sdk 9 | 10 | pkg.deps: 11 | - "@apache-mynewt-core/kernel/os" 12 | 13 | pkg.include_dirs: 14 | - src 15 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/repository.yml: -------------------------------------------------------------------------------- 1 | repo.name: tinyusb 2 | repo.versions: 3 | "0.0.0": "master" 4 | "0.5.0": "0.5.0" 5 | "0.6.0": "0.6.0" 6 | "0.7.0": "0.7.0" 7 | "0.8.0": "0.8.0" 8 | "0.9.0": "0.9.0" 9 | 10 | "0-dev": "0.0.0" # master 11 | "0-latest": "0.9.0" # latest stable release 12 | 13 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/bth/bth_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020 Jerzy Kasenberg 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef _TUSB_BTH_DEVICE_H_ 28 | #define _TUSB_BTH_DEVICE_H_ 29 | 30 | #include 31 | #include 32 | 33 | //--------------------------------------------------------------------+ 34 | // Class Driver Configuration 35 | //--------------------------------------------------------------------+ 36 | #ifndef CFG_TUD_BTH_EVENT_EPSIZE 37 | #define CFG_TUD_BTH_EVENT_EPSIZE 16 38 | #endif 39 | #ifndef CFG_TUD_BTH_DATA_EPSIZE 40 | #define CFG_TUD_BTH_DATA_EPSIZE 64 41 | #endif 42 | 43 | typedef struct TU_ATTR_PACKED 44 | { 45 | uint16_t op_code; 46 | uint8_t param_length; 47 | uint8_t param[255]; 48 | } bt_hci_cmd_t; 49 | 50 | #ifdef __cplusplus 51 | extern "C" { 52 | #endif 53 | 54 | //--------------------------------------------------------------------+ 55 | // Application Callback API (weak is optional) 56 | //--------------------------------------------------------------------+ 57 | 58 | // Invoked when HCI command was received over USB from Bluetooth host. 59 | // Detailed format is described in Bluetooth core specification Vol 2, 60 | // Part E, 5.4.1. 61 | // Length of the command is from 3 bytes (2 bytes for OpCode, 62 | // 1 byte for parameter total length) to 258. 63 | TU_ATTR_WEAK void tud_bt_hci_cmd_cb(void *hci_cmd, size_t cmd_len); 64 | 65 | // Invoked when ACL data was received over USB from Bluetooth host. 66 | // Detailed format is described in Bluetooth core specification Vol 2, 67 | // Part E, 5.4.2. 68 | // Length is from 4 bytes, (12 bits for Handle, 4 bits for flags 69 | // and 16 bits for data total length) to endpoint size. 70 | TU_ATTR_WEAK void tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len); 71 | 72 | // Called when event sent with tud_bt_event_send() was delivered to BT stack. 73 | // Controller can release/reuse buffer with Event packet at this point. 74 | TU_ATTR_WEAK void tud_bt_event_sent_cb(uint16_t sent_bytes); 75 | 76 | // Called when ACL data that was sent with tud_bt_acl_data_send() 77 | // was delivered to BT stack. 78 | // Controller can release/reuse buffer with ACL packet at this point. 79 | TU_ATTR_WEAK void tud_bt_acl_data_sent_cb(uint16_t sent_bytes); 80 | 81 | // Bluetooth controller calls this function when it wants to send even packet 82 | // as described in Bluetooth core specification Vol 2, Part E, 5.4.4. 83 | // Event has at least 2 bytes, first is Event code second contains parameter 84 | // total length. Controller can release/reuse event memory after 85 | // tud_bt_event_sent_cb() is called. 86 | bool tud_bt_event_send(void *event, uint16_t event_len); 87 | 88 | // Bluetooth controller calls this to send ACL data packet 89 | // as described in Bluetooth core specification Vol 2, Part E, 5.4.2 90 | // Minimum length is 4 bytes, (12 bits for Handle, 4 bits for flags 91 | // and 16 bits for data total length). Upper limit is not limited 92 | // to endpoint size since buffer is allocate by controller 93 | // and must not be reused till tud_bt_acl_data_sent_cb() is called. 94 | bool tud_bt_acl_data_send(void *acl_data, uint16_t data_len); 95 | 96 | //--------------------------------------------------------------------+ 97 | // Internal Class Driver API 98 | //--------------------------------------------------------------------+ 99 | void btd_init (void); 100 | void btd_reset (uint8_t rhport); 101 | uint16_t btd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); 102 | bool btd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request); 103 | bool btd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes); 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* _TUSB_BTH_DEVICE_H_ */ 110 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/cdc/cdc_rndis_host.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | /** \ingroup CDC_RNDIS 28 | * \defgroup CDC_RNSID_Host Host 29 | * @{ */ 30 | 31 | #ifndef _TUSB_CDC_RNDIS_HOST_H_ 32 | #define _TUSB_CDC_RNDIS_HOST_H_ 33 | 34 | #include "common/tusb_common.h" 35 | #include "host/usbh.h" 36 | #include "cdc_rndis.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | //--------------------------------------------------------------------+ 43 | // INTERNAL RNDIS-CDC Driver API 44 | //--------------------------------------------------------------------+ 45 | typedef struct { 46 | OSAL_SEM_DEF(semaphore_notification); 47 | osal_semaphore_handle_t sem_notification_hdl; // used to wait on notification pipe 48 | uint32_t max_xfer_size; // got from device's msg initialize complete 49 | uint8_t mac_address[6]; 50 | }rndish_data_t; 51 | 52 | void rndish_init(void); 53 | tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc); 54 | void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); 55 | void rndish_close(uint8_t dev_addr); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* _TUSB_CDC_RNDIS_HOST_H_ */ 62 | 63 | /** @} */ 64 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/dfu/dfu_rt_device.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Sylvain Munaut 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #include "tusb_option.h" 28 | 29 | #if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_DFU_RUNTIME) 30 | 31 | #include "dfu_rt_device.h" 32 | #include "device/usbd_pvt.h" 33 | 34 | //--------------------------------------------------------------------+ 35 | // MACRO CONSTANT TYPEDEF 36 | //--------------------------------------------------------------------+ 37 | typedef enum { 38 | DFU_REQUEST_DETACH = 0, 39 | DFU_REQUEST_DNLOAD = 1, 40 | DFU_REQUEST_UPLOAD = 2, 41 | DFU_REQUEST_GETSTATUS = 3, 42 | DFU_REQUEST_CLRSTATUS = 4, 43 | DFU_REQUEST_GETSTATE = 5, 44 | DFU_REQUEST_ABORT = 6, 45 | } dfu_requests_t; 46 | 47 | typedef struct TU_ATTR_PACKED 48 | { 49 | uint8_t status; 50 | uint8_t poll_timeout[3]; 51 | uint8_t state; 52 | uint8_t istring; 53 | } dfu_status_t; 54 | 55 | //--------------------------------------------------------------------+ 56 | // USBD Driver API 57 | //--------------------------------------------------------------------+ 58 | void dfu_rtd_init(void) 59 | { 60 | } 61 | 62 | void dfu_rtd_reset(uint8_t rhport) 63 | { 64 | (void) rhport; 65 | } 66 | 67 | uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) 68 | { 69 | (void) rhport; 70 | (void) max_len; 71 | 72 | // Ensure this is DFU Runtime 73 | TU_VERIFY(itf_desc->bInterfaceSubClass == TUD_DFU_APP_SUBCLASS && 74 | itf_desc->bInterfaceProtocol == DFU_PROTOCOL_RT, 0); 75 | 76 | uint8_t const * p_desc = tu_desc_next( itf_desc ); 77 | uint16_t drv_len = sizeof(tusb_desc_interface_t); 78 | 79 | if ( TUSB_DESC_FUNCTIONAL == tu_desc_type(p_desc) ) 80 | { 81 | drv_len += tu_desc_len(p_desc); 82 | p_desc = tu_desc_next(p_desc); 83 | } 84 | 85 | return drv_len; 86 | } 87 | 88 | // Invoked when a control transfer occurred on an interface of this class 89 | // Driver response accordingly to the request and the transfer stage (setup/data/ack) 90 | // return false to stall control endpoint (e.g unsupported request) 91 | bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) 92 | { 93 | // nothing to do with DATA and ACK stage 94 | if ( stage != CONTROL_STAGE_SETUP ) return true; 95 | 96 | TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE); 97 | 98 | // dfu-util will try to claim the interface with SET_INTERFACE request before sending DFU request 99 | if ( TUSB_REQ_TYPE_STANDARD == request->bmRequestType_bit.type && 100 | TUSB_REQ_SET_INTERFACE == request->bRequest ) 101 | { 102 | tud_control_status(rhport, request); 103 | return true; 104 | } 105 | 106 | // Handle class request only from here 107 | TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); 108 | 109 | switch ( request->bRequest ) 110 | { 111 | case DFU_REQUEST_DETACH: 112 | tud_control_status(rhport, request); 113 | tud_dfu_runtime_reboot_to_dfu_cb(); 114 | break; 115 | 116 | case DFU_REQUEST_GETSTATUS: 117 | { 118 | // status = OK, poll timeout = 0, state = app idle, istring = 0 119 | uint8_t status_response[6] = { 0, 0, 0, 0, 0, 0 }; 120 | tud_control_xfer(rhport, request, status_response, sizeof(status_response)); 121 | } 122 | break; 123 | 124 | default: return false; // stall unsupported request 125 | } 126 | 127 | return true; 128 | } 129 | 130 | bool dfu_rtd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) 131 | { 132 | (void) rhport; 133 | (void) ep_addr; 134 | (void) result; 135 | (void) xferred_bytes; 136 | return true; 137 | } 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/dfu/dfu_rt_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Sylvain Munaut 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef _TUSB_DFU_RT_DEVICE_H_ 28 | #define _TUSB_DFU_RT_DEVICE_H_ 29 | 30 | #include "common/tusb_common.h" 31 | #include "device/usbd.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | //--------------------------------------------------------------------+ 39 | // Common Definitions 40 | //--------------------------------------------------------------------+ 41 | 42 | // DFU Protocol 43 | typedef enum 44 | { 45 | DFU_PROTOCOL_RT = 1, 46 | DFU_PROTOCOL_DFU = 2, 47 | } dfu_protocol_type_t; 48 | 49 | // DFU Descriptor Type 50 | typedef enum 51 | { 52 | DFU_DESC_FUNCTIONAL = 0x21, 53 | } dfu_descriptor_type_t; 54 | 55 | 56 | //--------------------------------------------------------------------+ 57 | // Application Callback API (weak is optional) 58 | //--------------------------------------------------------------------+ 59 | 60 | // Invoked when received new data 61 | TU_ATTR_WEAK void tud_dfu_runtime_reboot_to_dfu_cb(void); 62 | 63 | //--------------------------------------------------------------------+ 64 | // Internal Class Driver API 65 | //--------------------------------------------------------------------+ 66 | void dfu_rtd_init(void); 67 | void dfu_rtd_reset(uint8_t rhport); 68 | uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); 69 | bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); 70 | bool dfu_rtd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* _TUSB_DFU_RT_DEVICE_H_ */ 77 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/net/net_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020 Peter Lawrence 5 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | * 25 | * This file is part of the TinyUSB stack. 26 | */ 27 | 28 | #ifndef _TUSB_NET_DEVICE_H_ 29 | #define _TUSB_NET_DEVICE_H_ 30 | 31 | #include "common/tusb_common.h" 32 | #include "device/usbd.h" 33 | #include "class/cdc/cdc.h" 34 | 35 | /* declared here, NOT in usb_descriptors.c, so that the driver can intelligently ZLP as needed */ 36 | #define CFG_TUD_NET_ENDPOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) 37 | 38 | /* Maximum Tranmission Unit (in bytes) of the network, including Ethernet header */ 39 | #ifndef CFG_TUD_NET_MTU 40 | #define CFG_TUD_NET_MTU 1514 41 | #endif 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | //--------------------------------------------------------------------+ 48 | // Application API 49 | //--------------------------------------------------------------------+ 50 | 51 | // client must provide this: initialize any network state back to the beginning 52 | void tud_network_init_cb(void); 53 | 54 | // client must provide this: return false if the packet buffer was not accepted 55 | bool tud_network_recv_cb(const uint8_t *src, uint16_t size); 56 | 57 | // client must provide this: copy from network stack packet pointer to dst 58 | uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg); 59 | 60 | // client must provide this: 48-bit MAC address 61 | // TODO removed later since it is not part of tinyusb stack 62 | extern const uint8_t tud_network_mac_address[6]; 63 | 64 | // indicate to network driver that client has finished with the packet provided to network_recv_cb() 65 | void tud_network_recv_renew(void); 66 | 67 | // poll network driver for its ability to accept another packet to transmit 68 | bool tud_network_can_xmit(void); 69 | 70 | // if network_can_xmit() returns true, network_xmit() can be called once 71 | void tud_network_xmit(void *ref, uint16_t arg); 72 | 73 | //--------------------------------------------------------------------+ 74 | // INTERNAL USBD-CLASS DRIVER API 75 | //--------------------------------------------------------------------+ 76 | void netd_init (void); 77 | void netd_reset (uint8_t rhport); 78 | uint16_t netd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); 79 | bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); 80 | bool netd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); 81 | void netd_report (uint8_t *buf, uint16_t len); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* _TUSB_NET_DEVICE_H_ */ 88 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/usbtmc/usbtmc_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usbtmc_device.h 3 | * 4 | * Created on: Sep 10, 2019 5 | * Author: nconrad 6 | */ 7 | /* 8 | * The MIT License (MIT) 9 | * 10 | * Copyright (c) 2019 N Conrad 11 | * 12 | * Permission is hereby granted, free of charge, to any person obtaining a copy 13 | * of this software and associated documentation files (the "Software"), to deal 14 | * in the Software without restriction, including without limitation the rights 15 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 | * copies of the Software, and to permit persons to whom the Software is 17 | * furnished to do so, subject to the following conditions: 18 | * 19 | * The above copyright notice and this permission notice shall be included in 20 | * all copies or substantial portions of the Software. 21 | * 22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 28 | * THE SOFTWARE. 29 | * 30 | * This file is part of the TinyUSB stack. 31 | */ 32 | 33 | 34 | #ifndef CLASS_USBTMC_USBTMC_DEVICE_H_ 35 | #define CLASS_USBTMC_USBTMC_DEVICE_H_ 36 | 37 | #include "usbtmc.h" 38 | 39 | // Enable 488 mode by default 40 | #if !defined(CFG_TUD_USBTMC_ENABLE_488) 41 | #define CFG_TUD_USBTMC_ENABLE_488 (1) 42 | #endif 43 | 44 | // USB spec says that full-speed must be 8,16,32, or 64. 45 | // However, this driver implementation requires it to be >=32 46 | #define USBTMCD_MAX_PACKET_SIZE (64u) 47 | 48 | /*********************************************** 49 | * Functions to be implemeted by the class implementation 50 | */ 51 | 52 | // In order to proceed, app must call call tud_usbtmc_start_bus_read(rhport) during or soon after: 53 | // * tud_usbtmc_open_cb 54 | // * tud_usbtmc_msg_data_cb 55 | // * tud_usbtmc_msgBulkIn_complete_cb 56 | // * tud_usbtmc_msg_trigger_cb 57 | // * (successful) tud_usbtmc_check_abort_bulk_out_cb 58 | // * (successful) tud_usbtmc_check_abort_bulk_in_cb 59 | // * (successful) tud_usmtmc_bulkOut_clearFeature_cb 60 | 61 | #if (CFG_TUD_USBTMC_ENABLE_488) 62 | usbtmc_response_capabilities_488_t const * tud_usbtmc_get_capabilities_cb(void); 63 | #else 64 | usbtmc_response_capabilities_t const * tud_usbtmc_get_capabilities_cb(void); 65 | #endif 66 | 67 | void tud_usbtmc_open_cb(uint8_t interface_id); 68 | 69 | bool tud_usbtmc_msgBulkOut_start_cb(usbtmc_msg_request_dev_dep_out const * msgHeader); 70 | // transfer_complete does not imply that a message is complete. 71 | bool tud_usbtmc_msg_data_cb( void *data, size_t len, bool transfer_complete); 72 | void tud_usbtmc_bulkOut_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer 73 | 74 | bool tud_usbtmc_msgBulkIn_request_cb(usbtmc_msg_request_dev_dep_in const * request); 75 | bool tud_usbtmc_msgBulkIn_complete_cb(void); 76 | void tud_usbtmc_bulkIn_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer 77 | 78 | bool tud_usbtmc_initiate_abort_bulk_in_cb(uint8_t *tmcResult); 79 | bool tud_usbtmc_initiate_abort_bulk_out_cb(uint8_t *tmcResult); 80 | bool tud_usbtmc_initiate_clear_cb(uint8_t *tmcResult); 81 | 82 | bool tud_usbtmc_check_abort_bulk_in_cb(usbtmc_check_abort_bulk_rsp_t *rsp); 83 | bool tud_usbtmc_check_abort_bulk_out_cb(usbtmc_check_abort_bulk_rsp_t *rsp); 84 | bool tud_usbtmc_check_clear_cb(usbtmc_get_clear_status_rsp_t *rsp); 85 | 86 | // Indicator pulse should be 0.5 to 1.0 seconds long 87 | TU_ATTR_WEAK bool tud_usbtmc_indicator_pulse_cb(tusb_control_request_t const * msg, uint8_t *tmcResult); 88 | 89 | #if (CFG_TUD_USBTMC_ENABLE_488) 90 | uint8_t tud_usbtmc_get_stb_cb(uint8_t *tmcResult); 91 | TU_ATTR_WEAK bool tud_usbtmc_msg_trigger_cb(usbtmc_msg_generic_t* msg); 92 | //TU_ATTR_WEAK bool tud_usbtmc_app_go_to_local_cb(); 93 | #endif 94 | 95 | /******************************************* 96 | * Called from app 97 | * 98 | * We keep a reference to the buffer, so it MUST not change until the app is 99 | * notified that the transfer is complete. 100 | ******************************************/ 101 | 102 | bool tud_usbtmc_transmit_dev_msg_data( 103 | const void * data, size_t len, 104 | bool endOfMessage, bool usingTermChar); 105 | 106 | bool tud_usbtmc_start_bus_read(void); 107 | 108 | 109 | /* "callbacks" from USB device core */ 110 | 111 | uint16_t usbtmcd_open_cb(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); 112 | void usbtmcd_reset_cb(uint8_t rhport); 113 | bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); 114 | bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); 115 | void usbtmcd_init_cb(void); 116 | 117 | /************************************************************ 118 | * USBTMC Descriptor Templates 119 | *************************************************************/ 120 | 121 | 122 | #endif /* CLASS_USBTMC_USBTMC_DEVICE_H_ */ 123 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/vendor/vendor_device.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef _TUSB_VENDOR_DEVICE_H_ 28 | #define _TUSB_VENDOR_DEVICE_H_ 29 | 30 | #include "common/tusb_common.h" 31 | #include "device/usbd.h" 32 | 33 | #ifndef CFG_TUD_VENDOR_EPSIZE 34 | #define CFG_TUD_VENDOR_EPSIZE 64 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | //--------------------------------------------------------------------+ 42 | // Application API (Multiple Interfaces) 43 | //--------------------------------------------------------------------+ 44 | bool tud_vendor_n_mounted (uint8_t itf); 45 | 46 | uint32_t tud_vendor_n_available (uint8_t itf); 47 | uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize); 48 | bool tud_vendor_n_peek (uint8_t itf, int pos, uint8_t* u8); 49 | 50 | uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize); 51 | uint32_t tud_vendor_n_write_available (uint8_t itf); 52 | 53 | static inline 54 | uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str); 55 | 56 | //--------------------------------------------------------------------+ 57 | // Application API (Single Port) 58 | //--------------------------------------------------------------------+ 59 | static inline bool tud_vendor_mounted (void); 60 | static inline uint32_t tud_vendor_available (void); 61 | static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize); 62 | static inline bool tud_vendor_peek (int pos, uint8_t* u8); 63 | static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize); 64 | static inline uint32_t tud_vendor_write_str (char const* str); 65 | static inline uint32_t tud_vendor_write_available (void); 66 | 67 | //--------------------------------------------------------------------+ 68 | // Application Callback API (weak is optional) 69 | //--------------------------------------------------------------------+ 70 | 71 | // Invoked when received new data 72 | TU_ATTR_WEAK void tud_vendor_rx_cb(uint8_t itf); 73 | 74 | //--------------------------------------------------------------------+ 75 | // Inline Functions 76 | //--------------------------------------------------------------------+ 77 | 78 | static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str) 79 | { 80 | return tud_vendor_n_write(itf, str, strlen(str)); 81 | } 82 | 83 | static inline bool tud_vendor_mounted (void) 84 | { 85 | return tud_vendor_n_mounted(0); 86 | } 87 | 88 | static inline uint32_t tud_vendor_available (void) 89 | { 90 | return tud_vendor_n_available(0); 91 | } 92 | 93 | static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize) 94 | { 95 | return tud_vendor_n_read(0, buffer, bufsize); 96 | } 97 | 98 | static inline bool tud_vendor_peek (int pos, uint8_t* u8) 99 | { 100 | return tud_vendor_n_peek(0, pos, u8); 101 | } 102 | 103 | static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize) 104 | { 105 | return tud_vendor_n_write(0, buffer, bufsize); 106 | } 107 | 108 | static inline uint32_t tud_vendor_write_str (char const* str) 109 | { 110 | return tud_vendor_n_write_str(0, str); 111 | } 112 | 113 | static inline uint32_t tud_vendor_write_available (void) 114 | { 115 | return tud_vendor_n_write_available(0); 116 | } 117 | 118 | //--------------------------------------------------------------------+ 119 | // Internal Class Driver API 120 | //--------------------------------------------------------------------+ 121 | void vendord_init(void); 122 | void vendord_reset(uint8_t rhport); 123 | uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); 124 | bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif /* _TUSB_VENDOR_DEVICE_H_ */ 131 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/class/vendor/vendor_host.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | /** \ingroup group_class 28 | * \defgroup Group_Custom Custom Class (not supported yet) 29 | * @{ */ 30 | 31 | #ifndef _TUSB_VENDOR_HOST_H_ 32 | #define _TUSB_VENDOR_HOST_H_ 33 | 34 | #include "common/tusb_common.h" 35 | #include "host/usbh.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | typedef struct { 42 | pipe_handle_t pipe_in; 43 | pipe_handle_t pipe_out; 44 | }custom_interface_info_t; 45 | 46 | //--------------------------------------------------------------------+ 47 | // USBH-CLASS DRIVER API 48 | //--------------------------------------------------------------------+ 49 | static inline bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id) 50 | { 51 | (void) vendor_id; // TODO check this later 52 | (void) product_id; 53 | // return (tusbh_device_get_mounted_class_flag(dev_addr) & TU_BIT(TUSB_CLASS_MAPPED_INDEX_END-1) ) != 0; 54 | return false; 55 | } 56 | 57 | tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length); 58 | tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void const * p_data, uint16_t length); 59 | 60 | //--------------------------------------------------------------------+ 61 | // Internal Class Driver API 62 | //--------------------------------------------------------------------+ 63 | void cush_init(void); 64 | tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length); 65 | void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event); 66 | void cush_close(uint8_t dev_addr); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* _TUSB_VENDOR_HOST_H_ */ 73 | 74 | /** @} */ 75 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/common/tusb_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | /** \ingroup Group_Common 28 | * \defgroup Group_Error Error Codes 29 | * @{ */ 30 | 31 | #ifndef _TUSB_ERRORS_H_ 32 | #define _TUSB_ERRORS_H_ 33 | 34 | #include "tusb_option.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #define ERROR_ENUM(x) x, 41 | #define ERROR_STRING(x) #x, 42 | 43 | #define ERROR_TABLE(ENTRY) \ 44 | ENTRY(TUSB_ERROR_NONE )\ 45 | ENTRY(TUSB_ERROR_INVALID_PARA )\ 46 | ENTRY(TUSB_ERROR_DEVICE_NOT_READY )\ 47 | ENTRY(TUSB_ERROR_INTERFACE_IS_BUSY )\ 48 | ENTRY(TUSB_ERROR_HCD_OPEN_PIPE_FAILED )\ 49 | ENTRY(TUSB_ERROR_OSAL_TIMEOUT )\ 50 | ENTRY(TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED )\ 51 | ENTRY(TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED )\ 52 | ENTRY(TUSB_ERROR_NOT_SUPPORTED )\ 53 | ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\ 54 | ENTRY(TUSB_ERROR_FAILED )\ 55 | 56 | /// \brief Error Code returned 57 | /// TODO obsolete and to be remove 58 | typedef enum 59 | { 60 | ERROR_TABLE(ERROR_ENUM) 61 | TUSB_ERROR_COUNT 62 | }tusb_error_t; 63 | 64 | #if CFG_TUSB_DEBUG 65 | /// Enum to String for debugging purposes. Only available if \ref CFG_TUSB_DEBUG > 0 66 | extern char const* const tusb_strerr[TUSB_ERROR_COUNT]; 67 | #endif 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif /* _TUSB_ERRORS_H_ */ 74 | 75 | /** @} */ 76 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/common/tusb_timeout.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | /** \ingroup Group_Common Common Files 28 | * \defgroup Group_TimeoutTimer timeout timer 29 | * @{ */ 30 | 31 | #ifndef _TUSB_TIMEOUT_H_ 32 | #define _TUSB_TIMEOUT_H_ 33 | 34 | #include 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | typedef struct { 42 | uint32_t start; 43 | uint32_t interval; 44 | }tu_timeout_t; 45 | 46 | #if 0 47 | 48 | extern uint32_t tusb_hal_millis(void); 49 | 50 | static inline void tu_timeout_set(tu_timeout_t* tt, uint32_t msec) 51 | { 52 | tt->interval = msec; 53 | tt->start = tusb_hal_millis(); 54 | } 55 | 56 | static inline bool tu_timeout_expired(tu_timeout_t* tt) 57 | { 58 | return ( tusb_hal_millis() - tt->start ) >= tt->interval; 59 | } 60 | 61 | // For used with periodic event to prevent drift 62 | static inline void tu_timeout_reset(tu_timeout_t* tt) 63 | { 64 | tt->start += tt->interval; 65 | } 66 | 67 | static inline void tu_timeout_restart(tu_timeout_t* tt) 68 | { 69 | tt->start = tusb_hal_millis(); 70 | } 71 | 72 | #endif 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* _TUSB_TIMEOUT_H_ */ 79 | 80 | /** @} */ 81 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/device/usbd_pvt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | #ifndef USBD_PVT_H_ 27 | #define USBD_PVT_H_ 28 | 29 | #include "osal/osal.h" 30 | #include "common/tusb_fifo.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | //--------------------------------------------------------------------+ 37 | // Class Drivers 38 | //--------------------------------------------------------------------+ 39 | 40 | typedef struct 41 | { 42 | #if CFG_TUSB_DEBUG >= 2 43 | char const* name; 44 | #endif 45 | 46 | void (* init ) (void); 47 | void (* reset ) (uint8_t rhport); 48 | uint16_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t max_len); 49 | bool (* control_xfer_cb ) (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); 50 | bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); 51 | void (* sof ) (uint8_t rhport); /* optional */ 52 | } usbd_class_driver_t; 53 | 54 | // Invoked when initializing device stack to get additional class drivers. 55 | // Can optionally implemented by application to extend/overwrite class driver support. 56 | // Note: The drivers array must be accessible at all time when stack is active 57 | usbd_class_driver_t const* usbd_app_driver_get_cb(uint8_t* driver_count) TU_ATTR_WEAK; 58 | 59 | 60 | typedef bool (*usbd_control_xfer_cb_t)(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request); 61 | 62 | //--------------------------------------------------------------------+ 63 | // USBD Endpoint API 64 | //--------------------------------------------------------------------+ 65 | 66 | // Open an endpoint 67 | bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * desc_ep); 68 | 69 | // Close an endpoint 70 | void usbd_edpt_close(uint8_t rhport, uint8_t ep_addr); 71 | 72 | // Submit a usb transfer 73 | bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes); 74 | 75 | // Submit a usb ISO transfer by use of a FIFO (ring buffer) - all bytes in FIFO get transmitted 76 | bool usbd_edpt_iso_xfer(uint8_t rhport, uint8_t ep_addr, tu_fifo_t * ff, uint16_t total_bytes); 77 | 78 | // Claim an endpoint before submitting a transfer. 79 | // If caller does not make any transfer, it must release endpoint for others. 80 | bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr); 81 | 82 | // Release an endpoint without submitting a transfer 83 | bool usbd_edpt_release(uint8_t rhport, uint8_t ep_addr); 84 | 85 | // Check if endpoint transferring is complete 86 | bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr); 87 | 88 | // Stall endpoint 89 | void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr); 90 | 91 | // Clear stalled endpoint 92 | void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr); 93 | 94 | // Check if endpoint is stalled 95 | bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr); 96 | 97 | static inline 98 | bool usbd_edpt_ready(uint8_t rhport, uint8_t ep_addr) 99 | { 100 | return !usbd_edpt_busy(rhport, ep_addr) && !usbd_edpt_stalled(rhport, ep_addr); 101 | } 102 | 103 | /*------------------------------------------------------------------*/ 104 | /* Helper 105 | *------------------------------------------------------------------*/ 106 | 107 | bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in); 108 | void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr ); 109 | 110 | 111 | #ifdef __cplusplus 112 | } 113 | #endif 114 | 115 | #endif /* USBD_PVT_H_ */ 116 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/host/usbh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | /** \ingroup group_usbh USB Host Core (USBH) 28 | * @{ */ 29 | 30 | #ifndef _TUSB_USBH_H_ 31 | #define _TUSB_USBH_H_ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | //--------------------------------------------------------------------+ 38 | // INCLUDE 39 | //--------------------------------------------------------------------+ 40 | #include "osal/osal.h" // TODO refractor move to common.h ? 41 | #include "hcd.h" 42 | 43 | //--------------------------------------------------------------------+ 44 | // MACRO CONSTANT TYPEDEF 45 | //--------------------------------------------------------------------+ 46 | typedef enum tusb_interface_status_{ 47 | TUSB_INTERFACE_STATUS_READY = 0, 48 | TUSB_INTERFACE_STATUS_BUSY, 49 | TUSB_INTERFACE_STATUS_COMPLETE, 50 | TUSB_INTERFACE_STATUS_ERROR, 51 | TUSB_INTERFACE_STATUS_INVALID_PARA 52 | } tusb_interface_status_t; 53 | 54 | typedef struct { 55 | #if CFG_TUSB_DEBUG >= 2 56 | char const* name; 57 | #endif 58 | 59 | uint8_t class_code; 60 | 61 | void (* const init )(void); 62 | bool (* const open )(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const * itf_desc, uint16_t* outlen); 63 | bool (* const set_config )(uint8_t dev_addr, uint8_t itf_num); 64 | bool (* const xfer_cb )(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); 65 | void (* const close )(uint8_t dev_addr); 66 | } usbh_class_driver_t; 67 | 68 | typedef bool (*tuh_control_complete_cb_t)(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result); 69 | 70 | //--------------------------------------------------------------------+ 71 | // INTERNAL OBJECT & FUNCTION DECLARATION 72 | //--------------------------------------------------------------------+ 73 | 74 | //--------------------------------------------------------------------+ 75 | // APPLICATION API 76 | //--------------------------------------------------------------------+ 77 | 78 | // Init host stack 79 | bool tuh_init(void); 80 | 81 | // Task function should be called in main/rtos loop 82 | void tuh_task(void); 83 | 84 | // Interrupt handler, name alias to HCD 85 | extern void hcd_int_handler(uint8_t rhport); 86 | #define tuh_int_handler hcd_int_handler 87 | 88 | tusb_device_state_t tuh_device_get_state (uint8_t dev_addr); 89 | tusb_speed_t tuh_device_get_speed (uint8_t dev_addr); 90 | static inline bool tuh_device_is_configured(uint8_t dev_addr) 91 | { 92 | return tuh_device_get_state(dev_addr) == TUSB_DEVICE_STATE_CONFIGURED; 93 | } 94 | 95 | bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb); 96 | 97 | //--------------------------------------------------------------------+ 98 | // APPLICATION CALLBACK 99 | //--------------------------------------------------------------------+ 100 | //TU_ATTR_WEAK uint8_t tuh_attach_cb (tusb_desc_device_t const *desc_device); 101 | 102 | /** Callback invoked when device is mounted (configured) */ 103 | TU_ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr); 104 | 105 | /** Callback invoked when device is unmounted (bus reset/unplugged) */ 106 | TU_ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr); 107 | 108 | //--------------------------------------------------------------------+ 109 | // CLASS-USBH & INTERNAL API 110 | // TODO move to usbh_pvt.h 111 | //--------------------------------------------------------------------+ 112 | 113 | bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); 114 | bool usbh_edpt_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes); 115 | 116 | // Claim an endpoint before submitting a transfer. 117 | // If caller does not make any transfer, it must release endpoint for others. 118 | bool usbh_edpt_claim(uint8_t dev_addr, uint8_t ep_addr); 119 | 120 | void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num); 121 | 122 | uint8_t usbh_get_rhport(uint8_t dev_addr); 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif /* _TUSB_USBH_H_ */ 129 | 130 | /** @} */ 131 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/host/usbh_control.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020, Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #include "tusb_option.h" 28 | 29 | #if TUSB_OPT_HOST_ENABLED 30 | 31 | #include "tusb.h" 32 | #include "usbh_hcd.h" 33 | 34 | enum 35 | { 36 | STAGE_SETUP, 37 | STAGE_DATA, 38 | STAGE_ACK 39 | }; 40 | 41 | typedef struct 42 | { 43 | tusb_control_request_t request TU_ATTR_ALIGNED(4); 44 | 45 | uint8_t stage; 46 | uint8_t* buffer; 47 | tuh_control_complete_cb_t complete_cb; 48 | } usbh_control_xfer_t; 49 | 50 | static usbh_control_xfer_t _ctrl_xfer; 51 | 52 | //CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN 53 | //static uint8_t _tuh_ctrl_buf[CFG_TUSB_HOST_ENUM_BUFFER_SIZE]; 54 | 55 | //--------------------------------------------------------------------+ 56 | // MACRO TYPEDEF CONSTANT ENUM DECLARATION 57 | //--------------------------------------------------------------------+ 58 | 59 | bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb) 60 | { 61 | // TODO need to claim the endpoint first 62 | 63 | usbh_device_t* dev = &_usbh_devices[dev_addr]; 64 | const uint8_t rhport = dev->rhport; 65 | 66 | _ctrl_xfer.request = (*request); 67 | _ctrl_xfer.buffer = buffer; 68 | _ctrl_xfer.stage = STAGE_SETUP; 69 | _ctrl_xfer.complete_cb = complete_cb; 70 | 71 | TU_LOG2("Control Setup: "); 72 | TU_LOG2_VAR(request); 73 | TU_LOG2("\r\n"); 74 | 75 | // Send setup packet 76 | TU_ASSERT( hcd_setup_send(rhport, dev_addr, (uint8_t const*) &_ctrl_xfer.request) ); 77 | 78 | return true; 79 | } 80 | 81 | static void _xfer_complete(uint8_t dev_addr, xfer_result_t result) 82 | { 83 | if (_ctrl_xfer.complete_cb) _ctrl_xfer.complete_cb(dev_addr, &_ctrl_xfer.request, result); 84 | } 85 | 86 | bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) 87 | { 88 | (void) ep_addr; 89 | (void) xferred_bytes; 90 | 91 | usbh_device_t* dev = &_usbh_devices[dev_addr]; 92 | const uint8_t rhport = dev->rhport; 93 | 94 | tusb_control_request_t const * request = &_ctrl_xfer.request; 95 | 96 | if (XFER_RESULT_SUCCESS != result) 97 | { 98 | TU_LOG2("Control failed: result = %d\r\n", result); 99 | 100 | // terminate transfer if any stage failed 101 | _xfer_complete(dev_addr, result); 102 | }else 103 | { 104 | switch(_ctrl_xfer.stage) 105 | { 106 | case STAGE_SETUP: 107 | _ctrl_xfer.stage = STAGE_DATA; 108 | if (request->wLength) 109 | { 110 | // Note: initial data toggle is always 1 111 | hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), _ctrl_xfer.buffer, request->wLength); 112 | return true; 113 | } 114 | __attribute__((fallthrough)); 115 | 116 | case STAGE_DATA: 117 | _ctrl_xfer.stage = STAGE_ACK; 118 | 119 | if (request->wLength) 120 | { 121 | TU_LOG2("Control data:\r\n"); 122 | TU_LOG2_MEM(_ctrl_xfer.buffer, request->wLength, 2); 123 | } 124 | 125 | // data toggle is always 1 126 | hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0); 127 | break; 128 | 129 | case STAGE_ACK: 130 | _xfer_complete(dev_addr, result); 131 | break; 132 | 133 | default: return false; 134 | } 135 | } 136 | 137 | return true; 138 | } 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/host/usbh_hcd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | /** \ingroup Group_HCD 28 | * @{ */ 29 | 30 | #ifndef _TUSB_USBH_HCD_H_ 31 | #define _TUSB_USBH_HCD_H_ 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | //--------------------------------------------------------------------+ 38 | // INCLUDE 39 | //--------------------------------------------------------------------+ 40 | #include "common/tusb_common.h" 41 | #include "osal/osal.h" 42 | 43 | #ifndef CFG_TUH_EP_MAX 44 | #define CFG_TUH_EP_MAX 9 45 | #endif 46 | 47 | //--------------------------------------------------------------------+ 48 | // USBH-HCD common data structure 49 | //--------------------------------------------------------------------+ 50 | 51 | // TODO move to usbh.c 52 | typedef struct { 53 | //------------- port -------------// 54 | uint8_t rhport; 55 | uint8_t hub_addr; 56 | uint8_t hub_port; 57 | uint8_t speed; 58 | 59 | //------------- device descriptor -------------// 60 | uint16_t vendor_id; 61 | uint16_t product_id; 62 | uint8_t ep0_packet_size; 63 | 64 | //------------- configuration descriptor -------------// 65 | // uint8_t interface_count; // bNumInterfaces alias 66 | 67 | //------------- device -------------// 68 | struct TU_ATTR_PACKED 69 | { 70 | uint8_t connected : 1; 71 | uint8_t addressed : 1; 72 | uint8_t configured : 1; 73 | uint8_t suspended : 1; 74 | }; 75 | 76 | volatile uint8_t state; // device state, value from enum tusbh_device_state_t 77 | 78 | uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) 79 | uint8_t ep2drv[CFG_TUH_EP_MAX][2]; // map endpoint to driver ( 0xff is invalid ) 80 | 81 | struct TU_ATTR_PACKED 82 | { 83 | volatile bool busy : 1; 84 | volatile bool stalled : 1; 85 | volatile bool claimed : 1; 86 | 87 | // TODO merge ep2drv here, 4-bit should be sufficient 88 | }ep_status[CFG_TUH_EP_MAX][2]; 89 | 90 | // Mutex for claiming endpoint, only needed when using with preempted RTOS 91 | #if CFG_TUSB_OS != OPT_OS_NONE 92 | osal_mutex_def_t mutexdef; 93 | osal_mutex_t mutex; 94 | #endif 95 | 96 | } usbh_device_t; 97 | 98 | extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address 99 | 100 | //--------------------------------------------------------------------+ 101 | // callback from HCD ISR 102 | //--------------------------------------------------------------------+ 103 | 104 | 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif /* _TUSB_USBH_HCD_H_ */ 111 | 112 | /** @} */ 113 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/osal/osal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef _TUSB_OSAL_H_ 28 | #define _TUSB_OSAL_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** \addtogroup group_osal 35 | * @{ */ 36 | 37 | #include "common/tusb_common.h" 38 | 39 | // Return immediately 40 | #define OSAL_TIMEOUT_NOTIMEOUT (0) 41 | // Default timeout 42 | #define OSAL_TIMEOUT_NORMAL (10) 43 | // Wait forever 44 | #define OSAL_TIMEOUT_WAIT_FOREVER (UINT32_MAX) 45 | 46 | #define OSAL_TIMEOUT_CONTROL_XFER OSAL_TIMEOUT_WAIT_FOREVER 47 | 48 | typedef void (*osal_task_func_t)( void * ); 49 | 50 | #if CFG_TUSB_OS == OPT_OS_NONE 51 | #include "osal_none.h" 52 | #elif CFG_TUSB_OS == OPT_OS_FREERTOS 53 | #include "osal_freertos.h" 54 | #elif CFG_TUSB_OS == OPT_OS_MYNEWT 55 | #include "osal_mynewt.h" 56 | #elif CFG_TUSB_OS == OPT_OS_PICO 57 | #include "osal_pico.h" 58 | #elif CFG_TUSB_OS == OPT_OS_RTTHREAD 59 | #include "osal_rtthread.h" 60 | #elif CFG_TUSB_OS == OPT_OS_CUSTOM 61 | #include "tusb_os_custom.h" // implemented by application 62 | #else 63 | #error OS is not supported yet 64 | #endif 65 | 66 | //--------------------------------------------------------------------+ 67 | // OSAL Porting API 68 | //--------------------------------------------------------------------+ 69 | 70 | //------------- Semaphore -------------// 71 | static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef); 72 | static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr); 73 | static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec); 74 | 75 | static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed 76 | 77 | //------------- Mutex -------------// 78 | static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef); 79 | static inline bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec); 80 | static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl); 81 | 82 | //------------- Queue -------------// 83 | static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef); 84 | static inline bool osal_queue_receive(osal_queue_t qhdl, void* data); 85 | static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr); 86 | static inline bool osal_queue_empty(osal_queue_t qhdl); 87 | 88 | #if 0 // TODO remove subtask related macros later 89 | // Sub Task 90 | #define OSAL_SUBTASK_BEGIN 91 | #define OSAL_SUBTASK_END return TUSB_ERROR_NONE; 92 | 93 | #define STASK_RETURN(_error) return _error; 94 | #define STASK_INVOKE(_subtask, _status) (_status) = _subtask 95 | #define STASK_ASSERT(_cond) TU_VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED) 96 | #endif 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | /** @} */ 103 | 104 | #endif /* _TUSB_OSAL_H_ */ 105 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/osal/osal_rtthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020 tfx2001 (2479727366@qq.com) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #ifndef _TUSB_OSAL_RTTHREAD_H_ 28 | #define _TUSB_OSAL_RTTHREAD_H_ 29 | 30 | // RT-Thread Headers 31 | #include "rtthread.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | //--------------------------------------------------------------------+ 38 | // TASK API 39 | //--------------------------------------------------------------------+ 40 | static inline void osal_task_delay(uint32_t msec) { 41 | rt_thread_mdelay(msec); 42 | } 43 | 44 | //--------------------------------------------------------------------+ 45 | // Semaphore API 46 | //--------------------------------------------------------------------+ 47 | typedef struct rt_semaphore osal_semaphore_def_t; 48 | typedef rt_sem_t osal_semaphore_t; 49 | 50 | static inline osal_semaphore_t 51 | osal_semaphore_create(osal_semaphore_def_t *semdef) { 52 | rt_sem_init(semdef, "tusb", 0, RT_IPC_FLAG_FIFO); 53 | return semdef; 54 | } 55 | 56 | static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr) { 57 | (void) in_isr; 58 | return rt_sem_release(sem_hdl) == RT_EOK; 59 | } 60 | 61 | static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec) { 62 | return rt_sem_take(sem_hdl, rt_tick_from_millisecond(msec)) == RT_EOK; 63 | } 64 | 65 | static inline void osal_semaphore_reset(osal_semaphore_t const sem_hdl) { 66 | // TODO: implement 67 | } 68 | 69 | //--------------------------------------------------------------------+ 70 | // MUTEX API (priority inheritance) 71 | //--------------------------------------------------------------------+ 72 | typedef struct rt_mutex osal_mutex_def_t; 73 | typedef rt_mutex_t osal_mutex_t; 74 | 75 | static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t *mdef) { 76 | rt_mutex_init(mdef, "tusb", RT_IPC_FLAG_FIFO); 77 | return mdef; 78 | } 79 | 80 | static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec) { 81 | return rt_mutex_take(mutex_hdl, rt_tick_from_millisecond(msec)) == RT_EOK; 82 | } 83 | 84 | static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl) { 85 | return rt_mutex_release(mutex_hdl) == RT_EOK; 86 | } 87 | 88 | //--------------------------------------------------------------------+ 89 | // QUEUE API 90 | //--------------------------------------------------------------------+ 91 | 92 | // role device/host is used by OS NONE for mutex (disable usb isr) only 93 | #define OSAL_QUEUE_DEF(_role, _name, _depth, _type) \ 94 | static _type _name##_##buf[_depth]; \ 95 | osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf }; 96 | 97 | typedef struct { 98 | uint16_t depth; 99 | uint16_t item_sz; 100 | void *buf; 101 | 102 | struct rt_messagequeue sq; 103 | } osal_queue_def_t; 104 | 105 | typedef rt_mq_t osal_queue_t; 106 | 107 | static inline osal_queue_t osal_queue_create(osal_queue_def_t *qdef) { 108 | rt_mq_init(&(qdef->sq), "tusb", qdef->buf, qdef->item_sz, 109 | qdef->item_sz * qdef->depth, RT_IPC_FLAG_FIFO); 110 | return &(qdef->sq); 111 | } 112 | 113 | static inline bool osal_queue_receive(osal_queue_t qhdl, void *data) { 114 | return rt_mq_recv(qhdl, data, qhdl->msg_size, RT_WAITING_FOREVER) == RT_EOK; 115 | } 116 | 117 | static inline bool osal_queue_send(osal_queue_t qhdl, void const *data, bool in_isr) { 118 | (void) in_isr; 119 | return rt_mq_send(qhdl, (void *)data, qhdl->msg_size) == RT_EOK; 120 | } 121 | 122 | static inline bool osal_queue_empty(osal_queue_t qhdl) { 123 | return (qhdl->entry) == 0; 124 | } 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif /* _TUSB_OSAL_RTTHREAD_H_ */ 131 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/src/tusb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | * 24 | * This file is part of the TinyUSB stack. 25 | */ 26 | 27 | #include "tusb_option.h" 28 | 29 | #if TUSB_OPT_HOST_ENABLED || TUSB_OPT_DEVICE_ENABLED 30 | 31 | #include "tusb.h" 32 | 33 | static bool _initialized = false; 34 | 35 | // TODO clean up 36 | #if TUSB_OPT_DEVICE_ENABLED 37 | #include "device/usbd_pvt.h" 38 | #endif 39 | 40 | bool tusb_init(void) 41 | { 42 | // skip if already initialized 43 | if (_initialized) return true; 44 | 45 | #if TUSB_OPT_HOST_ENABLED 46 | TU_ASSERT( tuh_init() ); // init host stack 47 | #endif 48 | 49 | #if TUSB_OPT_DEVICE_ENABLED 50 | TU_ASSERT ( tud_init() ); // init device stack 51 | #endif 52 | 53 | _initialized = true; 54 | 55 | return true; 56 | } 57 | 58 | bool tusb_inited(void) 59 | { 60 | return _initialized; 61 | } 62 | 63 | /*------------------------------------------------------------------*/ 64 | /* Debug 65 | *------------------------------------------------------------------*/ 66 | #if CFG_TUSB_DEBUG 67 | #include 68 | 69 | char const* const tusb_strerr[TUSB_ERROR_COUNT] = { ERROR_TABLE(ERROR_STRING) }; 70 | 71 | static void dump_str_line(uint8_t const* buf, uint16_t count) 72 | { 73 | tu_printf(" |"); 74 | 75 | // each line is 16 bytes 76 | for(uint16_t i=0; i 1: 23 | input_args = list(set(mylist).intersection(sys.argv)) 24 | if len(input_args) > 0: 25 | mylist[:] = input_args 26 | 27 | # If examples are not specified in arguments, build all 28 | all_examples = [] 29 | for entry in os.scandir("examples/device"): 30 | if entry.is_dir(): 31 | all_examples.append("device/" + entry.name) 32 | for entry in os.scandir("examples/host"): 33 | if entry.is_dir(): 34 | all_examples.append("host/" + entry.name) 35 | filter_with_input(all_examples) 36 | all_examples.sort() 37 | 38 | # If boards are not specified in arguments, build all 39 | all_boards = [] 40 | for entry in os.scandir("hw/bsp"): 41 | if entry.is_dir() and os.path.exists(entry.path + "/board.mk"): 42 | all_boards.append(entry.name) 43 | filter_with_input(all_boards) 44 | all_boards.sort() 45 | 46 | def build_board(example, board): 47 | global success_count, fail_count, skip_count, exit_status 48 | start_time = time.monotonic() 49 | flash_size = "-" 50 | sram_size = "-" 51 | 52 | # Check if board is skipped 53 | if skip_example(example, board): 54 | success = SKIPPED 55 | skip_count += 1 56 | print(build_format.format(example, board, success, '-', flash_size, sram_size)) 57 | else: 58 | subprocess.run("make -C examples/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 59 | build_result = subprocess.run("make -j -C examples/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 60 | 61 | if build_result.returncode == 0: 62 | success = SUCCEEDED 63 | success_count += 1 64 | (flash_size, sram_size) = build_size(example, board) 65 | else: 66 | exit_status = build_result.returncode 67 | success = FAILED 68 | fail_count += 1 69 | 70 | build_duration = time.monotonic() - start_time 71 | print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) 72 | 73 | if build_result.returncode != 0: 74 | print(build_result.stdout.decode("utf-8")) 75 | 76 | def build_size(example, board): 77 | #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) 78 | elf_file = 'examples/{}/_build/{}/*.elf'.format(example, board) 79 | size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") 80 | size_list = size_output.split('\n')[1].split('\t') 81 | flash_size = int(size_list[0]) 82 | sram_size = int(size_list[1]) + int(size_list[2]) 83 | return (flash_size, sram_size) 84 | 85 | def skip_example(example, board): 86 | ex_dir = 'examples/' + example 87 | board_mk = 'hw/bsp/{}/board.mk'.format(board) 88 | with open(board_mk) as mk: 89 | mk_contents = mk.read() 90 | 91 | # Skip all OPT_MCU_NONE these are WIP port 92 | if '-DCFG_TUSB_MCU=OPT_MCU_NONE' in mk_contents: 93 | return 1 94 | 95 | # Skip if CFG_TUSB_MCU in board.mk to match skip file 96 | for skip_file in glob.iglob(ex_dir + '/.skip.MCU_*'): 97 | mcu_cflag = '-DCFG_TUSB_MCU=OPT_' + os.path.basename(skip_file).split('.')[2] 98 | if mcu_cflag in mk_contents: 99 | return 1 100 | 101 | # Build only list, if exists only these MCU are built 102 | only_list = list(glob.iglob(ex_dir + '/.only.MCU_*')) 103 | if len(only_list) > 0: 104 | for only_file in only_list: 105 | mcu_cflag = '-DCFG_TUSB_MCU=OPT_' + os.path.basename(only_file).split('.')[2] 106 | if mcu_cflag in mk_contents: 107 | return 0 108 | return 1 109 | 110 | return 0 111 | 112 | print(build_separator) 113 | print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) 114 | 115 | for example in all_examples: 116 | print(build_separator) 117 | for board in all_boards: 118 | build_board(example, board) 119 | 120 | total_time = time.monotonic() - total_time 121 | print(build_separator) 122 | print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time)) 123 | print(build_separator) 124 | 125 | sys.exit(exit_status) 126 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/tools/build_esp32sx.py: -------------------------------------------------------------------------------- 1 | import os 2 | import glob 3 | import sys 4 | import subprocess 5 | import time 6 | 7 | SUCCEEDED = "\033[32msucceeded\033[0m" 8 | FAILED = "\033[31mfailed\033[0m" 9 | SKIPPED = "\033[33mskipped\033[0m" 10 | 11 | success_count = 0 12 | fail_count = 0 13 | skip_count = 0 14 | exit_status = 0 15 | 16 | total_time = time.monotonic() 17 | 18 | build_format = '| {:23} | {:30} | {:18} | {:7} | {:6} | {:6} |' 19 | build_separator = '-' * 100 20 | 21 | def filter_with_input(mylist): 22 | if len(sys.argv) > 1: 23 | input_args = list(set(mylist).intersection(sys.argv)) 24 | if len(input_args) > 0: 25 | mylist[:] = input_args 26 | 27 | # Build all examples if not specified 28 | all_examples = [] 29 | for entry in os.scandir("examples/device"): 30 | # Only includes example with CMakeLists.txt for esp32s, and skip board_test to speed up ci 31 | if entry.is_dir() and os.path.exists(entry.path + "/sdkconfig.defaults") and entry.name != 'board_test': 32 | all_examples.append(entry.name) 33 | filter_with_input(all_examples) 34 | all_examples.sort() 35 | 36 | # Build all boards if not specified 37 | all_boards = [] 38 | for entry in os.scandir("hw/bsp/esp32s2/boards"): 39 | if entry.is_dir(): 40 | all_boards.append(entry.name) 41 | for entry in os.scandir("hw/bsp/esp32s3/boards"): 42 | if entry.is_dir(): 43 | all_boards.append(entry.name) 44 | filter_with_input(all_boards) 45 | all_boards.sort() 46 | 47 | def build_board(example, board): 48 | global success_count, fail_count, skip_count, exit_status 49 | start_time = time.monotonic() 50 | flash_size = "-" 51 | sram_size = "-" 52 | 53 | # Check if board is skipped 54 | if skip_example(example, board): 55 | success = SKIPPED 56 | skip_count += 1 57 | print(build_format.format(example, board, success, '-', flash_size, sram_size)) 58 | else: 59 | subprocess.run("make -C examples/device/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 60 | build_result = subprocess.run("make -j -C examples/device/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 61 | 62 | if build_result.returncode == 0: 63 | success = SUCCEEDED 64 | success_count += 1 65 | (flash_size, sram_size) = build_size(example, board) 66 | else: 67 | exit_status = build_result.returncode 68 | success = FAILED 69 | fail_count += 1 70 | 71 | build_duration = time.monotonic() - start_time 72 | print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) 73 | 74 | if build_result.returncode != 0: 75 | print(build_result.stdout.decode("utf-8")) 76 | 77 | def build_size(example, board): 78 | #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) 79 | elf_file = 'examples/device/{}/_build/{}/*.elf'.format(example, board) 80 | size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") 81 | size_list = size_output.split('\n')[1].split('\t') 82 | flash_size = int(size_list[0]) 83 | sram_size = int(size_list[1]) + int(size_list[2]) 84 | return (flash_size, sram_size) 85 | 86 | def skip_example(example, board): 87 | return 0 88 | 89 | print(build_separator) 90 | print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) 91 | print(build_separator) 92 | 93 | for example in all_examples: 94 | for board in all_boards: 95 | build_board(example, board) 96 | 97 | total_time = time.monotonic() - total_time 98 | print(build_separator) 99 | print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time)) 100 | print(build_separator) 101 | 102 | sys.exit(exit_status) 103 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/tools/build_family.py: -------------------------------------------------------------------------------- 1 | import os 2 | import glob 3 | import sys 4 | import subprocess 5 | import time 6 | 7 | SUCCEEDED = "\033[32msucceeded\033[0m" 8 | FAILED = "\033[31mfailed\033[0m" 9 | SKIPPED = "\033[33mskipped\033[0m" 10 | 11 | success_count = 0 12 | fail_count = 0 13 | skip_count = 0 14 | exit_status = 0 15 | 16 | total_time = time.monotonic() 17 | 18 | build_format = '| {:29} | {:30} | {:18} | {:7} | {:6} | {:6} |' 19 | build_separator = '-' * 106 20 | 21 | def filter_with_input(mylist): 22 | if len(sys.argv) > 1: 23 | input_args = list(set(mylist).intersection(sys.argv)) 24 | if len(input_args) > 0: 25 | mylist[:] = input_args 26 | 27 | # If examples are not specified in arguments, build all 28 | all_examples = [] 29 | for entry in os.scandir("examples/device"): 30 | if entry.is_dir(): 31 | all_examples.append("device/" + entry.name) 32 | for entry in os.scandir("examples/host"): 33 | if entry.is_dir(): 34 | all_examples.append("host/" + entry.name) 35 | filter_with_input(all_examples) 36 | all_examples.sort() 37 | 38 | # If family are not specified in arguments, build all 39 | all_families = [] 40 | for entry in os.scandir("hw/bsp"): 41 | if entry.is_dir() and os.path.isdir(entry.path + "/boards") and entry.name != "esp32s2" and entry.name != "esp32s3": 42 | all_families.append(entry.name) 43 | 44 | filter_with_input(all_families) 45 | all_families.sort() 46 | 47 | def build_family(example, family): 48 | all_boards = [] 49 | for entry in os.scandir("hw/bsp/{}/boards".format(family)): 50 | if entry.is_dir(): 51 | all_boards.append(entry.name) 52 | filter_with_input(all_boards) 53 | all_boards.sort() 54 | 55 | for board in all_boards: 56 | build_board(example, board) 57 | 58 | def build_board(example, board): 59 | global success_count, fail_count, skip_count, exit_status 60 | start_time = time.monotonic() 61 | flash_size = "-" 62 | sram_size = "-" 63 | 64 | # Check if board is skipped 65 | if skip_example(example, board): 66 | success = SKIPPED 67 | skip_count += 1 68 | print(build_format.format(example, board, success, '-', flash_size, sram_size)) 69 | else: 70 | #subprocess.run("make -C examples/{} BOARD={} clean".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 71 | build_result = subprocess.run("make -j -C examples/{} BOARD={} all".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 72 | 73 | if build_result.returncode == 0: 74 | success = SUCCEEDED 75 | success_count += 1 76 | (flash_size, sram_size) = build_size(example, board) 77 | subprocess.run("make -j -C examples/{} BOARD={} copy-artifact".format(example, board), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 78 | else: 79 | exit_status = build_result.returncode 80 | success = FAILED 81 | fail_count += 1 82 | 83 | build_duration = time.monotonic() - start_time 84 | print(build_format.format(example, board, success, "{:.2f}s".format(build_duration), flash_size, sram_size)) 85 | 86 | if build_result.returncode != 0: 87 | print(build_result.stdout.decode("utf-8")) 88 | 89 | def build_size(example, board): 90 | #elf_file = 'examples/device/{}/_build/{}/{}-firmware.elf'.format(example, board, board) 91 | elf_file = 'examples/{}/_build/{}/*.elf'.format(example, board) 92 | size_output = subprocess.run('size {}'.format(elf_file), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") 93 | size_list = size_output.split('\n')[1].split('\t') 94 | flash_size = int(size_list[0]) 95 | sram_size = int(size_list[1]) + int(size_list[2]) 96 | return (flash_size, sram_size) 97 | 98 | def skip_example(example, board): 99 | ex_dir = 'examples/' + example 100 | 101 | # family CMake 102 | board_mk = 'hw/bsp/{}/family.cmake'.format(family) 103 | 104 | # family.mk 105 | if not os.path.exists(board_mk): 106 | board_mk = 'hw/bsp/{}/family.mk'.format(family) 107 | 108 | with open(board_mk) as mk: 109 | mk_contents = mk.read() 110 | 111 | # Skip all OPT_MCU_NONE these are WIP port 112 | if 'CFG_TUSB_MCU=OPT_MCU_NONE' in mk_contents: 113 | return 1 114 | 115 | # Skip if CFG_TUSB_MCU in board.mk to match skip file 116 | for skip_file in glob.iglob(ex_dir + '/.skip.MCU_*'): 117 | mcu_cflag = 'CFG_TUSB_MCU=OPT_' + os.path.basename(skip_file).split('.')[2] 118 | if mcu_cflag in mk_contents: 119 | return 1 120 | 121 | # Build only list, if exists only these MCU are built 122 | only_list = list(glob.iglob(ex_dir + '/.only.MCU_*')) 123 | if len(only_list) > 0: 124 | for only_file in only_list: 125 | mcu_cflag = 'CFG_TUSB_MCU=OPT_' + os.path.basename(only_file).split('.')[2] 126 | if mcu_cflag in mk_contents: 127 | return 0 128 | return 1 129 | return 0 130 | 131 | print(build_separator) 132 | print(build_format.format('Example', 'Board', '\033[39mResult\033[0m', 'Time', 'Flash', 'SRAM')) 133 | 134 | for example in all_examples: 135 | print(build_separator) 136 | for family in all_families: 137 | build_family(example, family) 138 | 139 | total_time = time.monotonic() - total_time 140 | print(build_separator) 141 | print("Build Summary: {} {}, {} {}, {} {} and took {:.2f}s".format(success_count, SUCCEEDED, fail_count, FAILED, skip_count, SKIPPED, total_time)) 142 | print(build_separator) 143 | 144 | sys.exit(exit_status) 145 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/tools/top.mk: -------------------------------------------------------------------------------- 1 | ifneq ($(lastword a b),b) 2 | $(error This Makefile require make 3.81 or newer) 3 | endif 4 | 5 | # Detect whether shell style is windows or not 6 | # https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069 7 | ifeq '$(findstring ;,$(PATH))' ';' 8 | CMDEXE := 1 9 | endif 10 | 11 | # Set TOP to be the path to get from the current directory (where make was 12 | # invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns 13 | # the name of this makefile relative to where make was invoked. 14 | 15 | THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) 16 | TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE)) 17 | 18 | ifeq ($(CMDEXE),1) 19 | TOP := $(subst \,/,$(shell for %%i in ( $(TOP) ) do echo %%~fi)) 20 | else 21 | TOP := $(shell realpath $(TOP)) 22 | endif 23 | #$(info Top directory is $(TOP)) 24 | 25 | ifeq ($(CMDEXE),1) 26 | CURRENT_PATH := $(subst $(TOP)/,,$(subst \,/,$(shell echo %CD%))) 27 | else 28 | CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`) 29 | endif 30 | #$(info Path from top is $(CURRENT_PATH)) 31 | -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/tools/usb_drivers/tinyusb_win_usbser.inf: -------------------------------------------------------------------------------- 1 | ;************************************************************ 2 | ; Windows USB CDC ACM Setup File 3 | ; Copyright (c) 2000 Microsoft Corporation 4 | 5 | 6 | [Version] 7 | Signature="$Windows NT$" 8 | Class=Ports 9 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 10 | Provider=%MFGNAME% 11 | LayoutFile=layout.inf 12 | CatalogFile=%MFGFILENAME%.cat 13 | DriverVer=11/15/2007,5.1.2600.0 14 | DriverPackageDisplayName=%DESCRIPTION% 15 | 16 | [Manufacturer] 17 | %MFGNAME%=DeviceList, NTamd64 18 | 19 | [DestinationDirs] 20 | DefaultDestDir=12 21 | 22 | 23 | ;------------------------------------------------------------------------------ 24 | ; Windows 2000/XP/Vista-32bit Sections 25 | ;------------------------------------------------------------------------------ 26 | 27 | [DriverInstall.nt] 28 | include=mdmcpq.inf 29 | CopyFiles=DriverCopyFiles.nt 30 | AddReg=DriverInstall.nt.AddReg 31 | 32 | [DriverCopyFiles.nt] 33 | usbser.sys,,,0x20 34 | 35 | [DriverInstall.nt.AddReg] 36 | HKR,,DevLoader,,*ntkern 37 | HKR,,NTMPDriver,,%DRIVERFILENAME%.sys 38 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 39 | 40 | [DriverInstall.nt.Services] 41 | AddService=usbser, 0x00000002, DriverService.nt 42 | 43 | [DriverService.nt] 44 | DisplayName=%SERVICE% 45 | ServiceType=1 46 | StartType=3 47 | ErrorControl=1 48 | ServiceBinary=%12%\%DRIVERFILENAME%.sys 49 | 50 | ;------------------------------------------------------------------------------ 51 | ; Vista-64bit Sections 52 | ;------------------------------------------------------------------------------ 53 | 54 | [DriverInstall.NTamd64] 55 | include=mdmcpq.inf 56 | CopyFiles=DriverCopyFiles.NTamd64 57 | AddReg=DriverInstall.NTamd64.AddReg 58 | 59 | [DriverCopyFiles.NTamd64] 60 | %DRIVERFILENAME%.sys,,,0x20 61 | 62 | [DriverInstall.NTamd64.AddReg] 63 | HKR,,DevLoader,,*ntkern 64 | HKR,,NTMPDriver,,%DRIVERFILENAME%.sys 65 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 66 | 67 | [DriverInstall.NTamd64.Services] 68 | AddService=usbser, 0x00000002, DriverService.NTamd64 69 | 70 | [DriverService.NTamd64] 71 | DisplayName=%SERVICE% 72 | ServiceType=1 73 | StartType=3 74 | ErrorControl=1 75 | ServiceBinary=%12%\%DRIVERFILENAME%.sys 76 | 77 | 78 | ;------------------------------------------------------------------------------ 79 | ; Vendor and Product ID Definitions 80 | ;------------------------------------------------------------------------------ 81 | ; When developing your USB device, the VID and PID used in the PC side 82 | ; application program and the firmware on the microcontroller must match. 83 | ; Modify the below line to use your VID and PID. Use the format as shown below. 84 | ; Note: One INF file can be used for multiple devices with different VID and PIDs. 85 | ; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. 86 | ;------------------------------------------------------------------------------ 87 | [SourceDisksFiles] 88 | [SourceDisksNames] 89 | [DeviceList] 90 | 91 | %DESCRIPTION%=DriverInstall, USB\VID_CAFE&PID_4001&MI_00, USB\VID_CAFE&PID_4003&MI_00, USB\VID_CAFE&PID_4005&MI_00, USB\VID_CAFE&PID_4007&MI_00, USB\VID_CAFE&PID_4009&MI_00, USB\VID_CAFE&PID_400b&MI_00, USB\VID_CAFE&PID_400d&MI_00, USB\VID_CAFE&PID_400f&MI_00, USB\VID_CAFE&PID_4011&MI_00, USB\VID_CAFE&PID_4013&MI_00, USB\VID_CAFE&PID_4015&MI_00, USB\VID_CAFE&PID_4017&MI_00, USB\VID_CAFE&PID_4019&MI_00, USB\VID_CAFE&PID_401b&MI_00, USB\VID_CAFE&PID_401d&MI_00, USB\VID_CAFE&PID_401f&MI_00, USB\VID_CAFE&PID_4021&MI_00, USB\VID_CAFE&PID_4023&MI_00, USB\VID_CAFE&PID_4025&MI_00, USB\VID_CAFE&PID_4027&MI_00, USB\VID_CAFE&PID_4029&MI_00, USB\VID_CAFE&PID_402b&MI_00, USB\VID_CAFE&PID_402d&MI_00, USB\VID_CAFE&PID_402f&MI_00, USB\VID_CAFE&PID_4031&MI_00, USB\VID_CAFE&PID_4033&MI_00, USB\VID_CAFE&PID_4035&MI_00, USB\VID_CAFE&PID_4037&MI_00, USB\VID_CAFE&PID_4039&MI_00, USB\VID_CAFE&PID_403b&MI_00, USB\VID_CAFE&PID_403d&MI_00, USB\VID_CAFE&PID_403f&MI_00 92 | 93 | 94 | [DeviceList.NTamd64] 95 | %DESCRIPTION%=DriverInstall, USB\VID_CAFE&PID_4001&MI_00, USB\VID_CAFE&PID_4003&MI_00, USB\VID_CAFE&PID_4005&MI_00, USB\VID_CAFE&PID_4007&MI_00, USB\VID_CAFE&PID_4009&MI_00, USB\VID_CAFE&PID_400b&MI_00, USB\VID_CAFE&PID_400d&MI_00, USB\VID_CAFE&PID_400f&MI_00, USB\VID_CAFE&PID_4011&MI_00, USB\VID_CAFE&PID_4013&MI_00, USB\VID_CAFE&PID_4015&MI_00, USB\VID_CAFE&PID_4017&MI_00, USB\VID_CAFE&PID_4019&MI_00, USB\VID_CAFE&PID_401b&MI_00, USB\VID_CAFE&PID_401d&MI_00, USB\VID_CAFE&PID_401f&MI_00, USB\VID_CAFE&PID_4021&MI_00, USB\VID_CAFE&PID_4023&MI_00, USB\VID_CAFE&PID_4025&MI_00, USB\VID_CAFE&PID_4027&MI_00, USB\VID_CAFE&PID_4029&MI_00, USB\VID_CAFE&PID_402b&MI_00, USB\VID_CAFE&PID_402d&MI_00, USB\VID_CAFE&PID_402f&MI_00, USB\VID_CAFE&PID_4031&MI_00, USB\VID_CAFE&PID_4033&MI_00, USB\VID_CAFE&PID_4035&MI_00, USB\VID_CAFE&PID_4037&MI_00, USB\VID_CAFE&PID_4039&MI_00, USB\VID_CAFE&PID_403b&MI_00, USB\VID_CAFE&PID_403d&MI_00, USB\VID_CAFE&PID_403f&MI_00 96 | 97 | ;------------------------------------------------------------------------------ 98 | ; String Definitions 99 | ;------------------------------------------------------------------------------ 100 | ;Modify these strings to customize your device 101 | ;------------------------------------------------------------------------------ 102 | [Strings] 103 | MFGFILENAME="tinyusb_usbser" 104 | DRIVERFILENAME ="usbser" 105 | MFGNAME="tinyusb.org" 106 | INSTDISK="tinyusb CDC Driver" 107 | DESCRIPTION="tinyusb Serial" 108 | SERVICE="USB RS-232 Emulation Driver" -------------------------------------------------------------------------------- /components/tinyusb/tinyusb/version.yml: -------------------------------------------------------------------------------- 1 | # Newt uses this file to determine the version of a checked out repo. 2 | # This should always be 0.0.0 in the master branch. 3 | repo.version: 0.0.0 4 | -------------------------------------------------------------------------------- /main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(srcs) 2 | set(includes) 3 | 4 | 5 | list(APPEND srcs "main.c" ) 6 | 7 | idf_component_register( SRCS ${srcs} 8 | INCLUDE_DIRS ${includes} 9 | PRIV_REQUIRES "freertos" "tinyusb" "driver" ) 10 | 11 | -------------------------------------------------------------------------------- /testapp/Makefile: -------------------------------------------------------------------------------- 1 | all : dmx512testapp 2 | 3 | UNAME := $(shell uname) 4 | 5 | ifeq ($(UNAME), Linux) 6 | CFLAGS:=-g -O0 7 | LDFLAGS:=-ludev 8 | else 9 | CFLAGS:=-g -O0 10 | LDFLAGS:=C:/windows/system32/setupapi.dll 11 | endif 12 | 13 | dmx512testapp : dmx512testapp.c 14 | gcc $(CFLAGS) -o $@ $^ $(LDFLAGS) 15 | 16 | clean : 17 | rm -rf *.o *~ dmx512testapp 18 | 19 | -------------------------------------------------------------------------------- /testapp/dmx512testapp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "hidapi.h" 7 | #include "hidapi.c" 8 | 9 | #define VID 0x303a 10 | #define PID 0x4004 11 | 12 | hid_device * hd; 13 | 14 | int tries = 0; 15 | int alignlen = 4; 16 | 17 | int req_sandbox = 1024; 18 | 19 | 20 | uint32_t EHSVtoHEX( uint8_t hue, uint8_t sat, uint8_t val ); 21 | 22 | int main( int argc, char ** argv ) 23 | { 24 | int r; 25 | hid_init(); 26 | hd = hid_open( VID, PID, L"cndmx512v001"); 27 | if( !hd ) { fprintf( stderr, "Could not open USB\n" ); return -94; } 28 | // Disable mode. 29 | uint8_t colodata[800] = { 0 }; 30 | int channels = 512; 31 | int frame = 0; 32 | do 33 | { 34 | frame++; 35 | int i; 36 | int idlight = frame%(512/3); 37 | for( i = 0; i < 512/3+1; i++ ) 38 | { 39 | /* 40 | int color = EHSVtoHEX( i*10 + frame, 0xff, 0xff ); 41 | colodata[i*3+0] = color & 0xff; 42 | colodata[i*3+1] = (color>>8) & 0xff; 43 | colodata[i*3+2] = (color>>16) & 0xff; 44 | */ 45 | colodata[i*3+0] = 46 | colodata[i*3+1] = 47 | colodata[i*3+2] = (idlight==i)?200:0; 48 | } 49 | 50 | 51 | int chunk; 52 | int chunks = (channels + 247) / 248; 53 | for( chunk = chunks-1; chunk >= 0; chunk-- ) 54 | { 55 | // Upon sending 0th chunk, it will transmit the acutal signal. 56 | uint8_t rdata[256] = { 0 }; 57 | 58 | int offset = chunk * 248; 59 | int remain = channels - offset; 60 | if( remain > 248 ) remain = 248; 61 | 62 | rdata[0] = 0xad; // Feature Report ID 63 | rdata[1] = 0x73; 64 | rdata[2] = offset/4; 65 | rdata[3] = remain; 66 | memcpy( rdata+4, colodata + chunk * 248, remain ); 67 | //printf( "%d %d rdata[10] = %02x\n", offset, remain, rdata[15] ); 68 | do 69 | { 70 | r = hid_send_feature_report( hd, rdata, 255 ); 71 | if( tries++ > 10 ) { fprintf( stderr, "Error sending feature report on command %d (%d)\n", rdata[1], r ); return -85; } 72 | } while ( r < 6 ); 73 | tries = 0; 74 | } 75 | printf( "." ); fflush( stdout ); 76 | } while( 1 ); 77 | 78 | } 79 | 80 | 81 | 82 | 83 | uint32_t EHSVtoHEX( uint8_t hue, uint8_t sat, uint8_t val ) 84 | { 85 | #define SIXTH1 43 86 | #define SIXTH2 85 87 | #define SIXTH3 128 88 | #define SIXTH4 171 89 | #define SIXTH5 213 90 | 91 | uint16_t or = 0, og = 0, ob = 0; 92 | 93 | hue -= SIXTH1; //Off by 60 degrees. 94 | 95 | //TODO: There are colors that overlap here, consider 96 | //tweaking this to make the best use of the colorspace. 97 | 98 | if( hue < SIXTH1 ) //Ok: Yellow->Red. 99 | { 100 | or = 255; 101 | og = 255 - ((uint16_t)hue * 255) / (SIXTH1); 102 | } 103 | else if( hue < SIXTH2 ) //Ok: Red->Purple 104 | { 105 | or = 255; 106 | ob = (uint16_t)hue*255 / SIXTH1 - 255; 107 | } 108 | else if( hue < SIXTH3 ) //Ok: Purple->Blue 109 | { 110 | ob = 255; 111 | or = ((SIXTH3-hue) * 255) / (SIXTH1); 112 | } 113 | else if( hue < SIXTH4 ) //Ok: Blue->Cyan 114 | { 115 | ob = 255; 116 | og = (hue - SIXTH3)*255 / SIXTH1; 117 | } 118 | else if( hue < SIXTH5 ) //Ok: Cyan->Green. 119 | { 120 | og = 255; 121 | ob = ((SIXTH5-hue)*255) / SIXTH1; 122 | } 123 | else //Green->Yellow 124 | { 125 | og = 255; 126 | or = (hue - SIXTH5) * 255 / SIXTH1; 127 | } 128 | 129 | uint16_t rv = val; 130 | if( rv > 128 ) rv++; 131 | uint16_t rs = sat; 132 | if( rs > 128 ) rs++; 133 | 134 | //or, og, ob range from 0...255 now. 135 | //Need to apply saturation and value. 136 | 137 | or = (or * val)>>8; 138 | og = (og * val)>>8; 139 | ob = (ob * val)>>8; 140 | 141 | //OR..OB == 0..65025 142 | or = or * rs + 255 * (256-rs); 143 | og = og * rs + 255 * (256-rs); 144 | ob = ob * rs + 255 * (256-rs); 145 | //printf( "__%d %d %d =-> %d\n", or, og, ob, rs ); 146 | 147 | or >>= 8; 148 | og >>= 8; 149 | ob >>= 8; 150 | 151 | return or | (og<<8) | ((uint32_t)ob<<16); 152 | } 153 | 154 | --------------------------------------------------------------------------------