![]() |
USB Component
Version 6.5
MDK-Professional Middleware for USB Device and Host
|
Implement application specific behavior of an Audio Device Class (ADC) USB Device. More...
Content | |
Configuration | |
Configuration of the USB Device ADC Class in µVision. | |
Functions | |
void | USBD_ADCn_Initialize (void) |
Called during USBD_Initialize to initialize the USB ADC class Device. | |
void | USBD_ADCn_Uninitialize (void) |
Called during USBD_Uninitialize to de-initialize the USB ADC class Device. | |
void | USBD_ADCn_SpeakerStatusEvent (bool active) |
Callback function called when speaker activity (interface) setting changed event. | |
void | USBD_ADCn_SpeakerMuteEvent (uint8_t ch, bool cur) |
Callback function called when speaker mute setting changed event. | |
void | USBD_ADCn_SpeakerVolumeEvent (uint8_t ch, uint16_t cur) |
Callback function called when speaker volume setting changed event. | |
void | USBD_ADCn_MicrophoneStatusEvent (bool active) |
Callback function called when microphone activity (interface) setting changed event. | |
void | USBD_ADCn_MicrophoneMuteEvent (uint8_t ch, bool cur) |
Callback function called when microphone mute setting changed event. | |
void | USBD_ADCn_MicrophoneVolumeEvent (uint8_t ch, uint16_t cur) |
Callback function called when microphone volume setting changed event. | |
usbStatus | USBD_ADC_SpeakerSetVolumeRange (uint8_t instance, uint8_t ch, uint16_t min, uint16_t max, uint16_t res, uint16_t cur) |
Set range for speaker volume control. | |
usbStatus | USBD_ADC_MicrophoneSetVolumeRange (uint8_t instance, uint8_t ch, uint16_t min, uint16_t max, uint16_t res, uint16_t cur) |
Set range for microphone volume (level) control. | |
uint32_t | USBD_ADC_ReceivedSamplesAvailable (uint8_t instance) |
Number of audio samples received from USB Host and available to be read. | |
uint32_t | USBD_ADC_WrittenSamplesPending (uint8_t instance) |
Number of audio samples written and pending to be sent to USB Host. | |
int32_t | USBD_ADC_ReadSamples (uint8_t instance, void *buf, int32_t num) |
Read audio samples received from USB Host. | |
int32_t | USBD_ADC_WriteSamples (uint8_t instance, const void *buf, int32_t num) |
Write audio samples to be transferred to USB Host. | |
Implement application specific behavior of an Audio Device Class (ADC) USB Device.
Use the following class specific functions to customize the functionality of an Audio Device Class (ADC) Device. Adapt these functions in the user code template file USBD_User_ADC_n.c.
Refer to:
The USB Component allows multiple instances of the ADC class. This feature is used to create USB Composite Devices. Each ADC class instance has a separate files and interface functions:
This documentation uses n as a placeholder for the instance number 0 - 3. Most applications only require one instance of an ADC class. For the first ADC class instance the instance number is 0:
Software Structure
The handling for the ADC class endpoint events is implemented in USBD_ADC_Thread which is started by USBD_Initialize. Each instance of an ADC class runs an instance of the USBD_ADC_Thread. This thread handles the Isochronous IN/OUT Endpoints of the USB ADC Device.
To create an USB Device with an ADC class:
User Code Templates
There are two user code templates available that help to add support for an ADC device:
User Code Template USBD_User_ADC.c
The following source code can be used to implement the application specific behavior of an USB ADC Device.
User Code Template USBD_User_ADC_Headphone.c
The following source code can be used to implement the application specific behavior of an USB ADC Headphone Device.
usbStatus USBD_ADC_MicrophoneSetVolumeRange | ( | uint8_t | instance, |
uint8_t | ch, | ||
uint16_t | min, | ||
uint16_t | max, | ||
uint16_t | res, | ||
uint16_t | cur | ||
) |
Set range for microphone volume (level) control.
[in] | instance | instance of ADC class. |
[in] | ch | channel index.
|
[in] | min | minimum volume value. |
[in] | max | maximum volume value. |
[in] | res | volume resolution. |
[in] | cur | current volume value. |
The function USBD_ADC_MicrophoneSetVolumeRange sets the range for the microphone volume control.
The argument instance specifies the instance of the ADC class to be used.
The argument ch specifies the channel on the instance.
The argument min sets the minimum volume level.
The argument max sets the maximum volume level.
The argument res defines the volume resolution.
The argument cur sets the current volume level.
Code Example
int32_t USBD_ADC_ReadSamples | ( | uint8_t | instance, |
void * | buf, | ||
int32_t | num | ||
) |
Read audio samples received from USB Host.
[in] | instance | instance of ADC class. |
[out] | buf | buffer that receives samples. |
[in] | num | maximum number of samples to read. |
The function USBD_ADC_ReadSamples reads audio samples that have been received from an USB Host.
The argument instance specifies the instance of the ADC class to be used.
The argument buf is a pointer to the buffer that stores the received samples. The data type is uint8_t, uint16_t or uint32_t and is specified by the USBD_ADCn_OUT_BBITRESOLUTION in USBD_Config_ADC_n.h file (USBD_ADCn_OUT_BBITRESOLUTION = 8 -> uint8_t, USBD_ADCn_OUT_BBITRESOLUTION = 16 -> uint16_t, USBD_ADCn_OUT_BBITRESOLUTION >= 24 -> uint32_t). If stereo mode is used channels are encoded one sample per channel (0 L, 0 R, 1 L, 1 R, ...)
The argument num specifies the maximum number of samples to be read. For stereo it specifies maximum number of sample pairs (left, right) to be read.
Code Example
uint32_t USBD_ADC_ReceivedSamplesAvailable | ( | uint8_t | instance | ) |
Number of audio samples received from USB Host and available to be read.
[in] | instance | instance of ADC class. |
The function USBD_ADC_ReceivedSamplesAvailable signals the number of audio samples that have been received from the USB Host and are available to be read.
The argument instance specifies the instance of the ADC class to be used.
Code Example
usbStatus USBD_ADC_SpeakerSetVolumeRange | ( | uint8_t | instance, |
uint8_t | ch, | ||
uint16_t | min, | ||
uint16_t | max, | ||
uint16_t | res, | ||
uint16_t | cur | ||
) |
Set range for speaker volume control.
[in] | instance | instance of ADC class. |
[in] | ch | channel index.
|
[in] | min | minimum volume value. |
[in] | max | maximum volume value. |
[in] | res | volume resolution. |
[in] | cur | current volume value. |
The function USBD_ADC_SpeakerSetVolumeRange sets the range for the speaker volume control.
The argument instance specifies the instance of the ADC class to be used.
The argument ch specifies the channel on the instance.
The argument min sets the minimum volume level.
The argument max sets the maximum volume level.
The argument res defines the volume resolution.
The argument cur sets the current volume level.
Code Example
int32_t USBD_ADC_WriteSamples | ( | uint8_t | instance, |
const void * | buf, | ||
int32_t | num | ||
) |
Write audio samples to be transferred to USB Host.
[in] | instance | instance of ADC class. |
[in] | buf | buffer containing samples to write. |
[in] | num | maximum number of samples to write. |
The function USBD_ADC_WriteSamples writes audio samples to be transferred to an USB Host.
The argument instance specifies the instance of the ADC class to be used.
The argument buf is a pointer to the buffer containing the samples to be written. The data type is uint8_t, uint16_t or uint32_t and is specified by the USBD_ADCn_IN_BBITRESOLUTION in USBD_Config_ADC_n.h file (USBD_ADCn_IN_BBITRESOLUTION = 8 -> uint8_t, USBD_ADCn_IN_BBITRESOLUTION = 16 -> uint16_t, USBD_ADCn_IN_BBITRESOLUTION >= 24 -> uint32_t). If stereo mode is used channels are encoded one sample per channel (0 L, 0 R, 1 L, 1 R, ...)
The argument num specifies the maximum number of samples to be written. For stereo it specifies maximum number of sample pairs (left, right) to be written.
Code Example
uint32_t USBD_ADC_WrittenSamplesPending | ( | uint8_t | instance | ) |
Number of audio samples written and pending to be sent to USB Host.
[in] | instance | instance of ADC class. |
The function USBD_ADC_WrittenSamplesPending signals the number of audio samples that have been written and are pending to be sent to the USB Host.
The argument instance specifies the instance of the ADC class to be used.
Code Example
USBD_ADCn_Initialize | ( | void | ) |
Called during USBD_Initialize to initialize the USB ADC class Device.
The function USBD_ADCn_Initialize initializes the hardware resources of the Audio Device Class USB Device. It is called during USBD_Initialize. The function may be used to allocate resources and initialize peripherals. Modify this function to the application needs.
Code Example
USBD_ADCn_MicrophoneMuteEvent | ( | uint8_t | ch, |
bool | cur | ||
) |
Callback function called when microphone mute setting changed event.
[in] | ch | channel index.
|
[in] | cur | current setting. |
The callback function USBD_ADCn_MicrophoneMuteEvent is called when the microphone went to mute/unmute.
The argument ch specifies the channel that is used.
The argument cur specifies the current mute setting.
Code Example
USBD_ADCn_MicrophoneStatusEvent | ( | bool | active | ) |
Callback function called when microphone activity (interface) setting changed event.
[in] | active | activity status. |
The callback function USBD_ADCn_MicrophoneStatusEvent is called when a status change on the microphone has taken place.
The argument active specifies the activity status.
Code Example
USBD_ADCn_MicrophoneVolumeEvent | ( | uint8_t | ch, |
uint16_t | cur | ||
) |
Callback function called when microphone volume setting changed event.
[in] | ch | channel index.
|
[in] | cur | current setting. |
The callback function USBD_ADCn_MicrophoneVolumeEvent is called when the microphone volume has changed.
The argument ch specifies the channel that is used.
The argument cur specifies the current volume setting.
Code Example
USBD_ADCn_SpeakerMuteEvent | ( | uint8_t | ch, |
bool | cur | ||
) |
Callback function called when speaker mute setting changed event.
[in] | ch | channel index.
|
[in] | cur | current setting. |
The callback function USBD_ADCn_SpeakerMuteEvent is called when the speaker went to mute/unmute.
The argument ch specifies the channel that is used.
The argument cur specifies the current mute setting.
Code Example
USBD_ADCn_SpeakerStatusEvent | ( | bool | active | ) |
Callback function called when speaker activity (interface) setting changed event.
[in] | active | activity status. |
The callback function USBD_ADCn_SpeakerStatusEvent is called when a status change on the speaker activity has taken place.
The argument active specifies the activity status.
Code Example
USBD_ADCn_SpeakerVolumeEvent | ( | uint8_t | ch, |
uint16_t | cur | ||
) |
Callback function called when speaker volume setting changed event.
[in] | ch | channel index.
|
[in] | cur | current setting. |
The callback function USBD_ADCn_SpeakerVolumeEvent is called when the speaker volume has changed.
The argument ch specifies the channel that is used.
The argument cur specifies the current volume setting.
Code Example
USBD_ADCn_Uninitialize | ( | void | ) |
Called during USBD_Uninitialize to de-initialize the USB ADC class Device.
The function USBD_ADCn_Uninitialize de-initializes/releases the hardware resources of the Audio Device Class USB Device. It is called during USBD_Uninitialize. If USBD_ADCn_Initialize has been adapted to the application, USBD_ADCn_Uninitialize should release resources and de-initialize peripherals.