Implement application specific behavior of an Audio Device Class (ADC) USB Device.
More...
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 file USBD_User_ADC_Audio_n.c.
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:
The following source code can be used to implement the application specific behavior of an USB ADC Device with Audio Interface.
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "USBD_Config_ADC_%Instance%.h"
#define PLAYBACK_AVAILABLE (USBD_ADC%Instance%_EP_ISO_OUT_EN != 0U)
#define PLAYBACK_CHANNELS (USBD_ADC%Instance%_OUT_CH_NUM)
#define PLAYBACK_FREQ (USBD_ADC%Instance%_OUT_TSAM_FREQ)
#define PLAYBACK_RESOLUTION (USBD_ADC%Instance%_OUT_BBITRESOLUTION)
#if (USBD_ADC%Instance%_OUT_BSUBFRAMESIZE >= 3U)
#define PLAYBACK_SAMPLE_SIZE (4U)
#else
#define PLAYBACK_SAMPLE_SIZE (USBD_ADC%Instance%_OUT_BSUBFRAMESIZE)
#endif
#if (PLAYBACK_CHANNELS > 1U)
#define PLAYBACK_FORMAT (PLAYBACK_SAMPLE_SIZE | ((PLAYBACK_CHANNELS - 1U) << 7))
#else
#define PLAYBACK_FORMAT (PLAYBACK_SAMPLE_SIZE)
#endif
#define PLAYBACK_USB_BUFFER_SAMPLES (USBD_ADC%Instance%_OUT_BUF_SIZE)
#define PLAYBACK_AUDIO_BUFFER_SAMPLES (PLAYBACK_USB_BUFFER_SAMPLES / 8U)
#define PLAYBACK_AUDIO_BUFFER_SIZE ((PLAYBACK_AUDIO_BUFFER_SAMPLES + PLAYBACK_CHANNELS) * PLAYBACK_SAMPLE_SIZE)
#define RECORD_AVAILABLE (USBD_ADC%Instance%_EP_ISO_IN_EN != 0U)
#define RECORD_CHANNELS (USBD_ADC%Instance%_IN_CH_NUM)
#define RECORD_FREQ (USBD_ADC%Instance%_IN_TSAM_FREQ)
#if (USBD_ADC%Instance%_IN_BSUBFRAMESIZE >= 3U)
#define RECORD_SAMPLE_SIZE (4U)
#else
#define RECORD_SAMPLE_SIZE (USBD_ADC%Instance%_IN_BSUBFRAMESIZE)
#endif
#if (RECORD_CHANNELS > 1U)
#define RECORD_FORMAT (RECORD_SAMPLE_SIZE | ((RECORD_CHANNELS - 1U) << 7))
#else
#define RECORD_FORMAT (RECORD_SAMPLE_SIZE)
#endif
#define RECORD_USB_BUFFER_SAMPLES (USBD_ADC%Instance%_IN_BUF_SIZE)
#define RECORD_AUDIO_BUFFER_SAMPLES (RECORD_USB_BUFFER_SAMPLES / 8U)
#define RECORD_AUDIO_BUFFER_SIZE ((RECORD_AUDIO_BUFFER_SAMPLES + RECORD_CHANNELS) * RECORD_SAMPLE_SIZE)
#if (PLAYBACK_AVAILABLE)
#if ((PLAYBACK_CHANNELS == 0U) || (PLAYBACK_CHANNELS > 2U))
#error Playback channel configuration mono or stereo supported!
#endif
#endif
#if (RECORD_AVAILABLE)
#if ((RECORD_CHANNELS == 0U) || (RECORD_CHANNELS > 2U))
#error Recording channel configuration mono or stereo supported!
#endif
#endif
static void AudioCallback (uint32_t event) {
(void)event;
}
#if (PLAYBACK_AVAILABLE)
void USBD_ADC%Instance%_ReceivedSamples (void) {
}
#endif
void USBD_ADC%Instance%_Initialize (void) {
}
void USBD_ADC%Instance%_Uninitialize (void) {
}
#if (PLAYBACK_AVAILABLE)
void USBD_ADC%Instance%_PlayStart (void) {
}
void USBD_ADC%Instance%_PlayStop (void) {
}
void USBD_ADC%Instance%_SetSpeakerMute (uint8_t ch, bool on) {
(void)ch;
(void)on;
}
void USBD_ADC%Instance%_SetSpeakerVolume (uint8_t ch, uint16_t vol) {
(void)ch;
(void)vol;
}
#endif
#if (RECORD_AVAILABLE)
void USBD_ADC%Instance%_RecordStart (void) {
}
void USBD_ADC%Instance%_RecordStop (void) {
}
void USBD_ADC%Instance%_SetMicrophoneMute (uint8_t ch, bool on) {
(void)ch;
(void)on;
}
void USBD_ADC%Instance%_SetMicrophoneVolume (uint8_t ch, uint16_t vol) {
(void)ch;
(void)vol;
}
#endif