Merge remote-tracking branch 'hathach/master' into cdc_without_dtr
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* 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
|
||||
@@ -35,28 +36,44 @@
|
||||
#include "common/tusb_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/// Audio Interface Subclass Codes
|
||||
/// Audio Device Class Codes
|
||||
|
||||
/// A.2 - Audio Function Subclass Codes
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_SUBCLASS_CONTROL = 0x01 , ///< Audio Control
|
||||
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;
|
||||
|
||||
/// Audio Protocol Codes
|
||||
/// A.6 - Audio Interface Protocol Codes
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_PROTOCOL_V1 = 0x00, ///< Version 1.0
|
||||
AUDIO_PROTOCOL_V2 = 0x20, ///< Version 2.0
|
||||
AUDIO_PROTOCOL_V3 = 0x30, ///< Version 3.0
|
||||
} audio_protocol_type_t;
|
||||
AUDIO_INT_PROTOCOL_CODE_UNDEF = 0x00,
|
||||
AUDIO_INT_PROTOCOL_CODE_V2 = 0x20, ///< Version 2.0
|
||||
} audio_interface_protocol_code_t;
|
||||
|
||||
/// Audio Function Category Codes
|
||||
/// 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,
|
||||
@@ -68,33 +85,850 @@ typedef enum
|
||||
AUDIO_FUNC_MUSICAL_INSTRUMENT = 0x09,
|
||||
AUDIO_FUNC_PRO_AUDIO = 0x0A,
|
||||
AUDIO_FUNC_AUDIO_VIDEO = 0x0B,
|
||||
AUDIO_FUNC_CONTROL_PANEL = 0x0C
|
||||
} audio_function_t;
|
||||
AUDIO_FUNC_CONTROL_PANEL = 0x0C,
|
||||
AUDIO_FUNC_OTHER = 0xFF,
|
||||
} audio_function_code_t;
|
||||
|
||||
/// Audio Class-Specific AC Interface Descriptor Subtypes
|
||||
/// A.9 - Audio Class-Specific AC Interface Descriptor Subtypes UAC2
|
||||
typedef enum
|
||||
{
|
||||
AUDIO_CS_INTERFACE_HEADER = 0x01,
|
||||
AUDIO_CS_INTERFACE_INPUT_TERMINAL = 0x02,
|
||||
AUDIO_CS_INTERFACE_OUTPUT_TERMINAL = 0x03,
|
||||
AUDIO_CS_INTERFACE_MIXER_UNIT = 0x04,
|
||||
AUDIO_CS_INTERFACE_SELECTOR_UNIT = 0x05,
|
||||
AUDIO_CS_INTERFACE_FEATURE_UNIT = 0x06,
|
||||
AUDIO_CS_INTERFACE_EFFECT_UNIT = 0x07,
|
||||
AUDIO_CS_INTERFACE_PROCESSING_UNIT = 0x08,
|
||||
AUDIO_CS_INTERFACE_EXTENSION_UNIT = 0x09,
|
||||
AUDIO_CS_INTERFACE_CLOCK_SOURCE = 0x0A,
|
||||
AUDIO_CS_INTERFACE_CLOCK_SELECTOR = 0x0B,
|
||||
AUDIO_CS_INTERFACE_CLOCK_MULTIPLIER = 0x0C,
|
||||
AUDIO_CS_INTERFACE_SAMPLE_RATE_CONVERTER = 0x0D,
|
||||
} audio_cs_interface_subtype_t;
|
||||
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;
|
||||
|
||||
#define AUDIO_FORMAT_TYPE_UNDEFINED 0x00
|
||||
#define AUDIO_FORMAT_TYPE_I 0x01
|
||||
#define AUDIO_FORMAT_TYPE_II 0x02
|
||||
#define AUDIO_FORMAT_TYPE_III 0x03
|
||||
#define AUDIO_FORMAT_TYPE_IV 0x04
|
||||
#define AUDIO_EXT_FORMAT_TYPE_I 0x81
|
||||
#define AUDIO_EXT_FORMAT_TYPE_II 0x82
|
||||
#define AUDIO_EXT_FORMAT_TYPE_III 0x83
|
||||
|
||||
/// 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 = 0x100000000,
|
||||
//} audio_data_format_type_I_t;
|
||||
|
||||
#define AUDIO_DATA_FORMAT_TYPE_I_PCM ((uint32_t) (1 << 0))
|
||||
#define AUDIO_DATA_FORMAT_TYPE_I_PCM8 ((uint32_t) (1 << 1))
|
||||
#define AUDIO_DATA_FORMAT_TYPE_I_IEEE_FLOAT ((uint32_t) (1 << 2))
|
||||
#define AUDIO_DATA_FORMAT_TYPE_I_ALAW ((uint32_t) (1 << 3))
|
||||
#define AUDIO_DATA_FORMAT_TYPE_I_MULAW ((uint32_t) (1 << 4))
|
||||
#define AUDIO_DATA_FORMAT_TYPE_I_RAW_DATA 0x100000000
|
||||
|
||||
/// 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.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
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
1448
src/class/audio/audio_device.c
Normal file
1448
src/class/audio/audio_device.c
Normal file
File diff suppressed because it is too large
Load Diff
401
src/class/audio/audio_device.h
Normal file
401
src/class/audio/audio_device.h
Normal file
@@ -0,0 +1,401 @@
|
||||
/*
|
||||
* 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 "assert.h"
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/usbd.h"
|
||||
|
||||
#include "audio.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Class Driver Configuration
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// 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 - We restrict us here to have a constant number for all audio functions (which means this has to be the maximum number of AS interfaces an audio function has and a second audio function with less AS interfaces just waste a few bytes)
|
||||
#ifndef CFG_TUD_AUDIO_N_AS_INT
|
||||
#define CFG_TUD_AUDIO_N_AS_INT 0
|
||||
#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_CTRL_BUF_SIZE
|
||||
#error You must define an audio class control request buffer size!
|
||||
#endif
|
||||
|
||||
// Use of TX/RX FIFOs - If sizes are not zero, audio.c implements FIFOs for RX and TX (whatever defined).
|
||||
// For RX: the input stream gets decoded into its corresponding channels, where for each channel a FIFO is setup to hold its data -> see: audio_rx_done_cb().
|
||||
// For TX: the output stream is composed from CFG_TUD_AUDIO_N_CHANNELS_TX channels, where for each channel a FIFO is defined.
|
||||
// Further, it implements encoding and decoding of the individual channels (parameterized by the defines below).
|
||||
// If you don't use the FIFOs you need to handle encoding and decoding on your own in audio_rx_done_cb() and audio_tx_done_cb(). This, however, allows for optimizations.
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||
#define CFG_TUD_AUDIO_TX_FIFO_SIZE 0 // Buffer size per channel
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_RX_FIFO_SIZE
|
||||
#define CFG_TUD_AUDIO_RX_FIFO_SIZE 0 // Buffer size per channel
|
||||
#endif
|
||||
|
||||
// End point sizes - Limits: Full Speed <= 1023, High Speed <= 1024
|
||||
#ifndef CFG_TUD_AUDIO_EPSIZE_IN
|
||||
#define CFG_TUD_AUDIO_EPSIZE_IN 0 // TX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_EPSIZE_OUT
|
||||
#define CFG_TUD_AUDIO_EPSIZE_OUT 0 // RX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
|
||||
#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP 0 // Feedback
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
|
||||
#define CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN 0 // Audio interrupt control
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
|
||||
#ifndef CFG_TUD_AUDIO_INT_CTR_BUFSIZE
|
||||
#define CFG_TUD_AUDIO_INT_CTR_BUFSIZE 6 // Buffer size of audio control interrupt EP - 6 Bytes according to UAC 2 specification (p. 74)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_N_CHANNELS_TX
|
||||
#define CFG_TUD_AUDIO_N_CHANNELS_TX 1
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_N_CHANNELS_RX
|
||||
#define CFG_TUD_AUDIO_N_CHANNELS_RX 1
|
||||
#endif
|
||||
|
||||
// Audio data format types
|
||||
#ifndef CFG_TUD_AUDIO_FORMAT_TYPE_TX
|
||||
#define CFG_TUD_AUDIO_FORMAT_TYPE_TX AUDIO_FORMAT_TYPE_UNDEFINED // If this option is used, an encoding function has to be implemented in audio_device.c
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_FORMAT_TYPE_RX
|
||||
#define CFG_TUD_AUDIO_FORMAT_TYPE_RX AUDIO_FORMAT_TYPE_UNDEFINED // If this option is used, a decoding function has to be implemented in audio_device.c
|
||||
#endif
|
||||
|
||||
// Audio data format type I specifications
|
||||
#if CFG_TUD_AUDIO_FORMAT_TYPE_TX == AUDIO_FORMAT_TYPE_I
|
||||
|
||||
// Type definitions - for possible formats see: audio_data_format_type_I_t and further in UAC2 specifications.
|
||||
#ifndef CFG_TUD_AUDIO_FORMAT_TYPE_I_TX
|
||||
#define CFG_TUD_AUDIO_FORMAT_TYPE_I_TX AUDIO_DATA_FORMAT_TYPE_I_PCM
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX // bSubslotSize
|
||||
#define CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX 1
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_TX_ITEMSIZE
|
||||
#if CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX == 1
|
||||
#define CFG_TUD_AUDIO_TX_ITEMSIZE 1
|
||||
#elif CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX == 2
|
||||
#define CFG_TUD_AUDIO_TX_ITEMSIZE 2
|
||||
#else
|
||||
#define CFG_TUD_AUDIO_TX_ITEMSIZE 4
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_TX_ITEMSIZE < CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX
|
||||
#error FIFO element size (ITEMSIZE) must not be smaller then sample size
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_FORMAT_TYPE_RX == AUDIO_FORMAT_TYPE_I
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_FORMAT_TYPE_I_RX
|
||||
#define CFG_TUD_AUDIO_FORMAT_TYPE_I_RX AUDIO_DATA_FORMAT_TYPE_I_PCM
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_RX // bSubslotSize
|
||||
#define CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_RX 1
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_RX == 1
|
||||
#define CFG_TUD_AUDIO_RX_ITEMSIZE 1
|
||||
#elif CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_RX == 2
|
||||
#define CFG_TUD_AUDIO_RX_ITEMSIZE 2
|
||||
#else
|
||||
#define CFG_TUD_AUDIO_RX_ITEMSIZE 4
|
||||
#endif
|
||||
|
||||
#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 itf);
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_OUT && CFG_TUD_AUDIO_RX_FIFO_SIZE
|
||||
#if CFG_TUD_AUDIO_RX_FIFO_COUNT > 1
|
||||
uint16_t tud_audio_n_available (uint8_t itf, uint8_t channelId);
|
||||
uint16_t tud_audio_n_read (uint8_t itf, uint8_t channelId, void* buffer, uint16_t bufsize);
|
||||
void tud_audio_n_read_flush (uint8_t itf, uint8_t channelId);
|
||||
#else
|
||||
uint16_t tud_audio_n_available (uint8_t itf);
|
||||
uint16_t tud_audio_n_read (uint8_t itf, void* buffer, uint16_t bufsize);
|
||||
void tud_audio_n_read_flush (uint8_t itf);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function is intended for later use once EP buffers (at least for ISO EPs) are implemented as ring buffers
|
||||
#if CFG_TUD_AUDIO_EPSIZE_IN && !CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||
uint16_t tud_audio_n_write_ep_in_buffer(uint8_t itf, const void * data, uint16_t len)
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef CFG_TUD_AUDIO_TX_FIFO_COUNT
|
||||
#define CFG_TUD_AUDIO_TX_FIFO_COUNT 1
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||
#if CFG_TUD_AUDIO_TX_FIFO_COUNT > 1
|
||||
uint16_t tud_audio_n_write (uint8_t itf, uint8_t channelId, const void * data, uint16_t len);
|
||||
#else
|
||||
uint16_t tud_audio_n_write (uint8_t itf, const void * data, uint16_t len);
|
||||
#endif
|
||||
uint16_t tud_audio_n_write_flush(uint8_t itf);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN > 0
|
||||
uint16_t tud_audio_int_ctr_n_available (uint8_t itf);
|
||||
uint16_t tud_audio_int_ctr_n_read (uint8_t itf, void* buffer, uint16_t bufsize);
|
||||
void tud_audio_int_ctr_n_read_flush (uint8_t itf);
|
||||
uint16_t tud_audio_int_ctr_n_write (uint8_t itf, uint8_t const* buffer, uint16_t bufsize);
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Interface0)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static inline bool tud_audio_mounted (void);
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_OUT && CFG_TUD_AUDIO_RX_FIFO_SIZE
|
||||
static inline uint16_t tud_audio_available (void);
|
||||
static inline uint16_t tud_audio_read (void* buffer, uint16_t bufsize);
|
||||
static inline void tud_audio_read_flush (void);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||
#if CFG_TUD_AUDIO_TX_FIFO_COUNT > 1
|
||||
static inline uint16_t tud_audio_write (uint8_t channelId, uint8_t const* buffer, uint16_t bufsize);
|
||||
#else
|
||||
static inline uint16_t tud_audio_write (uint8_t const* buffer, uint16_t bufsize);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN > 0
|
||||
static inline uint32_t tud_audio_int_ctr_available (void);
|
||||
static inline uint32_t tud_audio_int_ctr_read (void* buffer, uint32_t bufsize);
|
||||
static inline void tud_audio_int_ctr_read_flush (void);
|
||||
static inline uint32_t tud_audio_int_ctr_write (uint8_t const* buffer, uint32_t bufsize);
|
||||
#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_EPSIZE_IN
|
||||
TU_ATTR_WEAK bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t itf, 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 itf, uint8_t ep_in, uint8_t cur_alt_setting);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_OUT
|
||||
TU_ATTR_WEAK bool tud_audio_rx_done_cb(uint8_t rhport, uint8_t * buffer, uint16_t bufsize);
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_OUT > 0 && 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_fb_set(uint8_t rhport, 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);
|
||||
}
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_IN
|
||||
#if CFG_TUD_AUDIO_TX_FIFO_SIZE && CFG_TUD_AUDIO_TX_FIFO_COUNT > 1
|
||||
static inline uint16_t tud_audio_write (uint8_t channelId, uint8_t const* buffer, uint16_t n_bytes) // Short version if only one audio function is used
|
||||
{
|
||||
return tud_audio_n_write(0, channelId, buffer, n_bytes);
|
||||
}
|
||||
#else
|
||||
static inline uint16_t tud_audio_write (uint8_t const* buffer, uint16_t n_bytes) // Short version if only one audio function is used
|
||||
{
|
||||
return tud_audio_n_write(0, buffer, n_bytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint16_t tud_audio_write_flush (void) // Short version if only one audio function is used
|
||||
{
|
||||
#if CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||
return tud_audio_n_write_flush(0);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif // CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||
|
||||
#if CFG_TUD_AUDIO_EPSIZE_OUT && CFG_TUD_AUDIO_RX_FIFO_SIZE
|
||||
#if CFG_TUD_AUDIO_RX_FIFO_COUNT > 1
|
||||
static inline uint16_t tud_audio_available(uint8_t channelId)
|
||||
{
|
||||
return tud_audio_n_available(0, channelId);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_read(uint8_t channelId, void* buffer, uint16_t bufsize)
|
||||
{
|
||||
return tud_audio_n_read(0, channelId, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline void tud_audio_read_flush(uint8_t channelId)
|
||||
{
|
||||
tud_audio_n_read_flush(0, channelId);
|
||||
}
|
||||
#else
|
||||
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 void tud_audio_read_flush(void)
|
||||
{
|
||||
tud_audio_n_read_flush(0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN > 0
|
||||
static inline uint16_t tud_audio_int_ctr_available(void)
|
||||
{
|
||||
return tud_audio_int_ctr_n_available(0);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_int_ctr_read(void* buffer, uint16_t bufsize)
|
||||
{
|
||||
return tud_audio_int_ctr_n_read(0, buffer, bufsize);
|
||||
}
|
||||
|
||||
static inline void tud_audio_int_ctr_read_flush(void)
|
||||
{
|
||||
return tud_audio_int_ctr_n_read_flush(0);
|
||||
}
|
||||
|
||||
static inline uint16_t tud_audio_int_ctr_write(uint8_t const* buffer, uint16_t bufsize)
|
||||
{
|
||||
return tud_audio_int_ctr_n_write(0, buffer, bufsize);
|
||||
}
|
||||
#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_request (uint8_t rhport, tusb_control_request_t const * request);
|
||||
bool audiod_control_complete (uint8_t rhport, 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_ */
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
@@ -63,7 +63,7 @@ typedef enum
|
||||
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_NETWORKING_CONTROL_MODEL , ///< Ethernet Networking Control Model [USBECM1.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]
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
enum
|
||||
{
|
||||
BULK_PACKET_SIZE = (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_num;
|
||||
@@ -73,18 +78,29 @@ typedef struct
|
||||
//--------------------------------------------------------------------+
|
||||
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
|
||||
|
||||
static void _prep_out_transaction (uint8_t itf)
|
||||
static void _prep_out_transaction (cdcd_interface_t* p_cdc)
|
||||
{
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
|
||||
// skip if previous transfer not complete
|
||||
if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
|
||||
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.
|
||||
uint16_t max_read = tu_fifo_remaining(&p_cdc->rx_ff);
|
||||
if ( max_read >= sizeof(p_cdc->epout_buf) )
|
||||
// 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
|
||||
{
|
||||
usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, sizeof(p_cdc->epout_buf));
|
||||
// Release endpoint since we don't make any transfer
|
||||
usbd_edpt_release(rhport, p_cdc->ep_out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +139,9 @@ uint32_t tud_cdc_n_available(uint8_t itf)
|
||||
|
||||
uint32_t tud_cdc_n_read(uint8_t itf, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
uint32_t num_read = tu_fifo_read_n(&_cdcd_itf[itf].rx_ff, buffer, bufsize);
|
||||
_prep_out_transaction(itf);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -135,8 +152,9 @@ bool tud_cdc_n_peek(uint8_t itf, int pos, uint8_t* chr)
|
||||
|
||||
void tud_cdc_n_read_flush (uint8_t itf)
|
||||
{
|
||||
tu_fifo_clear(&_cdcd_itf[itf].rx_ff);
|
||||
_prep_out_transaction(itf);
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
tu_fifo_clear(&p_cdc->rx_ff);
|
||||
_prep_out_transaction(p_cdc);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -144,15 +162,14 @@ void tud_cdc_n_read_flush (uint8_t itf)
|
||||
//--------------------------------------------------------------------+
|
||||
uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
uint16_t ret = tu_fifo_write_n(&_cdcd_itf[itf].tx_ff, buffer, bufsize);
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
uint16_t ret = tu_fifo_write_n(&p_cdc->tx_ff, buffer, bufsize);
|
||||
|
||||
#if 0 // TODO issue with circuitpython's REPL
|
||||
// flush if queue more than endpoint size
|
||||
if ( tu_fifo_count(&_cdcd_itf[itf].tx_ff) >= CFG_TUD_CDC_EP_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);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -161,13 +178,28 @@ uint32_t tud_cdc_n_write_flush (uint8_t itf)
|
||||
{
|
||||
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
|
||||
|
||||
// skip if previous transfer not complete yet
|
||||
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in), 0 );
|
||||
// No data to send
|
||||
if ( !tu_fifo_count(&p_cdc->tx_ff) ) return 0;
|
||||
|
||||
uint16_t 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(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count), 0 );
|
||||
uint8_t const rhport = TUD_OPT_RHPORT;
|
||||
|
||||
return count;
|
||||
// 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)
|
||||
@@ -190,7 +222,7 @@ void cdcd_init(void)
|
||||
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.bit_rate = 115200;
|
||||
p_cdc->line_coding.stop_bits = 0;
|
||||
p_cdc->line_coding.parity = 0;
|
||||
p_cdc->line_coding.data_bits = 8;
|
||||
@@ -221,16 +253,15 @@ void cdcd_reset(uint8_t rhport)
|
||||
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);
|
||||
TU_VERIFY( TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
|
||||
CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL == itf_desc->bInterfaceSubClass, 0);
|
||||
|
||||
// Note: 0xFF can be used with RNDIS
|
||||
TU_VERIFY(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA), 0);
|
||||
|
||||
// Find available interface
|
||||
cdcd_interface_t * p_cdc = NULL;
|
||||
uint8_t cdc_id;
|
||||
for(cdc_id=0; cdc_id<CFG_TUD_CDC; cdc_id++)
|
||||
for(uint8_t cdc_id=0; cdc_id<CFG_TUD_CDC; cdc_id++)
|
||||
{
|
||||
if ( _cdcd_itf[cdc_id].ep_in == 0 )
|
||||
{
|
||||
@@ -279,7 +310,7 @@ uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
|
||||
}
|
||||
|
||||
// Prepare for incoming data
|
||||
_prep_out_transaction(cdc_id);
|
||||
_prep_out_transaction(p_cdc);
|
||||
|
||||
return drv_len;
|
||||
}
|
||||
@@ -417,7 +448,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
|
||||
|
||||
// prepare for OUT transaction
|
||||
_prep_out_transaction(itf);
|
||||
_prep_out_transaction(p_cdc);
|
||||
}
|
||||
|
||||
// Data sent to host, we continue to fetch from tx fifo to send.
|
||||
@@ -430,12 +461,14 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
|
||||
if ( 0 == tud_cdc_n_write_flush(itf) )
|
||||
{
|
||||
// There is no data left, a ZLP should be sent if
|
||||
// xferred_bytes is multiple of EP size and not zero
|
||||
// FIXME CFG_TUD_CDC_EP_BUFSIZE is not Endpoint packet size
|
||||
if ( xferred_bytes && (0 == (xferred_bytes % CFG_TUD_CDC_EP_BUFSIZE)) )
|
||||
// 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))) )
|
||||
{
|
||||
usbd_edpt_xfer(rhport, p_cdc->ep_in, NULL, 0);
|
||||
if ( usbd_edpt_claim(rhport, p_cdc->ep_in) )
|
||||
{
|
||||
usbd_edpt_xfer(rhport, p_cdc->ep_in, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ uint32_t tud_cdc_n_write (uint8_t itf, void const* buffer, uint32_t bu
|
||||
static inline
|
||||
uint32_t tud_cdc_n_write_char (uint8_t itf, char ch);
|
||||
|
||||
// Write a nul-terminated string
|
||||
// Write a null-terminated string
|
||||
static inline
|
||||
uint32_t tud_cdc_n_write_str (uint8_t itf, char const* str);
|
||||
|
||||
|
||||
@@ -86,7 +86,6 @@ bool tuh_cdc_serial_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
// TODO consider all AT Command as serial candidate
|
||||
return tuh_cdc_mounted(dev_addr) &&
|
||||
(CDC_COMM_PROTOCOL_NONE <= cdch_data[dev_addr-1].itf_protocol) &&
|
||||
(cdch_data[dev_addr-1].itf_protocol <= CDC_COMM_PROTOCOL_ATCOMMAND_CDMA);
|
||||
}
|
||||
|
||||
@@ -159,7 +158,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
// notification endpoint
|
||||
tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc;
|
||||
|
||||
TU_ASSERT( hcd_edpt_open(rhport, dev_addr, ep_desc) );
|
||||
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, ep_desc) );
|
||||
p_cdc->ep_notif = ep_desc->bEndpointAddress;
|
||||
|
||||
(*p_length) += p_desc[DESC_OFFSET_LEN];
|
||||
@@ -180,7 +179,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
|
||||
TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
|
||||
|
||||
TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
|
||||
TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
|
||||
|
||||
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@@ -57,33 +57,34 @@ typedef struct
|
||||
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
|
||||
|
||||
/*------------- Helpers -------------*/
|
||||
static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
|
||||
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 &_hidd_itf[i];
|
||||
}
|
||||
for (uint8_t i=0; i < CFG_TUD_HID; i++ )
|
||||
{
|
||||
if ( itf_num == _hidd_itf[i].itf_num ) return i;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_ready(void)
|
||||
bool tud_hid_n_ready(uint8_t itf)
|
||||
{
|
||||
uint8_t itf = 0;
|
||||
uint8_t const ep_in = _hidd_itf[itf].ep_in;
|
||||
return tud_ready() && (ep_in != 0) && usbd_edpt_ready(TUD_OPT_RHPORT, ep_in);
|
||||
return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
|
||||
}
|
||||
|
||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||
bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len)
|
||||
{
|
||||
TU_VERIFY( tud_hid_ready() );
|
||||
|
||||
uint8_t itf = 0;
|
||||
uint8_t const rhport = 0;
|
||||
hidd_interface_t * p_hid = &_hidd_itf[itf];
|
||||
|
||||
// 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);
|
||||
@@ -101,16 +102,15 @@ bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||
return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
|
||||
}
|
||||
|
||||
bool tud_hid_boot_mode(void)
|
||||
bool tud_hid_n_boot_mode(uint8_t itf)
|
||||
{
|
||||
uint8_t itf = 0;
|
||||
return _hidd_itf[itf].boot_mode;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
|
||||
bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
|
||||
{
|
||||
hid_keyboard_report_t report;
|
||||
|
||||
@@ -124,13 +124,13 @@ bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycod
|
||||
tu_memclr(report.keycode, 6);
|
||||
}
|
||||
|
||||
return tud_hid_report(report_id, &report, sizeof(report));
|
||||
return tud_hid_n_report(itf, report_id, &report, sizeof(report));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
|
||||
bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
|
||||
{
|
||||
hid_mouse_report_t report =
|
||||
{
|
||||
@@ -141,7 +141,7 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y
|
||||
.pan = horizontal
|
||||
};
|
||||
|
||||
return tud_hid_report(report_id, &report, sizeof(report));
|
||||
return tud_hid_n_report(itf, report_id, &report, sizeof(report));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -194,7 +194,7 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1
|
||||
|
||||
p_hid->boot_mode = false; // default mode is REPORT
|
||||
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);
|
||||
|
||||
@@ -217,8 +217,10 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
{
|
||||
TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
|
||||
|
||||
hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) request->wIndex );
|
||||
TU_ASSERT(p_hid);
|
||||
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)
|
||||
{
|
||||
@@ -234,7 +236,11 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
}
|
||||
else if (request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||
{
|
||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
|
||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb(
|
||||
#if CFG_TUD_HID > 1
|
||||
hid_itf // TODO for backward compatible callback, remove later when appropriate
|
||||
#endif
|
||||
);
|
||||
tud_control_xfer(rhport, request, (void*) desc_report, p_hid->report_desc_len);
|
||||
}
|
||||
else
|
||||
@@ -253,7 +259,12 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
uint8_t const report_type = tu_u16_high(request->wValue);
|
||||
uint8_t const report_id = tu_u16_low(request->wValue);
|
||||
|
||||
uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength);
|
||||
uint16_t xferlen = tud_hid_get_report_cb(
|
||||
#if CFG_TUD_HID > 1
|
||||
hid_itf, // TODO for backward compatible callback, remove later when appropriate
|
||||
#endif
|
||||
report_id, (hid_report_type_t) report_type, p_hid->epin_buf, request->wLength
|
||||
);
|
||||
TU_ASSERT( xferlen > 0 );
|
||||
|
||||
tud_control_xfer(rhport, request, p_hid->epin_buf, xferlen);
|
||||
@@ -270,7 +281,12 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
if ( tud_hid_set_idle_cb )
|
||||
{
|
||||
// stall request if callback return false
|
||||
if ( !tud_hid_set_idle_cb(p_hid->idle_rate) ) return false;
|
||||
TU_VERIFY( tud_hid_set_idle_cb(
|
||||
#if CFG_TUD_HID > 1
|
||||
hid_itf, // TODO for backward compatible callback, remove later when appropriate
|
||||
#endif
|
||||
p_hid->idle_rate)
|
||||
);
|
||||
}
|
||||
|
||||
tud_control_status(rhport, request);
|
||||
@@ -291,7 +307,15 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
case HID_REQ_CONTROL_SET_PROTOCOL:
|
||||
p_hid->boot_mode = 1 - request->wValue; // 0 is Boot, 1 is Report protocol
|
||||
|
||||
if (tud_hid_boot_mode_cb) tud_hid_boot_mode_cb(p_hid->boot_mode);
|
||||
if (tud_hid_boot_mode_cb)
|
||||
{
|
||||
tud_hid_boot_mode_cb(
|
||||
#if CFG_TUD_HID > 1
|
||||
hid_itf, // TODO for backward compatible callback, remove later when appropriate
|
||||
#endif
|
||||
p_hid->boot_mode
|
||||
);
|
||||
}
|
||||
|
||||
tud_control_status(rhport, request);
|
||||
break;
|
||||
@@ -311,8 +335,11 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
bool hidd_control_complete(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
(void) rhport;
|
||||
hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex );
|
||||
TU_ASSERT(p_hid);
|
||||
|
||||
uint8_t const hid_itf = get_index_by_itfnum((uint8_t) p_request->wIndex);
|
||||
TU_VERIFY(hid_itf < CFG_TUD_HID);
|
||||
|
||||
hidd_interface_t* p_hid = &_hidd_itf[hid_itf];
|
||||
|
||||
if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
|
||||
p_request->bRequest == HID_REQ_CONTROL_SET_REPORT)
|
||||
@@ -321,7 +348,12 @@ bool hidd_control_complete(uint8_t rhport, tusb_control_request_t const * p_requ
|
||||
uint8_t const report_type = tu_u16_high(p_request->wValue);
|
||||
uint8_t const report_id = tu_u16_low(p_request->wValue);
|
||||
|
||||
tud_hid_set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength);
|
||||
tud_hid_set_report_cb(
|
||||
#if CFG_TUD_HID > 1
|
||||
hid_itf, // TODO for backward compatible callback, remove later when appropriate
|
||||
#endif
|
||||
report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -343,7 +375,12 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
|
||||
if (ep_addr == p_hid->ep_out)
|
||||
{
|
||||
tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
|
||||
tud_hid_set_report_cb(
|
||||
#if CFG_TUD_HID > 1
|
||||
itf, // TODO for backward compatible callback, remove later when appropriate
|
||||
#endif
|
||||
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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
||||
@@ -50,51 +50,104 @@
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
// Application API (Multiple Ports)
|
||||
// CFG_TUD_HID > 1
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Check if the interface is ready to use
|
||||
bool tud_hid_ready(void);
|
||||
bool tud_hid_n_ready(uint8_t itf);
|
||||
|
||||
// Check if current mode is Boot (true) or Report (false)
|
||||
bool tud_hid_boot_mode(void);
|
||||
bool tud_hid_n_boot_mode(uint8_t itf);
|
||||
|
||||
// Send report to host
|
||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
|
||||
bool tud_hid_n_report(uint8_t itf, 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_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||
bool tud_hid_n_keyboard_report(uint8_t itf, 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_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||
bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API (Single Port)
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_hid_ready(void);
|
||||
static inline bool tud_hid_boot_mode(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);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Callbacks (Weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if CFG_TUD_HID > 1
|
||||
|
||||
// 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(void);
|
||||
uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf);
|
||||
|
||||
// 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 report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||
uint16_t tud_hid_get_report_cb(uint8_t itf, 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 report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||
void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||
|
||||
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
|
||||
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
|
||||
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t itf, uint8_t boot_mode);
|
||||
|
||||
// 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 itf, uint8_t idle_rate);
|
||||
|
||||
#else
|
||||
|
||||
// TODO for backward compatible callback, remove later when appropriate
|
||||
uint8_t const * tud_hid_descriptor_report_cb(void);
|
||||
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||
|
||||
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
|
||||
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Inline Functions
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool tud_hid_ready(void)
|
||||
{
|
||||
return tud_hid_n_ready(0);
|
||||
}
|
||||
|
||||
static inline bool tud_hid_boot_mode(void)
|
||||
{
|
||||
return tud_hid_n_boot_mode(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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------+
|
||||
* HID Report Descriptor Template
|
||||
*
|
||||
@@ -264,7 +317,7 @@ TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
|
||||
HID_LOGICAL_MAX ( 1 ) ,\
|
||||
HID_REPORT_COUNT ( 16 ) ,\
|
||||
HID_REPORT_SIZE ( 1 ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
|
||||
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
|
||||
/* X, Y, Z, Rz (min -127, max 127 ) */ \
|
||||
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
|
||||
HID_LOGICAL_MIN ( 0x81 ) ,\
|
||||
@@ -318,4 +371,3 @@ bool hidd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t e
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HID_DEVICE_H_ */
|
||||
|
||||
|
||||
@@ -35,35 +35,43 @@
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
typedef struct {
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
uint16_t report_size;
|
||||
}hidh_interface_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HID Interface common functions
|
||||
//--------------------------------------------------------------------+
|
||||
static inline bool hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid)
|
||||
static inline bool hidh_interface_open(uint8_t rhport, uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_t *p_hid)
|
||||
{
|
||||
p_hid->pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
|
||||
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
|
||||
p_hid->interface_number = interface_number;
|
||||
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, p_endpoint_desc) );
|
||||
|
||||
TU_ASSERT (pipehandle_is_valid(p_hid->pipe_hdl));
|
||||
p_hid->ep_in = p_endpoint_desc->bEndpointAddress;
|
||||
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
|
||||
p_hid->itf_num = interface_number;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void hidh_interface_close(hidh_interface_info_t *p_hid)
|
||||
static inline void hidh_interface_close(hidh_interface_t *p_hid)
|
||||
{
|
||||
tu_memclr(p_hid, sizeof(hidh_interface_info_t));
|
||||
tu_memclr(p_hid, sizeof(hidh_interface_t));
|
||||
}
|
||||
|
||||
// called from public API need to validate parameters
|
||||
tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_interface_info_t *p_hid)
|
||||
tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_interface_t *p_hid)
|
||||
{
|
||||
//------------- parameters validation -------------//
|
||||
// TODO change to use is configured function
|
||||
TU_ASSERT (TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
TU_VERIFY (report, TUSB_ERROR_INVALID_PARA);
|
||||
TU_ASSERT (!hcd_edpt_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY);
|
||||
TU_ASSERT(TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
TU_VERIFY(report, TUSB_ERROR_INVALID_PARA);
|
||||
TU_ASSERT(!hcd_edpt_busy(dev_addr, p_hid->ep_in), TUSB_ERROR_INTERFACE_IS_BUSY);
|
||||
|
||||
TU_ASSERT_ERR( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ;
|
||||
TU_ASSERT( hcd_pipe_xfer(dev_addr, p_hid->ep_in, report, p_hid->report_size, true) ) ;
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
@@ -73,24 +81,12 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
|
||||
#if 0
|
||||
#define EXPAND_KEYCODE_TO_ASCII(keycode, ascii, shift_modified) \
|
||||
[0][keycode] = ascii,\
|
||||
[1][keycode] = shift_modified,\
|
||||
|
||||
// TODO size of table should be a macro for application to check boundary
|
||||
uint8_t const hid_keycode_to_ascii_tbl[2][128] =
|
||||
{
|
||||
HID_KEYCODE_TABLE(EXPAND_KEYCODE_TO_ASCII)
|
||||
};
|
||||
#endif
|
||||
|
||||
static hidh_interface_info_t keyboardh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
static hidh_interface_t keyboardh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
|
||||
//------------- KEYBOARD PUBLIC API (parameter validation required) -------------//
|
||||
bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_is_configured(dev_addr) && pipehandle_is_valid(keyboardh_data[dev_addr-1].pipe_hdl);
|
||||
return tuh_device_is_configured(dev_addr) && (keyboardh_data[dev_addr-1].ep_in != 0);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void* p_report)
|
||||
@@ -100,8 +96,7 @@ tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void* p_report)
|
||||
|
||||
bool tuh_hid_keyboard_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_hid_keyboard_is_mounted(dev_addr) &&
|
||||
hcd_edpt_busy( keyboardh_data[dev_addr-1].pipe_hdl );
|
||||
return tuh_hid_keyboard_is_mounted(dev_addr) && hcd_edpt_busy(dev_addr, keyboardh_data[dev_addr-1].ep_in);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -111,18 +106,17 @@ bool tuh_hid_keyboard_is_busy(uint8_t dev_addr)
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
|
||||
static hidh_interface_info_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
static hidh_interface_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1
|
||||
|
||||
//------------- Public API -------------//
|
||||
bool tuh_hid_mouse_is_mounted(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_device_is_configured(dev_addr) && pipehandle_is_valid(mouseh_data[dev_addr-1].pipe_hdl);
|
||||
return tuh_device_is_configured(dev_addr) && (mouseh_data[dev_addr-1].ep_in != 0);
|
||||
}
|
||||
|
||||
bool tuh_hid_mouse_is_busy(uint8_t dev_addr)
|
||||
{
|
||||
return tuh_hid_mouse_is_mounted(dev_addr) &&
|
||||
hcd_edpt_busy( mouseh_data[dev_addr-1].pipe_hdl );
|
||||
return tuh_hid_mouse_is_mounted(dev_addr) && hcd_edpt_busy(dev_addr, mouseh_data[dev_addr-1].ep_in);
|
||||
}
|
||||
|
||||
tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report)
|
||||
@@ -149,11 +143,11 @@ tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report)
|
||||
void hidh_init(void)
|
||||
{
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
tu_memclr(&keyboardh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
tu_memclr(&keyboardh_data, sizeof(hidh_interface_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
tu_memclr(&mouseh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
tu_memclr(&mouseh_data, sizeof(hidh_interface_t)*CFG_TUSB_HOST_DEVICE_MAX);
|
||||
#endif
|
||||
|
||||
#if CFG_TUSB_HOST_HID_GENERIC
|
||||
@@ -165,7 +159,7 @@ void hidh_init(void)
|
||||
CFG_TUSB_MEM_SECTION uint8_t report_descriptor[256];
|
||||
#endif
|
||||
|
||||
bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
|
||||
bool hidh_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
|
||||
|
||||
@@ -208,7 +202,8 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
if ( HID_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
TU_ASSERT( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) );
|
||||
TU_ASSERT( hidh_interface_open(rhport, dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) );
|
||||
TU_LOG2_HEX(keyboardh_data[dev_addr-1].ep_in);
|
||||
tuh_hid_keyboard_mounted_cb(dev_addr);
|
||||
} else
|
||||
#endif
|
||||
@@ -216,7 +211,8 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
if ( HID_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
TU_ASSERT ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) );
|
||||
TU_ASSERT ( hidh_interface_open(rhport, dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) );
|
||||
TU_LOG2_HEX(mouseh_data[dev_addr-1].ep_in);
|
||||
tuh_hid_mouse_mounted_cb(dev_addr);
|
||||
} else
|
||||
#endif
|
||||
@@ -236,22 +232,22 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
|
||||
return true;
|
||||
}
|
||||
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes)
|
||||
void hidh_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
(void) xferred_bytes; // TODO may need to use this para later
|
||||
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
if ( pipehandle_is_equal(pipe_hdl, keyboardh_data[pipe_hdl.dev_addr-1].pipe_hdl) )
|
||||
if ( ep_addr == keyboardh_data[dev_addr-1].ep_in )
|
||||
{
|
||||
tuh_hid_keyboard_isr(pipe_hdl.dev_addr, event);
|
||||
tuh_hid_keyboard_isr(dev_addr, event);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
if ( pipehandle_is_equal(pipe_hdl, mouseh_data[pipe_hdl.dev_addr-1].pipe_hdl) )
|
||||
if ( ep_addr == mouseh_data[dev_addr-1].ep_in )
|
||||
{
|
||||
tuh_hid_mouse_isr(pipe_hdl.dev_addr, event);
|
||||
tuh_hid_mouse_isr(dev_addr, event);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@@ -264,7 +260,7 @@ void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_byte
|
||||
void hidh_close(uint8_t dev_addr)
|
||||
{
|
||||
#if CFG_TUH_HID_KEYBOARD
|
||||
if ( pipehandle_is_valid( keyboardh_data[dev_addr-1].pipe_hdl ) )
|
||||
if ( keyboardh_data[dev_addr-1].ep_in != 0 )
|
||||
{
|
||||
hidh_interface_close(&keyboardh_data[dev_addr-1]);
|
||||
tuh_hid_keyboard_unmounted_cb(dev_addr);
|
||||
@@ -272,7 +268,7 @@ void hidh_close(uint8_t dev_addr)
|
||||
#endif
|
||||
|
||||
#if CFG_TUH_HID_MOUSE
|
||||
if( pipehandle_is_valid( mouseh_data[dev_addr-1].pipe_hdl ) )
|
||||
if( mouseh_data[dev_addr-1].ep_in != 0 )
|
||||
{
|
||||
hidh_interface_close(&mouseh_data[dev_addr-1]);
|
||||
tuh_hid_mouse_unmounted_cb( dev_addr );
|
||||
|
||||
@@ -195,15 +195,9 @@ void tuh_hid_generic_isr(uint8_t dev_addr, xfer_result_t event);
|
||||
//--------------------------------------------------------------------+
|
||||
// Internal Class Driver API
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
pipe_handle_t pipe_hdl;
|
||||
uint16_t report_size;
|
||||
uint8_t interface_number;
|
||||
}hidh_interface_info_t;
|
||||
|
||||
void hidh_init(void);
|
||||
bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
|
||||
bool hidh_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
|
||||
void hidh_isr(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void hidh_close(uint8_t dev_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -153,15 +153,25 @@ void midi_rx_done_cb(midid_interface_t* midi, uint8_t const* buffer, uint32_t bu
|
||||
|
||||
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_busy(TUD_OPT_RHPORT, midi->ep_in) );
|
||||
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 > 0)
|
||||
{
|
||||
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, midi->ep_in, midi->epin_buf, 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;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
uint32_t tud_midi_n_write(uint8_t itf, uint8_t jack_id, uint8_t const* buffer, uint32_t bufsize)
|
||||
@@ -183,7 +193,7 @@ uint32_t tud_midi_n_write(uint8_t itf, uint8_t jack_id, uint8_t const* buffer, u
|
||||
if (data == 0xf7) {
|
||||
midi->write_buffer[0] = 0x5;
|
||||
} else {
|
||||
midi->write_buffer_length = 4;
|
||||
midi->write_target_length = 4;
|
||||
}
|
||||
} else if ((msg >= 0x8 && msg <= 0xB) || msg == 0xE) {
|
||||
midi->write_buffer[0] = jack_id << 4 | msg;
|
||||
@@ -290,9 +300,9 @@ void midid_reset(uint8_t rhport)
|
||||
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_PROTOCOL_V1 == desc_itf->bInterfaceProtocol, 0);
|
||||
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);
|
||||
@@ -308,9 +318,9 @@ uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint
|
||||
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_PROTOCOL_V1 == desc_midi->bInterfaceProtocol, 0);
|
||||
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;
|
||||
@@ -405,17 +415,22 @@ bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32
|
||||
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
|
||||
TU_ASSERT(usbd_edpt_xfer(rhport, p_midi->ep_out, p_midi->epout_buf, CFG_TUD_MIDI_EP_BUFSIZE), false);
|
||||
}
|
||||
else if ( ep_addr == p_midi->ep_in )
|
||||
{
|
||||
if (0 == write_flush(p_midi))
|
||||
{
|
||||
// There is no data left, a ZLP should be sent if
|
||||
// If there is no data left, a ZLP should be sent if
|
||||
// xferred_bytes is multiple of EP size and not zero
|
||||
if ( xferred_bytes && (0 == (xferred_bytes % CFG_TUD_MIDI_EP_BUFSIZE)) )
|
||||
if ( !tu_fifo_count(&p_midi->tx_ff) && xferred_bytes && (0 == (xferred_bytes % CFG_TUD_MIDI_EP_BUFSIZE)) )
|
||||
{
|
||||
usbd_edpt_xfer(rhport, p_midi->ep_in, NULL, 0);
|
||||
if ( usbd_edpt_claim(rhport, p_midi->ep_in) )
|
||||
{
|
||||
usbd_edpt_xfer(rhport, p_midi->ep_in, NULL, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
|
||||
TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
|
||||
|
||||
TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
|
||||
TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
|
||||
|
||||
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
|
||||
{
|
||||
@@ -306,15 +306,16 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc);
|
||||
}
|
||||
|
||||
p_msc->itf_numr = itf_desc->bInterfaceNumber;
|
||||
p_msc->itf_num = itf_desc->bInterfaceNumber;
|
||||
(*p_length) += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
//------------- 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 = p_msc->itf_numr,
|
||||
.wIndex = p_msc->itf_num,
|
||||
.wLength = 1
|
||||
};
|
||||
// TODO STALL means zero
|
||||
@@ -327,7 +328,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
|
||||
.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_numr,
|
||||
.wIndex = p_msc->itf_num,
|
||||
.wLength = 0
|
||||
};
|
||||
TU_ASSERT( usbh_control_xfer( dev_addr, &request, NULL ) );
|
||||
|
||||
@@ -175,7 +175,7 @@ void tuh_msc_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes);
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_numr;
|
||||
uint8_t itf_num;
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
|
||||
|
||||
@@ -141,9 +141,9 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
|
||||
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_NETWORKING_CONTROL_MODEL == itf_desc->bInterfaceSubClass &&
|
||||
0x00 == 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);
|
||||
|
||||
@@ -366,23 +366,7 @@ static void handle_incoming_packet(uint32_t len)
|
||||
}
|
||||
}
|
||||
|
||||
bool accepted = false;
|
||||
|
||||
if (size)
|
||||
{
|
||||
struct pbuf *p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL);
|
||||
|
||||
if (p)
|
||||
{
|
||||
memcpy(p->payload, pnt, size);
|
||||
p->len = size;
|
||||
accepted = tud_network_recv_cb(p);
|
||||
|
||||
if (!accepted) pbuf_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
if (!accepted)
|
||||
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();
|
||||
@@ -429,9 +413,8 @@ bool tud_network_can_xmit(void)
|
||||
return can_xmit;
|
||||
}
|
||||
|
||||
void tud_network_xmit(struct pbuf *p)
|
||||
void tud_network_xmit(void *ref, uint16_t arg)
|
||||
{
|
||||
struct pbuf *q;
|
||||
uint8_t *data;
|
||||
uint16_t len;
|
||||
|
||||
@@ -441,12 +424,7 @@ void tud_network_xmit(struct pbuf *p)
|
||||
len = (_netd_itf.ecm_mode) ? 0 : CFG_TUD_NET_PACKET_PREFIX_LEN;
|
||||
data = transmitted + len;
|
||||
|
||||
for(q = p; q != NULL; q = q->next)
|
||||
{
|
||||
memcpy(data, (char *)q->payload, q->len);
|
||||
data += q->len;
|
||||
len += q->len;
|
||||
}
|
||||
len += tud_network_xmit_cb(data, ref, arg);
|
||||
|
||||
if (!_netd_itf.ecm_mode)
|
||||
{
|
||||
|
||||
@@ -32,15 +32,13 @@
|
||||
#include "device/usbd.h"
|
||||
#include "class/cdc/cdc.h"
|
||||
|
||||
// TODO should not include external files
|
||||
#include "lwip/pbuf.h"
|
||||
#include "netif/ethernet.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 */
|
||||
#define CFG_TUD_NET_MTU (1500 + SIZEOF_ETH_HDR)
|
||||
#ifndef CFG_TUD_NET_MTU
|
||||
#define CFG_TUD_NET_MTU 1514
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -54,7 +52,10 @@
|
||||
void tud_network_init_cb(void);
|
||||
|
||||
// client must provide this: return false if the packet buffer was not accepted
|
||||
bool tud_network_recv_cb(struct pbuf *p);
|
||||
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
|
||||
@@ -67,7 +68,7 @@ void tud_network_recv_renew(void);
|
||||
bool tud_network_can_xmit(void);
|
||||
|
||||
// if network_can_xmit() returns true, network_xmit() can be called once
|
||||
void tud_network_xmit(struct pbuf *p);
|
||||
void tud_network_xmit(void *ref, uint16_t arg);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL USBD-CLASS DRIVER API
|
||||
|
||||
2
src/class/vendor/vendor_host.c
vendored
2
src/class/vendor/vendor_host.c
vendored
@@ -107,7 +107,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_
|
||||
|
||||
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 = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC);
|
||||
*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);
|
||||
|
||||
Reference in New Issue
Block a user