USB Component  Version 6.6
MDK-Professional Middleware for USB Device and Host
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
User API

User API reference of the Audio Device Class. More...

Functions

void USBD_ADCn_Initialize (void)
 Called during USBD_Initialize to initialize the USB ADC class instance.
 
void USBD_ADCn_Uninitialize (void)
 Called during USBD_Uninitialize to de-initialize the USB ADC class instance.
 
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.
 

Description

User API reference of the Audio Device Class.

Function Documentation

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.

Parameters
[in]instanceinstance of ADC class.
[in]chchannel index.
  • value 0: master channel
  • value 1: left microphone (in stereo mode)
  • value 2: right microphone (in stereo mode)
[in]minminimum volume value.
[in]maxmaximum volume value.
[in]resvolume resolution.
[in]curcurrent volume value.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

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

USBD_ADC_MicrophoneSetVolumeRange (0, 0, 0, 100, 1, 50);
int32_t USBD_ADC_ReadSamples ( uint8_t  instance,
void *  buf,
int32_t  num 
)

Read audio samples received from USB Host.

Parameters
[in]instanceinstance of ADC class.
[out]bufbuffer that receives samples.
[in]nummaximum number of samples to read.
Returns
number of samples read or execution status.
  • value >= 0: number of samples read
  • value < 0: error occurred, -value is execution status as defined with usbStatus

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

uint16_t spkr_data[1024];
USBD_ADC_ReadSamples (0, (void *)spkr_data, 1024);
uint32_t USBD_ADC_ReceivedSamplesAvailable ( uint8_t  instance)

Number of audio samples received from USB Host and available to be read.

Parameters
[in]instanceinstance of ADC class.
Returns
number of samples available to be read.

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

uint16_t spkr_data[1024];
// If number of samples available is more than 1024 read new samples
USBD_ADC_ReadSamples (0, (void *)spkr_data, 1024);
}
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.

Parameters
[in]instanceinstance of ADC class.
[in]chchannel index.
  • value 0: master channel
  • value 1: left speaker (in stereo mode)
  • value 2: right speaker (in stereo mode)
[in]minminimum volume value.
[in]maxmaximum volume value.
[in]resvolume resolution.
[in]curcurrent volume value.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

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

USBD_ADC_SpeakerSetVolumeRange (0, 0, 0, 100, 1, 50);
int32_t USBD_ADC_WriteSamples ( uint8_t  instance,
const void *  buf,
int32_t  num 
)

Write audio samples to be transferred to USB Host.

Parameters
[in]instanceinstance of ADC class.
[in]bufbuffer containing samples to write.
[in]nummaximum number of samples to write.
Returns
number of samples written or execution status.
  • value >= 0: number of samples written for sending
  • value < 0: error occurred, -value is execution status as defined with usbStatus

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

uint16_t mic_data[1024];
USBD_ADC_WriteSamples (0, (void *)mic_data, 1024);
uint32_t USBD_ADC_WrittenSamplesPending ( uint8_t  instance)

Number of audio samples written and pending to be sent to USB Host.

Parameters
[in]instanceinstance of ADC class.
Returns
number of samples ready to be sent.

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

uint16_t mic_data[1024];
// If number of samples pending is below 1024 write more samples
USBD_ADC_WriteSamples (0, (void *)mic_data, 1024);
}
USBD_ADCn_Initialize ( void  )

Called during USBD_Initialize to initialize the USB ADC class instance.

Returns
none.

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's needs.

Code Example

void USBD_ADC0_Initialize (void) {
USBD_ADC_SpeakerSetVolumeRange (0, 0, 0, 100, 1, 50);
USBD_ADC_MicrophoneSetVolumeRange (0, 0, 0, 100, 1, 50);
}
USBD_ADCn_MicrophoneMuteEvent ( uint8_t  ch,
bool  cur 
)

Callback function called when microphone mute setting changed event.

Parameters
[in]chchannel index.
  • value 0: master channel
  • value 1: left microphone (in stereo mode)
  • value 2: right microphone (in stereo mode)
[in]curcurrent setting.
Returns
none.

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

void USBD_ADC0_MicrophoneMuteEvent (uint8_t ch, bool cur) {
if (cur) {
// start scaling samples to 0
} else {
// start scaling samples to volume
}
}
USBD_ADCn_MicrophoneStatusEvent ( bool  active)

Callback function called when microphone activity (interface) setting changed event.

Parameters
[in]activeactivity status.
Returns
none.

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

void USBD_ADC0_MicrophoneStatusEvent (bool active) {
if (active) {
// start acquiring microphone samples
} else {
// stop acquiring microphone samples
}
}
USBD_ADCn_MicrophoneVolumeEvent ( uint8_t  ch,
uint16_t  cur 
)

Callback function called when microphone volume setting changed event.

Parameters
[in]chchannel index.
  • value 0: master channel
  • value 1: left microphone (in stereo mode)
  • value 2: right microphone (in stereo mode)
[in]curcurrent setting.
Returns
none.

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

void USBD_ADC0_MicrophoneVolumeEvent (uint8_t ch, uint16_t cur) {
// store new volume and use it for scaling samples
}
USBD_ADCn_SpeakerMuteEvent ( uint8_t  ch,
bool  cur 
)

Callback function called when speaker mute setting changed event.

Parameters
[in]chchannel index.
  • value 0: master channel
  • value 1: left speaker (in stereo mode)
  • value 2: right speaker (in stereo mode)
[in]curcurrent setting.
Returns
none.

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

void USBD_ADC0_SpeakerMuteEvent (uint8_t ch, bool cur) {
if (cur) {
// start scaling samples to 0
} else {
// start scaling samples to volume
}
}
USBD_ADCn_SpeakerStatusEvent ( bool  active)

Callback function called when speaker activity (interface) setting changed event.

Parameters
[in]activeactivity status.
Returns
none.

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

void USBD_ADC0_SpeakerStatusEvent (bool active) {
if (active) {
// start playing samples
} else {
// stop playing samples
}
}
USBD_ADCn_SpeakerVolumeEvent ( uint8_t  ch,
uint16_t  cur 
)

Callback function called when speaker volume setting changed event.

Parameters
[in]chchannel index.
  • value 0: master channel
  • value 1: left speaker (in stereo mode)
  • value 2: right speaker (in stereo mode)
[in]curcurrent setting.
Returns
none.

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

void USBD_ADC0_SpeakerVolumeEvent (uint8_t ch, uint16_t cur) {
// store new volume and use it for scaling samples
}
USBD_ADCn_Uninitialize ( void  )

Called during USBD_Uninitialize to de-initialize the USB ADC class instance.

Returns
none.

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.