summaryrefslogtreecommitdiffstats
path: root/tinyusb/src/class
diff options
context:
space:
mode:
Diffstat (limited to 'tinyusb/src/class')
-rwxr-xr-xtinyusb/src/class/audio/audio.h945
-rwxr-xr-xtinyusb/src/class/audio/audio_device.c2272
-rwxr-xr-xtinyusb/src/class/audio/audio_device.h627
-rwxr-xr-xtinyusb/src/class/bth/bth_device.c254
-rwxr-xr-xtinyusb/src/class/bth/bth_device.h109
-rwxr-xr-xtinyusb/src/class/cdc/cdc.h410
-rwxr-xr-xtinyusb/src/class/cdc/cdc_device.c484
-rwxr-xr-xtinyusb/src/class/cdc/cdc_device.h260
-rwxr-xr-xtinyusb/src/class/cdc/cdc_host.c249
-rwxr-xr-xtinyusb/src/class/cdc/cdc_host.h134
-rwxr-xr-xtinyusb/src/class/cdc/cdc_rndis.h301
-rwxr-xr-xtinyusb/src/class/cdc/cdc_rndis_host.c279
-rwxr-xr-xtinyusb/src/class/cdc/cdc_rndis_host.h63
-rwxr-xr-xtinyusb/src/class/dfu/dfu.h119
-rwxr-xr-xtinyusb/src/class/dfu/dfu_device.c458
-rwxr-xr-xtinyusb/src/class/dfu/dfu_device.h98
-rwxr-xr-xtinyusb/src/class/dfu/dfu_rt_device.c128
-rwxr-xr-xtinyusb/src/class/dfu/dfu_rt_device.h54
-rwxr-xr-xtinyusb/src/class/hid/hid.h1119
-rwxr-xr-xtinyusb/src/class/hid/hid_device.c417
-rwxr-xr-xtinyusb/src/class/hid/hid_device.h393
-rwxr-xr-xtinyusb/src/class/hid/hid_host.c628
-rwxr-xr-xtinyusb/src/class/hid/hid_host.h152
-rwxr-xr-xtinyusb/src/class/midi/midi.h212
-rwxr-xr-xtinyusb/src/class/midi/midi_device.c538
-rwxr-xr-xtinyusb/src/class/midi/midi_device.h173
-rwxr-xr-xtinyusb/src/class/msc/msc.h382
-rwxr-xr-xtinyusb/src/class/msc/msc_device.c705
-rwxr-xr-xtinyusb/src/class/msc/msc_device.h159
-rwxr-xr-xtinyusb/src/class/msc/msc_host.c491
-rwxr-xr-xtinyusb/src/class/msc/msc_host.h119
-rwxr-xr-xtinyusb/src/class/net/net_device.c441
-rwxr-xr-xtinyusb/src/class/net/net_device.h85
-rwxr-xr-xtinyusb/src/class/usbtmc/usbtmc.h316
-rwxr-xr-xtinyusb/src/class/usbtmc/usbtmc_device.c860
-rwxr-xr-xtinyusb/src/class/usbtmc/usbtmc_device.h122
-rwxr-xr-xtinyusb/src/class/vendor/vendor_device.c248
-rwxr-xr-xtinyusb/src/class/vendor/vendor_device.h136
-rwxr-xr-xtinyusb/src/class/vendor/vendor_host.c146
-rwxr-xr-xtinyusb/src/class/vendor/vendor_host.h67
40 files changed, 0 insertions, 15153 deletions
diff --git a/tinyusb/src/class/audio/audio.h b/tinyusb/src/class/audio/audio.h
deleted file mode 100755
index f99061ea..00000000
--- a/tinyusb/src/class/audio/audio.h
+++ /dev/null
@@ -1,945 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- * Copyright (c) 2020 Reinhard Panhuber
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/** \ingroup group_class
- * \defgroup ClassDriver_Audio Audio
- * Currently only MIDI subclass is supported
- * @{ */
-
-#ifndef _TUSB_AUDIO_H__
-#define _TUSB_AUDIO_H__
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/// Audio Device Class Codes
-
-/// A.2 - Audio Function Subclass Codes
-typedef enum
-{
- AUDIO_FUNCTION_SUBCLASS_UNDEFINED = 0x00,
-} audio_function_subclass_type_t;
-
-/// A.3 - Audio Function Protocol Codes
-typedef enum
-{
- AUDIO_FUNC_PROTOCOL_CODE_UNDEF = 0x00,
- AUDIO_FUNC_PROTOCOL_CODE_V2 = 0x20, ///< Version 2.0
-} audio_function_protocol_code_t;
-
-/// A.5 - Audio Interface Subclass Codes
-typedef enum
-{
- AUDIO_SUBCLASS_UNDEFINED = 0x00,
- AUDIO_SUBCLASS_CONTROL , ///< Audio Control
- AUDIO_SUBCLASS_STREAMING , ///< Audio Streaming
- AUDIO_SUBCLASS_MIDI_STREAMING , ///< MIDI Streaming
-} audio_subclass_type_t;
-
-/// A.6 - Audio Interface Protocol Codes
-typedef enum
-{
- AUDIO_INT_PROTOCOL_CODE_UNDEF = 0x00,
- AUDIO_INT_PROTOCOL_CODE_V2 = 0x20, ///< Version 2.0
-} audio_interface_protocol_code_t;
-
-/// A.7 - Audio Function Category Codes
-typedef enum
-{
- AUDIO_FUNC_UNDEF = 0x00,
- AUDIO_FUNC_DESKTOP_SPEAKER = 0x01,
- AUDIO_FUNC_HOME_THEATER = 0x02,
- AUDIO_FUNC_MICROPHONE = 0x03,
- AUDIO_FUNC_HEADSET = 0x04,
- AUDIO_FUNC_TELEPHONE = 0x05,
- AUDIO_FUNC_CONVERTER = 0x06,
- AUDIO_FUNC_SOUND_RECODER = 0x07,
- AUDIO_FUNC_IO_BOX = 0x08,
- AUDIO_FUNC_MUSICAL_INSTRUMENT = 0x09,
- AUDIO_FUNC_PRO_AUDIO = 0x0A,
- AUDIO_FUNC_AUDIO_VIDEO = 0x0B,
- AUDIO_FUNC_CONTROL_PANEL = 0x0C,
- AUDIO_FUNC_OTHER = 0xFF,
-} audio_function_code_t;
-
-/// A.9 - Audio Class-Specific AC Interface Descriptor Subtypes UAC2
-typedef enum
-{
- AUDIO_CS_AC_INTERFACE_AC_DESCRIPTOR_UNDEF = 0x00,
- AUDIO_CS_AC_INTERFACE_HEADER = 0x01,
- AUDIO_CS_AC_INTERFACE_INPUT_TERMINAL = 0x02,
- AUDIO_CS_AC_INTERFACE_OUTPUT_TERMINAL = 0x03,
- AUDIO_CS_AC_INTERFACE_MIXER_UNIT = 0x04,
- AUDIO_CS_AC_INTERFACE_SELECTOR_UNIT = 0x05,
- AUDIO_CS_AC_INTERFACE_FEATURE_UNIT = 0x06,
- AUDIO_CS_AC_INTERFACE_EFFECT_UNIT = 0x07,
- AUDIO_CS_AC_INTERFACE_PROCESSING_UNIT = 0x08,
- AUDIO_CS_AC_INTERFACE_EXTENSION_UNIT = 0x09,
- AUDIO_CS_AC_INTERFACE_CLOCK_SOURCE = 0x0A,
- AUDIO_CS_AC_INTERFACE_CLOCK_SELECTOR = 0x0B,
- AUDIO_CS_AC_INTERFACE_CLOCK_MULTIPLIER = 0x0C,
- AUDIO_CS_AC_INTERFACE_SAMPLE_RATE_CONVERTER = 0x0D,
-} audio_cs_ac_interface_subtype_t;
-
-/// A.10 - Audio Class-Specific AS Interface Descriptor Subtypes UAC2
-typedef enum
-{
- AUDIO_CS_AS_INTERFACE_AS_DESCRIPTOR_UNDEF = 0x00,
- AUDIO_CS_AS_INTERFACE_AS_GENERAL = 0x01,
- AUDIO_CS_AS_INTERFACE_FORMAT_TYPE = 0x02,
- AUDIO_CS_AS_INTERFACE_ENCODER = 0x03,
- AUDIO_CS_AS_INTERFACE_DECODER = 0x04,
-} audio_cs_as_interface_subtype_t;
-
-/// A.11 - Effect Unit Effect Types
-typedef enum
-{
- AUDIO_EFFECT_TYPE_UNDEF = 0x00,
- AUDIO_EFFECT_TYPE_PARAM_EQ_SECTION = 0x01,
- AUDIO_EFFECT_TYPE_REVERBERATION = 0x02,
- AUDIO_EFFECT_TYPE_MOD_DELAY = 0x03,
- AUDIO_EFFECT_TYPE_DYN_RANGE_COMP = 0x04,
-} audio_effect_unit_effect_type_t;
-
-/// A.12 - Processing Unit Process Types
-typedef enum
-{
- AUDIO_PROCESS_TYPE_UNDEF = 0x00,
- AUDIO_PROCESS_TYPE_UP_DOWN_MIX = 0x01,
- AUDIO_PROCESS_TYPE_DOLBY_PROLOGIC = 0x02,
- AUDIO_PROCESS_TYPE_STEREO_EXTENDER = 0x03,
-} audio_processing_unit_process_type_t;
-
-/// A.13 - Audio Class-Specific EP Descriptor Subtypes UAC2
-typedef enum
-{
- AUDIO_CS_EP_SUBTYPE_UNDEF = 0x00,
- AUDIO_CS_EP_SUBTYPE_GENERAL = 0x01,
-} audio_cs_ep_subtype_t;
-
-/// A.14 - Audio Class-Specific Request Codes
-typedef enum
-{
- AUDIO_CS_REQ_UNDEF = 0x00,
- AUDIO_CS_REQ_CUR = 0x01,
- AUDIO_CS_REQ_RANGE = 0x02,
- AUDIO_CS_REQ_MEM = 0x03,
-} audio_cs_req_t;
-
-/// A.17 - Control Selector Codes
-
-/// A.17.1 - Clock Source Control Selectors
-typedef enum
-{
- AUDIO_CS_CTRL_UNDEF = 0x00,
- AUDIO_CS_CTRL_SAM_FREQ = 0x01,
- AUDIO_CS_CTRL_CLK_VALID = 0x02,
-} audio_clock_src_control_selector_t;
-
-/// A.17.2 - Clock Selector Control Selectors
-typedef enum
-{
- AUDIO_CX_CTRL_UNDEF = 0x00,
- AUDIO_CX_CTRL_CONTROL = 0x01,
-} audio_clock_sel_control_selector_t;
-
-/// A.17.3 - Clock Multiplier Control Selectors
-typedef enum
-{
- AUDIO_CM_CTRL_UNDEF = 0x00,
- AUDIO_CM_CTRL_NUMERATOR_CONTROL = 0x01,
- AUDIO_CM_CTRL_DENOMINATOR_CONTROL = 0x02,
-} audio_clock_mul_control_selector_t;
-
-/// A.17.4 - Terminal Control Selectors
-typedef enum
-{
- AUDIO_TE_CTRL_UNDEF = 0x00,
- AUDIO_TE_CTRL_COPY_PROTECT = 0x01,
- AUDIO_TE_CTRL_CONNECTOR = 0x02,
- AUDIO_TE_CTRL_OVERLOAD = 0x03,
- AUDIO_TE_CTRL_CLUSTER = 0x04,
- AUDIO_TE_CTRL_UNDERFLOW = 0x05,
- AUDIO_TE_CTRL_OVERFLOW = 0x06,
- AUDIO_TE_CTRL_LATENCY = 0x07,
-} audio_terminal_control_selector_t;
-
-/// A.17.5 - Mixer Control Selectors
-typedef enum
-{
- AUDIO_MU_CTRL_UNDEF = 0x00,
- AUDIO_MU_CTRL_MIXER = 0x01,
- AUDIO_MU_CTRL_CLUSTER = 0x02,
- AUDIO_MU_CTRL_UNDERFLOW = 0x03,
- AUDIO_MU_CTRL_OVERFLOW = 0x04,
- AUDIO_MU_CTRL_LATENCY = 0x05,
-} audio_mixer_control_selector_t;
-
-/// A.17.6 - Selector Control Selectors
-typedef enum
-{
- AUDIO_SU_CTRL_UNDEF = 0x00,
- AUDIO_SU_CTRL_SELECTOR = 0x01,
- AUDIO_SU_CTRL_LATENCY = 0x02,
-} audio_sel_control_selector_t;
-
-/// A.17.7 - Feature Unit Control Selectors
-typedef enum
-{
- AUDIO_FU_CTRL_UNDEF = 0x00,
- AUDIO_FU_CTRL_MUTE = 0x01,
- AUDIO_FU_CTRL_VOLUME = 0x02,
- AUDIO_FU_CTRL_BASS = 0x03,
- AUDIO_FU_CTRL_MID = 0x04,
- AUDIO_FU_CTRL_TREBLE = 0x05,
- AUDIO_FU_CTRL_GRAPHIC_EQUALIZER = 0x06,
- AUDIO_FU_CTRL_AGC = 0x07,
- AUDIO_FU_CTRL_DELAY = 0x08,
- AUDIO_FU_CTRL_BASS_BOOST = 0x09,
- AUDIO_FU_CTRL_LOUDNESS = 0x0A,
- AUDIO_FU_CTRL_INPUT_GAIN = 0x0B,
- AUDIO_FU_CTRL_GAIN_PAD = 0x0C,
- AUDIO_FU_CTRL_INVERTER = 0x0D,
- AUDIO_FU_CTRL_UNDERFLOW = 0x0E,
- AUDIO_FU_CTRL_OVERVLOW = 0x0F,
- AUDIO_FU_CTRL_LATENCY = 0x10,
-} audio_feature_unit_control_selector_t;
-
-/// A.17.8 Effect Unit Control Selectors
-
-/// A.17.8.1 Parametric Equalizer Section Effect Unit Control Selectors
-typedef enum
-{
- AUDIO_PE_CTRL_UNDEF = 0x00,
- AUDIO_PE_CTRL_ENABLE = 0x01,
- AUDIO_PE_CTRL_CENTERFREQ = 0x02,
- AUDIO_PE_CTRL_QFACTOR = 0x03,
- AUDIO_PE_CTRL_GAIN = 0x04,
- AUDIO_PE_CTRL_UNDERFLOW = 0x05,
- AUDIO_PE_CTRL_OVERFLOW = 0x06,
- AUDIO_PE_CTRL_LATENCY = 0x07,
-} audio_parametric_equalizer_control_selector_t;
-
-/// A.17.8.2 Reverberation Effect Unit Control Selectors
-typedef enum
-{
- AUDIO_RV_CTRL_UNDEF = 0x00,
- AUDIO_RV_CTRL_ENABLE = 0x01,
- AUDIO_RV_CTRL_TYPE = 0x02,
- AUDIO_RV_CTRL_LEVEL = 0x03,
- AUDIO_RV_CTRL_TIME = 0x04,
- AUDIO_RV_CTRL_FEEDBACK = 0x05,
- AUDIO_RV_CTRL_PREDELAY = 0x06,
- AUDIO_RV_CTRL_DENSITY = 0x07,
- AUDIO_RV_CTRL_HIFREQ_ROLLOFF = 0x08,
- AUDIO_RV_CTRL_UNDERFLOW = 0x09,
- AUDIO_RV_CTRL_OVERFLOW = 0x0A,
- AUDIO_RV_CTRL_LATENCY = 0x0B,
-} audio_reverberation_effect_control_selector_t;
-
-/// A.17.8.3 Modulation Delay Effect Unit Control Selectors
-typedef enum
-{
- AUDIO_MD_CTRL_UNDEF = 0x00,
- AUDIO_MD_CTRL_ENABLE = 0x01,
- AUDIO_MD_CTRL_BALANCE = 0x02,
- AUDIO_MD_CTRL_RATE = 0x03,
- AUDIO_MD_CTRL_DEPTH = 0x04,
- AUDIO_MD_CTRL_TIME = 0x05,
- AUDIO_MD_CTRL_FEEDBACK = 0x06,
- AUDIO_MD_CTRL_UNDERFLOW = 0x07,
- AUDIO_MD_CTRL_OVERFLOW = 0x08,
- AUDIO_MD_CTRL_LATENCY = 0x09,
-} audio_modulation_delay_control_selector_t;
-
-/// A.17.8.4 Dynamic Range Compressor Effect Unit Control Selectors
-typedef enum
-{
- AUDIO_DR_CTRL_UNDEF = 0x00,
- AUDIO_DR_CTRL_ENABLE = 0x01,
- AUDIO_DR_CTRL_COMPRESSION_RATE = 0x02,
- AUDIO_DR_CTRL_MAXAMPL = 0x03,
- AUDIO_DR_CTRL_THRESHOLD = 0x04,
- AUDIO_DR_CTRL_ATTACK_TIME = 0x05,
- AUDIO_DR_CTRL_RELEASE_TIME = 0x06,
- AUDIO_DR_CTRL_UNDERFLOW = 0x07,
- AUDIO_DR_CTRL_OVERFLOW = 0x08,
- AUDIO_DR_CTRL_LATENCY = 0x09,
-} audio_dynamic_range_compression_control_selector_t;
-
-/// A.17.9 Processing Unit Control Selectors
-
-/// A.17.9.1 Up/Down-mix Processing Unit Control Selectors
-typedef enum
-{
- AUDIO_UD_CTRL_UNDEF = 0x00,
- AUDIO_UD_CTRL_ENABLE = 0x01,
- AUDIO_UD_CTRL_MODE_SELECT = 0x02,
- AUDIO_UD_CTRL_CLUSTER = 0x03,
- AUDIO_UD_CTRL_UNDERFLOW = 0x04,
- AUDIO_UD_CTRL_OVERFLOW = 0x05,
- AUDIO_UD_CTRL_LATENCY = 0x06,
-} audio_up_down_mix_control_selector_t;
-
-/// A.17.9.2 Dolby Prologic ™ Processing Unit Control Selectors
-typedef enum
-{
- AUDIO_DP_CTRL_UNDEF = 0x00,
- AUDIO_DP_CTRL_ENABLE = 0x01,
- AUDIO_DP_CTRL_MODE_SELECT = 0x02,
- AUDIO_DP_CTRL_CLUSTER = 0x03,
- AUDIO_DP_CTRL_UNDERFLOW = 0x04,
- AUDIO_DP_CTRL_OVERFLOW = 0x05,
- AUDIO_DP_CTRL_LATENCY = 0x06,
-} audio_dolby_prologic_control_selector_t;
-
-/// A.17.9.3 Stereo Extender Processing Unit Control Selectors
-typedef enum
-{
- AUDIO_ST_EXT_CTRL_UNDEF = 0x00,
- AUDIO_ST_EXT_CTRL_ENABLE = 0x01,
- AUDIO_ST_EXT_CTRL_WIDTH = 0x02,
- AUDIO_ST_EXT_CTRL_UNDERFLOW = 0x03,
- AUDIO_ST_EXT_CTRL_OVERFLOW = 0x04,
- AUDIO_ST_EXT_CTRL_LATENCY = 0x05,
-} audio_stereo_extender_control_selector_t;
-
-/// A.17.10 Extension Unit Control Selectors
-typedef enum
-{
- AUDIO_XU_CTRL_UNDEF = 0x00,
- AUDIO_XU_CTRL_ENABLE = 0x01,
- AUDIO_XU_CTRL_CLUSTER = 0x02,
- AUDIO_XU_CTRL_UNDERFLOW = 0x03,
- AUDIO_XU_CTRL_OVERFLOW = 0x04,
- AUDIO_XU_CTRL_LATENCY = 0x05,
-} audio_extension_unit_control_selector_t;
-
-/// A.17.11 AudioStreaming Interface Control Selectors
-typedef enum
-{
- AUDIO_AS_CTRL_UNDEF = 0x00,
- AUDIO_AS_CTRL_ACT_ALT_SETTING = 0x01,
- AUDIO_AS_CTRL_VAL_ALT_SETTINGS = 0x02,
- AUDIO_AS_CTRL_AUDIO_DATA_FORMAT = 0x03,
-} audio_audiostreaming_interface_control_selector_t;
-
-/// A.17.12 Encoder Control Selectors
-typedef enum
-{
- AUDIO_EN_CTRL_UNDEF = 0x00,
- AUDIO_EN_CTRL_BIT_RATE = 0x01,
- AUDIO_EN_CTRL_QUALITY = 0x02,
- AUDIO_EN_CTRL_VBR = 0x03,
- AUDIO_EN_CTRL_TYPE = 0x04,
- AUDIO_EN_CTRL_UNDERFLOW = 0x05,
- AUDIO_EN_CTRL_OVERFLOW = 0x06,
- AUDIO_EN_CTRL_ENCODER_ERROR = 0x07,
- AUDIO_EN_CTRL_PARAM1 = 0x08,
- AUDIO_EN_CTRL_PARAM2 = 0x09,
- AUDIO_EN_CTRL_PARAM3 = 0x0A,
- AUDIO_EN_CTRL_PARAM4 = 0x0B,
- AUDIO_EN_CTRL_PARAM5 = 0x0C,
- AUDIO_EN_CTRL_PARAM6 = 0x0D,
- AUDIO_EN_CTRL_PARAM7 = 0x0E,
- AUDIO_EN_CTRL_PARAM8 = 0x0F,
-} audio_encoder_control_selector_t;
-
-/// A.17.13 Decoder Control Selectors
-
-/// A.17.13.1 MPEG Decoder Control Selectors
-typedef enum
-{
- AUDIO_MPD_CTRL_UNDEF = 0x00,
- AUDIO_MPD_CTRL_DUAL_CHANNEL = 0x01,
- AUDIO_MPD_CTRL_SECOND_STEREO = 0x02,
- AUDIO_MPD_CTRL_MULTILINGUAL = 0x03,
- AUDIO_MPD_CTRL_DYN_RANGE = 0x04,
- AUDIO_MPD_CTRL_SCALING = 0x05,
- AUDIO_MPD_CTRL_HILO_SCALING = 0x06,
- AUDIO_MPD_CTRL_UNDERFLOW = 0x07,
- AUDIO_MPD_CTRL_OVERFLOW = 0x08,
- AUDIO_MPD_CTRL_DECODER_ERROR = 0x09,
-} audio_MPEG_decoder_control_selector_t;
-
-/// A.17.13.2 AC-3 Decoder Control Selectors
-typedef enum
-{
- AUDIO_AD_CTRL_UNDEF = 0x00,
- AUDIO_AD_CTRL_MODE = 0x01,
- AUDIO_AD_CTRL_DYN_RANGE = 0x02,
- AUDIO_AD_CTRL_SCALING = 0x03,
- AUDIO_AD_CTRL_HILO_SCALING = 0x04,
- AUDIO_AD_CTRL_UNDERFLOW = 0x05,
- AUDIO_AD_CTRL_OVERFLOW = 0x06,
- AUDIO_AD_CTRL_DECODER_ERROR = 0x07,
-} audio_AC3_decoder_control_selector_t;
-
-/// A.17.13.3 WMA Decoder Control Selectors
-typedef enum
-{
- AUDIO_WD_CTRL_UNDEF = 0x00,
- AUDIO_WD_CTRL_UNDERFLOW = 0x01,
- AUDIO_WD_CTRL_OVERFLOW = 0x02,
- AUDIO_WD_CTRL_DECODER_ERROR = 0x03,
-} audio_WMA_decoder_control_selector_t;
-
-/// A.17.13.4 DTS Decoder Control Selectors
-typedef enum
-{
- AUDIO_DD_CTRL_UNDEF = 0x00,
- AUDIO_DD_CTRL_UNDERFLOW = 0x01,
- AUDIO_DD_CTRL_OVERFLOW = 0x02,
- AUDIO_DD_CTRL_DECODER_ERROR = 0x03,
-} audio_DTS_decoder_control_selector_t;
-
-/// A.17.14 Endpoint Control Selectors
-typedef enum
-{
- AUDIO_EP_CTRL_UNDEF = 0x00,
- AUDIO_EP_CTRL_PITCH = 0x01,
- AUDIO_EP_CTRL_DATA_OVERRUN = 0x02,
- AUDIO_EP_CTRL_DATA_UNDERRUN = 0x03,
-} audio_EP_control_selector_t;
-
-/// Terminal Types
-
-/// 2.1 - Audio Class-Terminal Types UAC2
-typedef enum
-{
- AUDIO_TERM_TYPE_USB_UNDEFINED = 0x0100,
- AUDIO_TERM_TYPE_USB_STREAMING = 0x0101,
- AUDIO_TERM_TYPE_USB_VENDOR_SPEC = 0x01FF,
-} audio_terminal_type_t;
-
-/// 2.2 - Audio Class-Input Terminal Types UAC2
-typedef enum
-{
- AUDIO_TERM_TYPE_IN_UNDEFINED = 0x0200,
- AUDIO_TERM_TYPE_IN_GENERIC_MIC = 0x0201,
- AUDIO_TERM_TYPE_IN_DESKTOP_MIC = 0x0202,
- AUDIO_TERM_TYPE_IN_PERSONAL_MIC = 0x0203,
- AUDIO_TERM_TYPE_IN_OMNI_MIC = 0x0204,
- AUDIO_TERM_TYPE_IN_ARRAY_MIC = 0x0205,
- AUDIO_TERM_TYPE_IN_PROC_ARRAY_MIC = 0x0206,
-} audio_terminal_input_type_t;
-
-/// 2.3 - Audio Class-Output Terminal Types UAC2
-typedef enum
-{
- AUDIO_TERM_TYPE_OUT_UNDEFINED = 0x0300,
- AUDIO_TERM_TYPE_OUT_GENERIC_SPEAKER = 0x0301,
- AUDIO_TERM_TYPE_OUT_HEADPHONES = 0x0302,
- AUDIO_TERM_TYPE_OUT_HEAD_MNT_DISP_AUIDO = 0x0303,
- AUDIO_TERM_TYPE_OUT_DESKTOP_SPEAKER = 0x0304,
- AUDIO_TERM_TYPE_OUT_ROOM_SPEAKER = 0x0305,
- AUDIO_TERM_TYPE_OUT_COMMUNICATION_SPEAKER = 0x0306,
- AUDIO_TERM_TYPE_OUT_LOW_FRQ_EFFECTS_SPEAKER = 0x0307,
-} audio_terminal_output_type_t;
-
-/// Rest is yet to be implemented
-
-/// Additional Audio Device Class Codes - Source: Audio Data Formats
-
-/// A.1 - Audio Class-Format Type Codes UAC2
-typedef enum
-{
- AUDIO_FORMAT_TYPE_UNDEFINED = 0x00,
- AUDIO_FORMAT_TYPE_I = 0x01,
- AUDIO_FORMAT_TYPE_II = 0x02,
- AUDIO_FORMAT_TYPE_III = 0x03,
- AUDIO_FORMAT_TYPE_IV = 0x04,
- AUDIO_EXT_FORMAT_TYPE_I = 0x81,
- AUDIO_EXT_FORMAT_TYPE_II = 0x82,
- AUDIO_EXT_FORMAT_TYPE_III = 0x83,
-} audio_format_type_t;
-
-// A.2.1 - Audio Class-Audio Data Format Type I UAC2
-typedef enum
-{
- AUDIO_DATA_FORMAT_TYPE_I_PCM = (uint32_t) (1 << 0),
- AUDIO_DATA_FORMAT_TYPE_I_PCM8 = (uint32_t) (1 << 1),
- AUDIO_DATA_FORMAT_TYPE_I_IEEE_FLOAT = (uint32_t) (1 << 2),
- AUDIO_DATA_FORMAT_TYPE_I_ALAW = (uint32_t) (1 << 3),
- AUDIO_DATA_FORMAT_TYPE_I_MULAW = (uint32_t) (1 << 4),
- AUDIO_DATA_FORMAT_TYPE_I_RAW_DATA = 0x80000000,
-} audio_data_format_type_I_t;
-
-/// All remaining definitions are taken from the descriptor descriptions in the UAC2 main specification
-
-/// Isochronous End Point Attributes
-typedef enum
-{
- TUSB_ISO_EP_ATT_NO_SYNC = 0x00,
- TUSB_ISO_EP_ATT_ASYNCHRONOUS = 0x04,
- TUSB_ISO_EP_ATT_ADAPTIVE = 0x08,
- TUSB_ISO_EP_ATT_SYNCHRONOUS = 0x0C,
- TUSB_ISO_EP_ATT_DATA = 0x00, ///< Data End Point
- TUSB_ISO_EP_ATT_EXPLICIT_FB = 0x10, ///< Feedback End Point
- TUSB_ISO_EP_ATT_IMPLICIT_FB = 0x20, ///< Data endpoint that also serves as an implicit feedback
-} tusb_iso_ep_attribute_t;
-
-/// Audio Class-Control Values UAC2
-typedef enum
-{
- AUDIO_CTRL_NONE = 0x00, ///< No Host access
- AUDIO_CTRL_R = 0x01, ///< Host read access only
- AUDIO_CTRL_RW = 0x03, ///< Host read write access
-} audio_control_t;
-
-/// Audio Class-Specific AC Interface Descriptor Controls UAC2
-typedef enum
-{
- AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS = 0,
-} audio_cs_ac_interface_control_pos_t;
-
-/// Audio Class-Specific AS Interface Descriptor Controls UAC2
-typedef enum
-{
- AUDIO_CS_AS_INTERFACE_CTRL_ACTIVE_ALT_SET_POS = 0,
- AUDIO_CS_AS_INTERFACE_CTRL_VALID_ALT_SET_POS = 2,
-} audio_cs_as_interface_control_pos_t;
-
-/// Audio Class-Specific AS Isochronous Data EP Attributes UAC2
-typedef enum
-{
- AUDIO_CS_AS_ISO_DATA_EP_ATT_MAX_PACKETS_ONLY = 0x80,
- AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK = 0x00,
-} audio_cs_as_iso_data_ep_attribute_t;
-
-/// Audio Class-Specific AS Isochronous Data EP Controls UAC2
-typedef enum
-{
- AUDIO_CS_AS_ISO_DATA_EP_CTRL_PITCH_POS = 0,
- AUDIO_CS_AS_ISO_DATA_EP_CTRL_DATA_OVERRUN_POS = 2,
- AUDIO_CS_AS_ISO_DATA_EP_CTRL_DATA_UNDERRUN_POS = 4,
-} audio_cs_as_iso_data_ep_control_pos_t;
-
-/// Audio Class-Specific AS Isochronous Data EP Lock Delay Units UAC2
-typedef enum
-{
- AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED = 0x00,
- AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC = 0x01,
- AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_PCM_SAMPLES = 0x02,
-} audio_cs_as_iso_data_ep_lock_delay_unit_t;
-
-/// Audio Class-Clock Source Attributes UAC2
-typedef enum
-{
- AUDIO_CLOCK_SOURCE_ATT_EXT_CLK = 0x00,
- AUDIO_CLOCK_SOURCE_ATT_INT_FIX_CLK = 0x01,
- AUDIO_CLOCK_SOURCE_ATT_INT_VAR_CLK = 0x02,
- AUDIO_CLOCK_SOURCE_ATT_INT_PRO_CLK = 0x03,
- AUDIO_CLOCK_SOURCE_ATT_CLK_SYC_SOF = 0x04,
-} audio_clock_source_attribute_t;
-
-/// Audio Class-Clock Source Controls UAC2
-typedef enum
-{
- AUDIO_CLOCK_SOURCE_CTRL_CLK_FRQ_POS = 0,
- AUDIO_CLOCK_SOURCE_CTRL_CLK_VAL_POS = 2,
-} audio_clock_source_control_pos_t;
-
-/// Audio Class-Clock Selector Controls UAC2
-typedef enum
-{
- AUDIO_CLOCK_SELECTOR_CTRL_POS = 0,
-} audio_clock_selector_control_pos_t;
-
-/// Audio Class-Clock Multiplier Controls UAC2
-typedef enum
-{
- AUDIO_CLOCK_MULTIPLIER_CTRL_NUMERATOR_POS = 0,
- AUDIO_CLOCK_MULTIPLIER_CTRL_DENOMINATOR_POS = 2,
-} audio_clock_multiplier_control_pos_t;
-
-/// Audio Class-Input Terminal Controls UAC2
-typedef enum
-{
- AUDIO_IN_TERM_CTRL_CPY_PROT_POS = 0,
- AUDIO_IN_TERM_CTRL_CONNECTOR_POS = 2,
- AUDIO_IN_TERM_CTRL_OVERLOAD_POS = 4,
- AUDIO_IN_TERM_CTRL_CLUSTER_POS = 6,
- AUDIO_IN_TERM_CTRL_UNDERFLOW_POS = 8,
- AUDIO_IN_TERM_CTRL_OVERFLOW_POS = 10,
-} audio_terminal_input_control_pos_t;
-
-/// Audio Class-Output Terminal Controls UAC2
-typedef enum
-{
- AUDIO_OUT_TERM_CTRL_CPY_PROT_POS = 0,
- AUDIO_OUT_TERM_CTRL_CONNECTOR_POS = 2,
- AUDIO_OUT_TERM_CTRL_OVERLOAD_POS = 4,
- AUDIO_OUT_TERM_CTRL_UNDERFLOW_POS = 6,
- AUDIO_OUT_TERM_CTRL_OVERFLOW_POS = 8,
-} audio_terminal_output_control_pos_t;
-
-/// Audio Class-Feature Unit Controls UAC2
-typedef enum
-{
- AUDIO_FEATURE_UNIT_CTRL_MUTE_POS = 0,
- AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS = 2,
- AUDIO_FEATURE_UNIT_CTRL_BASS_POS = 4,
- AUDIO_FEATURE_UNIT_CTRL_MID_POS = 6,
- AUDIO_FEATURE_UNIT_CTRL_TREBLE_POS = 8,
- AUDIO_FEATURE_UNIT_CTRL_GRAPHIC_EQU_POS = 10,
- AUDIO_FEATURE_UNIT_CTRL_AGC_POS = 12,
- AUDIO_FEATURE_UNIT_CTRL_DELAY_POS = 14,
- AUDIO_FEATURE_UNIT_CTRL_BASS_BOOST_POS = 16,
- AUDIO_FEATURE_UNIT_CTRL_LOUDNESS_POS = 18,
- AUDIO_FEATURE_UNIT_CTRL_INPUT_GAIN_POS = 20,
- AUDIO_FEATURE_UNIT_CTRL_INPUT_GAIN_PAD_POS = 22,
- AUDIO_FEATURE_UNIT_CTRL_PHASE_INV_POS = 24,
- AUDIO_FEATURE_UNIT_CTRL_UNDERFLOW_POS = 26,
- AUDIO_FEATURE_UNIT_CTRL_OVERFLOW_POS = 28,
-} audio_feature_unit_control_pos_t;
-
-/// Audio Class-Audio Channel Configuration UAC2
-typedef enum
-{
- AUDIO_CHANNEL_CONFIG_NON_PREDEFINED = 0x00000000,
- AUDIO_CHANNEL_CONFIG_FRONT_LEFT = 0x00000001,
- AUDIO_CHANNEL_CONFIG_FRONT_RIGHT = 0x00000002,
- AUDIO_CHANNEL_CONFIG_FRONT_CENTER = 0x00000004,
- AUDIO_CHANNEL_CONFIG_LOW_FRQ_EFFECTS = 0x00000008,
- AUDIO_CHANNEL_CONFIG_BACK_LEFT = 0x00000010,
- AUDIO_CHANNEL_CONFIG_BACK_RIGHT = 0x00000020,
- AUDIO_CHANNEL_CONFIG_FRONT_LEFT_OF_CENTER = 0x00000040,
- AUDIO_CHANNEL_CONFIG_FRONT_RIGHT_OF_CENTER = 0x00000080,
- AUDIO_CHANNEL_CONFIG_BACK_CENTER = 0x00000100,
- AUDIO_CHANNEL_CONFIG_SIDE_LEFT = 0x00000200,
- AUDIO_CHANNEL_CONFIG_SIDE_RIGHT = 0x00000400,
- AUDIO_CHANNEL_CONFIG_TOP_CENTER = 0x00000800,
- AUDIO_CHANNEL_CONFIG_TOP_FRONT_LEFT = 0x00001000,
- AUDIO_CHANNEL_CONFIG_TOP_FRONT_CENTER = 0x00002000,
- AUDIO_CHANNEL_CONFIG_TOP_FRONT_RIGHT = 0x00004000,
- AUDIO_CHANNEL_CONFIG_TOP_BACK_LEFT = 0x00008000,
- AUDIO_CHANNEL_CONFIG_TOP_BACK_CENTER = 0x00010000,
- AUDIO_CHANNEL_CONFIG_TOP_BACK_RIGHT = 0x00020000,
- AUDIO_CHANNEL_CONFIG_TOP_FRONT_LEFT_OF_CENTER = 0x00040000,
- AUDIO_CHANNEL_CONFIG_TOP_FRONT_RIGHT_OF_CENTER = 0x00080000,
- AUDIO_CHANNEL_CONFIG_LEFT_LOW_FRQ_EFFECTS = 0x00100000,
- AUDIO_CHANNEL_CONFIG_RIGHT_LOW_FRQ_EFFECTS = 0x00200000,
- AUDIO_CHANNEL_CONFIG_TOP_SIDE_LEFT = 0x00400000,
- AUDIO_CHANNEL_CONFIG_TOP_SIDE_RIGHT = 0x00800000,
- AUDIO_CHANNEL_CONFIG_BOTTOM_CENTER = 0x01000000,
- AUDIO_CHANNEL_CONFIG_BACK_LEFT_OF_CENTER = 0x02000000,
- AUDIO_CHANNEL_CONFIG_BACK_RIGHT_OF_CENTER = 0x04000000,
- AUDIO_CHANNEL_CONFIG_RAW_DATA = 0x80000000,
-} audio_channel_config_t;
-
-/// AUDIO Channel Cluster Descriptor (4.1)
-typedef struct TU_ATTR_PACKED {
- uint8_t bNrChannels; ///< Number of channels currently connected.
- audio_channel_config_t bmChannelConfig; ///< Bitmap according to 'audio_channel_config_t' with a 1 set if channel is connected and 0 else. In case channels are non-predefined ignore them here (see UAC2 specification 4.1 Audio Channel Cluster Descriptor.
- uint8_t iChannelNames; ///< Index of a string descriptor, describing the name of the first inserted channel with a non-predefined spatial location.
-} audio_desc_channel_cluster_t;
-
-/// AUDIO Class-Specific AC Interface Header Descriptor (4.7.2)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes: 9.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_HEADER.
- uint16_t bcdADC ; ///< Audio Device Class Specification Release Number in Binary-Coded Decimal. Value: U16_TO_U8S_LE(0x0200).
- uint8_t bCategory ; ///< Constant, indicating the primary use of this audio function, as intended by the manufacturer. See: audio_function_t.
- uint16_t wTotalLength ; ///< Total number of bytes returned for the class-specific AudioControl interface descriptor. Includes the combined length of this descriptor header and all Clock Source, Unit and Terminal descriptors.
- uint8_t bmControls ; ///< See: audio_cs_ac_interface_control_pos_t.
-} audio_desc_cs_ac_interface_t;
-
-/// AUDIO Clock Source Descriptor (4.7.2.1)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes: 8.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_CLOCK_SOURCE.
- uint8_t bClockID ; ///< Constant uniquely identifying the Clock Source Entity within the audio function. This value is used in all requests to address this Entity.
- uint8_t bmAttributes ; ///< See: audio_clock_source_attribute_t.
- uint8_t bmControls ; ///< See: audio_clock_source_control_pos_t.
- uint8_t bAssocTerminal ; ///< Terminal ID of the Terminal that is associated with this Clock Source.
- uint8_t iClockSource ; ///< Index of a string descriptor, describing the Clock Source Entity.
-} audio_desc_clock_source_t;
-
-/// AUDIO Clock Selector Descriptor (4.7.2.2) for ONE pin
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 7+p.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_CLOCK_SELECTOR.
- uint8_t bClockID ; ///< Constant uniquely identifying the Clock Selector Entity within the audio function. This value is used in all requests to address this Entity.
- uint8_t bNrInPins ; ///< Number of Input Pins of this Unit: p = 1 thus bNrInPins = 1.
- uint8_t baCSourceID ; ///< ID of the Clock Entity to which the first Clock Input Pin of this Clock Selector Entity is connected..
- uint8_t bmControls ; ///< See: audio_clock_selector_control_pos_t.
- uint8_t iClockSource ; ///< Index of a string descriptor, describing the Clock Selector Entity.
-} audio_desc_clock_selector_t;
-
-/// AUDIO Clock Selector Descriptor (4.7.2.2) for multiple pins
-#define audio_desc_clock_selector_n_t(source_num) \
- struct TU_ATTR_PACKED { \
- uint8_t bLength ; \
- uint8_t bDescriptorType ; \
- uint8_t bDescriptorSubType ; \
- uint8_t bClockID ; \
- uint8_t bNrInPins ; \
- struct TU_ATTR_PACKED { \
- uint8_t baSourceID ; \
- } sourceID[source_num] ; \
- uint8_t bmControls ; \
- uint8_t iClockSource ; \
-}
-
-/// AUDIO Clock Multiplier Descriptor (4.7.2.3)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 7.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_CLOCK_MULTIPLIER.
- uint8_t bClockID ; ///< Constant uniquely identifying the Clock Multiplier Entity within the audio function. This value is used in all requests to address this Entity.
- uint8_t bCSourceID ; ///< ID of the Clock Entity to which the last Clock Input Pin of this Clock Selector Entity is connected.
- uint8_t bmControls ; ///< See: audio_clock_multiplier_control_pos_t.
- uint8_t iClockSource ; ///< Index of a string descriptor, describing the Clock Multiplier Entity.
-} audio_desc_clock_multiplier_t;
-
-/// AUDIO Input Terminal Descriptor(4.7.2.4)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 17.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_INPUT_TERMINAL.
- uint16_t wTerminalType ; ///< Constant characterizing the type of Terminal. See: audio_terminal_type_t for USB streaming and audio_terminal_input_type_t for other input types.
- uint8_t bAssocTerminal ; ///< ID of the Output Terminal to which this Input Terminal is associated.
- uint8_t bCSourceID ; ///< ID of the Clock Entity to which this Input Terminal is connected.
- uint8_t bNrChannels ; ///< Number of logical output channels in the Terminal’s output audio channel cluster.
- uint32_t bmChannelConfig ; ///< Describes the spatial location of the logical channels. See:audio_channel_config_t.
- uint16_t bmControls ; ///< See: audio_terminal_input_control_pos_t.
- uint8_t iTerminal ; ///< Index of a string descriptor, describing the Input Terminal.
-} audio_desc_input_terminal_t;
-
-/// AUDIO Output Terminal Descriptor(4.7.2.5)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 12.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_OUTPUT_TERMINAL.
- uint8_t bTerminalID ; ///< Constant uniquely identifying the Terminal within the audio function. This value is used in all requests to address this Terminal.
- uint16_t wTerminalType ; ///< Constant characterizing the type of Terminal. See: audio_terminal_type_t for USB streaming and audio_terminal_output_type_t for other output types.
- uint8_t bAssocTerminal ; ///< Constant, identifying the Input Terminal to which this Output Terminal is associated.
- uint8_t bSourceID ; ///< ID of the Unit or Terminal to which this Terminal is connected.
- uint8_t bCSourceID ; ///< ID of the Clock Entity to which this Output Terminal is connected.
- uint16_t bmControls ; ///< See: audio_terminal_output_type_t.
- uint8_t iTerminal ; ///< Index of a string descriptor, describing the Output Terminal.
-} audio_desc_output_terminal_t;
-
-/// AUDIO Feature Unit Descriptor(4.7.2.8) for ONE channel
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 14.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AC_INTERFACE_FEATURE_UNIT.
- uint8_t bUnitID ; ///< Constant uniquely identifying the Unit within the audio function. This value is used in all requests to address this Unit.
- uint8_t bSourceID ; ///< ID of the Unit or Terminal to which this Feature Unit is connected.
- struct TU_ATTR_PACKED {
- uint32_t bmaControls ; ///< See: audio_feature_unit_control_pos_t. Controls0 is master channel 0 (always present) and Controls1 is logical channel 1.
- } controls[2] ;
- uint8_t iTerminal ; ///< Index of a string descriptor, describing this Feature Unit.
-} audio_desc_feature_unit_t;
-
-/// AUDIO Feature Unit Descriptor(4.7.2.8) for multiple channels
-#define audio_desc_feature_unit_n_t(ch_num)\
- struct TU_ATTR_PACKED { \
- uint8_t bLength ; /* 6+(ch_num+1)*4 */\
- uint8_t bDescriptorType ; \
- uint8_t bDescriptorSubType ; \
- uint8_t bUnitID ; \
- uint8_t bSourceID ; \
- struct TU_ATTR_PACKED { \
- uint32_t bmaControls ; \
- } controls[ch_num+1] ; \
- uint8_t iTerminal ; \
-}
-
-/// AUDIO Class-Specific AS Interface Descriptor(4.9.2)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 16.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AS_INTERFACE_AS_GENERAL.
- uint8_t bTerminalLink ; ///< The Terminal ID of the Terminal to which this interface is connected.
- uint8_t bmControls ; ///< See: audio_cs_as_interface_control_pos_t.
- uint8_t bFormatType ; ///< Constant identifying the Format Type the AudioStreaming interface is using. See: audio_format_type_t.
- uint32_t bmFormats ; ///< The Audio Data Format(s) that can be used to communicate with this interface.See: audio_data_format_type_I_t.
- uint8_t bNrChannels ; ///< Number of physical channels in the AS Interface audio channel cluster.
- uint32_t bmChannelConfig ; ///< Describes the spatial location of the physical channels. See: audio_channel_config_t.
- uint8_t iChannelNames ; ///< Index of a string descriptor, describing the name of the first physical channel.
-} audio_desc_cs_as_interface_t;
-
-/// AUDIO Type I Format Type Descriptor(2.3.1.6 - Audio Formats)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 6.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_INTERFACE.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_AS_INTERFACE_FORMAT_TYPE.
- uint8_t bFormatType ; ///< Constant identifying the Format Type the AudioStreaming interface is using. Value: AUDIO_FORMAT_TYPE_I.
- uint8_t bSubslotSize ; ///< The number of bytes occupied by one audio subslot. Can be 1, 2, 3 or 4.
- uint8_t bBitResolution ; ///< The number of effectively used bits from the available bits in an audio subslot.
-} audio_desc_type_I_format_t;
-
-/// AUDIO Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor, in bytes: 8.
- uint8_t bDescriptorType ; ///< Descriptor Type. Value: TUSB_DESC_CS_ENDPOINT.
- uint8_t bDescriptorSubType ; ///< Descriptor SubType. Value: AUDIO_CS_EP_SUBTYPE_GENERAL.
- uint8_t bmAttributes ; ///< See: audio_cs_as_iso_data_ep_attribute_t.
- uint8_t bmControls ; ///< See: audio_cs_as_iso_data_ep_control_pos_t.
- uint8_t bLockDelayUnits ; ///< Indicates the units used for the wLockDelay field. See: audio_cs_as_iso_data_ep_lock_delay_unit_t.
- uint16_t wLockDelay ; ///< Indicates the time it takes this endpoint to reliably lock its internal clock recovery circuitry. Units used depend on the value of the bLockDelayUnits field.
-} audio_desc_cs_as_iso_data_ep_t;
-
-// 5.2.2 Control Request Layout
-typedef struct TU_ATTR_PACKED
-{
- union
- {
- struct TU_ATTR_PACKED
- {
- uint8_t recipient : 5; ///< Recipient type tusb_request_recipient_t.
- uint8_t type : 2; ///< Request type tusb_request_type_t.
- uint8_t direction : 1; ///< Direction type. tusb_dir_t
- } bmRequestType_bit;
-
- uint8_t bmRequestType;
- };
-
- uint8_t bRequest; ///< Request type audio_cs_req_t
- uint8_t bChannelNumber;
- uint8_t bControlSelector;
- union
- {
- uint8_t bInterface;
- uint8_t bEndpoint;
- };
- uint8_t bEntityID;
- uint16_t wLength;
-} audio_control_request_t;
-
-//// 5.2.3 Control Request Parameter Block Layout
-
-// 5.2.3.1 1-byte Control CUR Parameter Block
-typedef struct TU_ATTR_PACKED
-{
- int8_t bCur ; ///< The setting for the CUR attribute of the addressed Control
-} audio_control_cur_1_t;
-
-// 5.2.3.2 2-byte Control CUR Parameter Block
-typedef struct TU_ATTR_PACKED
-{
- int16_t bCur ; ///< The setting for the CUR attribute of the addressed Control
-} audio_control_cur_2_t;
-
-// 5.2.3.3 4-byte Control CUR Parameter Block
-typedef struct TU_ATTR_PACKED
-{
- int32_t bCur ; ///< The setting for the CUR attribute of the addressed Control
-} audio_control_cur_4_t;
-
-// Use the following ONLY for RECEIVED data - compiler does not know how many subranges are defined! Use the one below for predefined lengths - or if you know what you are doing do what you like
-// 5.2.3.1 1-byte Control RANGE Parameter Block
-typedef struct TU_ATTR_PACKED {
- uint16_t wNumSubRanges;
- struct TU_ATTR_PACKED {
- int8_t bMin ; /*The setting for the MIN attribute of the nth subrange of the addressed Control*/
- int8_t bMax ; /*The setting for the MAX attribute of the nth subrange of the addressed Control*/
- uint8_t bRes ; /*The setting for the RES attribute of the nth subrange of the addressed Control*/
- } subrange[] ;
-} audio_control_range_1_t;
-
-// 5.2.3.2 2-byte Control RANGE Parameter Block
-typedef struct TU_ATTR_PACKED {
- uint16_t wNumSubRanges;
- struct TU_ATTR_PACKED {
- int16_t bMin ; /*The setting for the MIN attribute of the nth subrange of the addressed Control*/
- int16_t bMax ; /*The setting for the MAX attribute of the nth subrange of the addressed Control*/
- uint16_t bRes ; /*The setting for the RES attribute of the nth subrange of the addressed Control*/
- } subrange[] ;
-} audio_control_range_2_t;
-
-// 5.2.3.3 4-byte Control RANGE Parameter Block
-typedef struct TU_ATTR_PACKED {
- uint16_t wNumSubRanges;
- struct TU_ATTR_PACKED {
- int32_t bMin ; /*The setting for the MIN attribute of the nth subrange of the addressed Control*/
- int32_t bMax ; /*The setting for the MAX attribute of the nth subrange of the addressed Control*/
- uint32_t bRes ; /*The setting for the RES attribute of the nth subrange of the addressed Control*/
- } subrange[] ;
-} audio_control_range_4_t;
-
-// 5.2.3.1 1-byte Control RANGE Parameter Block
-#define audio_control_range_1_n_t(numSubRanges) \
- struct TU_ATTR_PACKED { \
- uint16_t wNumSubRanges; \
- struct TU_ATTR_PACKED { \
- int8_t bMin ; /*The setting for the MIN attribute of the nth subrange of the addressed Control*/\
- int8_t bMax ; /*The setting for the MAX attribute of the nth subrange of the addressed Control*/\
- uint8_t bRes ; /*The setting for the RES attribute of the nth subrange of the addressed Control*/\
- } subrange[numSubRanges] ; \
-}
-
-/// 5.2.3.2 2-byte Control RANGE Parameter Block
-#define audio_control_range_2_n_t(numSubRanges) \
- struct TU_ATTR_PACKED { \
- uint16_t wNumSubRanges; \
- struct TU_ATTR_PACKED { \
- int16_t bMin ; /*The setting for the MIN attribute of the nth subrange of the addressed Control*/\
- int16_t bMax ; /*The setting for the MAX attribute of the nth subrange of the addressed Control*/\
- uint16_t bRes ; /*The setting for the RES attribute of the nth subrange of the addressed Control*/\
- } subrange[numSubRanges]; \
-}
-
-// 5.2.3.3 4-byte Control RANGE Parameter Block
-#define audio_control_range_4_n_t(numSubRanges) \
- struct TU_ATTR_PACKED { \
- uint16_t wNumSubRanges; \
- struct TU_ATTR_PACKED { \
- int32_t bMin ; /*The setting for the MIN attribute of the nth subrange of the addressed Control*/\
- int32_t bMax ; /*The setting for the MAX attribute of the nth subrange of the addressed Control*/\
- uint32_t bRes ; /*The setting for the RES attribute of the nth subrange of the addressed Control*/\
- } subrange[numSubRanges]; \
-}
-
-/** @} */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-/** @} */
diff --git a/tinyusb/src/class/audio/audio_device.c b/tinyusb/src/class/audio/audio_device.c
deleted file mode 100755
index ff4e312a..00000000
--- a/tinyusb/src/class/audio/audio_device.c
+++ /dev/null
@@ -1,2272 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Reinhard Panhuber, Jerzy Kasenberg
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/*
- * This driver supports at most one out EP, one in EP, one control EP, and one feedback EP and one alternative interface other than zero. Hence, only one input terminal and one output terminal are support, if you need more adjust the driver!
- * It supports multiple TX and RX channels.
- *
- * In case you need more alternate interfaces, you need to define additional defines for this specific alternate interface. Just define them and set them in the set_interface function.
- *
- * There are three data flow structures currently implemented, where at least one SW-FIFO is used to decouple the asynchronous processes MCU vs. host
- *
- * 1. Input data -> SW-FIFO -> MCU USB
- *
- * The most easiest version, available in case the target MCU can handle the software FIFO (SW-FIFO) and if it is implemented in the device driver (if yes then dcd_edpt_xfer_fifo() is available)
- *
- * 2. Input data -> SW-FIFO -> Linear buffer -> MCU USB
- *
- * In case the target MCU can not handle a SW-FIFO, a linear buffer is used. This uses the default function dcd_edpt_xfer(). In this case more memory is required.
- *
- * 3. (Input data 1 | Input data 2 | ... | Input data N) -> (SW-FIFO 1 | SW-FIFO 2 | ... | SW-FIFO N) -> Linear buffer -> MCU USB
- *
- * This case is used if you have more channels which need to be combined into one stream. Every channel has its own SW-FIFO. All data is encoded into an Linear buffer.
- *
- * The same holds in the RX case.
- *
- * */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_AUDIO)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "audio_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-// Linear buffer in case target MCU is not capable of handling a ring buffer FIFO e.g. no hardware buffer
-// is available or driver is would need to be changed dramatically
-
-// Only STM32 synopsys use non-linear buffer for now
-// Synopsys detection copied from dcd_synopsys.c (refactor later on)
-#if defined (STM32F105x8) || defined (STM32F105xB) || defined (STM32F105xC) || \
- defined (STM32F107xB) || defined (STM32F107xC)
-#define STM32F1_SYNOPSYS
-#endif
-
-#if defined (STM32L475xx) || defined (STM32L476xx) || \
- defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || \
- defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || \
- defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
-#define STM32L4_SYNOPSYS
-#endif
-
-#if (CFG_TUSB_MCU == OPT_MCU_STM32F1 && defined(STM32F1_SYNOPSYS)) || \
- CFG_TUSB_MCU == OPT_MCU_STM32F2 || \
- CFG_TUSB_MCU == OPT_MCU_STM32F4 || \
- CFG_TUSB_MCU == OPT_MCU_STM32F7 || \
- CFG_TUSB_MCU == OPT_MCU_STM32H7 || \
- (CFG_TUSB_MCU == OPT_MCU_STM32L4 && defined(STM32L4_SYNOPSYS)) || \
- CFG_TUSB_MCU == OPT_MCU_RX63X || \
- CFG_TUSB_MCU == OPT_MCU_RX65X || \
- CFG_TUSB_MCU == OPT_MCU_RX72N || \
- CFG_TUSB_MCU == OPT_MCU_GD32VF103
-#define USE_LINEAR_BUFFER 0
-#else
-#define USE_LINEAR_BUFFER 1
-#endif
-
-// Declaration of buffers
-
-// Check for maximum supported numbers
-#if CFG_TUD_AUDIO > 3
-#error Maximum number of audio functions restricted to three!
-#endif
-
-// EP IN software buffers and mutexes
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-#if CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t audio_ep_in_sw_buf_1[CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t ep_in_ff_mutex_wr_1; // No need for read mutex as only USB driver reads from FIFO
-#endif
-#endif // CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ > 0
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t audio_ep_in_sw_buf_2[CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t ep_in_ff_mutex_wr_2; // No need for read mutex as only USB driver reads from FIFO
-#endif
-#endif // CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ > 0
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t audio_ep_in_sw_buf_3[CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t ep_in_ff_mutex_wr_3; // No need for read mutex as only USB driver reads from FIFO
-#endif
-#endif // CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ > 0
-#endif // CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-
-// Linear buffer TX in case:
-// - target MCU is not capable of handling a ring buffer FIFO e.g. no hardware buffer is available or driver is would need to be changed dramatically OR
-// - the software encoding is used - in this case the linear buffers serve as a target memory where logical channels are encoded into
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && (USE_LINEAR_BUFFER || CFG_TUD_AUDIO_ENABLE_ENCODING)
-#if CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t lin_buf_in_1[CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX];
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t lin_buf_in_2[CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX];
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t lin_buf_in_3[CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX];
-#endif
-#endif // CFG_TUD_AUDIO_ENABLE_EP_IN && (USE_LINEAR_BUFFER || CFG_TUD_AUDIO_ENABLE_DECODING)
-
-// EP OUT software buffers and mutexes
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-#if CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t audio_ep_out_sw_buf_1[CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t ep_out_ff_mutex_rd_1; // No need for write mutex as only USB driver writes into FIFO
-#endif
-#endif // CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ > 0
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t audio_ep_out_sw_buf_2[CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t ep_out_ff_mutex_rd_2; // No need for write mutex as only USB driver writes into FIFO
-#endif
-#endif // CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ > 0
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t audio_ep_out_sw_buf_3[CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t ep_out_ff_mutex_rd_3; // No need for write mutex as only USB driver writes into FIFO
-#endif
-#endif // CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ > 0
-#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-
-// Linear buffer RX in case:
-// - target MCU is not capable of handling a ring buffer FIFO e.g. no hardware buffer is available or driver is would need to be changed dramatically OR
-// - the software encoding is used - in this case the linear buffers serve as a target memory where logical channels are encoded into
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && (USE_LINEAR_BUFFER || CFG_TUD_AUDIO_ENABLE_DECODING)
-#if CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t lin_buf_out_1[CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX];
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t lin_buf_out_2[CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX];
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t lin_buf_out_3[CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX];
-#endif
-#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT && (USE_LINEAR_BUFFER || CFG_TUD_AUDIO_ENABLE_DECODING)
-
-// Control buffers
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t ctrl_buf_1[CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ];
-#if CFG_TUD_AUDIO > 1
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t ctrl_buf_2[CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ];
-#endif
-#if CFG_TUD_AUDIO > 2
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t ctrl_buf_3[CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ];
-#endif
-
-// Active alternate setting of interfaces
-uint8_t alt_setting_1[CFG_TUD_AUDIO_FUNC_1_N_AS_INT];
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_N_AS_INT > 0
-uint8_t alt_setting_2[CFG_TUD_AUDIO_FUNC_2_N_AS_INT];
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_N_AS_INT > 0
-uint8_t alt_setting_3[CFG_TUD_AUDIO_FUNC_3_N_AS_INT];
-#endif
-
-// Software encoding/decoding support FIFOs
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
-#if CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t tx_supp_ff_buf_1[CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO][CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ];
-tu_fifo_t tx_supp_ff_1[CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t tx_supp_ff_mutex_wr_1[CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO]; // No need for read mutex as only USB driver reads from FIFO
-#endif
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t tx_supp_ff_buf_2[CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO][CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ];
-tu_fifo_t tx_supp_ff_2[CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t tx_supp_ff_mutex_wr_2[CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO]; // No need for read mutex as only USB driver reads from FIFO
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t tx_supp_ff_buf_3[CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO][CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ];
-tu_fifo_t tx_supp_ff_3[CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t tx_supp_ff_mutex_wr_3[CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO]; // No need for read mutex as only USB driver reads from FIFO
-#endif
-#endif
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
-#if CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t rx_supp_ff_buf_1[CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO][CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ];
-tu_fifo_t rx_supp_ff_1[CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t rx_supp_ff_mutex_rd_1[CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO]; // No need for write mutex as only USB driver writes into FIFO
-#endif
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t rx_supp_ff_buf_2[CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO][CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ];
-tu_fifo_t rx_supp_ff_2[CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t rx_supp_ff_mutex_rd_2[CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO]; // No need for write mutex as only USB driver writes into FIFO
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ > 0
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t rx_supp_ff_buf_3[CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO][CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ];
-tu_fifo_t rx_supp_ff_3[CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO];
-#if CFG_FIFO_MUTEX
-osal_mutex_def_t rx_supp_ff_mutex_rd_3[CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO]; // No need for write mutex as only USB driver writes into FIFO
-#endif
-#endif
-#endif
-
-typedef struct
-{
- uint8_t rhport;
- uint8_t const * p_desc; // Pointer pointing to Standard AC Interface Descriptor(4.7.1) - Audio Control descriptor defining audio function
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
- uint8_t ep_in; // TX audio data EP.
- uint16_t ep_in_sz; // Current size of TX EP
- uint8_t ep_in_as_intf_num; // Corresponding Standard AS Interface Descriptor (4.9.1) belonging to output terminal to which this EP belongs - 0 is invalid (this fits to UAC2 specification since AS interfaces can not have interface number equal to zero)
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
- uint8_t ep_out; // Incoming (into uC) audio data EP.
- uint16_t ep_out_sz; // Current size of RX EP
- uint8_t ep_out_as_intf_num; // Corresponding Standard AS Interface Descriptor (4.9.1) belonging to input terminal to which this EP belongs - 0 is invalid (this fits to UAC2 specification since AS interfaces can not have interface number equal to zero)
-
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
- uint8_t ep_fb; // Feedback EP.
-#endif
-
-#endif
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
- uint8_t ep_int_ctr; // Audio control interrupt EP.
-#endif
-
- /*------------- From this point, data is not cleared by bus reset -------------*/
-
- uint16_t desc_length; // Length of audio function descriptor
-
- // Buffer for control requests
- uint8_t * ctrl_buf;
- uint8_t ctrl_buf_sz;
-
- // Current active alternate settings
- uint8_t * alt_setting; // We need to save the current alternate setting this way, because it is possible that there are AS interfaces which do not have an EP!
-
- // EP Transfer buffers and FIFOs
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-#if !CFG_TUD_AUDIO_ENABLE_DECODING
- tu_fifo_t ep_out_ff;
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
- uint32_t fb_val; // Feedback value for asynchronous mode (in 16.16 format).
-#endif
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
- tu_fifo_t ep_in_ff;
-#endif
-
- // Audio control interrupt buffer - no FIFO - 6 Bytes according to UAC 2 specification (p. 74)
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
- CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN uint8_t ep_int_ctr_buf[CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE];
-#endif
-
- // Decoding parameters - parameters are set when alternate AS interface is set by host
- // Coding is currently only supported for EP. Software coding corresponding to AS interfaces without EPs are not supported currently.
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
- audio_format_type_t format_type_rx;
- uint8_t n_channels_rx;
-
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
- audio_data_format_type_I_t format_type_I_rx;
- uint8_t n_bytes_per_sampe_rx;
- uint8_t n_channels_per_ff_rx;
- uint8_t n_ff_used_rx;
-#endif
-#endif
-
- // Encoding parameters - parameters are set when alternate AS interface is set by host
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
- audio_format_type_t format_type_tx;
- uint8_t n_channels_tx;
-
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
- audio_data_format_type_I_t format_type_I_tx;
- uint8_t n_bytes_per_sampe_tx;
- uint8_t n_channels_per_ff_tx;
- uint8_t n_ff_used_tx;
-#endif
-#endif
-
- // Support FIFOs for software encoding and decoding
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
- tu_fifo_t * rx_supp_ff;
- uint8_t n_rx_supp_ff;
- uint16_t rx_supp_ff_sz_max;
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
- tu_fifo_t * tx_supp_ff;
- uint8_t n_tx_supp_ff;
- uint16_t tx_supp_ff_sz_max;
-#endif
-
- // Linear buffer in case target MCU is not capable of handling a ring buffer FIFO e.g. no hardware buffer is available or driver is would need to be changed dramatically OR the support FIFOs are used
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && (USE_LINEAR_BUFFER || CFG_TUD_AUDIO_ENABLE_DECODING)
- uint8_t * lin_buf_out;
-#define USE_LINEAR_BUFFER_RX 1
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && (USE_LINEAR_BUFFER || CFG_TUD_AUDIO_ENABLE_ENCODING)
- uint8_t * lin_buf_in;
-#define USE_LINEAR_BUFFER_TX 1
-#endif
-
-} audiod_function_t;
-
-#ifndef USE_LINEAR_BUFFER_TX
-#define USE_LINEAR_BUFFER_TX 0
-#endif
-
-#ifndef USE_LINEAR_BUFFER_RX
-#define USE_LINEAR_BUFFER_RX 0
-#endif
-
-#define ITF_MEM_RESET_SIZE offsetof(audiod_function_t, ctrl_buf)
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION audiod_function_t _audiod_fct[CFG_TUD_AUDIO];
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-static bool audiod_rx_done_cb(uint8_t rhport, audiod_function_t* audio, uint16_t n_bytes_received);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_EP_OUT
-static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_function_t* audio, uint16_t n_bytes_received);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
-static bool audiod_tx_done_cb(uint8_t rhport, audiod_function_t* audio);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_EP_IN
-static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audio);
-#endif
-
-static bool audiod_get_interface(uint8_t rhport, tusb_control_request_t const * p_request);
-static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const * p_request);
-
-static bool audiod_get_AS_interface_index_global(uint8_t itf, uint8_t *func_id, uint8_t *idxItf, uint8_t const **pp_desc_int);
-static bool audiod_get_AS_interface_index(uint8_t itf, audiod_function_t * audio, uint8_t *idxItf, uint8_t const **pp_desc_int);
-static bool audiod_verify_entity_exists(uint8_t itf, uint8_t entityID, uint8_t *func_id);
-static bool audiod_verify_itf_exists(uint8_t itf, uint8_t *func_id);
-static bool audiod_verify_ep_exists(uint8_t ep, uint8_t *func_id);
-static uint8_t audiod_get_audio_fct_idx(audiod_function_t * audio);
-
-#if CFG_TUD_AUDIO_ENABLE_ENCODING || CFG_TUD_AUDIO_ENABLE_DECODING
-static void audiod_parse_for_AS_params(audiod_function_t* audio, uint8_t const * p_desc, uint8_t const * p_desc_end, uint8_t const as_itf);
-
-static inline uint8_t tu_desc_subtype(void const* desc)
-{
- return ((uint8_t const*) desc)[2];
-}
-#endif
-
-bool tud_audio_n_mounted(uint8_t func_id)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO);
- audiod_function_t* audio = &_audiod_fct[func_id];
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (audio->ep_out == 0) return false;
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
- if (audio->ep_in == 0) return false;
-#endif
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
- if (audio->ep_int_ctr == 0) return false;
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
- if (audio->ep_fb == 0) return false;
-#endif
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// READ API
-//--------------------------------------------------------------------+
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-
-uint16_t tud_audio_n_available(uint8_t func_id)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
- return tu_fifo_count(&_audiod_fct[func_id].ep_out_ff);
-}
-
-uint16_t tud_audio_n_read(uint8_t func_id, void* buffer, uint16_t bufsize)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
- return tu_fifo_read_n(&_audiod_fct[func_id].ep_out_ff, buffer, bufsize);
-}
-
-bool tud_audio_n_clear_ep_out_ff(uint8_t func_id)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
- return tu_fifo_clear(&_audiod_fct[func_id].ep_out_ff);
-}
-
-tu_fifo_t* tud_audio_n_get_ep_out_ff(uint8_t func_id)
-{
- if(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL) return &_audiod_fct[func_id].ep_out_ff;
- return NULL;
-}
-
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_EP_OUT
-// Delete all content in the support RX FIFOs
-bool tud_audio_n_clear_rx_support_ff(uint8_t func_id, uint8_t ff_idx)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL && ff_idx < _audiod_fct[func_id].n_rx_supp_ff);
- return tu_fifo_clear(&_audiod_fct[func_id].rx_supp_ff[ff_idx]);
-}
-
-uint16_t tud_audio_n_available_support_ff(uint8_t func_id, uint8_t ff_idx)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL && ff_idx < _audiod_fct[func_id].n_rx_supp_ff);
- return tu_fifo_count(&_audiod_fct[func_id].rx_supp_ff[ff_idx]);
-}
-
-uint16_t tud_audio_n_read_support_ff(uint8_t func_id, uint8_t ff_idx, void* buffer, uint16_t bufsize)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL && ff_idx < _audiod_fct[func_id].n_rx_supp_ff);
- return tu_fifo_read_n(&_audiod_fct[func_id].rx_supp_ff[ff_idx], buffer, bufsize);
-}
-
-tu_fifo_t* tud_audio_n_get_rx_support_ff(uint8_t func_id, uint8_t ff_idx)
-{
- if(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL && ff_idx < _audiod_fct[func_id].n_rx_supp_ff) return &_audiod_fct[func_id].rx_supp_ff[ff_idx];
- return NULL;
-}
-#endif
-
-// This function is called once an audio packet is received by the USB and is responsible for putting data from USB memory into EP_OUT_FIFO (or support FIFOs + decoding of received stream into audio channels).
-// If you prefer your own (more efficient) implementation suiting your purpose set CFG_TUD_AUDIO_ENABLE_DECODING = 0.
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-
-static bool audiod_rx_done_cb(uint8_t rhport, audiod_function_t* audio, uint16_t n_bytes_received)
-{
- uint8_t idxItf;
- uint8_t const *dummy2;
- uint8_t idx_audio_fct = 0;
-
- if (tud_audio_rx_done_pre_read_cb || tud_audio_rx_done_post_read_cb)
- {
- idx_audio_fct = audiod_get_audio_fct_idx(audio);
- TU_VERIFY(audiod_get_AS_interface_index(audio->ep_out_as_intf_num, audio, &idxItf, &dummy2));
- }
-
- // Call a weak callback here - a possibility for user to get informed an audio packet was received and data gets now loaded into EP FIFO (or decoded into support RX software FIFO)
- if (tud_audio_rx_done_pre_read_cb) TU_VERIFY(tud_audio_rx_done_pre_read_cb(rhport, n_bytes_received, idx_audio_fct, audio->ep_out, audio->alt_setting[idxItf]));
-
-#if CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_EP_OUT
-
- switch (audio->format_type_rx)
- {
- case AUDIO_FORMAT_TYPE_UNDEFINED:
- // INDIVIDUAL DECODING PROCEDURE REQUIRED HERE!
- TU_LOG2(" Desired CFG_TUD_AUDIO_FORMAT encoding not implemented!\r\n");
- TU_BREAKPOINT();
- break;
-
- case AUDIO_FORMAT_TYPE_I:
-
- switch (audio->format_type_I_tx)
- {
- case AUDIO_DATA_FORMAT_TYPE_I_PCM:
- TU_VERIFY(audiod_decode_type_I_pcm(rhport, audio, n_bytes_received));
- break;
-
- default:
- // DESIRED CFG_TUD_AUDIO_FORMAT_TYPE_I_RX NOT IMPLEMENTED!
- TU_LOG2(" Desired CFG_TUD_AUDIO_FORMAT_TYPE_I_RX encoding not implemented!\r\n");
- TU_BREAKPOINT();
- break;
- }
- break;
-
- default:
- // Desired CFG_TUD_AUDIO_FORMAT_TYPE_RX not implemented!
- TU_LOG2(" Desired CFG_TUD_AUDIO_FORMAT_TYPE_RX not implemented!\r\n");
- TU_BREAKPOINT();
- break;
- }
-
- // Prepare for next transmission
- TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false);
-
-#else
-
-#if USE_LINEAR_BUFFER_RX
- // Data currently is in linear buffer, copy into EP OUT FIFO
- TU_VERIFY(tu_fifo_write_n(&audio->ep_out_ff, audio->lin_buf_out, n_bytes_received));
-
- // Schedule for next receive
- TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false);
-#else
- // Data is already placed in EP FIFO, schedule for next receive
- TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false);
-#endif
-
-#endif
-
- // Call a weak callback here - a possibility for user to get informed decoding was completed
- if (tud_audio_rx_done_post_read_cb) TU_VERIFY(tud_audio_rx_done_post_read_cb(rhport, n_bytes_received, idx_audio_fct, audio->ep_out, audio->alt_setting[idxItf]));
-
- return true;
-}
-
-#endif //CFG_TUD_AUDIO_ENABLE_EP_OUT
-
-// The following functions are used in case CFG_TUD_AUDIO_ENABLE_DECODING != 0
-#if CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_EP_OUT
-
-// Decoding according to 2.3.1.5 Audio Streams
-
-// Helper function
-static inline uint8_t * audiod_interleaved_copy_bytes_fast_decode(uint16_t const nBytesToCopy, void * dst, uint8_t * dst_end, uint8_t * src, uint8_t const n_ff_used)
-{
-
- // This function is an optimized version of
- // while((uint8_t *)dst < dst_end)
- // {
- // memcpy(dst, src, nBytesToCopy);
- // dst = (uint8_t *)dst + nBytesToCopy;
- // src += nBytesToCopy * n_ff_used;
- // }
-
- // Optimize for fast half word copies
- typedef struct{
- uint16_t val;
- } __attribute((__packed__)) unaligned_uint16_t;
-
- // Optimize for fast word copies
- typedef struct{
- uint32_t val;
- } __attribute((__packed__)) unaligned_uint32_t;
-
- switch (nBytesToCopy)
- {
- case 1:
- while((uint8_t *)dst < dst_end)
- {
- *(uint8_t *)dst++ = *src;
- src += n_ff_used;
- }
- break;
-
- case 2:
- while((uint8_t *)dst < dst_end)
- {
- *(unaligned_uint16_t*)dst = *(unaligned_uint16_t*)src;
- dst += 2;
- src += 2 * n_ff_used;
- }
- break;
-
- case 3:
- while((uint8_t *)dst < dst_end)
- {
- // memcpy(dst, src, 3);
- // dst = (uint8_t *)dst + 3;
- // src += 3 * n_ff_used;
-
- // TODO: Is there a faster way to copy 3 bytes?
- *(uint8_t *)dst++ = *src++;
- *(uint8_t *)dst++ = *src++;
- *(uint8_t *)dst++ = *src++;
-
- src += 3 * (n_ff_used - 1);
- }
- break;
-
- case 4:
- while((uint8_t *)dst < dst_end)
- {
- *(unaligned_uint32_t*)dst = *(unaligned_uint32_t*)src;
- dst += 4;
- src += 4 * n_ff_used;
- }
- break;
- }
-
- return src;
-}
-
-static bool audiod_decode_type_I_pcm(uint8_t rhport, audiod_function_t* audio, uint16_t n_bytes_received)
-{
- (void) rhport;
-
- // Determine amount of samples
- uint8_t const n_ff_used = audio->n_ff_used_rx;
- uint16_t const nBytesPerFFToRead = n_bytes_received / n_ff_used;
- uint8_t cnt_ff;
-
- // Decode
- uint8_t * src;
- uint8_t * dst_end;
-
- tu_fifo_buffer_info_t info;
-
- for (cnt_ff = 0; cnt_ff < n_ff_used; cnt_ff++)
- {
- tu_fifo_get_write_info(&audio->rx_supp_ff[cnt_ff], &info);
-
- if (info.len_lin != 0)
- {
- info.len_lin = tu_min16(nBytesPerFFToRead, info.len_lin);
- src = &audio->lin_buf_out[cnt_ff*audio->n_channels_per_ff_rx * audio->n_bytes_per_sampe_rx];
- dst_end = info.ptr_lin + info.len_lin;
- src = audiod_interleaved_copy_bytes_fast_decode(audio->n_bytes_per_sampe_rx, info.ptr_lin, dst_end, src, n_ff_used);
-
- // Handle wrapped part of FIFO
- info.len_wrap = tu_min16(nBytesPerFFToRead - info.len_lin, info.len_wrap);
- if (info.len_wrap != 0)
- {
- dst_end = info.ptr_wrap + info.len_wrap;
- audiod_interleaved_copy_bytes_fast_decode(audio->n_bytes_per_sampe_rx, info.ptr_wrap, dst_end, src, n_ff_used);
- }
- tu_fifo_advance_write_pointer(&audio->rx_supp_ff[cnt_ff], info.len_lin + info.len_wrap);
- }
- }
-
- // Number of bytes should be a multiple of CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_RX * CFG_TUD_AUDIO_N_CHANNELS_RX but checking makes no sense - no way to correct it
- // TU_VERIFY(cnt != n_bytes);
-
- return true;
-}
-#endif //CFG_TUD_AUDIO_ENABLE_DECODING
-
-//--------------------------------------------------------------------+
-// WRITE API
-//--------------------------------------------------------------------+
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-
-/**
- * \brief Write data to EP in buffer
- *
- * Write data to buffer. If it is full, new data can be inserted once a transmit was scheduled. See audiod_tx_done_cb().
- * If TX FIFOs are used, this function is not available in order to not let the user mess up the encoding process.
- *
- * \param[in] func_id: Index of audio function interface
- * \param[in] data: Pointer to data array to be copied from
- * \param[in] len: # of array elements to copy
- * \return Number of bytes actually written
- */
-uint16_t tud_audio_n_write(uint8_t func_id, const void * data, uint16_t len)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
- return tu_fifo_write_n(&_audiod_fct[func_id].ep_in_ff, data, len);
-}
-
-bool tud_audio_n_clear_ep_in_ff(uint8_t func_id) // Delete all content in the EP IN FIFO
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
- return tu_fifo_clear(&_audiod_fct[func_id].ep_in_ff);
-}
-
-tu_fifo_t* tud_audio_n_get_ep_in_ff(uint8_t func_id)
-{
- if(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL) return &_audiod_fct[func_id].ep_in_ff;
- return NULL;
-}
-
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_EP_IN
-
-uint16_t tud_audio_n_flush_tx_support_ff(uint8_t func_id) // Force all content in the support TX FIFOs to be written into linear buffer and schedule a transmit
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
- audiod_function_t* audio = &_audiod_fct[func_id];
-
- uint16_t n_bytes_copied = tu_fifo_count(&audio->tx_supp_ff[0]);
-
- TU_VERIFY(audiod_tx_done_cb(audio->rhport, audio));
-
- n_bytes_copied -= tu_fifo_count(&audio->tx_supp_ff[0]);
- n_bytes_copied = n_bytes_copied*audio->tx_supp_ff[0].item_size;
-
- return n_bytes_copied;
-}
-
-bool tud_audio_n_clear_tx_support_ff(uint8_t func_id, uint8_t ff_idx)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL && ff_idx < _audiod_fct[func_id].n_tx_supp_ff);
- return tu_fifo_clear(&_audiod_fct[func_id].tx_supp_ff[ff_idx]);
-}
-
-uint16_t tud_audio_n_write_support_ff(uint8_t func_id, uint8_t ff_idx, const void * data, uint16_t len)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL && ff_idx < _audiod_fct[func_id].n_tx_supp_ff);
- return tu_fifo_write_n(&_audiod_fct[func_id].tx_supp_ff[ff_idx], data, len);
-}
-
-tu_fifo_t* tud_audio_n_get_tx_support_ff(uint8_t func_id, uint8_t ff_idx)
-{
- if(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL && ff_idx < _audiod_fct[func_id].n_tx_supp_ff) return &_audiod_fct[func_id].tx_supp_ff[ff_idx];
- return NULL;
-}
-
-#endif
-
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
-
-// If no interrupt transmit is pending bytes get written into buffer and a transmit is scheduled - once transmit completed tud_audio_int_ctr_done_cb() is called in inform user
-uint16_t tud_audio_int_ctr_n_write(uint8_t func_id, uint8_t const* buffer, uint16_t len)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
-
- // We write directly into the EP's buffer - abort if previous transfer not complete
- TU_VERIFY(!usbd_edpt_busy(_audiod_fct[func_id].rhport, _audiod_fct[func_id].ep_int_ctr));
-
- // Check length
- TU_VERIFY(len <= CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE);
-
- memcpy(_audiod_fct[func_id].ep_int_ctr_buf, buffer, len);
-
- // Schedule transmit
- TU_VERIFY(usbd_edpt_xfer(_audiod_fct[func_id].rhport, _audiod_fct[func_id].ep_int_ctr, _audiod_fct[func_id].ep_int_ctr_buf, len));
-
- return true;
-}
-
-#endif
-
-
-// This function is called once a transmit of an audio packet was successfully completed. Here, we encode samples and place it in IN EP's buffer for next transmission.
-// If you prefer your own (more efficient) implementation suiting your purpose set CFG_TUD_AUDIO_ENABLE_ENCODING = 0 and use tud_audio_n_write.
-
-// n_bytes_copied - Informs caller how many bytes were loaded. In case n_bytes_copied = 0, a ZLP is scheduled to inform host no data is available for current frame.
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
-static bool audiod_tx_done_cb(uint8_t rhport, audiod_function_t * audio)
-{
- uint8_t idxItf;
- uint8_t const *dummy2;
-
- uint8_t idx_audio_fct = audiod_get_audio_fct_idx(audio);
- TU_VERIFY(audiod_get_AS_interface_index(audio->ep_in_as_intf_num, audio, &idxItf, &dummy2));
-
- // Only send something if current alternate interface is not 0 as in this case nothing is to be sent due to UAC2 specifications
- if (audio->alt_setting[idxItf] == 0) return false;
-
- // Call a weak callback here - a possibility for user to get informed former TX was completed and data gets now loaded into EP in buffer (in case FIFOs are used) or
- // if no FIFOs are used the user may use this call back to load its data into the EP IN buffer by use of tud_audio_n_write_ep_in_buffer().
- if (tud_audio_tx_done_pre_load_cb) TU_VERIFY(tud_audio_tx_done_pre_load_cb(rhport, idx_audio_fct, audio->ep_in, audio->alt_setting[idxItf]));
-
- // Send everything in ISO EP FIFO
- uint16_t n_bytes_tx;
-
- // If support FIFOs are used, encode and schedule transmit
-#if CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_EP_IN
- switch (audio->format_type_tx)
- {
- case AUDIO_FORMAT_TYPE_UNDEFINED:
- // INDIVIDUAL ENCODING PROCEDURE REQUIRED HERE!
- TU_LOG2(" Desired CFG_TUD_AUDIO_FORMAT encoding not implemented!\r\n");
- TU_BREAKPOINT();
- n_bytes_tx = 0;
- break;
-
- case AUDIO_FORMAT_TYPE_I:
-
- switch (audio->format_type_I_tx)
- {
- case AUDIO_DATA_FORMAT_TYPE_I_PCM:
-
- n_bytes_tx = audiod_encode_type_I_pcm(rhport, audio);
- break;
-
- default:
- // YOUR ENCODING IS REQUIRED HERE!
- TU_LOG2(" Desired CFG_TUD_AUDIO_FORMAT_TYPE_I_TX encoding not implemented!\r\n");
- TU_BREAKPOINT();
- n_bytes_tx = 0;
- break;
- }
- break;
-
- default:
- // Desired CFG_TUD_AUDIO_FORMAT_TYPE_TX not implemented!
- TU_LOG2(" Desired CFG_TUD_AUDIO_FORMAT_TYPE_TX not implemented!\r\n");
- TU_BREAKPOINT();
- n_bytes_tx = 0;
- break;
- }
-
- TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_in, audio->lin_buf_in, n_bytes_tx));
-
-#else
- // No support FIFOs, if no linear buffer required schedule transmit, else put data into linear buffer and schedule
-
- n_bytes_tx = tu_min16(tu_fifo_count(&audio->ep_in_ff), audio->ep_in_sz); // Limit up to max packet size, more can not be done for ISO
-
-#if USE_LINEAR_BUFFER_TX
- tu_fifo_read_n(&audio->ep_in_ff, audio->lin_buf_in, n_bytes_tx);
- TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_in, audio->lin_buf_in, n_bytes_tx));
-#else
- // Send everything in ISO EP FIFO
- TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_in, &audio->ep_in_ff, n_bytes_tx));
-#endif
-
-#endif
-
- // Call a weak callback here - a possibility for user to get informed former TX was completed and how many bytes were loaded for the next frame
- if (tud_audio_tx_done_post_load_cb) TU_VERIFY(tud_audio_tx_done_post_load_cb(rhport, n_bytes_tx, idx_audio_fct, audio->ep_in, audio->alt_setting[idxItf]));
-
- return true;
-}
-
-#endif //CFG_TUD_AUDIO_ENABLE_EP_IN
-
-#if CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_EP_IN
-// Take samples from the support buffer and encode them into the IN EP software FIFO
-// Returns number of bytes written into linear buffer
-
-/* 2.3.1.7.1 PCM Format
-The PCM (Pulse Coded Modulation) format is the most commonly used audio format to represent audio
-data streams. The audio data is not compressed and uses a signed two’s-complement fixed point format. It
-is left-justified (the sign bit is the Msb) and data is padded with trailing zeros to fill the remaining unused
-bits of the subslot. The binary point is located to the right of the sign bit so that all values lie within the
-range [-1, +1)
- */
-
-/*
- * This function encodes channels saved within the support FIFOs into one stream by interleaving the PCM samples
- * in the support FIFOs according to 2.3.1.5 Audio Streams. It does not control justification (left or right) and
- * does not change the number of bytes per sample.
- * */
-
-// Helper function
-static inline uint8_t * audiod_interleaved_copy_bytes_fast_encode(uint16_t const nBytesToCopy, uint8_t * src, uint8_t * src_end, uint8_t * dst, uint8_t const n_ff_used)
-{
- // Optimize for fast half word copies
- typedef struct{
- uint16_t val;
- } __attribute((__packed__)) unaligned_uint16_t;
-
- // Optimize for fast word copies
- typedef struct{
- uint32_t val;
- } __attribute((__packed__)) unaligned_uint32_t;
-
- switch (nBytesToCopy)
- {
- case 1:
- while(src < src_end)
- {
- *dst = *src++;
- dst += n_ff_used;
- }
- break;
-
- case 2:
- while(src < src_end)
- {
- *(unaligned_uint16_t*)dst = *(unaligned_uint16_t*)src;
- src += 2;
- dst += 2 * n_ff_used;
- }
- break;
-
- case 3:
- while(src < src_end)
- {
- // memcpy(dst, src, 3);
- // src = (uint8_t *)src + 3;
- // dst += 3 * n_ff_used;
-
- // TODO: Is there a faster way to copy 3 bytes?
- *dst++ = *src++;
- *dst++ = *src++;
- *dst++ = *src++;
-
- dst += 3 * (n_ff_used - 1);
- }
- break;
-
- case 4:
- while(src < src_end)
- {
- *(unaligned_uint32_t*)dst = *(unaligned_uint32_t*)src;
- src += 4;
- dst += 4 * n_ff_used;
- }
- break;
- }
-
- return dst;
-}
-
-static uint16_t audiod_encode_type_I_pcm(uint8_t rhport, audiod_function_t* audio)
-{
- // This function relies on the fact that the length of the support FIFOs was configured to be a multiple of the active sample size in bytes s.t. no sample is split within a wrap
- // This is ensured within set_interface, where the FIFOs are reconfigured according to this size
-
- // We encode directly into IN EP's linear buffer - abort if previous transfer not complete
- TU_VERIFY(!usbd_edpt_busy(rhport, audio->ep_in));
-
- // Determine amount of samples
- uint8_t const n_ff_used = audio->n_ff_used_tx;
- uint16_t const nBytesToCopy = audio->n_channels_per_ff_tx * audio->n_bytes_per_sampe_tx;
- uint16_t const capPerFF = audio->ep_in_sz / n_ff_used; // Sample capacity per FIFO in bytes
- uint16_t nBytesPerFFToSend = tu_fifo_count(&audio->tx_supp_ff[0]);
- uint8_t cnt_ff;
-
- for (cnt_ff = 1; cnt_ff < n_ff_used; cnt_ff++)
- {
- uint16_t const count = tu_fifo_count(&audio->tx_supp_ff[cnt_ff]);
- if (count < nBytesPerFFToSend)
- {
- nBytesPerFFToSend = count;
- }
- }
-
- // Check if there is enough
- if (nBytesPerFFToSend == 0) return 0;
-
- // Limit to maximum sample number - THIS IS A POSSIBLE ERROR SOURCE IF TOO MANY SAMPLE WOULD NEED TO BE SENT BUT CAN NOT!
- nBytesPerFFToSend = tu_min16(nBytesPerFFToSend, capPerFF);
-
- // Round to full number of samples (flooring)
- nBytesPerFFToSend = (nBytesPerFFToSend / nBytesToCopy) * nBytesToCopy;
-
- // Encode
- uint8_t * dst;
- uint8_t * src_end;
-
- tu_fifo_buffer_info_t info;
-
- for (cnt_ff = 0; cnt_ff < n_ff_used; cnt_ff++)
- {
- dst = &audio->lin_buf_in[cnt_ff*audio->n_channels_per_ff_tx*audio->n_bytes_per_sampe_tx];
-
- tu_fifo_get_read_info(&audio->tx_supp_ff[cnt_ff], &info);
-
- if (info.len_lin != 0)
- {
- info.len_lin = tu_min16(nBytesPerFFToSend, info.len_lin); // Limit up to desired length
- src_end = (uint8_t *)info.ptr_lin + info.len_lin;
- dst = audiod_interleaved_copy_bytes_fast_encode(audio->n_bytes_per_sampe_tx, info.ptr_lin, src_end, dst, n_ff_used);
-
- // Limit up to desired length
- info.len_wrap = tu_min16(nBytesPerFFToSend - info.len_lin, info.len_wrap);
-
- // Handle wrapped part of FIFO
- if (info.len_wrap != 0)
- {
- src_end = (uint8_t *)info.ptr_wrap + info.len_wrap;
- audiod_interleaved_copy_bytes_fast_encode(audio->n_bytes_per_sampe_tx, info.ptr_wrap, src_end, dst, n_ff_used);
- }
-
- tu_fifo_advance_read_pointer(&audio->tx_supp_ff[cnt_ff], info.len_lin + info.len_wrap);
- }
- }
-
- return nBytesPerFFToSend * n_ff_used;
-}
-#endif //CFG_TUD_AUDIO_ENABLE_ENCODING
-
-// This function is called once a transmit of a feedback packet was successfully completed. Here, we get the next feedback value to be sent
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
-static inline bool audiod_fb_send(uint8_t rhport, audiod_function_t *audio)
-{
- return usbd_edpt_xfer(rhport, audio->ep_fb, (uint8_t *) &audio->fb_val, 4);
-}
-#endif
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void audiod_init(void)
-{
- tu_memclr(_audiod_fct, sizeof(_audiod_fct));
-
- for(uint8_t i=0; i<CFG_TUD_AUDIO; i++)
- {
- audiod_function_t* audio = &_audiod_fct[i];
-
- // Initialize control buffers
- switch (i)
- {
- case 0:
- audio->ctrl_buf = ctrl_buf_1;
- audio->ctrl_buf_sz = CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ;
- break;
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ > 0
- case 1:
- audio->ctrl_buf = ctrl_buf_2;
- audio->ctrl_buf_sz = CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ;
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ > 0
- case 2:
- audio->ctrl_buf = ctrl_buf_3;
- audio->ctrl_buf_sz = CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ;
- break;
-#endif
- }
-
- // Initialize active alternate interface buffers
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_N_AS_INT > 0
- case 0:
- audio->alt_setting = alt_setting_1;
- break;
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_N_AS_INT > 0
- case 1:
- audio->alt_setting = alt_setting_2;
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_N_AS_INT > 0
- case 2:
- audio->alt_setting = alt_setting_3;
- break;
-#endif
- }
-
- // Initialize IN EP FIFO if required
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ > 0
- case 0:
- tu_fifo_config(&audio->ep_in_ff, audio_ep_in_sw_buf_1, CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&audio->ep_in_ff, osal_mutex_create(&ep_in_ff_mutex_wr_1), NULL);
-#endif
- break;
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ > 0
- case 1:
- tu_fifo_config(&audio->ep_in_ff, audio_ep_in_sw_buf_2, CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&audio->ep_in_ff, osal_mutex_create(&ep_in_ff_mutex_wr_2), NULL);
-#endif
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ > 0
- case 2:
- tu_fifo_config(&audio->ep_in_ff, audio_ep_in_sw_buf_3, CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&audio->ep_in_ff, osal_mutex_create(&ep_in_ff_mutex_wr_3), NULL);
-#endif
- break;
-#endif
- }
-#endif // CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-
- // Initialize linear buffers
-#if USE_LINEAR_BUFFER_TX
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX > 0
- case 0:
- audio->lin_buf_in = lin_buf_in_1;
- break;
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX > 0
- case 1:
- audio->lin_buf_in = lin_buf_in_2;
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX > 0
- case 2:
- audio->lin_buf_in = lin_buf_in_3;
- break;
-#endif
- }
-#endif // USE_LINEAR_BUFFER_TX
-
- // Initialize OUT EP FIFO if required
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ > 0
- case 0:
- tu_fifo_config(&audio->ep_out_ff, audio_ep_out_sw_buf_1, CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&audio->ep_out_ff, NULL, osal_mutex_create(&ep_out_ff_mutex_rd_1));
-#endif
- break;
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ > 0
- case 1:
- tu_fifo_config(&audio->ep_out_ff, audio_ep_out_sw_buf_2, CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&audio->ep_out_ff, NULL, osal_mutex_create(&ep_out_ff_mutex_rd_2));
-#endif
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ > 0
- case 2:
- tu_fifo_config(&audio->ep_out_ff, audio_ep_out_sw_buf_3, CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&audio->ep_out_ff, NULL, osal_mutex_create(&ep_out_ff_mutex_rd_3));
-#endif
- break;
-#endif
- }
-#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-
- // Initialize linear buffers
-#if USE_LINEAR_BUFFER_RX
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX > 0
- case 0:
- audio->lin_buf_out = lin_buf_out_1;
- break;
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX > 0
- case 1:
- audio->lin_buf_out = lin_buf_out_2;
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX > 0
- case 2:
- audio->lin_buf_out = lin_buf_out_3;
- break;
-#endif
- }
-#endif // USE_LINEAR_BUFFER_TX
-
- // Initialize TX support FIFOs if required
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
-
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ > 0
- case 0:
- audio->tx_supp_ff = tx_supp_ff_1;
- audio->n_tx_supp_ff = CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO;
- audio->tx_supp_ff_sz_max = CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ;
- for (uint8_t cnt = 0; cnt < CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO; cnt++)
- {
- tu_fifo_config(&tx_supp_ff_1[cnt], tx_supp_ff_buf_1[cnt], CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&tx_supp_ff_1[cnt], osal_mutex_create(&tx_supp_ff_mutex_wr_1[cnt]), NULL);
-#endif
- }
-
- break;
-#endif // CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ > 0
-
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ > 0
- case 1:
- audio->tx_supp_ff = tx_supp_ff_2;
- audio->n_tx_supp_ff = CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO;
- audio->tx_supp_ff_sz_max = CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ;
- for (uint8_t cnt = 0; cnt < CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO; cnt++)
- {
- tu_fifo_config(&tx_supp_ff_2[cnt], tx_supp_ff_buf_2[cnt], CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&tx_supp_ff_2[cnt], osal_mutex_create(&tx_supp_ff_mutex_wr_2[cnt]), NULL);
-#endif
- }
-
- break;
-#endif // CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ > 0
-
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ > 0
- case 2:
- audio->tx_supp_ff = tx_supp_ff_3;
- audio->n_tx_supp_ff = CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO;
- audio->tx_supp_ff_sz_max = CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ;
- for (uint8_t cnt = 0; cnt < CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO; cnt++)
- {
- tu_fifo_config(&tx_supp_ff_3[cnt], tx_supp_ff_buf_3[cnt], CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&tx_supp_ff_3[cnt], osal_mutex_create(&tx_supp_ff_mutex_wr_3[cnt]), NULL);
-#endif
- }
-
- break;
-#endif // CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ > 0
- }
-#endif // CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
-
- // Set encoding parameters for Type_I formats
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ > 0
- case 0:
- audio->n_channels_per_ff_tx = CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX;
- break;
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ > 0
- case 1:
- audio->n_channels_per_ff_tx = CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_TX;
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ > 0
- case 2:
- audio->n_channels_per_ff_tx = CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_TX;
- break;
-#endif
- }
-#endif // CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
-
- // Initialize RX support FIFOs if required
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
-
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ > 0
- case 0:
- audio->rx_supp_ff = rx_supp_ff_1;
- audio->n_rx_supp_ff = CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO;
- audio->rx_supp_ff_sz_max = CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ;
- for (uint8_t cnt = 0; cnt < CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO; cnt++)
- {
- tu_fifo_config(&rx_supp_ff_1[cnt], rx_supp_ff_buf_1[cnt], CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&rx_supp_ff_1[cnt], osal_mutex_create(&rx_supp_ff_mutex_rd_1[cnt]), NULL);
-#endif
- }
-
- break;
-#endif // CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ > 0
-
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ > 0
- case 1:
- audio->rx_supp_ff = rx_supp_ff_2;
- audio->n_rx_supp_ff = CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO;
- audio->rx_supp_ff_sz_max = CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ;
- for (uint8_t cnt = 0; cnt < CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO; cnt++)
- {
- tu_fifo_config(&rx_supp_ff_2[cnt], rx_supp_ff_buf_2[cnt], CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&rx_supp_ff_2[cnt], osal_mutex_create(&rx_supp_ff_mutex_rd_2[cnt]), NULL);
-#endif
- }
-
- break;
-#endif // CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ > 0
-
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ > 0
- case 2:
- audio->rx_supp_ff = rx_supp_ff_3;
- audio->n_rx_supp_ff = CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO;
- audio->rx_supp_ff_sz_max = CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ;
- for (uint8_t cnt = 0; cnt < CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO; cnt++)
- {
- tu_fifo_config(&rx_supp_ff_3[cnt], rx_supp_ff_buf_3[cnt], CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ, 1, true);
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&rx_supp_ff_3[cnt], osal_mutex_create(&rx_supp_ff_mutex_rd_3[cnt]), NULL);
-#endif
- }
-
- break;
-#endif // CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ > 0
- }
-#endif // CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
-
- // Set encoding parameters for Type_I formats
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
- switch (i)
- {
-#if CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ > 0
- case 0:
- audio->n_channels_per_ff_rx = CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_RX;
- break;
-#endif
-#if CFG_TUD_AUDIO > 1 && CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ > 0
- case 1:
- audio->n_channels_per_ff_rx = CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_RX;
- break;
-#endif
-#if CFG_TUD_AUDIO > 2 && CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ > 0
- case 2:
- audio->n_channels_per_ff_rx = CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_RX;
- break;
-#endif
- }
-#endif // CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
- }
-}
-
-void audiod_reset(uint8_t rhport)
-{
- (void) rhport;
-
- for(uint8_t i=0; i<CFG_TUD_AUDIO; i++)
- {
- audiod_function_t* audio = &_audiod_fct[i];
- tu_memclr(audio, ITF_MEM_RESET_SIZE);
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
- tu_fifo_clear(&audio->ep_in_ff);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
- tu_fifo_clear(&audio->ep_out_ff);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
- for (uint8_t cnt = 0; cnt < audio->n_tx_supp_ff; cnt++)
- {
- tu_fifo_clear(&audio->tx_supp_ff[cnt]);
- }
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
- for (uint8_t cnt = 0; cnt < audio->n_rx_supp_ff; cnt++)
- {
- tu_fifo_clear(&audio->rx_supp_ff[cnt]);
- }
-#endif
- }
-}
-
-uint16_t audiod_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- (void) max_len;
-
- TU_VERIFY ( TUSB_CLASS_AUDIO == itf_desc->bInterfaceClass &&
- AUDIO_SUBCLASS_CONTROL == itf_desc->bInterfaceSubClass);
-
- // Verify version is correct - this check can be omitted
- TU_VERIFY(itf_desc->bInterfaceProtocol == AUDIO_INT_PROTOCOL_CODE_V2);
-
- // Verify interrupt control EP is enabled if demanded by descriptor - this should be best some static check however - this check can be omitted
- if (itf_desc->bNumEndpoints == 1) // 0 or 1 EPs are allowed
- {
- TU_VERIFY(CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN > 0);
- }
-
- // Alternate setting MUST be zero - this check can be omitted
- TU_VERIFY(itf_desc->bAlternateSetting == 0);
-
- // Find available audio driver interface
- uint8_t i;
- for (i = 0; i < CFG_TUD_AUDIO; i++)
- {
- if (!_audiod_fct[i].p_desc)
- {
- _audiod_fct[i].p_desc = (uint8_t const *)itf_desc; // Save pointer to AC descriptor which is by specification always the first one
- _audiod_fct[i].rhport = rhport;
-
- // Setup descriptor lengths
- switch (i)
- {
- case 0:
- _audiod_fct[i].desc_length = CFG_TUD_AUDIO_FUNC_1_DESC_LEN;
- break;
-#if CFG_TUD_AUDIO > 1
- case 1:
- _audiod_fct[i].desc_length = CFG_TUD_AUDIO_FUNC_2_DESC_LEN;
- break;
-#endif
-#if CFG_TUD_AUDIO > 2
- case 2:
- _audiod_fct[i].desc_length = CFG_TUD_AUDIO_FUNC_3_DESC_LEN;
- break;
-#endif
- }
-
- break;
- }
- }
-
- // Verify we found a free one
- TU_ASSERT( i < CFG_TUD_AUDIO );
-
- // This is all we need so far - the EPs are setup by a later set_interface request (as per UAC2 specification)
- uint16_t drv_len = _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN; // - TUD_AUDIO_DESC_IAD_LEN since tinyUSB already handles the IAD descriptor
-
- return drv_len;
-}
-
-static bool audiod_get_interface(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- uint8_t const itf = tu_u16_low(p_request->wIndex);
-
- // Find index of audio streaming interface
- uint8_t func_id, idxItf;
- uint8_t const *dummy;
-
- TU_VERIFY(audiod_get_AS_interface_index_global(itf, &func_id, &idxItf, &dummy));
- TU_VERIFY(tud_control_xfer(rhport, p_request, &_audiod_fct[func_id].alt_setting[idxItf], 1));
-
- TU_LOG2(" Get itf: %u - current alt: %u\r\n", itf, _audiod_fct[func_id].alt_setting[idxItf]);
-
- return true;
-}
-
-static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void) rhport;
-
- // Here we need to do the following:
-
- // 1. Find the audio driver assigned to the given interface to be set
- // Since one audio driver interface has to be able to cover an unknown number of interfaces (AC, AS + its alternate settings), the best memory efficient way to solve this is to always search through the descriptors.
- // The audio driver is mapped to an audio function by a reference pointer to the corresponding AC interface of this audio function which serves as a starting point for searching
-
- // 2. Close EPs which are currently open
- // To do so it is not necessary to know the current active alternate interface since we already save the current EP addresses - we simply close them
-
- // 3. Open new EP
-
- uint8_t const itf = tu_u16_low(p_request->wIndex);
- uint8_t const alt = tu_u16_low(p_request->wValue);
-
- TU_LOG2(" Set itf: %u - alt: %u\r\n", itf, alt);
-
- // Find index of audio streaming interface and index of interface
- uint8_t func_id, idxItf;
- uint8_t const *p_desc;
- TU_VERIFY(audiod_get_AS_interface_index_global(itf, &func_id, &idxItf, &p_desc));
-
- audiod_function_t* audio = &_audiod_fct[func_id];
-
- // Look if there is an EP to be closed - for this driver, there are only 3 possible EPs which may be closed (only AS related EPs can be closed, AC EP (if present) is always open)
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
- if (audio->ep_in_as_intf_num == itf)
- {
- audio->ep_in_as_intf_num = 0;
- usbd_edpt_close(rhport, audio->ep_in);
-
- // Clear FIFOs, since data is no longer valid
-#if !CFG_TUD_AUDIO_ENABLE_ENCODING
- tu_fifo_clear(&audio->ep_in_ff);
-#else
- for (uint8_t cnt = 0; cnt < audio->n_tx_supp_ff; cnt++)
- {
- tu_fifo_clear(&audio->tx_supp_ff[cnt]);
- }
-#endif
-
- // Invoke callback - can be used to stop data sampling
- if (tud_audio_set_itf_close_EP_cb) TU_VERIFY(tud_audio_set_itf_close_EP_cb(rhport, p_request));
-
- audio->ep_in = 0; // Necessary?
-
- }
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (audio->ep_out_as_intf_num == itf)
- {
- audio->ep_out_as_intf_num = 0;
- usbd_edpt_close(rhport, audio->ep_out);
-
- // Clear FIFOs, since data is no longer valid
-#if !CFG_TUD_AUDIO_ENABLE_DECODING
- tu_fifo_clear(&audio->ep_out_ff);
-#else
- for (uint8_t cnt = 0; cnt < audio->n_rx_supp_ff; cnt++)
- {
- tu_fifo_clear(&audio->rx_supp_ff[cnt]);
- }
-#endif
-
- // Invoke callback - can be used to stop data sampling
- if (tud_audio_set_itf_close_EP_cb) TU_VERIFY(tud_audio_set_itf_close_EP_cb(rhport, p_request));
-
- audio->ep_out = 0; // Necessary?
-
- // Close corresponding feedback EP
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
- usbd_edpt_close(rhport, audio->ep_fb);
- audio->ep_fb = 0; // Necessary?
-#endif
- }
-#endif
-
- // Save current alternative interface setting
- audio->alt_setting[idxItf] = alt;
-
- // Open new EP if necessary - EPs are only to be closed or opened for AS interfaces - Look for AS interface with correct alternate interface
- // Get pointer at end
- uint8_t const *p_desc_end = audio->p_desc + audio->desc_length - TUD_AUDIO_DESC_IAD_LEN;
-
- // p_desc starts at required interface with alternate setting zero
- while (p_desc < p_desc_end)
- {
- // Find correct interface
- if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE && ((tusb_desc_interface_t const * )p_desc)->bInterfaceNumber == itf && ((tusb_desc_interface_t const * )p_desc)->bAlternateSetting == alt)
- {
-#if CFG_TUD_AUDIO_ENABLE_ENCODING || CFG_TUD_AUDIO_ENABLE_DECODING
- uint8_t const * p_desc_parse_for_params = p_desc;
-#endif
- // From this point forward follow the EP descriptors associated to the current alternate setting interface - Open EPs if necessary
- uint8_t foundEPs = 0, nEps = ((tusb_desc_interface_t const * )p_desc)->bNumEndpoints;
- while (foundEPs < nEps && p_desc < p_desc_end)
- {
- if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT)
- {
- TU_ASSERT(usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *)p_desc));
-
- uint8_t ep_addr = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
-
- //TODO: We need to set EP non busy since this is not taken care of right now in ep_close() - THIS IS A WORKAROUND!
- usbd_edpt_clear_stall(rhport, ep_addr);
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN && ((tusb_desc_endpoint_t const *) p_desc)->bmAttributes.usage == 0x00) // Check if usage is data EP
- {
- // Save address
- audio->ep_in = ep_addr;
- audio->ep_in_as_intf_num = itf;
- audio->ep_in_sz = ((tusb_desc_endpoint_t const *) p_desc)->wMaxPacketSize.size;
-
- // If software encoding is enabled, parse for the corresponding parameters - doing this here means only AS interfaces with EPs get scanned for parameters
-#if CFG_TUD_AUDIO_ENABLE_ENCODING
- audiod_parse_for_AS_params(audio, p_desc_parse_for_params, p_desc_end, itf);
-
- // Reconfigure size of support FIFOs - this is necessary to avoid samples to get split in case of a wrap
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
- const uint16_t active_fifo_depth = (audio->tx_supp_ff_sz_max / audio->n_bytes_per_sampe_tx) * audio->n_bytes_per_sampe_tx;
- for (uint8_t cnt = 0; cnt < audio->n_tx_supp_ff; cnt++)
- {
- tu_fifo_config(&audio->tx_supp_ff[cnt], audio->tx_supp_ff[cnt].buffer, active_fifo_depth, 1, true);
- }
- audio->n_ff_used_tx = audio->n_channels_tx / audio->n_channels_per_ff_tx;
- TU_ASSERT( audio->n_ff_used_tx <= audio->n_tx_supp_ff );
-#endif
-
-#endif
- // Invoke callback - can be used to trigger data sampling if not already running
- if (tud_audio_set_itf_cb) TU_VERIFY(tud_audio_set_itf_cb(rhport, p_request));
-
- // Schedule first transmit if alternate interface is not zero i.e. streaming is disabled - in case no sample data is available a ZLP is loaded
- // It is necessary to trigger this here since the refill is done with an RX FIFO empty interrupt which can only trigger if something was in there
- TU_VERIFY(audiod_tx_done_cb(rhport, &_audiod_fct[func_id]));
- }
-#endif // CFG_TUD_AUDIO_ENABLE_EP_IN
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_OUT) // Checking usage not necessary
- {
- // Save address
- audio->ep_out = ep_addr;
- audio->ep_out_as_intf_num = itf;
- audio->ep_out_sz = ((tusb_desc_endpoint_t const *) p_desc)->wMaxPacketSize.size;
-
-#if CFG_TUD_AUDIO_ENABLE_DECODING
- audiod_parse_for_AS_params(audio, p_desc_parse_for_params, p_desc_end, itf);
-
- // Reconfigure size of support FIFOs - this is necessary to avoid samples to get split in case of a wrap
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
- const uint16_t active_fifo_depth = (audio->rx_supp_ff_sz_max / audio->n_bytes_per_sampe_rx) * audio->n_bytes_per_sampe_rx;
- for (uint8_t cnt = 0; cnt < audio->n_rx_supp_ff; cnt++)
- {
- tu_fifo_config(&audio->rx_supp_ff[cnt], audio->rx_supp_ff[cnt].buffer, active_fifo_depth, 1, true);
- }
- audio->n_ff_used_rx = audio->n_channels_rx / audio->n_channels_per_ff_rx;
- TU_ASSERT( audio->n_ff_used_rx <= audio->n_rx_supp_ff );
-#endif
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
- // In case of asynchronous EP, call Cb after ep_fb is set
- if (!(((tusb_desc_endpoint_t const *) p_desc)->bmAttributes.sync == 0x01 && audio->ep_fb == 0))
- {
- if (tud_audio_set_itf_cb) TU_VERIFY(tud_audio_set_itf_cb(rhport, p_request));
- }
-#else
- // Invoke callback
- if (tud_audio_set_itf_cb) TU_VERIFY(tud_audio_set_itf_cb(rhport, p_request));
-#endif
- // Prepare for incoming data
-#if USE_LINEAR_BUFFER_RX
- TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_out, audio->lin_buf_out, audio->ep_out_sz), false);
-#else
- TU_VERIFY(usbd_edpt_xfer_fifo(rhport, audio->ep_out, &audio->ep_out_ff, audio->ep_out_sz), false);
-#endif
- }
-
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN && ((tusb_desc_endpoint_t const *) p_desc)->bmAttributes.usage == 1) // Check if usage is explicit data feedback
- {
- audio->ep_fb = ep_addr;
-
- // Invoke callback after ep_out is set
- if (audio->ep_out != 0)
- {
- if (tud_audio_set_itf_cb) TU_VERIFY(tud_audio_set_itf_cb(rhport, p_request));
- }
- }
-#endif
-#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT
-
- foundEPs += 1;
- }
- p_desc = tu_desc_next(p_desc);
- }
-
- TU_VERIFY(foundEPs == nEps);
-
- // We are done - abort loop
- break;
- }
-
- // Moving forward
- p_desc = tu_desc_next(p_desc);
- }
-
- tud_control_status(rhport, p_request);
-
- return true;
-}
-
-// Invoked when class request DATA stage is finished.
-// return false to stall control EP (e.g Host send non-sense DATA)
-static bool audiod_control_complete(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- // Handle audio class specific set requests
- if(p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS && p_request->bmRequestType_bit.direction == TUSB_DIR_OUT)
- {
- uint8_t func_id;
-
- switch (p_request->bmRequestType_bit.recipient)
- {
- case TUSB_REQ_RCPT_INTERFACE:
- {
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
- uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
-
- if (entityID != 0)
- {
- if (tud_audio_set_req_entity_cb)
- {
- // Check if entity is present and get corresponding driver index
- TU_VERIFY(audiod_verify_entity_exists(itf, entityID, &func_id));
-
- // Invoke callback
- return tud_audio_set_req_entity_cb(rhport, p_request, _audiod_fct[func_id].ctrl_buf);
- }
- else
- {
- TU_LOG2(" No entity set request callback available!\r\n");
- return false; // In case no callback function is present or request can not be conducted we stall it
- }
- }
- else
- {
- if (tud_audio_set_req_itf_cb)
- {
- // Find index of audio driver structure and verify interface really exists
- TU_VERIFY(audiod_verify_itf_exists(itf, &func_id));
-
- // Invoke callback
- return tud_audio_set_req_itf_cb(rhport, p_request, _audiod_fct[func_id].ctrl_buf);
- }
- else
- {
- TU_LOG2(" No interface set request callback available!\r\n");
- return false; // In case no callback function is present or request can not be conducted we stall it
- }
- }
- }
- break;
-
- case TUSB_REQ_RCPT_ENDPOINT:
- {
- uint8_t ep = TU_U16_LOW(p_request->wIndex);
-
- if (tud_audio_set_req_ep_cb)
- {
- // Check if entity is present and get corresponding driver index
- TU_VERIFY(audiod_verify_ep_exists(ep, &func_id));
-
- // Invoke callback
- return tud_audio_set_req_ep_cb(rhport, p_request, _audiod_fct[func_id].ctrl_buf);
- }
- else
- {
- TU_LOG2(" No EP set request callback available!\r\n");
- return false; // In case no callback function is present or request can not be conducted we stall it
- }
- }
- break;
- // Unknown/Unsupported recipient
- default: TU_BREAKPOINT(); return false;
- }
- }
- return true;
-}
-
-// Handle class control request
-// return false to stall control endpoint (e.g unsupported request)
-static bool audiod_control_request(uint8_t rhport, tusb_control_request_t const * p_request)
-{
- (void) rhport;
-
- // Handle standard requests - standard set requests usually have no data stage so we also handle set requests here
- if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
- {
- switch (p_request->bRequest)
- {
- case TUSB_REQ_GET_INTERFACE:
- return audiod_get_interface(rhport, p_request);
-
- case TUSB_REQ_SET_INTERFACE:
- return audiod_set_interface(rhport, p_request);
-
- // Unknown/Unsupported request
- default: TU_BREAKPOINT(); return false;
- }
- }
-
- // Handle class requests
- if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS)
- {
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
- uint8_t func_id;
-
- // Conduct checks which depend on the recipient
- switch (p_request->bmRequestType_bit.recipient)
- {
- case TUSB_REQ_RCPT_INTERFACE:
- {
- uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
-
- // Verify if entity is present
- if (entityID != 0)
- {
- // Find index of audio driver structure and verify entity really exists
- TU_VERIFY(audiod_verify_entity_exists(itf, entityID, &func_id));
-
- // In case we got a get request invoke callback - callback needs to answer as defined in UAC2 specification page 89 - 5. Requests
- if (p_request->bmRequestType_bit.direction == TUSB_DIR_IN)
- {
- if (tud_audio_get_req_entity_cb)
- {
- return tud_audio_get_req_entity_cb(rhport, p_request);
- }
- else
- {
- TU_LOG2(" No entity get request callback available!\r\n");
- return false; // Stall
- }
- }
- }
- else
- {
- // Find index of audio driver structure and verify interface really exists
- TU_VERIFY(audiod_verify_itf_exists(itf, &func_id));
-
- // In case we got a get request invoke callback - callback needs to answer as defined in UAC2 specification page 89 - 5. Requests
- if (p_request->bmRequestType_bit.direction == TUSB_DIR_IN)
- {
- if (tud_audio_get_req_itf_cb)
- {
- return tud_audio_get_req_itf_cb(rhport, p_request);
- }
- else
- {
- TU_LOG2(" No interface get request callback available!\r\n");
- return false; // Stall
- }
- }
- }
- }
- break;
-
- case TUSB_REQ_RCPT_ENDPOINT:
- {
- uint8_t ep = TU_U16_LOW(p_request->wIndex);
-
- // Find index of audio driver structure and verify EP really exists
- TU_VERIFY(audiod_verify_ep_exists(ep, &func_id));
-
- // In case we got a get request invoke callback - callback needs to answer as defined in UAC2 specification page 89 - 5. Requests
- if (p_request->bmRequestType_bit.direction == TUSB_DIR_IN)
- {
- if (tud_audio_get_req_ep_cb)
- {
- return tud_audio_get_req_ep_cb(rhport, p_request);
- }
- else
- {
- TU_LOG2(" No EP get request callback available!\r\n");
- return false; // Stall
- }
- }
- }
- break;
-
- // Unknown/Unsupported recipient
- default: TU_LOG2(" Unsupported recipient: %d\r\n", p_request->bmRequestType_bit.recipient); TU_BREAKPOINT(); return false;
- }
-
- // If we end here, the received request is a set request - we schedule a receive for the data stage and return true here. We handle the rest later in audiod_control_complete() once the data stage was finished
- TU_VERIFY(tud_control_xfer(rhport, p_request, _audiod_fct[func_id].ctrl_buf, _audiod_fct[func_id].ctrl_buf_sz));
- return true;
- }
-
- // There went something wrong - unsupported control request type
- TU_BREAKPOINT();
- return false;
-}
-
-bool audiod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- if ( stage == CONTROL_STAGE_SETUP )
- {
- return audiod_control_request(rhport, request);
- }
- else if ( stage == CONTROL_STAGE_DATA )
- {
- return audiod_control_complete(rhport, request);
- }
-
- return true;
-}
-
-bool audiod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void) result;
- (void) xferred_bytes;
-
- // Search for interface belonging to given end point address and proceed as required
- uint8_t func_id;
- for (func_id = 0; func_id < CFG_TUD_AUDIO; func_id++)
- {
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
-
- // Data transmission of control interrupt finished
- if (_audiod_fct[func_id].ep_int_ctr == ep_addr)
- {
- // According to USB2 specification, maximum payload of interrupt EP is 8 bytes on low speed, 64 bytes on full speed, and 1024 bytes on high speed (but only if an alternate interface other than 0 is used - see specification p. 49)
- // In case there is nothing to send we have to return a NAK - this is taken care of by PHY ???
- // In case of an erroneous transmission a retransmission is conducted - this is taken care of by PHY ???
-
- // I assume here, that things above are handled by PHY
- // All transmission is done - what remains to do is to inform job was completed
-
- if (tud_audio_int_ctr_done_cb) TU_VERIFY(tud_audio_int_ctr_done_cb(rhport, (uint16_t) xferred_bytes));
- }
-
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
-
- // Data transmission of audio packet finished
- if (_audiod_fct[func_id].ep_in == ep_addr && _audiod_fct[func_id].alt_setting != 0)
- {
- // USB 2.0, section 5.6.4, third paragraph, states "An isochronous endpoint must specify its required bus access period. However, an isochronous endpoint must be prepared to handle poll rates faster than the one specified."
- // That paragraph goes on to say "An isochronous IN endpoint must return a zero-length packet whenever data is requested at a faster interval than the specified interval and data is not available."
- // This can only be solved reliably if we load a ZLP after every IN transmission since we can not say if the host requests samples earlier than we declared! Once all samples are collected we overwrite the loaded ZLP.
-
- // Check if there is data to load into EPs buffer - if not load it with ZLP
- // Be aware - we as a device are not able to know if the host polls for data with a faster rate as we stated this in the descriptors. Therefore we always have to put something into the EPs buffer. However, once we did that, there is no way of aborting this or replacing what we put into the buffer before!
- // This is the only place where we can fill something into the EPs buffer!
-
- // Load new data
- TU_VERIFY(audiod_tx_done_cb(rhport, &_audiod_fct[func_id]));
-
- // Transmission of ZLP is done by audiod_tx_done_cb()
- return true;
- }
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-
- // New audio packet received
- if (_audiod_fct[func_id].ep_out == ep_addr)
- {
- TU_VERIFY(audiod_rx_done_cb(rhport, &_audiod_fct[func_id], (uint16_t) xferred_bytes));
- return true;
- }
-
-
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
- // Transmission of feedback EP finished
- if (_audiod_fct[func_id].ep_fb == ep_addr)
- {
- if (tud_audio_fb_done_cb) TU_VERIFY(tud_audio_fb_done_cb(rhport));
-
- // Schedule a transmit with the new value if EP is not busy
- if (!usbd_edpt_busy(rhport, _audiod_fct[func_id].ep_fb))
- {
- // Schedule next transmission - value is changed bytud_audio_n_fb_set() in the meantime or the old value gets sent
- return audiod_fb_send(rhport, &_audiod_fct[func_id]);
- }
- }
-#endif
-#endif
- }
-
- return false;
-}
-
-bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport, tusb_control_request_t const * p_request, void* data, uint16_t len)
-{
- // Handles only sending of data not receiving
- if (p_request->bmRequestType_bit.direction == TUSB_DIR_OUT) return false;
-
- // Get corresponding driver index
- uint8_t func_id;
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
-
- // Conduct checks which depend on the recipient
- switch (p_request->bmRequestType_bit.recipient)
- {
- case TUSB_REQ_RCPT_INTERFACE:
- {
- uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
-
- // Verify if entity is present
- if (entityID != 0)
- {
- // Find index of audio driver structure and verify entity really exists
- TU_VERIFY(audiod_verify_entity_exists(itf, entityID, &func_id));
- }
- else
- {
- // Find index of audio driver structure and verify interface really exists
- TU_VERIFY(audiod_verify_itf_exists(itf, &func_id));
- }
- }
- break;
-
- case TUSB_REQ_RCPT_ENDPOINT:
- {
- uint8_t ep = TU_U16_LOW(p_request->wIndex);
-
- // Find index of audio driver structure and verify EP really exists
- TU_VERIFY(audiod_verify_ep_exists(ep, &func_id));
- }
- break;
-
- // Unknown/Unsupported recipient
- default: TU_LOG2(" Unsupported recipient: %d\r\n", p_request->bmRequestType_bit.recipient); TU_BREAKPOINT(); return false;
- }
-
- // Crop length
- if (len > _audiod_fct[func_id].ctrl_buf_sz) len = _audiod_fct[func_id].ctrl_buf_sz;
-
- // Copy into buffer
- memcpy((void *)_audiod_fct[func_id].ctrl_buf, data, (size_t)len);
-
- // Schedule transmit
- return tud_control_xfer(rhport, p_request, (void*)_audiod_fct[func_id].ctrl_buf, len);
-}
-
-// This helper function finds for a given audio function and AS interface number the index of the attached driver structure, the index of the interface in the audio function
-// (e.g. the std. AS interface with interface number 15 is the first AS interface for the given audio function and thus gets index zero), and
-// finally a pointer to the std. AS interface, where the pointer always points to the first alternate setting i.e. alternate interface zero.
-static bool audiod_get_AS_interface_index(uint8_t itf, audiod_function_t * audio, uint8_t *idxItf, uint8_t const **pp_desc_int)
-{
- if (audio->p_desc)
- {
- // Get pointer at end
- uint8_t const *p_desc_end = audio->p_desc + audio->desc_length - TUD_AUDIO_DESC_IAD_LEN;
-
- // Advance past AC descriptors
- uint8_t const *p_desc = tu_desc_next(audio->p_desc);
- p_desc += ((audio_desc_cs_ac_interface_t const *)p_desc)->wTotalLength;
-
- uint8_t tmp = 0;
- while (p_desc < p_desc_end)
- {
- // We assume the number of alternate settings is increasing thus we return the index of alternate setting zero!
- if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE && ((tusb_desc_interface_t const * )p_desc)->bAlternateSetting == 0)
- {
- if (((tusb_desc_interface_t const * )p_desc)->bInterfaceNumber == itf)
- {
- *idxItf = tmp;
- *pp_desc_int = p_desc;
- return true;
- }
- // Increase index, bytes read, and pointer
- tmp++;
- }
- p_desc = tu_desc_next(p_desc);
- }
- }
- return false;
-}
-
-// This helper function finds for a given AS interface number the index of the attached driver structure, the index of the interface in the audio function
-// (e.g. the std. AS interface with interface number 15 is the first AS interface for the given audio function and thus gets index zero), and
-// finally a pointer to the std. AS interface, where the pointer always points to the first alternate setting i.e. alternate interface zero.
-static bool audiod_get_AS_interface_index_global(uint8_t itf, uint8_t *func_id, uint8_t *idxItf, uint8_t const **pp_desc_int)
-{
- // Loop over audio driver interfaces
- uint8_t i;
- for (i = 0; i < CFG_TUD_AUDIO; i++)
- {
- if (audiod_get_AS_interface_index(itf, &_audiod_fct[i], idxItf, pp_desc_int))
- {
- *func_id = i;
- return true;
- }
- }
-
- return false;
-}
-
-// Verify an entity with the given ID exists and returns also the corresponding driver index
-static bool audiod_verify_entity_exists(uint8_t itf, uint8_t entityID, uint8_t *func_id)
-{
- uint8_t i;
- for (i = 0; i < CFG_TUD_AUDIO; i++)
- {
- // Look for the correct driver by checking if the unique standard AC interface number fits
- if (_audiod_fct[i].p_desc && ((tusb_desc_interface_t const *)_audiod_fct[i].p_desc)->bInterfaceNumber == itf)
- {
- // Get pointers after class specific AC descriptors and end of AC descriptors - entities are defined in between
- uint8_t const *p_desc = tu_desc_next(_audiod_fct[i].p_desc); // Points to CS AC descriptor
- uint8_t const *p_desc_end = ((audio_desc_cs_ac_interface_t const *)p_desc)->wTotalLength + p_desc;
- p_desc = tu_desc_next(p_desc); // Get past CS AC descriptor
-
- while (p_desc < p_desc_end)
- {
- if (p_desc[3] == entityID) // Entity IDs are always at offset 3
- {
- *func_id = i;
- return true;
- }
- p_desc = tu_desc_next(p_desc);
- }
- }
- }
- return false;
-}
-
-static bool audiod_verify_itf_exists(uint8_t itf, uint8_t *func_id)
-{
- uint8_t i;
- for (i = 0; i < CFG_TUD_AUDIO; i++)
- {
- if (_audiod_fct[i].p_desc)
- {
- // Get pointer at beginning and end
- uint8_t const *p_desc = _audiod_fct[i].p_desc;
- uint8_t const *p_desc_end = _audiod_fct[i].p_desc + _audiod_fct[i].desc_length - TUD_AUDIO_DESC_IAD_LEN;
-
- while (p_desc < p_desc_end)
- {
- if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE && ((tusb_desc_interface_t const *)_audiod_fct[i].p_desc)->bInterfaceNumber == itf)
- {
- *func_id = i;
- return true;
- }
- p_desc = tu_desc_next(p_desc);
- }
- }
- }
- return false;
-}
-
-static bool audiod_verify_ep_exists(uint8_t ep, uint8_t *func_id)
-{
- uint8_t i;
- for (i = 0; i < CFG_TUD_AUDIO; i++)
- {
- if (_audiod_fct[i].p_desc)
- {
- // Get pointer at end
- uint8_t const *p_desc_end = _audiod_fct[i].p_desc + _audiod_fct[i].desc_length;
-
- // Advance past AC descriptors - EP we look for are streaming EPs
- uint8_t const *p_desc = tu_desc_next(_audiod_fct[i].p_desc);
- p_desc += ((audio_desc_cs_ac_interface_t const *)p_desc)->wTotalLength;
-
- while (p_desc < p_desc_end)
- {
- if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT && ((tusb_desc_endpoint_t const * )p_desc)->bEndpointAddress == ep)
- {
- *func_id = i;
- return true;
- }
- p_desc = tu_desc_next(p_desc);
- }
- }
- }
- return false;
-}
-
-#if CFG_TUD_AUDIO_ENABLE_ENCODING || CFG_TUD_AUDIO_ENABLE_DECODING
-// p_desc points to the AS interface of alternate setting zero
-// itf is the interface number of the corresponding interface - we check if the interface belongs to EP in or EP out to see if it is a TX or RX parameter
-// Currently, only AS interfaces with an EP (in or out) are supposed to be parsed for!
-static void audiod_parse_for_AS_params(audiod_function_t* audio, uint8_t const * p_desc, uint8_t const * p_desc_end, uint8_t const as_itf)
-{
- p_desc = tu_desc_next(p_desc); // Exclude standard AS interface descriptor of current alternate interface descriptor
-
- while (p_desc < p_desc_end)
- {
- // Abort if follow up descriptor is a new standard interface descriptor - indicates the last AS descriptor was already finished
- if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE) break;
-
- // Look for a Class-Specific AS Interface Descriptor(4.9.2) to verify format type and format and also to get number of physical channels
- if (tu_desc_type(p_desc) == TUSB_DESC_CS_INTERFACE && tu_desc_subtype(p_desc) == AUDIO_CS_AS_INTERFACE_AS_GENERAL)
- {
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf != audio->ep_in_as_intf_num && as_itf != audio->ep_out_as_intf_num) break; // Abort loop, this interface has no EP, this driver does not support this currently
-#endif
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf != audio->ep_in_as_intf_num) break;
-#endif
-#if !CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf != audio->ep_out_as_intf_num) break;
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
- if (as_itf == audio->ep_in_as_intf_num)
- {
- audio->n_channels_tx = ((audio_desc_cs_as_interface_t const * )p_desc)->bNrChannels;
- audio->format_type_tx = (audio_format_type_t)(((audio_desc_cs_as_interface_t const * )p_desc)->bFormatType);
-
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
- audio->format_type_I_tx = (audio_data_format_type_I_t)(((audio_desc_cs_as_interface_t const * )p_desc)->bmFormats);
-#endif
- }
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf == audio->ep_out_as_intf_num)
- {
- audio->n_channels_rx = ((audio_desc_cs_as_interface_t const * )p_desc)->bNrChannels;
- audio->format_type_rx = ((audio_desc_cs_as_interface_t const * )p_desc)->bFormatType;
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
- audio->format_type_I_rx = ((audio_desc_cs_as_interface_t const * )p_desc)->bmFormats;
-#endif
- }
-#endif
- }
-
- // Look for a Type I Format Type Descriptor(2.3.1.6 - Audio Formats)
-#if CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING || CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
- if (tu_desc_type(p_desc) == TUSB_DESC_CS_INTERFACE && tu_desc_subtype(p_desc) == AUDIO_CS_AS_INTERFACE_FORMAT_TYPE && ((audio_desc_type_I_format_t const * )p_desc)->bFormatType == AUDIO_FORMAT_TYPE_I)
- {
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf != audio->ep_in_as_intf_num && as_itf != audio->ep_out_as_intf_num) break; // Abort loop, this interface has no EP, this driver does not support this currently
-#endif
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf != audio->ep_in_as_intf_num) break;
-#endif
-#if !CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf != audio->ep_out_as_intf_num) break;
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
- if (as_itf == audio->ep_in_as_intf_num)
- {
- audio->n_bytes_per_sampe_tx = ((audio_desc_type_I_format_t const * )p_desc)->bSubslotSize;
- }
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
- if (as_itf == audio->ep_out_as_intf_num)
- {
- audio->n_bytes_per_sampe_rx = ((audio_desc_type_I_format_t const * )p_desc)->bSubslotSize;
- }
-#endif
- }
-#endif
-
- // Other format types are not supported yet
-
- p_desc = tu_desc_next(p_desc);
- }
-}
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
-
-// Input value feedback has to be in 16.16 format - the format will be converted according to speed settings automatically
-bool tud_audio_n_fb_set(uint8_t func_id, uint32_t feedback)
-{
- TU_VERIFY(func_id < CFG_TUD_AUDIO && _audiod_fct[func_id].p_desc != NULL);
-
- // Format the feedback value
-#if !TUD_OPT_HIGH_SPEED
- uint8_t * fb = (uint8_t *) &_audiod_fct[func_id].fb_val;
-
- // For FS format is 10.14
- *(fb++) = (feedback >> 2) & 0xFF;
- *(fb++) = (feedback >> 10) & 0xFF;
- *(fb++) = (feedback >> 18) & 0xFF;
- // 4th byte is needed to work correctly with MS Windows
- *fb = 0;
-#else
- // For HS format is 16.16 as originally demanded
- _audiod_fct[func_id].fb_val = feedback;
-#endif
-
- // Schedule a transmit with the new value if EP is not busy - this triggers repetitive scheduling of the feedback value
- if (!usbd_edpt_busy(_audiod_fct[func_id].rhport, _audiod_fct[func_id].ep_fb))
- {
- return audiod_fb_send(_audiod_fct[func_id].rhport, &_audiod_fct[func_id]);
- }
-
- return true;
-}
-#endif
-
-// No security checks here - internal function only which should always succeed
-uint8_t audiod_get_audio_fct_idx(audiod_function_t * audio)
-{
- for (uint8_t cnt=0; cnt < CFG_TUD_AUDIO; cnt++)
- {
- if (&_audiod_fct[cnt] == audio) return cnt;
- }
- return 0;
-}
-
-#endif //TUSB_OPT_DEVICE_ENABLED && CFG_TUD_AUDIO
diff --git a/tinyusb/src/class/audio/audio_device.h b/tinyusb/src/class/audio/audio_device.h
deleted file mode 100755
index 5a469523..00000000
--- a/tinyusb/src/class/audio/audio_device.h
+++ /dev/null
@@ -1,627 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Ha Thach (tinyusb.org)
- * Copyright (c) 2020 Reinhard Panhuber
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_AUDIO_DEVICE_H_
-#define _TUSB_AUDIO_DEVICE_H_
-
-#include "audio.h"
-
-//--------------------------------------------------------------------+
-// Class Driver Configuration
-//--------------------------------------------------------------------+
-
-// All sizes are in bytes!
-
-#ifndef CFG_TUD_AUDIO_FUNC_1_DESC_LEN
-#error You must tell the driver the length of the audio function descriptor including IAD descriptor
-#endif
-#if CFG_TUD_AUDIO > 1
-#ifndef CFG_TUD_AUDIO_FUNC_2_DESC_LEN
-#error You must tell the driver the length of the audio function descriptor including IAD descriptor
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2
-#ifndef CFG_TUD_AUDIO_FUNC_3_DESC_LEN
-#error You must tell the driver the length of the audio function descriptor including IAD descriptor
-#endif
-#endif
-
-// Number of Standard AS Interface Descriptors (4.9.1) defined per audio function - this is required to be able to remember the current alternate settings of these interfaces
-#ifndef CFG_TUD_AUDIO_FUNC_1_N_AS_INT
-#error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
-#endif
-#if CFG_TUD_AUDIO > 1
-#ifndef CFG_TUD_AUDIO_FUNC_2_N_AS_INT
-#error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2
-#ifndef CFG_TUD_AUDIO_FUNC_3_N_AS_INT
-#error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
-#endif
-#endif
-
-// Size of control buffer used to receive and send control messages via EP0 - has to be big enough to hold your biggest request structure e.g. range requests with multiple intervals defined or cluster descriptors
-#ifndef CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ
-#error You must define an audio class control request buffer size!
-#endif
-
-#if CFG_TUD_AUDIO > 1
-#ifndef CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ
-#error You must define an audio class control request buffer size!
-#endif
-#endif
-
-#if CFG_TUD_AUDIO > 2
-#ifndef CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ
-#error You must define an audio class control request buffer size!
-#endif
-#endif
-
-// End point sizes IN BYTES - Limits: Full Speed <= 1023, High Speed <= 1024
-#ifndef CFG_TUD_AUDIO_ENABLE_EP_IN
-#define CFG_TUD_AUDIO_ENABLE_EP_IN 0 // TX
-#endif
-
-#ifndef CFG_TUD_AUDIO_ENABLE_EP_OUT
-#define CFG_TUD_AUDIO_ENABLE_EP_OUT 0 // RX
-#endif
-
-// Maximum EP sizes for all alternate AS interface settings - used for checks and buffer allocation
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
-#ifndef CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX
-#error You must tell the driver the biggest EP IN size!
-#endif
-#if CFG_TUD_AUDIO > 1
-#ifndef CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX
-#error You must tell the driver the biggest EP IN size!
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2
-#ifndef CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX
-#error You must tell the driver the biggest EP IN size!
-#endif
-#endif
-#endif // CFG_TUD_AUDIO_ENABLE_EP_IN
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-#ifndef CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX
-#error You must tell the driver the biggest EP OUT size!
-#endif
-#if CFG_TUD_AUDIO > 1
-#ifndef CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX
-#error You must tell the driver the biggest EP OUT size!
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2
-#ifndef CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX
-#error You must tell the driver the biggest EP OUT size!
-#endif
-#endif
-#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT
-
-// Software EP FIFO buffer sizes - must be >= max EP SIZEs!
-#ifndef CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ
-#define CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ
-#define CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ 0
-#endif
-
-#ifndef CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ
-#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ
-#define CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ
-#define CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ 0
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
-#if CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX
-#error EP software buffer size MUST BE at least as big as maximum EP size
-#endif
-
-#if CFG_TUD_AUDIO > 1
-#if CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX
-#error EP software buffer size MUST BE at least as big as maximum EP size
-#endif
-#endif
-
-#if CFG_TUD_AUDIO > 2
-#if CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX
-#error EP software buffer size MUST BE at least as big as maximum EP size
-#endif
-#endif
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-#if CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX
-#error EP software buffer size MUST BE at least as big as maximum EP size
-#endif
-
-#if CFG_TUD_AUDIO > 1
-#if CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX
-#error EP software buffer size MUST BE at least as big as maximum EP size
-#endif
-#endif
-
-#if CFG_TUD_AUDIO > 2
-#if CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX
-#error EP software buffer size MUST BE at least as big as maximum EP size
-#endif
-#endif
-#endif
-
-// Enable/disable feedback EP (required for asynchronous RX applications)
-#ifndef CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
-#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP 0 // Feedback - 0 or 1
-#endif
-
-// Audio interrupt control EP size - disabled if 0
-#ifndef CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
-#define CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN 0 // Audio interrupt control - if required - 6 Bytes according to UAC 2 specification (p. 74)
-#endif
-
-#ifndef CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE
-#define CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE 6 // Buffer size of audio control interrupt EP - 6 Bytes according to UAC 2 specification (p. 74)
-#endif
-
-// Use software encoding/decoding
-
-// The software coding feature of the driver is not mandatory. It is useful if, for instance, you have two I2S streams which need to be interleaved
-// into a single PCM stream as SAMPLE_1 | SAMPLE_2 | SAMPLE_3 | SAMPLE_4.
-//
-// Currently, only PCM type I encoding/decoding is supported!
-//
-// If the coding feature is to be used, support FIFOs need to be configured. Their sizes and numbers are defined below.
-
-// Encoding/decoding is done in software and thus time consuming. If you can encode/decode your stream more efficiently do not use the
-// support FIFOs but write/read directly into/from the EP_X_SW_BUFFER_FIFOs using
-// - tud_audio_n_write() or
-// - tud_audio_n_read().
-// To write/read to/from the support FIFOs use
-// - tud_audio_n_write_support_ff() or
-// - tud_audio_n_read_support_ff().
-//
-// The encoding/decoding format type done is defined below.
-//
-// The encoding/decoding starts when the private callback functions
-// - audio_tx_done_cb()
-// - audio_rx_done_cb()
-// are invoked. If support FIFOs are used, the corresponding encoding/decoding functions are called from there.
-// Once encoding/decoding is done the result is put directly into the EP_X_SW_BUFFER_FIFOs. You can use the public callback functions
-// - tud_audio_tx_done_pre_load_cb() or tud_audio_tx_done_post_load_cb()
-// - tud_audio_rx_done_pre_read_cb() or tud_audio_rx_done_post_read_cb()
-// if you want to get informed what happened.
-//
-// If you don't use the support FIFOs you may use the public callback functions
-// - tud_audio_tx_done_pre_load_cb() or tud_audio_tx_done_post_load_cb()
-// - tud_audio_rx_done_pre_read_cb() or tud_audio_rx_done_post_read_cb()
-// to write/read from/into the EP_X_SW_BUFFER_FIFOs at the right time.
-//
-// If you need a different encoding which is not support so far implement it in the
-// - audio_tx_done_cb()
-// - audio_rx_done_cb()
-// functions.
-
-// Enable encoding/decodings - for these to work, support FIFOs need to be setup in appropriate numbers and size
-// The actual coding parameters of active AS alternate interface is parsed from the descriptors
-
-// The item size of the FIFO is always fixed to one i.e. bytes! Furthermore, the actively used FIFO depth is reconfigured such that the depth is a multiple of the current sample size in order to avoid samples to get split up in case of a wrap in the FIFO ring buffer (depth = (max_depth / sampe_sz) * sampe_sz)!
-// This is important to remind in case you use DMAs! If the sample sizes changes, the DMA MUST BE RECONFIGURED just like the FIFOs for a different depth!!!
-
-// For PCM encoding/decoding
-
-#ifndef CFG_TUD_AUDIO_ENABLE_ENCODING
-#define CFG_TUD_AUDIO_ENABLE_ENCODING 0
-#endif
-
-#ifndef CFG_TUD_AUDIO_ENABLE_DECODING
-#define CFG_TUD_AUDIO_ENABLE_DECODING 0
-#endif
-
-// This enabling allows to save the current coding parameters e.g. # of bytes per sample etc. - TYPE_I includes common PCM encoding
-#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
-#define CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING 0
-#endif
-
-#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
-#define CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING 0
-#endif
-
-// Type I Coding parameters not given within UAC2 descriptors
-// It would be possible to allow for a more flexible setting and not fix this parameter as done below. However, this is most often not needed and kept for later if really necessary. The more flexible setting could be implemented within set_interface(), however, how the values are saved per alternate setting is to be determined!
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
-#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX
-#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
-#endif
-#if CFG_TUD_AUDIO > 1
-#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_TX
-#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2
-#ifndef CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_TX
-#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
-#endif
-#endif
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
-#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_RX
-#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
-#endif
-#if CFG_TUD_AUDIO > 1
-#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_RX
-#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
-#endif
-#endif
-#if CFG_TUD_AUDIO > 2
-#ifndef CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_RX
-#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
-#endif
-#endif
-#endif
-
-// Remaining types not support so far
-
-// Number of support FIFOs to set up - multiple channels can be handled by one FIFO - very common is two channels per FIFO stemming from one I2S interface
-#ifndef CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO
-#define CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO
-#define CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO
-#define CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO 0
-#endif
-
-#ifndef CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO
-#define CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO
-#define CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO
-#define CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO 0
-#endif
-
-// Size of support FIFOs IN BYTES - if size > 0 there are as many FIFOs set up as CFG_TUD_AUDIO_FUNC_X_N_TX_SUPP_SW_FIFO and CFG_TUD_AUDIO_FUNC_X_N_RX_SUPP_SW_FIFO
-#ifndef CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ
-#define CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ 0 // FIFO size - minimum size: ceil(f_s/1000) * max(# of TX channels) / (# of TX support FIFOs) * max(# of bytes per sample)
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ
-#define CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ
-#define CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ 0
-#endif
-
-#ifndef CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ
-#define CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ 0 // FIFO size - minimum size: ceil(f_s/1000) * max(# of RX channels) / (# of RX support FIFOs) * max(# of bytes per sample)
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ
-#define CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ 0
-#endif
-#ifndef CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ
-#define CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ 0
-#endif
-
-//static_assert(sizeof(tud_audio_desc_lengths) != CFG_TUD_AUDIO, "Supply audio function descriptor pack length!");
-
-// Supported types of this driver:
-// AUDIO_DATA_FORMAT_TYPE_I_PCM - Required definitions: CFG_TUD_AUDIO_N_CHANNELS and CFG_TUD_AUDIO_BYTES_PER_CHANNEL
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/** \addtogroup AUDIO_Serial Serial
- * @{
- * \defgroup AUDIO_Serial_Device Device
- * @{ */
-
-//--------------------------------------------------------------------+
-// Application API (Multiple Interfaces)
-// CFG_TUD_AUDIO > 1
-//--------------------------------------------------------------------+
-bool tud_audio_n_mounted (uint8_t func_id);
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-uint16_t tud_audio_n_available (uint8_t func_id);
-uint16_t tud_audio_n_read (uint8_t func_id, void* buffer, uint16_t bufsize);
-bool tud_audio_n_clear_ep_out_ff (uint8_t func_id); // Delete all content in the EP OUT FIFO
-tu_fifo_t* tud_audio_n_get_ep_out_ff (uint8_t func_id);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
-bool tud_audio_n_clear_rx_support_ff (uint8_t func_id, uint8_t ff_idx); // Delete all content in the support RX FIFOs
-uint16_t tud_audio_n_available_support_ff (uint8_t func_id, uint8_t ff_idx);
-uint16_t tud_audio_n_read_support_ff (uint8_t func_id, uint8_t ff_idx, void* buffer, uint16_t bufsize);
-tu_fifo_t* tud_audio_n_get_rx_support_ff (uint8_t func_id, uint8_t ff_idx);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-uint16_t tud_audio_n_write (uint8_t func_id, const void * data, uint16_t len);
-bool tud_audio_n_clear_ep_in_ff (uint8_t func_id); // Delete all content in the EP IN FIFO
-tu_fifo_t* tud_audio_n_get_ep_in_ff (uint8_t func_id);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
-uint16_t tud_audio_n_flush_tx_support_ff (uint8_t func_id); // Force all content in the support TX FIFOs to be written into EP SW FIFO
-bool tud_audio_n_clear_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
-uint16_t tud_audio_n_write_support_ff (uint8_t func_id, uint8_t ff_idx, const void * data, uint16_t len);
-tu_fifo_t* tud_audio_n_get_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
-#endif
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
-uint16_t tud_audio_int_ctr_n_write (uint8_t func_id, uint8_t const* buffer, uint16_t len);
-#endif
-
-//--------------------------------------------------------------------+
-// Application API (Interface0)
-//--------------------------------------------------------------------+
-
-static inline bool tud_audio_mounted (void);
-
-// RX API
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-static inline uint16_t tud_audio_available (void);
-static inline bool tud_audio_clear_ep_out_ff (void); // Delete all content in the EP OUT FIFO
-static inline uint16_t tud_audio_read (void* buffer, uint16_t bufsize);
-static inline tu_fifo_t* tud_audio_get_ep_out_ff (void);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
-static inline bool tud_audio_clear_rx_support_ff (uint8_t ff_idx);
-static inline uint16_t tud_audio_available_support_ff (uint8_t ff_idx);
-static inline uint16_t tud_audio_read_support_ff (uint8_t ff_idx, void* buffer, uint16_t bufsize);
-static inline tu_fifo_t* tud_audio_get_rx_support_ff (uint8_t ff_idx);
-#endif
-
-// TX API
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-static inline uint16_t tud_audio_write (const void * data, uint16_t len);
-static inline bool tud_audio_clear_ep_in_ff (void);
-static inline tu_fifo_t* tud_audio_get_ep_in_ff (void);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
-static inline uint16_t tud_audio_flush_tx_support_ff (void);
-static inline uint16_t tud_audio_clear_tx_support_ff (uint8_t ff_idx);
-static inline uint16_t tud_audio_write_support_ff (uint8_t ff_idx, const void * data, uint16_t len);
-static inline tu_fifo_t* tud_audio_get_tx_support_ff (uint8_t ff_idx);
-#endif
-
-// INT CTR API
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
-static inline uint16_t tud_audio_int_ctr_write (uint8_t const* buffer, uint16_t len);
-#endif
-
-// Buffer control EP data and schedule a transmit
-// This function is intended to be used if you do not have a persistent buffer or memory location available (e.g. non-local variables) and need to answer onto a
-// get request. This function buffers your answer request frame into the control buffer of the corresponding audio driver and schedules a transmit for sending it.
-// Since transmission is triggered via interrupts, a persistent memory location is required onto which the buffer pointer in pointing. If you already have such
-// available you may directly use 'tud_control_xfer(...)'. In this case data does not need to be copied into an additional buffer and you save some time.
-// If the request's wLength is zero, a status packet is sent instead.
-bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport, tusb_control_request_t const * p_request, void* data, uint16_t len);
-
-//--------------------------------------------------------------------+
-// Application Callback API (weak is optional)
-//--------------------------------------------------------------------+
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN
-TU_ATTR_WEAK bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t func_id, uint8_t ep_in, uint8_t cur_alt_setting);
-TU_ATTR_WEAK bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uint8_t func_id, uint8_t ep_in, uint8_t cur_alt_setting);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT
-TU_ATTR_WEAK bool tud_audio_rx_done_pre_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting);
-TU_ATTR_WEAK bool tud_audio_rx_done_post_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting);
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
-TU_ATTR_WEAK bool tud_audio_fb_done_cb(uint8_t rhport);
-// User code should call this function with feedback value in 16.16 format for FS and HS.
-// Value will be corrected for FS to 10.14 format automatically.
-// (see Universal Serial Bus Specification Revision 2.0 5.12.4.2).
-// Feedback value will be sent at FB endpoint interval till it's changed.
-bool tud_audio_n_fb_set(uint8_t func_id, uint32_t feedback);
-static inline bool tud_audio_fb_set(uint32_t feedback);
-#endif
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
-TU_ATTR_WEAK bool tud_audio_int_ctr_done_cb(uint8_t rhport, uint16_t n_bytes_copied);
-#endif
-
-// Invoked when audio set interface request received
-TU_ATTR_WEAK bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request);
-
-// Invoked when audio set interface request received which closes an EP
-TU_ATTR_WEAK bool tud_audio_set_itf_close_EP_cb(uint8_t rhport, tusb_control_request_t const * p_request);
-
-// Invoked when audio class specific set request received for an EP
-TU_ATTR_WEAK bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff);
-
-// Invoked when audio class specific set request received for an interface
-TU_ATTR_WEAK bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff);
-
-// Invoked when audio class specific set request received for an entity
-TU_ATTR_WEAK bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff);
-
-// Invoked when audio class specific get request received for an EP
-TU_ATTR_WEAK bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request);
-
-// Invoked when audio class specific get request received for an interface
-TU_ATTR_WEAK bool tud_audio_get_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request);
-
-// Invoked when audio class specific get request received for an entity
-TU_ATTR_WEAK bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request);
-
-//--------------------------------------------------------------------+
-// Inline Functions
-//--------------------------------------------------------------------+
-
-static inline bool tud_audio_mounted(void)
-{
- return tud_audio_n_mounted(0);
-}
-
-// RX API
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
-
-static inline uint16_t tud_audio_available(void)
-{
- return tud_audio_n_available(0);
-}
-
-static inline uint16_t tud_audio_read(void* buffer, uint16_t bufsize)
-{
- return tud_audio_n_read(0, buffer, bufsize);
-}
-
-static inline bool tud_audio_clear_ep_out_ff(void)
-{
- return tud_audio_n_clear_ep_out_ff(0);
-}
-
-static inline tu_fifo_t* tud_audio_get_ep_out_ff(void)
-{
- return tud_audio_n_get_ep_out_ff(0);
-}
-
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
-
-static inline bool tud_audio_clear_rx_support_ff(uint8_t ff_idx)
-{
- return tud_audio_n_clear_rx_support_ff(0, ff_idx);
-}
-
-static inline uint16_t tud_audio_available_support_ff(uint8_t ff_idx)
-{
- return tud_audio_n_available_support_ff(0, ff_idx);
-}
-
-static inline uint16_t tud_audio_read_support_ff(uint8_t ff_idx, void* buffer, uint16_t bufsize)
-{
- return tud_audio_n_read_support_ff(0, ff_idx, buffer, bufsize);
-}
-
-static inline tu_fifo_t* tud_audio_get_rx_support_ff(uint8_t ff_idx)
-{
- return tud_audio_n_get_rx_support_ff(0, ff_idx);
-}
-
-#endif
-
-// TX API
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
-
-static inline uint16_t tud_audio_write(const void * data, uint16_t len)
-{
- return tud_audio_n_write(0, data, len);
-}
-
-static inline bool tud_audio_clear_ep_in_ff(void)
-{
- return tud_audio_n_clear_ep_in_ff(0);
-}
-
-static inline tu_fifo_t* tud_audio_get_ep_in_ff(void)
-{
- return tud_audio_n_get_ep_in_ff(0);
-}
-
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
-
-static inline uint16_t tud_audio_flush_tx_support_ff(void)
-{
- return tud_audio_n_flush_tx_support_ff(0);
-}
-
-static inline uint16_t tud_audio_clear_tx_support_ff(uint8_t ff_idx)
-{
- return tud_audio_n_clear_tx_support_ff(0, ff_idx);
-}
-
-static inline uint16_t tud_audio_write_support_ff(uint8_t ff_idx, const void * data, uint16_t len)
-{
- return tud_audio_n_write_support_ff(0, ff_idx, data, len);
-}
-
-static inline tu_fifo_t* tud_audio_get_tx_support_ff(uint8_t ff_idx)
-{
- return tud_audio_n_get_tx_support_ff(0, ff_idx);
-}
-
-#endif
-
-#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
-static inline uint16_t tud_audio_int_ctr_write(uint8_t const* buffer, uint16_t len)
-{
- return tud_audio_int_ctr_n_write(0, buffer, len);
-}
-#endif
-
-#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
-static inline bool tud_audio_fb_set(uint32_t feedback)
-{
- return tud_audio_n_fb_set(0, feedback);
-}
-#endif
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void audiod_init (void);
-void audiod_reset (uint8_t rhport);
-uint16_t audiod_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool audiod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-bool audiod_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _TUSB_AUDIO_DEVICE_H_ */
-
-/** @} */
-/** @} */
diff --git a/tinyusb/src/class/bth/bth_device.c b/tinyusb/src/class/bth/bth_device.c
deleted file mode 100755
index 1d27ae7c..00000000
--- a/tinyusb/src/class/bth/bth_device.c
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jerzy Kasenberg
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_BTH)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "bth_device.h"
-#include <device/usbd_pvt.h>
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-typedef struct
-{
- uint8_t itf_num;
- uint8_t ep_ev;
- uint8_t ep_acl_in;
- uint8_t ep_acl_out;
- uint8_t ep_voice[2]; // Not used yet
- uint8_t ep_voice_size[2][CFG_TUD_BTH_ISO_ALT_COUNT];
-
- // Endpoint Transfer buffer
- CFG_TUSB_MEM_ALIGN bt_hci_cmd_t hci_cmd;
- CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_BTH_DATA_EPSIZE];
-
-} btd_interface_t;
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION btd_interface_t _btd_itf;
-
-static bool bt_tx_data(uint8_t ep, void *data, uint16_t len)
-{
- // skip if previous transfer not complete
- TU_VERIFY(!usbd_edpt_busy(TUD_OPT_RHPORT, ep));
-
- TU_ASSERT(usbd_edpt_xfer(TUD_OPT_RHPORT, ep, data, len));
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// READ API
-//--------------------------------------------------------------------+
-
-
-//--------------------------------------------------------------------+
-// WRITE API
-//--------------------------------------------------------------------+
-
-bool tud_bt_event_send(void *event, uint16_t event_len)
-{
- return bt_tx_data(_btd_itf.ep_ev, event, event_len);
-}
-
-bool tud_bt_acl_data_send(void *event, uint16_t event_len)
-{
- return bt_tx_data(_btd_itf.ep_acl_in, event, event_len);
-}
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void btd_init(void)
-{
- tu_memclr(&_btd_itf, sizeof(_btd_itf));
-}
-
-void btd_reset(uint8_t rhport)
-{
- (void)rhport;
-}
-
-uint16_t btd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
-{
- tusb_desc_endpoint_t const *desc_ep;
- uint16_t drv_len = 0;
- // Size of single alternative of ISO interface
- const uint16_t iso_alt_itf_size = sizeof(tusb_desc_interface_t) + 2 * sizeof(tusb_desc_endpoint_t);
- // Size of hci interface
- const uint16_t hci_itf_size = sizeof(tusb_desc_interface_t) + 3 * sizeof(tusb_desc_endpoint_t);
- // Ensure this is BT Primary Controller
- TU_VERIFY(TUSB_CLASS_WIRELESS_CONTROLLER == itf_desc->bInterfaceClass &&
- TUD_BT_APP_SUBCLASS == itf_desc->bInterfaceSubClass &&
- TUD_BT_PROTOCOL_PRIMARY_CONTROLLER == itf_desc->bInterfaceProtocol, 0);
-
- // Distinguish interface by number of endpoints, as both interface have same class, subclass and protocol
- if (itf_desc->bNumEndpoints == 3 && max_len >= hci_itf_size)
- {
- _btd_itf.itf_num = itf_desc->bInterfaceNumber;
-
- desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
-
- TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
- TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
- _btd_itf.ep_ev = desc_ep->bEndpointAddress;
-
- // Open endpoint pair
- TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(desc_ep), 2, TUSB_XFER_BULK, &_btd_itf.ep_acl_out,
- &_btd_itf.ep_acl_in), 0);
-
- // Prepare for incoming data from host
- TU_ASSERT(usbd_edpt_xfer(rhport, _btd_itf.ep_acl_out, _btd_itf.epout_buf, CFG_TUD_BTH_DATA_EPSIZE), 0);
-
- drv_len = hci_itf_size;
- }
- else if (itf_desc->bNumEndpoints == 2 && max_len >= iso_alt_itf_size)
- {
- uint8_t dir;
-
- desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(itf_desc);
- TU_ASSERT(itf_desc->bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT, 0);
- TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT, 0);
- dir = tu_edpt_dir(desc_ep->bEndpointAddress);
- _btd_itf.ep_voice[dir] = desc_ep->bEndpointAddress;
- // Store endpoint size for alternative
- _btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t)desc_ep->wMaxPacketSize.size;
-
- desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(desc_ep);
- TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT, 0);
- dir = tu_edpt_dir(desc_ep->bEndpointAddress);
- _btd_itf.ep_voice[dir] = desc_ep->bEndpointAddress;
- // Store endpoint size for alternative
- _btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t)desc_ep->wMaxPacketSize.size;
- drv_len += iso_alt_itf_size;
-
- for (int i = 1; i < CFG_TUD_BTH_ISO_ALT_COUNT && drv_len + iso_alt_itf_size <= max_len; ++i) {
- // Make sure rest of alternatives matches
- itf_desc = (tusb_desc_interface_t const *)tu_desc_next(desc_ep);
- if (itf_desc->bDescriptorType != TUSB_DESC_INTERFACE ||
- TUSB_CLASS_WIRELESS_CONTROLLER != itf_desc->bInterfaceClass ||
- TUD_BT_APP_SUBCLASS != itf_desc->bInterfaceSubClass ||
- TUD_BT_PROTOCOL_PRIMARY_CONTROLLER != itf_desc->bInterfaceProtocol)
- {
- // Not an Iso interface instance
- break;
- }
- TU_ASSERT(itf_desc->bAlternateSetting < CFG_TUD_BTH_ISO_ALT_COUNT, 0);
-
- desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(itf_desc);
- dir = tu_edpt_dir(desc_ep->bEndpointAddress);
- // Verify that alternative endpoint are same as first ones
- TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT &&
- _btd_itf.ep_voice[dir] == desc_ep->bEndpointAddress, 0);
- _btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t)desc_ep->wMaxPacketSize.size;
-
- desc_ep = (tusb_desc_endpoint_t const *)tu_desc_next(desc_ep);
- dir = tu_edpt_dir(desc_ep->bEndpointAddress);
- // Verify that alternative endpoint are same as first ones
- TU_ASSERT(desc_ep->bDescriptorType == TUSB_DESC_ENDPOINT &&
- _btd_itf.ep_voice[dir] == desc_ep->bEndpointAddress, 0);
- _btd_itf.ep_voice_size[dir][itf_desc->bAlternateSetting] = (uint8_t)desc_ep->wMaxPacketSize.size;
- drv_len += iso_alt_itf_size;
- }
- }
-
- return drv_len;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool btd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
-{
- (void)rhport;
-
- if ( stage == CONTROL_STAGE_SETUP )
- {
- if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
- request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_DEVICE)
- {
- // HCI command packet addressing for single function Primary Controllers
- TU_VERIFY(request->bRequest == 0 && request->wValue == 0 && request->wIndex == 0);
- }
- else if (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE)
- {
- if (request->bRequest == TUSB_REQ_SET_INTERFACE && _btd_itf.itf_num + 1 == request->wIndex)
- {
- // TODO: Set interface it would involve changing size of endpoint size
- }
- else
- {
- // HCI command packet for Primary Controller function in a composite device
- TU_VERIFY(request->bRequest == 0 && request->wValue == 0 && request->wIndex == _btd_itf.itf_num);
- }
- }
- else return false;
-
- return tud_control_xfer(rhport, request, &_btd_itf.hci_cmd, request->wLength);
- }
- else if ( stage == CONTROL_STAGE_DATA )
- {
- // Handle class request only
- TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
-
- if (tud_bt_hci_cmd_cb) tud_bt_hci_cmd_cb(&_btd_itf.hci_cmd, request->wLength);
- }
-
- return true;
-}
-
-bool btd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void)result;
-
- // received new data from host
- if (ep_addr == _btd_itf.ep_acl_out)
- {
- if (tud_bt_acl_data_received_cb) tud_bt_acl_data_received_cb(_btd_itf.epout_buf, xferred_bytes);
-
- // prepare for next data
- TU_ASSERT(usbd_edpt_xfer(rhport, _btd_itf.ep_acl_out, _btd_itf.epout_buf, CFG_TUD_BTH_DATA_EPSIZE));
- }
- else if (ep_addr == _btd_itf.ep_ev)
- {
- if (tud_bt_event_sent_cb) tud_bt_event_sent_cb((uint16_t)xferred_bytes);
- }
- else if (ep_addr == _btd_itf.ep_acl_in)
- {
- if (tud_bt_acl_data_sent_cb) tud_bt_acl_data_sent_cb((uint16_t)xferred_bytes);
- }
-
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/class/bth/bth_device.h b/tinyusb/src/class/bth/bth_device.h
deleted file mode 100755
index 1b90d091..00000000
--- a/tinyusb/src/class/bth/bth_device.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Jerzy Kasenberg
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_BTH_DEVICE_H_
-#define _TUSB_BTH_DEVICE_H_
-
-#include <common/tusb_common.h>
-#include <device/usbd.h>
-
-//--------------------------------------------------------------------+
-// Class Driver Configuration
-//--------------------------------------------------------------------+
-#ifndef CFG_TUD_BTH_EVENT_EPSIZE
-#define CFG_TUD_BTH_EVENT_EPSIZE 16
-#endif
-#ifndef CFG_TUD_BTH_DATA_EPSIZE
-#define CFG_TUD_BTH_DATA_EPSIZE 64
-#endif
-
-typedef struct TU_ATTR_PACKED
-{
- uint16_t op_code;
- uint8_t param_length;
- uint8_t param[255];
-} bt_hci_cmd_t;
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Application Callback API (weak is optional)
-//--------------------------------------------------------------------+
-
-// Invoked when HCI command was received over USB from Bluetooth host.
-// Detailed format is described in Bluetooth core specification Vol 2,
-// Part E, 5.4.1.
-// Length of the command is from 3 bytes (2 bytes for OpCode,
-// 1 byte for parameter total length) to 258.
-TU_ATTR_WEAK void tud_bt_hci_cmd_cb(void *hci_cmd, size_t cmd_len);
-
-// Invoked when ACL data was received over USB from Bluetooth host.
-// Detailed format is described in Bluetooth core specification Vol 2,
-// Part E, 5.4.2.
-// Length is from 4 bytes, (12 bits for Handle, 4 bits for flags
-// and 16 bits for data total length) to endpoint size.
-TU_ATTR_WEAK void tud_bt_acl_data_received_cb(void *acl_data, uint16_t data_len);
-
-// Called when event sent with tud_bt_event_send() was delivered to BT stack.
-// Controller can release/reuse buffer with Event packet at this point.
-TU_ATTR_WEAK void tud_bt_event_sent_cb(uint16_t sent_bytes);
-
-// Called when ACL data that was sent with tud_bt_acl_data_send()
-// was delivered to BT stack.
-// Controller can release/reuse buffer with ACL packet at this point.
-TU_ATTR_WEAK void tud_bt_acl_data_sent_cb(uint16_t sent_bytes);
-
-// Bluetooth controller calls this function when it wants to send even packet
-// as described in Bluetooth core specification Vol 2, Part E, 5.4.4.
-// Event has at least 2 bytes, first is Event code second contains parameter
-// total length. Controller can release/reuse event memory after
-// tud_bt_event_sent_cb() is called.
-bool tud_bt_event_send(void *event, uint16_t event_len);
-
-// Bluetooth controller calls this to send ACL data packet
-// as described in Bluetooth core specification Vol 2, Part E, 5.4.2
-// Minimum length is 4 bytes, (12 bits for Handle, 4 bits for flags
-// and 16 bits for data total length). Upper limit is not limited
-// to endpoint size since buffer is allocate by controller
-// and must not be reused till tud_bt_acl_data_sent_cb() is called.
-bool tud_bt_acl_data_send(void *acl_data, uint16_t data_len);
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void btd_init (void);
-void btd_reset (uint8_t rhport);
-uint16_t btd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool btd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const *request);
-bool btd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_BTH_DEVICE_H_ */
diff --git a/tinyusb/src/class/cdc/cdc.h b/tinyusb/src/class/cdc/cdc.h
deleted file mode 100755
index 5df47f70..00000000
--- a/tinyusb/src/class/cdc/cdc.h
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/** \ingroup group_class
- * \defgroup ClassDriver_CDC Communication Device Class (CDC)
- * Currently only Abstract Control Model subclass is supported
- * @{ */
-
-#ifndef _TUSB_CDC_H__
-#define _TUSB_CDC_H__
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/** \defgroup ClassDriver_CDC_Common Common Definitions
- * @{ */
-
-// TODO remove
-/// CDC Pipe ID, used to indicate which pipe the API is addressing to (Notification, Out, In)
-typedef enum
-{
- CDC_PIPE_NOTIFICATION , ///< Notification pipe
- CDC_PIPE_DATA_IN , ///< Data in pipe
- CDC_PIPE_DATA_OUT , ///< Data out pipe
- CDC_PIPE_ERROR , ///< Invalid Pipe ID
-}cdc_pipeid_t;
-
-//--------------------------------------------------------------------+
-// CDC Communication Interface Class
-//--------------------------------------------------------------------+
-
-/// Communication Interface Subclass Codes
-typedef enum
-{
- CDC_COMM_SUBCLASS_DIRECT_LINE_CONTROL_MODEL = 0x01 , ///< Direct Line Control Model [USBPSTN1.2]
- CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL , ///< Abstract Control Model [USBPSTN1.2]
- CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL , ///< Telephone Control Model [USBPSTN1.2]
- CDC_COMM_SUBCLASS_MULTICHANNEL_CONTROL_MODEL , ///< Multi-Channel Control Model [USBISDN1.2]
- CDC_COMM_SUBCLASS_CAPI_CONTROL_MODEL , ///< CAPI Control Model [USBISDN1.2]
- CDC_COMM_SUBCLASS_ETHERNET_CONTROL_MODEL , ///< Ethernet Networking Control Model [USBECM1.2]
- CDC_COMM_SUBCLASS_ATM_NETWORKING_CONTROL_MODEL , ///< ATM Networking Control Model [USBATM1.2]
- CDC_COMM_SUBCLASS_WIRELESS_HANDSET_CONTROL_MODEL , ///< Wireless Handset Control Model [USBWMC1.1]
- CDC_COMM_SUBCLASS_DEVICE_MANAGEMENT , ///< Device Management [USBWMC1.1]
- CDC_COMM_SUBCLASS_MOBILE_DIRECT_LINE_MODEL , ///< Mobile Direct Line Model [USBWMC1.1]
- CDC_COMM_SUBCLASS_OBEX , ///< OBEX [USBWMC1.1]
- CDC_COMM_SUBCLASS_ETHERNET_EMULATION_MODEL ///< Ethernet Emulation Model [USBEEM1.0]
-} cdc_comm_sublcass_type_t;
-
-/// Communication Interface Protocol Codes
-typedef enum
-{
- CDC_COMM_PROTOCOL_NONE = 0x00 , ///< No specific protocol
- CDC_COMM_PROTOCOL_ATCOMMAND , ///< AT Commands: V.250 etc
- CDC_COMM_PROTOCOL_ATCOMMAND_PCCA_101 , ///< AT Commands defined by PCCA-101
- CDC_COMM_PROTOCOL_ATCOMMAND_PCCA_101_AND_ANNEXO , ///< AT Commands defined by PCCA-101 & Annex O
- CDC_COMM_PROTOCOL_ATCOMMAND_GSM_707 , ///< AT Commands defined by GSM 07.07
- CDC_COMM_PROTOCOL_ATCOMMAND_3GPP_27007 , ///< AT Commands defined by 3GPP 27.007
- CDC_COMM_PROTOCOL_ATCOMMAND_CDMA , ///< AT Commands defined by TIA for CDMA
- CDC_COMM_PROTOCOL_ETHERNET_EMULATION_MODEL ///< Ethernet Emulation Model
-} cdc_comm_protocol_type_t;
-
-//------------- SubType Descriptor in COMM Functional Descriptor -------------//
-/// Communication Interface SubType Descriptor
-typedef enum
-{
- CDC_FUNC_DESC_HEADER = 0x00 , ///< Header Functional Descriptor, which marks the beginning of the concatenated set of functional descriptors for the interface.
- CDC_FUNC_DESC_CALL_MANAGEMENT = 0x01 , ///< Call Management Functional Descriptor.
- CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT = 0x02 , ///< Abstract Control Management Functional Descriptor.
- CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT = 0x03 , ///< Direct Line Management Functional Descriptor.
- CDC_FUNC_DESC_TELEPHONE_RINGER = 0x04 , ///< Telephone Ringer Functional Descriptor.
- CDC_FUNC_DESC_TELEPHONE_CALL_AND_LINE_STATE_REPORTING_CAPACITY = 0x05 , ///< Telephone Call and Line State Reporting Capabilities Functional Descriptor.
- CDC_FUNC_DESC_UNION = 0x06 , ///< Union Functional Descriptor
- CDC_FUNC_DESC_COUNTRY_SELECTION = 0x07 , ///< Country Selection Functional Descriptor
- CDC_FUNC_DESC_TELEPHONE_OPERATIONAL_MODES = 0x08 , ///< Telephone Operational ModesFunctional Descriptor
- CDC_FUNC_DESC_USB_TERMINAL = 0x09 , ///< USB Terminal Functional Descriptor
- CDC_FUNC_DESC_NETWORK_CHANNEL_TERMINAL = 0x0A , ///< Network Channel Terminal Descriptor
- CDC_FUNC_DESC_PROTOCOL_UNIT = 0x0B , ///< Protocol Unit Functional Descriptor
- CDC_FUNC_DESC_EXTENSION_UNIT = 0x0C , ///< Extension Unit Functional Descriptor
- CDC_FUNC_DESC_MULTICHANEL_MANAGEMENT = 0x0D , ///< Multi-Channel Management Functional Descriptor
- CDC_FUNC_DESC_CAPI_CONTROL_MANAGEMENT = 0x0E , ///< CAPI Control Management Functional Descriptor
- CDC_FUNC_DESC_ETHERNET_NETWORKING = 0x0F , ///< Ethernet Networking Functional Descriptor
- CDC_FUNC_DESC_ATM_NETWORKING = 0x10 , ///< ATM Networking Functional Descriptor
- CDC_FUNC_DESC_WIRELESS_HANDSET_CONTROL_MODEL = 0x11 , ///< Wireless Handset Control Model Functional Descriptor
- CDC_FUNC_DESC_MOBILE_DIRECT_LINE_MODEL = 0x12 , ///< Mobile Direct Line Model Functional Descriptor
- CDC_FUNC_DESC_MOBILE_DIRECT_LINE_MODEL_DETAIL = 0x13 , ///< MDLM Detail Functional Descriptor
- CDC_FUNC_DESC_DEVICE_MANAGEMENT_MODEL = 0x14 , ///< Device Management Model Functional Descriptor
- CDC_FUNC_DESC_OBEX = 0x15 , ///< OBEX Functional Descriptor
- CDC_FUNC_DESC_COMMAND_SET = 0x16 , ///< Command Set Functional Descriptor
- CDC_FUNC_DESC_COMMAND_SET_DETAIL = 0x17 , ///< Command Set Detail Functional Descriptor
- CDC_FUNC_DESC_TELEPHONE_CONTROL_MODEL = 0x18 , ///< Telephone Control Model Functional Descriptor
- CDC_FUNC_DESC_OBEX_SERVICE_IDENTIFIER = 0x19 ///< OBEX Service Identifier Functional Descriptor
-}cdc_func_desc_type_t;
-
-//--------------------------------------------------------------------+
-// CDC Data Interface Class
-//--------------------------------------------------------------------+
-
-// SUBCLASS code of Data Interface is not used and should/must be zero
-/// Data Interface Protocol Codes
-typedef enum{
- CDC_DATA_PROTOCOL_ISDN_BRI = 0x30, ///< Physical interface protocol for ISDN BRI
- CDC_DATA_PROTOCOL_HDLC = 0x31, ///< HDLC
- CDC_DATA_PROTOCOL_TRANSPARENT = 0x32, ///< Transparent
- CDC_DATA_PROTOCOL_Q921_MANAGEMENT = 0x50, ///< Management protocol for Q.921 data link protocol
- CDC_DATA_PROTOCOL_Q921_DATA_LINK = 0x51, ///< Data link protocol for Q.931
- CDC_DATA_PROTOCOL_Q921_TEI_MULTIPLEXOR = 0x52, ///< TEI-multiplexor for Q.921 data link protocol
- CDC_DATA_PROTOCOL_V42BIS_DATA_COMPRESSION = 0x90, ///< Data compression procedures
- CDC_DATA_PROTOCOL_EURO_ISDN = 0x91, ///< Euro-ISDN protocol control
- CDC_DATA_PROTOCOL_V24_RATE_ADAPTION_TO_ISDN = 0x92, ///< V.24 rate adaptation to ISDN
- CDC_DATA_PROTOCOL_CAPI_COMMAND = 0x93, ///< CAPI Commands
- CDC_DATA_PROTOCOL_HOST_BASED_DRIVER = 0xFD, ///< Host based driver. Note: This protocol code should only be used in messages between host and device to identify the host driver portion of a protocol stack.
- CDC_DATA_PROTOCOL_IN_PROTOCOL_UNIT_FUNCTIONAL_DESCRIPTOR = 0xFE ///< The protocol(s) are described using a ProtocolUnit Functional Descriptors on Communications Class Interface
-}cdc_data_protocol_type_t;
-
-//--------------------------------------------------------------------+
-// Management Element Request (Control Endpoint)
-//--------------------------------------------------------------------+
-
-/// Communication Interface Management Element Request Codes
-typedef enum
-{
- CDC_REQUEST_SEND_ENCAPSULATED_COMMAND = 0x00, ///< is used to issue a command in the format of the supported control protocol of the Communications Class interface
- CDC_REQUEST_GET_ENCAPSULATED_RESPONSE = 0x01, ///< is used to request a response in the format of the supported control protocol of the Communications Class interface.
-
- CDC_REQUEST_SET_COMM_FEATURE = 0x02,
- CDC_REQUEST_GET_COMM_FEATURE = 0x03,
- CDC_REQUEST_CLEAR_COMM_FEATURE = 0x04,
-
- CDC_REQUEST_SET_AUX_LINE_STATE = 0x10,
- CDC_REQUEST_SET_HOOK_STATE = 0x11,
- CDC_REQUEST_PULSE_SETUP = 0x12,
- CDC_REQUEST_SEND_PULSE = 0x13,
- CDC_REQUEST_SET_PULSE_TIME = 0x14,
- CDC_REQUEST_RING_AUX_JACK = 0x15,
-
- CDC_REQUEST_SET_LINE_CODING = 0x20,
- CDC_REQUEST_GET_LINE_CODING = 0x21,
- CDC_REQUEST_SET_CONTROL_LINE_STATE = 0x22,
- CDC_REQUEST_SEND_BREAK = 0x23,
-
- CDC_REQUEST_SET_RINGER_PARMS = 0x30,
- CDC_REQUEST_GET_RINGER_PARMS = 0x31,
- CDC_REQUEST_SET_OPERATION_PARMS = 0x32,
- CDC_REQUEST_GET_OPERATION_PARMS = 0x33,
- CDC_REQUEST_SET_LINE_PARMS = 0x34,
- CDC_REQUEST_GET_LINE_PARMS = 0x35,
- CDC_REQUEST_DIAL_DIGITS = 0x36,
- CDC_REQUEST_SET_UNIT_PARAMETER = 0x37,
- CDC_REQUEST_GET_UNIT_PARAMETER = 0x38,
- CDC_REQUEST_CLEAR_UNIT_PARAMETER = 0x39,
- CDC_REQUEST_GET_PROFILE = 0x3A,
-
- CDC_REQUEST_SET_ETHERNET_MULTICAST_FILTERS = 0x40,
- CDC_REQUEST_SET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER = 0x41,
- CDC_REQUEST_GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER = 0x42,
- CDC_REQUEST_SET_ETHERNET_PACKET_FILTER = 0x43,
- CDC_REQUEST_GET_ETHERNET_STATISTIC = 0x44,
-
- CDC_REQUEST_SET_ATM_DATA_FORMAT = 0x50,
- CDC_REQUEST_GET_ATM_DEVICE_STATISTICS = 0x51,
- CDC_REQUEST_SET_ATM_DEFAULT_VC = 0x52,
- CDC_REQUEST_GET_ATM_VC_STATISTICS = 0x53,
-
- CDC_REQUEST_MDLM_SEMANTIC_MODEL = 0x60,
-}cdc_management_request_t;
-
-//--------------------------------------------------------------------+
-// Management Elemenent Notification (Notification Endpoint)
-//--------------------------------------------------------------------+
-
-/// Communication Interface Management Element Notification Codes
-typedef enum
-{
- NETWORK_CONNECTION = 0x00, ///< This notification allows the device to notify the host about network connection status.
- RESPONSE_AVAILABLE = 0x01, ///< This notification allows the device to notify the hostthat a response is available. This response can be retrieved with a subsequent \ref CDC_REQUEST_GET_ENCAPSULATED_RESPONSE request.
-
- AUX_JACK_HOOK_STATE = 0x08,
- RING_DETECT = 0x09,
-
- SERIAL_STATE = 0x20,
-
- CALL_STATE_CHANGE = 0x28,
- LINE_STATE_CHANGE = 0x29,
- CONNECTION_SPEED_CHANGE = 0x2A, ///< This notification allows the device to inform the host-networking driver that a change in either the upstream or the downstream bit rate of the connection has occurred
- MDLM_SEMANTIC_MODEL_NOTIFICATION = 0x40,
-}cdc_notification_request_t;
-
-//--------------------------------------------------------------------+
-// Class Specific Functional Descriptor (Communication Interface)
-//--------------------------------------------------------------------+
-
-// Start of all packed definitions for compiler without per-type packed
-TU_ATTR_PACKED_BEGIN
-TU_ATTR_BIT_FIELD_ORDER_BEGIN
-
-/// Header Functional Descriptor (Communication Interface)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUNC_DESC_
- uint16_t bcdCDC ; ///< CDC release number in Binary-Coded Decimal
-}cdc_desc_func_header_t;
-
-/// Union Functional Descriptor (Communication Interface)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
- uint8_t bControlInterface ; ///< Interface number of Communication Interface
- uint8_t bSubordinateInterface ; ///< Array of Interface number of Data Interface
-}cdc_desc_func_union_t;
-
-#define cdc_desc_func_union_n_t(no_slave)\
- struct TU_ATTR_PACKED { \
- uint8_t bLength ;\
- uint8_t bDescriptorType ;\
- uint8_t bDescriptorSubType ;\
- uint8_t bControlInterface ;\
- uint8_t bSubordinateInterface[no_slave] ;\
-}
-
-/// Country Selection Functional Descriptor (Communication Interface)
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
- uint8_t iCountryCodeRelDate ; ///< Index of a string giving the release date for the implemented ISO 3166 Country Codes.
- uint16_t wCountryCode ; ///< Country code in the format as defined in [ISO3166], release date as specified inoffset 3 for the first supported country.
-}cdc_desc_func_country_selection_t;
-
-#define cdc_desc_func_country_selection_n_t(no_country) \
- struct TU_ATTR_PACKED { \
- uint8_t bLength ;\
- uint8_t bDescriptorType ;\
- uint8_t bDescriptorSubType ;\
- uint8_t iCountryCodeRelDate ;\
- uint16_t wCountryCode[no_country] ;\
-}
-
-//--------------------------------------------------------------------+
-// PUBLIC SWITCHED TELEPHONE NETWORK (PSTN) SUBCLASS
-//--------------------------------------------------------------------+
-
-/// \brief Call Management Functional Descriptor
-/// \details This functional descriptor describes the processing of calls for the Communications Class interface.
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
-
- struct {
- uint8_t handle_call : 1; ///< 0 - Device sends/receives call management information only over the Communications Class interface. 1 - Device can send/receive call management information over a Data Class interface.
- uint8_t send_recv_call : 1; ///< 0 - Device does not handle call management itself. 1 - Device handles call management itself.
- uint8_t TU_RESERVED : 6;
- } bmCapabilities;
-
- uint8_t bDataInterface;
-}cdc_desc_func_call_management_t;
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t support_comm_request : 1; ///< Device supports the request combination of Set_Comm_Feature, Clear_Comm_Feature, and Get_Comm_Feature.
- uint8_t support_line_request : 1; ///< Device supports the request combination of Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.
- uint8_t support_send_break : 1; ///< Device supports the request Send_Break
- uint8_t support_notification_network_connection : 1; ///< Device supports the notification Network_Connection.
- uint8_t TU_RESERVED : 4;
-}cdc_acm_capability_t;
-
-TU_VERIFY_STATIC(sizeof(cdc_acm_capability_t) == 1, "mostly problem with compiler");
-
-/// Abstract Control Management Functional Descriptor
-/// This functional descriptor describes the commands supported by by the Communications Class interface with SubClass code of \ref CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
- cdc_acm_capability_t bmCapabilities ;
-}cdc_desc_func_acm_t;
-
-/// \brief Direct Line Management Functional Descriptor
-/// \details This functional descriptor describes the commands supported by the Communications Class interface with SubClass code of \ref CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
- struct {
- uint8_t require_pulse_setup : 1; ///< Device requires extra Pulse_Setup request during pulse dialing sequence to disengage holding circuit.
- uint8_t support_aux_request : 1; ///< Device supports the request combination of Set_Aux_Line_State, Ring_Aux_Jack, and notification Aux_Jack_Hook_State.
- uint8_t support_pulse_request : 1; ///< Device supports the request combination of Pulse_Setup, Send_Pulse, and Set_Pulse_Time.
- uint8_t TU_RESERVED : 5;
- } bmCapabilities;
-}cdc_desc_func_direct_line_management_t;
-
-/// \brief Telephone Ringer Functional Descriptor
-/// \details The Telephone Ringer functional descriptor describes the ringer capabilities supported by the Communications Class interface,
-/// with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
- uint8_t bRingerVolSteps ;
- uint8_t bNumRingerPatterns ;
-}cdc_desc_func_telephone_ringer_t;
-
-/// \brief Telephone Operational Modes Functional Descriptor
-/// \details The Telephone Operational Modes functional descriptor describes the operational modes supported by
-/// the Communications Class interface, with the SubClass code of \ref CDC_COMM_SUBCLASS_TELEPHONE_CONTROL_MODEL
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
- struct {
- uint8_t simple_mode : 1;
- uint8_t standalone_mode : 1;
- uint8_t computer_centric_mode : 1;
- uint8_t TU_RESERVED : 5;
- } bmCapabilities;
-}cdc_desc_func_telephone_operational_modes_t;
-
-/// \brief Telephone Call and Line State Reporting Capabilities Descriptor
-/// \details The Telephone Call and Line State Reporting Capabilities functional descriptor describes the abilities of a
-/// telephone device to report optional call and line states.
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType one of above CDC_FUCN_DESC_
- struct {
- uint32_t interrupted_dialtone : 1; ///< 0 : Reports only dialtone (does not differentiate between normal and interrupted dialtone). 1 : Reports interrupted dialtone in addition to normal dialtone
- uint32_t ringback_busy_fastbusy : 1; ///< 0 : Reports only dialing state. 1 : Reports ringback, busy, and fast busy states.
- uint32_t caller_id : 1; ///< 0 : Does not report caller ID. 1 : Reports caller ID information.
- uint32_t incoming_distinctive : 1; ///< 0 : Reports only incoming ringing. 1 : Reports incoming distinctive ringing patterns.
- uint32_t dual_tone_multi_freq : 1; ///< 0 : Cannot report dual tone multi-frequency (DTMF) digits input remotely over the telephone line. 1 : Can report DTMF digits input remotely over the telephone line.
- uint32_t line_state_change : 1; ///< 0 : Does not support line state change notification. 1 : Does support line state change notification
- uint32_t TU_RESERVED : 26;
- } bmCapabilities;
-}cdc_desc_func_telephone_call_state_reporting_capabilities_t;
-
-// TODO remove
-static inline uint8_t cdc_functional_desc_typeof(uint8_t const * p_desc)
-{
- return p_desc[2];
-}
-
-//--------------------------------------------------------------------+
-// Requests
-//--------------------------------------------------------------------+
-typedef struct TU_ATTR_PACKED
-{
- uint32_t bit_rate;
- uint8_t stop_bits; ///< 0: 1 stop bit - 1: 1.5 stop bits - 2: 2 stop bits
- uint8_t parity; ///< 0: None - 1: Odd - 2: Even - 3: Mark - 4: Space
- uint8_t data_bits; ///< can be 5, 6, 7, 8 or 16
-} cdc_line_coding_t;
-
-TU_VERIFY_STATIC(sizeof(cdc_line_coding_t) == 7, "size is not correct");
-
-typedef struct TU_ATTR_PACKED
-{
- uint16_t dte_is_present : 1; ///< Indicates to DCE if DTE is presentor not. This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR.
- uint16_t half_duplex_carrier_control : 1;
- uint16_t : 14;
-} cdc_line_control_state_t;
-
-TU_VERIFY_STATIC(sizeof(cdc_line_control_state_t) == 2, "size is not correct");
-
-TU_ATTR_PACKED_END // End of all packed definitions
-TU_ATTR_BIT_FIELD_ORDER_END
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif
-
-/** @} */
diff --git a/tinyusb/src/class/cdc/cdc_device.c b/tinyusb/src/class/cdc/cdc_device.c
deleted file mode 100755
index e622bd61..00000000
--- a/tinyusb/src/class/cdc/cdc_device.c
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CDC)
-
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "cdc_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-enum
-{
- BULK_PACKET_SIZE = (TUD_OPT_HIGH_SPEED ? 512 : 64)
-};
-
-typedef struct
-{
- uint8_t itf_num;
- uint8_t ep_notif;
- uint8_t ep_in;
- uint8_t ep_out;
-
- // Bit 0: DTR (Data Terminal Ready), Bit 1: RTS (Request to Send)
- uint8_t line_state;
-
- /*------------- From this point, data is not cleared by bus reset -------------*/
- char wanted_char;
- cdc_line_coding_t line_coding;
-
- // FIFO
- tu_fifo_t rx_ff;
- tu_fifo_t tx_ff;
-
- uint8_t rx_ff_buf[CFG_TUD_CDC_RX_BUFSIZE];
- uint8_t tx_ff_buf[CFG_TUD_CDC_TX_BUFSIZE];
-
-#if CFG_FIFO_MUTEX
- osal_mutex_def_t rx_ff_mutex;
- osal_mutex_def_t tx_ff_mutex;
-#endif
-
- // Endpoint Transfer buffer
- CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_CDC_EP_BUFSIZE];
- CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_CDC_EP_BUFSIZE];
-
-}cdcd_interface_t;
-
-#define ITF_MEM_RESET_SIZE offsetof(cdcd_interface_t, wanted_char)
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
-
-static void _prep_out_transaction (cdcd_interface_t* p_cdc)
-{
- uint8_t const rhport = TUD_OPT_RHPORT;
- uint16_t available = tu_fifo_remaining(&p_cdc->rx_ff);
-
- // Prepare for incoming data but only allow what we can store in the ring buffer.
- // TODO Actually we can still carry out the transfer, keeping count of received bytes
- // and slowly move it to the FIFO when read().
- // This pre-check reduces endpoint claiming
- TU_VERIFY(available >= sizeof(p_cdc->epout_buf), );
-
- // claim endpoint
- TU_VERIFY(usbd_edpt_claim(rhport, p_cdc->ep_out), );
-
- // fifo can be changed before endpoint is claimed
- available = tu_fifo_remaining(&p_cdc->rx_ff);
-
- if ( available >= sizeof(p_cdc->epout_buf) )
- {
- usbd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, sizeof(p_cdc->epout_buf));
- }else
- {
- // Release endpoint since we don't make any transfer
- usbd_edpt_release(rhport, p_cdc->ep_out);
- }
-}
-
-//--------------------------------------------------------------------+
-// APPLICATION API
-//--------------------------------------------------------------------+
-bool tud_cdc_n_connected(uint8_t itf)
-{
- // DTR (bit 0) active is considered as connected
- return tud_ready() && tu_bit_test(_cdcd_itf[itf].line_state, 0);
-}
-
-uint8_t tud_cdc_n_get_line_state (uint8_t itf)
-{
- return _cdcd_itf[itf].line_state;
-}
-
-void tud_cdc_n_get_line_coding (uint8_t itf, cdc_line_coding_t* coding)
-{
- (*coding) = _cdcd_itf[itf].line_coding;
-}
-
-void tud_cdc_n_set_wanted_char (uint8_t itf, char wanted)
-{
- _cdcd_itf[itf].wanted_char = wanted;
-}
-
-
-//--------------------------------------------------------------------+
-// READ API
-//--------------------------------------------------------------------+
-uint32_t tud_cdc_n_available(uint8_t itf)
-{
- return tu_fifo_count(&_cdcd_itf[itf].rx_ff);
-}
-
-uint32_t tud_cdc_n_read(uint8_t itf, void* buffer, uint32_t bufsize)
-{
- cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
- uint32_t num_read = tu_fifo_read_n(&p_cdc->rx_ff, buffer, bufsize);
- _prep_out_transaction(p_cdc);
- return num_read;
-}
-
-bool tud_cdc_n_peek(uint8_t itf, uint8_t* chr)
-{
- return tu_fifo_peek(&_cdcd_itf[itf].rx_ff, chr);
-}
-
-void tud_cdc_n_read_flush (uint8_t itf)
-{
- cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
- tu_fifo_clear(&p_cdc->rx_ff);
- _prep_out_transaction(p_cdc);
-}
-
-//--------------------------------------------------------------------+
-// WRITE API
-//--------------------------------------------------------------------+
-uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize)
-{
- cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
- uint16_t ret = tu_fifo_write_n(&p_cdc->tx_ff, buffer, bufsize);
-
- // flush if queue more than packet size
- if ( tu_fifo_count(&p_cdc->tx_ff) >= BULK_PACKET_SIZE )
- {
- tud_cdc_n_write_flush(itf);
- }
-
- return ret;
-}
-
-uint32_t tud_cdc_n_write_flush (uint8_t itf)
-{
- cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
-
- // Skip if usb is not ready yet
- TU_VERIFY( tud_ready(), 0 );
-
- // No data to send
- if ( !tu_fifo_count(&p_cdc->tx_ff) ) return 0;
-
- uint8_t const rhport = TUD_OPT_RHPORT;
-
- // Claim the endpoint
- TU_VERIFY( usbd_edpt_claim(rhport, p_cdc->ep_in), 0 );
-
- // Pull data from FIFO
- uint16_t const count = tu_fifo_read_n(&p_cdc->tx_ff, p_cdc->epin_buf, sizeof(p_cdc->epin_buf));
-
- if ( count )
- {
- TU_ASSERT( usbd_edpt_xfer(rhport, p_cdc->ep_in, p_cdc->epin_buf, count), 0 );
- return count;
- }else
- {
- // Release endpoint since we don't make any transfer
- // Note: data is dropped if terminal is not connected
- usbd_edpt_release(rhport, p_cdc->ep_in);
- return 0;
- }
-}
-
-uint32_t tud_cdc_n_write_available (uint8_t itf)
-{
- return tu_fifo_remaining(&_cdcd_itf[itf].tx_ff);
-}
-
-bool tud_cdc_n_write_clear (uint8_t itf)
-{
- return tu_fifo_clear(&_cdcd_itf[itf].tx_ff);
-}
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void cdcd_init(void)
-{
- tu_memclr(_cdcd_itf, sizeof(_cdcd_itf));
-
- for(uint8_t i=0; i<CFG_TUD_CDC; i++)
- {
- cdcd_interface_t* p_cdc = &_cdcd_itf[i];
-
- p_cdc->wanted_char = -1;
-
- // default line coding is : stop bit = 1, parity = none, data bits = 8
- p_cdc->line_coding.bit_rate = 115200;
- p_cdc->line_coding.stop_bits = 0;
- p_cdc->line_coding.parity = 0;
- p_cdc->line_coding.data_bits = 8;
-
- // Config RX fifo
- tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, TU_ARRAY_SIZE(p_cdc->rx_ff_buf), 1, false);
-
- // Config TX fifo as overwritable at initialization and will be changed to non-overwritable
- // if terminal supports DTR bit. Without DTR we do not know if data is actually polled by terminal.
- // In this way, the most current data is prioritized.
- tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, true);
-
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&p_cdc->rx_ff, NULL, osal_mutex_create(&p_cdc->rx_ff_mutex));
- tu_fifo_config_mutex(&p_cdc->tx_ff, osal_mutex_create(&p_cdc->tx_ff_mutex), NULL);
-#endif
- }
-}
-
-void cdcd_reset(uint8_t rhport)
-{
- (void) rhport;
-
- for(uint8_t i=0; i<CFG_TUD_CDC; i++)
- {
- cdcd_interface_t* p_cdc = &_cdcd_itf[i];
-
- tu_memclr(p_cdc, ITF_MEM_RESET_SIZE);
- tu_fifo_clear(&p_cdc->rx_ff);
- tu_fifo_clear(&p_cdc->tx_ff);
- tu_fifo_set_overwritable(&p_cdc->tx_ff, true);
- }
-}
-
-uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- // Only support ACM subclass
- TU_VERIFY( TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
- CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass, 0);
-
- // Find available interface
- cdcd_interface_t * p_cdc = NULL;
- for(uint8_t cdc_id=0; cdc_id<CFG_TUD_CDC; cdc_id++)
- {
- if ( _cdcd_itf[cdc_id].ep_in == 0 )
- {
- p_cdc = &_cdcd_itf[cdc_id];
- break;
- }
- }
- TU_ASSERT(p_cdc, 0);
-
- //------------- Control Interface -------------//
- p_cdc->itf_num = itf_desc->bInterfaceNumber;
-
- uint16_t drv_len = sizeof(tusb_desc_interface_t);
- uint8_t const * p_desc = tu_desc_next( itf_desc );
-
- // Communication Functional Descriptors
- while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len )
- {
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
- {
- // notification endpoint
- tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
-
- TU_ASSERT( usbd_edpt_open(rhport, desc_ep), 0 );
- p_cdc->ep_notif = desc_ep->bEndpointAddress;
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- //------------- Data Interface (if any) -------------//
- if ( (TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) &&
- (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
- {
- // next to endpoint descriptor
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
-
- // Open endpoint pair
- TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in), 0 );
-
- drv_len += 2*sizeof(tusb_desc_endpoint_t);
- }
-
- // Prepare for incoming data
- _prep_out_transaction(p_cdc);
-
- return drv_len;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- // Handle class request only
- TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
-
- uint8_t itf = 0;
- cdcd_interface_t* p_cdc = _cdcd_itf;
-
- // Identify which interface to use
- for ( ; ; itf++, p_cdc++)
- {
- if (itf >= TU_ARRAY_SIZE(_cdcd_itf)) return false;
-
- if ( p_cdc->itf_num == request->wIndex ) break;
- }
-
- switch ( request->bRequest )
- {
- case CDC_REQUEST_SET_LINE_CODING:
- if (stage == CONTROL_STAGE_SETUP)
- {
- TU_LOG2(" Set Line Coding\r\n");
- tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
- }
- else if ( stage == CONTROL_STAGE_ACK)
- {
- if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding);
- }
- break;
-
- case CDC_REQUEST_GET_LINE_CODING:
- if (stage == CONTROL_STAGE_SETUP)
- {
- TU_LOG2(" Get Line Coding\r\n");
- tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
- }
- break;
-
- case CDC_REQUEST_SET_CONTROL_LINE_STATE:
- if (stage == CONTROL_STAGE_SETUP)
- {
- tud_control_status(rhport, request);
- }
- else if (stage == CONTROL_STAGE_ACK)
- {
- // CDC PSTN v1.2 section 6.3.12
- // Bit 0: Indicates if DTE is present or not.
- // This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready)
- // Bit 1: Carrier control for half-duplex modems.
- // This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send)
- bool const dtr = tu_bit_test(request->wValue, 0);
- bool const rts = tu_bit_test(request->wValue, 1);
-
- p_cdc->line_state = (uint8_t) request->wValue;
-
- // Disable fifo overwriting if DTR bit is set
- tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
-
- TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
-
- // Invoke callback
- if ( tud_cdc_line_state_cb ) tud_cdc_line_state_cb(itf, dtr, rts);
- }
- break;
- case CDC_REQUEST_SEND_BREAK:
- if (stage == CONTROL_STAGE_SETUP)
- {
- tud_control_status(rhport, request);
- }
- else if (stage == CONTROL_STAGE_ACK)
- {
- TU_LOG2(" Send Break\r\n");
- if ( tud_cdc_send_break_cb ) tud_cdc_send_break_cb(itf, request->wValue);
- }
- break;
-
- default: return false; // stall unsupported request
- }
-
- return true;
-}
-
-bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void) result;
-
- uint8_t itf;
- cdcd_interface_t* p_cdc;
-
- // Identify which interface to use
- for (itf = 0; itf < CFG_TUD_CDC; itf++)
- {
- p_cdc = &_cdcd_itf[itf];
- if ( ( ep_addr == p_cdc->ep_out ) || ( ep_addr == p_cdc->ep_in ) ) break;
- }
- TU_ASSERT(itf < CFG_TUD_CDC);
-
- // Received new data
- if ( ep_addr == p_cdc->ep_out )
- {
- tu_fifo_write_n(&p_cdc->rx_ff, &p_cdc->epout_buf, xferred_bytes);
-
- // Check for wanted char and invoke callback if needed
- if ( tud_cdc_rx_wanted_cb && (((signed char) p_cdc->wanted_char) != -1) )
- {
- for ( uint32_t i = 0; i < xferred_bytes; i++ )
- {
- if ( (p_cdc->wanted_char == p_cdc->epout_buf[i]) && !tu_fifo_empty(&p_cdc->rx_ff) )
- {
- tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
- }
- }
- }
-
- // invoke receive callback (if there is still data)
- if (tud_cdc_rx_cb && !tu_fifo_empty(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
-
- // prepare for OUT transaction
- _prep_out_transaction(p_cdc);
- }
-
- // Data sent to host, we continue to fetch from tx fifo to send.
- // Note: This will cause incorrect baudrate set in line coding.
- // Though maybe the baudrate is not really important !!!
- if ( ep_addr == p_cdc->ep_in )
- {
- // invoke transmit callback to possibly refill tx fifo
- if ( tud_cdc_tx_complete_cb ) tud_cdc_tx_complete_cb(itf);
-
- if ( 0 == tud_cdc_n_write_flush(itf) )
- {
- // If there is no data left, a ZLP should be sent if
- // xferred_bytes is multiple of EP Packet size and not zero
- if ( !tu_fifo_count(&p_cdc->tx_ff) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE-1))) )
- {
- if ( usbd_edpt_claim(rhport, p_cdc->ep_in) )
- {
- usbd_edpt_xfer(rhport, p_cdc->ep_in, NULL, 0);
- }
- }
- }
- }
-
- // nothing to do with notif endpoint for now
-
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/class/cdc/cdc_device.h b/tinyusb/src/class/cdc/cdc_device.h
deleted file mode 100755
index 7ff757ad..00000000
--- a/tinyusb/src/class/cdc/cdc_device.h
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_CDC_DEVICE_H_
-#define _TUSB_CDC_DEVICE_H_
-
-#include "common/tusb_common.h"
-#include "cdc.h"
-
-//--------------------------------------------------------------------+
-// Class Driver Configuration
-//--------------------------------------------------------------------+
-#if !defined(CFG_TUD_CDC_EP_BUFSIZE) && defined(CFG_TUD_CDC_EPSIZE)
- #warning CFG_TUD_CDC_EPSIZE is renamed to CFG_TUD_CDC_EP_BUFSIZE, please update to use the new name
- #define CFG_TUD_CDC_EP_BUFSIZE CFG_TUD_CDC_EPSIZE
-#endif
-
-#ifndef CFG_TUD_CDC_EP_BUFSIZE
- #define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
-#endif
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/** \addtogroup CDC_Serial Serial
- * @{
- * \defgroup CDC_Serial_Device Device
- * @{ */
-
-//--------------------------------------------------------------------+
-// Application API (Multiple Ports)
-// CFG_TUD_CDC > 1
-//--------------------------------------------------------------------+
-
-// Check if terminal is connected to this port
-bool tud_cdc_n_connected (uint8_t itf);
-
-// Get current line state. Bit 0: DTR (Data Terminal Ready), Bit 1: RTS (Request to Send)
-uint8_t tud_cdc_n_get_line_state (uint8_t itf);
-
-// Get current line encoding: bit rate, stop bits parity etc ..
-void tud_cdc_n_get_line_coding (uint8_t itf, cdc_line_coding_t* coding);
-
-// Set special character that will trigger tud_cdc_rx_wanted_cb() callback on receiving
-void tud_cdc_n_set_wanted_char (uint8_t itf, char wanted);
-
-// Get the number of bytes available for reading
-uint32_t tud_cdc_n_available (uint8_t itf);
-
-// Read received bytes
-uint32_t tud_cdc_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
-
-// Read a byte, return -1 if there is none
-static inline
-int32_t tud_cdc_n_read_char (uint8_t itf);
-
-// Clear the received FIFO
-void tud_cdc_n_read_flush (uint8_t itf);
-
-// Get a byte from FIFO at the specified position without removing it
-bool tud_cdc_n_peek (uint8_t itf, uint8_t* u8);
-
-// Write bytes to TX FIFO, data may remain in the FIFO for a while
-uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
-
-// Write a byte
-static inline
-uint32_t tud_cdc_n_write_char (uint8_t itf, char ch);
-
-// Write a null-terminated string
-static inline
-uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str);
-
-// Force sending data if possible, return number of forced bytes
-uint32_t tud_cdc_n_write_flush (uint8_t itf);
-
-// Return the number of bytes (characters) available for writing to TX FIFO buffer in a single n_write operation.
-uint32_t tud_cdc_n_write_available (uint8_t itf);
-
-// Clear the transmit FIFO
-bool tud_cdc_n_write_clear (uint8_t itf);
-
-//--------------------------------------------------------------------+
-// Application API (Single Port)
-//--------------------------------------------------------------------+
-static inline bool tud_cdc_connected (void);
-static inline uint8_t tud_cdc_get_line_state (void);
-static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding);
-static inline void tud_cdc_set_wanted_char (char wanted);
-
-static inline uint32_t tud_cdc_available (void);
-static inline int32_t tud_cdc_read_char (void);
-static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize);
-static inline void tud_cdc_read_flush (void);
-static inline bool tud_cdc_peek (uint8_t* u8);
-
-static inline uint32_t tud_cdc_write_char (char ch);
-static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize);
-static inline uint32_t tud_cdc_write_str (char const* str);
-static inline uint32_t tud_cdc_write_flush (void);
-static inline uint32_t tud_cdc_write_available (void);
-static inline bool tud_cdc_write_clear (void);
-
-//--------------------------------------------------------------------+
-// Application Callback API (weak is optional)
-//--------------------------------------------------------------------+
-
-// Invoked when received new data
-TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
-
-// Invoked when received `wanted_char`
-TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
-
-// Invoked when space becomes available in TX buffer
-TU_ATTR_WEAK void tud_cdc_tx_complete_cb(uint8_t itf);
-
-// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
-TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
-
-// Invoked when line coding is change via SET_LINE_CODING
-TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
-
-// Invoked when received send break
-TU_ATTR_WEAK void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms);
-
-//--------------------------------------------------------------------+
-// Inline Functions
-//--------------------------------------------------------------------+
-static inline int32_t tud_cdc_n_read_char (uint8_t itf)
-{
- uint8_t ch;
- return tud_cdc_n_read(itf, &ch, 1) ? (int32_t) ch : -1;
-}
-
-static inline uint32_t tud_cdc_n_write_char(uint8_t itf, char ch)
-{
- return tud_cdc_n_write(itf, &ch, 1);
-}
-
-static inline uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str)
-{
- return tud_cdc_n_write(itf, str, strlen(str));
-}
-
-static inline bool tud_cdc_connected (void)
-{
- return tud_cdc_n_connected(0);
-}
-
-static inline uint8_t tud_cdc_get_line_state (void)
-{
- return tud_cdc_n_get_line_state(0);
-}
-
-static inline void tud_cdc_get_line_coding (cdc_line_coding_t* coding)
-{
- tud_cdc_n_get_line_coding(0, coding);
-}
-
-static inline void tud_cdc_set_wanted_char (char wanted)
-{
- tud_cdc_n_set_wanted_char(0, wanted);
-}
-
-static inline uint32_t tud_cdc_available (void)
-{
- return tud_cdc_n_available(0);
-}
-
-static inline int32_t tud_cdc_read_char (void)
-{
- return tud_cdc_n_read_char(0);
-}
-
-static inline uint32_t tud_cdc_read (void* buffer, uint32_t bufsize)
-{
- return tud_cdc_n_read(0, buffer, bufsize);
-}
-
-static inline void tud_cdc_read_flush (void)
-{
- tud_cdc_n_read_flush(0);
-}
-
-static inline bool tud_cdc_peek (uint8_t* u8)
-{
- return tud_cdc_n_peek(0, u8);
-}
-
-static inline uint32_t tud_cdc_write_char (char ch)
-{
- return tud_cdc_n_write_char(0, ch);
-}
-
-static inline uint32_t tud_cdc_write (void const* buffer, uint32_t bufsize)
-{
- return tud_cdc_n_write(0, buffer, bufsize);
-}
-
-static inline uint32_t tud_cdc_write_str (char const* str)
-{
- return tud_cdc_n_write_str(0, str);
-}
-
-static inline uint32_t tud_cdc_write_flush (void)
-{
- return tud_cdc_n_write_flush(0);
-}
-
-static inline uint32_t tud_cdc_write_available(void)
-{
- return tud_cdc_n_write_available(0);
-}
-
-static inline bool tud_cdc_write_clear(void)
-{
- return tud_cdc_n_write_clear(0);
-}
-
-/** @} */
-/** @} */
-
-//--------------------------------------------------------------------+
-// INTERNAL USBD-CLASS DRIVER API
-//--------------------------------------------------------------------+
-void cdcd_init (void);
-void cdcd_reset (uint8_t rhport);
-uint16_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool cdcd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CDC_DEVICE_H_ */
diff --git a/tinyusb/src/class/cdc/cdc_host.c b/tinyusb/src/class/cdc/cdc_host.c
deleted file mode 100755
index e7eaf4d0..00000000
--- a/tinyusb/src/class/cdc/cdc_host.c
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_CDC)
-
-#include "host/usbh.h"
-#include "host/usbh_classdriver.h"
-
-#include "cdc_host.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-typedef struct {
- uint8_t itf_num;
- uint8_t itf_protocol;
-
- uint8_t ep_notif;
- uint8_t ep_in;
- uint8_t ep_out;
-
- cdc_acm_capability_t acm_capability;
-
-} cdch_data_t;
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-static cdch_data_t cdch_data[CFG_TUH_DEVICE_MAX];
-
-static inline cdch_data_t* get_itf(uint8_t dev_addr)
-{
- return &cdch_data[dev_addr-1];
-}
-
-bool tuh_cdc_mounted(uint8_t dev_addr)
-{
- cdch_data_t* cdc = get_itf(dev_addr);
- return cdc->ep_in && cdc->ep_out;
-}
-
-bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid)
-{
- if ( !tuh_cdc_mounted(dev_addr) ) return false;
-
- cdch_data_t const * p_cdc = get_itf(dev_addr);
-
- switch (pipeid)
- {
- case CDC_PIPE_NOTIFICATION:
- return usbh_edpt_busy(dev_addr, p_cdc->ep_notif );
-
- case CDC_PIPE_DATA_IN:
- return usbh_edpt_busy(dev_addr, p_cdc->ep_in );
-
- case CDC_PIPE_DATA_OUT:
- return usbh_edpt_busy(dev_addr, p_cdc->ep_out );
-
- default:
- return false;
- }
-}
-
-//--------------------------------------------------------------------+
-// APPLICATION API (parameter validation needed)
-//--------------------------------------------------------------------+
-bool tuh_cdc_serial_is_mounted(uint8_t dev_addr)
-{
- // TODO consider all AT Command as serial candidate
- return tuh_cdc_mounted(dev_addr) &&
- (cdch_data[dev_addr-1].itf_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA);
-}
-
-bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify)
-{
- (void) is_notify;
- TU_VERIFY( tuh_cdc_mounted(dev_addr) );
- TU_VERIFY( p_data != NULL && length, TUSB_ERROR_INVALID_PARA);
-
- uint8_t const ep_out = cdch_data[dev_addr-1].ep_out;
- if ( usbh_edpt_busy(dev_addr, ep_out) ) return false;
-
- return usbh_edpt_xfer(dev_addr, ep_out, (void *) p_data, length);
-}
-
-bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify)
-{
- (void) is_notify;
- TU_VERIFY( tuh_cdc_mounted(dev_addr) );
- TU_VERIFY( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA);
-
- uint8_t const ep_in = cdch_data[dev_addr-1].ep_in;
- if ( usbh_edpt_busy(dev_addr, ep_in) ) return false;
-
- return usbh_edpt_xfer(dev_addr, ep_in, p_buffer, length);
-}
-
-bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_control_complete_cb_t complete_cb)
-{
- cdch_data_t const * p_cdc = get_itf(dev_addr);
- tusb_control_request_t const request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE,
- .wValue = (rts ? 2 : 0) | (dtr ? 1 : 0),
- .wIndex = p_cdc->itf_num,
- .wLength = 0
- };
-
- TU_ASSERT( tuh_control_xfer(dev_addr, &request, NULL, complete_cb) );
- return true;
-}
-
-//--------------------------------------------------------------------+
-// USBH-CLASS DRIVER API
-//--------------------------------------------------------------------+
-void cdch_init(void)
-{
- tu_memclr(cdch_data, sizeof(cdch_data));
-}
-
-bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
-{
- (void) max_len;
-
- // Only support ACM subclass
- // Protocol 0xFF can be RNDIS device for windows XP
- TU_VERIFY( TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
- CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass &&
- 0xFF != itf_desc->bInterfaceProtocol);
-
- cdch_data_t * p_cdc = get_itf(dev_addr);
-
- p_cdc->itf_num = itf_desc->bInterfaceNumber;
- p_cdc->itf_protocol = itf_desc->bInterfaceProtocol;
-
- //------------- Communication Interface -------------//
- uint16_t drv_len = tu_desc_len(itf_desc);
- uint8_t const * p_desc = tu_desc_next(itf_desc);
-
- // Communication Functional Descriptors
- while( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len )
- {
- if ( CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT == cdc_functional_desc_typeof(p_desc) )
- {
- // save ACM bmCapabilities
- p_cdc->acm_capability = ((cdc_desc_func_acm_t const *) p_desc)->bmCapabilities;
- }
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
- {
- // notification endpoint
- tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
-
- TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
- p_cdc->ep_notif = desc_ep->bEndpointAddress;
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- //------------- Data Interface (if any) -------------//
- if ( (TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) &&
- (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
- {
- // next to endpoint descriptor
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
-
- // data endpoints expected to be in pairs
- for(uint32_t i=0; i<2; i++)
- {
- tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_BULK == desc_ep->bmAttributes.xfer);
-
- TU_ASSERT(usbh_edpt_open(rhport, dev_addr, desc_ep));
-
- if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
- {
- p_cdc->ep_in = desc_ep->bEndpointAddress;
- }else
- {
- p_cdc->ep_out = desc_ep->bEndpointAddress;
- }
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next( p_desc );
- }
- }
-
- return true;
-}
-
-bool cdch_set_config(uint8_t dev_addr, uint8_t itf_num)
-{
- (void) dev_addr; (void) itf_num;
- return true;
-}
-
-bool cdch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
-{
- (void) ep_addr;
- tuh_cdc_xfer_isr( dev_addr, event, 0, xferred_bytes );
- return true;
-}
-
-void cdch_close(uint8_t dev_addr)
-{
- TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX, );
-
- cdch_data_t * p_cdc = get_itf(dev_addr);
- tu_memclr(p_cdc, sizeof(cdch_data_t));
-}
-
-#endif
diff --git a/tinyusb/src/class/cdc/cdc_host.h b/tinyusb/src/class/cdc/cdc_host.h
deleted file mode 100755
index 0d435138..00000000
--- a/tinyusb/src/class/cdc/cdc_host.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_CDC_HOST_H_
-#define _TUSB_CDC_HOST_H_
-
-#include "cdc.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// CDC APPLICATION PUBLIC API
-//--------------------------------------------------------------------+
-/** \ingroup ClassDriver_CDC Communication Device Class (CDC)
- * \addtogroup CDC_Serial Serial
- * @{
- * \defgroup CDC_Serial_Host Host
- * @{ */
-
-bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_control_complete_cb_t complete_cb);
-
-static inline bool tuh_cdc_connect(uint8_t dev_addr, tuh_control_complete_cb_t complete_cb)
-{
- return tuh_cdc_set_control_line_state(dev_addr, true, true, complete_cb);
-}
-
-static inline bool tuh_cdc_disconnect(uint8_t dev_addr, tuh_control_complete_cb_t complete_cb)
-{
- return tuh_cdc_set_control_line_state(dev_addr, false, false, complete_cb);
-}
-
-/** \brief Check if device support CDC Serial interface or not
- * \param[in] dev_addr device address
- * \retval true if device supports
- * \retval false if device does not support or is not mounted
- */
-bool tuh_cdc_serial_is_mounted(uint8_t dev_addr);
-
-/** \brief Check if the interface is currently busy or not
- * \param[in] dev_addr device address
- * \param[in] pipeid value from \ref cdc_pipeid_t to indicate target pipe.
- * \retval true if the interface is busy, meaning the stack is still transferring/waiting data from/to device
- * \retval false if the interface is not busy, meaning the stack successfully transferred data from/to device
- * \note This function is used to check if previous transfer is complete (success or error), so that the next transfer
- * can be scheduled. User needs to make sure the corresponding interface is mounted
- * (by \ref tuh_cdc_serial_is_mounted) before calling this function.
- */
-bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid);
-
-/** \brief Perform USB OUT transfer to device
- * \param[in] dev_addr device address
- * \param[in] p_data Buffer containing data. Must be accessible by USB controller (see \ref CFG_TUSB_MEM_SECTION)
- * \param[in] length Number of bytes to be transferred via USB bus
- * \retval TUSB_ERROR_NONE on success
- * \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
- * \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
- * \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
- * \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the
- * interface's callback function. \a p_data must be declared with \ref CFG_TUSB_MEM_SECTION.
- */
-bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify);
-
-/** \brief Perform USB IN transfer to get data from device
- * \param[in] dev_addr device address
- * \param[in] p_buffer Buffer containing received data. Must be accessible by USB controller (see \ref CFG_TUSB_MEM_SECTION)
- * \param[in] length Number of bytes to be transferred via USB bus
- * \retval TUSB_ERROR_NONE on success
- * \retval TUSB_ERROR_INTERFACE_IS_BUSY if the interface is already transferring data with device
- * \retval TUSB_ERROR_DEVICE_NOT_READY if device is not yet configured (by SET CONFIGURED request)
- * \retval TUSB_ERROR_INVALID_PARA if input parameters are not correct
- * \note This function is non-blocking and returns immediately. The result of USB transfer will be reported by the
- * interface's callback function. \a p_data must be declared with \ref CFG_TUSB_MEM_SECTION.
- */
-bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify);
-
-//--------------------------------------------------------------------+
-// CDC APPLICATION CALLBACKS
-//--------------------------------------------------------------------+
-
-/** \brief Callback function that is invoked when an transferring event occurred
- * \param[in] dev_addr Address of device
- * \param[in] event an value from \ref xfer_result_t
- * \param[in] pipe_id value from \ref cdc_pipeid_t indicate the pipe
- * \param[in] xferred_bytes Number of bytes transferred via USB bus
- * \note event can be one of following
- * - XFER_RESULT_SUCCESS : previously scheduled transfer completes successfully.
- * - XFER_RESULT_FAILED : previously scheduled transfer encountered a transaction error.
- * - XFER_RESULT_STALLED : previously scheduled transfer is stalled by device.
- * \note
- */
-void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes);
-
-/// @} // group CDC_Serial_Host
-/// @}
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void cdch_init (void);
-bool cdch_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
-bool cdch_set_config (uint8_t dev_addr, uint8_t itf_num);
-bool cdch_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
-void cdch_close (uint8_t dev_addr);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CDC_HOST_H_ */
diff --git a/tinyusb/src/class/cdc/cdc_rndis.h b/tinyusb/src/class/cdc/cdc_rndis.h
deleted file mode 100755
index e0f129fe..00000000
--- a/tinyusb/src/class/cdc/cdc_rndis.h
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/** \ingroup ClassDriver_CDC Communication Device Class (CDC)
- * \defgroup CDC_RNDIS Remote Network Driver Interface Specification (RNDIS)
- * @{
- * \defgroup CDC_RNDIS_Common Common Definitions
- * @{ */
-
-#ifndef _TUSB_CDC_RNDIS_H_
-#define _TUSB_CDC_RNDIS_H_
-
-#include "cdc.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#ifdef __CC_ARM
-#pragma diag_suppress 66 // Suppress Keil warnings #66-D: enumeration value is out of "int" range
-#endif
-
-/// RNDIS Message Types
-typedef enum
-{
- RNDIS_MSG_PACKET = 0x00000001UL, ///< The host and device use this to send network data to one another.
-
- RNDIS_MSG_INITIALIZE = 0x00000002UL, ///< Sent by the host to initialize the device.
- RNDIS_MSG_INITIALIZE_CMPLT = 0x80000002UL, ///< Device response to an initialize message.
-
- RNDIS_MSG_HALT = 0x00000003UL, ///< Sent by the host to halt the device. This does not have a response. It is optional for the device to send this message to the host.
-
- RNDIS_MSG_QUERY = 0x00000004UL, ///< Sent by the host to send a query OID.
- RNDIS_MSG_QUERY_CMPLT = 0x80000004UL, ///< Device response to a query OID.
-
- RNDIS_MSG_SET = 0x00000005UL, ///< Sent by the host to send a set OID.
- RNDIS_MSG_SET_CMPLT = 0x80000005UL, ///< Device response to a set OID.
-
- RNDIS_MSG_RESET = 0x00000006UL, ///< Sent by the host to perform a soft reset on the device.
- RNDIS_MSG_RESET_CMPLT = 0x80000006UL, ///< Device response to reset message.
-
- RNDIS_MSG_INDICATE_STATUS = 0x00000007UL, ///< Sent by the device to indicate its status or an error when an unrecognized message is received.
-
- RNDIS_MSG_KEEP_ALIVE = 0x00000008UL, ///< During idle periods, sent every few seconds by the host to check that the device is still responsive. It is optional for the device to send this message to check if the host is active.
- RNDIS_MSG_KEEP_ALIVE_CMPLT = 0x80000008UL ///< The device response to a keepalivemessage. The host can respond with this message to a keepalive message from the device when the device implements the optional KeepAliveTimer.
-}rndis_msg_type_t;
-
-/// RNDIS Message Status Values
-typedef enum
-{
- RNDIS_STATUS_SUCCESS = 0x00000000UL, ///< Success
- RNDIS_STATUS_FAILURE = 0xC0000001UL, ///< Unspecified error
- RNDIS_STATUS_INVALID_DATA = 0xC0010015UL, ///< Invalid data error
- RNDIS_STATUS_NOT_SUPPORTED = 0xC00000BBUL, ///< Unsupported request error
- RNDIS_STATUS_MEDIA_CONNECT = 0x4001000BUL, ///< Device is connected to a network medium.
- RNDIS_STATUS_MEDIA_DISCONNECT = 0x4001000CUL ///< Device is disconnected from the medium.
-}rndis_msg_status_t;
-
-#ifdef __CC_ARM
-#pragma diag_default 66 // return Keil 66 to normal severity
-#endif
-
-//--------------------------------------------------------------------+
-// MESSAGE STRUCTURE
-//--------------------------------------------------------------------+
-
-//------------- Initialize -------------//
-/// \brief Initialize Message
-/// \details This message MUST be sent by the host to initialize the device.
-typedef struct {
- uint32_t type ; ///< Message type, must be \ref RNDIS_MSG_INITIALIZE
- uint32_t length ; ///< Message length in bytes, must be 0x18
- uint32_t request_id ; ///< A 32-bit integer value, generated by the host, used to match the host's sent request to the response from the device.
- uint32_t major_version ; ///< The major version of the RNDIS Protocol implemented by the host.
- uint32_t minor_version ; ///< The minor version of the RNDIS Protocol implemented by the host
- uint32_t max_xfer_size ; ///< The maximum size, in bytes, of any single bus data transfer that the host expects to receive from the device.
-}rndis_msg_initialize_t;
-
-/// \brief Initialize Complete Message
-/// \details This message MUST be sent by the device in response to an initialize message.
-typedef struct {
- uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_INITIALIZE_CMPLT
- uint32_t length ; ///< Message length in bytes, must be 0x30
- uint32_t request_id ; ///< A 32-bit integer value from \a request_id field of the \ref rndis_msg_initialize_t to which this message is a response.
- uint32_t status ; ///< The initialization status of the device, has value from \ref rndis_msg_status_t
- uint32_t major_version ; ///< the highest-numbered RNDIS Protocol version supported by the device.
- uint32_t minor_version ; ///< the highest-numbered RNDIS Protocol version supported by the device.
- uint32_t device_flags ; ///< MUST be set to 0x000000010. Other values are reserved for future use.
- uint32_t medium ; ///< is 0x00 for RNDIS_MEDIUM_802_3
- uint32_t max_packet_per_xfer ; ///< The maximum number of concatenated \ref RNDIS_MSG_PACKET messages that the device can handle in a single bus transfer to it. This value MUST be at least 1.
- uint32_t max_xfer_size ; ///< The maximum size, in bytes, of any single bus data transfer that the device expects to receive from the host.
- uint32_t packet_alignment_factor ; ///< The byte alignment the device expects for each RNDIS message that is part of a multimessage transfer to it. The value is specified as an exponent of 2; for example, the host uses 2<SUP>{PacketAlignmentFactor}</SUP> as the alignment value.
- uint32_t reserved[2] ;
-} rndis_msg_initialize_cmplt_t;
-
-//------------- Query -------------//
-/// \brief Query Message
-/// \details This message MUST be sent by the host to query an OID.
-typedef struct {
- uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_QUERY
- uint32_t length ; ///< Message length in bytes, including the header and the \a oid_buffer
- uint32_t request_id ; ///< A 32-bit integer value, generated by the host, used to match the host's sent request to the response from the device.
- uint32_t oid ; ///< The integer value of the host operating system-defined identifier, for the parameter of the device being queried for.
- uint32_t buffer_length ; ///< The length, in bytes, of the input data required for the OID query. This MUST be set to 0 when there is no input data associated with the OID.
- uint32_t buffer_offset ; ///< The offset, in bytes, from the beginning of \a request_id field where the input data for the query is located in the message. This value MUST be set to 0 when there is no input data associated with the OID.
- uint32_t reserved ;
- uint8_t oid_buffer[] ; ///< Flexible array contains the input data supplied by the host, required for the OID query request processing by the device, as per the host NDIS specification.
-} rndis_msg_query_t, rndis_msg_set_t;
-
-TU_VERIFY_STATIC(sizeof(rndis_msg_query_t) == 28, "Make sure flexible array member does not affect layout");
-
-/// \brief Query Complete Message
-/// \details This message MUST be sent by the device in response to a query OID message.
-typedef struct {
- uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_QUERY_CMPLT
- uint32_t length ; ///< Message length in bytes, including the header and the \a oid_buffer
- uint32_t request_id ; ///< A 32-bit integer value from \a request_id field of the \ref rndis_msg_query_t to which this message is a response.
- uint32_t status ; ///< The status of processing for the query request, has value from \ref rndis_msg_status_t.
- uint32_t buffer_length ; ///< The length, in bytes, of the data in the response to the query. This MUST be set to 0 when there is no OIDInputBuffer.
- uint32_t buffer_offset ; ///< The offset, in bytes, from the beginning of \a request_id field where the response data for the query is located in the message. This MUST be set to 0 when there is no \ref oid_buffer.
- uint8_t oid_buffer[] ; ///< Flexible array member contains the response data to the OID query request as specified by the host.
-} rndis_msg_query_cmplt_t;
-
-TU_VERIFY_STATIC(sizeof(rndis_msg_query_cmplt_t) == 24, "Make sure flexible array member does not affect layout");
-
-//------------- Reset -------------//
-/// \brief Reset Message
-/// \details This message MUST be sent by the host to perform a soft reset on the device.
-typedef struct {
- uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_RESET
- uint32_t length ; ///< Message length in bytes, MUST be 0x06
- uint32_t reserved ;
-} rndis_msg_reset_t;
-
-/// \brief Reset Complete Message
-/// \details This message MUST be sent by the device in response to a reset message.
-typedef struct {
- uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_RESET_CMPLT
- uint32_t length ; ///< Message length in bytes, MUST be 0x10
- uint32_t status ; ///< The status of processing for the \ref rndis_msg_reset_t, has value from \ref rndis_msg_status_t.
- uint32_t addressing_reset ; ///< This field indicates whether the addressing information, which is the multicast address list or packet filter, has been lost during the reset operation. This MUST be set to 0x00000001 if the device requires that the host to resend addressing information or MUST be set to zero otherwise.
-} rndis_msg_reset_cmplt_t;
-
-//typedef struct {
-// uint32_t type;
-// uint32_t length;
-// uint32_t status;
-// uint32_t buffer_length;
-// uint32_t buffer_offset;
-// uint32_t diagnostic_status; // optional
-// uint32_t diagnostic_error_offset; // optional
-// uint32_t status_buffer[0]; // optional
-//} rndis_msg_indicate_status_t;
-
-/// \brief Keep Alive Message
-/// \details This message MUST be sent by the host to check that device is still responsive. It is optional for the device to send this message to check if the host is active
-typedef struct {
- uint32_t type ; ///< Message Type
- uint32_t length ; ///< Message length in bytes, MUST be 0x10
- uint32_t request_id ;
-} rndis_msg_keep_alive_t, rndis_msg_halt_t;
-
-/// \brief Set Complete Message
-/// \brief This message MUST be sent in response to a the request message
-typedef struct {
- uint32_t type ; ///< Message Type
- uint32_t length ; ///< Message length in bytes, MUST be 0x10
- uint32_t request_id ; ///< must be the same as requesting message
- uint32_t status ; ///< The status of processing for the request message request by the device to which this message is the response.
-} rndis_msg_set_cmplt_t, rndis_msg_keep_alive_cmplt_t;
-
-/// \brief Packet Data Message
-/// \brief This message MUST be used by the host and the device to send network data to one another.
-typedef struct {
- uint32_t type ; ///< Message Type, must be \ref RNDIS_MSG_PACKET
- uint32_t length ; ///< Message length in bytes, The total length of this RNDIS message including the header, payload, and padding.
- uint32_t data_offset ; ///< Specifies the offset, in bytes, from the start of this \a data_offset field of this message to the start of the data. This MUST be an integer multiple of 4.
- uint32_t data_length ; ///< Specifies the number of bytes in the payload of this message.
- uint32_t out_of_band_data_offet ; ///< Specifies the offset, in bytes, of the first out-of-band data record from the start of the DataOffset field in this message. MUST be an integer multiple of 4 when out-of-band data is present or set to 0 otherwise. When there are multiple out-ofband data records, each subsequent record MUST immediately follow the previous out-of-band data record.
- uint32_t out_of_band_data_length ; ///< Specifies, in bytes, the total length of the out-of-band data.
- uint32_t num_out_of_band_data_elements ; ///< Specifies the number of out-of-band records in this message.
- uint32_t per_packet_info_offset ; ///< Specifies the offset, in bytes, of the start of per-packet-info data record from the start of the \a data_offset field in this message. MUST be an integer multiple of 4 when per-packet-info data record is present or MUST be set to 0 otherwise. When there are multiple per-packet-info data records, each subsequent record MUST immediately follow the previous record.
- uint32_t per_packet_info_length ; ///< Specifies, in bytes, the total length of per-packetinformation contained in this message.
- uint32_t reserved[2] ;
- uint32_t payload[0] ; ///< Network data contained in this message.
-
- // uint8_t padding[0]
- // Additional bytes of zeros added at the end of the message to comply with
- // the internal and external padding requirements. Internal padding SHOULD be as per the
- // specification of the out-of-band data record and per-packet-info data record. The external
- //padding size SHOULD be determined based on the PacketAlignmentFactor field specification
- //in REMOTE_NDIS_INITIALIZE_CMPLT message by the device, when multiple
- //REMOTE_NDIS_PACKET_MSG messages are bundled together in a single bus-native message.
- //In this case, all but the very last REMOTE_NDIS_PACKET_MSG MUST respect the
- //PacketAlignmentFactor field.
-
- // rndis_msg_packet_t [0] : (optional) more packet if multiple packet per bus transaction is supported
-} rndis_msg_packet_t;
-
-
-typedef struct {
- uint32_t size ; ///< Length, in bytes, of this header and appended data and padding. This value MUST be an integer multiple of 4.
- uint32_t type ; ///< MUST be as per host operating system specification.
- uint32_t offset ; ///< The byte offset from the beginning of this record to the beginning of data.
- uint32_t data[0] ; ///< Flexible array contains data
-} rndis_msg_out_of_band_data_t, rndis_msg_per_packet_info_t;
-
-//--------------------------------------------------------------------+
-// NDIS Object ID
-//--------------------------------------------------------------------+
-
-/// NDIS Object ID
-typedef enum
-{
- //------------- General Required OIDs -------------//
- RNDIS_OID_GEN_SUPPORTED_LIST = 0x00010101, ///< List of supported OIDs
- RNDIS_OID_GEN_HARDWARE_STATUS = 0x00010102, ///< Hardware status
- RNDIS_OID_GEN_MEDIA_SUPPORTED = 0x00010103, ///< Media types supported (encoded)
- RNDIS_OID_GEN_MEDIA_IN_USE = 0x00010104, ///< Media types in use (encoded)
- RNDIS_OID_GEN_MAXIMUM_LOOKAHEAD = 0x00010105, ///<
- RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE = 0x00010106, ///< Maximum frame size in bytes
- RNDIS_OID_GEN_LINK_SPEED = 0x00010107, ///< Link speed in units of 100 bps
- RNDIS_OID_GEN_TRANSMIT_BUFFER_SPACE = 0x00010108, ///< Transmit buffer space
- RNDIS_OID_GEN_RECEIVE_BUFFER_SPACE = 0x00010109, ///< Receive buffer space
- RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE = 0x0001010A, ///< Minimum amount of storage, in bytes, that a single packet occupies in the transmit buffer space of the NIC
- RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE = 0x0001010B, ///< Amount of storage, in bytes, that a single packet occupies in the receive buffer space of the NIC
- RNDIS_OID_GEN_VENDOR_ID = 0x0001010C, ///< Vendor NIC code
- RNDIS_OID_GEN_VENDOR_DESCRIPTION = 0x0001010D, ///< Vendor network card description
- RNDIS_OID_GEN_CURRENT_PACKET_FILTER = 0x0001010E, ///< Current packet filter (encoded)
- RNDIS_OID_GEN_CURRENT_LOOKAHEAD = 0x0001010F, ///< Current lookahead size in bytes
- RNDIS_OID_GEN_DRIVER_VERSION = 0x00010110, ///< NDIS version number used by the driver
- RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE = 0x00010111, ///< Maximum total packet length in bytes
- RNDIS_OID_GEN_PROTOCOL_OPTIONS = 0x00010112, ///< Optional protocol flags (encoded)
- RNDIS_OID_GEN_MAC_OPTIONS = 0x00010113, ///< Optional NIC flags (encoded)
- RNDIS_OID_GEN_MEDIA_CONNECT_STATUS = 0x00010114, ///< Whether the NIC is connected to the network
- RNDIS_OID_GEN_MAXIMUM_SEND_PACKETS = 0x00010115, ///< The maximum number of send packets the driver can accept per call to its MiniportSendPacketsfunction
-
- //------------- General Optional OIDs -------------//
- RNDIS_OID_GEN_VENDOR_DRIVER_VERSION = 0x00010116, ///< Vendor-assigned version number of the driver
- RNDIS_OID_GEN_SUPPORTED_GUIDS = 0x00010117, ///< The custom GUIDs (Globally Unique Identifier) supported by the miniport driver
- RNDIS_OID_GEN_NETWORK_LAYER_ADDRESSES = 0x00010118, ///< List of network-layer addresses associated with the binding between a transport and the driver
- RNDIS_OID_GEN_TRANSPORT_HEADER_OFFSET = 0x00010119, ///< Size of packets' additional headers
- RNDIS_OID_GEN_MEDIA_CAPABILITIES = 0x00010201, ///<
- RNDIS_OID_GEN_PHYSICAL_MEDIUM = 0x00010202, ///< Physical media supported by the miniport driver (encoded)
-
- //------------- 802.3 Objects (Ethernet) -------------//
- RNDIS_OID_802_3_PERMANENT_ADDRESS = 0x01010101, ///< Permanent station address
- RNDIS_OID_802_3_CURRENT_ADDRESS = 0x01010102, ///< Current station address
- RNDIS_OID_802_3_MULTICAST_LIST = 0x01010103, ///< Current multicast address list
- RNDIS_OID_802_3_MAXIMUM_LIST_SIZE = 0x01010104, ///< Maximum size of multicast address list
-} rndis_oid_type_t;
-
-/// RNDIS Packet Filter Bits \ref RNDIS_OID_GEN_CURRENT_PACKET_FILTER.
-typedef enum
-{
- RNDIS_PACKET_TYPE_DIRECTED = 0x00000001, ///< Directed packets. Directed packets contain a destination address equal to the station address of the NIC.
- RNDIS_PACKET_TYPE_MULTICAST = 0x00000002, ///< Multicast address packets sent to addresses in the multicast address list.
- RNDIS_PACKET_TYPE_ALL_MULTICAST = 0x00000004, ///< All multicast address packets, not just the ones enumerated in the multicast address list.
- RNDIS_PACKET_TYPE_BROADCAST = 0x00000008, ///< Broadcast packets.
- RNDIS_PACKET_TYPE_SOURCE_ROUTING = 0x00000010, ///< All source routing packets. If the protocol driver sets this bit, the NDIS library attempts to act as a source routing bridge.
- RNDIS_PACKET_TYPE_PROMISCUOUS = 0x00000020, ///< Specifies all packets regardless of whether VLAN filtering is enabled or not and whether the VLAN identifier matches or not.
- RNDIS_PACKET_TYPE_SMT = 0x00000040, ///< SMT packets that an FDDI NIC receives.
- RNDIS_PACKET_TYPE_ALL_LOCAL = 0x00000080, ///< All packets sent by installed protocols and all packets indicated by the NIC that is identified by a given NdisBindingHandle.
- RNDIS_PACKET_TYPE_GROUP = 0x00001000, ///< Packets sent to the current group address.
- RNDIS_PACKET_TYPE_ALL_FUNCTIONAL = 0x00002000, ///< All functional address packets, not just the ones in the current functional address.
- RNDIS_PACKET_TYPE_FUNCTIONAL = 0x00004000, ///< Functional address packets sent to addresses included in the current functional address.
- RNDIS_PACKET_TYPE_MAC_FRAME = 0x00008000, ///< NIC driver frames that a Token Ring NIC receives.
- RNDIS_PACKET_TYPE_NO_LOCAL = 0x00010000,
-} rndis_packet_filter_type_t;
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CDC_RNDIS_H_ */
-
-/** @} */
-/** @} */
diff --git a/tinyusb/src/class/cdc/cdc_rndis_host.c b/tinyusb/src/class/cdc/cdc_rndis_host.c
deleted file mode 100755
index cc4ffd1c..00000000
--- a/tinyusb/src/class/cdc/cdc_rndis_host.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_CDC && CFG_TUH_CDC_RNDIS)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "common/tusb_common.h"
-#include "cdc_host.h"
-#include "cdc_rndis_host.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-#define RNDIS_MSG_PAYLOAD_MAX (1024*4)
-
-CFG_TUSB_MEM_SECTION static uint8_t msg_notification[CFG_TUH_DEVICE_MAX][8];
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t msg_payload[RNDIS_MSG_PAYLOAD_MAX];
-
-static rndish_data_t rndish_data[CFG_TUH_DEVICE_MAX];
-
-// TODO Microsoft requires message length for any get command must be at least 4096 bytes
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-static tusb_error_t rndis_body_subtask(void);
-static tusb_error_t send_message_get_response_subtask( uint8_t dev_addr, cdch_data_t *p_cdc,
- uint8_t * p_mess, uint32_t mess_length,
- uint8_t *p_response );
-
-//--------------------------------------------------------------------+
-// APPLICATION API
-//--------------------------------------------------------------------+
-tusb_error_t tusbh_cdc_rndis_get_mac_addr(uint8_t dev_addr, uint8_t mac_address[6])
-{
- TU_ASSERT( tusbh_cdc_rndis_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED);
- TU_VERIFY( mac_address, TUSB_ERROR_INVALID_PARA);
-
- memcpy(mac_address, rndish_data[dev_addr-1].mac_address, 6);
-
- return TUSB_ERROR_NONE;
-}
-
-//--------------------------------------------------------------------+
-// IMPLEMENTATION
-//--------------------------------------------------------------------+
-
-// To enable the TASK_ASSERT style (quick return on false condition) in a real RTOS, a task must act as a wrapper
-// and is used mainly to call subtasks. Within a subtask return statement can be called freely, the task with
-// forever loop cannot have any return at all.
-OSAL_TASK_FUNCTION(cdch_rndis_task) (void* param;)
-{
- OSAL_TASK_BEGIN
- rndis_body_subtask();
- OSAL_TASK_END
-}
-
-static tusb_error_t rndis_body_subtask(void)
-{
- static uint8_t relative_addr;
-
- OSAL_SUBTASK_BEGIN
-
- for (relative_addr = 0; relative_addr < CFG_TUH_DEVICE_MAX; relative_addr++)
- {
-
- }
-
- osal_task_delay(100);
-
- OSAL_SUBTASK_END
-}
-
-//--------------------------------------------------------------------+
-// RNDIS-CDC Driver API
-//--------------------------------------------------------------------+
-void rndish_init(void)
-{
- tu_memclr(rndish_data, sizeof(rndish_data_t)*CFG_TUH_DEVICE_MAX);
-
- //------------- Task creation -------------//
-
- //------------- semaphore creation for notificaiton pipe -------------//
- for(uint8_t i=0; i<CFG_TUH_DEVICE_MAX; i++)
- {
- rndish_data[i].sem_notification_hdl = osal_semaphore_create( OSAL_SEM_REF(rndish_data[i].semaphore_notification) );
- }
-}
-
-void rndish_close(uint8_t dev_addr)
-{
- osal_semaphore_reset( rndish_data[dev_addr-1].sem_notification_hdl );
-// tu_memclr(&rndish_data[dev_addr-1], sizeof(rndish_data_t)); TODO need to move semaphore & its handle out before memclr
-}
-
-
-static rndis_msg_initialize_t const msg_init =
-{
- .type = RNDIS_MSG_INITIALIZE,
- .length = sizeof(rndis_msg_initialize_t),
- .request_id = 1, // TODO should use some magic number
- .major_version = 1,
- .minor_version = 0,
- .max_xfer_size = 0x4000 // TODO mimic windows
-};
-
-static rndis_msg_query_t const msg_query_permanent_addr =
-{
- .type = RNDIS_MSG_QUERY,
- .length = sizeof(rndis_msg_query_t)+6,
- .request_id = 1,
- .oid = RNDIS_OID_802_3_PERMANENT_ADDRESS,
- .buffer_length = 6,
- .buffer_offset = 20,
-};
-
-static rndis_msg_set_t const msg_set_packet_filter =
-{
- .type = RNDIS_MSG_SET,
- .length = sizeof(rndis_msg_set_t)+4,
- .request_id = 1,
- .oid = RNDIS_OID_GEN_CURRENT_PACKET_FILTER,
- .buffer_length = 4,
- .buffer_offset = 20,
-};
-
-tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc)
-{
- tusb_error_t error;
-
- OSAL_SUBTASK_BEGIN
-
- //------------- Message Initialize -------------//
- memcpy(msg_payload, &msg_init, sizeof(rndis_msg_initialize_t));
- STASK_INVOKE(
- send_message_get_response_subtask( dev_addr, p_cdc,
- msg_payload, sizeof(rndis_msg_initialize_t),
- msg_payload),
- error
- );
- if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error);
-
- // TODO currently not support multiple data packets per xfer
- rndis_msg_initialize_cmplt_t * const p_init_cmpt = (rndis_msg_initialize_cmplt_t *) msg_payload;
- STASK_ASSERT(p_init_cmpt->type == RNDIS_MSG_INITIALIZE_CMPLT && p_init_cmpt->status == RNDIS_STATUS_SUCCESS &&
- p_init_cmpt->max_packet_per_xfer == 1 && p_init_cmpt->max_xfer_size <= RNDIS_MSG_PAYLOAD_MAX);
- rndish_data[dev_addr-1].max_xfer_size = p_init_cmpt->max_xfer_size;
-
- //------------- Message Query 802.3 Permanent Address -------------//
- memcpy(msg_payload, &msg_query_permanent_addr, sizeof(rndis_msg_query_t));
- tu_memclr(msg_payload + sizeof(rndis_msg_query_t), 6); // 6 bytes for MAC address
-
- STASK_INVOKE(
- send_message_get_response_subtask( dev_addr, p_cdc,
- msg_payload, sizeof(rndis_msg_query_t) + 6,
- msg_payload),
- error
- );
- if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error);
-
- rndis_msg_query_cmplt_t * const p_query_cmpt = (rndis_msg_query_cmplt_t *) msg_payload;
- STASK_ASSERT(p_query_cmpt->type == RNDIS_MSG_QUERY_CMPLT && p_query_cmpt->status == RNDIS_STATUS_SUCCESS);
- memcpy(rndish_data[dev_addr-1].mac_address, msg_payload + 8 + p_query_cmpt->buffer_offset, 6);
-
- //------------- Set OID_GEN_CURRENT_PACKET_FILTER to (DIRECTED | MULTICAST | BROADCAST) -------------//
- memcpy(msg_payload, &msg_set_packet_filter, sizeof(rndis_msg_set_t));
- tu_memclr(msg_payload + sizeof(rndis_msg_set_t), 4); // 4 bytes for filter flags
- ((rndis_msg_set_t*) msg_payload)->oid_buffer[0] = (RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_MULTICAST | RNDIS_PACKET_TYPE_BROADCAST);
-
- STASK_INVOKE(
- send_message_get_response_subtask( dev_addr, p_cdc,
- msg_payload, sizeof(rndis_msg_set_t) + 4,
- msg_payload),
- error
- );
- if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error);
-
- rndis_msg_set_cmplt_t * const p_set_cmpt = (rndis_msg_set_cmplt_t *) msg_payload;
- STASK_ASSERT(p_set_cmpt->type == RNDIS_MSG_SET_CMPLT && p_set_cmpt->status == RNDIS_STATUS_SUCCESS);
-
- tusbh_cdc_rndis_mounted_cb(dev_addr);
-
- OSAL_SUBTASK_END
-}
-
-void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes)
-{
- if ( pipehandle_is_equal(pipe_hdl, p_cdc->pipe_notification) )
- {
- osal_semaphore_post( rndish_data[pipe_hdl.dev_addr-1].sem_notification_hdl );
- }
-}
-
-//--------------------------------------------------------------------+
-// INTERNAL & HELPER
-//--------------------------------------------------------------------+
-static tusb_error_t send_message_get_response_subtask( uint8_t dev_addr, cdch_data_t *p_cdc,
- uint8_t * p_mess, uint32_t mess_length,
- uint8_t *p_response)
-{
- tusb_error_t error;
-
- OSAL_SUBTASK_BEGIN
-
- //------------- Send RNDIS Control Message -------------//
- STASK_INVOKE(
- usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_INTERFACE),
- CDC_REQUEST_SEND_ENCAPSULATED_COMMAND, 0, p_cdc->interface_number,
- mess_length, p_mess),
- error
- );
- if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error);
-
- //------------- waiting for Response Available notification -------------//
- (void) usbh_edpt_xfer(p_cdc->pipe_notification, msg_notification[dev_addr-1], 8);
- osal_semaphore_wait(rndish_data[dev_addr-1].sem_notification_hdl, OSAL_TIMEOUT_NORMAL, &error);
- if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error);
- STASK_ASSERT(msg_notification[dev_addr-1][0] == 1);
-
- //------------- Get RNDIS Message Initialize Complete -------------//
- STASK_INVOKE(
- usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_INTERFACE),
- CDC_REQUEST_GET_ENCAPSULATED_RESPONSE, 0, p_cdc->interface_number,
- RNDIS_MSG_PAYLOAD_MAX, p_response),
- error
- );
- if ( TUSB_ERROR_NONE != error ) STASK_RETURN(error);
-
- OSAL_SUBTASK_END
-}
-
-//static tusb_error_t send_process_msg_initialize_subtask(uint8_t dev_addr, cdch_data_t *p_cdc)
-//{
-// tusb_error_t error;
-//
-// OSAL_SUBTASK_BEGIN
-//
-// *((rndis_msg_initialize_t*) msg_payload) = (rndis_msg_initialize_t)
-// {
-// .type = RNDIS_MSG_INITIALIZE,
-// .length = sizeof(rndis_msg_initialize_t),
-// .request_id = 1, // TODO should use some magic number
-// .major_version = 1,
-// .minor_version = 0,
-// .max_xfer_size = 0x4000 // TODO mimic windows
-// };
-//
-//
-//
-// OSAL_SUBTASK_END
-//}
-#endif
diff --git a/tinyusb/src/class/cdc/cdc_rndis_host.h b/tinyusb/src/class/cdc/cdc_rndis_host.h
deleted file mode 100755
index 170cb3b0..00000000
--- a/tinyusb/src/class/cdc/cdc_rndis_host.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/** \ingroup CDC_RNDIS
- * \defgroup CDC_RNSID_Host Host
- * @{ */
-
-#ifndef _TUSB_CDC_RNDIS_HOST_H_
-#define _TUSB_CDC_RNDIS_HOST_H_
-
-#include "common/tusb_common.h"
-#include "host/usbh.h"
-#include "cdc_rndis.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// INTERNAL RNDIS-CDC Driver API
-//--------------------------------------------------------------------+
-typedef struct {
- OSAL_SEM_DEF(semaphore_notification);
- osal_semaphore_handle_t sem_notification_hdl; // used to wait on notification pipe
- uint32_t max_xfer_size; // got from device's msg initialize complete
- uint8_t mac_address[6];
-}rndish_data_t;
-
-void rndish_init(void);
-tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc);
-void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
-void rndish_close(uint8_t dev_addr);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_CDC_RNDIS_HOST_H_ */
-
-/** @} */
diff --git a/tinyusb/src/class/dfu/dfu.h b/tinyusb/src/class/dfu/dfu.h
deleted file mode 100755
index 114c827b..00000000
--- a/tinyusb/src/class/dfu/dfu.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2021 XMOS LIMITED
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_DFU_H_
-#define _TUSB_DFU_H_
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Common Definitions
-//--------------------------------------------------------------------+
-
-// DFU Protocol
-typedef enum
-{
- DFU_PROTOCOL_RT = 0x01,
- DFU_PROTOCOL_DFU = 0x02,
-} dfu_protocol_type_t;
-
-// DFU Descriptor Type
-typedef enum
-{
- DFU_DESC_FUNCTIONAL = 0x21,
-} dfu_descriptor_type_t;
-
-// DFU Requests
-typedef enum {
- DFU_REQUEST_DETACH = 0,
- DFU_REQUEST_DNLOAD = 1,
- DFU_REQUEST_UPLOAD = 2,
- DFU_REQUEST_GETSTATUS = 3,
- DFU_REQUEST_CLRSTATUS = 4,
- DFU_REQUEST_GETSTATE = 5,
- DFU_REQUEST_ABORT = 6,
-} dfu_requests_t;
-
-// DFU States
-typedef enum {
- APP_IDLE = 0,
- APP_DETACH = 1,
- DFU_IDLE = 2,
- DFU_DNLOAD_SYNC = 3,
- DFU_DNBUSY = 4,
- DFU_DNLOAD_IDLE = 5,
- DFU_MANIFEST_SYNC = 6,
- DFU_MANIFEST = 7,
- DFU_MANIFEST_WAIT_RESET = 8,
- DFU_UPLOAD_IDLE = 9,
- DFU_ERROR = 10,
-} dfu_state_t;
-
-// DFU Status
-typedef enum {
- DFU_STATUS_OK = 0x00,
- DFU_STATUS_ERR_TARGET = 0x01,
- DFU_STATUS_ERR_FILE = 0x02,
- DFU_STATUS_ERR_WRITE = 0x03,
- DFU_STATUS_ERR_ERASE = 0x04,
- DFU_STATUS_ERR_CHECK_ERASED = 0x05,
- DFU_STATUS_ERR_PROG = 0x06,
- DFU_STATUS_ERR_VERIFY = 0x07,
- DFU_STATUS_ERR_ADDRESS = 0x08,
- DFU_STATUS_ERR_NOTDONE = 0x09,
- DFU_STATUS_ERR_FIRMWARE = 0x0A,
- DFU_STATUS_ERR_VENDOR = 0x0B,
- DFU_STATUS_ERR_USBR = 0x0C,
- DFU_STATUS_ERR_POR = 0x0D,
- DFU_STATUS_ERR_UNKNOWN = 0x0E,
- DFU_STATUS_ERR_STALLEDPKT = 0x0F,
-} dfu_status_t;
-
-#define DFU_ATTR_CAN_DOWNLOAD (1u << 0)
-#define DFU_ATTR_CAN_UPLOAD (1u << 1)
-#define DFU_ATTR_MANIFESTATION_TOLERANT (1u << 2)
-#define DFU_ATTR_WILL_DETACH (1u << 3)
-
-// DFU Status Request Payload
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bStatus;
- uint8_t bwPollTimeout[3];
- uint8_t bState;
- uint8_t iString;
-} dfu_status_response_t;
-
-TU_VERIFY_STATIC( sizeof(dfu_status_response_t) == 6, "size is not correct");
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_DFU_H_ */
diff --git a/tinyusb/src/class/dfu/dfu_device.c b/tinyusb/src/class/dfu/dfu_device.c
deleted file mode 100755
index 28abf6e8..00000000
--- a/tinyusb/src/class/dfu/dfu_device.c
+++ /dev/null
@@ -1,458 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2021 XMOS LIMITED
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_DFU)
-
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "dfu_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-typedef struct
-{
- uint8_t attrs;
- uint8_t alt;
-
- dfu_state_t state;
- dfu_status_t status;
-
- bool flashing_in_progress;
- uint16_t block;
- uint16_t length;
-
- CFG_TUSB_MEM_ALIGN uint8_t transfer_buf[CFG_TUD_DFU_XFER_BUFSIZE];
-} dfu_state_ctx_t;
-
-// Only a single dfu state is allowed
-CFG_TUSB_MEM_SECTION static dfu_state_ctx_t _dfu_ctx;
-
-static void reset_state(void)
-{
- _dfu_ctx.state = DFU_IDLE;
- _dfu_ctx.status = DFU_STATUS_OK;
- _dfu_ctx.flashing_in_progress = false;
-}
-
-static bool reply_getstatus(uint8_t rhport, tusb_control_request_t const * request, dfu_state_t state, dfu_status_t status, uint32_t timeout);
-static bool process_download_get_status(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-static bool process_manifest_get_status(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-
-//--------------------------------------------------------------------+
-// Debug
-//--------------------------------------------------------------------+
-#if CFG_TUSB_DEBUG >= 2
-
-static tu_lookup_entry_t const _dfu_request_lookup[] =
-{
- { .key = DFU_REQUEST_DETACH , .data = "DETACH" },
- { .key = DFU_REQUEST_DNLOAD , .data = "DNLOAD" },
- { .key = DFU_REQUEST_UPLOAD , .data = "UPLOAD" },
- { .key = DFU_REQUEST_GETSTATUS , .data = "GETSTATUS" },
- { .key = DFU_REQUEST_CLRSTATUS , .data = "CLRSTATUS" },
- { .key = DFU_REQUEST_GETSTATE , .data = "GETSTATE" },
- { .key = DFU_REQUEST_ABORT , .data = "ABORT" },
-};
-
-static tu_lookup_table_t const _dfu_request_table =
-{
- .count = TU_ARRAY_SIZE(_dfu_request_lookup),
- .items = _dfu_request_lookup
-};
-
-static tu_lookup_entry_t const _dfu_state_lookup[] =
-{
- { .key = APP_IDLE , .data = "APP_IDLE" },
- { .key = APP_DETACH , .data = "APP_DETACH" },
- { .key = DFU_IDLE , .data = "IDLE" },
- { .key = DFU_DNLOAD_SYNC , .data = "DNLOAD_SYNC" },
- { .key = DFU_DNBUSY , .data = "DNBUSY" },
- { .key = DFU_DNLOAD_IDLE , .data = "DNLOAD_IDLE" },
- { .key = DFU_MANIFEST_SYNC , .data = "MANIFEST_SYNC" },
- { .key = DFU_MANIFEST , .data = "MANIFEST" },
- { .key = DFU_MANIFEST_WAIT_RESET , .data = "MANIFEST_WAIT_RESET" },
- { .key = DFU_UPLOAD_IDLE , .data = "UPLOAD_IDLE" },
- { .key = DFU_ERROR , .data = "ERROR" },
-};
-
-static tu_lookup_table_t const _dfu_state_table =
-{
- .count = TU_ARRAY_SIZE(_dfu_state_lookup),
- .items = _dfu_state_lookup
-};
-
-static tu_lookup_entry_t const _dfu_status_lookup[] =
-{
- { .key = DFU_STATUS_OK , .data = "OK" },
- { .key = DFU_STATUS_ERR_TARGET , .data = "errTARGET" },
- { .key = DFU_STATUS_ERR_FILE , .data = "errFILE" },
- { .key = DFU_STATUS_ERR_WRITE , .data = "errWRITE" },
- { .key = DFU_STATUS_ERR_ERASE , .data = "errERASE" },
- { .key = DFU_STATUS_ERR_CHECK_ERASED , .data = "errCHECK_ERASED" },
- { .key = DFU_STATUS_ERR_PROG , .data = "errPROG" },
- { .key = DFU_STATUS_ERR_VERIFY , .data = "errVERIFY" },
- { .key = DFU_STATUS_ERR_ADDRESS , .data = "errADDRESS" },
- { .key = DFU_STATUS_ERR_NOTDONE , .data = "errNOTDONE" },
- { .key = DFU_STATUS_ERR_FIRMWARE , .data = "errFIRMWARE" },
- { .key = DFU_STATUS_ERR_VENDOR , .data = "errVENDOR" },
- { .key = DFU_STATUS_ERR_USBR , .data = "errUSBR" },
- { .key = DFU_STATUS_ERR_POR , .data = "errPOR" },
- { .key = DFU_STATUS_ERR_UNKNOWN , .data = "errUNKNOWN" },
- { .key = DFU_STATUS_ERR_STALLEDPKT , .data = "errSTALLEDPKT" },
-};
-
-static tu_lookup_table_t const _dfu_status_table =
-{
- .count = TU_ARRAY_SIZE(_dfu_status_lookup),
- .items = _dfu_status_lookup
-};
-
-#endif
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void dfu_moded_reset(uint8_t rhport)
-{
- (void) rhport;
-
- _dfu_ctx.attrs = 0;
- _dfu_ctx.alt = 0;
-
- reset_state();
-}
-
-void dfu_moded_init(void)
-{
- dfu_moded_reset(0);
-}
-
-uint16_t dfu_moded_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- (void) rhport;
-
- //------------- Interface (with Alt) descriptor -------------//
- uint8_t const itf_num = itf_desc->bInterfaceNumber;
- uint8_t alt_count = 0;
-
- uint16_t drv_len = 0;
- while(itf_desc->bInterfaceSubClass == TUD_DFU_APP_SUBCLASS && itf_desc->bInterfaceProtocol == DFU_PROTOCOL_DFU)
- {
- TU_ASSERT(max_len > drv_len, 0);
-
- // Alternate must have the same interface number
- TU_ASSERT(itf_desc->bInterfaceNumber == itf_num, 0);
-
- // Alt should increase by one every time
- TU_ASSERT(itf_desc->bAlternateSetting == alt_count, 0);
- alt_count++;
-
- drv_len += tu_desc_len(itf_desc);
- itf_desc = (tusb_desc_interface_t const *) tu_desc_next(itf_desc);
- }
-
- //------------- DFU Functional descriptor -------------//
- tusb_desc_dfu_functional_t const *func_desc = (tusb_desc_dfu_functional_t const *) itf_desc;
- TU_ASSERT(tu_desc_type(func_desc) == TUSB_DESC_FUNCTIONAL, 0);
- drv_len += sizeof(tusb_desc_dfu_functional_t);
-
- _dfu_ctx.attrs = func_desc->bAttributes;
-
- // CFG_TUD_DFU_XFER_BUFSIZE has to be set to the buffer size used in TUD_DFU_DESCRIPTOR
- uint16_t const transfer_size = tu_le16toh( tu_unaligned_read16((uint8_t*) func_desc + offsetof(tusb_desc_dfu_functional_t, wTransferSize)) );
- TU_ASSERT(transfer_size <= CFG_TUD_DFU_XFER_BUFSIZE, drv_len);
-
- return drv_len;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
-
- TU_LOG2(" DFU State : %s, Status: %s\r\n", tu_lookup_find(&_dfu_state_table, _dfu_ctx.state), tu_lookup_find(&_dfu_status_table, _dfu_ctx.status));
-
- if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD )
- {
- // Standard request include GET/SET_INTERFACE
- switch ( request->bRequest )
- {
- case TUSB_REQ_SET_INTERFACE:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- // Switch Alt interface and reset state machine
- _dfu_ctx.alt = (uint8_t) request->wValue;
- reset_state();
- return tud_control_status(rhport, request);
- }
- break;
-
- case TUSB_REQ_GET_INTERFACE:
- if(stage == CONTROL_STAGE_SETUP)
- {
- return tud_control_xfer(rhport, request, &_dfu_ctx.alt, 1);
- }
- break;
-
- // unsupported request
- default: return false;
- }
- }
- else if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS )
- {
- TU_LOG2(" DFU Request: %s\r\n", tu_lookup_find(&_dfu_request_table, request->bRequest));
-
- // Class request
- switch ( request->bRequest )
- {
- case DFU_REQUEST_DETACH:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- tud_control_status(rhport, request);
- }
- else if ( stage == CONTROL_STAGE_ACK )
- {
- if ( tud_dfu_detach_cb ) tud_dfu_detach_cb();
- }
- break;
-
- case DFU_REQUEST_CLRSTATUS:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- reset_state();
- tud_control_status(rhport, request);
- }
- break;
-
- case DFU_REQUEST_GETSTATE:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- tud_control_xfer(rhport, request, &_dfu_ctx.state, 1);
- }
- break;
-
- case DFU_REQUEST_ABORT:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- reset_state();
- tud_control_status(rhport, request);
- }
- else if ( stage == CONTROL_STAGE_ACK )
- {
- if ( tud_dfu_abort_cb ) tud_dfu_abort_cb(_dfu_ctx.alt);
- }
- break;
-
- case DFU_REQUEST_UPLOAD:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- TU_VERIFY(_dfu_ctx.attrs & DFU_ATTR_CAN_UPLOAD);
- TU_VERIFY(tud_dfu_upload_cb);
- TU_VERIFY(request->wLength <= CFG_TUD_DFU_XFER_BUFSIZE);
-
- uint16_t const xfer_len = tud_dfu_upload_cb(_dfu_ctx.alt, request->wValue, _dfu_ctx.transfer_buf, request->wLength);
-
- return tud_control_xfer(rhport, request, _dfu_ctx.transfer_buf, xfer_len);
- }
- break;
-
- case DFU_REQUEST_DNLOAD:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- TU_VERIFY(_dfu_ctx.attrs & DFU_ATTR_CAN_DOWNLOAD);
- TU_VERIFY(_dfu_ctx.state == DFU_IDLE || _dfu_ctx.state == DFU_DNLOAD_IDLE);
- TU_VERIFY(request->wLength <= CFG_TUD_DFU_XFER_BUFSIZE);
-
- // set to true for both download and manifest
- _dfu_ctx.flashing_in_progress = true;
-
- // save block and length for flashing
- _dfu_ctx.block = request->wValue;
- _dfu_ctx.length = request->wLength;
-
- if ( request->wLength )
- {
- // Download with payload -> transition to DOWNLOAD SYNC
- _dfu_ctx.state = DFU_DNLOAD_SYNC;
- return tud_control_xfer(rhport, request, _dfu_ctx.transfer_buf, request->wLength);
- }
- else
- {
- // Download is complete -> transition to MANIFEST SYNC
- _dfu_ctx.state = DFU_MANIFEST_SYNC;
- return tud_control_status(rhport, request);
- }
- }
- break;
-
- case DFU_REQUEST_GETSTATUS:
- switch ( _dfu_ctx.state )
- {
- case DFU_DNLOAD_SYNC:
- return process_download_get_status(rhport, stage, request);
- break;
-
- case DFU_MANIFEST_SYNC:
- return process_manifest_get_status(rhport, stage, request);
- break;
-
- default:
- if ( stage == CONTROL_STAGE_SETUP ) return reply_getstatus(rhport, request, _dfu_ctx.state, _dfu_ctx.status, 0);
- break;
- }
- break;
-
- default: return false; // stall unsupported request
- }
- }else
- {
- return false; // unsupported request
- }
-
- return true;
-}
-
-void tud_dfu_finish_flashing(uint8_t status)
-{
- _dfu_ctx.flashing_in_progress = false;
-
- if ( status == DFU_STATUS_OK )
- {
- if (_dfu_ctx.state == DFU_DNBUSY)
- {
- _dfu_ctx.state = DFU_DNLOAD_SYNC;
- }
- else if (_dfu_ctx.state == DFU_MANIFEST)
- {
- _dfu_ctx.state = (_dfu_ctx.attrs & DFU_ATTR_MANIFESTATION_TOLERANT)
- ? DFU_MANIFEST_SYNC : DFU_MANIFEST_WAIT_RESET;
- }
- }
- else
- {
- // failed while flashing, move to dfuError
- _dfu_ctx.state = DFU_ERROR;
- _dfu_ctx.status = (dfu_status_t)status;
- }
-}
-
-static bool process_download_get_status(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- if ( stage == CONTROL_STAGE_SETUP )
- {
- // only transition to next state on CONTROL_STAGE_ACK
- dfu_state_t next_state;
- uint32_t timeout;
-
- if ( _dfu_ctx.flashing_in_progress )
- {
- next_state = DFU_DNBUSY;
- timeout = tud_dfu_get_timeout_cb(_dfu_ctx.alt, (uint8_t) next_state);
- }
- else
- {
- next_state = DFU_DNLOAD_IDLE;
- timeout = 0;
- }
-
- return reply_getstatus(rhport, request, next_state, _dfu_ctx.status, timeout);
- }
- else if ( stage == CONTROL_STAGE_ACK )
- {
- if ( _dfu_ctx.flashing_in_progress )
- {
- _dfu_ctx.state = DFU_DNBUSY;
- tud_dfu_download_cb(_dfu_ctx.alt, _dfu_ctx.block, _dfu_ctx.transfer_buf, _dfu_ctx.length);
- }else
- {
- _dfu_ctx.state = DFU_DNLOAD_IDLE;
- }
- }
-
- return true;
-}
-
-static bool process_manifest_get_status(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- if ( stage == CONTROL_STAGE_SETUP )
- {
- // only transition to next state on CONTROL_STAGE_ACK
- dfu_state_t next_state;
- uint32_t timeout;
-
- if ( _dfu_ctx.flashing_in_progress )
- {
- next_state = DFU_MANIFEST;
- timeout = tud_dfu_get_timeout_cb(_dfu_ctx.alt, next_state);
- }
- else
- {
- next_state = DFU_IDLE;
- timeout = 0;
- }
-
- return reply_getstatus(rhport, request, next_state, _dfu_ctx.status, timeout);
- }
- else if ( stage == CONTROL_STAGE_ACK )
- {
- if ( _dfu_ctx.flashing_in_progress )
- {
- _dfu_ctx.state = DFU_MANIFEST;
- tud_dfu_manifest_cb(_dfu_ctx.alt);
- }
- else
- {
- _dfu_ctx.state = DFU_IDLE;
- }
- }
-
- return true;
-}
-
-static bool reply_getstatus(uint8_t rhport, tusb_control_request_t const * request, dfu_state_t state, dfu_status_t status, uint32_t timeout)
-{
- dfu_status_response_t resp;
- resp.bStatus = (uint8_t) status;
- resp.bwPollTimeout[0] = TU_U32_BYTE0(timeout);
- resp.bwPollTimeout[1] = TU_U32_BYTE1(timeout);
- resp.bwPollTimeout[2] = TU_U32_BYTE2(timeout);
- resp.bState = (uint8_t) state;
- resp.iString = 0;
-
- return tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_response_t));
-}
-
-#endif
diff --git a/tinyusb/src/class/dfu/dfu_device.h b/tinyusb/src/class/dfu/dfu_device.h
deleted file mode 100755
index fecf8596..00000000
--- a/tinyusb/src/class/dfu/dfu_device.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2021 XMOS LIMITED
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_DFU_DEVICE_H_
-#define _TUSB_DFU_DEVICE_H_
-
-#include "dfu.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Class Driver Default Configure & Validation
-//--------------------------------------------------------------------+
-
-#if !defined(CFG_TUD_DFU_XFER_BUFSIZE)
- #error "CFG_TUD_DFU_XFER_BUFSIZE must be defined, it has to be set to the buffer size used in TUD_DFU_DESCRIPTOR"
-#endif
-
-//--------------------------------------------------------------------+
-// Application API
-//--------------------------------------------------------------------+
-
-// Must be called when the application is done with flashing started by
-// tud_dfu_download_cb() and tud_dfu_manifest_cb().
-// status is DFU_STATUS_OK if successful, any other error status will cause state to enter dfuError
-void tud_dfu_finish_flashing(uint8_t status);
-
-//--------------------------------------------------------------------+
-// Application Callback API (weak is optional)
-//--------------------------------------------------------------------+
-
-// Note: alt is used as the partition number, in order to support multiple partitions like FLASH, EEPROM, etc.
-
-// Invoked right before tud_dfu_download_cb() (state=DFU_DNBUSY) or tud_dfu_manifest_cb() (state=DFU_MANIFEST)
-// Application return timeout in milliseconds (bwPollTimeout) for the next download/manifest operation.
-// During this period, USB host won't try to communicate with us.
-uint32_t tud_dfu_get_timeout_cb(uint8_t alt, uint8_t state);
-
-// Invoked when received DFU_DNLOAD (wLength>0) following by DFU_GETSTATUS (state=DFU_DNBUSY) requests
-// This callback could be returned before flashing op is complete (async).
-// Once finished flashing, application must call tud_dfu_finish_flashing()
-void tud_dfu_download_cb (uint8_t alt, uint16_t block_num, uint8_t const *data, uint16_t length);
-
-// Invoked when download process is complete, received DFU_DNLOAD (wLength=0) following by DFU_GETSTATUS (state=Manifest)
-// Application can do checksum, or actual flashing if buffered entire image previously.
-// Once finished flashing, application must call tud_dfu_finish_flashing()
-void tud_dfu_manifest_cb(uint8_t alt);
-
-// Invoked when received DFU_UPLOAD request
-// Application must populate data with up to length bytes and
-// Return the number of written bytes
-TU_ATTR_WEAK uint16_t tud_dfu_upload_cb(uint8_t alt, uint16_t block_num, uint8_t* data, uint16_t length);
-
-// Invoked when a DFU_DETACH request is received
-TU_ATTR_WEAK void tud_dfu_detach_cb(void);
-
-// Invoked when the Host has terminated a download or upload transfer
-TU_ATTR_WEAK void tud_dfu_abort_cb(uint8_t alt);
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void dfu_moded_init(void);
-void dfu_moded_reset(uint8_t rhport);
-uint16_t dfu_moded_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_DFU_MODE_DEVICE_H_ */
diff --git a/tinyusb/src/class/dfu/dfu_rt_device.c b/tinyusb/src/class/dfu/dfu_rt_device.c
deleted file mode 100755
index afee2aa1..00000000
--- a/tinyusb/src/class/dfu/dfu_rt_device.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Sylvain Munaut <tnt@246tNt.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_DFU_RUNTIME)
-
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "dfu_rt_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void dfu_rtd_init(void)
-{
-}
-
-void dfu_rtd_reset(uint8_t rhport)
-{
- (void) rhport;
-}
-
-uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- (void) rhport;
- (void) max_len;
-
- // Ensure this is DFU Runtime
- TU_VERIFY((itf_desc->bInterfaceSubClass == TUD_DFU_APP_SUBCLASS) &&
- (itf_desc->bInterfaceProtocol == DFU_PROTOCOL_RT), 0);
-
- uint8_t const * p_desc = tu_desc_next( itf_desc );
- uint16_t drv_len = sizeof(tusb_desc_interface_t);
-
- if ( TUSB_DESC_FUNCTIONAL == tu_desc_type(p_desc) )
- {
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- return drv_len;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- // nothing to do with DATA or ACK stage
- if ( stage != CONTROL_STAGE_SETUP ) return true;
-
- TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
-
- // dfu-util will try to claim the interface with SET_INTERFACE request before sending DFU request
- if ( TUSB_REQ_TYPE_STANDARD == request->bmRequestType_bit.type &&
- TUSB_REQ_SET_INTERFACE == request->bRequest )
- {
- tud_control_status(rhport, request);
- return true;
- }
-
- // Handle class request only from here
- TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
-
- switch (request->bRequest)
- {
- case DFU_REQUEST_DETACH:
- {
- TU_LOG2(" DFU RT Request: DETACH\r\n");
- tud_control_status(rhport, request);
- tud_dfu_runtime_reboot_to_dfu_cb();
- }
- break;
-
- case DFU_REQUEST_GETSTATUS:
- {
- TU_LOG2(" DFU RT Request: GETSTATUS\r\n");
- dfu_status_response_t resp;
- // Status = OK, Poll timeout is ignored during RT, State = APP_IDLE, IString = 0
- memset(&resp, 0x00, sizeof(dfu_status_response_t));
- tud_control_xfer(rhport, request, &resp, sizeof(dfu_status_response_t));
- }
- break;
-
- default:
- {
- TU_LOG2(" DFU RT Unexpected Request: %d\r\n", request->bRequest);
- return false; // stall unsupported request
- }
- }
-
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/class/dfu/dfu_rt_device.h b/tinyusb/src/class/dfu/dfu_rt_device.h
deleted file mode 100755
index babaa821..00000000
--- a/tinyusb/src/class/dfu/dfu_rt_device.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Sylvain Munaut <tnt@246tNt.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_DFU_RT_DEVICE_H_
-#define _TUSB_DFU_RT_DEVICE_H_
-
-#include "dfu.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Application Callback API (weak is optional)
-//--------------------------------------------------------------------+
-// Invoked when a DFU_DETACH request is received and bitWillDetach is set
-void tud_dfu_runtime_reboot_to_dfu_cb(void);
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void dfu_rtd_init(void);
-void dfu_rtd_reset(uint8_t rhport);
-uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_DFU_RT_DEVICE_H_ */
diff --git a/tinyusb/src/class/hid/hid.h b/tinyusb/src/class/hid/hid.h
deleted file mode 100755
index 9265a2ed..00000000
--- a/tinyusb/src/class/hid/hid.h
+++ /dev/null
@@ -1,1119 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/** \ingroup group_class
- * \defgroup ClassDriver_HID Human Interface Device (HID)
- * @{ */
-
-#ifndef _TUSB_HID_H_
-#define _TUSB_HID_H_
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Common Definitions
-//--------------------------------------------------------------------+
-/** \defgroup ClassDriver_HID_Common Common Definitions
- * @{ */
-
- /// USB HID Descriptor
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
- uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
-
- uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
- uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
- uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
-
- uint8_t bReportType; /**< Type of HID class report. */
- uint16_t wReportLength; /**< the total size of the Report descriptor. */
-} tusb_hid_descriptor_hid_t;
-
-/// HID Subclass
-typedef enum
-{
- HID_SUBCLASS_NONE = 0, ///< No Subclass
- HID_SUBCLASS_BOOT = 1 ///< Boot Interface Subclass
-}hid_subclass_enum_t;
-
-/// HID Interface Protocol
-typedef enum
-{
- HID_ITF_PROTOCOL_NONE = 0, ///< None
- HID_ITF_PROTOCOL_KEYBOARD = 1, ///< Keyboard
- HID_ITF_PROTOCOL_MOUSE = 2 ///< Mouse
-}hid_interface_protocol_enum_t;
-
-/// HID Descriptor Type
-typedef enum
-{
- HID_DESC_TYPE_HID = 0x21, ///< HID Descriptor
- HID_DESC_TYPE_REPORT = 0x22, ///< Report Descriptor
- HID_DESC_TYPE_PHYSICAL = 0x23 ///< Physical Descriptor
-}hid_descriptor_enum_t;
-
-/// HID Request Report Type
-typedef enum
-{
- HID_REPORT_TYPE_INVALID = 0,
- HID_REPORT_TYPE_INPUT, ///< Input
- HID_REPORT_TYPE_OUTPUT, ///< Output
- HID_REPORT_TYPE_FEATURE ///< Feature
-}hid_report_type_t;
-
-/// HID Class Specific Control Request
-typedef enum
-{
- HID_REQ_CONTROL_GET_REPORT = 0x01, ///< Get Report
- HID_REQ_CONTROL_GET_IDLE = 0x02, ///< Get Idle
- HID_REQ_CONTROL_GET_PROTOCOL = 0x03, ///< Get Protocol
- HID_REQ_CONTROL_SET_REPORT = 0x09, ///< Set Report
- HID_REQ_CONTROL_SET_IDLE = 0x0a, ///< Set Idle
- HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
-}hid_request_enum_t;
-
-/// HID Local Code
-typedef enum
-{
- HID_LOCAL_NotSupported = 0 , ///< NotSupported
- HID_LOCAL_Arabic , ///< Arabic
- HID_LOCAL_Belgian , ///< Belgian
- HID_LOCAL_Canadian_Bilingual , ///< Canadian_Bilingual
- HID_LOCAL_Canadian_French , ///< Canadian_French
- HID_LOCAL_Czech_Republic , ///< Czech_Republic
- HID_LOCAL_Danish , ///< Danish
- HID_LOCAL_Finnish , ///< Finnish
- HID_LOCAL_French , ///< French
- HID_LOCAL_German , ///< German
- HID_LOCAL_Greek , ///< Greek
- HID_LOCAL_Hebrew , ///< Hebrew
- HID_LOCAL_Hungary , ///< Hungary
- HID_LOCAL_International , ///< International
- HID_LOCAL_Italian , ///< Italian
- HID_LOCAL_Japan_Katakana , ///< Japan_Katakana
- HID_LOCAL_Korean , ///< Korean
- HID_LOCAL_Latin_American , ///< Latin_American
- HID_LOCAL_Netherlands_Dutch , ///< Netherlands/Dutch
- HID_LOCAL_Norwegian , ///< Norwegian
- HID_LOCAL_Persian_Farsi , ///< Persian (Farsi)
- HID_LOCAL_Poland , ///< Poland
- HID_LOCAL_Portuguese , ///< Portuguese
- HID_LOCAL_Russia , ///< Russia
- HID_LOCAL_Slovakia , ///< Slovakia
- HID_LOCAL_Spanish , ///< Spanish
- HID_LOCAL_Swedish , ///< Swedish
- HID_LOCAL_Swiss_French , ///< Swiss/French
- HID_LOCAL_Swiss_German , ///< Swiss/German
- HID_LOCAL_Switzerland , ///< Switzerland
- HID_LOCAL_Taiwan , ///< Taiwan
- HID_LOCAL_Turkish_Q , ///< Turkish-Q
- HID_LOCAL_UK , ///< UK
- HID_LOCAL_US , ///< US
- HID_LOCAL_Yugoslavia , ///< Yugoslavia
- HID_LOCAL_Turkish_F ///< Turkish-F
-} hid_local_enum_t;
-
-// HID protocol value used by GetProtocol / SetProtocol
-typedef enum
-{
- HID_PROTOCOL_BOOT = 0,
- HID_PROTOCOL_REPORT = 1
-} hid_protocol_mode_enum_t;
-
-/** @} */
-
-//--------------------------------------------------------------------+
-// GAMEPAD
-//--------------------------------------------------------------------+
-/** \addtogroup ClassDriver_HID_Gamepad Gamepad
- * @{ */
-
-/* From https://www.kernel.org/doc/html/latest/input/gamepad.html
- ____________________________ __
- / [__ZL__] [__ZR__] \ |
- / [__ TL __] [__ TR __] \ | Front Triggers
- __/________________________________\__ __|
- / _ \ |
- / /\ __ (N) \ |
- / || __ |MO| __ _ _ \ | Main Pad
- | <===DP===> |SE| |ST| (W) -|- (E) | |
- \ || ___ ___ _ / |
- /\ \/ / \ / \ (S) /\ __|
- / \________ | LS | ____ | RS | ________/ \ |
-| / \ \___/ / \ \___/ / \ | | Control Sticks
-| / \_____/ \_____/ \ | __|
-| / \ |
- \_____/ \_____/
-
- |________|______| |______|___________|
- D-Pad Left Right Action Pad
- Stick Stick
-
- |_____________|
- Menu Pad
-
- Most gamepads have the following features:
- - Action-Pad 4 buttons in diamonds-shape (on the right side) NORTH, SOUTH, WEST and EAST.
- - D-Pad (Direction-pad) 4 buttons (on the left side) that point up, down, left and right.
- - Menu-Pad Different constellations, but most-times 2 buttons: SELECT - START.
- - Analog-Sticks provide freely moveable sticks to control directions, Analog-sticks may also
- provide a digital button if you press them.
- - Triggers are located on the upper-side of the pad in vertical direction. The upper buttons
- are normally named Left- and Right-Triggers, the lower buttons Z-Left and Z-Right.
- - Rumble Many devices provide force-feedback features. But are mostly just simple rumble motors.
- */
-
-/// HID Gamepad Protocol Report.
-typedef struct TU_ATTR_PACKED
-{
- int8_t x; ///< Delta x movement of left analog-stick
- int8_t y; ///< Delta y movement of left analog-stick
- int8_t z; ///< Delta z movement of right analog-joystick
- int8_t rz; ///< Delta Rz movement of right analog-joystick
- int8_t rx; ///< Delta Rx movement of analog left trigger
- int8_t ry; ///< Delta Ry movement of analog right trigger
- uint8_t hat; ///< Buttons mask for currently pressed buttons in the DPad/hat
- uint32_t buttons; ///< Buttons mask for currently pressed buttons
-}hid_gamepad_report_t;
-
-/// Standard Gamepad Buttons Bitmap
-typedef enum
-{
- GAMEPAD_BUTTON_0 = TU_BIT(0),
- GAMEPAD_BUTTON_1 = TU_BIT(1),
- GAMEPAD_BUTTON_2 = TU_BIT(2),
- GAMEPAD_BUTTON_3 = TU_BIT(3),
- GAMEPAD_BUTTON_4 = TU_BIT(4),
- GAMEPAD_BUTTON_5 = TU_BIT(5),
- GAMEPAD_BUTTON_6 = TU_BIT(6),
- GAMEPAD_BUTTON_7 = TU_BIT(7),
- GAMEPAD_BUTTON_8 = TU_BIT(8),
- GAMEPAD_BUTTON_9 = TU_BIT(9),
- GAMEPAD_BUTTON_10 = TU_BIT(10),
- GAMEPAD_BUTTON_11 = TU_BIT(11),
- GAMEPAD_BUTTON_12 = TU_BIT(12),
- GAMEPAD_BUTTON_13 = TU_BIT(13),
- GAMEPAD_BUTTON_14 = TU_BIT(14),
- GAMEPAD_BUTTON_15 = TU_BIT(15),
- GAMEPAD_BUTTON_16 = TU_BIT(16),
- GAMEPAD_BUTTON_17 = TU_BIT(17),
- GAMEPAD_BUTTON_18 = TU_BIT(18),
- GAMEPAD_BUTTON_19 = TU_BIT(19),
- GAMEPAD_BUTTON_20 = TU_BIT(20),
- GAMEPAD_BUTTON_21 = TU_BIT(21),
- GAMEPAD_BUTTON_22 = TU_BIT(22),
- GAMEPAD_BUTTON_23 = TU_BIT(23),
- GAMEPAD_BUTTON_24 = TU_BIT(24),
- GAMEPAD_BUTTON_25 = TU_BIT(25),
- GAMEPAD_BUTTON_26 = TU_BIT(26),
- GAMEPAD_BUTTON_27 = TU_BIT(27),
- GAMEPAD_BUTTON_28 = TU_BIT(28),
- GAMEPAD_BUTTON_29 = TU_BIT(29),
- GAMEPAD_BUTTON_30 = TU_BIT(30),
- GAMEPAD_BUTTON_31 = TU_BIT(31),
-}hid_gamepad_button_bm_t;
-
-/// Standard Gamepad Buttons Naming from Linux input event codes
-/// https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
-#define GAMEPAD_BUTTON_A GAMEPAD_BUTTON_0
-#define GAMEPAD_BUTTON_SOUTH GAMEPAD_BUTTON_0
-
-#define GAMEPAD_BUTTON_B GAMEPAD_BUTTON_1
-#define GAMEPAD_BUTTON_EAST GAMEPAD_BUTTON_1
-
-#define GAMEPAD_BUTTON_C GAMEPAD_BUTTON_2
-
-#define GAMEPAD_BUTTON_X GAMEPAD_BUTTON_3
-#define GAMEPAD_BUTTON_NORTH GAMEPAD_BUTTON_3
-
-#define GAMEPAD_BUTTON_Y GAMEPAD_BUTTON_4
-#define GAMEPAD_BUTTON_WEST GAMEPAD_BUTTON_4
-
-#define GAMEPAD_BUTTON_Z GAMEPAD_BUTTON_5
-#define GAMEPAD_BUTTON_TL GAMEPAD_BUTTON_6
-#define GAMEPAD_BUTTON_TR GAMEPAD_BUTTON_7
-#define GAMEPAD_BUTTON_TL2 GAMEPAD_BUTTON_8
-#define GAMEPAD_BUTTON_TR2 GAMEPAD_BUTTON_9
-#define GAMEPAD_BUTTON_SELECT GAMEPAD_BUTTON_10
-#define GAMEPAD_BUTTON_START GAMEPAD_BUTTON_11
-#define GAMEPAD_BUTTON_MODE GAMEPAD_BUTTON_12
-#define GAMEPAD_BUTTON_THUMBL GAMEPAD_BUTTON_13
-#define GAMEPAD_BUTTON_THUMBR GAMEPAD_BUTTON_14
-
-/// Standard Gamepad HAT/DPAD Buttons (from Linux input event codes)
-typedef enum
-{
- GAMEPAD_HAT_CENTERED = 0, ///< DPAD_CENTERED
- GAMEPAD_HAT_UP = 1, ///< DPAD_UP
- GAMEPAD_HAT_UP_RIGHT = 2, ///< DPAD_UP_RIGHT
- GAMEPAD_HAT_RIGHT = 3, ///< DPAD_RIGHT
- GAMEPAD_HAT_DOWN_RIGHT = 4, ///< DPAD_DOWN_RIGHT
- GAMEPAD_HAT_DOWN = 5, ///< DPAD_DOWN
- GAMEPAD_HAT_DOWN_LEFT = 6, ///< DPAD_DOWN_LEFT
- GAMEPAD_HAT_LEFT = 7, ///< DPAD_LEFT
- GAMEPAD_HAT_UP_LEFT = 8, ///< DPAD_UP_LEFT
-}hid_gamepad_hat_t;
-
-/// @}
-
-//--------------------------------------------------------------------+
-// MOUSE
-//--------------------------------------------------------------------+
-/** \addtogroup ClassDriver_HID_Mouse Mouse
- * @{ */
-
-/// Standard HID Boot Protocol Mouse Report.
-typedef struct TU_ATTR_PACKED
-{
- uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */
- int8_t x; /**< Current delta x movement of the mouse. */
- int8_t y; /**< Current delta y movement on the mouse. */
- int8_t wheel; /**< Current delta wheel movement on the mouse. */
- int8_t pan; // using AC Pan
-} hid_mouse_report_t;
-
-/// Standard Mouse Buttons Bitmap
-typedef enum
-{
- MOUSE_BUTTON_LEFT = TU_BIT(0), ///< Left button
- MOUSE_BUTTON_RIGHT = TU_BIT(1), ///< Right button
- MOUSE_BUTTON_MIDDLE = TU_BIT(2), ///< Middle button
- MOUSE_BUTTON_BACKWARD = TU_BIT(3), ///< Backward button,
- MOUSE_BUTTON_FORWARD = TU_BIT(4), ///< Forward button,
-}hid_mouse_button_bm_t;
-
-/// @}
-
-//--------------------------------------------------------------------+
-// Keyboard
-//--------------------------------------------------------------------+
-/** \addtogroup ClassDriver_HID_Keyboard Keyboard
- * @{ */
-
-/// Standard HID Boot Protocol Keyboard Report.
-typedef struct TU_ATTR_PACKED
-{
- uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFIER_* masks). */
- uint8_t reserved; /**< Reserved for OEM use, always set to 0. */
- uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
-} hid_keyboard_report_t;
-
-/// Keyboard modifier codes bitmap
-typedef enum
-{
- KEYBOARD_MODIFIER_LEFTCTRL = TU_BIT(0), ///< Left Control
- KEYBOARD_MODIFIER_LEFTSHIFT = TU_BIT(1), ///< Left Shift
- KEYBOARD_MODIFIER_LEFTALT = TU_BIT(2), ///< Left Alt
- KEYBOARD_MODIFIER_LEFTGUI = TU_BIT(3), ///< Left Window
- KEYBOARD_MODIFIER_RIGHTCTRL = TU_BIT(4), ///< Right Control
- KEYBOARD_MODIFIER_RIGHTSHIFT = TU_BIT(5), ///< Right Shift
- KEYBOARD_MODIFIER_RIGHTALT = TU_BIT(6), ///< Right Alt
- KEYBOARD_MODIFIER_RIGHTGUI = TU_BIT(7) ///< Right Window
-}hid_keyboard_modifier_bm_t;
-
-typedef enum
-{
- KEYBOARD_LED_NUMLOCK = TU_BIT(0), ///< Num Lock LED
- KEYBOARD_LED_CAPSLOCK = TU_BIT(1), ///< Caps Lock LED
- KEYBOARD_LED_SCROLLLOCK = TU_BIT(2), ///< Scroll Lock LED
- KEYBOARD_LED_COMPOSE = TU_BIT(3), ///< Composition Mode
- KEYBOARD_LED_KANA = TU_BIT(4) ///< Kana mode
-}hid_keyboard_led_bm_t;
-
-/// @}
-
-//--------------------------------------------------------------------+
-// HID KEYCODE
-//--------------------------------------------------------------------+
-#define HID_KEY_NONE 0x00
-#define HID_KEY_A 0x04
-#define HID_KEY_B 0x05
-#define HID_KEY_C 0x06
-#define HID_KEY_D 0x07
-#define HID_KEY_E 0x08
-#define HID_KEY_F 0x09
-#define HID_KEY_G 0x0A
-#define HID_KEY_H 0x0B
-#define HID_KEY_I 0x0C
-#define HID_KEY_J 0x0D
-#define HID_KEY_K 0x0E
-#define HID_KEY_L 0x0F
-#define HID_KEY_M 0x10
-#define HID_KEY_N 0x11
-#define HID_KEY_O 0x12
-#define HID_KEY_P 0x13
-#define HID_KEY_Q 0x14
-#define HID_KEY_R 0x15
-#define HID_KEY_S 0x16
-#define HID_KEY_T 0x17
-#define HID_KEY_U 0x18
-#define HID_KEY_V 0x19
-#define HID_KEY_W 0x1A
-#define HID_KEY_X 0x1B
-#define HID_KEY_Y 0x1C
-#define HID_KEY_Z 0x1D
-#define HID_KEY_1 0x1E
-#define HID_KEY_2 0x1F
-#define HID_KEY_3 0x20
-#define HID_KEY_4 0x21
-#define HID_KEY_5 0x22
-#define HID_KEY_6 0x23
-#define HID_KEY_7 0x24
-#define HID_KEY_8 0x25
-#define HID_KEY_9 0x26
-#define HID_KEY_0 0x27
-#define HID_KEY_ENTER 0x28
-#define HID_KEY_ESCAPE 0x29
-#define HID_KEY_BACKSPACE 0x2A
-#define HID_KEY_TAB 0x2B
-#define HID_KEY_SPACE 0x2C
-#define HID_KEY_MINUS 0x2D
-#define HID_KEY_EQUAL 0x2E
-#define HID_KEY_BRACKET_LEFT 0x2F
-#define HID_KEY_BRACKET_RIGHT 0x30
-#define HID_KEY_BACKSLASH 0x31
-#define HID_KEY_EUROPE_1 0x32
-#define HID_KEY_SEMICOLON 0x33
-#define HID_KEY_APOSTROPHE 0x34
-#define HID_KEY_GRAVE 0x35
-#define HID_KEY_COMMA 0x36
-#define HID_KEY_PERIOD 0x37
-#define HID_KEY_SLASH 0x38
-#define HID_KEY_CAPS_LOCK 0x39
-#define HID_KEY_F1 0x3A
-#define HID_KEY_F2 0x3B
-#define HID_KEY_F3 0x3C
-#define HID_KEY_F4 0x3D
-#define HID_KEY_F5 0x3E
-#define HID_KEY_F6 0x3F
-#define HID_KEY_F7 0x40
-#define HID_KEY_F8 0x41
-#define HID_KEY_F9 0x42
-#define HID_KEY_F10 0x43
-#define HID_KEY_F11 0x44
-#define HID_KEY_F12 0x45
-#define HID_KEY_PRINT_SCREEN 0x46
-#define HID_KEY_SCROLL_LOCK 0x47
-#define HID_KEY_PAUSE 0x48
-#define HID_KEY_INSERT 0x49
-#define HID_KEY_HOME 0x4A
-#define HID_KEY_PAGE_UP 0x4B
-#define HID_KEY_DELETE 0x4C
-#define HID_KEY_END 0x4D
-#define HID_KEY_PAGE_DOWN 0x4E
-#define HID_KEY_ARROW_RIGHT 0x4F
-#define HID_KEY_ARROW_LEFT 0x50
-#define HID_KEY_ARROW_DOWN 0x51
-#define HID_KEY_ARROW_UP 0x52
-#define HID_KEY_NUM_LOCK 0x53
-#define HID_KEY_KEYPAD_DIVIDE 0x54
-#define HID_KEY_KEYPAD_MULTIPLY 0x55
-#define HID_KEY_KEYPAD_SUBTRACT 0x56
-#define HID_KEY_KEYPAD_ADD 0x57
-#define HID_KEY_KEYPAD_ENTER 0x58
-#define HID_KEY_KEYPAD_1 0x59
-#define HID_KEY_KEYPAD_2 0x5A
-#define HID_KEY_KEYPAD_3 0x5B
-#define HID_KEY_KEYPAD_4 0x5C
-#define HID_KEY_KEYPAD_5 0x5D
-#define HID_KEY_KEYPAD_6 0x5E
-#define HID_KEY_KEYPAD_7 0x5F
-#define HID_KEY_KEYPAD_8 0x60
-#define HID_KEY_KEYPAD_9 0x61
-#define HID_KEY_KEYPAD_0 0x62
-#define HID_KEY_KEYPAD_DECIMAL 0x63
-#define HID_KEY_EUROPE_2 0x64
-#define HID_KEY_APPLICATION 0x65
-#define HID_KEY_POWER 0x66
-#define HID_KEY_KEYPAD_EQUAL 0x67
-#define HID_KEY_F13 0x68
-#define HID_KEY_F14 0x69
-#define HID_KEY_F15 0x6A
-#define HID_KEY_F16 0x6B
-#define HID_KEY_F17 0x6C
-#define HID_KEY_F18 0x6D
-#define HID_KEY_F19 0x6E
-#define HID_KEY_F20 0x6F
-#define HID_KEY_F21 0x70
-#define HID_KEY_F22 0x71
-#define HID_KEY_F23 0x72
-#define HID_KEY_F24 0x73
-#define HID_KEY_EXECUTE 0x74
-#define HID_KEY_HELP 0x75
-#define HID_KEY_MENU 0x76
-#define HID_KEY_SELECT 0x77
-#define HID_KEY_STOP 0x78
-#define HID_KEY_AGAIN 0x79
-#define HID_KEY_UNDO 0x7A
-#define HID_KEY_CUT 0x7B
-#define HID_KEY_COPY 0x7C
-#define HID_KEY_PASTE 0x7D
-#define HID_KEY_FIND 0x7E
-#define HID_KEY_MUTE 0x7F
-#define HID_KEY_VOLUME_UP 0x80
-#define HID_KEY_VOLUME_DOWN 0x81
-#define HID_KEY_LOCKING_CAPS_LOCK 0x82
-#define HID_KEY_LOCKING_NUM_LOCK 0x83
-#define HID_KEY_LOCKING_SCROLL_LOCK 0x84
-#define HID_KEY_KEYPAD_COMMA 0x85
-#define HID_KEY_KEYPAD_EQUAL_SIGN 0x86
-#define HID_KEY_KANJI1 0x87
-#define HID_KEY_KANJI2 0x88
-#define HID_KEY_KANJI3 0x89
-#define HID_KEY_KANJI4 0x8A
-#define HID_KEY_KANJI5 0x8B
-#define HID_KEY_KANJI6 0x8C
-#define HID_KEY_KANJI7 0x8D
-#define HID_KEY_KANJI8 0x8E
-#define HID_KEY_KANJI9 0x8F
-#define HID_KEY_LANG1 0x90
-#define HID_KEY_LANG2 0x91
-#define HID_KEY_LANG3 0x92
-#define HID_KEY_LANG4 0x93
-#define HID_KEY_LANG5 0x94
-#define HID_KEY_LANG6 0x95
-#define HID_KEY_LANG7 0x96
-#define HID_KEY_LANG8 0x97
-#define HID_KEY_LANG9 0x98
-#define HID_KEY_ALTERNATE_ERASE 0x99
-#define HID_KEY_SYSREQ_ATTENTION 0x9A
-#define HID_KEY_CANCEL 0x9B
-#define HID_KEY_CLEAR 0x9C
-#define HID_KEY_PRIOR 0x9D
-#define HID_KEY_RETURN 0x9E
-#define HID_KEY_SEPARATOR 0x9F
-#define HID_KEY_OUT 0xA0
-#define HID_KEY_OPER 0xA1
-#define HID_KEY_CLEAR_AGAIN 0xA2
-#define HID_KEY_CRSEL_PROPS 0xA3
-#define HID_KEY_EXSEL 0xA4
-// RESERVED 0xA5-DF
-#define HID_KEY_CONTROL_LEFT 0xE0
-#define HID_KEY_SHIFT_LEFT 0xE1
-#define HID_KEY_ALT_LEFT 0xE2
-#define HID_KEY_GUI_LEFT 0xE3
-#define HID_KEY_CONTROL_RIGHT 0xE4
-#define HID_KEY_SHIFT_RIGHT 0xE5
-#define HID_KEY_ALT_RIGHT 0xE6
-#define HID_KEY_GUI_RIGHT 0xE7
-
-
-//--------------------------------------------------------------------+
-// REPORT DESCRIPTOR
-//--------------------------------------------------------------------+
-
-//------------- ITEM & TAG -------------//
-#define HID_REPORT_DATA_0(data)
-#define HID_REPORT_DATA_1(data) , data
-#define HID_REPORT_DATA_2(data) , U16_TO_U8S_LE(data)
-#define HID_REPORT_DATA_3(data) , U32_TO_U8S_LE(data)
-
-#define HID_REPORT_ITEM(data, tag, type, size) \
- (((tag) << 4) | ((type) << 2) | (size)) HID_REPORT_DATA_##size(data)
-
-// Report Item Types
-enum {
- RI_TYPE_MAIN = 0,
- RI_TYPE_GLOBAL = 1,
- RI_TYPE_LOCAL = 2
-};
-
-//------------- Main Items - HID 1.11 section 6.2.2.4 -------------//
-
-// Report Item Main group
-enum {
- RI_MAIN_INPUT = 8,
- RI_MAIN_OUTPUT = 9,
- RI_MAIN_COLLECTION = 10,
- RI_MAIN_FEATURE = 11,
- RI_MAIN_COLLECTION_END = 12
-};
-
-#define HID_INPUT(x) HID_REPORT_ITEM(x, RI_MAIN_INPUT , RI_TYPE_MAIN, 1)
-#define HID_OUTPUT(x) HID_REPORT_ITEM(x, RI_MAIN_OUTPUT , RI_TYPE_MAIN, 1)
-#define HID_COLLECTION(x) HID_REPORT_ITEM(x, RI_MAIN_COLLECTION , RI_TYPE_MAIN, 1)
-#define HID_FEATURE(x) HID_REPORT_ITEM(x, RI_MAIN_FEATURE , RI_TYPE_MAIN, 1)
-#define HID_COLLECTION_END HID_REPORT_ITEM(x, RI_MAIN_COLLECTION_END, RI_TYPE_MAIN, 0)
-
-//------------- Input, Output, Feature - HID 1.11 section 6.2.2.5 -------------//
-#define HID_DATA (0<<0)
-#define HID_CONSTANT (1<<0)
-
-#define HID_ARRAY (0<<1)
-#define HID_VARIABLE (1<<1)
-
-#define HID_ABSOLUTE (0<<2)
-#define HID_RELATIVE (1<<2)
-
-#define HID_WRAP_NO (0<<3)
-#define HID_WRAP (1<<3)
-
-#define HID_LINEAR (0<<4)
-#define HID_NONLINEAR (1<<4)
-
-#define HID_PREFERRED_STATE (0<<5)
-#define HID_PREFERRED_NO (1<<5)
-
-#define HID_NO_NULL_POSITION (0<<6)
-#define HID_NULL_STATE (1<<6)
-
-#define HID_NON_VOLATILE (0<<7)
-#define HID_VOLATILE (1<<7)
-
-#define HID_BITFIELD (0<<8)
-#define HID_BUFFERED_BYTES (1<<8)
-
-//------------- Collection Item - HID 1.11 section 6.2.2.6 -------------//
-enum {
- HID_COLLECTION_PHYSICAL = 0,
- HID_COLLECTION_APPLICATION,
- HID_COLLECTION_LOGICAL,
- HID_COLLECTION_REPORT,
- HID_COLLECTION_NAMED_ARRAY,
- HID_COLLECTION_USAGE_SWITCH,
- HID_COLLECTION_USAGE_MODIFIER
-};
-
-//------------- Global Items - HID 1.11 section 6.2.2.7 -------------//
-
-// Report Item Global group
-enum {
- RI_GLOBAL_USAGE_PAGE = 0,
- RI_GLOBAL_LOGICAL_MIN = 1,
- RI_GLOBAL_LOGICAL_MAX = 2,
- RI_GLOBAL_PHYSICAL_MIN = 3,
- RI_GLOBAL_PHYSICAL_MAX = 4,
- RI_GLOBAL_UNIT_EXPONENT = 5,
- RI_GLOBAL_UNIT = 6,
- RI_GLOBAL_REPORT_SIZE = 7,
- RI_GLOBAL_REPORT_ID = 8,
- RI_GLOBAL_REPORT_COUNT = 9,
- RI_GLOBAL_PUSH = 10,
- RI_GLOBAL_POP = 11
-};
-
-#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, RI_GLOBAL_USAGE_PAGE, RI_TYPE_GLOBAL, 1)
-#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_USAGE_PAGE, RI_TYPE_GLOBAL, n)
-
-#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MIN, RI_TYPE_GLOBAL, 1)
-#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MIN, RI_TYPE_GLOBAL, n)
-
-#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MAX, RI_TYPE_GLOBAL, 1)
-#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MAX, RI_TYPE_GLOBAL, n)
-
-#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MIN, RI_TYPE_GLOBAL, 1)
-#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MIN, RI_TYPE_GLOBAL, n)
-
-#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MAX, RI_TYPE_GLOBAL, 1)
-#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MAX, RI_TYPE_GLOBAL, n)
-
-#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT_EXPONENT, RI_TYPE_GLOBAL, 1)
-#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT_EXPONENT, RI_TYPE_GLOBAL, n)
-
-#define HID_UNIT(x) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT, RI_TYPE_GLOBAL, 1)
-#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT, RI_TYPE_GLOBAL, n)
-
-#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_SIZE, RI_TYPE_GLOBAL, 1)
-#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_SIZE, RI_TYPE_GLOBAL, n)
-
-#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, 1),
-#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, n),
-
-#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_COUNT, RI_TYPE_GLOBAL, 1)
-#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_COUNT, RI_TYPE_GLOBAL, n)
-
-#define HID_PUSH HID_REPORT_ITEM(x, RI_GLOBAL_PUSH, RI_TYPE_GLOBAL, 0)
-#define HID_POP HID_REPORT_ITEM(x, RI_GLOBAL_POP, RI_TYPE_GLOBAL, 0)
-
-//------------- LOCAL ITEMS 6.2.2.8 -------------//
-
-enum {
- RI_LOCAL_USAGE = 0,
- RI_LOCAL_USAGE_MIN = 1,
- RI_LOCAL_USAGE_MAX = 2,
- RI_LOCAL_DESIGNATOR_INDEX = 3,
- RI_LOCAL_DESIGNATOR_MIN = 4,
- RI_LOCAL_DESIGNATOR_MAX = 5,
- // 6 is reserved
- RI_LOCAL_STRING_INDEX = 7,
- RI_LOCAL_STRING_MIN = 8,
- RI_LOCAL_STRING_MAX = 9,
- RI_LOCAL_DELIMITER = 10,
-};
-
-#define HID_USAGE(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE, RI_TYPE_LOCAL, 1)
-#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE, RI_TYPE_LOCAL, n)
-
-#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MIN, RI_TYPE_LOCAL, 1)
-#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MIN, RI_TYPE_LOCAL, n)
-
-#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MAX, RI_TYPE_LOCAL, 1)
-#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MAX, RI_TYPE_LOCAL, n)
-
-//--------------------------------------------------------------------+
-// Usage Table
-//--------------------------------------------------------------------+
-
-/// HID Usage Table - Table 1: Usage Page Summary
-enum {
- HID_USAGE_PAGE_DESKTOP = 0x01,
- HID_USAGE_PAGE_SIMULATE = 0x02,
- HID_USAGE_PAGE_VIRTUAL_REALITY = 0x03,
- HID_USAGE_PAGE_SPORT = 0x04,
- HID_USAGE_PAGE_GAME = 0x05,
- HID_USAGE_PAGE_GENERIC_DEVICE = 0x06,
- HID_USAGE_PAGE_KEYBOARD = 0x07,
- HID_USAGE_PAGE_LED = 0x08,
- HID_USAGE_PAGE_BUTTON = 0x09,
- HID_USAGE_PAGE_ORDINAL = 0x0a,
- HID_USAGE_PAGE_TELEPHONY = 0x0b,
- HID_USAGE_PAGE_CONSUMER = 0x0c,
- HID_USAGE_PAGE_DIGITIZER = 0x0d,
- HID_USAGE_PAGE_PID = 0x0f,
- HID_USAGE_PAGE_UNICODE = 0x10,
- HID_USAGE_PAGE_ALPHA_DISPLAY = 0x14,
- HID_USAGE_PAGE_MEDICAL = 0x40,
- HID_USAGE_PAGE_MONITOR = 0x80, //0x80 - 0x83
- HID_USAGE_PAGE_POWER = 0x84, // 0x084 - 0x87
- HID_USAGE_PAGE_BARCODE_SCANNER = 0x8c,
- HID_USAGE_PAGE_SCALE = 0x8d,
- HID_USAGE_PAGE_MSR = 0x8e,
- HID_USAGE_PAGE_CAMERA = 0x90,
- HID_USAGE_PAGE_ARCADE = 0x91,
- HID_USAGE_PAGE_VENDOR = 0xFF00 // 0xFF00 - 0xFFFF
-};
-
-/// HID Usage Table - Table 6: Generic Desktop Page
-enum {
- HID_USAGE_DESKTOP_POINTER = 0x01,
- HID_USAGE_DESKTOP_MOUSE = 0x02,
- HID_USAGE_DESKTOP_JOYSTICK = 0x04,
- HID_USAGE_DESKTOP_GAMEPAD = 0x05,
- HID_USAGE_DESKTOP_KEYBOARD = 0x06,
- HID_USAGE_DESKTOP_KEYPAD = 0x07,
- HID_USAGE_DESKTOP_MULTI_AXIS_CONTROLLER = 0x08,
- HID_USAGE_DESKTOP_TABLET_PC_SYSTEM = 0x09,
- HID_USAGE_DESKTOP_X = 0x30,
- HID_USAGE_DESKTOP_Y = 0x31,
- HID_USAGE_DESKTOP_Z = 0x32,
- HID_USAGE_DESKTOP_RX = 0x33,
- HID_USAGE_DESKTOP_RY = 0x34,
- HID_USAGE_DESKTOP_RZ = 0x35,
- HID_USAGE_DESKTOP_SLIDER = 0x36,
- HID_USAGE_DESKTOP_DIAL = 0x37,
- HID_USAGE_DESKTOP_WHEEL = 0x38,
- HID_USAGE_DESKTOP_HAT_SWITCH = 0x39,
- HID_USAGE_DESKTOP_COUNTED_BUFFER = 0x3a,
- HID_USAGE_DESKTOP_BYTE_COUNT = 0x3b,
- HID_USAGE_DESKTOP_MOTION_WAKEUP = 0x3c,
- HID_USAGE_DESKTOP_START = 0x3d,
- HID_USAGE_DESKTOP_SELECT = 0x3e,
- HID_USAGE_DESKTOP_VX = 0x40,
- HID_USAGE_DESKTOP_VY = 0x41,
- HID_USAGE_DESKTOP_VZ = 0x42,
- HID_USAGE_DESKTOP_VBRX = 0x43,
- HID_USAGE_DESKTOP_VBRY = 0x44,
- HID_USAGE_DESKTOP_VBRZ = 0x45,
- HID_USAGE_DESKTOP_VNO = 0x46,
- HID_USAGE_DESKTOP_FEATURE_NOTIFICATION = 0x47,
- HID_USAGE_DESKTOP_RESOLUTION_MULTIPLIER = 0x48,
- HID_USAGE_DESKTOP_SYSTEM_CONTROL = 0x80,
- HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN = 0x81,
- HID_USAGE_DESKTOP_SYSTEM_SLEEP = 0x82,
- HID_USAGE_DESKTOP_SYSTEM_WAKE_UP = 0x83,
- HID_USAGE_DESKTOP_SYSTEM_CONTEXT_MENU = 0x84,
- HID_USAGE_DESKTOP_SYSTEM_MAIN_MENU = 0x85,
- HID_USAGE_DESKTOP_SYSTEM_APP_MENU = 0x86,
- HID_USAGE_DESKTOP_SYSTEM_MENU_HELP = 0x87,
- HID_USAGE_DESKTOP_SYSTEM_MENU_EXIT = 0x88,
- HID_USAGE_DESKTOP_SYSTEM_MENU_SELECT = 0x89,
- HID_USAGE_DESKTOP_SYSTEM_MENU_RIGHT = 0x8A,
- HID_USAGE_DESKTOP_SYSTEM_MENU_LEFT = 0x8B,
- HID_USAGE_DESKTOP_SYSTEM_MENU_UP = 0x8C,
- HID_USAGE_DESKTOP_SYSTEM_MENU_DOWN = 0x8D,
- HID_USAGE_DESKTOP_SYSTEM_COLD_RESTART = 0x8E,
- HID_USAGE_DESKTOP_SYSTEM_WARM_RESTART = 0x8F,
- HID_USAGE_DESKTOP_DPAD_UP = 0x90,
- HID_USAGE_DESKTOP_DPAD_DOWN = 0x91,
- HID_USAGE_DESKTOP_DPAD_RIGHT = 0x92,
- HID_USAGE_DESKTOP_DPAD_LEFT = 0x93,
- HID_USAGE_DESKTOP_SYSTEM_DOCK = 0xA0,
- HID_USAGE_DESKTOP_SYSTEM_UNDOCK = 0xA1,
- HID_USAGE_DESKTOP_SYSTEM_SETUP = 0xA2,
- HID_USAGE_DESKTOP_SYSTEM_BREAK = 0xA3,
- HID_USAGE_DESKTOP_SYSTEM_DEBUGGER_BREAK = 0xA4,
- HID_USAGE_DESKTOP_APPLICATION_BREAK = 0xA5,
- HID_USAGE_DESKTOP_APPLICATION_DEBUGGER_BREAK = 0xA6,
- HID_USAGE_DESKTOP_SYSTEM_SPEAKER_MUTE = 0xA7,
- HID_USAGE_DESKTOP_SYSTEM_HIBERNATE = 0xA8,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INVERT = 0xB0,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INTERNAL = 0xB1,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_EXTERNAL = 0xB2,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_BOTH = 0xB3,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_DUAL = 0xB4,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_TOGGLE_INT_EXT = 0xB5,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_SWAP_PRIMARY_SECONDARY = 0xB6,
- HID_USAGE_DESKTOP_SYSTEM_DISPLAY_LCD_AUTOSCALE = 0xB7
-};
-
-
-/// HID Usage Table: Consumer Page (0x0C)
-/// Only contains controls that supported by Windows (whole list is too long)
-enum
-{
- // Generic Control
- HID_USAGE_CONSUMER_CONTROL = 0x0001,
-
- // Power Control
- HID_USAGE_CONSUMER_POWER = 0x0030,
- HID_USAGE_CONSUMER_RESET = 0x0031,
- HID_USAGE_CONSUMER_SLEEP = 0x0032,
-
- // Screen Brightness
- HID_USAGE_CONSUMER_BRIGHTNESS_INCREMENT = 0x006F,
- HID_USAGE_CONSUMER_BRIGHTNESS_DECREMENT = 0x0070,
-
- // These HID usages operate only on mobile systems (battery powered) and
- // require Windows 8 (build 8302 or greater).
- HID_USAGE_CONSUMER_WIRELESS_RADIO_CONTROLS = 0x000C,
- HID_USAGE_CONSUMER_WIRELESS_RADIO_BUTTONS = 0x00C6,
- HID_USAGE_CONSUMER_WIRELESS_RADIO_LED = 0x00C7,
- HID_USAGE_CONSUMER_WIRELESS_RADIO_SLIDER_SWITCH = 0x00C8,
-
- // Media Control
- HID_USAGE_CONSUMER_PLAY_PAUSE = 0x00CD,
- HID_USAGE_CONSUMER_SCAN_NEXT = 0x00B5,
- HID_USAGE_CONSUMER_SCAN_PREVIOUS = 0x00B6,
- HID_USAGE_CONSUMER_STOP = 0x00B7,
- HID_USAGE_CONSUMER_VOLUME = 0x00E0,
- HID_USAGE_CONSUMER_MUTE = 0x00E2,
- HID_USAGE_CONSUMER_BASS = 0x00E3,
- HID_USAGE_CONSUMER_TREBLE = 0x00E4,
- HID_USAGE_CONSUMER_BASS_BOOST = 0x00E5,
- HID_USAGE_CONSUMER_VOLUME_INCREMENT = 0x00E9,
- HID_USAGE_CONSUMER_VOLUME_DECREMENT = 0x00EA,
- HID_USAGE_CONSUMER_BASS_INCREMENT = 0x0152,
- HID_USAGE_CONSUMER_BASS_DECREMENT = 0x0153,
- HID_USAGE_CONSUMER_TREBLE_INCREMENT = 0x0154,
- HID_USAGE_CONSUMER_TREBLE_DECREMENT = 0x0155,
-
- // Application Launcher
- HID_USAGE_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION = 0x0183,
- HID_USAGE_CONSUMER_AL_EMAIL_READER = 0x018A,
- HID_USAGE_CONSUMER_AL_CALCULATOR = 0x0192,
- HID_USAGE_CONSUMER_AL_LOCAL_BROWSER = 0x0194,
-
- // Browser/Explorer Specific
- HID_USAGE_CONSUMER_AC_SEARCH = 0x0221,
- HID_USAGE_CONSUMER_AC_HOME = 0x0223,
- HID_USAGE_CONSUMER_AC_BACK = 0x0224,
- HID_USAGE_CONSUMER_AC_FORWARD = 0x0225,
- HID_USAGE_CONSUMER_AC_STOP = 0x0226,
- HID_USAGE_CONSUMER_AC_REFRESH = 0x0227,
- HID_USAGE_CONSUMER_AC_BOOKMARKS = 0x022A,
-
- // Mouse Horizontal scroll
- HID_USAGE_CONSUMER_AC_PAN = 0x0238,
-};
-
-/*--------------------------------------------------------------------
- * ASCII to KEYCODE Conversion
- * Expand to array of [128][2] (shift, keycode)
- *
- * Usage: example to convert input chr into keyboard report (modifier + keycode)
- *
- * uint8_t const conv_table[128][2] = { HID_ASCII_TO_KEYCODE };
- *
- * uint8_t keycode[6] = { 0 };
- * uint8_t modifier = 0;
- *
- * if ( conv_table[chr][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
- * keycode[0] = conv_table[chr][1];
- * tud_hid_keyboard_report(report_id, modifier, keycode);
- *
- *--------------------------------------------------------------------*/
-#define HID_ASCII_TO_KEYCODE \
- {0, 0 }, /* 0x00 Null */ \
- {0, 0 }, /* 0x01 */ \
- {0, 0 }, /* 0x02 */ \
- {0, 0 }, /* 0x03 */ \
- {0, 0 }, /* 0x04 */ \
- {0, 0 }, /* 0x05 */ \
- {0, 0 }, /* 0x06 */ \
- {0, 0 }, /* 0x07 */ \
- {0, HID_KEY_BACKSPACE }, /* 0x08 Backspace */ \
- {0, HID_KEY_TAB }, /* 0x09 Tab */ \
- {0, HID_KEY_ENTER }, /* 0x0A Line Feed */ \
- {0, 0 }, /* 0x0B */ \
- {0, 0 }, /* 0x0C */ \
- {0, HID_KEY_ENTER }, /* 0x0D CR */ \
- {0, 0 }, /* 0x0E */ \
- {0, 0 }, /* 0x0F */ \
- {0, 0 }, /* 0x10 */ \
- {0, 0 }, /* 0x11 */ \
- {0, 0 }, /* 0x12 */ \
- {0, 0 }, /* 0x13 */ \
- {0, 0 }, /* 0x14 */ \
- {0, 0 }, /* 0x15 */ \
- {0, 0 }, /* 0x16 */ \
- {0, 0 }, /* 0x17 */ \
- {0, 0 }, /* 0x18 */ \
- {0, 0 }, /* 0x19 */ \
- {0, 0 }, /* 0x1A */ \
- {0, HID_KEY_ESCAPE }, /* 0x1B Escape */ \
- {0, 0 }, /* 0x1C */ \
- {0, 0 }, /* 0x1D */ \
- {0, 0 }, /* 0x1E */ \
- {0, 0 }, /* 0x1F */ \
- \
- {0, HID_KEY_SPACE }, /* 0x20 */ \
- {1, HID_KEY_1 }, /* 0x21 ! */ \
- {1, HID_KEY_APOSTROPHE }, /* 0x22 " */ \
- {1, HID_KEY_3 }, /* 0x23 # */ \
- {1, HID_KEY_4 }, /* 0x24 $ */ \
- {1, HID_KEY_5 }, /* 0x25 % */ \
- {1, HID_KEY_7 }, /* 0x26 & */ \
- {0, HID_KEY_APOSTROPHE }, /* 0x27 ' */ \
- {1, HID_KEY_9 }, /* 0x28 ( */ \
- {1, HID_KEY_0 }, /* 0x29 ) */ \
- {1, HID_KEY_8 }, /* 0x2A * */ \
- {1, HID_KEY_EQUAL }, /* 0x2B + */ \
- {0, HID_KEY_COMMA }, /* 0x2C , */ \
- {0, HID_KEY_MINUS }, /* 0x2D - */ \
- {0, HID_KEY_PERIOD }, /* 0x2E . */ \
- {0, HID_KEY_SLASH }, /* 0x2F / */ \
- {0, HID_KEY_0 }, /* 0x30 0 */ \
- {0, HID_KEY_1 }, /* 0x31 1 */ \
- {0, HID_KEY_2 }, /* 0x32 2 */ \
- {0, HID_KEY_3 }, /* 0x33 3 */ \
- {0, HID_KEY_4 }, /* 0x34 4 */ \
- {0, HID_KEY_5 }, /* 0x35 5 */ \
- {0, HID_KEY_6 }, /* 0x36 6 */ \
- {0, HID_KEY_7 }, /* 0x37 7 */ \
- {0, HID_KEY_8 }, /* 0x38 8 */ \
- {0, HID_KEY_9 }, /* 0x39 9 */ \
- {1, HID_KEY_SEMICOLON }, /* 0x3A : */ \
- {0, HID_KEY_SEMICOLON }, /* 0x3B ; */ \
- {1, HID_KEY_COMMA }, /* 0x3C < */ \
- {0, HID_KEY_EQUAL }, /* 0x3D = */ \
- {1, HID_KEY_PERIOD }, /* 0x3E > */ \
- {1, HID_KEY_SLASH }, /* 0x3F ? */ \
- \
- {1, HID_KEY_2 }, /* 0x40 @ */ \
- {1, HID_KEY_A }, /* 0x41 A */ \
- {1, HID_KEY_B }, /* 0x42 B */ \
- {1, HID_KEY_C }, /* 0x43 C */ \
- {1, HID_KEY_D }, /* 0x44 D */ \
- {1, HID_KEY_E }, /* 0x45 E */ \
- {1, HID_KEY_F }, /* 0x46 F */ \
- {1, HID_KEY_G }, /* 0x47 G */ \
- {1, HID_KEY_H }, /* 0x48 H */ \
- {1, HID_KEY_I }, /* 0x49 I */ \
- {1, HID_KEY_J }, /* 0x4A J */ \
- {1, HID_KEY_K }, /* 0x4B K */ \
- {1, HID_KEY_L }, /* 0x4C L */ \
- {1, HID_KEY_M }, /* 0x4D M */ \
- {1, HID_KEY_N }, /* 0x4E N */ \
- {1, HID_KEY_O }, /* 0x4F O */ \
- {1, HID_KEY_P }, /* 0x50 P */ \
- {1, HID_KEY_Q }, /* 0x51 Q */ \
- {1, HID_KEY_R }, /* 0x52 R */ \
- {1, HID_KEY_S }, /* 0x53 S */ \
- {1, HID_KEY_T }, /* 0x55 T */ \
- {1, HID_KEY_U }, /* 0x55 U */ \
- {1, HID_KEY_V }, /* 0x56 V */ \
- {1, HID_KEY_W }, /* 0x57 W */ \
- {1, HID_KEY_X }, /* 0x58 X */ \
- {1, HID_KEY_Y }, /* 0x59 Y */ \
- {1, HID_KEY_Z }, /* 0x5A Z */ \
- {0, HID_KEY_BRACKET_LEFT }, /* 0x5B [ */ \
- {0, HID_KEY_BACKSLASH }, /* 0x5C '\' */ \
- {0, HID_KEY_BRACKET_RIGHT }, /* 0x5D ] */ \
- {1, HID_KEY_6 }, /* 0x5E ^ */ \
- {1, HID_KEY_MINUS }, /* 0x5F _ */ \
- \
- {0, HID_KEY_GRAVE }, /* 0x60 ` */ \
- {0, HID_KEY_A }, /* 0x61 a */ \
- {0, HID_KEY_B }, /* 0x62 b */ \
- {0, HID_KEY_C }, /* 0x63 c */ \
- {0, HID_KEY_D }, /* 0x66 d */ \
- {0, HID_KEY_E }, /* 0x65 e */ \
- {0, HID_KEY_F }, /* 0x66 f */ \
- {0, HID_KEY_G }, /* 0x67 g */ \
- {0, HID_KEY_H }, /* 0x68 h */ \
- {0, HID_KEY_I }, /* 0x69 i */ \
- {0, HID_KEY_J }, /* 0x6A j */ \
- {0, HID_KEY_K }, /* 0x6B k */ \
- {0, HID_KEY_L }, /* 0x6C l */ \
- {0, HID_KEY_M }, /* 0x6D m */ \
- {0, HID_KEY_N }, /* 0x6E n */ \
- {0, HID_KEY_O }, /* 0x6F o */ \
- {0, HID_KEY_P }, /* 0x70 p */ \
- {0, HID_KEY_Q }, /* 0x71 q */ \
- {0, HID_KEY_R }, /* 0x72 r */ \
- {0, HID_KEY_S }, /* 0x73 s */ \
- {0, HID_KEY_T }, /* 0x75 t */ \
- {0, HID_KEY_U }, /* 0x75 u */ \
- {0, HID_KEY_V }, /* 0x76 v */ \
- {0, HID_KEY_W }, /* 0x77 w */ \
- {0, HID_KEY_X }, /* 0x78 x */ \
- {0, HID_KEY_Y }, /* 0x79 y */ \
- {0, HID_KEY_Z }, /* 0x7A z */ \
- {1, HID_KEY_BRACKET_LEFT }, /* 0x7B { */ \
- {1, HID_KEY_BACKSLASH }, /* 0x7C | */ \
- {1, HID_KEY_BRACKET_RIGHT }, /* 0x7D } */ \
- {1, HID_KEY_GRAVE }, /* 0x7E ~ */ \
- {0, HID_KEY_DELETE } /* 0x7F Delete */ \
-
-/*--------------------------------------------------------------------
- * KEYCODE to Ascii Conversion
- * Expand to array of [128][2] (ascii without shift, ascii with shift)
- *
- * Usage: example to convert ascii from keycode (key) and shift modifier (shift).
- * Here we assume key < 128 ( printable )
- *
- * uint8_t const conv_table[128][2] = { HID_KEYCODE_TO_ASCII };
- * char ch = shift ? conv_table[chr][1] : conv_table[chr][0];
- *
- *--------------------------------------------------------------------*/
-#define HID_KEYCODE_TO_ASCII \
- {0 , 0 }, /* 0x00 */ \
- {0 , 0 }, /* 0x01 */ \
- {0 , 0 }, /* 0x02 */ \
- {0 , 0 }, /* 0x03 */ \
- {'a' , 'A' }, /* 0x04 */ \
- {'b' , 'B' }, /* 0x05 */ \
- {'c' , 'C' }, /* 0x06 */ \
- {'d' , 'D' }, /* 0x07 */ \
- {'e' , 'E' }, /* 0x08 */ \
- {'f' , 'F' }, /* 0x09 */ \
- {'g' , 'G' }, /* 0x0a */ \
- {'h' , 'H' }, /* 0x0b */ \
- {'i' , 'I' }, /* 0x0c */ \
- {'j' , 'J' }, /* 0x0d */ \
- {'k' , 'K' }, /* 0x0e */ \
- {'l' , 'L' }, /* 0x0f */ \
- {'m' , 'M' }, /* 0x10 */ \
- {'n' , 'N' }, /* 0x11 */ \
- {'o' , 'O' }, /* 0x12 */ \
- {'p' , 'P' }, /* 0x13 */ \
- {'q' , 'Q' }, /* 0x14 */ \
- {'r' , 'R' }, /* 0x15 */ \
- {'s' , 'S' }, /* 0x16 */ \
- {'t' , 'T' }, /* 0x17 */ \
- {'u' , 'U' }, /* 0x18 */ \
- {'v' , 'V' }, /* 0x19 */ \
- {'w' , 'W' }, /* 0x1a */ \
- {'x' , 'X' }, /* 0x1b */ \
- {'y' , 'Y' }, /* 0x1c */ \
- {'z' , 'Z' }, /* 0x1d */ \
- {'1' , '!' }, /* 0x1e */ \
- {'2' , '@' }, /* 0x1f */ \
- {'3' , '#' }, /* 0x20 */ \
- {'4' , '$' }, /* 0x21 */ \
- {'5' , '%' }, /* 0x22 */ \
- {'6' , '^' }, /* 0x23 */ \
- {'7' , '&' }, /* 0x24 */ \
- {'8' , '*' }, /* 0x25 */ \
- {'9' , '(' }, /* 0x26 */ \
- {'0' , ')' }, /* 0x27 */ \
- {'\r' , '\r' }, /* 0x28 */ \
- {'\x1b', '\x1b' }, /* 0x29 */ \
- {'\b' , '\b' }, /* 0x2a */ \
- {'\t' , '\t' }, /* 0x2b */ \
- {' ' , ' ' }, /* 0x2c */ \
- {'-' , '_' }, /* 0x2d */ \
- {'=' , '+' }, /* 0x2e */ \
- {'[' , '{' }, /* 0x2f */ \
- {']' , '}' }, /* 0x30 */ \
- {'\\' , '|' }, /* 0x31 */ \
- {'#' , '~' }, /* 0x32 */ \
- {';' , ':' }, /* 0x33 */ \
- {'\'' , '\"' }, /* 0x34 */ \
- {'`' , '~' }, /* 0x35 */ \
- {',' , '<' }, /* 0x36 */ \
- {'.' , '>' }, /* 0x37 */ \
- {'/' , '?' }, /* 0x38 */ \
- \
- {0 , 0 }, /* 0x39 */ \
- {0 , 0 }, /* 0x3a */ \
- {0 , 0 }, /* 0x3b */ \
- {0 , 0 }, /* 0x3c */ \
- {0 , 0 }, /* 0x3d */ \
- {0 , 0 }, /* 0x3e */ \
- {0 , 0 }, /* 0x3f */ \
- {0 , 0 }, /* 0x40 */ \
- {0 , 0 }, /* 0x41 */ \
- {0 , 0 }, /* 0x42 */ \
- {0 , 0 }, /* 0x43 */ \
- {0 , 0 }, /* 0x44 */ \
- {0 , 0 }, /* 0x45 */ \
- {0 , 0 }, /* 0x46 */ \
- {0 , 0 }, /* 0x47 */ \
- {0 , 0 }, /* 0x48 */ \
- {0 , 0 }, /* 0x49 */ \
- {0 , 0 }, /* 0x4a */ \
- {0 , 0 }, /* 0x4b */ \
- {0 , 0 }, /* 0x4c */ \
- {0 , 0 }, /* 0x4d */ \
- {0 , 0 }, /* 0x4e */ \
- {0 , 0 }, /* 0x4f */ \
- {0 , 0 }, /* 0x50 */ \
- {0 , 0 }, /* 0x51 */ \
- {0 , 0 }, /* 0x52 */ \
- {0 , 0 }, /* 0x53 */ \
- \
- {'/' , '/' }, /* 0x54 */ \
- {'*' , '*' }, /* 0x55 */ \
- {'-' , '-' }, /* 0x56 */ \
- {'+' , '+' }, /* 0x57 */ \
- {'\r' , '\r' }, /* 0x58 */ \
- {'1' , 0 }, /* 0x59 */ \
- {'2' , 0 }, /* 0x5a */ \
- {'3' , 0 }, /* 0x5b */ \
- {'4' , 0 }, /* 0x5c */ \
- {'5' , '5' }, /* 0x5d */ \
- {'6' , 0 }, /* 0x5e */ \
- {'7' , 0 }, /* 0x5f */ \
- {'8' , 0 }, /* 0x60 */ \
- {'9' , 0 }, /* 0x61 */ \
- {'0' , 0 }, /* 0x62 */ \
- {'0' , 0 }, /* 0x63 */ \
- {'=' , '=' }, /* 0x67 */ \
-
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_HID_H__ */
-
-/// @}
diff --git a/tinyusb/src/class/hid/hid_device.c b/tinyusb/src/class/hid/hid_device.c
deleted file mode 100755
index 2ee80750..00000000
--- a/tinyusb/src/class/hid/hid_device.c
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_HID)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "hid_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-typedef struct
-{
- uint8_t itf_num;
- uint8_t ep_in;
- uint8_t ep_out; // optional Out endpoint
- uint8_t itf_protocol; // Boot mouse or keyboard
-
- uint8_t protocol_mode; // Boot (0) or Report protocol (1)
- uint8_t idle_rate; // up to application to handle idle rate
- uint16_t report_desc_len;
-
- CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_EP_BUFSIZE];
- CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_EP_BUFSIZE];
-
- // TODO save hid descriptor since host can specifically request this after enumeration
- // Note: HID descriptor may be not available from application after enumeration
- tusb_hid_descriptor_hid_t const * hid_descriptor;
-} hidd_interface_t;
-
-CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
-
-/*------------- Helpers -------------*/
-static inline uint8_t get_index_by_itfnum(uint8_t itf_num)
-{
- for (uint8_t i=0; i < CFG_TUD_HID; i++ )
- {
- if ( itf_num == _hidd_itf[i].itf_num ) return i;
- }
-
- return 0xFF;
-}
-
-//--------------------------------------------------------------------+
-// APPLICATION API
-//--------------------------------------------------------------------+
-bool tud_hid_n_ready(uint8_t instance)
-{
- uint8_t const ep_in = _hidd_itf[instance].ep_in;
- return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
-}
-
-bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint8_t len)
-{
- uint8_t const rhport = 0;
- hidd_interface_t * p_hid = &_hidd_itf[instance];
-
- // claim endpoint
- TU_VERIFY( usbd_edpt_claim(rhport, p_hid->ep_in) );
-
- // prepare data
- if (report_id)
- {
- len = tu_min8(len, CFG_TUD_HID_EP_BUFSIZE-1);
-
- p_hid->epin_buf[0] = report_id;
- memcpy(p_hid->epin_buf+1, report, len);
- len++;
- }else
- {
- // If report id = 0, skip ID field
- len = tu_min8(len, CFG_TUD_HID_EP_BUFSIZE);
- memcpy(p_hid->epin_buf, report, len);
- }
-
- return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
-}
-
-uint8_t tud_hid_n_interface_protocol(uint8_t instance)
-{
- return _hidd_itf[instance].itf_protocol;
-}
-
-uint8_t tud_hid_n_get_protocol(uint8_t instance)
-{
- return _hidd_itf[instance].protocol_mode;
-}
-
-bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
-{
- hid_keyboard_report_t report;
-
- report.modifier = modifier;
- report.reserved = 0;
-
- if ( keycode )
- {
- memcpy(report.keycode, keycode, 6);
- }else
- {
- tu_memclr(report.keycode, 6);
- }
-
- return tud_hid_n_report(instance, report_id, &report, sizeof(report));
-}
-
-bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id,
- uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
-{
- hid_mouse_report_t report =
- {
- .buttons = buttons,
- .x = x,
- .y = y,
- .wheel = vertical,
- .pan = horizontal
- };
-
- return tud_hid_n_report(instance, report_id, &report, sizeof(report));
-}
-
-bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id,
- int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons)
-{
- hid_gamepad_report_t report =
- {
- .x = x,
- .y = y,
- .z = z,
- .rz = rz,
- .rx = rx,
- .ry = ry,
- .hat = hat,
- .buttons = buttons,
- };
-
- return tud_hid_n_report(instance, report_id, &report, sizeof(report));
-}
-
-//--------------------------------------------------------------------+
-// USBD-CLASS API
-//--------------------------------------------------------------------+
-void hidd_init(void)
-{
- hidd_reset(TUD_OPT_RHPORT);
-}
-
-void hidd_reset(uint8_t rhport)
-{
- (void) rhport;
- tu_memclr(_hidd_itf, sizeof(_hidd_itf));
-}
-
-uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t max_len)
-{
- TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass, 0);
-
- // len = interface + hid + n*endpoints
- uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
- TU_ASSERT(max_len >= drv_len, 0);
-
- // Find available interface
- hidd_interface_t * p_hid = NULL;
- uint8_t hid_id;
- for(hid_id=0; hid_id<CFG_TUD_HID; hid_id++)
- {
- if ( _hidd_itf[hid_id].ep_in == 0 )
- {
- p_hid = &_hidd_itf[hid_id];
- break;
- }
- }
- TU_ASSERT(p_hid, 0);
-
- uint8_t const *p_desc = (uint8_t const *) desc_itf;
-
- //------------- HID descriptor -------------//
- p_desc = tu_desc_next(p_desc);
- p_hid->hid_descriptor = (tusb_hid_descriptor_hid_t const *) p_desc;
- TU_ASSERT(HID_DESC_TYPE_HID == p_hid->hid_descriptor->bDescriptorType, 0);
-
- //------------- Endpoint Descriptor -------------//
- p_desc = tu_desc_next(p_desc);
- TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, desc_itf->bNumEndpoints, TUSB_XFER_INTERRUPT, &p_hid->ep_out, &p_hid->ep_in), 0);
-
- if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->itf_protocol = desc_itf->bInterfaceProtocol;
-
- p_hid->protocol_mode = HID_PROTOCOL_REPORT; // Per Specs: default is report mode
- p_hid->itf_num = desc_itf->bInterfaceNumber;
-
- // Use offsetof to avoid pointer to the odd/misaligned address
- memcpy(&p_hid->report_desc_len, (uint8_t*) p_hid->hid_descriptor + offsetof(tusb_hid_descriptor_hid_t, wReportLength), 2);
-
- // Prepare for output endpoint
- if (p_hid->ep_out)
- {
- if ( !usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)) )
- {
- TU_LOG_FAILED();
- TU_BREAKPOINT();
- }
- }
-
- return drv_len;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
-
- uint8_t const hid_itf = get_index_by_itfnum((uint8_t) request->wIndex);
- TU_VERIFY(hid_itf < CFG_TUD_HID);
-
- hidd_interface_t* p_hid = &_hidd_itf[hid_itf];
-
- if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
- {
- //------------- STD Request -------------//
- if ( stage == CONTROL_STAGE_SETUP )
- {
- uint8_t const desc_type = tu_u16_high(request->wValue);
- //uint8_t const desc_index = tu_u16_low (request->wValue);
-
- if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID)
- {
- TU_VERIFY(p_hid->hid_descriptor != NULL);
- TU_VERIFY(tud_control_xfer(rhport, request, (void*) p_hid->hid_descriptor, p_hid->hid_descriptor->bLength));
- }
- else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
- {
- uint8_t const * desc_report = tud_hid_descriptor_report_cb(hid_itf);
- tud_control_xfer(rhport, request, (void*) desc_report, p_hid->report_desc_len);
- }
- else
- {
- return false; // stall unsupported request
- }
- }
- }
- else if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS)
- {
- //------------- Class Specific Request -------------//
- switch( request->bRequest )
- {
- case HID_REQ_CONTROL_GET_REPORT:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- uint8_t const report_type = tu_u16_high(request->wValue);
- uint8_t const report_id = tu_u16_low(request->wValue);
-
- uint8_t* report_buf = p_hid->epin_buf;
- uint16_t req_len = request->wLength;
-
- uint16_t xferlen = 0;
-
- // If host request a specific Report ID, add ID to as 1 byte of response
- if ( (report_id != HID_REPORT_TYPE_INVALID) && (req_len > 1) )
- {
- *report_buf++ = report_id;
- req_len--;
-
- xferlen++;
- }
-
- xferlen += tud_hid_get_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, report_buf, req_len);
- TU_ASSERT( xferlen > 0 );
-
- tud_control_xfer(rhport, request, p_hid->epin_buf, xferlen);
- }
- break;
-
- case HID_REQ_CONTROL_SET_REPORT:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- TU_VERIFY(request->wLength <= sizeof(p_hid->epout_buf));
- tud_control_xfer(rhport, request, p_hid->epout_buf, request->wLength);
- }
- else if ( stage == CONTROL_STAGE_ACK )
- {
- uint8_t const report_type = tu_u16_high(request->wValue);
- uint8_t const report_id = tu_u16_low(request->wValue);
-
- uint8_t const* report_buf = p_hid->epout_buf;
- uint16_t report_len = request->wLength;
-
- // If host request a specific Report ID, extract report ID in buffer before invoking callback
- if ( (report_id != HID_REPORT_TYPE_INVALID) && (report_len > 1) && (report_id == report_buf[0]) )
- {
- report_buf++;
- report_len--;
- }
-
- tud_hid_set_report_cb(hid_itf, report_id, (hid_report_type_t) report_type, report_buf, report_len);
- }
- break;
-
- case HID_REQ_CONTROL_SET_IDLE:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- p_hid->idle_rate = tu_u16_high(request->wValue);
- if ( tud_hid_set_idle_cb )
- {
- // stall request if callback return false
- TU_VERIFY( tud_hid_set_idle_cb( hid_itf, p_hid->idle_rate) );
- }
-
- tud_control_status(rhport, request);
- }
- break;
-
- case HID_REQ_CONTROL_GET_IDLE:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- // TODO idle rate of report
- tud_control_xfer(rhport, request, &p_hid->idle_rate, 1);
- }
- break;
-
- case HID_REQ_CONTROL_GET_PROTOCOL:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- tud_control_xfer(rhport, request, &p_hid->protocol_mode, 1);
- }
- break;
-
- case HID_REQ_CONTROL_SET_PROTOCOL:
- if ( stage == CONTROL_STAGE_SETUP )
- {
- tud_control_status(rhport, request);
- }
- else if ( stage == CONTROL_STAGE_ACK )
- {
- p_hid->protocol_mode = (uint8_t) request->wValue;
- if (tud_hid_set_protocol_cb)
- {
- tud_hid_set_protocol_cb(hid_itf, p_hid->protocol_mode);
- }
- }
- break;
-
- default: return false; // stall unsupported request
- }
- }else
- {
- return false; // stall unsupported request
- }
-
- return true;
-}
-
-bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void) result;
-
- uint8_t instance = 0;
- hidd_interface_t * p_hid = _hidd_itf;
-
- // Identify which interface to use
- for (instance = 0; instance < CFG_TUD_HID; instance++)
- {
- p_hid = &_hidd_itf[instance];
- if ( (ep_addr == p_hid->ep_out) || (ep_addr == p_hid->ep_in) ) break;
- }
- TU_ASSERT(instance < CFG_TUD_HID);
-
- // Sent report successfully
- if (ep_addr == p_hid->ep_in)
- {
- if (tud_hid_report_complete_cb)
- {
- tud_hid_report_complete_cb(instance, p_hid->epin_buf, (uint8_t) xferred_bytes);
- }
- }
- // Received report
- else if (ep_addr == p_hid->ep_out)
- {
- tud_hid_set_report_cb(instance, 0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
- TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
- }
-
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/class/hid/hid_device.h b/tinyusb/src/class/hid/hid_device.h
deleted file mode 100755
index e2c950dd..00000000
--- a/tinyusb/src/class/hid/hid_device.h
+++ /dev/null
@@ -1,393 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_HID_DEVICE_H_
-#define _TUSB_HID_DEVICE_H_
-
-#include "hid.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Class Driver Default Configure & Validation
-//--------------------------------------------------------------------+
-
-#if !defined(CFG_TUD_HID_EP_BUFSIZE) & defined(CFG_TUD_HID_BUFSIZE)
- // TODO warn user to use new name later on
- // #warning CFG_TUD_HID_BUFSIZE is renamed to CFG_TUD_HID_EP_BUFSIZE, please update to use the new name
- #define CFG_TUD_HID_EP_BUFSIZE CFG_TUD_HID_BUFSIZE
-#endif
-
-#ifndef CFG_TUD_HID_EP_BUFSIZE
- #define CFG_TUD_HID_EP_BUFSIZE 64
-#endif
-
-//--------------------------------------------------------------------+
-// Application API (Multiple Instances)
-// CFG_TUD_HID > 1
-//--------------------------------------------------------------------+
-
-// Check if the interface is ready to use
-bool tud_hid_n_ready(uint8_t instance);
-
-// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values
-uint8_t tud_hid_n_interface_protocol(uint8_t instance);
-
-// Get current active protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
-uint8_t tud_hid_n_get_protocol(uint8_t instance);
-
-// Send report to host
-bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint8_t len);
-
-// KEYBOARD: convenient helper to send keyboard report if application
-// use template layout report as defined by hid_keyboard_report_t
-bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
-
-// MOUSE: convenient helper to send mouse report if application
-// use template layout report as defined by hid_mouse_report_t
-bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
-
-// Gamepad: convenient helper to send gamepad report if application
-// use template layout report TUD_HID_REPORT_DESC_GAMEPAD
-bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons);
-
-//--------------------------------------------------------------------+
-// Application API (Single Port)
-//--------------------------------------------------------------------+
-static inline bool tud_hid_ready(void);
-static inline uint8_t tud_hid_interface_protocol(void);
-static inline uint8_t tud_hid_get_protocol(void);
-static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
-static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
-static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
-static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons);
-
-//--------------------------------------------------------------------+
-// Callbacks (Weak is optional)
-//--------------------------------------------------------------------+
-
-// Invoked when received GET HID REPORT DESCRIPTOR request
-// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance);
-
-// Invoked when received GET_REPORT control request
-// Application must fill buffer report's content and return its length.
-// Return zero will cause the stack to STALL request
-uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
-
-// Invoked when received SET_REPORT control request or
-// received data on OUT endpoint ( Report ID = 0, Type = 0 )
-void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
-
-// Invoked when received SET_PROTOCOL request
-// protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
-TU_ATTR_WEAK void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol);
-
-// Invoked when received SET_IDLE request. return false will stall the request
-// - Idle Rate = 0 : only send report if there is changes, i.e skip duplication
-// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
-TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate);
-
-// Invoked when sent REPORT successfully to host
-// Application can use this to send the next report
-// Note: For composite reports, report[0] is report ID
-TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len);
-
-
-//--------------------------------------------------------------------+
-// Inline Functions
-//--------------------------------------------------------------------+
-static inline bool tud_hid_ready(void)
-{
- return tud_hid_n_ready(0);
-}
-
-static inline uint8_t tud_hid_interface_protocol(void)
-{
- return tud_hid_n_interface_protocol(0);
-}
-
-static inline uint8_t tud_hid_get_protocol(void)
-{
- return tud_hid_n_get_protocol(0);
-}
-
-static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
-{
- return tud_hid_n_report(0, report_id, report, len);
-}
-
-static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
-{
- return tud_hid_n_keyboard_report(0, report_id, modifier, keycode);
-}
-
-static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
-{
- return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal);
-}
-
-static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons)
-{
- return tud_hid_n_gamepad_report(0, report_id, x, y, z, rz, rx, ry, hat, buttons);
-}
-
-/* --------------------------------------------------------------------+
- * HID Report Descriptor Template
- *
- * Convenient for declaring popular HID device (keyboard, mouse, consumer,
- * gamepad etc...). Templates take "HID_REPORT_ID(n)" as input, leave
- * empty if multiple reports is not used
- *
- * - Only 1 report: no parameter
- * uint8_t const report_desc[] = { TUD_HID_REPORT_DESC_KEYBOARD() };
- *
- * - Multiple Reports: "HID_REPORT_ID(ID)" must be passed to template
- * uint8_t const report_desc[] =
- * {
- * TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1) ) ,
- * TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2) )
- * };
- *--------------------------------------------------------------------*/
-
-// Keyboard Report Descriptor Template
-#define TUD_HID_REPORT_DESC_KEYBOARD(...) \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ) ,\
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
- /* Report ID if any */\
- __VA_ARGS__ \
- /* 8 bits Modifier Keys (Shfit, Control, Alt) */ \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
- HID_USAGE_MIN ( 224 ) ,\
- HID_USAGE_MAX ( 231 ) ,\
- HID_LOGICAL_MIN ( 0 ) ,\
- HID_LOGICAL_MAX ( 1 ) ,\
- HID_REPORT_COUNT ( 8 ) ,\
- HID_REPORT_SIZE ( 1 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
- /* 8 bit reserved */ \
- HID_REPORT_COUNT ( 1 ) ,\
- HID_REPORT_SIZE ( 8 ) ,\
- HID_INPUT ( HID_CONSTANT ) ,\
- /* 6-byte Keycodes */ \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
- HID_USAGE_MIN ( 0 ) ,\
- HID_USAGE_MAX_N ( 255, 2 ) ,\
- HID_LOGICAL_MIN ( 0 ) ,\
- HID_LOGICAL_MAX_N( 255, 2 ) ,\
- HID_REPORT_COUNT ( 6 ) ,\
- HID_REPORT_SIZE ( 8 ) ,\
- HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
- /* 5-bit LED Indicator Kana | Compose | ScrollLock | CapsLock | NumLock */ \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ) ,\
- HID_USAGE_MIN ( 1 ) ,\
- HID_USAGE_MAX ( 5 ) ,\
- HID_REPORT_COUNT ( 5 ) ,\
- HID_REPORT_SIZE ( 1 ) ,\
- HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
- /* led padding */ \
- HID_REPORT_COUNT ( 1 ) ,\
- HID_REPORT_SIZE ( 3 ) ,\
- HID_OUTPUT ( HID_CONSTANT ) ,\
- HID_COLLECTION_END \
-
-// Mouse Report Descriptor Template
-#define TUD_HID_REPORT_DESC_MOUSE(...) \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
- /* Report ID if any */\
- __VA_ARGS__ \
- HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\
- HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\
- HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
- HID_USAGE_MIN ( 1 ) ,\
- HID_USAGE_MAX ( 5 ) ,\
- HID_LOGICAL_MIN ( 0 ) ,\
- HID_LOGICAL_MAX ( 1 ) ,\
- /* Left, Right, Middle, Backward, Forward buttons */ \
- HID_REPORT_COUNT( 5 ) ,\
- HID_REPORT_SIZE ( 1 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
- /* 3 bit padding */ \
- HID_REPORT_COUNT( 1 ) ,\
- HID_REPORT_SIZE ( 3 ) ,\
- HID_INPUT ( HID_CONSTANT ) ,\
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- /* X, Y position [-127, 127] */ \
- HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
- HID_LOGICAL_MIN ( 0x81 ) ,\
- HID_LOGICAL_MAX ( 0x7f ) ,\
- HID_REPORT_COUNT( 2 ) ,\
- HID_REPORT_SIZE ( 8 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
- /* Verital wheel scroll [-127, 127] */ \
- HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ) ,\
- HID_LOGICAL_MIN ( 0x81 ) ,\
- HID_LOGICAL_MAX ( 0x7f ) ,\
- HID_REPORT_COUNT( 1 ) ,\
- HID_REPORT_SIZE ( 8 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
- HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ), \
- /* Horizontal wheel scroll [-127, 127] */ \
- HID_USAGE_N ( HID_USAGE_CONSUMER_AC_PAN, 2 ), \
- HID_LOGICAL_MIN ( 0x81 ), \
- HID_LOGICAL_MAX ( 0x7f ), \
- HID_REPORT_COUNT( 1 ), \
- HID_REPORT_SIZE ( 8 ), \
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), \
- HID_COLLECTION_END , \
- HID_COLLECTION_END \
-
-// Consumer Control Report Descriptor Template
-#define TUD_HID_REPORT_DESC_CONSUMER(...) \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\
- HID_USAGE ( HID_USAGE_CONSUMER_CONTROL ) ,\
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
- /* Report ID if any */\
- __VA_ARGS__ \
- HID_LOGICAL_MIN ( 0x00 ) ,\
- HID_LOGICAL_MAX_N( 0x03FF, 2 ) ,\
- HID_USAGE_MIN ( 0x00 ) ,\
- HID_USAGE_MAX_N ( 0x03FF, 2 ) ,\
- HID_REPORT_COUNT ( 1 ) ,\
- HID_REPORT_SIZE ( 16 ) ,\
- HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
- HID_COLLECTION_END \
-
-/* System Control Report Descriptor Template
- * 0x00 - do nothing
- * 0x01 - Power Off
- * 0x02 - Standby
- * 0x03 - Wake Host
- */
-#define TUD_HID_REPORT_DESC_SYSTEM_CONTROL(...) \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_CONTROL ) ,\
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
- /* Report ID if any */\
- __VA_ARGS__ \
- /* 2 bit system power control */ \
- HID_LOGICAL_MIN ( 1 ) ,\
- HID_LOGICAL_MAX ( 3 ) ,\
- HID_REPORT_COUNT ( 1 ) ,\
- HID_REPORT_SIZE ( 2 ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_SLEEP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_WAKE_UP ) ,\
- HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
- /* 6 bit padding */ \
- HID_REPORT_COUNT ( 1 ) ,\
- HID_REPORT_SIZE ( 6 ) ,\
- HID_INPUT ( HID_CONSTANT ) ,\
- HID_COLLECTION_END \
-
-// Gamepad Report Descriptor Template
-// with 16 buttons, 2 joysticks and 1 hat/dpad with following layout
-// | X | Y | Z | Rz | Rx | Ry (1 byte each) | hat/DPAD (1 byte) | Button Map (2 bytes) |
-#define TUD_HID_REPORT_DESC_GAMEPAD(...) \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
- /* Report ID if any */\
- __VA_ARGS__ \
- /* 8 bit X, Y, Z, Rz, Rx, Ry (min -127, max 127 ) */ \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\
- HID_LOGICAL_MIN ( 0x81 ) ,\
- HID_LOGICAL_MAX ( 0x7f ) ,\
- HID_REPORT_COUNT ( 6 ) ,\
- HID_REPORT_SIZE ( 8 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
- /* 8 bit DPad/Hat Button Map */ \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\
- HID_LOGICAL_MIN ( 1 ) ,\
- HID_LOGICAL_MAX ( 8 ) ,\
- HID_PHYSICAL_MIN ( 0 ) ,\
- HID_PHYSICAL_MAX_N ( 315, 2 ) ,\
- HID_REPORT_COUNT ( 1 ) ,\
- HID_REPORT_SIZE ( 8 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
- /* 16 bit Button Map */ \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
- HID_USAGE_MIN ( 1 ) ,\
- HID_USAGE_MAX ( 32 ) ,\
- HID_LOGICAL_MIN ( 0 ) ,\
- HID_LOGICAL_MAX ( 1 ) ,\
- HID_REPORT_COUNT ( 32 ) ,\
- HID_REPORT_SIZE ( 1 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
- HID_COLLECTION_END \
-
-// HID Generic Input & Output
-// - 1st parameter is report size (mandatory)
-// - 2nd parameter is report id HID_REPORT_ID(n) (optional)
-#define TUD_HID_REPORT_DESC_GENERIC_INOUT(report_size, ...) \
- HID_USAGE_PAGE_N ( HID_USAGE_PAGE_VENDOR, 2 ),\
- HID_USAGE ( 0x01 ),\
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ),\
- /* Report ID if any */\
- __VA_ARGS__ \
- /* Input */ \
- HID_USAGE ( 0x02 ),\
- HID_LOGICAL_MIN ( 0x00 ),\
- HID_LOGICAL_MAX ( 0xff ),\
- HID_REPORT_SIZE ( 8 ),\
- HID_REPORT_COUNT( report_size ),\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\
- /* Output */ \
- HID_USAGE ( 0x03 ),\
- HID_LOGICAL_MIN ( 0x00 ),\
- HID_LOGICAL_MAX ( 0xff ),\
- HID_REPORT_SIZE ( 8 ),\
- HID_REPORT_COUNT( report_size ),\
- HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\
- HID_COLLECTION_END \
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void hidd_init (void);
-void hidd_reset (uint8_t rhport);
-uint16_t hidd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-bool hidd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_HID_DEVICE_H_ */
diff --git a/tinyusb/src/class/hid/hid_host.c b/tinyusb/src/class/hid/hid_host.c
deleted file mode 100755
index 8c66477b..00000000
--- a/tinyusb/src/class/hid/hid_host.c
+++ /dev/null
@@ -1,628 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_HID)
-
-#include "host/usbh.h"
-#include "host/usbh_classdriver.h"
-
-#include "hid_host.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-typedef struct
-{
- uint8_t itf_num;
- uint8_t ep_in;
- uint8_t ep_out;
-
- uint8_t itf_protocol; // None, Keyboard, Mouse
- uint8_t protocol_mode; // Boot (0) or Report protocol (1)
-
- uint8_t report_desc_type;
- uint16_t report_desc_len;
-
- uint16_t epin_size;
- uint16_t epout_size;
-
- uint8_t epin_buf[CFG_TUH_HID_EPIN_BUFSIZE];
- uint8_t epout_buf[CFG_TUH_HID_EPOUT_BUFSIZE];
-} hidh_interface_t;
-
-typedef struct
-{
- uint8_t inst_count;
- hidh_interface_t instances[CFG_TUH_HID];
-} hidh_device_t;
-
-static hidh_device_t _hidh_dev[CFG_TUH_DEVICE_MAX];
-
-//------------- Internal prototypes -------------//
-
-// Get HID device & interface
-TU_ATTR_ALWAYS_INLINE static inline hidh_device_t* get_dev(uint8_t dev_addr);
-TU_ATTR_ALWAYS_INLINE static inline hidh_interface_t* get_instance(uint8_t dev_addr, uint8_t instance);
-static uint8_t get_instance_id_by_itfnum(uint8_t dev_addr, uint8_t itf);
-static uint8_t get_instance_id_by_epaddr(uint8_t dev_addr, uint8_t ep_addr);
-
-//--------------------------------------------------------------------+
-// Interface API
-//--------------------------------------------------------------------+
-
-uint8_t tuh_hid_instance_count(uint8_t dev_addr)
-{
- return get_dev(dev_addr)->inst_count;
-}
-
-bool tuh_hid_mounted(uint8_t dev_addr, uint8_t instance)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
- return (hid_itf->ep_in != 0) || (hid_itf->ep_out != 0);
-}
-
-uint8_t tuh_hid_interface_protocol(uint8_t dev_addr, uint8_t instance)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
- return hid_itf->itf_protocol;
-}
-
-//--------------------------------------------------------------------+
-// Control Endpoint API
-//--------------------------------------------------------------------+
-
-uint8_t tuh_hid_get_protocol(uint8_t dev_addr, uint8_t instance)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
- return hid_itf->protocol_mode;
-}
-
-static bool set_protocol_complete(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result)
-{
- uint8_t const itf_num = (uint8_t) request->wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- if (XFER_RESULT_SUCCESS == result) hid_itf->protocol_mode = (uint8_t) request->wValue;
-
- if (tuh_hid_set_protocol_complete_cb)
- {
- tuh_hid_set_protocol_complete_cb(dev_addr, instance, hid_itf->protocol_mode);
- }
-
- return true;
-}
-
-bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
- TU_VERIFY(hid_itf->itf_protocol != HID_ITF_PROTOCOL_NONE);
-
- TU_LOG2("HID Set Protocol = %d\r\n", protocol);
-
- tusb_control_request_t const request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = HID_REQ_CONTROL_SET_PROTOCOL,
- .wValue = protocol,
- .wIndex = hid_itf->itf_num,
- .wLength = 0
- };
-
- TU_ASSERT( tuh_control_xfer(dev_addr, &request, NULL, set_protocol_complete) );
- return true;
-}
-
-static bool set_report_complete(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result)
-{
- TU_LOG2("HID Set Report complete\r\n");
-
- if (tuh_hid_set_report_complete_cb)
- {
- uint8_t const itf_num = (uint8_t) request->wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
-
- uint8_t const report_type = tu_u16_high(request->wValue);
- uint8_t const report_id = tu_u16_low(request->wValue);
-
- tuh_hid_set_report_complete_cb(dev_addr, instance, report_id, report_type, (result == XFER_RESULT_SUCCESS) ? request->wLength : 0);
- }
-
- return true;
-}
-
-bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, void* report, uint16_t len)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
- TU_LOG2("HID Set Report: id = %u, type = %u, len = %u\r\n", report_id, report_type, len);
-
- tusb_control_request_t const request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = HID_REQ_CONTROL_SET_REPORT,
- .wValue = tu_u16(report_type, report_id),
- .wIndex = hid_itf->itf_num,
- .wLength = len
- };
-
- TU_ASSERT( tuh_control_xfer(dev_addr, &request, report, set_report_complete) );
- return true;
-}
-
-//--------------------------------------------------------------------+
-// Interrupt Endpoint API
-//--------------------------------------------------------------------+
-
-bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- // claim endpoint
- TU_VERIFY( usbh_edpt_claim(dev_addr, hid_itf->ep_in) );
-
- return usbh_edpt_xfer(dev_addr, hid_itf->ep_in, hid_itf->epin_buf, hid_itf->epin_size);
-}
-
-//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance)
-//{
-// TU_VERIFY(tuh_n_hid_n_mounted(dev_addr, instance));
-//
-// hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
-//}
-
-//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
-
-//--------------------------------------------------------------------+
-// USBH API
-//--------------------------------------------------------------------+
-void hidh_init(void)
-{
- tu_memclr(_hidh_dev, sizeof(_hidh_dev));
-}
-
-bool hidh_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void) result;
-
- uint8_t const dir = tu_edpt_dir(ep_addr);
- uint8_t const instance = get_instance_id_by_epaddr(dev_addr, ep_addr);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- if ( dir == TUSB_DIR_IN )
- {
- TU_LOG2(" Get Report callback (%u, %u)\r\n", dev_addr, instance);
- TU_LOG3_MEM(hid_itf->epin_buf, xferred_bytes, 2);
- tuh_hid_report_received_cb(dev_addr, instance, hid_itf->epin_buf, xferred_bytes);
- }else
- {
- if (tuh_hid_report_sent_cb) tuh_hid_report_sent_cb(dev_addr, instance, hid_itf->epout_buf, xferred_bytes);
- }
-
- return true;
-}
-
-void hidh_close(uint8_t dev_addr)
-{
- TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX, );
-
- hidh_device_t* hid_dev = get_dev(dev_addr);
-
- if (tuh_hid_umount_cb)
- {
- for (uint8_t inst = 0; inst < hid_dev->inst_count; inst++ ) tuh_hid_umount_cb(dev_addr, inst);
- }
-
- tu_memclr(hid_dev, sizeof(hidh_device_t));
-}
-
-//--------------------------------------------------------------------+
-// Enumeration
-//--------------------------------------------------------------------+
-
-static bool config_set_protocol (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result);
-static bool config_get_report_desc (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result);
-static bool config_get_report_desc_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result);
-
-static void config_driver_mount_complete(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len);
-
-bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
-{
- (void) max_len;
-
- TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass);
-
- TU_LOG2("HID opening Interface %u (addr = %u)\r\n", desc_itf->bInterfaceNumber, dev_addr);
-
- // len = interface + hid + n*endpoints
- uint16_t const drv_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
- TU_ASSERT(max_len >= drv_len);
-
- uint8_t const *p_desc = (uint8_t const *) desc_itf;
-
- //------------- HID descriptor -------------//
- p_desc = tu_desc_next(p_desc);
- tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
- TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType);
-
- // not enough interface, try to increase CFG_TUH_HID
- // TODO multiple devices
- hidh_device_t* hid_dev = get_dev(dev_addr);
- TU_ASSERT(hid_dev->inst_count < CFG_TUH_HID, 0);
-
- //------------- Endpoint Descriptor -------------//
- p_desc = tu_desc_next(p_desc);
- tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
-
- // TODO also open endpoint OUT
- TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
-
- hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count);
- hid_dev->inst_count++;
-
- hid_itf->itf_num = desc_itf->bInterfaceNumber;
- hid_itf->ep_in = desc_ep->bEndpointAddress;
- hid_itf->epin_size = desc_ep->wMaxPacketSize.size;
-
- // Assume bNumDescriptors = 1
- hid_itf->report_desc_type = desc_hid->bReportType;
- hid_itf->report_desc_len = tu_unaligned_read16(&desc_hid->wReportLength);
-
- // Per HID Specs: default is Report protocol, though we will force Boot protocol when set_config
- hid_itf->protocol_mode = HID_PROTOCOL_BOOT;
- if ( HID_SUBCLASS_BOOT == desc_itf->bInterfaceSubClass ) hid_itf->itf_protocol = desc_itf->bInterfaceProtocol;
-
- return true;
-}
-
-bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num)
-{
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- // Idle rate = 0 mean only report when there is changes
- uint16_t const idle_rate = 0;
-
- // SET IDLE request, device can stall if not support this request
- TU_LOG2("HID Set Idle \r\n");
- tusb_control_request_t const request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = HID_REQ_CONTROL_SET_IDLE,
- .wValue = idle_rate,
- .wIndex = itf_num,
- .wLength = 0
- };
-
- TU_ASSERT( tuh_control_xfer(dev_addr, &request, NULL, (hid_itf->itf_protocol != HID_ITF_PROTOCOL_NONE) ? config_set_protocol : config_get_report_desc) );
-
- return true;
-}
-
-// Force device to work in BOOT protocol
-static bool config_set_protocol(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result)
-{
- // Stall is a valid response for SET_IDLE, therefore we could ignore its result
- (void) result;
-
- uint8_t const itf_num = (uint8_t) request->wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- TU_LOG2("HID Set Protocol to Boot Mode\r\n");
- hid_itf->protocol_mode = HID_PROTOCOL_BOOT;
- tusb_control_request_t const new_request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = HID_REQ_CONTROL_SET_PROTOCOL,
- .wValue = HID_PROTOCOL_BOOT,
- .wIndex = hid_itf->itf_num,
- .wLength = 0
- };
-
- TU_ASSERT( tuh_control_xfer(dev_addr, &new_request, NULL, config_get_report_desc) );
- return true;
-}
-
-static bool config_get_report_desc(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result)
-{
- // We can be here after SET_IDLE or SET_PROTOCOL (boot device)
- // Trigger assert if result is not successful with set protocol
- if ( request->bRequest != HID_REQ_CONTROL_SET_IDLE )
- {
- TU_ASSERT(result == XFER_RESULT_SUCCESS);
- }
-
- uint8_t const itf_num = (uint8_t) request->wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- // Get Report Descriptor if possible
- // using usbh enumeration buffer since report descriptor can be very long
- if( hid_itf->report_desc_len > CFG_TUH_ENUMERATION_BUFSIZE )
- {
- TU_LOG2("HID Skip Report Descriptor since it is too large %u bytes\r\n", hid_itf->report_desc_len);
-
- // Driver is mounted without report descriptor
- config_driver_mount_complete(dev_addr, instance, NULL, 0);
- }else
- {
- TU_LOG2("HID Get Report Descriptor\r\n");
- tusb_control_request_t const new_request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_STANDARD,
- .direction = TUSB_DIR_IN
- },
- .bRequest = TUSB_REQ_GET_DESCRIPTOR,
- .wValue = tu_u16(hid_itf->report_desc_type, 0),
- .wIndex = itf_num,
- .wLength = hid_itf->report_desc_len
- };
-
- TU_ASSERT(tuh_control_xfer(dev_addr, &new_request, usbh_get_enum_buf(), config_get_report_desc_complete));
- }
-
- return true;
-}
-
-static bool config_get_report_desc_complete(uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result)
-{
- TU_ASSERT(XFER_RESULT_SUCCESS == result);
-
- uint8_t const itf_num = (uint8_t) request->wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
-
- uint8_t const* desc_report = usbh_get_enum_buf();
- uint16_t const desc_len = request->wLength;
-
- config_driver_mount_complete(dev_addr, instance, desc_report, desc_len);
-
- return true;
-}
-
-static void config_driver_mount_complete(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- // enumeration is complete
- tuh_hid_mount_cb(dev_addr, instance, desc_report, desc_len);
-
- // notify usbh that driver enumeration is complete
- usbh_driver_set_config_complete(dev_addr, hid_itf->itf_num);
-}
-
-//--------------------------------------------------------------------+
-// Report Descriptor Parser
-//--------------------------------------------------------------------+
-
-uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* report_info_arr, uint8_t arr_count, uint8_t const* desc_report, uint16_t desc_len)
-{
- // Report Item 6.2.2.2 USB HID 1.11
- union TU_ATTR_PACKED
- {
- uint8_t byte;
- struct TU_ATTR_PACKED
- {
- uint8_t size : 2;
- uint8_t type : 2;
- uint8_t tag : 4;
- };
- } header;
-
- tu_memclr(report_info_arr, arr_count*sizeof(tuh_hid_report_info_t));
-
- uint8_t report_num = 0;
- tuh_hid_report_info_t* info = report_info_arr;
-
- // current parsed report count & size from descriptor
-// uint8_t ri_report_count = 0;
-// uint8_t ri_report_size = 0;
-
- uint8_t ri_collection_depth = 0;
-
- while(desc_len && report_num < arr_count)
- {
- header.byte = *desc_report++;
- desc_len--;
-
- uint8_t const tag = header.tag;
- uint8_t const type = header.type;
- uint8_t const size = header.size;
-
- uint8_t const data8 = desc_report[0];
-
- TU_LOG(3, "tag = %d, type = %d, size = %d, data = ", tag, type, size);
- for(uint32_t i=0; i<size; i++) TU_LOG(3, "%02X ", desc_report[i]);
- TU_LOG(3, "\r\n");
-
- switch(type)
- {
- case RI_TYPE_MAIN:
- switch (tag)
- {
- case RI_MAIN_INPUT: break;
- case RI_MAIN_OUTPUT: break;
- case RI_MAIN_FEATURE: break;
-
- case RI_MAIN_COLLECTION:
- ri_collection_depth++;
- break;
-
- case RI_MAIN_COLLECTION_END:
- ri_collection_depth--;
- if (ri_collection_depth == 0)
- {
- info++;
- report_num++;
- }
- break;
-
- default: break;
- }
- break;
-
- case RI_TYPE_GLOBAL:
- switch(tag)
- {
- case RI_GLOBAL_USAGE_PAGE:
- // only take in account the "usage page" before REPORT ID
- if ( ri_collection_depth == 0 ) memcpy(&info->usage_page, desc_report, size);
- break;
-
- case RI_GLOBAL_LOGICAL_MIN : break;
- case RI_GLOBAL_LOGICAL_MAX : break;
- case RI_GLOBAL_PHYSICAL_MIN : break;
- case RI_GLOBAL_PHYSICAL_MAX : break;
-
- case RI_GLOBAL_REPORT_ID:
- info->report_id = data8;
- break;
-
- case RI_GLOBAL_REPORT_SIZE:
-// ri_report_size = data8;
- break;
-
- case RI_GLOBAL_REPORT_COUNT:
-// ri_report_count = data8;
- break;
-
- case RI_GLOBAL_UNIT_EXPONENT : break;
- case RI_GLOBAL_UNIT : break;
- case RI_GLOBAL_PUSH : break;
- case RI_GLOBAL_POP : break;
-
- default: break;
- }
- break;
-
- case RI_TYPE_LOCAL:
- switch(tag)
- {
- case RI_LOCAL_USAGE:
- // only take in account the "usage" before starting REPORT ID
- if ( ri_collection_depth == 0 ) info->usage = data8;
- break;
-
- case RI_LOCAL_USAGE_MIN : break;
- case RI_LOCAL_USAGE_MAX : break;
- case RI_LOCAL_DESIGNATOR_INDEX : break;
- case RI_LOCAL_DESIGNATOR_MIN : break;
- case RI_LOCAL_DESIGNATOR_MAX : break;
- case RI_LOCAL_STRING_INDEX : break;
- case RI_LOCAL_STRING_MIN : break;
- case RI_LOCAL_STRING_MAX : break;
- case RI_LOCAL_DELIMITER : break;
- default: break;
- }
- break;
-
- // error
- default: break;
- }
-
- desc_report += size;
- desc_len -= size;
- }
-
- for ( uint8_t i = 0; i < report_num; i++ )
- {
- info = report_info_arr+i;
- TU_LOG2("%u: id = %u, usage_page = %u, usage = %u\r\n", i, info->report_id, info->usage_page, info->usage);
- }
-
- return report_num;
-}
-
-//--------------------------------------------------------------------+
-// Helper
-//--------------------------------------------------------------------+
-
-// Get Device by address
-TU_ATTR_ALWAYS_INLINE static inline hidh_device_t* get_dev(uint8_t dev_addr)
-{
- return &_hidh_dev[dev_addr-1];
-}
-
-// Get Interface by instance number
-TU_ATTR_ALWAYS_INLINE static inline hidh_interface_t* get_instance(uint8_t dev_addr, uint8_t instance)
-{
- return &_hidh_dev[dev_addr-1].instances[instance];
-}
-
-// Get instance ID by interface number
-static uint8_t get_instance_id_by_itfnum(uint8_t dev_addr, uint8_t itf)
-{
- for ( uint8_t inst = 0; inst < CFG_TUH_HID; inst++ )
- {
- hidh_interface_t *hid = get_instance(dev_addr, inst);
-
- if ( (hid->itf_num == itf) && (hid->ep_in || hid->ep_out) ) return inst;
- }
-
- return 0xff;
-}
-
-// Get instance ID by endpoint address
-static uint8_t get_instance_id_by_epaddr(uint8_t dev_addr, uint8_t ep_addr)
-{
- for ( uint8_t inst = 0; inst < CFG_TUH_HID; inst++ )
- {
- hidh_interface_t *hid = get_instance(dev_addr, inst);
-
- if ( (ep_addr == hid->ep_in) || ( ep_addr == hid->ep_out) ) return inst;
- }
-
- return 0xff;
-}
-
-#endif
diff --git a/tinyusb/src/class/hid/hid_host.h b/tinyusb/src/class/hid/hid_host.h
deleted file mode 100755
index fe09b03b..00000000
--- a/tinyusb/src/class/hid/hid_host.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_HID_HOST_H_
-#define _TUSB_HID_HOST_H_
-
-#include "hid.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Class Driver Configuration
-//--------------------------------------------------------------------+
-
-// TODO Highspeed interrupt can be up to 512 bytes
-#ifndef CFG_TUH_HID_EPIN_BUFSIZE
-#define CFG_TUH_HID_EPIN_BUFSIZE 64
-#endif
-
-#ifndef CFG_TUH_HID_EPOUT_BUFSIZE
-#define CFG_TUH_HID_EPOUT_BUFSIZE 64
-#endif
-
-
-typedef struct
-{
- uint8_t report_id;
- uint8_t usage;
- uint16_t usage_page;
-
- // TODO still use the endpoint size for now
-// uint8_t in_len; // length of IN report
-// uint8_t out_len; // length of OUT report
-} tuh_hid_report_info_t;
-
-//--------------------------------------------------------------------+
-// Interface API
-//--------------------------------------------------------------------+
-
-// Get the number of HID instances
-uint8_t tuh_hid_instance_count(uint8_t dev_addr);
-
-// Check if HID instance is mounted
-bool tuh_hid_mounted(uint8_t dev_addr, uint8_t instance);
-
-// Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible values
-uint8_t tuh_hid_interface_protocol(uint8_t dev_addr, uint8_t instance);
-
-// Parse report descriptor into array of report_info struct and return number of reports.
-// For complicated report, application should write its own parser.
-uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* reports_info_arr, uint8_t arr_count, uint8_t const* desc_report, uint16_t desc_len) TU_ATTR_UNUSED;
-
-//--------------------------------------------------------------------+
-// Control Endpoint API
-//--------------------------------------------------------------------+
-
-// Get current protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
-// Note: Device will be initialized in Boot protocol for simplicity.
-// Application can use set_protocol() to switch back to Report protocol.
-uint8_t tuh_hid_get_protocol(uint8_t dev_addr, uint8_t instance);
-
-// Set protocol to HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
-// This function is only supported by Boot interface (tuh_n_hid_interface_protocol() != NONE)
-bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol);
-
-// Set Report using control endpoint
-// report_type is either Intput, Output or Feature, (value from hid_report_type_t)
-bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, void* report, uint16_t len);
-
-//--------------------------------------------------------------------+
-// Interrupt Endpoint API
-//--------------------------------------------------------------------+
-
-// Check if the interface is ready to use
-//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance);
-
-// Try to receive next report on Interrupt Endpoint. Immediately return
-// - true If succeeded, tuh_hid_report_received_cb() callback will be invoked when report is available
-// - false if failed to queue the transfer e.g endpoint is busy
-bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance);
-
-// Send report using interrupt endpoint
-// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
-//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len);
-
-//--------------------------------------------------------------------+
-// Callbacks (Weak is optional)
-//--------------------------------------------------------------------+
-
-// Invoked when device with hid interface is mounted
-// Report descriptor is also available for use. tuh_hid_parse_report_descriptor()
-// can be used to parse common/simple enough descriptor.
-// Note: if report descriptor length > CFG_TUH_ENUMERATION_BUFSIZE, it will be skipped
-// therefore report_desc = NULL, desc_len = 0
-void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report_desc, uint16_t desc_len);
-
-// Invoked when device with hid interface is un-mounted
-TU_ATTR_WEAK void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance);
-
-// Invoked when received report from device via interrupt endpoint
-// Note: if there is report ID (composite), it is 1st byte of report
-void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
-
-// Invoked when sent report to device successfully via interrupt endpoint
-TU_ATTR_WEAK void tuh_hid_report_sent_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
-
-// Invoked when Sent Report to device via either control endpoint
-// len = 0 indicate there is error in the transfer e.g stalled response
-TU_ATTR_WEAK void tuh_hid_set_report_complete_cb(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, uint16_t len);
-
-// Invoked when Set Protocol request is complete
-TU_ATTR_WEAK void tuh_hid_set_protocol_complete_cb(uint8_t dev_addr, uint8_t instance, uint8_t protocol);
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void hidh_init (void);
-bool hidh_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len);
-bool hidh_set_config (uint8_t dev_addr, uint8_t itf_num);
-bool hidh_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
-void hidh_close (uint8_t dev_addr);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _TUSB_HID_HOST_H_ */
diff --git a/tinyusb/src/class/midi/midi.h b/tinyusb/src/class/midi/midi.h
deleted file mode 100755
index 74dc4174..00000000
--- a/tinyusb/src/class/midi/midi.h
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/** \ingroup group_class
- * \defgroup ClassDriver_CDC Communication Device Class (CDC)
- * Currently only Abstract Control Model subclass is supported
- * @{ */
-
-#ifndef _TUSB_MIDI_H__
-#define _TUSB_MIDI_H__
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Class Specific Descriptor
-//--------------------------------------------------------------------+
-
-typedef enum
-{
- MIDI_CS_INTERFACE_HEADER = 0x01,
- MIDI_CS_INTERFACE_IN_JACK = 0x02,
- MIDI_CS_INTERFACE_OUT_JACK = 0x03,
- MIDI_CS_INTERFACE_ELEMENT = 0x04,
-} midi_cs_interface_subtype_t;
-
-typedef enum
-{
- MIDI_CS_ENDPOINT_GENERAL = 0x01
-} midi_cs_endpoint_subtype_t;
-
-typedef enum
-{
- MIDI_JACK_EMBEDDED = 0x01,
- MIDI_JACK_EXTERNAL = 0x02
-} midi_jack_type_t;
-
-typedef enum
-{
- MIDI_CIN_MISC = 0,
- MIDI_CIN_CABLE_EVENT = 1,
- MIDI_CIN_SYSCOM_2BYTE = 2, // 2 byte system common message e.g MTC, SongSelect
- MIDI_CIN_SYSCOM_3BYTE = 3, // 3 byte system common message e.g SPP
- MIDI_CIN_SYSEX_START = 4, // SysEx starts or continue
- MIDI_CIN_SYSEX_END_1BYTE = 5, // SysEx ends with 1 data, or 1 byte system common message
- MIDI_CIN_SYSEX_END_2BYTE = 6, // SysEx ends with 2 data
- MIDI_CIN_SYSEX_END_3BYTE = 7, // SysEx ends with 3 data
- MIDI_CIN_NOTE_ON = 8,
- MIDI_CIN_NOTE_OFF = 9,
- MIDI_CIN_POLY_KEYPRESS = 10,
- MIDI_CIN_CONTROL_CHANGE = 11,
- MIDI_CIN_PROGRAM_CHANGE = 12,
- MIDI_CIN_CHANNEL_PRESSURE = 13,
- MIDI_CIN_PITCH_BEND_CHANGE = 14,
- MIDI_CIN_1BYTE_DATA = 15
-} midi_code_index_number_t;
-
-// MIDI 1.0 status byte
-enum
-{
- //------------- System Exclusive -------------//
- MIDI_STATUS_SYSEX_START = 0xF0,
- MIDI_STATUS_SYSEX_END = 0xF7,
-
- //------------- System Common -------------//
- MIDI_STATUS_SYSCOM_TIME_CODE_QUARTER_FRAME = 0xF1,
- MIDI_STATUS_SYSCOM_SONG_POSITION_POINTER = 0xF2,
- MIDI_STATUS_SYSCOM_SONG_SELECT = 0xF3,
- // F4, F5 is undefined
- MIDI_STATUS_SYSCOM_TUNE_REQUEST = 0xF6,
-
- //------------- System RealTime -------------//
- MIDI_STATUS_SYSREAL_TIMING_CLOCK = 0xF8,
- // 0xF9 is undefined
- MIDI_STATUS_SYSREAL_START = 0xFA,
- MIDI_STATUS_SYSREAL_CONTINUE = 0xFB,
- MIDI_STATUS_SYSREAL_STOP = 0xFC,
- // 0xFD is undefined
- MIDI_STATUS_SYSREAL_ACTIVE_SENSING = 0xFE,
- MIDI_STATUS_SYSREAL_SYSTEM_RESET = 0xFF,
-};
-
-/// MIDI Interface Header Descriptor
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType
- uint16_t bcdMSC ; ///< MidiStreaming SubClass release number in Binary-Coded Decimal
- uint16_t wTotalLength ;
-} midi_desc_header_t;
-
-/// MIDI In Jack Descriptor
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType
- uint8_t bJackType ; ///< Embedded or External
- uint8_t bJackID ; ///< Unique ID for MIDI IN Jack
- uint8_t iJack ; ///< string descriptor
-} midi_desc_in_jack_t;
-
-
-/// MIDI Out Jack Descriptor with single pin
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType
- uint8_t bJackType ; ///< Embedded or External
- uint8_t bJackID ; ///< Unique ID for MIDI IN Jack
- uint8_t bNrInputPins;
-
- uint8_t baSourceID;
- uint8_t baSourcePin;
-
- uint8_t iJack ; ///< string descriptor
-} midi_desc_out_jack_t ;
-
-/// MIDI Out Jack Descriptor with multiple pins
-#define midi_desc_out_jack_n_t(input_num) \
- struct TU_ATTR_PACKED { \
- uint8_t bLength ; \
- uint8_t bDescriptorType ; \
- uint8_t bDescriptorSubType ; \
- uint8_t bJackType ; \
- uint8_t bJackID ; \
- uint8_t bNrInputPins ; \
- struct TU_ATTR_PACKED { \
- uint8_t baSourceID; \
- uint8_t baSourcePin; \
- } pins[input_num]; \
- uint8_t iJack ; \
- }
-
-/// MIDI Element Descriptor
-typedef struct TU_ATTR_PACKED
-{
- uint8_t bLength ; ///< Size of this descriptor in bytes.
- uint8_t bDescriptorType ; ///< Descriptor Type, must be Class-Specific
- uint8_t bDescriptorSubType ; ///< Descriptor SubType
- uint8_t bElementID;
-
- uint8_t bNrInputPins;
- uint8_t baSourceID;
- uint8_t baSourcePin;
-
- uint8_t bNrOutputPins;
- uint8_t bInTerminalLink;
- uint8_t bOutTerminalLink;
- uint8_t bElCapsSize;
-
- uint16_t bmElementCaps;
- uint8_t iElement;
-} midi_desc_element_t;
-
-/// MIDI Element Descriptor with multiple pins
-#define midi_desc_element_n_t(input_num) \
- struct TU_ATTR_PACKED { \
- uint8_t bLength; \
- uint8_t bDescriptorType; \
- uint8_t bDescriptorSubType; \
- uint8_t bElementID; \
- uint8_t bNrInputPins; \
- struct TU_ATTR_PACKED { \
- uint8_t baSourceID; \
- uint8_t baSourcePin; \
- } pins[input_num]; \
- uint8_t bNrOutputPins; \
- uint8_t bInTerminalLink; \
- uint8_t bOutTerminalLink; \
- uint8_t bElCapsSize; \
- uint16_t bmElementCaps; \
- uint8_t iElement; \
- }
-
-/** @} */
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif
-
-/** @} */
diff --git a/tinyusb/src/class/midi/midi_device.c b/tinyusb/src/class/midi/midi_device.c
deleted file mode 100755
index eb85b668..00000000
--- a/tinyusb/src/class/midi/midi_device.c
+++ /dev/null
@@ -1,538 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_MIDI)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "midi_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-typedef struct
-{
- uint8_t buffer[4];
- uint8_t index;
- uint8_t total;
-}midid_stream_t;
-
-typedef struct
-{
- uint8_t itf_num;
- uint8_t ep_in;
- uint8_t ep_out;
-
- // For Stream read()/write() API
- // Messages are always 4 bytes long, queue them for reading and writing so the
- // callers can use the Stream interface with single-byte read/write calls.
- midid_stream_t stream_write;
- midid_stream_t stream_read;
-
- /*------------- From this point, data is not cleared by bus reset -------------*/
- // FIFO
- tu_fifo_t rx_ff;
- tu_fifo_t tx_ff;
- uint8_t rx_ff_buf[CFG_TUD_MIDI_RX_BUFSIZE];
- uint8_t tx_ff_buf[CFG_TUD_MIDI_TX_BUFSIZE];
-
- #if CFG_FIFO_MUTEX
- osal_mutex_def_t rx_ff_mutex;
- osal_mutex_def_t tx_ff_mutex;
- #endif
-
- // Endpoint Transfer buffer
- CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_MIDI_EP_BUFSIZE];
- CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_MIDI_EP_BUFSIZE];
-
-} midid_interface_t;
-
-#define ITF_MEM_RESET_SIZE offsetof(midid_interface_t, rx_ff)
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION midid_interface_t _midid_itf[CFG_TUD_MIDI];
-
-bool tud_midi_n_mounted (uint8_t itf)
-{
- midid_interface_t* midi = &_midid_itf[itf];
- return midi->ep_in && midi->ep_out;
-}
-
-static void _prep_out_transaction (midid_interface_t* p_midi)
-{
- uint8_t const rhport = TUD_OPT_RHPORT;
- uint16_t available = tu_fifo_remaining(&p_midi->rx_ff);
-
- // Prepare for incoming data but only allow what we can store in the ring buffer.
- // TODO Actually we can still carry out the transfer, keeping count of received bytes
- // and slowly move it to the FIFO when read().
- // This pre-check reduces endpoint claiming
- TU_VERIFY(available >= sizeof(p_midi->epout_buf), );
-
- // claim endpoint
- TU_VERIFY(usbd_edpt_claim(rhport, p_midi->ep_out), );
-
- // fifo can be changed before endpoint is claimed
- available = tu_fifo_remaining(&p_midi->rx_ff);
-
- if ( available >= sizeof(p_midi->epout_buf) ) {
- usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, sizeof(p_midi->epout_buf));
- }else
- {
- // Release endpoint since we don't make any transfer
- usbd_edpt_release(rhport, p_midi->ep_out);
- }
-}
-
-//--------------------------------------------------------------------+
-// READ API
-//--------------------------------------------------------------------+
-uint32_t tud_midi_n_available(uint8_t itf, uint8_t cable_num)
-{
- (void) cable_num;
-
- midid_interface_t* midi = &_midid_itf[itf];
- midid_stream_t const* stream = &midi->stream_read;
-
- // when using with packet API stream total & index are both zero
- return tu_fifo_count(&midi->rx_ff) + (stream->total - stream->index);
-}
-
-uint32_t tud_midi_n_stream_read(uint8_t itf, uint8_t cable_num, void* buffer, uint32_t bufsize)
-{
- (void) cable_num;
- TU_VERIFY(bufsize, 0);
-
- uint8_t* buf8 = (uint8_t*) buffer;
-
- midid_interface_t* midi = &_midid_itf[itf];
- midid_stream_t* stream = &midi->stream_read;
-
- uint32_t total_read = 0;
- while( bufsize )
- {
- // Get new packet from fifo, then set packet expected bytes
- if ( stream->total == 0 )
- {
- // return if there is no more data from fifo
- if ( !tud_midi_n_packet_read(itf, stream->buffer) ) return total_read;
-
- uint8_t const code_index = stream->buffer[0] & 0x0f;
-
- // MIDI 1.0 Table 4-1: Code Index Number Classifications
- switch(code_index)
- {
- case MIDI_CIN_MISC:
- case MIDI_CIN_CABLE_EVENT:
- // These are reserved and unused, possibly issue somewhere, skip this packet
- return 0;
- break;
-
- case MIDI_CIN_SYSEX_END_1BYTE:
- case MIDI_CIN_1BYTE_DATA:
- stream->total = 1;
- break;
-
- case MIDI_CIN_SYSCOM_2BYTE :
- case MIDI_CIN_SYSEX_END_2BYTE :
- case MIDI_CIN_PROGRAM_CHANGE :
- case MIDI_CIN_CHANNEL_PRESSURE :
- stream->total = 2;
- break;
-
- default:
- stream->total = 3;
- break;
- }
- }
-
- // Copy data up to bufsize
- uint32_t const count = tu_min32(stream->total - stream->index, bufsize);
-
- // Skip the header (1st byte) in the buffer
- memcpy(buf8, stream->buffer + 1 + stream->index, count);
-
- total_read += count;
- stream->index += count;
- buf8 += count;
- bufsize -= count;
-
- // complete current event packet, reset stream
- if ( stream->total == stream->index )
- {
- stream->index = 0;
- stream->total = 0;
- }
- }
-
- return total_read;
-}
-
-bool tud_midi_n_packet_read (uint8_t itf, uint8_t packet[4])
-{
- midid_interface_t* midi = &_midid_itf[itf];
- TU_VERIFY(midi->ep_out);
-
- uint32_t const num_read = tu_fifo_read_n(&midi->rx_ff, packet, 4);
- _prep_out_transaction(midi);
- return (num_read == 4);
-}
-
-//--------------------------------------------------------------------+
-// WRITE API
-//--------------------------------------------------------------------+
-
-static uint32_t write_flush(midid_interface_t* midi)
-{
- // No data to send
- if ( !tu_fifo_count(&midi->tx_ff) ) return 0;
-
- uint8_t const rhport = TUD_OPT_RHPORT;
-
- // skip if previous transfer not complete
- TU_VERIFY( usbd_edpt_claim(rhport, midi->ep_in), 0 );
-
- uint16_t count = tu_fifo_read_n(&midi->tx_ff, midi->epin_buf, CFG_TUD_MIDI_EP_BUFSIZE);
-
- if (count)
- {
- TU_ASSERT( usbd_edpt_xfer(rhport, midi->ep_in, midi->epin_buf, count), 0 );
- return count;
- }else
- {
- // Release endpoint since we don't make any transfer
- usbd_edpt_release(rhport, midi->ep_in);
- return 0;
- }
-}
-
-uint32_t tud_midi_n_stream_write(uint8_t itf, uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize)
-{
- midid_interface_t* midi = &_midid_itf[itf];
- TU_VERIFY(midi->ep_in, 0);
-
- midid_stream_t* stream = &midi->stream_write;
-
- uint32_t i = 0;
- while ( (i < bufsize) && (tu_fifo_remaining(&midi->tx_ff) >= 4) )
- {
- uint8_t const data = buffer[i];
- i++;
-
- if ( stream->index == 0 )
- {
- //------------- New event packet -------------//
-
- uint8_t const msg = data >> 4;
-
- stream->index = 2;
- stream->buffer[1] = data;
-
- // Check to see if we're still in a SysEx transmit.
- if ( stream->buffer[0] == MIDI_CIN_SYSEX_START )
- {
- if ( data == MIDI_STATUS_SYSEX_END )
- {
- stream->buffer[0] = MIDI_CIN_SYSEX_END_1BYTE;
- stream->total = 2;
- }
- else
- {
- stream->total = 4;
- }
- }
- else if ( (msg >= 0x8 && msg <= 0xB) || msg == 0xE )
- {
- // Channel Voice Messages
- stream->buffer[0] = (cable_num << 4) | msg;
- stream->total = 4;
- }
- else if ( msg == 0xf )
- {
- // System message
- if ( data == MIDI_STATUS_SYSEX_START )
- {
- stream->buffer[0] = MIDI_CIN_SYSEX_START;
- stream->total = 4;
- }
- else if ( data == MIDI_STATUS_SYSCOM_TIME_CODE_QUARTER_FRAME || data == MIDI_STATUS_SYSCOM_SONG_SELECT )
- {
- stream->buffer[0] = MIDI_CIN_SYSCOM_2BYTE;
- stream->total = 3;
- }
- else if ( data == MIDI_STATUS_SYSCOM_SONG_POSITION_POINTER )
- {
- stream->buffer[0] = MIDI_CIN_SYSCOM_3BYTE;
- stream->total = 4;
- }
- else
- {
- stream->buffer[0] = MIDI_CIN_SYSEX_END_1BYTE;
- stream->total = 2;
- }
- }
- else
- {
- // Pack individual bytes if we don't support packing them into words.
- stream->buffer[0] = cable_num << 4 | 0xf;
- stream->buffer[2] = 0;
- stream->buffer[3] = 0;
- stream->index = 2;
- stream->total = 2;
- }
- }
- else
- {
- //------------- On-going (buffering) packet -------------//
-
- TU_ASSERT(stream->index < 4, i);
- stream->buffer[stream->index] = data;
- stream->index++;
-
- // See if this byte ends a SysEx.
- if ( stream->buffer[0] == MIDI_CIN_SYSEX_START && data == MIDI_STATUS_SYSEX_END )
- {
- stream->buffer[0] = MIDI_CIN_SYSEX_START + (stream->index - 1);
- stream->total = stream->index;
- }
- }
-
- // Send out packet
- if ( stream->index == stream->total )
- {
- // zeroes unused bytes
- for(uint8_t idx = stream->total; idx < 4; idx++) stream->buffer[idx] = 0;
-
- uint16_t const count = tu_fifo_write_n(&midi->tx_ff, stream->buffer, 4);
-
- // complete current event packet, reset stream
- stream->index = stream->total = 0;
-
- // FIFO overflown, since we already check fifo remaining. It is probably race condition
- TU_ASSERT(count == 4, i);
- }
- }
-
- write_flush(midi);
-
- return i;
-}
-
-bool tud_midi_n_packet_write (uint8_t itf, uint8_t const packet[4])
-{
- midid_interface_t* midi = &_midid_itf[itf];
- TU_VERIFY(midi->ep_in);
-
- if (tu_fifo_remaining(&midi->tx_ff) < 4) return false;
-
- tu_fifo_write_n(&midi->tx_ff, packet, 4);
- write_flush(midi);
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void midid_init(void)
-{
- tu_memclr(_midid_itf, sizeof(_midid_itf));
-
- for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
- {
- midid_interface_t* midi = &_midid_itf[i];
-
- // config fifo
- tu_fifo_config(&midi->rx_ff, midi->rx_ff_buf, CFG_TUD_MIDI_RX_BUFSIZE, 1, false); // true, true
- tu_fifo_config(&midi->tx_ff, midi->tx_ff_buf, CFG_TUD_MIDI_TX_BUFSIZE, 1, false); // OBVS.
-
- #if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&midi->rx_ff, NULL, osal_mutex_create(&midi->rx_ff_mutex));
- tu_fifo_config_mutex(&midi->tx_ff, osal_mutex_create(&midi->tx_ff_mutex), NULL);
- #endif
- }
-}
-
-void midid_reset(uint8_t rhport)
-{
- (void) rhport;
-
- for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
- {
- midid_interface_t* midi = &_midid_itf[i];
- tu_memclr(midi, ITF_MEM_RESET_SIZE);
- tu_fifo_clear(&midi->rx_ff);
- tu_fifo_clear(&midi->tx_ff);
- }
-}
-
-uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t max_len)
-{
- // 1st Interface is Audio Control v1
- TU_VERIFY(TUSB_CLASS_AUDIO == desc_itf->bInterfaceClass &&
- AUDIO_SUBCLASS_CONTROL == desc_itf->bInterfaceSubClass &&
- AUDIO_FUNC_PROTOCOL_CODE_UNDEF == desc_itf->bInterfaceProtocol, 0);
-
- uint16_t drv_len = tu_desc_len(desc_itf);
- uint8_t const * p_desc = tu_desc_next(desc_itf);
-
- // Skip Class Specific descriptors
- while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len )
- {
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- // 2nd Interface is MIDI Streaming
- TU_VERIFY(TUSB_DESC_INTERFACE == tu_desc_type(p_desc), 0);
- tusb_desc_interface_t const * desc_midi = (tusb_desc_interface_t const *) p_desc;
-
- TU_VERIFY(TUSB_CLASS_AUDIO == desc_midi->bInterfaceClass &&
- AUDIO_SUBCLASS_MIDI_STREAMING == desc_midi->bInterfaceSubClass &&
- AUDIO_FUNC_PROTOCOL_CODE_UNDEF == desc_midi->bInterfaceProtocol, 0);
-
- // Find available interface
- midid_interface_t * p_midi = NULL;
- for(uint8_t i=0; i<CFG_TUD_MIDI; i++)
- {
- if ( _midid_itf[i].ep_in == 0 && _midid_itf[i].ep_out == 0 )
- {
- p_midi = &_midid_itf[i];
- break;
- }
- }
-
- p_midi->itf_num = desc_midi->bInterfaceNumber;
- (void) p_midi->itf_num;
-
- // next descriptor
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
-
- // Find and open endpoint descriptors
- uint8_t found_endpoints = 0;
- while ( (found_endpoints < desc_midi->bNumEndpoints) && (drv_len <= max_len) )
- {
- if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
- {
- TU_ASSERT(usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), 0);
- uint8_t ep_addr = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
-
- if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN)
- {
- p_midi->ep_in = ep_addr;
- } else {
- p_midi->ep_out = ep_addr;
- }
-
- // Class Specific MIDI Stream endpoint descriptor
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
-
- found_endpoints += 1;
- }
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- // Prepare for incoming data
- _prep_out_transaction(p_midi);
-
- return drv_len;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool midid_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- (void) rhport;
- (void) stage;
- (void) request;
-
- // driver doesn't support any request yet
- return false;
-}
-
-bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void) result;
- (void) rhport;
-
- uint8_t itf;
- midid_interface_t* p_midi;
-
- // Identify which interface to use
- for (itf = 0; itf < CFG_TUD_MIDI; itf++)
- {
- p_midi = &_midid_itf[itf];
- if ( ( ep_addr == p_midi->ep_out ) || ( ep_addr == p_midi->ep_in ) ) break;
- }
- TU_ASSERT(itf < CFG_TUD_MIDI);
-
- // receive new data
- if ( ep_addr == p_midi->ep_out )
- {
- tu_fifo_write_n(&p_midi->rx_ff, p_midi->epout_buf, xferred_bytes);
-
- // invoke receive callback if available
- if (tud_midi_rx_cb) tud_midi_rx_cb(itf);
-
- // prepare for next
- // TODO for now ep_out is not used by public API therefore there is no race condition,
- // and does not need to claim like ep_in
- _prep_out_transaction(p_midi);
- }
- else if ( ep_addr == p_midi->ep_in )
- {
- if (0 == write_flush(p_midi))
- {
- // If there is no data left, a ZLP should be sent if
- // xferred_bytes is multiple of EP size and not zero
- if ( !tu_fifo_count(&p_midi->tx_ff) && xferred_bytes && (0 == (xferred_bytes % CFG_TUD_MIDI_EP_BUFSIZE)) )
- {
- if ( usbd_edpt_claim(rhport, p_midi->ep_in) )
- {
- usbd_edpt_xfer(rhport, p_midi->ep_in, NULL, 0);
- }
- }
- }
- }
-
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/class/midi/midi_device.h b/tinyusb/src/class/midi/midi_device.h
deleted file mode 100755
index 211edc8d..00000000
--- a/tinyusb/src/class/midi/midi_device.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_MIDI_DEVICE_H_
-#define _TUSB_MIDI_DEVICE_H_
-
-#include "class/audio/audio.h"
-#include "midi.h"
-
-//--------------------------------------------------------------------+
-// Class Driver Configuration
-//--------------------------------------------------------------------+
-
-#if !defined(CFG_TUD_MIDI_EP_BUFSIZE) && defined(CFG_TUD_MIDI_EPSIZE)
- #warning CFG_TUD_MIDI_EPSIZE is renamed to CFG_TUD_MIDI_EP_BUFSIZE, please update to use the new name
- #define CFG_TUD_MIDI_EP_BUFSIZE CFG_TUD_MIDI_EPSIZE
-#endif
-
-#ifndef CFG_TUD_MIDI_EP_BUFSIZE
- #define CFG_TUD_MIDI_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
-#endif
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-/** \addtogroup MIDI_Serial Serial
- * @{
- * \defgroup MIDI_Serial_Device Device
- * @{ */
-
-//--------------------------------------------------------------------+
-// Application API (Multiple Interfaces)
-// CFG_TUD_MIDI > 1
-//--------------------------------------------------------------------+
-
-// Check if midi interface is mounted
-bool tud_midi_n_mounted (uint8_t itf);
-
-// Get the number of bytes available for reading
-uint32_t tud_midi_n_available (uint8_t itf, uint8_t cable_num);
-
-// Read byte stream (legacy)
-uint32_t tud_midi_n_stream_read (uint8_t itf, uint8_t cable_num, void* buffer, uint32_t bufsize);
-
-// Write byte Stream (legacy)
-uint32_t tud_midi_n_stream_write (uint8_t itf, uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize);
-
-// Read event packet (4 bytes)
-bool tud_midi_n_packet_read (uint8_t itf, uint8_t packet[4]);
-
-// Write event packet (4 bytes)
-bool tud_midi_n_packet_write (uint8_t itf, uint8_t const packet[4]);
-
-//--------------------------------------------------------------------+
-// Application API (Single Interface)
-//--------------------------------------------------------------------+
-static inline bool tud_midi_mounted (void);
-static inline uint32_t tud_midi_available (void);
-
-static inline uint32_t tud_midi_stream_read (void* buffer, uint32_t bufsize);
-static inline uint32_t tud_midi_stream_write (uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize);
-
-static inline bool tud_midi_packet_read (uint8_t packet[4]);
-static inline bool tud_midi_packet_write (uint8_t const packet[4]);
-
-//------------- Deprecated API name -------------//
-// TODO remove after 0.10.0 release
-
-TU_ATTR_DEPRECATED("tud_midi_read() is renamed to tud_midi_stream_read()")
-static inline uint32_t tud_midi_read (void* buffer, uint32_t bufsize)
-{
- return tud_midi_stream_read(buffer, bufsize);
-}
-
-TU_ATTR_DEPRECATED("tud_midi_write() is renamed to tud_midi_stream_write()")
-static inline uint32_t tud_midi_write(uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize)
-{
- return tud_midi_stream_write(cable_num, buffer, bufsize);
-}
-
-
-TU_ATTR_DEPRECATED("tud_midi_send() is renamed to tud_midi_packet_write()")
-static inline bool tud_midi_send(uint8_t packet[4])
-{
- return tud_midi_packet_write(packet);
-}
-
-TU_ATTR_DEPRECATED("tud_midi_receive() is renamed to tud_midi_packet_read()")
-static inline bool tud_midi_receive(uint8_t packet[4])
-{
- return tud_midi_packet_read(packet);
-}
-
-//--------------------------------------------------------------------+
-// Application Callback API (weak is optional)
-//--------------------------------------------------------------------+
-TU_ATTR_WEAK void tud_midi_rx_cb(uint8_t itf);
-
-//--------------------------------------------------------------------+
-// Inline Functions
-//--------------------------------------------------------------------+
-
-static inline bool tud_midi_mounted (void)
-{
- return tud_midi_n_mounted(0);
-}
-
-static inline uint32_t tud_midi_available (void)
-{
- return tud_midi_n_available(0, 0);
-}
-
-static inline uint32_t tud_midi_stream_read (void* buffer, uint32_t bufsize)
-{
- return tud_midi_n_stream_read(0, 0, buffer, bufsize);
-}
-
-static inline uint32_t tud_midi_stream_write (uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize)
-{
- return tud_midi_n_stream_write(0, cable_num, buffer, bufsize);
-}
-
-static inline bool tud_midi_packet_read (uint8_t packet[4])
-{
- return tud_midi_n_packet_read(0, packet);
-}
-
-static inline bool tud_midi_packet_write (uint8_t const packet[4])
-{
- return tud_midi_n_packet_write(0, packet);
-}
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void midid_init (void);
-void midid_reset (uint8_t rhport);
-uint16_t midid_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool midid_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-bool midid_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_MIDI_DEVICE_H_ */
-
-/** @} */
-/** @} */
diff --git a/tinyusb/src/class/msc/msc.h b/tinyusb/src/class/msc/msc.h
deleted file mode 100755
index 84b6e4d7..00000000
--- a/tinyusb/src/class/msc/msc.h
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_MSC_H_
-#define _TUSB_MSC_H_
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Mass Storage Class Constant
-//--------------------------------------------------------------------+
-/// MassStorage Subclass
-typedef enum
-{
- MSC_SUBCLASS_RBC = 1 , ///< Reduced Block Commands (RBC) T10 Project 1240-D
- MSC_SUBCLASS_SFF_MMC , ///< SFF-8020i, MMC-2 (ATAPI). Typically used by a CD/DVD device
- MSC_SUBCLASS_QIC , ///< QIC-157. Typically used by a tape device
- MSC_SUBCLASS_UFI , ///< UFI. Typically used by Floppy Disk Drive (FDD) device
- MSC_SUBCLASS_SFF , ///< SFF-8070i. Can be used by Floppy Disk Drive (FDD) device
- MSC_SUBCLASS_SCSI ///< SCSI transparent command set
-}msc_subclass_type_t;
-
-enum {
- MSC_CBW_SIGNATURE = 0x43425355, ///< Constant value of 43425355h (little endian)
- MSC_CSW_SIGNATURE = 0x53425355 ///< Constant value of 53425355h (little endian)
-};
-
-/// \brief MassStorage Protocol.
-/// \details CBI only approved to use with full-speed floopy disk & should not used with highspeed or device other than floopy
-typedef enum
-{
- MSC_PROTOCOL_CBI = 0 , ///< Control/Bulk/Interrupt protocol (with command completion interrupt)
- MSC_PROTOCOL_CBI_NO_INTERRUPT = 1 , ///< Control/Bulk/Interrupt protocol (without command completion interrupt)
- MSC_PROTOCOL_BOT = 0x50 ///< Bulk-Only Transport
-}msc_protocol_type_t;
-
-/// MassStorage Class-Specific Control Request
-typedef enum
-{
- MSC_REQ_GET_MAX_LUN = 254, ///< The Get Max LUN device request is used to determine the number of logical units supported by the device. Logical Unit Numbers on the device shall be numbered contiguously starting from LUN 0 to a maximum LUN of 15
- MSC_REQ_RESET = 255 ///< This request is used to reset the mass storage device and its associated interface. This class-specific request shall ready the device for the next CBW from the host.
-}msc_request_type_t;
-
-/// \brief Command Block Status Values
-/// \details Indicates the success or failure of the command. The device shall set this byte to zero if the command completed
-/// successfully. A non-zero value shall indicate a failure during command execution according to the following
-typedef enum
-{
- MSC_CSW_STATUS_PASSED = 0 , ///< MSC_CSW_STATUS_PASSED
- MSC_CSW_STATUS_FAILED , ///< MSC_CSW_STATUS_FAILED
- MSC_CSW_STATUS_PHASE_ERROR ///< MSC_CSW_STATUS_PHASE_ERROR
-}msc_csw_status_t;
-
-/// Command Block Wrapper
-typedef struct TU_ATTR_PACKED
-{
- uint32_t signature; ///< Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
- uint32_t tag; ///< Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTagfield of the associated CSW. The dCSWTagpositively associates a CSW with the corresponding CBW.
- uint32_t total_bytes; ///< The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (as indicated by the Direction bit) during the execution of this command. If this field is zero, the device and the host shall transfer no data between the CBW and the associated CSW, and the device shall ignore the value of the Direction bit in bmCBWFlags.
- uint8_t dir; ///< Bit 7 of this field define transfer direction \n - 0 : Data-Out from host to the device. \n - 1 : Data-In from the device to the host.
- uint8_t lun; ///< The device Logical Unit Number (LUN) to which the command block is being sent. For devices that support multiple LUNs, the host shall place into this field the LUN to which this command block is addressed. Otherwise, the host shall set this field to zero.
- uint8_t cmd_len; ///< The valid length of the CBWCBin bytes. This defines the valid length of the command block. The only legal values are 1 through 16
- uint8_t command[16]; ///< The command block to be executed by the device. The device shall interpret the first cmd_len bytes in this field as a command block
-}msc_cbw_t;
-
-TU_VERIFY_STATIC(sizeof(msc_cbw_t) == 31, "size is not correct");
-
-/// Command Status Wrapper
-typedef struct TU_ATTR_PACKED
-{
- uint32_t signature ; ///< Signature that helps identify this data packet as a CSW. The signature field shall contain the value 53425355h (little endian), indicating CSW.
- uint32_t tag ; ///< The device shall set this field to the value received in the dCBWTag of the associated CBW.
- uint32_t data_residue ; ///< For Data-Out the device shall report in the dCSWDataResiduethe difference between the amount of data expected as stated in the dCBWDataTransferLength, and the actual amount of data processed by the device. For Data-In the device shall report in the dCSWDataResiduethe difference between the amount of data expected as stated in the dCBWDataTransferLengthand the actual amount of relevant data sent by the device
- uint8_t status ; ///< indicates the success or failure of the command. Values from \ref msc_csw_status_t
-}msc_csw_t;
-
-TU_VERIFY_STATIC(sizeof(msc_csw_t) == 13, "size is not correct");
-
-//--------------------------------------------------------------------+
-// SCSI Constant
-//--------------------------------------------------------------------+
-
-/// SCSI Command Operation Code
-typedef enum
-{
- SCSI_CMD_TEST_UNIT_READY = 0x00, ///< The SCSI Test Unit Ready command is used to determine if a device is ready to transfer data (read/write), i.e. if a disk has spun up, if a tape is loaded and ready etc. The device does not perform a self-test operation.
- SCSI_CMD_INQUIRY = 0x12, ///< The SCSI Inquiry command is used to obtain basic information from a target device.
- SCSI_CMD_MODE_SELECT_6 = 0x15, ///< provides a means for the application client to specify medium, logical unit, or peripheral device parameters to the device server. Device servers that implement the MODE SELECT(6) command shall also implement the MODE SENSE(6) command. Application clients should issue MODE SENSE(6) prior to each MODE SELECT(6) to determine supported mode pages, page lengths, and other parameters.
- SCSI_CMD_MODE_SENSE_6 = 0x1A, ///< provides a means for a device server to report parameters to an application client. It is a complementary command to the MODE SELECT(6) command. Device servers that implement the MODE SENSE(6) command shall also implement the MODE SELECT(6) command.
- SCSI_CMD_START_STOP_UNIT = 0x1B,
- SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1E,
- SCSI_CMD_READ_CAPACITY_10 = 0x25, ///< The SCSI Read Capacity command is used to obtain data capacity information from a target device.
- SCSI_CMD_REQUEST_SENSE = 0x03, ///< The SCSI Request Sense command is part of the SCSI computer protocol standard. This command is used to obtain sense data -- status/error information -- from a target device.
- SCSI_CMD_READ_FORMAT_CAPACITY = 0x23, ///< The command allows the Host to request a list of the possible format capacities for an installed writable media. This command also has the capability to report the writable capacity for a media when it is installed
- SCSI_CMD_READ_10 = 0x28, ///< The READ (10) command requests that the device server read the specified logical block(s) and transfer them to the data-in buffer.
- SCSI_CMD_WRITE_10 = 0x2A, ///< The WRITE (10) command requests thatthe device server transfer the specified logical block(s) from the data-out buffer and write them.
-}scsi_cmd_type_t;
-
-/// SCSI Sense Key
-typedef enum
-{
- SCSI_SENSE_NONE = 0x00, ///< no specific Sense Key. This would be the case for a successful command
- SCSI_SENSE_RECOVERED_ERROR = 0x01, ///< ndicates the last command completed successfully with some recovery action performed by the disc drive.
- SCSI_SENSE_NOT_READY = 0x02, ///< Indicates the logical unit addressed cannot be accessed.
- SCSI_SENSE_MEDIUM_ERROR = 0x03, ///< Indicates the command terminated with a non-recovered error condition.
- SCSI_SENSE_HARDWARE_ERROR = 0x04, ///< Indicates the disc drive detected a nonrecoverable hardware failure while performing the command or during a self test.
- SCSI_SENSE_ILLEGAL_REQUEST = 0x05, ///< Indicates an illegal parameter in the command descriptor block or in the additional parameters
- SCSI_SENSE_UNIT_ATTENTION = 0x06, ///< Indicates the disc drive may have been reset.
- SCSI_SENSE_DATA_PROTECT = 0x07, ///< Indicates that a command that reads or writes the medium was attempted on a block that is protected from this operation. The read or write operation is not performed.
- SCSI_SENSE_FIRMWARE_ERROR = 0x08, ///< Vendor specific sense key.
- SCSI_SENSE_ABORTED_COMMAND = 0x0b, ///< Indicates the disc drive aborted the command.
- SCSI_SENSE_EQUAL = 0x0c, ///< Indicates a SEARCH DATA command has satisfied an equal comparison.
- SCSI_SENSE_VOLUME_OVERFLOW = 0x0d, ///< Indicates a buffered peripheral device has reached the end of medium partition and data remains in the buffer that has not been written to the medium.
- SCSI_SENSE_MISCOMPARE = 0x0e ///< ndicates that the source data did not match the data read from the medium.
-}scsi_sense_key_type_t;
-
-//--------------------------------------------------------------------+
-// SCSI Primary Command (SPC-4)
-//--------------------------------------------------------------------+
-
-/// SCSI Test Unit Ready Command
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_TEST_UNIT_READY
- uint8_t lun ; ///< Logical Unit
- uint8_t reserved[3] ;
- uint8_t control ;
-} scsi_test_unit_ready_t;
-
-TU_VERIFY_STATIC(sizeof(scsi_test_unit_ready_t) == 6, "size is not correct");
-
-/// SCSI Inquiry Command
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_INQUIRY
- uint8_t reserved1 ;
- uint8_t page_code ;
- uint8_t reserved2 ;
- uint8_t alloc_length ; ///< specifies the maximum number of bytes that USB host has allocated in the Data-In Buffer. An allocation length of zero specifies that no data shall be transferred.
- uint8_t control ;
-} scsi_inquiry_t, scsi_request_sense_t;
-
-TU_VERIFY_STATIC(sizeof(scsi_inquiry_t) == 6, "size is not correct");
-
-/// SCSI Inquiry Response Data
-typedef struct TU_ATTR_PACKED
-{
- uint8_t peripheral_device_type : 5;
- uint8_t peripheral_qualifier : 3;
-
- uint8_t : 7;
- uint8_t is_removable : 1;
-
- uint8_t version;
-
- uint8_t response_data_format : 4;
- uint8_t hierarchical_support : 1;
- uint8_t normal_aca : 1;
- uint8_t : 2;
-
- uint8_t additional_length;
-
- uint8_t protect : 1;
- uint8_t : 2;
- uint8_t third_party_copy : 1;
- uint8_t target_port_group_support : 2;
- uint8_t access_control_coordinator : 1;
- uint8_t scc_support : 1;
-
- uint8_t addr16 : 1;
- uint8_t : 3;
- uint8_t multi_port : 1;
- uint8_t : 1; // vendor specific
- uint8_t enclosure_service : 1;
- uint8_t : 1;
-
- uint8_t : 1; // vendor specific
- uint8_t cmd_que : 1;
- uint8_t : 2;
- uint8_t sync : 1;
- uint8_t wbus16 : 1;
- uint8_t : 2;
-
- uint8_t vendor_id[8] ; ///< 8 bytes of ASCII data identifying the vendor of the product.
- uint8_t product_id[16]; ///< 16 bytes of ASCII data defined by the vendor.
- uint8_t product_rev[4]; ///< 4 bytes of ASCII data defined by the vendor.
-} scsi_inquiry_resp_t;
-
-TU_VERIFY_STATIC(sizeof(scsi_inquiry_resp_t) == 36, "size is not correct");
-
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t response_code : 7; ///< 70h - current errors, Fixed Format 71h - deferred errors, Fixed Format
- uint8_t valid : 1;
-
- uint8_t reserved;
-
- uint8_t sense_key : 4;
- uint8_t : 1;
- uint8_t ili : 1; ///< Incorrect length indicator
- uint8_t end_of_medium : 1;
- uint8_t filemark : 1;
-
- uint32_t information;
- uint8_t add_sense_len;
- uint32_t command_specific_info;
- uint8_t add_sense_code;
- uint8_t add_sense_qualifier;
- uint8_t field_replaceable_unit_code;
-
- uint8_t sense_key_specific[3]; ///< sense key specific valid bit is bit 7 of key[0], aka MSB in Big Endian layout
-
-} scsi_sense_fixed_resp_t;
-
-TU_VERIFY_STATIC(sizeof(scsi_sense_fixed_resp_t) == 18, "size is not correct");
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_MODE_SENSE_6
-
- uint8_t : 3;
- uint8_t disable_block_descriptor : 1;
- uint8_t : 4;
-
- uint8_t page_code : 6;
- uint8_t page_control : 2;
-
- uint8_t subpage_code;
- uint8_t alloc_length;
- uint8_t control;
-} scsi_mode_sense6_t;
-
-TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_t) == 6, "size is not correct");
-
-// This is only a Mode parameter header(6).
-typedef struct TU_ATTR_PACKED
-{
- uint8_t data_len;
- uint8_t medium_type;
-
- uint8_t reserved : 7;
- bool write_protected : 1;
-
- uint8_t block_descriptor_len;
-} scsi_mode_sense6_resp_t;
-
-TU_VERIFY_STATIC( sizeof(scsi_mode_sense6_resp_t) == 4, "size is not correct");
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code; ///< SCSI OpCode for \ref SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL
- uint8_t reserved[3];
- uint8_t prohibit_removal;
- uint8_t control;
-} scsi_prevent_allow_medium_removal_t;
-
-TU_VERIFY_STATIC( sizeof(scsi_prevent_allow_medium_removal_t) == 6, "size is not correct");
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code;
-
- uint8_t immded : 1;
- uint8_t : 7;
-
- uint8_t TU_RESERVED;
-
- uint8_t power_condition_mod : 4;
- uint8_t : 4;
-
- uint8_t start : 1;
- uint8_t load_eject : 1;
- uint8_t no_flush : 1;
- uint8_t : 1;
- uint8_t power_condition : 4;
-
- uint8_t control;
-} scsi_start_stop_unit_t;
-
-TU_VERIFY_STATIC( sizeof(scsi_start_stop_unit_t) == 6, "size is not correct");
-
-//--------------------------------------------------------------------+
-// SCSI MMC
-//--------------------------------------------------------------------+
-/// SCSI Read Format Capacity: Write Capacity
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code;
- uint8_t reserved[6];
- uint16_t alloc_length;
- uint8_t control;
-} scsi_read_format_capacity_t;
-
-TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_t) == 10, "size is not correct");
-
-typedef struct TU_ATTR_PACKED{
- uint8_t reserved[3];
- uint8_t list_length; /// must be 8*n, length in bytes of formattable capacity descriptor followed it.
-
- uint32_t block_num; /// Number of Logical Blocks
- uint8_t descriptor_type; // 00: reserved, 01 unformatted media , 10 Formatted media, 11 No media present
-
- uint8_t reserved2;
- uint16_t block_size_u16;
-
-} scsi_read_format_capacity_data_t;
-
-TU_VERIFY_STATIC( sizeof(scsi_read_format_capacity_data_t) == 12, "size is not correct");
-
-//--------------------------------------------------------------------+
-// SCSI Block Command (SBC-3)
-// NOTE: All data in SCSI command are in Big Endian
-//--------------------------------------------------------------------+
-
-/// SCSI Read Capacity 10 Command: Read Capacity
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code ; ///< SCSI OpCode for \ref SCSI_CMD_READ_CAPACITY_10
- uint8_t reserved1 ;
- uint32_t lba ; ///< The first Logical Block Address (LBA) accessed by this command
- uint16_t reserved2 ;
- uint8_t partial_medium_indicator ;
- uint8_t control ;
-} scsi_read_capacity10_t;
-
-TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_t) == 10, "size is not correct");
-
-/// SCSI Read Capacity 10 Response Data
-typedef struct {
- uint32_t last_lba ; ///< The last Logical Block Address of the device
- uint32_t block_size ; ///< Block size in bytes
-} scsi_read_capacity10_resp_t;
-
-TU_VERIFY_STATIC(sizeof(scsi_read_capacity10_resp_t) == 8, "size is not correct");
-
-/// SCSI Read 10 Command
-typedef struct TU_ATTR_PACKED
-{
- uint8_t cmd_code ; ///< SCSI OpCode
- uint8_t reserved ; // has LUN according to wiki
- uint32_t lba ; ///< The first Logical Block Address (LBA) accessed by this command
- uint8_t reserved2 ;
- uint16_t block_count ; ///< Number of Blocks used by this command
- uint8_t control ;
-} scsi_read10_t, scsi_write10_t;
-
-TU_VERIFY_STATIC(sizeof(scsi_read10_t) == 10, "size is not correct");
-TU_VERIFY_STATIC(sizeof(scsi_write10_t) == 10, "size is not correct");
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_MSC_H_ */
diff --git a/tinyusb/src/class/msc/msc_device.c b/tinyusb/src/class/msc/msc_device.c
deleted file mode 100755
index 014e8b69..00000000
--- a/tinyusb/src/class/msc/msc_device.c
+++ /dev/null
@@ -1,705 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_MSC)
-
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-#include "device/dcd.h" // for faking dcd_event_xfer_complete
-
-#include "msc_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-// Can be selectively disabled to reduce logging when troubleshooting other driver
-#define MSC_DEBUG 2
-
-enum
-{
- MSC_STAGE_CMD = 0,
- MSC_STAGE_DATA,
- MSC_STAGE_STATUS,
- MSC_STAGE_STATUS_SENT
-};
-
-typedef struct
-{
- // TODO optimize alignment
- CFG_TUSB_MEM_ALIGN msc_cbw_t cbw;
- CFG_TUSB_MEM_ALIGN msc_csw_t csw;
-
- uint8_t itf_num;
- uint8_t ep_in;
- uint8_t ep_out;
-
- // Bulk Only Transfer (BOT) Protocol
- uint8_t stage;
- uint32_t total_len;
- uint32_t xferred_len; // numbered of bytes transferred so far in the Data Stage
-
- // Sense Response Data
- uint8_t sense_key;
- uint8_t add_sense_code;
- uint8_t add_sense_qualifier;
-}mscd_interface_t;
-
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf;
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _mscd_buf[CFG_TUD_MSC_EP_BUFSIZE];
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_t* buffer, uint32_t bufsize);
-static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc);
-static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc);
-
-static inline uint32_t rdwr10_get_lba(uint8_t const command[])
-{
- // use offsetof to avoid pointer to the odd/unaligned address
- uint32_t const lba = tu_unaligned_read32(command + offsetof(scsi_write10_t, lba));
-
- // lba is in Big Endian
- return tu_ntohl(lba);
-}
-
-static inline uint16_t rdwr10_get_blockcount(uint8_t const command[])
-{
- // use offsetof to avoid pointer to the odd/misaligned address
- uint16_t const block_count = tu_unaligned_read16(command + offsetof(scsi_write10_t, block_count));
-
- // block count is in Big Endian
- return tu_ntohs(block_count);
-}
-
-//--------------------------------------------------------------------+
-// Debug
-//--------------------------------------------------------------------+
-#if CFG_TUSB_DEBUG >= 2
-
-TU_ATTR_UNUSED static tu_lookup_entry_t const _msc_scsi_cmd_lookup[] =
-{
- { .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" },
- { .key = SCSI_CMD_INQUIRY , .data = "Inquiry" },
- { .key = SCSI_CMD_MODE_SELECT_6 , .data = "Mode_Select 6" },
- { .key = SCSI_CMD_MODE_SENSE_6 , .data = "Mode_Sense 6" },
- { .key = SCSI_CMD_START_STOP_UNIT , .data = "Start Stop Unit" },
- { .key = SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL , .data = "Prevent Allow Medium Removal" },
- { .key = SCSI_CMD_READ_CAPACITY_10 , .data = "Read Capacity10" },
- { .key = SCSI_CMD_REQUEST_SENSE , .data = "Request Sense" },
- { .key = SCSI_CMD_READ_FORMAT_CAPACITY , .data = "Read Format Capacity" },
- { .key = SCSI_CMD_READ_10 , .data = "Read10" },
- { .key = SCSI_CMD_WRITE_10 , .data = "Write10" }
-};
-
-TU_ATTR_UNUSED static tu_lookup_table_t const _msc_scsi_cmd_table =
-{
- .count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup),
- .items = _msc_scsi_cmd_lookup
-};
-
-#endif
-
-//--------------------------------------------------------------------+
-// APPLICATION API
-//--------------------------------------------------------------------+
-bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier)
-{
- (void) lun;
-
- _mscd_itf.sense_key = sense_key;
- _mscd_itf.add_sense_code = add_sense_code;
- _mscd_itf.add_sense_qualifier = add_sense_qualifier;
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void mscd_init(void)
-{
- tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
-}
-
-void mscd_reset(uint8_t rhport)
-{
- (void) rhport;
- tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
-}
-
-uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- // only support SCSI's BOT protocol
- TU_VERIFY(TUSB_CLASS_MSC == itf_desc->bInterfaceClass &&
- MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass &&
- MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol, 0);
-
- // msc driver length is fixed
- uint16_t const drv_len = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
-
- // Max length mus be at least 1 interface + 2 endpoints
- TU_ASSERT(max_len >= drv_len, 0);
-
- mscd_interface_t * p_msc = &_mscd_itf;
- p_msc->itf_num = itf_desc->bInterfaceNumber;
-
- // Open endpoint pair
- TU_ASSERT( usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in), 0 );
-
- // Prepare for Command Block Wrapper
- if ( !usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) )
- {
- TU_LOG_FAILED();
- TU_BREAKPOINT();
- }
-
- return drv_len;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool mscd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * p_request)
-{
- // nothing to do with DATA & ACK stage
- if (stage != CONTROL_STAGE_SETUP) return true;
-
- // Handle class request only
- TU_VERIFY(p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
-
- switch ( p_request->bRequest )
- {
- case MSC_REQ_RESET:
- // TODO: Actually reset interface.
- tud_control_status(rhport, p_request);
- break;
-
- case MSC_REQ_GET_MAX_LUN:
- {
- uint8_t maxlun = 1;
- if (tud_msc_get_maxlun_cb) maxlun = tud_msc_get_maxlun_cb();
- TU_VERIFY(maxlun);
-
- // MAX LUN is minus 1 by specs
- maxlun--;
-
- tud_control_xfer(rhport, p_request, &maxlun, 1);
- }
- break;
-
- default: return false; // stall unsupported request
- }
-
- return true;
-}
-
-bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
-{
- mscd_interface_t* p_msc = &_mscd_itf;
- msc_cbw_t const * p_cbw = &p_msc->cbw;
- msc_csw_t * p_csw = &p_msc->csw;
-
- switch (p_msc->stage)
- {
- case MSC_STAGE_CMD:
- //------------- new CBW received -------------//
- // Complete IN while waiting for CMD is usually Status of previous SCSI op, ignore it
- if(ep_addr != p_msc->ep_out) return true;
-
- TU_ASSERT( event == XFER_RESULT_SUCCESS &&
- xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE );
-
- TU_LOG(MSC_DEBUG, " SCSI Command: %s\r\n", tu_lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0]));
- // TU_LOG_MEM(MSC_DEBUG, p_cbw, xferred_bytes, 2);
-
- p_csw->signature = MSC_CSW_SIGNATURE;
- p_csw->tag = p_cbw->tag;
- p_csw->data_residue = 0;
-
- /*------------- Parse command and prepare DATA -------------*/
- p_msc->stage = MSC_STAGE_DATA;
- p_msc->total_len = p_cbw->total_bytes;
- p_msc->xferred_len = 0;
-
- if (SCSI_CMD_READ_10 == p_cbw->command[0])
- {
- proc_read10_cmd(rhport, p_msc);
- }
- else if (SCSI_CMD_WRITE_10 == p_cbw->command[0])
- {
- proc_write10_cmd(rhport, p_msc);
- }
- else
- {
- // For other SCSI commands
- // 1. OUT : queue transfer (invoke app callback after done)
- // 2. IN & Zero: Process if is built-in, else Invoke app callback. Skip DATA if zero length
- if ( (p_cbw->total_bytes > 0 ) && !tu_bit_test(p_cbw->dir, 7) )
- {
- // queue transfer
- TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
- }else
- {
- int32_t resplen;
-
- // First process if it is a built-in commands
- resplen = proc_builtin_scsi(p_cbw->lun, p_cbw->command, _mscd_buf, sizeof(_mscd_buf));
-
- // Not built-in, invoke user callback
- if ( (resplen < 0) && (p_msc->sense_key == 0) )
- {
- resplen = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->total_len);
- }
-
- if ( resplen < 0 )
- {
- p_msc->total_len = 0;
- p_csw->status = MSC_CSW_STATUS_FAILED;
- p_msc->stage = MSC_STAGE_STATUS;
-
- // failed but senskey is not set: default to Illegal Request
- if ( p_msc->sense_key == 0 ) tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
-
- // Stall bulk In if needed
- if (p_cbw->total_bytes) usbd_edpt_stall(rhport, p_msc->ep_in);
- }
- else
- {
- p_msc->total_len = (uint32_t) resplen;
- p_csw->status = MSC_CSW_STATUS_PASSED;
-
- if (p_msc->total_len)
- {
- TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len ); // cannot return more than host expect
- TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
- }else
- {
- p_msc->stage = MSC_STAGE_STATUS;
- }
- }
- }
- }
- break;
-
- case MSC_STAGE_DATA:
- TU_LOG(MSC_DEBUG, " SCSI Data\r\n");
- //TU_LOG_MEM(MSC_DEBUG, _mscd_buf, xferred_bytes, 2);
-
- // OUT transfer, invoke callback if needed
- if ( !tu_bit_test(p_cbw->dir, 7) )
- {
- if ( SCSI_CMD_WRITE_10 != p_cbw->command[0] )
- {
- int32_t cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->total_len);
-
- if ( cb_result < 0 )
- {
- p_csw->status = MSC_CSW_STATUS_FAILED;
- tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
- }else
- {
- p_csw->status = MSC_CSW_STATUS_PASSED;
- }
- }
- else
- {
- uint16_t const block_sz = p_cbw->total_bytes / rdwr10_get_blockcount(p_cbw->command);
-
- // Adjust lba with transferred bytes
- uint32_t const lba = rdwr10_get_lba(p_cbw->command) + (p_msc->xferred_len / block_sz);
-
- // Application can consume smaller bytes
- int32_t nbytes = tud_msc_write10_cb(p_cbw->lun, lba, p_msc->xferred_len % block_sz, _mscd_buf, xferred_bytes);
-
- if ( nbytes < 0 )
- {
- // negative means error -> skip to status phase, status in CSW set to failed
- p_csw->data_residue = p_cbw->total_bytes - p_msc->xferred_len;
- p_csw->status = MSC_CSW_STATUS_FAILED;
- p_msc->stage = MSC_STAGE_STATUS;
-
- tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
- break;
- }else
- {
- // Application consume less than what we got (including zero)
- if ( nbytes < (int32_t) xferred_bytes )
- {
- if ( nbytes > 0 )
- {
- p_msc->xferred_len += nbytes;
- memmove(_mscd_buf, _mscd_buf+nbytes, xferred_bytes-nbytes);
- }
-
- // simulate an transfer complete with adjusted parameters --> this driver callback will fired again
- dcd_event_xfer_complete(rhport, p_msc->ep_out, xferred_bytes-nbytes, XFER_RESULT_SUCCESS, false);
-
- return true; // skip the rest
- }
- else
- {
- // Application consume all bytes in our buffer. Nothing to do, process with normal flow
- }
- }
- }
- }
-
- // Accumulate data so far
- p_msc->xferred_len += xferred_bytes;
-
- if ( p_msc->xferred_len >= p_msc->total_len )
- {
- // Data Stage is complete
- p_msc->stage = MSC_STAGE_STATUS;
- }
- else
- {
- // READ10 & WRITE10 Can be executed with large bulk of data e.g write 8K bytes (several flash write)
- // We break it into multiple smaller command whose data size is up to CFG_TUD_MSC_EP_BUFSIZE
- if (SCSI_CMD_READ_10 == p_cbw->command[0])
- {
- proc_read10_cmd(rhport, p_msc);
- }
- else if (SCSI_CMD_WRITE_10 == p_cbw->command[0])
- {
- proc_write10_cmd(rhport, p_msc);
- }else
- {
- // No other command take more than one transfer yet -> unlikely error
- TU_BREAKPOINT();
- }
- }
- break;
-
- case MSC_STAGE_STATUS:
- // processed immediately after this switch, supposedly to be empty
- break;
-
- case MSC_STAGE_STATUS_SENT:
- // Wait for the Status phase to complete
- if( (ep_addr == p_msc->ep_in) && (xferred_bytes == sizeof(msc_csw_t)) )
- {
- TU_LOG(MSC_DEBUG, " SCSI Status: %u\r\n", p_csw->status);
- // TU_LOG_MEM(MSC_DEBUG, p_csw, xferred_bytes, 2);
-
- // Invoke complete callback if defined
- // Note: There is racing issue with samd51 + qspi flash testing with arduino
- // if complete_cb() is invoked after queuing the status.
- switch(p_cbw->command[0])
- {
- case SCSI_CMD_READ_10:
- if ( tud_msc_read10_complete_cb ) tud_msc_read10_complete_cb(p_cbw->lun);
- break;
-
- case SCSI_CMD_WRITE_10:
- if ( tud_msc_write10_complete_cb ) tud_msc_write10_complete_cb(p_cbw->lun);
- break;
-
- default:
- if ( tud_msc_scsi_complete_cb ) tud_msc_scsi_complete_cb(p_cbw->lun, p_cbw->command);
- break;
- }
-
- // Move to default CMD stage
- p_msc->stage = MSC_STAGE_CMD;
-
- // Queue for the next CBW
- TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
- }
- break;
-
- default : break;
- }
-
- if ( p_msc->stage == MSC_STAGE_STATUS )
- {
- // Either endpoints is stalled, need to wait until it is cleared by host
- if ( usbd_edpt_stalled(rhport, p_msc->ep_in) || usbd_edpt_stalled(rhport, p_msc->ep_out) )
- {
- // simulate an transfer complete with adjusted parameters --> this driver callback will fired again
- // and response with status phase after halted endpoints are cleared.
- // note: use ep_out to prevent confusing with STATUS complete
- dcd_event_xfer_complete(rhport, p_msc->ep_out, 0, XFER_RESULT_SUCCESS, false);
- }
- else
- {
- // Move to Status Sent stage
- p_msc->stage = MSC_STAGE_STATUS_SENT;
-
- // Send SCSI Status
- TU_ASSERT(usbd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)));
- }
- }
-
- return true;
-}
-
-/*------------------------------------------------------------------*/
-/* SCSI Command Process
- *------------------------------------------------------------------*/
-
-// return response's length (copied to buffer). Negative if it is not an built-in command or indicate Failed status (CSW)
-// In case of a failed status, sense key must be set for reason of failure
-static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_t* buffer, uint32_t bufsize)
-{
- (void) bufsize; // TODO refractor later
- int32_t resplen;
-
- switch ( scsi_cmd[0] )
- {
- case SCSI_CMD_TEST_UNIT_READY:
- resplen = 0;
- if ( !tud_msc_test_unit_ready_cb(lun) )
- {
- // Failed status response
- resplen = - 1;
-
- // If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
- if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
- }
- break;
-
- case SCSI_CMD_START_STOP_UNIT:
- resplen = 0;
-
- if (tud_msc_start_stop_cb)
- {
- scsi_start_stop_unit_t const * start_stop = (scsi_start_stop_unit_t const *) scsi_cmd;
- if ( !tud_msc_start_stop_cb(lun, start_stop->power_condition, start_stop->start, start_stop->load_eject) )
- {
- // Failed status response
- resplen = - 1;
-
- // If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
- if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
- }
- }
- break;
-
- case SCSI_CMD_READ_CAPACITY_10:
- {
- uint32_t block_count;
- uint32_t block_size;
- uint16_t block_size_u16;
-
- tud_msc_capacity_cb(lun, &block_count, &block_size_u16);
- block_size = (uint32_t) block_size_u16;
-
- // Invalid block size/count from callback, possibly unit is not ready
- // stall this request, set sense key to NOT READY
- if (block_count == 0 || block_size == 0)
- {
- resplen = -1;
-
- // If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
- if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
- }else
- {
- scsi_read_capacity10_resp_t read_capa10;
-
- read_capa10.last_lba = tu_htonl(block_count-1);
- read_capa10.block_size = tu_htonl(block_size);
-
- resplen = sizeof(read_capa10);
- memcpy(buffer, &read_capa10, resplen);
- }
- }
- break;
-
- case SCSI_CMD_READ_FORMAT_CAPACITY:
- {
- scsi_read_format_capacity_data_t read_fmt_capa =
- {
- .list_length = 8,
- .block_num = 0,
- .descriptor_type = 2, // formatted media
- .block_size_u16 = 0
- };
-
- uint32_t block_count;
- uint16_t block_size;
-
- tud_msc_capacity_cb(lun, &block_count, &block_size);
-
- // Invalid block size/count from callback, possibly unit is not ready
- // stall this request, set sense key to NOT READY
- if (block_count == 0 || block_size == 0)
- {
- resplen = -1;
-
- // If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
- if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
- }else
- {
- read_fmt_capa.block_num = tu_htonl(block_count);
- read_fmt_capa.block_size_u16 = tu_htons(block_size);
-
- resplen = sizeof(read_fmt_capa);
- memcpy(buffer, &read_fmt_capa, resplen);
- }
- }
- break;
-
- case SCSI_CMD_INQUIRY:
- {
- scsi_inquiry_resp_t inquiry_rsp =
- {
- .is_removable = 1,
- .version = 2,
- .response_data_format = 2,
- };
-
- // vendor_id, product_id, product_rev is space padded string
- memset(inquiry_rsp.vendor_id , ' ', sizeof(inquiry_rsp.vendor_id));
- memset(inquiry_rsp.product_id , ' ', sizeof(inquiry_rsp.product_id));
- memset(inquiry_rsp.product_rev, ' ', sizeof(inquiry_rsp.product_rev));
-
- tud_msc_inquiry_cb(lun, inquiry_rsp.vendor_id, inquiry_rsp.product_id, inquiry_rsp.product_rev);
-
- resplen = sizeof(inquiry_rsp);
- memcpy(buffer, &inquiry_rsp, resplen);
- }
- break;
-
- case SCSI_CMD_MODE_SENSE_6:
- {
- scsi_mode_sense6_resp_t mode_resp =
- {
- .data_len = 3,
- .medium_type = 0,
- .write_protected = false,
- .reserved = 0,
- .block_descriptor_len = 0 // no block descriptor are included
- };
-
- bool writable = true;
- if (tud_msc_is_writable_cb) {
- writable = tud_msc_is_writable_cb(lun);
- }
- mode_resp.write_protected = !writable;
-
- resplen = sizeof(mode_resp);
- memcpy(buffer, &mode_resp, resplen);
- }
- break;
-
- case SCSI_CMD_REQUEST_SENSE:
- {
- scsi_sense_fixed_resp_t sense_rsp =
- {
- .response_code = 0x70,
- .valid = 1
- };
-
- sense_rsp.add_sense_len = sizeof(scsi_sense_fixed_resp_t) - 8;
-
- sense_rsp.sense_key = _mscd_itf.sense_key;
- sense_rsp.add_sense_code = _mscd_itf.add_sense_code;
- sense_rsp.add_sense_qualifier = _mscd_itf.add_sense_qualifier;
-
- resplen = sizeof(sense_rsp);
- memcpy(buffer, &sense_rsp, resplen);
-
- // Clear sense data after copy
- tud_msc_set_sense(lun, 0, 0, 0);
- }
- break;
-
- default: resplen = -1; break;
- }
-
- return resplen;
-}
-
-static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
-{
- msc_cbw_t const * p_cbw = &p_msc->cbw;
- msc_csw_t * p_csw = &p_msc->csw;
-
- uint16_t const block_cnt = rdwr10_get_blockcount(p_cbw->command);
- TU_ASSERT(block_cnt, ); // prevent div by zero
-
- uint16_t const block_sz = p_cbw->total_bytes / block_cnt;
- TU_ASSERT(block_sz, ); // prevent div by zero
-
- // Adjust lba with transferred bytes
- uint32_t const lba = rdwr10_get_lba(p_cbw->command) + (p_msc->xferred_len / block_sz);
-
- // remaining bytes capped at class buffer
- int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
-
- // Application can consume smaller bytes
- nbytes = tud_msc_read10_cb(p_cbw->lun, lba, p_msc->xferred_len % block_sz, _mscd_buf, (uint32_t) nbytes);
-
- if ( nbytes < 0 )
- {
- // negative means error -> pipe is stalled & status in CSW set to failed
- p_csw->data_residue = p_cbw->total_bytes - p_msc->xferred_len;
- p_csw->status = MSC_CSW_STATUS_FAILED;
-
- tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
- usbd_edpt_stall(rhport, p_msc->ep_in);
- }
- else if ( nbytes == 0 )
- {
- // zero means not ready -> simulate an transfer complete so that this driver callback will fired again
- dcd_event_xfer_complete(rhport, p_msc->ep_in, 0, XFER_RESULT_SUCCESS, false);
- }
- else
- {
- TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
- }
-}
-
-static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
-{
- msc_cbw_t const * p_cbw = &p_msc->cbw;
- bool writable = true;
- if (tud_msc_is_writable_cb) {
- writable = tud_msc_is_writable_cb(p_cbw->lun);
- }
- if (!writable) {
- msc_csw_t* p_csw = &p_msc->csw;
- p_csw->data_residue = p_cbw->total_bytes;
- p_csw->status = MSC_CSW_STATUS_FAILED;
-
- tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_DATA_PROTECT, 0x27, 0x00); // Sense = Write protected
- usbd_edpt_stall(rhport, p_msc->ep_out);
- return;
- }
-
- // remaining bytes capped at class buffer
- int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
-
- // Write10 callback will be called later when usb transfer complete
- TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
-}
-
-#endif
diff --git a/tinyusb/src/class/msc/msc_device.h b/tinyusb/src/class/msc/msc_device.h
deleted file mode 100755
index 8f90ef4a..00000000
--- a/tinyusb/src/class/msc/msc_device.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_MSC_DEVICE_H_
-#define _TUSB_MSC_DEVICE_H_
-
-#include "common/tusb_common.h"
-#include "msc.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Class Driver Configuration
-//--------------------------------------------------------------------+
-
-#if !defined(CFG_TUD_MSC_EP_BUFSIZE) & defined(CFG_TUD_MSC_BUFSIZE)
- // TODO warn user to use new name later on
- // #warning CFG_TUD_MSC_BUFSIZE is renamed to CFG_TUD_MSC_EP_BUFSIZE, please update to use the new name
- #define CFG_TUD_MSC_EP_BUFSIZE CFG_TUD_MSC_BUFSIZE
-#endif
-
-#ifndef CFG_TUD_MSC_EP_BUFSIZE
- #error CFG_TUD_MSC_EP_BUFSIZE must be defined, value of a block size should work well, the more the better
-#endif
-
-TU_VERIFY_STATIC(CFG_TUD_MSC_EP_BUFSIZE < UINT16_MAX, "Size is not correct");
-
-//--------------------------------------------------------------------+
-// Application API
-//--------------------------------------------------------------------+
-
-// Set SCSI sense response
-bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier);
-
-//--------------------------------------------------------------------+
-// Application Callbacks (WEAK is optional)
-//--------------------------------------------------------------------+
-
-// Invoked when received SCSI READ10 command
-// - Address = lba * BLOCK_SIZE + offset
-// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE.
-//
-// - Application fill the buffer (up to bufsize) with address contents and return number of read byte. If
-// - read < bufsize : These bytes are transferred first and callback invoked again for remaining data.
-//
-// - read == 0 : Indicate application is not ready yet e.g disk I/O busy.
-// Callback invoked again with the same parameters later on.
-//
-// - read < 0 : Indicate application error e.g invalid address. This request will be STALLed
-// and return failed status in command status wrapper phase.
-int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
-
-// Invoked when received SCSI WRITE10 command
-// - Address = lba * BLOCK_SIZE + offset
-// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE.
-//
-// - Application write data from buffer to address contents (up to bufsize) and return number of written byte. If
-// - write < bufsize : callback invoked again with remaining data later on.
-//
-// - write == 0 : Indicate application is not ready yet e.g disk I/O busy.
-// Callback invoked again with the same parameters later on.
-//
-// - write < 0 : Indicate application error e.g invalid address. This request will be STALLed
-// and return failed status in command status wrapper phase.
-//
-// TODO change buffer to const uint8_t*
-int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize);
-
-// Invoked when received SCSI_CMD_INQUIRY
-// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
-void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]);
-
-// Invoked when received Test Unit Ready command.
-// return true allowing host to read/write this LUN e.g SD card inserted
-bool tud_msc_test_unit_ready_cb(uint8_t lun);
-
-// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
-// Application update block count and block size
-void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size);
-
-/**
- * Invoked when received an SCSI command not in built-in list below.
- * - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, TEST_UNIT_READY, START_STOP_UNIT, MODE_SENSE6, REQUEST_SENSE
- * - READ10 and WRITE10 has their own callbacks
- *
- * \param[in] lun Logical unit number
- * \param[in] scsi_cmd SCSI command contents which application must examine to response accordingly
- * \param[out] buffer Buffer for SCSI Data Stage.
- * - For INPUT: application must fill this with response.
- * - For OUTPUT it holds the Data from host
- * \param[in] bufsize Buffer's length.
- *
- * \return Actual bytes processed, can be zero for no-data command.
- * \retval negative Indicate error e.g unsupported command, tinyusb will \b STALL the corresponding
- * endpoint and return failed status in command status wrapper phase.
- */
-int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize);
-
-/*------------- Optional callbacks -------------*/
-
-// Invoked when received GET_MAX_LUN request, required for multiple LUNs implementation
-TU_ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void);
-
-// Invoked when received Start Stop Unit command
-// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage
-// - Start = 1 : active mode, if load_eject = 1 : load disk storage
-TU_ATTR_WEAK bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject);
-
-// Invoked when Read10 command is complete
-TU_ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
-
-// Invoke when Write10 command is complete, can be used to flush flash caching
-TU_ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun);
-
-// Invoked when command in tud_msc_scsi_cb is complete
-TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]);
-
-// Hook to make a mass storage device read-only. TODO remove
-TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun);
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void mscd_init (void);
-void mscd_reset (uint8_t rhport);
-uint16_t mscd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool mscd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * p_request);
-bool mscd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_MSC_DEVICE_H_ */
diff --git a/tinyusb/src/class/msc/msc_host.c b/tinyusb/src/class/msc/msc_host.c
deleted file mode 100755
index 8069353c..00000000
--- a/tinyusb/src/class/msc/msc_host.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if TUSB_OPT_HOST_ENABLED & CFG_TUH_MSC
-
-#include "host/usbh.h"
-#include "host/usbh_classdriver.h"
-
-#include "msc_host.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-enum
-{
- MSC_STAGE_IDLE = 0,
- MSC_STAGE_CMD,
- MSC_STAGE_DATA,
- MSC_STAGE_STATUS,
-};
-
-typedef struct
-{
- uint8_t itf_num;
- uint8_t ep_in;
- uint8_t ep_out;
-
- uint8_t max_lun;
-
- volatile bool configured; // Receive SET_CONFIGURE
- volatile bool mounted; // Enumeration is complete
-
- struct {
- uint32_t block_size;
- uint32_t block_count;
- } capacity[CFG_TUH_MSC_MAXLUN];
-
- //------------- SCSI -------------//
- uint8_t stage;
- void* buffer;
- tuh_msc_complete_cb_t complete_cb;
-
- msc_cbw_t cbw;
- msc_csw_t csw;
-}msch_interface_t;
-
-CFG_TUSB_MEM_SECTION static msch_interface_t _msch_itf[CFG_TUH_DEVICE_MAX];
-
-// buffer used to read scsi information when mounted
-// largest response data currently is inquiry TODO Inquiry is not part of enum anymore
-CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4)
-static uint8_t _msch_buffer[sizeof(scsi_inquiry_resp_t)];
-
-TU_ATTR_ALWAYS_INLINE
-static inline msch_interface_t* get_itf(uint8_t dev_addr)
-{
- return &_msch_itf[dev_addr-1];
-}
-
-//--------------------------------------------------------------------+
-// PUBLIC API
-//--------------------------------------------------------------------+
-uint8_t tuh_msc_get_maxlun(uint8_t dev_addr)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- return p_msc->max_lun;
-}
-
-uint32_t tuh_msc_get_block_count(uint8_t dev_addr, uint8_t lun)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- return p_msc->capacity[lun].block_count;
-}
-
-uint32_t tuh_msc_get_block_size(uint8_t dev_addr, uint8_t lun)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- return p_msc->capacity[lun].block_size;
-}
-
-bool tuh_msc_mounted(uint8_t dev_addr)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- return p_msc->mounted;
-}
-
-bool tuh_msc_ready(uint8_t dev_addr)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- return p_msc->mounted && !usbh_edpt_busy(dev_addr, p_msc->ep_in);
-}
-
-//--------------------------------------------------------------------+
-// PUBLIC API: SCSI COMMAND
-//--------------------------------------------------------------------+
-static inline void cbw_init(msc_cbw_t *cbw, uint8_t lun)
-{
- tu_memclr(cbw, sizeof(msc_cbw_t));
- cbw->signature = MSC_CBW_SIGNATURE;
- cbw->tag = 0x54555342; // TUSB
- cbw->lun = lun;
-}
-
-bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- TU_VERIFY(p_msc->configured);
-
- // TODO claim endpoint
-
- p_msc->cbw = *cbw;
- p_msc->stage = MSC_STAGE_CMD;
- p_msc->buffer = data;
- p_msc->complete_cb = complete_cb;
-
- TU_ASSERT(usbh_edpt_xfer(dev_addr, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)));
-
- return true;
-}
-
-bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- TU_VERIFY(p_msc->configured);
-
- msc_cbw_t cbw;
- cbw_init(&cbw, lun);
-
- cbw.total_bytes = sizeof(scsi_read_capacity10_resp_t);
- cbw.dir = TUSB_DIR_IN_MASK;
- cbw.cmd_len = sizeof(scsi_read_capacity10_t);
- cbw.command[0] = SCSI_CMD_READ_CAPACITY_10;
-
- return tuh_msc_scsi_command(dev_addr, &cbw, response, complete_cb);
-}
-
-bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- TU_VERIFY(p_msc->mounted);
-
- msc_cbw_t cbw;
- cbw_init(&cbw, lun);
-
- cbw.total_bytes = sizeof(scsi_inquiry_resp_t);
- cbw.dir = TUSB_DIR_IN_MASK;
- cbw.cmd_len = sizeof(scsi_inquiry_t);
-
- scsi_inquiry_t const cmd_inquiry =
- {
- .cmd_code = SCSI_CMD_INQUIRY,
- .alloc_length = sizeof(scsi_inquiry_resp_t)
- };
- memcpy(cbw.command, &cmd_inquiry, cbw.cmd_len);
-
- return tuh_msc_scsi_command(dev_addr, &cbw, response, complete_cb);
-}
-
-bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- TU_VERIFY(p_msc->configured);
-
- msc_cbw_t cbw;
- cbw_init(&cbw, lun);
-
- cbw.total_bytes = 0;
- cbw.dir = TUSB_DIR_OUT;
- cbw.cmd_len = sizeof(scsi_test_unit_ready_t);
- cbw.command[0] = SCSI_CMD_TEST_UNIT_READY;
- cbw.command[1] = lun; // according to wiki TODO need verification
-
- return tuh_msc_scsi_command(dev_addr, &cbw, NULL, complete_cb);
-}
-
-bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_msc_complete_cb_t complete_cb)
-{
- msc_cbw_t cbw;
- cbw_init(&cbw, lun);
-
- cbw.total_bytes = 18; // TODO sense response
- cbw.dir = TUSB_DIR_IN_MASK;
- cbw.cmd_len = sizeof(scsi_request_sense_t);
-
- scsi_request_sense_t const cmd_request_sense =
- {
- .cmd_code = SCSI_CMD_REQUEST_SENSE,
- .alloc_length = 18
- };
-
- memcpy(cbw.command, &cmd_request_sense, cbw.cmd_len);
-
- return tuh_msc_scsi_command(dev_addr, &cbw, resposne, complete_cb);
-}
-
-bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- TU_VERIFY(p_msc->mounted);
-
- msc_cbw_t cbw;
- cbw_init(&cbw, lun);
-
- cbw.total_bytes = block_count*p_msc->capacity[lun].block_size;
- cbw.dir = TUSB_DIR_IN_MASK;
- cbw.cmd_len = sizeof(scsi_read10_t);
-
- scsi_read10_t const cmd_read10 =
- {
- .cmd_code = SCSI_CMD_READ_10,
- .lba = tu_htonl(lba),
- .block_count = tu_htons(block_count)
- };
-
- memcpy(cbw.command, &cmd_read10, cbw.cmd_len);
-
- return tuh_msc_scsi_command(dev_addr, &cbw, buffer, complete_cb);
-}
-
-bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- TU_VERIFY(p_msc->mounted);
-
- msc_cbw_t cbw;
- cbw_init(&cbw, lun);
-
- cbw.total_bytes = block_count*p_msc->capacity[lun].block_size;
- cbw.dir = TUSB_DIR_OUT;
- cbw.cmd_len = sizeof(scsi_write10_t);
-
- scsi_write10_t const cmd_write10 =
- {
- .cmd_code = SCSI_CMD_WRITE_10,
- .lba = tu_htonl(lba),
- .block_count = tu_htons(block_count)
- };
-
- memcpy(cbw.command, &cmd_write10, cbw.cmd_len);
-
- return tuh_msc_scsi_command(dev_addr, &cbw, (void*) buffer, complete_cb);
-}
-
-#if 0
-// MSC interface Reset (not used now)
-bool tuh_msc_reset(uint8_t dev_addr)
-{
- tusb_control_request_t const new_request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = MSC_REQ_RESET,
- .wValue = 0,
- .wIndex = p_msc->itf_num,
- .wLength = 0
- };
- TU_ASSERT( usbh_control_xfer( dev_addr, &new_request, NULL ) );
-}
-#endif
-
-//--------------------------------------------------------------------+
-// CLASS-USBH API
-//--------------------------------------------------------------------+
-void msch_init(void)
-{
- tu_memclr(_msch_itf, sizeof(_msch_itf));
-}
-
-void msch_close(uint8_t dev_addr)
-{
- TU_VERIFY(dev_addr <= CFG_TUH_DEVICE_MAX, );
-
- msch_interface_t* p_msc = get_itf(dev_addr);
-
- // invoke Application Callback
- if (p_msc->mounted && tuh_msc_umount_cb) tuh_msc_umount_cb(dev_addr);
-
- tu_memclr(p_msc, sizeof(msch_interface_t));
-}
-
-bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- msc_cbw_t const * cbw = &p_msc->cbw;
- msc_csw_t * csw = &p_msc->csw;
-
- switch (p_msc->stage)
- {
- case MSC_STAGE_CMD:
- // Must be Command Block
- TU_ASSERT(ep_addr == p_msc->ep_out && event == XFER_RESULT_SUCCESS && xferred_bytes == sizeof(msc_cbw_t));
-
- if ( cbw->total_bytes && p_msc->buffer )
- {
- // Data stage if any
- p_msc->stage = MSC_STAGE_DATA;
-
- uint8_t const ep_data = (cbw->dir & TUSB_DIR_IN_MASK) ? p_msc->ep_in : p_msc->ep_out;
- TU_ASSERT(usbh_edpt_xfer(dev_addr, ep_data, p_msc->buffer, cbw->total_bytes));
- }else
- {
- // Status stage
- p_msc->stage = MSC_STAGE_STATUS;
- TU_ASSERT(usbh_edpt_xfer(dev_addr, p_msc->ep_in, (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)));
- }
- break;
-
- case MSC_STAGE_DATA:
- // Status stage
- p_msc->stage = MSC_STAGE_STATUS;
- TU_ASSERT(usbh_edpt_xfer(dev_addr, p_msc->ep_in, (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)));
- break;
-
- case MSC_STAGE_STATUS:
- // SCSI op is complete
- p_msc->stage = MSC_STAGE_IDLE;
-
- if (p_msc->complete_cb) p_msc->complete_cb(dev_addr, cbw, csw);
- break;
-
- // unknown state
- default: break;
- }
-
- return true;
-}
-
-//--------------------------------------------------------------------+
-// MSC Enumeration
-//--------------------------------------------------------------------+
-
-static bool config_get_maxlun_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result);
-static bool config_test_unit_ready_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
-static bool config_request_sense_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
-static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
-
-bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
-{
- TU_VERIFY (MSC_SUBCLASS_SCSI == desc_itf->bInterfaceSubClass &&
- MSC_PROTOCOL_BOT == desc_itf->bInterfaceProtocol);
-
- // msc driver length is fixed
- uint16_t const drv_len = sizeof(tusb_desc_interface_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
- TU_ASSERT(drv_len <= max_len);
-
- msch_interface_t* p_msc = get_itf(dev_addr);
- tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(desc_itf);
-
- for(uint32_t i=0; i<2; i++)
- {
- TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType && TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
- TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
-
- if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
- {
- p_msc->ep_in = ep_desc->bEndpointAddress;
- }else
- {
- p_msc->ep_out = ep_desc->bEndpointAddress;
- }
-
- ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc);
- }
-
- p_msc->itf_num = desc_itf->bInterfaceNumber;
-
- return true;
-}
-
-bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
-{
- msch_interface_t* p_msc = get_itf(dev_addr);
- TU_ASSERT(p_msc->itf_num == itf_num);
-
- p_msc->configured = true;
-
- //------------- Get Max Lun -------------//
- TU_LOG2("MSC Get Max Lun\r\n");
- tusb_control_request_t request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_IN
- },
- .bRequest = MSC_REQ_GET_MAX_LUN,
- .wValue = 0,
- .wIndex = itf_num,
- .wLength = 1
- };
- TU_ASSERT(tuh_control_xfer(dev_addr, &request, &p_msc->max_lun, config_get_maxlun_complete));
-
- return true;
-}
-
-static bool config_get_maxlun_complete (uint8_t dev_addr, tusb_control_request_t const * request, xfer_result_t result)
-{
- (void) request;
-
- msch_interface_t* p_msc = get_itf(dev_addr);
-
- // STALL means zero
- p_msc->max_lun = (XFER_RESULT_SUCCESS == result) ? _msch_buffer[0] : 0;
- p_msc->max_lun++; // MAX LUN is minus 1 by specs
-
- // TODO multiple LUN support
- TU_LOG2("SCSI Test Unit Ready\r\n");
- uint8_t const lun = 0;
- tuh_msc_test_unit_ready(dev_addr, lun, config_test_unit_ready_complete);
-
- return true;
-}
-
-static bool config_test_unit_ready_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
-{
- if (csw->status == 0)
- {
- // Unit is ready, read its capacity
- TU_LOG2("SCSI Read Capacity\r\n");
- tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete);
- }else
- {
- // Note: During enumeration, some device fails Test Unit Ready and require a few retries
- // with Request Sense to start working !!
- // TODO limit number of retries
- TU_LOG2("SCSI Request Sense\r\n");
- TU_ASSERT(tuh_msc_request_sense(dev_addr, cbw->lun, _msch_buffer, config_request_sense_complete));
- }
-
- return true;
-}
-
-static bool config_request_sense_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
-{
- TU_ASSERT(csw->status == 0);
- TU_ASSERT(tuh_msc_test_unit_ready(dev_addr, cbw->lun, config_test_unit_ready_complete));
- return true;
-}
-
-static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
-{
- TU_ASSERT(csw->status == 0);
-
- msch_interface_t* p_msc = get_itf(dev_addr);
-
- // Capacity response field: Block size and Last LBA are both Big-Endian
- scsi_read_capacity10_resp_t* resp = (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer);
- p_msc->capacity[cbw->lun].block_count = tu_ntohl(resp->last_lba) + 1;
- p_msc->capacity[cbw->lun].block_size = tu_ntohl(resp->block_size);
-
- // Mark enumeration is complete
- p_msc->mounted = true;
- if (tuh_msc_mount_cb) tuh_msc_mount_cb(dev_addr);
-
- // notify usbh that driver enumeration is complete
- usbh_driver_set_config_complete(dev_addr, p_msc->itf_num);
-
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/class/msc/msc_host.h b/tinyusb/src/class/msc/msc_host.h
deleted file mode 100755
index 7718ad4f..00000000
--- a/tinyusb/src/class/msc/msc_host.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_MSC_HOST_H_
-#define _TUSB_MSC_HOST_H_
-
-#include "msc.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Class Driver Configuration
-//--------------------------------------------------------------------+
-
-#ifndef CFG_TUH_MSC_MAXLUN
-#define CFG_TUH_MSC_MAXLUN 4
-#endif
-
-typedef bool (*tuh_msc_complete_cb_t)(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
-
-//--------------------------------------------------------------------+
-// Application API
-//--------------------------------------------------------------------+
-
-// Check if device supports MassStorage interface.
-// This function true after tuh_msc_mounted_cb() and false after tuh_msc_unmounted_cb()
-bool tuh_msc_mounted(uint8_t dev_addr);
-
-// Check if the interface is currently ready or busy transferring data
-bool tuh_msc_ready(uint8_t dev_addr);
-
-// Get Max Lun
-uint8_t tuh_msc_get_maxlun(uint8_t dev_addr);
-
-// Get number of block
-uint32_t tuh_msc_get_block_count(uint8_t dev_addr, uint8_t lun);
-
-// Get block size in bytes
-uint32_t tuh_msc_get_block_size(uint8_t dev_addr, uint8_t lun);
-
-// Perform a full SCSI command (cbw, data, csw) in non-blocking manner.
-// Complete callback is invoked when SCSI op is complete.
-// return true if success, false if there is already pending operation.
-bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb);
-
-// Perform SCSI Inquiry command
-// Complete callback is invoked when SCSI op is complete.
-bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb);
-
-// Perform SCSI Test Unit Ready command
-// Complete callback is invoked when SCSI op is complete.
-bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb);
-
-// Perform SCSI Request Sense 10 command
-// Complete callback is invoked when SCSI op is complete.
-bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_msc_complete_cb_t complete_cb);
-
-// Perform SCSI Read 10 command. Read n blocks starting from LBA to buffer
-// Complete callback is invoked when SCSI op is complete.
-bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb);
-
-// Perform SCSI Write 10 command. Write n blocks starting from LBA to device
-// Complete callback is invoked when SCSI op is complete.
-bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb);
-
-// Perform SCSI Read Capacity 10 command
-// Complete callback is invoked when SCSI op is complete.
-// Note: during enumeration, host stack already carried out this request. Application can retrieve capacity by
-// simply call tuh_msc_get_block_count() and tuh_msc_get_block_size()
-bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb);
-
-//------------- Application Callback -------------//
-
-// Invoked when a device with MassStorage interface is mounted
-TU_ATTR_WEAK void tuh_msc_mount_cb(uint8_t dev_addr);
-
-// Invoked when a device with MassStorage interface is unmounted
-TU_ATTR_WEAK void tuh_msc_umount_cb(uint8_t dev_addr);
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-
-void msch_init (void);
-bool msch_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len);
-bool msch_set_config (uint8_t dev_addr, uint8_t itf_num);
-void msch_close (uint8_t dev_addr);
-bool msch_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_MSC_HOST_H_ */
diff --git a/tinyusb/src/class/net/net_device.c b/tinyusb/src/class/net/net_device.c
deleted file mode 100755
index 9d9719ce..00000000
--- a/tinyusb/src/class/net/net_device.c
+++ /dev/null
@@ -1,441 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Peter Lawrence
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if ( TUSB_OPT_DEVICE_ENABLED && CFG_TUD_NET )
-
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "net_device.h"
-#include "rndis_protocol.h"
-
-void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networking/rndis_reports.c */
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-typedef struct
-{
- uint8_t itf_num; // Index number of Management Interface, +1 for Data Interface
- uint8_t itf_data_alt; // Alternate setting of Data Interface. 0 : inactive, 1 : active
-
- uint8_t ep_notif;
- uint8_t ep_in;
- uint8_t ep_out;
-
- bool ecm_mode;
-
- // Endpoint descriptor use to open/close when receving SetInterface
- // TODO since configuration descriptor may not be long-lived memory, we should
- // keep a copy of endpoint attribute instead
- uint8_t const * ecm_desc_epdata;
-
-} netd_interface_t;
-
-#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
-#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
-
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t received[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
-
-struct ecm_notify_struct
-{
- tusb_control_request_t header;
- uint32_t downlink, uplink;
-};
-
-static const struct ecm_notify_struct ecm_notify_nc =
-{
- .header = {
- .bmRequestType = 0xA1,
- .bRequest = 0 /* NETWORK_CONNECTION aka NetworkConnection */,
- .wValue = 1 /* Connected */,
- .wLength = 0,
- },
-};
-
-static const struct ecm_notify_struct ecm_notify_csc =
-{
- .header = {
- .bmRequestType = 0xA1,
- .bRequest = 0x2A /* CONNECTION_SPEED_CHANGE aka ConnectionSpeedChange */,
- .wLength = 8,
- },
- .downlink = 9728000,
- .uplink = 9728000,
-};
-
-// TODO remove CFG_TUSB_MEM_SECTION, control internal buffer is already in this special section
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static union
-{
- uint8_t rndis_buf[120];
- struct ecm_notify_struct ecm_buf;
-} notify;
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-// TODO remove CFG_TUSB_MEM_SECTION
-CFG_TUSB_MEM_SECTION static netd_interface_t _netd_itf;
-
-static bool can_xmit;
-
-void tud_network_recv_renew(void)
-{
- usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_out, received, sizeof(received));
-}
-
-static void do_in_xfer(uint8_t *buf, uint16_t len)
-{
- can_xmit = false;
- usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_in, buf, len);
-}
-
-void netd_report(uint8_t *buf, uint16_t len)
-{
- usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_notif, buf, len);
-}
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void netd_init(void)
-{
- tu_memclr(&_netd_itf, sizeof(_netd_itf));
-}
-
-void netd_reset(uint8_t rhport)
-{
- (void) rhport;
-
- netd_init();
-}
-
-uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- bool const is_rndis = (TUD_RNDIS_ITF_CLASS == itf_desc->bInterfaceClass &&
- TUD_RNDIS_ITF_SUBCLASS == itf_desc->bInterfaceSubClass &&
- TUD_RNDIS_ITF_PROTOCOL == itf_desc->bInterfaceProtocol);
-
- bool const is_ecm = (TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
- CDC_COMM_SUBCLASS_ETHERNET_CONTROL_MODEL == itf_desc->bInterfaceSubClass &&
- 0x00 == itf_desc->bInterfaceProtocol);
-
- TU_VERIFY(is_rndis || is_ecm, 0);
-
- // confirm interface hasn't already been allocated
- TU_ASSERT(0 == _netd_itf.ep_notif, 0);
-
- // sanity check the descriptor
- _netd_itf.ecm_mode = is_ecm;
-
- //------------- Management Interface -------------//
- _netd_itf.itf_num = itf_desc->bInterfaceNumber;
-
- uint16_t drv_len = sizeof(tusb_desc_interface_t);
- uint8_t const * p_desc = tu_desc_next( itf_desc );
-
- // Communication Functional Descriptors
- while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len )
- {
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- // notification endpoint (if any)
- if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
- {
- TU_ASSERT( usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), 0 );
-
- _netd_itf.ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- //------------- Data Interface -------------//
- // - RNDIS Data followed immediately by a pair of endpoints
- // - CDC-ECM data interface has 2 alternate settings
- // - 0 : zero endpoints for inactive (default)
- // - 1 : IN & OUT endpoints for active networking
- TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc), 0);
-
- do
- {
- tusb_desc_interface_t const * data_itf_desc = (tusb_desc_interface_t const *) p_desc;
- TU_ASSERT(TUSB_CLASS_CDC_DATA == data_itf_desc->bInterfaceClass, 0);
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }while( _netd_itf.ecm_mode && (TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) && (drv_len <= max_len) );
-
- // Pair of endpoints
- TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc), 0);
-
- if ( _netd_itf.ecm_mode )
- {
- // ECM by default is in-active, save the endpoint attribute
- // to open later when received setInterface
- _netd_itf.ecm_desc_epdata = p_desc;
- }else
- {
- // Open endpoint pair for RNDIS
- TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &_netd_itf.ep_out, &_netd_itf.ep_in), 0 );
-
- tud_network_init_cb();
-
- // we are ready to transmit a packet
- can_xmit = true;
-
- // prepare for incoming packets
- tud_network_recv_renew();
- }
-
- drv_len += 2*sizeof(tusb_desc_endpoint_t);
-
- return drv_len;
-}
-
-static void ecm_report(bool nc)
-{
- notify.ecm_buf = (nc) ? ecm_notify_nc : ecm_notify_csc;
- notify.ecm_buf.header.wIndex = _netd_itf.itf_num;
- netd_report((uint8_t *)&notify.ecm_buf, (nc) ? sizeof(notify.ecm_buf.header) : sizeof(notify.ecm_buf));
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- if ( stage == CONTROL_STAGE_SETUP )
- {
- switch ( request->bmRequestType_bit.type )
- {
- case TUSB_REQ_TYPE_STANDARD:
- switch ( request->bRequest )
- {
- case TUSB_REQ_GET_INTERFACE:
- {
- uint8_t const req_itfnum = (uint8_t) request->wIndex;
- TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum);
-
- tud_control_xfer(rhport, request, &_netd_itf.itf_data_alt, 1);
- }
- break;
-
- case TUSB_REQ_SET_INTERFACE:
- {
- uint8_t const req_itfnum = (uint8_t) request->wIndex;
- uint8_t const req_alt = (uint8_t) request->wValue;
-
- // Only valid for Data Interface with Alternate is either 0 or 1
- TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum && req_alt < 2);
-
- // ACM-ECM only: qequest to enable/disable network activities
- TU_VERIFY(_netd_itf.ecm_mode);
-
- _netd_itf.itf_data_alt = req_alt;
-
- if ( _netd_itf.itf_data_alt )
- {
- // TODO since we don't actually close endpoint
- // hack here to not re-open it
- if ( _netd_itf.ep_in == 0 && _netd_itf.ep_out == 0 )
- {
- TU_ASSERT(_netd_itf.ecm_desc_epdata);
- TU_ASSERT( usbd_open_edpt_pair(rhport, _netd_itf.ecm_desc_epdata, 2, TUSB_XFER_BULK, &_netd_itf.ep_out, &_netd_itf.ep_in) );
-
- // TODO should be merge with RNDIS's after endpoint opened
- // Also should have opposite callback for application to disable network !!
- tud_network_init_cb();
- can_xmit = true; // we are ready to transmit a packet
- tud_network_recv_renew(); // prepare for incoming packets
- }
- }else
- {
- // TODO close the endpoint pair
- // For now pretend that we did, this should have no harm since host won't try to
- // communicate with the endpoints again
- // _netd_itf.ep_in = _netd_itf.ep_out = 0
- }
-
- tud_control_status(rhport, request);
- }
- break;
-
- // unsupported request
- default: return false;
- }
- break;
-
- case TUSB_REQ_TYPE_CLASS:
- TU_VERIFY (_netd_itf.itf_num == request->wIndex);
-
- if (_netd_itf.ecm_mode)
- {
- /* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
- if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest)
- {
- tud_control_xfer(rhport, request, NULL, 0);
- ecm_report(true);
- }
- }
- else
- {
- if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
- {
- rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *) ((void*) notify.rndis_buf);
- uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
- TU_ASSERT(msglen <= sizeof(notify.rndis_buf));
- tud_control_xfer(rhport, request, notify.rndis_buf, msglen);
- }
- else
- {
- tud_control_xfer(rhport, request, notify.rndis_buf, sizeof(notify.rndis_buf));
- }
- }
- break;
-
- // unsupported request
- default: return false;
- }
- }
- else if ( stage == CONTROL_STAGE_DATA )
- {
- // Handle RNDIS class control OUT only
- if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
- request->bmRequestType_bit.direction == TUSB_DIR_OUT &&
- _netd_itf.itf_num == request->wIndex)
- {
- if ( !_netd_itf.ecm_mode )
- {
- rndis_class_set_handler(notify.rndis_buf, request->wLength);
- }
- }
- }
-
- return true;
-}
-
-static void handle_incoming_packet(uint32_t len)
-{
- uint8_t *pnt = received;
- uint32_t size = 0;
-
- if (_netd_itf.ecm_mode)
- {
- size = len;
- }
- else
- {
- rndis_data_packet_t *r = (rndis_data_packet_t *) ((void*) pnt);
- if (len >= sizeof(rndis_data_packet_t))
- if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
- if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
- {
- pnt = &received[r->DataOffset + offsetof(rndis_data_packet_t, DataOffset)];
- size = r->DataLength;
- }
- }
-
- if (!tud_network_recv_cb(pnt, size))
- {
- /* if a buffer was never handled by user code, we must renew on the user's behalf */
- tud_network_recv_renew();
- }
-}
-
-bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void) rhport;
- (void) result;
-
- /* new packet received */
- if ( ep_addr == _netd_itf.ep_out )
- {
- handle_incoming_packet(xferred_bytes);
- }
-
- /* data transmission finished */
- if ( ep_addr == _netd_itf.ep_in )
- {
- /* TinyUSB requires the class driver to implement ZLP (since ZLP usage is class-specific) */
-
- if ( xferred_bytes && (0 == (xferred_bytes % CFG_TUD_NET_ENDPOINT_SIZE)) )
- {
- do_in_xfer(NULL, 0); /* a ZLP is needed */
- }
- else
- {
- /* we're finally finished */
- can_xmit = true;
- }
- }
-
- if ( _netd_itf.ecm_mode && (ep_addr == _netd_itf.ep_notif) )
- {
- if (sizeof(notify.ecm_buf.header) == xferred_bytes) ecm_report(false);
- }
-
- return true;
-}
-
-bool tud_network_can_xmit(void)
-{
- return can_xmit;
-}
-
-void tud_network_xmit(void *ref, uint16_t arg)
-{
- uint8_t *data;
- uint16_t len;
-
- if (!can_xmit)
- return;
-
- len = (_netd_itf.ecm_mode) ? 0 : CFG_TUD_NET_PACKET_PREFIX_LEN;
- data = transmitted + len;
-
- len += tud_network_xmit_cb(data, ref, arg);
-
- if (!_netd_itf.ecm_mode)
- {
- rndis_data_packet_t *hdr = (rndis_data_packet_t *) ((void*) transmitted);
- memset(hdr, 0, sizeof(rndis_data_packet_t));
- hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
- hdr->MessageLength = len;
- hdr->DataOffset = sizeof(rndis_data_packet_t) - offsetof(rndis_data_packet_t, DataOffset);
- hdr->DataLength = len - sizeof(rndis_data_packet_t);
- }
-
- do_in_xfer(transmitted, len);
-}
-
-#endif
diff --git a/tinyusb/src/class/net/net_device.h b/tinyusb/src/class/net/net_device.h
deleted file mode 100755
index f030f307..00000000
--- a/tinyusb/src/class/net/net_device.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Peter Lawrence
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_NET_DEVICE_H_
-#define _TUSB_NET_DEVICE_H_
-
-#include "class/cdc/cdc.h"
-
-/* declared here, NOT in usb_descriptors.c, so that the driver can intelligently ZLP as needed */
-#define CFG_TUD_NET_ENDPOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
-
-/* Maximum Tranmission Unit (in bytes) of the network, including Ethernet header */
-#ifndef CFG_TUD_NET_MTU
-#define CFG_TUD_NET_MTU 1514
-#endif
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Application API
-//--------------------------------------------------------------------+
-
-// client must provide this: initialize any network state back to the beginning
-void tud_network_init_cb(void);
-
-// client must provide this: return false if the packet buffer was not accepted
-bool tud_network_recv_cb(const uint8_t *src, uint16_t size);
-
-// client must provide this: copy from network stack packet pointer to dst
-uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg);
-
-// client must provide this: 48-bit MAC address
-// TODO removed later since it is not part of tinyusb stack
-extern const uint8_t tud_network_mac_address[6];
-
-// indicate to network driver that client has finished with the packet provided to network_recv_cb()
-void tud_network_recv_renew(void);
-
-// poll network driver for its ability to accept another packet to transmit
-bool tud_network_can_xmit(void);
-
-// if network_can_xmit() returns true, network_xmit() can be called once
-void tud_network_xmit(void *ref, uint16_t arg);
-
-//--------------------------------------------------------------------+
-// INTERNAL USBD-CLASS DRIVER API
-//--------------------------------------------------------------------+
-void netd_init (void);
-void netd_reset (uint8_t rhport);
-uint16_t netd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-bool netd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
-void netd_report (uint8_t *buf, uint16_t len);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_NET_DEVICE_H_ */
diff --git a/tinyusb/src/class/usbtmc/usbtmc.h b/tinyusb/src/class/usbtmc/usbtmc.h
deleted file mode 100755
index 7d7005c2..00000000
--- a/tinyusb/src/class/usbtmc/usbtmc.h
+++ /dev/null
@@ -1,316 +0,0 @@
-
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 N Conrad
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_USBTMC_H__
-#define _TUSB_USBTMC_H__
-
-#include "common/tusb_common.h"
-
-
-/* Implements USBTMC Revision 1.0, April 14, 2003
-
- String descriptors must have a "LANGID=0x409"/US English string.
- Characters must be 0x20 (' ') to 0x7E ('~') ASCII,
- But MUST not contain: "/:?\*
- Also must not have leading or trailing space (' ')
- Device descriptor must state USB version 0x0200 or greater
-
- If USB488DeviceCapabilites.D2 = 1 (SR1), then there must be a INT endpoint.
-*/
-
-#define USBTMC_VERSION 0x0100
-#define USBTMC_488_VERSION 0x0100
-
-typedef enum {
- USBTMC_MSGID_DEV_DEP_MSG_OUT = 1u,
- USBTMC_MSGID_DEV_DEP_MSG_IN = 2u,
- USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT = 126u,
- USBTMC_MSGID_VENDOR_SPECIFIC_IN = 127u,
- USBTMC_MSGID_USB488_TRIGGER = 128u,
-} usbtmc_msgid_enum;
-
-/// \brief Message header (For BULK OUT and BULK IN); 4 bytes
-typedef struct TU_ATTR_PACKED
-{
- uint8_t MsgID ; ///< Message type ID (usbtmc_msgid_enum)
- uint8_t bTag ; ///< Transfer ID 1<=bTag<=255
- uint8_t bTagInverse ; ///< Complement of the tag
- uint8_t _reserved ; ///< Must be 0x00
-} usbtmc_msg_header_t;
-
-typedef struct TU_ATTR_PACKED
-{
- usbtmc_msg_header_t header;
- uint8_t data[8];
-} usbtmc_msg_generic_t;
-
-/* Uses on the bulk-out endpoint: */
-// Next 8 bytes are message-specific
-typedef struct TU_ATTR_PACKED {
- usbtmc_msg_header_t header ; ///< Header
- uint32_t TransferSize ; ///< Transfer size; LSB first
- struct TU_ATTR_PACKED
- {
- unsigned int EOM : 1 ; ///< EOM set on last byte
- } bmTransferAttributes;
- uint8_t _reserved[3];
-} usbtmc_msg_request_dev_dep_out;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_out) == 12u, "struct wrong length");
-
-// Next 8 bytes are message-specific
-typedef struct TU_ATTR_PACKED
-{
- usbtmc_msg_header_t header ; ///< Header
- uint32_t TransferSize ; ///< Transfer size; LSB first
- struct TU_ATTR_PACKED
- {
- unsigned int TermCharEnabled : 1 ; ///< "The Bulk-IN transfer must terminate on the specified TermChar."; CAPABILITIES must list TermChar
- } bmTransferAttributes;
- uint8_t TermChar;
- uint8_t _reserved[2];
-} usbtmc_msg_request_dev_dep_in;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_dev_dep_in) == 12u, "struct wrong length");
-
-/* Bulk-in headers */
-
-typedef struct TU_ATTR_PACKED
-{
- usbtmc_msg_header_t header;
- uint32_t TransferSize;
- struct TU_ATTR_PACKED
- {
- uint8_t EOM: 1; ///< Last byte of transfer is the end of the message
- uint8_t UsingTermChar: 1; ///< Support TermChar && Request.TermCharEnabled && last char in transfer is TermChar
- } bmTransferAttributes;
- uint8_t _reserved[3];
-} usbtmc_msg_dev_dep_msg_in_header_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_msg_dev_dep_msg_in_header_t) == 12u, "struct wrong length");
-
-/* Unsupported vendor things.... Are these ever used?*/
-
-typedef struct TU_ATTR_PACKED
-{
- usbtmc_msg_header_t header ; ///< Header
- uint32_t TransferSize ; ///< Transfer size; LSB first
- uint8_t _reserved[4];
-} usbtmc_msg_request_vendor_specific_out;
-
-
-TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_out) == 12u, "struct wrong length");
-
-typedef struct TU_ATTR_PACKED
-{
- usbtmc_msg_header_t header ; ///< Header
- uint32_t TransferSize ; ///< Transfer size; LSB first
- uint8_t _reserved[4];
-} usbtmc_msg_request_vendor_specific_in;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_msg_request_vendor_specific_in) == 12u, "struct wrong length");
-
-// Control request type should use tusb_control_request_t
-
-/*
-typedef struct TU_ATTR_PACKED {
- struct {
- unsigned int Recipient : 5 ; ///< EOM set on last byte
- unsigned int Type : 2 ; ///< EOM set on last byte
- unsigned int DirectionToHost : 1 ; ///< 0 is OUT, 1 is IN
- } bmRequestType;
- uint8_t bRequest ; ///< If bmRequestType.Type = Class, see usmtmc_request_type_enum
- uint16_t wValue ;
- uint16_t wIndex ;
- uint16_t wLength ; // Number of bytes in data stage
-} usbtmc_class_specific_control_req;
-
-*/
-// bulk-in protocol errors
-enum {
- USBTMC_BULK_IN_ERR_INCOMPLETE_HEADER = 1u,
- USBTMC_BULK_IN_ERR_UNSUPPORTED = 2u,
- USBTMC_BULK_IN_ERR_BAD_PARAMETER = 3u,
- USBTMC_BULK_IN_ERR_DATA_TOO_SHORT = 4u,
- USBTMC_BULK_IN_ERR_DATA_TOO_LONG = 5u,
-};
-// bult-in halt errors
-enum {
- USBTMC_BULK_IN_ERR = 1u, ///< receives a USBTMC command message that expects a response while a
- /// Bulk-IN transfer is in progress
-};
-
-typedef enum {
- USBTMC_bREQUEST_INITIATE_ABORT_BULK_OUT = 1u,
- USBTMC_bREQUEST_CHECK_ABORT_BULK_OUT_STATUS = 2u,
- USBTMC_bREQUEST_INITIATE_ABORT_BULK_IN = 3u,
- USBTMC_bREQUEST_CHECK_ABORT_BULK_IN_STATUS = 4u,
- USBTMC_bREQUEST_INITIATE_CLEAR = 5u,
- USBTMC_bREQUEST_CHECK_CLEAR_STATUS = 6u,
- USBTMC_bREQUEST_GET_CAPABILITIES = 7u,
-
- USBTMC_bREQUEST_INDICATOR_PULSE = 64u, // Optional
-
- /****** USBTMC 488 *************/
- USB488_bREQUEST_READ_STATUS_BYTE = 128u,
- USB488_bREQUEST_REN_CONTROL = 160u,
- USB488_bREQUEST_GO_TO_LOCAL = 161u,
- USB488_bREQUEST_LOCAL_LOCKOUT = 162u,
-
-} usmtmc_request_type_enum;
-
-typedef enum {
- USBTMC_STATUS_SUCCESS = 0x01,
- USBTMC_STATUS_PENDING = 0x02,
- USBTMC_STATUS_FAILED = 0x80,
- USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS = 0x81,
- USBTMC_STATUS_SPLIT_NOT_IN_PROGRESS = 0x82,
- USBTMC_STATUS_SPLIT_IN_PROGRESS = 0x83
-} usbtmc_status_enum;
-
-/************************************************************
- * Control Responses
- */
-
-typedef struct TU_ATTR_PACKED {
- uint8_t USBTMC_status; ///< usbtmc_status_enum
- uint8_t _reserved;
- uint16_t bcdUSBTMC; ///< USBTMC_VERSION
-
- struct TU_ATTR_PACKED
- {
- unsigned int listenOnly :1;
- unsigned int talkOnly :1;
- unsigned int supportsIndicatorPulse :1;
- } bmIntfcCapabilities;
- struct TU_ATTR_PACKED
- {
- unsigned int canEndBulkInOnTermChar :1;
- } bmDevCapabilities;
- uint8_t _reserved2[6];
- uint8_t _reserved3[12];
-} usbtmc_response_capabilities_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_t) == 0x18, "struct wrong length");
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t USBTMC_status;
- struct TU_ATTR_PACKED
- {
- unsigned int BulkInFifoBytes :1;
- } bmClear;
-} usbtmc_get_clear_status_rsp_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
-
-// Used for both abort bulk IN and bulk OUT
-typedef struct TU_ATTR_PACKED
-{
- uint8_t USBTMC_status;
- uint8_t bTag;
-} usbtmc_initiate_abort_rsp_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_get_clear_status_rsp_t) == 2u, "struct wrong length");
-
-// Used for both check_abort_bulk_in_status and check_abort_bulk_out_status
-typedef struct TU_ATTR_PACKED
-{
- uint8_t USBTMC_status;
- struct TU_ATTR_PACKED
- {
- unsigned int BulkInFifoBytes : 1; ///< Has queued data or a short packet that is queued
- } bmAbortBulkIn;
- uint8_t _reserved[2]; ///< Must be zero
- uint32_t NBYTES_RXD_TXD;
-} usbtmc_check_abort_bulk_rsp_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_check_abort_bulk_rsp_t) == 8u, "struct wrong length");
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t USBTMC_status; ///< usbtmc_status_enum
- uint8_t _reserved;
- uint16_t bcdUSBTMC; ///< USBTMC_VERSION
-
- struct TU_ATTR_PACKED
- {
- unsigned int listenOnly :1;
- unsigned int talkOnly :1;
- unsigned int supportsIndicatorPulse :1;
- } bmIntfcCapabilities;
-
- struct TU_ATTR_PACKED
- {
- unsigned int canEndBulkInOnTermChar :1;
- } bmDevCapabilities;
-
- uint8_t _reserved2[6];
- uint16_t bcdUSB488;
-
- struct TU_ATTR_PACKED
- {
- unsigned int is488_2 :1;
- unsigned int supportsREN_GTL_LLO :1;
- unsigned int supportsTrigger :1;
- } bmIntfcCapabilities488;
-
- struct TU_ATTR_PACKED
- {
- unsigned int SCPI :1;
- unsigned int SR1 :1;
- unsigned int RL1 :1;
- unsigned int DT1 :1;
- } bmDevCapabilities488;
- uint8_t _reserved3[8];
-} usbtmc_response_capabilities_488_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_response_capabilities_488_t) == 0x18, "struct wrong length");
-
-typedef struct TU_ATTR_PACKED
-{
- uint8_t USBTMC_status;
- uint8_t bTag;
- uint8_t statusByte;
-} usbtmc_read_stb_rsp_488_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_rsp_488_t) == 3u, "struct wrong length");
-
-typedef struct TU_ATTR_PACKED
-{
- struct TU_ATTR_PACKED
- {
- unsigned int bTag : 7;
- unsigned int one : 1;
- } bNotify1;
- uint8_t StatusByte;
-} usbtmc_read_stb_interrupt_488_t;
-
-TU_VERIFY_STATIC(sizeof(usbtmc_read_stb_interrupt_488_t) == 2u, "struct wrong length");
-
-#endif
-
diff --git a/tinyusb/src/class/usbtmc/usbtmc_device.c b/tinyusb/src/class/usbtmc/usbtmc_device.c
deleted file mode 100755
index c1ee49f4..00000000
--- a/tinyusb/src/class/usbtmc/usbtmc_device.c
+++ /dev/null
@@ -1,860 +0,0 @@
-/*
- * usbtmc.c
- *
- * Created on: Sep 9, 2019
- * Author: nconrad
- */
-
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Nathan Conrad
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/*
- * This library is not fully reentrant, though it is reentrant from the view
- * of either the application layer or the USB stack. Due to its locking,
- * it is not safe to call its functions from interrupts.
- *
- * The one exception is that its functions may not be called from the application
- * until the USB stack is initialized. This should not be a problem since the
- * device shouldn't be sending messages until it receives a request from the
- * host.
- */
-
-
-/*
- * In the case of single-CPU "no OS", this task is never preempted other than by
- * interrupts, and the USBTMC code isn't called by interrupts, so all is OK. For "no OS",
- * the mutex structure's main effect is to disable the USB interrupts.
- * With an OS, this class driver uses the OSAL to perform locking. The code uses a single lock
- * and does not call outside of this class with a lock held, so deadlocks won't happen.
- */
-
-//Limitations:
-// "vendor-specific" commands are not handled.
-// Dealing with "termchar" must be handled by the application layer,
-// though additional error checking is does in this module.
-// talkOnly and listenOnly are NOT supported. They're not permitted
-// in USB488, anyway.
-
-/* Supported:
- *
- * Notification pulse
- * Trigger
- * Read status byte (both by interrupt endpoint and control message)
- *
- */
-
-
-// TODO:
-// USBTMC 3.2.2 error conditions not strictly followed
-// No local lock-out, REN, or GTL.
-// Clear message available status byte at the correct time? (488 4.3.1.3)
-
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_USBTMC)
-
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "usbtmc_device.h"
-
-#ifdef xDEBUG
-#include "uart_util.h"
-static char logMsg[150];
-#endif
-
-/*
- * The state machine does not allow simultaneous reading and writing. This is
- * consistent with USBTMC.
- */
-
-typedef enum
-{
- STATE_CLOSED, // Endpoints have not yet been opened since USB reset
- STATE_NAK, // Bulk-out endpoint is in NAK state.
- STATE_IDLE, // Bulk-out endpoint is waiting for CMD.
- STATE_RCV, // Bulk-out is receiving DEV_DEP message
- STATE_TX_REQUESTED,
- STATE_TX_INITIATED,
- STATE_TX_SHORTED,
- STATE_CLEARING,
- STATE_ABORTING_BULK_IN,
- STATE_ABORTING_BULK_IN_SHORTED, // aborting, and short packet has been queued for transmission
- STATE_ABORTING_BULK_IN_ABORTED, // aborting, and short packet has been transmitted
- STATE_ABORTING_BULK_OUT,
- STATE_NUM_STATES
-} usbtmcd_state_enum;
-
-#if (CFG_TUD_USBTMC_ENABLE_488)
- typedef usbtmc_response_capabilities_488_t usbtmc_capabilities_specific_t;
-#else
- typedef usbtmc_response_capabilities_t usbtmc_capabilities_specific_t;
-#endif
-
-
-typedef struct
-{
- volatile usbtmcd_state_enum state;
-
- uint8_t itf_id;
- uint8_t rhport;
- uint8_t ep_bulk_in;
- uint8_t ep_bulk_out;
- uint8_t ep_int_in;
- // IN buffer is only used for first packet, not the remainder
- // in order to deal with prepending header
- CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_in_buf[USBTMCD_MAX_PACKET_SIZE];
- // OUT buffer receives one packet at a time
- CFG_TUSB_MEM_ALIGN uint8_t ep_bulk_out_buf[USBTMCD_MAX_PACKET_SIZE];
- uint32_t transfer_size_remaining; // also used for requested length for bulk IN.
- uint32_t transfer_size_sent; // To keep track of data bytes that have been queued in FIFO (not header bytes)
-
- uint8_t lastBulkOutTag; // used for aborts (mostly)
- uint8_t lastBulkInTag; // used for aborts (mostly)
-
- uint8_t const * devInBuffer; // pointer to application-layer used for transmissions
-
- usbtmc_capabilities_specific_t const * capabilities;
-} usbtmc_interface_state_t;
-
-CFG_TUSB_MEM_SECTION static usbtmc_interface_state_t usbtmc_state =
-{
- .itf_id = 0xFF,
-};
-
-// We need all headers to fit in a single packet in this implementation.
-TU_VERIFY_STATIC(USBTMCD_MAX_PACKET_SIZE >= 32u,"USBTMC dev EP packet size too small");
-TU_VERIFY_STATIC(
- (sizeof(usbtmc_state.ep_bulk_in_buf) % USBTMCD_MAX_PACKET_SIZE) == 0,
- "packet buffer must be a multiple of the packet size");
-
-static bool handle_devMsgOutStart(uint8_t rhport, void *data, size_t len);
-static bool handle_devMsgOut(uint8_t rhport, void *data, size_t len, size_t packetLen);
-
-static uint8_t termChar;
-static uint8_t termCharRequested = false;
-
-
-osal_mutex_def_t usbtmcLockBuffer;
-static osal_mutex_t usbtmcLock;
-
-// Our own private lock, mostly for the state variable.
-#define criticalEnter() do {osal_mutex_lock(usbtmcLock,OSAL_TIMEOUT_WAIT_FOREVER); } while (0)
-#define criticalLeave() do {osal_mutex_unlock(usbtmcLock); } while (0)
-
-bool atomicChangeState(usbtmcd_state_enum expectedState, usbtmcd_state_enum newState)
-{
- bool ret = true;
- criticalEnter();
- usbtmcd_state_enum oldState = usbtmc_state.state;
- if (oldState == expectedState)
- {
- usbtmc_state.state = newState;
- }
- else
- {
- ret = false;
- }
- criticalLeave();
- return ret;
-}
-
-// called from app
-// We keep a reference to the buffer, so it MUST not change until the app is
-// notified that the transfer is complete.
-// length of data is specified in the hdr.
-
-// We can't just send the whole thing at once because we need to concatanate the
-// header with the data.
-bool tud_usbtmc_transmit_dev_msg_data(
- const void * data, size_t len,
- bool endOfMessage,
- bool usingTermChar)
-{
- const unsigned int txBufLen = sizeof(usbtmc_state.ep_bulk_in_buf);
-
-#ifndef NDEBUG
- TU_ASSERT(len > 0u);
- TU_ASSERT(len <= usbtmc_state.transfer_size_remaining);
- TU_ASSERT(usbtmc_state.transfer_size_sent == 0u);
- if(usingTermChar)
- {
- TU_ASSERT(usbtmc_state.capabilities->bmDevCapabilities.canEndBulkInOnTermChar);
- TU_ASSERT(termCharRequested);
- TU_ASSERT(((uint8_t*)data)[len-1u] == termChar);
- }
-#endif
-
- TU_VERIFY(usbtmc_state.state == STATE_TX_REQUESTED);
- usbtmc_msg_dev_dep_msg_in_header_t *hdr = (usbtmc_msg_dev_dep_msg_in_header_t*)usbtmc_state.ep_bulk_in_buf;
- tu_varclr(hdr);
- hdr->header.MsgID = USBTMC_MSGID_DEV_DEP_MSG_IN;
- hdr->header.bTag = usbtmc_state.lastBulkInTag;
- hdr->header.bTagInverse = (uint8_t)~(usbtmc_state.lastBulkInTag);
- hdr->TransferSize = len;
- hdr->bmTransferAttributes.EOM = endOfMessage;
- hdr->bmTransferAttributes.UsingTermChar = usingTermChar;
-
- // Copy in the header
- const size_t headerLen = sizeof(*hdr);
- const size_t dataLen = ((headerLen + hdr->TransferSize) <= txBufLen) ?
- len : (txBufLen - headerLen);
- const size_t packetLen = headerLen + dataLen;
-
- memcpy((uint8_t*)(usbtmc_state.ep_bulk_in_buf) + headerLen, data, dataLen);
- usbtmc_state.transfer_size_remaining = len - dataLen;
- usbtmc_state.transfer_size_sent = dataLen;
- usbtmc_state.devInBuffer = (uint8_t*)data + (dataLen);
-
- bool stateChanged =
- atomicChangeState(STATE_TX_REQUESTED, (packetLen >= txBufLen) ? STATE_TX_INITIATED : STATE_TX_SHORTED);
- TU_VERIFY(stateChanged);
- TU_VERIFY(usbd_edpt_xfer(usbtmc_state.rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf, (uint16_t)packetLen));
- return true;
-}
-
-void usbtmcd_init_cb(void)
-{
- usbtmc_state.capabilities = tud_usbtmc_get_capabilities_cb();
-#ifndef NDEBUG
-# if CFG_TUD_USBTMC_ENABLE_488
- if(usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger)
- TU_ASSERT(&tud_usbtmc_msg_trigger_cb != NULL,);
- // Per USB488 spec: table 8
- TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.listenOnly,);
- TU_ASSERT(!usbtmc_state.capabilities->bmIntfcCapabilities.talkOnly,);
-# endif
- if(usbtmc_state.capabilities->bmIntfcCapabilities.supportsIndicatorPulse)
- TU_ASSERT(&tud_usbtmc_indicator_pulse_cb != NULL,);
-#endif
-
- usbtmcLock = osal_mutex_create(&usbtmcLockBuffer);
-}
-
-uint16_t usbtmcd_open_cb(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- (void)rhport;
-
- uint16_t drv_len;
- uint8_t const * p_desc;
- uint8_t found_endpoints = 0;
-
- TU_VERIFY(itf_desc->bInterfaceClass == TUD_USBTMC_APP_CLASS , 0);
- TU_VERIFY(itf_desc->bInterfaceSubClass == TUD_USBTMC_APP_SUBCLASS, 0);
-
-#ifndef NDEBUG
- // Only 2 or 3 endpoints are allowed for USBTMC.
- TU_ASSERT((itf_desc->bNumEndpoints == 2) || (itf_desc->bNumEndpoints ==3), 0);
-#endif
-
- TU_ASSERT(usbtmc_state.state == STATE_CLOSED, 0);
-
- // Interface
- drv_len = 0u;
- p_desc = (uint8_t const *) itf_desc;
-
- usbtmc_state.itf_id = itf_desc->bInterfaceNumber;
- usbtmc_state.rhport = rhport;
-
- while (found_endpoints < itf_desc->bNumEndpoints && drv_len <= max_len)
- {
- if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
- {
- tusb_desc_endpoint_t const *ep_desc = (tusb_desc_endpoint_t const *)p_desc;
- switch(ep_desc->bmAttributes.xfer) {
- case TUSB_XFER_BULK:
- TU_ASSERT(ep_desc->wMaxPacketSize.size == USBTMCD_MAX_PACKET_SIZE, 0);
- if (tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN)
- {
- usbtmc_state.ep_bulk_in = ep_desc->bEndpointAddress;
- } else {
- usbtmc_state.ep_bulk_out = ep_desc->bEndpointAddress;
- }
-
- break;
- case TUSB_XFER_INTERRUPT:
-#ifndef NDEBUG
- TU_ASSERT(tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN, 0);
- TU_ASSERT(usbtmc_state.ep_int_in == 0, 0);
-#endif
- usbtmc_state.ep_int_in = ep_desc->bEndpointAddress;
- break;
- default:
- TU_ASSERT(false, 0);
- }
- TU_ASSERT( usbd_edpt_open(rhport, ep_desc), 0);
- found_endpoints++;
- }
-
- drv_len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-
- // bulk endpoints are required, but interrupt IN is optional
-#ifndef NDEBUG
- TU_ASSERT(usbtmc_state.ep_bulk_in != 0, 0);
- TU_ASSERT(usbtmc_state.ep_bulk_out != 0, 0);
- if (itf_desc->bNumEndpoints == 2)
- {
- TU_ASSERT(usbtmc_state.ep_int_in == 0, 0);
- }
- else if (itf_desc->bNumEndpoints == 3)
- {
- TU_ASSERT(usbtmc_state.ep_int_in != 0, 0);
- }
-#if (CFG_TUD_USBTMC_ENABLE_488)
- if(usbtmc_state.capabilities->bmIntfcCapabilities488.is488_2 ||
- usbtmc_state.capabilities->bmDevCapabilities488.SR1)
- {
- TU_ASSERT(usbtmc_state.ep_int_in != 0, 0);
- }
-#endif
-#endif
- atomicChangeState(STATE_CLOSED, STATE_NAK);
- tud_usbtmc_open_cb(itf_desc->iInterface);
-
- return drv_len;
-}
-// Tell USBTMC class to set its bulk-in EP to ACK so that it can
-// receive USBTMC commands.
-// Returns false if it was already in an ACK state or is busy
-// processing a command (such as a clear). Returns true if it was
-// in the NAK state and successfully transitioned to the ACK wait
-// state.
-bool tud_usbtmc_start_bus_read()
-{
- usbtmcd_state_enum oldState = usbtmc_state.state;
- switch(oldState)
- {
- // These may transition to IDLE
- case STATE_NAK:
- case STATE_ABORTING_BULK_IN_ABORTED:
- TU_VERIFY(atomicChangeState(oldState, STATE_IDLE));
- break;
- // When receiving, let it remain receiving
- case STATE_RCV:
- break;
- default:
- TU_VERIFY(false);
- }
- TU_VERIFY(usbd_edpt_xfer(usbtmc_state.rhport, usbtmc_state.ep_bulk_out, usbtmc_state.ep_bulk_out_buf, 64));
- return true;
-}
-
-void usbtmcd_reset_cb(uint8_t rhport)
-{
- (void)rhport;
- usbtmc_capabilities_specific_t const * capabilities = tud_usbtmc_get_capabilities_cb();
-
- criticalEnter();
- tu_varclr(&usbtmc_state);
- usbtmc_state.capabilities = capabilities;
- usbtmc_state.itf_id = 0xFFu;
- criticalLeave();
-}
-
-static bool handle_devMsgOutStart(uint8_t rhport, void *data, size_t len)
-{
- (void)rhport;
- // return true upon failure, as we can assume error is being handled elsewhere.
- TU_VERIFY(atomicChangeState(STATE_IDLE, STATE_RCV), true);
- usbtmc_state.transfer_size_sent = 0u;
-
- // must be a header, should have been confirmed before calling here.
- usbtmc_msg_request_dev_dep_out *msg = (usbtmc_msg_request_dev_dep_out*)data;
- usbtmc_state.transfer_size_remaining = msg->TransferSize;
- TU_VERIFY(tud_usbtmc_msgBulkOut_start_cb(msg));
-
- TU_VERIFY(handle_devMsgOut(rhport, (uint8_t*)data + sizeof(*msg), len - sizeof(*msg), len));
- usbtmc_state.lastBulkOutTag = msg->header.bTag;
- return true;
-}
-
-static bool handle_devMsgOut(uint8_t rhport, void *data, size_t len, size_t packetLen)
-{
- (void)rhport;
- // return true upon failure, as we can assume error is being handled elsewhere.
- TU_VERIFY(usbtmc_state.state == STATE_RCV,true);
-
- bool shortPacket = (packetLen < USBTMCD_MAX_PACKET_SIZE);
-
- // Packet is to be considered complete when we get enough data or at a short packet.
- bool atEnd = false;
- if(len >= usbtmc_state.transfer_size_remaining || shortPacket)
- {
- atEnd = true;
- TU_VERIFY(atomicChangeState(STATE_RCV, STATE_NAK));
- }
-
- len = tu_min32(len, usbtmc_state.transfer_size_remaining);
-
- usbtmc_state.transfer_size_remaining -= len;
- usbtmc_state.transfer_size_sent += len;
-
- // App may (should?) call the wait_for_bus() command at this point
- if(!tud_usbtmc_msg_data_cb(data, len, atEnd))
- {
- // TODO: Go to an error state upon failure other than just stalling the EP?
- return false;
- }
-
-
- return true;
-}
-
-static bool handle_devMsgIn(void *data, size_t len)
-{
- TU_VERIFY(len == sizeof(usbtmc_msg_request_dev_dep_in));
- usbtmc_msg_request_dev_dep_in *msg = (usbtmc_msg_request_dev_dep_in*)data;
- bool stateChanged = atomicChangeState(STATE_IDLE, STATE_TX_REQUESTED);
- TU_VERIFY(stateChanged);
- usbtmc_state.lastBulkInTag = msg->header.bTag;
- usbtmc_state.transfer_size_remaining = msg->TransferSize;
- usbtmc_state.transfer_size_sent = 0u;
-
- termCharRequested = msg->bmTransferAttributes.TermCharEnabled;
- termChar = msg->TermChar;
-
- if(termCharRequested)
- TU_VERIFY(usbtmc_state.capabilities->bmDevCapabilities.canEndBulkInOnTermChar);
-
- TU_VERIFY(tud_usbtmc_msgBulkIn_request_cb(msg));
- return true;
-}
-
-bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- TU_VERIFY(result == XFER_RESULT_SUCCESS);
- //uart_tx_str_sync("TMC XFER CB\r\n");
- if(usbtmc_state.state == STATE_CLEARING) {
- return true; /* I think we can ignore everything here */
- }
-
- if(ep_addr == usbtmc_state.ep_bulk_out)
- {
- usbtmc_msg_generic_t *msg = NULL;
-
- switch(usbtmc_state.state)
- {
- case STATE_IDLE:
- TU_VERIFY(xferred_bytes >= sizeof(usbtmc_msg_generic_t));
- msg = (usbtmc_msg_generic_t*)(usbtmc_state.ep_bulk_out_buf);
- uint8_t invInvTag = (uint8_t)~(msg->header.bTagInverse);
- TU_VERIFY(msg->header.bTag == invInvTag);
- TU_VERIFY(msg->header.bTag != 0x00);
-
- switch(msg->header.MsgID) {
- case USBTMC_MSGID_DEV_DEP_MSG_OUT:
- if(!handle_devMsgOutStart(rhport, msg, xferred_bytes))
- {
- usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
- TU_VERIFY(false);
- }
- break;
-
- case USBTMC_MSGID_DEV_DEP_MSG_IN:
- TU_VERIFY(handle_devMsgIn(msg, xferred_bytes));
- break;
-
-#if (CFG_TUD_USBTMC_ENABLE_488)
- case USBTMC_MSGID_USB488_TRIGGER:
- // Spec says we halt the EP if we didn't declare we support it.
- TU_VERIFY(usbtmc_state.capabilities->bmIntfcCapabilities488.supportsTrigger);
- TU_VERIFY(tud_usbtmc_msg_trigger_cb(msg));
-
- break;
-#endif
- case USBTMC_MSGID_VENDOR_SPECIFIC_MSG_OUT:
- case USBTMC_MSGID_VENDOR_SPECIFIC_IN:
- default:
- usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
- TU_VERIFY(false);
- return false;
- }
- return true;
-
- case STATE_RCV:
- if(!handle_devMsgOut(rhport, usbtmc_state.ep_bulk_out_buf, xferred_bytes, xferred_bytes))
- {
- usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
- TU_VERIFY(false);
- }
- return true;
-
- case STATE_ABORTING_BULK_OUT:
- TU_VERIFY(false);
- return false; // Should be stalled by now, shouldn't have received a packet.
- case STATE_TX_REQUESTED:
- case STATE_TX_INITIATED:
- case STATE_ABORTING_BULK_IN:
- case STATE_ABORTING_BULK_IN_SHORTED:
- case STATE_ABORTING_BULK_IN_ABORTED:
- default:
-
- TU_VERIFY(false);
- }
- }
- else if(ep_addr == usbtmc_state.ep_bulk_in)
- {
- switch(usbtmc_state.state) {
- case STATE_TX_SHORTED:
- TU_VERIFY(atomicChangeState(STATE_TX_SHORTED, STATE_NAK));
- TU_VERIFY(tud_usbtmc_msgBulkIn_complete_cb());
- break;
-
- case STATE_TX_INITIATED:
- if(usbtmc_state.transfer_size_remaining >=sizeof(usbtmc_state.ep_bulk_in_buf))
- {
- // FIXME! This removes const below!
- TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in,
- (void*)usbtmc_state.devInBuffer,sizeof(usbtmc_state.ep_bulk_in_buf)));
- usbtmc_state.devInBuffer += sizeof(usbtmc_state.ep_bulk_in_buf);
- usbtmc_state.transfer_size_remaining -= sizeof(usbtmc_state.ep_bulk_in_buf);
- usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.ep_bulk_in_buf);
- }
- else // last packet
- {
- size_t packetLen = usbtmc_state.transfer_size_remaining;
- memcpy(usbtmc_state.ep_bulk_in_buf, usbtmc_state.devInBuffer, usbtmc_state.transfer_size_remaining);
- usbtmc_state.transfer_size_sent += sizeof(usbtmc_state.transfer_size_remaining);
- usbtmc_state.transfer_size_remaining = 0;
- usbtmc_state.devInBuffer = NULL;
- TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)packetLen));
- if(((packetLen % USBTMCD_MAX_PACKET_SIZE) != 0) || (packetLen == 0 ))
- {
- usbtmc_state.state = STATE_TX_SHORTED;
- }
- }
- return true;
- case STATE_ABORTING_BULK_IN:
- // need to send short packet (ZLP?)
- TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)0u));
- usbtmc_state.state = STATE_ABORTING_BULK_IN_SHORTED;
- return true;
- case STATE_ABORTING_BULK_IN_SHORTED:
- /* Done. :)*/
- usbtmc_state.state = STATE_ABORTING_BULK_IN_ABORTED;
- return true;
- default:
- TU_ASSERT(false);
- return false;
- }
- }
- else if (ep_addr == usbtmc_state.ep_int_in) {
- // Good?
- return true;
- }
- return false;
-}
-
-// Invoked when a control transfer occurred on an interface of this class
-// Driver response accordingly to the request and the transfer stage (setup/data/ack)
-// return false to stall control endpoint (e.g unsupported request)
-bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
-{
- // nothing to do with DATA and ACK stage
- if ( stage != CONTROL_STAGE_SETUP ) return true;
-
- uint8_t tmcStatusCode = USBTMC_STATUS_FAILED;
-#if (CFG_TUD_USBTMC_ENABLE_488)
- uint8_t bTag;
-#endif
-
- if((request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD) &&
- (request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_ENDPOINT) &&
- (request->bRequest == TUSB_REQ_CLEAR_FEATURE) &&
- (request->wValue == TUSB_REQ_FEATURE_EDPT_HALT))
- {
- uint32_t ep_addr = (request->wIndex);
-
- if(ep_addr == usbtmc_state.ep_bulk_out)
- {
- criticalEnter();
- usbtmc_state.state = STATE_NAK; // USBD core has placed EP in NAK state for us
- criticalLeave();
- tud_usbtmc_bulkOut_clearFeature_cb();
- }
- else if (ep_addr == usbtmc_state.ep_bulk_in)
- {
- tud_usbtmc_bulkIn_clearFeature_cb();
- }
- else
- {
- return false;
- }
- return true;
- }
-
- // Otherwise, we only handle class requests.
- if(request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS)
- {
- return false;
- }
-
- // Verification that we own the interface is unneeded since it's been routed to us specifically.
-
- switch(request->bRequest)
- {
- // USBTMC required requests
- case USBTMC_bREQUEST_INITIATE_ABORT_BULK_OUT:
- {
- usbtmc_initiate_abort_rsp_t rsp = {
- .bTag = usbtmc_state.lastBulkOutTag,
- };
- TU_VERIFY(request->bmRequestType == 0xA2); // in,class,interface
- TU_VERIFY(request->wLength == sizeof(rsp));
- TU_VERIFY(request->wIndex == usbtmc_state.ep_bulk_out);
-
- // wValue is the requested bTag to abort
- if(usbtmc_state.state != STATE_RCV)
- {
- rsp.USBTMC_status = USBTMC_STATUS_FAILED;
- }
- else if(usbtmc_state.lastBulkOutTag == (request->wValue & 0x7Fu))
- {
- rsp.USBTMC_status = USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
- }
- else
- {
- rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
- // Check if we've queued a short packet
- criticalEnter();
- usbtmc_state.state = STATE_ABORTING_BULK_OUT;
- criticalLeave();
- TU_VERIFY(tud_usbtmc_initiate_abort_bulk_out_cb(&(rsp.USBTMC_status)));
- usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
- }
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp,sizeof(rsp)));
- return true;
- }
-
- case USBTMC_bREQUEST_CHECK_ABORT_BULK_OUT_STATUS:
- {
- usbtmc_check_abort_bulk_rsp_t rsp = {
- .USBTMC_status = USBTMC_STATUS_SUCCESS,
- .NBYTES_RXD_TXD = usbtmc_state.transfer_size_sent
- };
- TU_VERIFY(request->bmRequestType == 0xA2); // in,class,EP
- TU_VERIFY(request->wLength == sizeof(rsp));
- TU_VERIFY(request->wIndex == usbtmc_state.ep_bulk_out);
- TU_VERIFY(tud_usbtmc_check_abort_bulk_out_cb(&rsp));
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp,sizeof(rsp)));
- return true;
- }
-
- case USBTMC_bREQUEST_INITIATE_ABORT_BULK_IN:
- {
- usbtmc_initiate_abort_rsp_t rsp = {
- .bTag = usbtmc_state.lastBulkInTag,
- };
- TU_VERIFY(request->bmRequestType == 0xA2); // in,class,interface
- TU_VERIFY(request->wLength == sizeof(rsp));
- TU_VERIFY(request->wIndex == usbtmc_state.ep_bulk_in);
- // wValue is the requested bTag to abort
- if((usbtmc_state.state == STATE_TX_REQUESTED || usbtmc_state.state == STATE_TX_INITIATED) &&
- usbtmc_state.lastBulkInTag == (request->wValue & 0x7Fu))
- {
- rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
- usbtmc_state.transfer_size_remaining = 0u;
- // Check if we've queued a short packet
- criticalEnter();
- usbtmc_state.state = ((usbtmc_state.transfer_size_sent % USBTMCD_MAX_PACKET_SIZE) == 0) ?
- STATE_ABORTING_BULK_IN : STATE_ABORTING_BULK_IN_SHORTED;
- criticalLeave();
- if(usbtmc_state.transfer_size_sent == 0)
- {
- // Send short packet, nothing is in the buffer yet
- TU_VERIFY( usbd_edpt_xfer(rhport, usbtmc_state.ep_bulk_in, usbtmc_state.ep_bulk_in_buf,(uint16_t)0u));
- usbtmc_state.state = STATE_ABORTING_BULK_IN_SHORTED;
- }
- TU_VERIFY(tud_usbtmc_initiate_abort_bulk_in_cb(&(rsp.USBTMC_status)));
- }
- else if((usbtmc_state.state == STATE_TX_REQUESTED || usbtmc_state.state == STATE_TX_INITIATED))
- { // FIXME: Unsure how to check if the OUT endpoint fifo is non-empty....
- rsp.USBTMC_status = USBTMC_STATUS_TRANSFER_NOT_IN_PROGRESS;
- }
- else
- {
- rsp.USBTMC_status = USBTMC_STATUS_FAILED;
- }
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp,sizeof(rsp)));
- return true;
- }
-
- case USBTMC_bREQUEST_CHECK_ABORT_BULK_IN_STATUS:
- {
- TU_VERIFY(request->bmRequestType == 0xA2); // in,class,EP
- TU_VERIFY(request->wLength == 8u);
-
- usbtmc_check_abort_bulk_rsp_t rsp =
- {
- .USBTMC_status = USBTMC_STATUS_FAILED,
- .bmAbortBulkIn =
- {
- .BulkInFifoBytes = (usbtmc_state.state != STATE_ABORTING_BULK_IN_ABORTED)
- },
- .NBYTES_RXD_TXD = usbtmc_state.transfer_size_sent,
- };
- TU_VERIFY(tud_usbtmc_check_abort_bulk_in_cb(&rsp));
- criticalEnter();
- switch(usbtmc_state.state)
- {
- case STATE_ABORTING_BULK_IN_ABORTED:
- rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
- usbtmc_state.state = STATE_IDLE;
- break;
- case STATE_ABORTING_BULK_IN:
- case STATE_ABORTING_BULK_OUT:
- rsp.USBTMC_status = USBTMC_STATUS_PENDING;
- break;
- default:
- break;
- }
- criticalLeave();
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp,sizeof(rsp)));
-
- return true;
- }
-
- case USBTMC_bREQUEST_INITIATE_CLEAR:
- {
- TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
- TU_VERIFY(request->wLength == sizeof(tmcStatusCode));
- // After receiving an INITIATE_CLEAR request, the device must Halt the Bulk-OUT endpoint, queue the
- // control endpoint response shown in Table 31, and clear all input buffers and output buffers.
- usbd_edpt_stall(rhport, usbtmc_state.ep_bulk_out);
- usbtmc_state.transfer_size_remaining = 0;
- criticalEnter();
- usbtmc_state.state = STATE_CLEARING;
- criticalLeave();
- TU_VERIFY(tud_usbtmc_initiate_clear_cb(&tmcStatusCode));
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&tmcStatusCode,sizeof(tmcStatusCode)));
- return true;
- }
-
- case USBTMC_bREQUEST_CHECK_CLEAR_STATUS:
- {
- TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
- usbtmc_get_clear_status_rsp_t clearStatusRsp = {0};
- TU_VERIFY(request->wLength == sizeof(clearStatusRsp));
-
- if(usbd_edpt_busy(rhport, usbtmc_state.ep_bulk_in))
- {
- // Stuff stuck in TX buffer?
- clearStatusRsp.bmClear.BulkInFifoBytes = 1;
- clearStatusRsp.USBTMC_status = USBTMC_STATUS_PENDING;
- }
- else
- {
- // Let app check if it's clear
- TU_VERIFY(tud_usbtmc_check_clear_cb(&clearStatusRsp));
- }
- if(clearStatusRsp.USBTMC_status == USBTMC_STATUS_SUCCESS)
- {
- criticalEnter();
- usbtmc_state.state = STATE_IDLE;
- criticalLeave();
- }
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&clearStatusRsp,sizeof(clearStatusRsp)));
- return true;
- }
-
- case USBTMC_bREQUEST_GET_CAPABILITIES:
- {
- TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
- TU_VERIFY(request->wLength == sizeof(*(usbtmc_state.capabilities)));
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)usbtmc_state.capabilities, sizeof(*usbtmc_state.capabilities)));
- return true;
- }
- // USBTMC Optional Requests
-
- case USBTMC_bREQUEST_INDICATOR_PULSE: // Optional
- {
- TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
- TU_VERIFY(request->wLength == sizeof(tmcStatusCode));
- TU_VERIFY(usbtmc_state.capabilities->bmIntfcCapabilities.supportsIndicatorPulse);
- TU_VERIFY(tud_usbtmc_indicator_pulse_cb(request, &tmcStatusCode));
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&tmcStatusCode, sizeof(tmcStatusCode)));
- return true;
- }
-#if (CFG_TUD_USBTMC_ENABLE_488)
-
- // USB488 required requests
- case USB488_bREQUEST_READ_STATUS_BYTE:
- {
- usbtmc_read_stb_rsp_488_t rsp;
- TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
- TU_VERIFY(request->wLength == sizeof(rsp)); // in,class,interface
-
- bTag = request->wValue & 0x7F;
- TU_VERIFY(request->bmRequestType == 0xA1);
- TU_VERIFY((request->wValue & (~0x7F)) == 0u); // Other bits are required to be zero
- TU_VERIFY(bTag >= 0x02 && bTag <= 127);
- TU_VERIFY(request->wIndex == usbtmc_state.itf_id);
- TU_VERIFY(request->wLength == 0x0003);
- rsp.bTag = (uint8_t)bTag;
- if(usbtmc_state.ep_int_in != 0)
- {
- rsp.USBTMC_status = USBTMC_STATUS_SUCCESS;
- rsp.statusByte = 0x00; // Use interrupt endpoint, instead.
-
- usbtmc_read_stb_interrupt_488_t intMsg =
- {
- .bNotify1 = {
- .one = 1,
- .bTag = bTag & 0x7Fu,
- },
- .StatusByte = tud_usbtmc_get_stb_cb(&(rsp.USBTMC_status))
- };
- usbd_edpt_xfer(rhport, usbtmc_state.ep_int_in, (void*)&intMsg, sizeof(intMsg));
- }
- else
- {
- rsp.statusByte = tud_usbtmc_get_stb_cb(&(rsp.USBTMC_status));
- }
- TU_VERIFY(tud_control_xfer(rhport, request, (void*)&rsp, sizeof(rsp)));
- return true;
- }
- // USB488 optional requests
- case USB488_bREQUEST_REN_CONTROL:
- case USB488_bREQUEST_GO_TO_LOCAL:
- case USB488_bREQUEST_LOCAL_LOCKOUT:
- {
- TU_VERIFY(request->bmRequestType == 0xA1); // in,class,interface
- TU_VERIFY(false);
- return false;
- }
-#endif
-
- default:
- TU_VERIFY(false);
- return false;
- }
- TU_VERIFY(false);
-}
-
-#endif /* CFG_TUD_TSMC */
diff --git a/tinyusb/src/class/usbtmc/usbtmc_device.h b/tinyusb/src/class/usbtmc/usbtmc_device.h
deleted file mode 100755
index 62280031..00000000
--- a/tinyusb/src/class/usbtmc/usbtmc_device.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * usbtmc_device.h
- *
- * Created on: Sep 10, 2019
- * Author: nconrad
- */
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 N Conrad
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-
-#ifndef CLASS_USBTMC_USBTMC_DEVICE_H_
-#define CLASS_USBTMC_USBTMC_DEVICE_H_
-
-#include "usbtmc.h"
-
-// Enable 488 mode by default
-#if !defined(CFG_TUD_USBTMC_ENABLE_488)
-#define CFG_TUD_USBTMC_ENABLE_488 (1)
-#endif
-
-// USB spec says that full-speed must be 8,16,32, or 64.
-// However, this driver implementation requires it to be >=32
-#define USBTMCD_MAX_PACKET_SIZE (64u)
-
-/***********************************************
- * Functions to be implemeted by the class implementation
- */
-
-// In order to proceed, app must call call tud_usbtmc_start_bus_read(rhport) during or soon after:
-// * tud_usbtmc_open_cb
-// * tud_usbtmc_msg_data_cb
-// * tud_usbtmc_msgBulkIn_complete_cb
-// * tud_usbtmc_msg_trigger_cb
-// * (successful) tud_usbtmc_check_abort_bulk_out_cb
-// * (successful) tud_usbtmc_check_abort_bulk_in_cb
-// * (successful) tud_usmtmc_bulkOut_clearFeature_cb
-
-#if (CFG_TUD_USBTMC_ENABLE_488)
-usbtmc_response_capabilities_488_t const * tud_usbtmc_get_capabilities_cb(void);
-#else
-usbtmc_response_capabilities_t const * tud_usbtmc_get_capabilities_cb(void);
-#endif
-
-void tud_usbtmc_open_cb(uint8_t interface_id);
-
-bool tud_usbtmc_msgBulkOut_start_cb(usbtmc_msg_request_dev_dep_out const * msgHeader);
-// transfer_complete does not imply that a message is complete.
-bool tud_usbtmc_msg_data_cb( void *data, size_t len, bool transfer_complete);
-void tud_usbtmc_bulkOut_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer
-
-bool tud_usbtmc_msgBulkIn_request_cb(usbtmc_msg_request_dev_dep_in const * request);
-bool tud_usbtmc_msgBulkIn_complete_cb(void);
-void tud_usbtmc_bulkIn_clearFeature_cb(void); // Notice to clear and abort the pending BULK out transfer
-
-bool tud_usbtmc_initiate_abort_bulk_in_cb(uint8_t *tmcResult);
-bool tud_usbtmc_initiate_abort_bulk_out_cb(uint8_t *tmcResult);
-bool tud_usbtmc_initiate_clear_cb(uint8_t *tmcResult);
-
-bool tud_usbtmc_check_abort_bulk_in_cb(usbtmc_check_abort_bulk_rsp_t *rsp);
-bool tud_usbtmc_check_abort_bulk_out_cb(usbtmc_check_abort_bulk_rsp_t *rsp);
-bool tud_usbtmc_check_clear_cb(usbtmc_get_clear_status_rsp_t *rsp);
-
-// Indicator pulse should be 0.5 to 1.0 seconds long
-TU_ATTR_WEAK bool tud_usbtmc_indicator_pulse_cb(tusb_control_request_t const * msg, uint8_t *tmcResult);
-
-#if (CFG_TUD_USBTMC_ENABLE_488)
-uint8_t tud_usbtmc_get_stb_cb(uint8_t *tmcResult);
-TU_ATTR_WEAK bool tud_usbtmc_msg_trigger_cb(usbtmc_msg_generic_t* msg);
-//TU_ATTR_WEAK bool tud_usbtmc_app_go_to_local_cb();
-#endif
-
-/*******************************************
- * Called from app
- *
- * We keep a reference to the buffer, so it MUST not change until the app is
- * notified that the transfer is complete.
- ******************************************/
-
-bool tud_usbtmc_transmit_dev_msg_data(
- const void * data, size_t len,
- bool endOfMessage, bool usingTermChar);
-
-bool tud_usbtmc_start_bus_read(void);
-
-
-/* "callbacks" from USB device core */
-
-uint16_t usbtmcd_open_cb(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-void usbtmcd_reset_cb(uint8_t rhport);
-bool usbtmcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
-bool usbtmcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
-void usbtmcd_init_cb(void);
-
-/************************************************************
- * USBTMC Descriptor Templates
- *************************************************************/
-
-
-#endif /* CLASS_USBTMC_USBTMC_DEVICE_H_ */
diff --git a/tinyusb/src/class/vendor/vendor_device.c b/tinyusb/src/class/vendor/vendor_device.c
deleted file mode 100755
index 8c59b4ea..00000000
--- a/tinyusb/src/class/vendor/vendor_device.c
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_VENDOR)
-
-#include "device/usbd.h"
-#include "device/usbd_pvt.h"
-
-#include "vendor_device.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-typedef struct
-{
- uint8_t itf_num;
- uint8_t ep_in;
- uint8_t ep_out;
-
- /*------------- From this point, data is not cleared by bus reset -------------*/
- tu_fifo_t rx_ff;
- tu_fifo_t tx_ff;
-
- uint8_t rx_ff_buf[CFG_TUD_VENDOR_RX_BUFSIZE];
- uint8_t tx_ff_buf[CFG_TUD_VENDOR_TX_BUFSIZE];
-
-#if CFG_FIFO_MUTEX
- osal_mutex_def_t rx_ff_mutex;
- osal_mutex_def_t tx_ff_mutex;
-#endif
-
- // Endpoint Transfer buffer
- CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_VENDOR_EPSIZE];
- CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_VENDOR_EPSIZE];
-} vendord_interface_t;
-
-CFG_TUSB_MEM_SECTION static vendord_interface_t _vendord_itf[CFG_TUD_VENDOR];
-
-#define ITF_MEM_RESET_SIZE offsetof(vendord_interface_t, rx_ff)
-
-
-bool tud_vendor_n_mounted (uint8_t itf)
-{
- return _vendord_itf[itf].ep_in && _vendord_itf[itf].ep_out;
-}
-
-uint32_t tud_vendor_n_available (uint8_t itf)
-{
- return tu_fifo_count(&_vendord_itf[itf].rx_ff);
-}
-
-bool tud_vendor_n_peek(uint8_t itf, uint8_t* u8)
-{
- return tu_fifo_peek(&_vendord_itf[itf].rx_ff, u8);
-}
-
-//--------------------------------------------------------------------+
-// Read API
-//--------------------------------------------------------------------+
-static void _prep_out_transaction (vendord_interface_t* p_itf)
-{
- // skip if previous transfer not complete
- if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_itf->ep_out) ) return;
-
- // Prepare for incoming data but only allow what we can store in the ring buffer.
- uint16_t max_read = tu_fifo_remaining(&p_itf->rx_ff);
- if ( max_read >= CFG_TUD_VENDOR_EPSIZE )
- {
- usbd_edpt_xfer(TUD_OPT_RHPORT, p_itf->ep_out, p_itf->epout_buf, CFG_TUD_VENDOR_EPSIZE);
- }
-}
-
-uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize)
-{
- vendord_interface_t* p_itf = &_vendord_itf[itf];
- uint32_t num_read = tu_fifo_read_n(&p_itf->rx_ff, buffer, bufsize);
- _prep_out_transaction(p_itf);
- return num_read;
-}
-
-void tud_vendor_n_read_flush (uint8_t itf)
-{
- vendord_interface_t* p_itf = &_vendord_itf[itf];
- tu_fifo_clear(&p_itf->rx_ff);
- _prep_out_transaction(p_itf);
-}
-
-//--------------------------------------------------------------------+
-// Write API
-//--------------------------------------------------------------------+
-static bool maybe_transmit(vendord_interface_t* p_itf)
-{
- // skip if previous transfer not complete
- TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_itf->ep_in) );
-
- uint16_t count = tu_fifo_read_n(&p_itf->tx_ff, p_itf->epin_buf, CFG_TUD_VENDOR_EPSIZE);
- if (count > 0)
- {
- TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, p_itf->ep_in, p_itf->epin_buf, count) );
- }
- return true;
-}
-
-uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize)
-{
- vendord_interface_t* p_itf = &_vendord_itf[itf];
- uint16_t ret = tu_fifo_write_n(&p_itf->tx_ff, buffer, bufsize);
- maybe_transmit(p_itf);
- return ret;
-}
-
-uint32_t tud_vendor_n_write_available (uint8_t itf)
-{
- return tu_fifo_remaining(&_vendord_itf[itf].tx_ff);
-}
-
-//--------------------------------------------------------------------+
-// USBD Driver API
-//--------------------------------------------------------------------+
-void vendord_init(void)
-{
- tu_memclr(_vendord_itf, sizeof(_vendord_itf));
-
- for(uint8_t i=0; i<CFG_TUD_VENDOR; i++)
- {
- vendord_interface_t* p_itf = &_vendord_itf[i];
-
- // config fifo
- tu_fifo_config(&p_itf->rx_ff, p_itf->rx_ff_buf, CFG_TUD_VENDOR_RX_BUFSIZE, 1, false);
- tu_fifo_config(&p_itf->tx_ff, p_itf->tx_ff_buf, CFG_TUD_VENDOR_TX_BUFSIZE, 1, false);
-
-#if CFG_FIFO_MUTEX
- tu_fifo_config_mutex(&p_itf->rx_ff, NULL, osal_mutex_create(&p_itf->rx_ff_mutex));
- tu_fifo_config_mutex(&p_itf->tx_ff, osal_mutex_create(&p_itf->tx_ff_mutex), NULL);
-#endif
- }
-}
-
-void vendord_reset(uint8_t rhport)
-{
- (void) rhport;
-
- for(uint8_t i=0; i<CFG_TUD_VENDOR; i++)
- {
- vendord_interface_t* p_itf = &_vendord_itf[i];
-
- tu_memclr(p_itf, ITF_MEM_RESET_SIZE);
- tu_fifo_clear(&p_itf->rx_ff);
- tu_fifo_clear(&p_itf->tx_ff);
- }
-}
-
-uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len)
-{
- TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == itf_desc->bInterfaceClass, 0);
-
- uint16_t const drv_len = sizeof(tusb_desc_interface_t) + itf_desc->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
- TU_VERIFY(max_len >= drv_len, 0);
-
- // Find available interface
- vendord_interface_t* p_vendor = NULL;
- for(uint8_t i=0; i<CFG_TUD_VENDOR; i++)
- {
- if ( _vendord_itf[i].ep_in == 0 && _vendord_itf[i].ep_out == 0 )
- {
- p_vendor = &_vendord_itf[i];
- break;
- }
- }
- TU_VERIFY(p_vendor, 0);
-
- // Open endpoint pair with usbd helper
- TU_ASSERT(usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_vendor->ep_out, &p_vendor->ep_in), 0);
-
- p_vendor->itf_num = itf_desc->bInterfaceNumber;
-
- // Prepare for incoming data
- if ( !usbd_edpt_xfer(rhport, p_vendor->ep_out, p_vendor->epout_buf, sizeof(p_vendor->epout_buf)) )
- {
- TU_LOG_FAILED();
- TU_BREAKPOINT();
- }
-
- maybe_transmit(p_vendor);
-
- return drv_len;
-}
-
-bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
-{
- (void) rhport;
- (void) result;
-
- uint8_t itf = 0;
- vendord_interface_t* p_itf = _vendord_itf;
-
- for ( ; ; itf++, p_itf++)
- {
- if (itf >= TU_ARRAY_SIZE(_vendord_itf)) return false;
-
- if ( ( ep_addr == p_itf->ep_out ) || ( ep_addr == p_itf->ep_in ) ) break;
- }
-
- if ( ep_addr == p_itf->ep_out )
- {
- // Receive new data
- tu_fifo_write_n(&p_itf->rx_ff, p_itf->epout_buf, xferred_bytes);
-
- // Invoked callback if any
- if (tud_vendor_rx_cb) tud_vendor_rx_cb(itf);
-
- _prep_out_transaction(p_itf);
- }
- else if ( ep_addr == p_itf->ep_in )
- {
- // Send complete, try to send more if possible
- maybe_transmit(p_itf);
- }
-
- return true;
-}
-
-#endif
diff --git a/tinyusb/src/class/vendor/vendor_device.h b/tinyusb/src/class/vendor/vendor_device.h
deleted file mode 100755
index 844693c6..00000000
--- a/tinyusb/src/class/vendor/vendor_device.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_VENDOR_DEVICE_H_
-#define _TUSB_VENDOR_DEVICE_H_
-
-#include "common/tusb_common.h"
-
-#ifndef CFG_TUD_VENDOR_EPSIZE
-#define CFG_TUD_VENDOR_EPSIZE 64
-#endif
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// Application API (Multiple Interfaces)
-//--------------------------------------------------------------------+
-bool tud_vendor_n_mounted (uint8_t itf);
-
-uint32_t tud_vendor_n_available (uint8_t itf);
-uint32_t tud_vendor_n_read (uint8_t itf, void* buffer, uint32_t bufsize);
-bool tud_vendor_n_peek (uint8_t itf, uint8_t* u8);
-void tud_vendor_n_read_flush (uint8_t itf);
-
-uint32_t tud_vendor_n_write (uint8_t itf, void const* buffer, uint32_t bufsize);
-uint32_t tud_vendor_n_write_available (uint8_t itf);
-
-static inline
-uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
-
-//--------------------------------------------------------------------+
-// Application API (Single Port)
-//--------------------------------------------------------------------+
-static inline bool tud_vendor_mounted (void);
-static inline uint32_t tud_vendor_available (void);
-static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize);
-static inline bool tud_vendor_peek (uint8_t* u8);
-static inline void tud_vendor_read_flush (void);
-static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize);
-static inline uint32_t tud_vendor_write_str (char const* str);
-static inline uint32_t tud_vendor_write_available (void);
-
-//--------------------------------------------------------------------+
-// Application Callback API (weak is optional)
-//--------------------------------------------------------------------+
-
-// Invoked when received new data
-TU_ATTR_WEAK void tud_vendor_rx_cb(uint8_t itf);
-
-//--------------------------------------------------------------------+
-// Inline Functions
-//--------------------------------------------------------------------+
-
-static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str)
-{
- return tud_vendor_n_write(itf, str, strlen(str));
-}
-
-static inline bool tud_vendor_mounted (void)
-{
- return tud_vendor_n_mounted(0);
-}
-
-static inline uint32_t tud_vendor_available (void)
-{
- return tud_vendor_n_available(0);
-}
-
-static inline uint32_t tud_vendor_read (void* buffer, uint32_t bufsize)
-{
- return tud_vendor_n_read(0, buffer, bufsize);
-}
-
-static inline bool tud_vendor_peek (uint8_t* u8)
-{
- return tud_vendor_n_peek(0, u8);
-}
-
-static inline void tud_vendor_read_flush(void)
-{
- tud_vendor_n_read_flush(0);
-}
-
-static inline uint32_t tud_vendor_write (void const* buffer, uint32_t bufsize)
-{
- return tud_vendor_n_write(0, buffer, bufsize);
-}
-
-static inline uint32_t tud_vendor_write_str (char const* str)
-{
- return tud_vendor_n_write_str(0, str);
-}
-
-static inline uint32_t tud_vendor_write_available (void)
-{
- return tud_vendor_n_write_available(0);
-}
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void vendord_init(void);
-void vendord_reset(uint8_t rhport);
-uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
-bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_VENDOR_DEVICE_H_ */
diff --git a/tinyusb/src/class/vendor/vendor_host.c b/tinyusb/src/class/vendor/vendor_host.c
deleted file mode 100755
index 1e28e9af..00000000
--- a/tinyusb/src/class/vendor/vendor_host.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#include "tusb_option.h"
-
-#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_VENDOR)
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "host/usbh.h"
-#include "vendor_host.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// INTERNAL OBJECT & FUNCTION DECLARATION
-//--------------------------------------------------------------------+
-custom_interface_info_t custom_interface[CFG_TUH_DEVICE_MAX];
-
-static tusb_error_t cush_validate_paras(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length)
-{
- if ( !tusbh_custom_is_mounted(dev_addr, vendor_id, product_id) )
- {
- return TUSB_ERROR_DEVICE_NOT_READY;
- }
-
- TU_ASSERT( p_buffer != NULL && length != 0, TUSB_ERROR_INVALID_PARA);
-
- return TUSB_ERROR_NONE;
-}
-//--------------------------------------------------------------------+
-// APPLICATION API (need to check parameters)
-//--------------------------------------------------------------------+
-tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length)
-{
- TU_ASSERT_ERR( cush_validate_paras(dev_addr, vendor_id, product_id, p_buffer, length) );
-
- if ( !hcd_pipe_is_idle(custom_interface[dev_addr-1].pipe_in) )
- {
- return TUSB_ERROR_INTERFACE_IS_BUSY;
- }
-
- (void) usbh_edpt_xfer( custom_interface[dev_addr-1].pipe_in, p_buffer, length);
-
- return TUSB_ERROR_NONE;
-}
-
-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)
-{
- TU_ASSERT_ERR( cush_validate_paras(dev_addr, vendor_id, product_id, p_data, length) );
-
- if ( !hcd_pipe_is_idle(custom_interface[dev_addr-1].pipe_out) )
- {
- return TUSB_ERROR_INTERFACE_IS_BUSY;
- }
-
- (void) usbh_edpt_xfer( custom_interface[dev_addr-1].pipe_out, p_data, length);
-
- return TUSB_ERROR_NONE;
-}
-
-//--------------------------------------------------------------------+
-// USBH-CLASS API
-//--------------------------------------------------------------------+
-void cush_init(void)
-{
- tu_memclr(&custom_interface, sizeof(custom_interface_info_t) * CFG_TUH_DEVICE_MAX);
-}
-
-tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
-{
- // FIXME quick hack to test lpc1k custom class with 2 bulk endpoints
- uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
- p_desc = tu_desc_next(p_desc);
-
- //------------- Bulk Endpoints Descriptor -------------//
- for(uint32_t i=0; i<2; i++)
- {
- tusb_desc_endpoint_t const *p_endpoint = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType, TUSB_ERROR_INVALID_PARA);
-
- pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ?
- &custom_interface[dev_addr-1].pipe_in : &custom_interface[dev_addr-1].pipe_out;
- *p_pipe_hdl = usbh_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC);
- TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED );
-
- p_desc = tu_desc_next(p_desc);
- }
-
- (*p_length) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
- return TUSB_ERROR_NONE;
-}
-
-void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event)
-{
-
-}
-
-void cush_close(uint8_t dev_addr)
-{
- tusb_error_t err1, err2;
- custom_interface_info_t * p_interface = &custom_interface[dev_addr-1];
-
- // TODO re-consider to check pipe valid before calling pipe_close
- if( pipehandle_is_valid( p_interface->pipe_in ) )
- {
- err1 = hcd_pipe_close( p_interface->pipe_in );
- }
-
- if ( pipehandle_is_valid( p_interface->pipe_out ) )
- {
- err2 = hcd_pipe_close( p_interface->pipe_out );
- }
-
- tu_memclr(p_interface, sizeof(custom_interface_info_t));
-
- TU_ASSERT(err1 == TUSB_ERROR_NONE && err2 == TUSB_ERROR_NONE, (void) 0 );
-}
-
-#endif
diff --git a/tinyusb/src/class/vendor/vendor_host.h b/tinyusb/src/class/vendor/vendor_host.h
deleted file mode 100755
index 07fa56c6..00000000
--- a/tinyusb/src/class/vendor/vendor_host.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-#ifndef _TUSB_VENDOR_HOST_H_
-#define _TUSB_VENDOR_HOST_H_
-
-#include "common/tusb_common.h"
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-typedef struct {
- pipe_handle_t pipe_in;
- pipe_handle_t pipe_out;
-}custom_interface_info_t;
-
-//--------------------------------------------------------------------+
-// USBH-CLASS DRIVER API
-//--------------------------------------------------------------------+
-static inline bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id)
-{
- (void) vendor_id; // TODO check this later
- (void) product_id;
-// return (tusbh_device_get_mounted_class_flag(dev_addr) & TU_BIT(TUSB_CLASS_MAPPED_INDEX_END-1) ) != 0;
- return false;
-}
-
-tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length);
-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);
-
-//--------------------------------------------------------------------+
-// Internal Class Driver API
-//--------------------------------------------------------------------+
-void cush_init(void);
-tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
-void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event);
-void cush_close(uint8_t dev_addr);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_VENDOR_HOST_H_ */