/* * Copyright (c) 2015, Freescale Semiconductor, Inc. * Copyright 2016, 2020 NXP * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef __USB_HOST_AUDIO_H__ #define __USB_HOST_AUDIO_H__ /******************************************************************************* * Audio class private structure, enumerations, macros ******************************************************************************/ /******************************************************************************* * Definitions ******************************************************************************/ /* Structure for an AUDIO class descriptor according to the 6.2.1 in Audio 1.0 specification*/ /* Audio 1.0 class codes */ #define SET_COMMAND (0x00) #define GET_COMMAND (0x80) #define CUR_REQUEST (0x01) #define MIN_REQUEST (0x02) #define MAX_REQUEST (0x03) #define RES_REQUEST (0x04) #define MEM_REQUEST (0x05) #define GET_STATUS (0xFF) #define ITF_REQUEST (0x21) #define EP_REQUEST (0x22) #define AUDIO_FU_MUTE_MASK 0x01 #define AUDIO_FU_VOLUME_MASK 0x02 #define AUDIO_FU_BASS_MASK 0x04 #define AUDIO_FU_MID_MASK 0x08 #define AUDIO_FU_TREBLE_MASK 0x10 #define AUDIO_FU_GRAPHIC_EQ_MASK 0x20 #define AUDIO_FU_AGC_MASK 0x40 #define AUDIO_FU_DELAY_MASK 0x80 #define AUDIO_FU_BASS_BOOST_MASK 0x01 /* USB audio1.0 Endpoint Control Selectors */ #define AUDIO_EP_CONTROL_UNDEFINED (0x00) #define AUDIO_SAMPLING_FREQ_CONTROL (0x01) #define AUDIO_PITCH_CONTROL (0x02) /* USB audio2.0 Endpoint Control Selectors */ #define AUDIO_EP_CONTROL_UNDEFINED_20 (0x00) #define AUDIO_EP_PITCH_CONTROL_20 (0x01) #define AUDIO_EP_DATA_OVERRUN_CONTRO_20 (0x02) #define AUDIO_EP_DATA_UNDERRUN_CONTROL_20 (0x03) /* USB audio1.0 MASK*/ #define AUDIO_SAMPLING_FREQ_MASK (0x01) #define AUDIO_PITCH_MASK (0x02) /*! @brief Audio device Format Type Codes */ #define USB_AUDIO_FORMAT_TYPE_UNDEFINED (0x00) #define USB_AUDIO_FORMAT_TYPE_I (0x01) #define USB_AUDIO_FORMAT_TYPE_II (0x02) #define USB_AUDIO_FORMAT_TYPE_III (0x03) /* USB audio2.0 format type */ #define USB_AUDIO_FORMAT_TYPE_IV (0x04) #define USB_AUDIO_FORMAT_EXT_FORMAT_TYPE_I (0x81) #define USB_AUDIO_FORMAT_EXT_FORMAT_TYPE_II (0x82) #define USB_AUDIO_FORMAT_EXT_FORMAT_TYPE_III (0x83) typedef enum _fu_request_code { kUSB_AudioCurMute = 0, kUSB_AudioCurVolume, kUSB_AudioMinVolume, kUSB_AudioMaxVolume, kUSB_AudioResVolume, NUMBER_OF_FEATURE_COMMANDS, } fu_request_code_t; typedef enum _ep_request_code { kUSB_AudioCurPitch = 0, kUSB_AudioCurSamplingFreq, kUSB_AudioMinSamplingFreq, kUSB_AudioMaxSamplingFreq, kUSB_AudioResSamplingFreq, NUMBER_OF_ENDPOINT_COMMANDS, } ep_request_code_t; typedef union _audio_descriptor_union { uint8_t *bufr; usb_descriptor_common_t *common; usb_descriptor_device_t *device; usb_descriptor_configuration_t *configuration; usb_descriptor_interface_t *interface; usb_descriptor_endpoint_t *endpoint; } audio_descriptor_union_t; /* Audio command structure */ typedef struct _usb_audio_request { uint8_t controlMask; uint8_t typeRequest; uint8_t codeRequest; uint8_t requestValue; uint8_t length; } usb_audio_request_t; /******************************************************************************* * Audio class public structure, enumeration, macros, functions ******************************************************************************/ /*! * @addtogroup usb_host_audio_drv * @{ */ /*! @brief Audio class code */ #define USB_AUDIO_CLASS_CODE 1 /*! @brief Audio class control interface code*/ #define USB_AUDIO_SUBCLASS_CODE_CONTROL 1 /*! @brief Audio class stream interface code*/ #define USB_AUDIO_SUBCLASS_CODE_AUDIOSTREAMING 2 /* Audio Device Class Specification Release Number in Binary-Coded Decimal.*/ #define AUDIO_DEVICE_VERSION_01 0x0100U #define AUDIO_DEVICE_VERSION_02 0x0200U /*! @brief AUDIO class-specific feature unit get current mute command*/ #define USB_AUDIO_GET_CUR_MUTE 0x80 /*! @brief AUDIO class-specific feature unit set current mute command*/ #define USB_AUDIO_SET_CUR_MUTE 0x00 /*! @brief AUDIO class-specific feature unit get current volume command*/ #define USB_AUDIO_GET_CUR_VOLUME 0x81 /*! @brief AUDIO class-specific feature unit set current volume command*/ #define USB_AUDIO_SET_CUR_VOLUME 0x01 /*! @brief AUDIO class-specific feature unit get minimum volume command*/ #define USB_AUDIO_GET_MIN_VOLUME 0x82 /*! @brief AUDIO class-specific feature unit set minimum volume command*/ #define USB_AUDIO_SET_MIN_VOLUME 0x02 /*! @brief AUDIO class-specific feature unit get maximum volume command*/ #define USB_AUDIO_GET_MAX_VOLUME 0x83 /*! @brief AUDIO class-specific feature unit set maximum volume command*/ #define USB_AUDIO_SET_MAX_VOLUME 0x03 /*! @brief AUDIO class-specific feature unit get resolution volume command*/ #define USB_AUDIO_GET_RES_VOLUME 0x84 /*! @brief AUDIO class-specific feature unit set resolution volume command*/ #define USB_AUDIO_SET_RES_VOLUME 0x04 /*! @brief AUDIO class-specific endpoint get current pitch control command*/ #define USB_AUDIO_GET_CUR_PITCH 0x80 /*! @brief AUDIO class-specific endpoint set current pitch control command*/ #define USB_AUDIO_SET_CUR_PITCH 0x00 /*! @brief AUDIO class-specific endpoint get current sampling frequency command*/ #define USB_AUDIO_GET_CUR_SAMPLING_FREQ 0x81 /*! @brief AUDIO class-specific endpoint set current sampling frequency command*/ #define USB_AUDIO_SET_CUR_SAMPLING_FREQ 0x01 /*! @brief AUDIO class-specific endpoint get minimum sampling frequency command*/ #define USB_AUDIO_GET_MIN_SAMPLING_FREQ 0x82 /*! @brief AUDIO class-specific endpoint set minimum sampling frequency command*/ #define USB_AUDIO_SET_MIN_SAMPLING_FREQ 0x02 /*! @brief AUDIO class-specific endpoint get maximum sampling frequency command*/ #define USB_AUDIO_GET_MAX_SAMPLING_FREQ 0x83 /*! @brief AUDIO class-specific endpoint set maximum sampling frequency command*/ #define USB_AUDIO_SET_MAX_SAMPLING_FREQ 0x03 /*! @brief AUDIO class-specific endpoint get resolution sampling frequency command*/ #define USB_AUDIO_GET_RES_SAMPLING_FREQ 0x84 /*! @brief AUDIO class-specific endpoint set resolution sampling frequency command*/ #define USB_AUDIO_SET_RES_SAMPLING_FREQ 0x04 /*Audio Class-Specific AC Interface Descriptor Subtypes*/ #define USB_AUDIO_DESC_SUBTYPE_AUDIO_UNDEFINED 0x00U /*undefined Descriptor*/ /*remain two input terminal descriptor macro for compatibility, please use the latter one*/ #define USB_DESC_SUBTYPE_AUDIO_CS_HEADER 0x01U #define USB_AUDIO_DESC_SUBTYPE_CS_HEADER 0x01U /*Header Descriptor*/ /*remain two input terminal descriptor macro for compatibility, please use the latter one*/ #define USB_DESC_SUBTYPE_AUDIO_CS_IT 0x02U /*Input Terminal Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_INPUT 0x02U /*Input Terminal Descriptor*/ /*remain two output terminal descriptor macro for compatibility, please use the latter one*/ #define USB_DESC_SUBTYPE_AUDIO_CS_OT 0x03U /*Output Terminal Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_OUTPUT 0x03U /*Output Terminal Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_MIXER 0x04U /*Mixer Unit Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_SELECTOR 0x05U /*Selector Unit Descriptor*/ /*remain two feature uint descriptor macro for compatibility, please use the latter one*/ #define USB_DESC_SUBTYPE_AUDIO_CS_FU 0x06U #define USB_AUDIO_DESC_SUBTYPE_CS_FEATURE 0x06U /*Feature Unit Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_EFEET 0x07U /*Effect Unit Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_PROCESSING 0x08U /*Processing Unit Descriptor*/ /*the following descriptor is not support by Audio version 01*/ #define USB_AUDIO_DESC_SUBTYPE_CS_EXTENSION 0x09U /*Extension Unit Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_CLOCK_SOURE 0x0AU /*Clock Source Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_CLCOK_SELECTOR 0x0BU /*Clock Selector Descriptor*/ #define USB_AUDIO_DESC_SUBTYPE_CS_CLOCK_MULTIPLE 0x0CU /*Clock Multiple Descriptor*/ /*remain two endpoint macro for compatibility, please use the latter one*/ #define USB_DESC_CLASS_ENDPOINT_GENERAL 0x01U #define USB_AUDIO_DESC_CLASS_ENDPOINT_GENERAL 0x01U /*! @brief Audio device class-specific descriptor type */ #define USB_AUDIO_DESCRIPTOR_TYPE_CS_DEVICE (0x21U) #define USB_AUDIO_DESCRIPTOR_TYPE_CS_CONFIGURATION (0x22U) #define USB_AUDIO_DESCRIPTOR_TYPE_CS_STRING (0x23U) #define USB_AUDIO_DESCRIPTOR_TYPE_CS_INTERFACE (0x24U) #define USB_AUDIO_DESCRIPTOR_TYPE_CS_ENDPOINT (0x25U) /*Feature Unit Control Selectors, audio1.0 and audio2.0 can share same featre unit control selector code*/ #define AUDIO_FU_MUTE 0x01U #define AUDIO_FU_VOLUME 0x02U #define AUDIO_FU_BASS 0x03U #define AUDIO_FU_MID 0x04U #define AUDIO_FU_TREBLE 0x05U #define AUDIO_FU_GRAPHIC_EQ 0x06U #define AUDIO_FU_AGC 0x07U #define AUDIO_FU_DELAY 0x08U #define AUDIO_FU_BASS_BOOST 0x09U /*Audio Class-Specific AS Interface Descriptor Subtypes*/ /*audio 1.0*/ /*remain two subtype macro for compatibility, please use the latter one*/ #define USB_DESC_SUBTYPE_AS_CS_GENERAL 0X01U #define USB_DESC_SUBTYPE_AS_CS_FORMAT_TYPE 0X02U #define USB_AUDIO_DESC_SUBTYPE_AS_GENERAL 0x01U #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_TYPE 0x02U #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_SEPCIFIC_TYPE 0x03U /*audio 2.0*/ #define USB_AUDIO_DESC_SUBTYPE_AS_GENERAL_20 0x01U #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_TYPE_20 0x02U #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_ENCODER_20 0x03U #define USB_AUDIO_DESC_SUBTYPE_AS_FORMAT_DECODER_20 0x04U /*Audio1.0 Class-Specific Request Codes*/ #define USB_AUDIO_CS_REQUEST_CODE_SET_CUR 0x01U #define USB_AUDIO_CS_REQUEST_CODE_GET_CUR 0x81U #define USB_AUDIO_CS_REQUEST_CODE_SET_MIN 0x02U #define USB_AUDIO_CS_REQUEST_CODE_GET_MIN 0x82U #define USB_AUDIO_CS_REQUEST_CODE_SET_MAX 0x03U #define USB_AUDIO_CS_REQUEST_CODE_GET_MAX 0x83U #define USB_AUDIO_CS_REQUEST_CODE_SET_RES 0x04U #define USB_AUDIO_CS_REQUEST_CODE_GET_RES 0x84U #define USB_AUDIO_CS_REQUEST_CODE_SET_MEM 0x05U #define USB_AUDIO_CS_REQUEST_CODE_GET_MEN 0x85U #define USB_AUDIO_CS_REQUEST_CODE_GET_STAT 0xFFU /*Audio2.0 Class-Specific Request Codes*/ #define USB_AUDIO_CS_REQUEST_CODE_CUR_20 0x01U #define USB_AUDIO_CS_REQUEST_CODE_RANGE_20 0x02U /*Audio2.0 Clock Source Control Selectors Codes*/ #define USB_AUDIO_CS_SAM_FREQ_CONTROL_20 0x01U #define USB_AUDIO_CS_CLOCK_VALID_CONTROL_20 0x02U /*common audio endpoint type code 00 = Data endpoint 01 = Feedback endpoint 10 = Implicit feedback Data endpoit, usb Spec 9.6*/ #define USB_AUDIO_EP_TYPE_DATA 0x00U #define USB_AUDIO_EP_TYPE_FEEDBACK 0x01U #define USB_AUDIO_EP_TYPE_IMPLICIT 0x02U /*endpoint control selectors*/ /*audio 1.0*/ #define USB_AUDIO_EP_CS_SAMPING_FREQ_CONTROL 0x01U #define USB_AUDIO_EP_CS_PINTCH_CONTROL 0x02U /*audio 2.0*/ #define USB_AUDIO_EP_CS_PINTCH_CONTROL_20 0x01U #define USB_AUDIO_EP_CS_OVERRUN_CONTROL_20 0x02U #define USB_AUDIO_EP_CS_UNDERRUN_CONTROL_20 0x03U struct _usb_audio_2_0_control_range_layout3_struct { uint8_t wNumSubRanges[2]; uint8_t wMIN[4]; uint8_t wMAX[4]; uint8_t wRES[4]; }; typedef struct _usb_audio_2_0_control_range_layout3_struct usb_audio_2_0_control_range_layout3_struct_t; struct _usb_audio_2_0_control_range_layout2_struct { uint8_t wNumSubRanges[2]; uint8_t wMIN[2]; uint8_t wMAX[2]; uint8_t wRES[2]; }; typedef struct _usb_audio_2_0_control_range_layout2_struct usb_audio_2_0_control_range_layout2_struct_t; /*! @brief Audio control interface header descriptor structure */ typedef struct _usb_audio_2_0_ctrl_header_desc { uint8_t blength; /*!< Total size of the header descriptor*/ uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ uint8_t bcdcdc[2]; /*!< Audio Device Class Specification Release Number in Binary-Coded Decimal*/ uint8_t bCategory; /*!< Constant, indicating the primary use of this audio function, as intended by the manufacturer. See Appendix A.7, Audio Function Category Codes.*/ uint8_t wtotallength[2]; /*!< Total number of bytes returned for the class-specific AudioControl interface descriptor. Includes the combined length of this descriptor header and all unit and terminal descriptors.*/ uint8_t bmControls; /*!< D1..0: Latency Control D7..2: Reserved. Must be set to 0.*/ } usb_audio_2_0_ctrl_header_desc_t; /*! @brief Audio control interface clock source descriptor structure */ typedef struct _usb_audio_2_0_ctrl_clock_source_desc { uint8_t blength; /*!< Total size of the header descriptor*/ uint8_t bdescriptortype; /*!< Descriptor type of audio header descriptor*/ uint8_t bdescriptorsubtype; /*!< Subtype of an audio header descriptor*/ uint8_t bClockID; /*!