Atmel Software Framework

services/usb/_asf_v1/class/audio/examples/device/enum/device/usb_specific_request.c File Reference
#include "conf_audio_mixer.h"
#include "conf_audio_player.h"
#include "conf_usb.h"
#include "usb_drv.h"
#include "usb_descriptors.h"
#include "usb_standard_request.h"
#include "usb_specific_request.h"
#include "usart.h"
#include "audio_example.h"
#include "usb_stream_player.h"
#include "device_audio_task.h"
#include "hid.h"

Data Structures

struct  st_audio_cmd
 

Macros

#define TARGET_MICRO   2
 
#define TARGET_SPEAKER   1
 
#define TARGET_UNDEFINED   0
 
#define TASKS_SCHEDULE()   device_audio_task()
 

Functions

void audio_micro_get_mute (void)
 
void audio_micro_get_vol_cur (void)
 
void audio_micro_get_vol_max (void)
 
void audio_micro_get_vol_min (void)
 
void audio_micro_get_vol_res (void)
 
void audio_micro_set_mute (void)
 Micro control. More...
 
void audio_micro_set_volume (void)
 
void audio_speaker_get_mute (void)
 
void audio_speaker_get_vol_cur (void)
 
void audio_speaker_get_vol_max (void)
 
void audio_speaker_get_vol_min (void)
 
void audio_speaker_get_vol_res (void)
 
void audio_speaker_set_mute (void)
 Speaker control. More...
 
void audio_speaker_set_sample_freq (void)
 
void audio_speaker_set_volume (void)
 
st_audio_cmd check_audio_control_request (uint16_t wValue)
 Checks if the audio control request is a Feature Unit Control request for the good feature unit and channel. More...
 
static void hid_get_descriptor (uint8_t size_of_report, const uint8_t *p_usb_hid_report)
 This function manages the HID Get_Descriptor request. More...
 
static void usb_hid_get_idle (uint8_t u8_report_id)
 This function manages hid get idle request. More...
 
static void usb_hid_set_idle (uint8_t u8_report_id, uint8_t u8_duration)
 
static void usb_hid_set_report_ouput (void)
 This function manages hit set report request. More...
 
void usb_user_endpoint_init (uint8_t conf_nb)
 This function configures the endpoints of the device application. More...
 
bool usb_user_get_descriptor (uint8_t type, uint8_t string)
 This function returns the size and the pointer on a user information structure. More...
 
bool usb_user_read_request (uint8_t bmRequestType, uint8_t bmRequest)
 This function is called by the standard USB read request function when the USB request is not supported. More...
 
static int16_t volume_usb_to_appli (int16_t usb_volume)
 This function converts the volume from the USB world to the application world. More...
 

Variables

bool b_micro_mute
 Mute control of micro true when ACTIVE, false otherwise. More...
 
bool b_speaker_mute
 Mute control of speaker true when ACTIVE, false otherwise. More...
 
uint16_t data_to_transfer
 
uint8_t g_u8_report_rate =0
 This function manages hid set idle request. More...
 
const void * pbuffer
 
int16_t s16_micro_volume
 Represents the current volume of audio stream micro No effect in this demo. More...
 
int16_t s16_speaker_volume = (SPEAKER_VOL_MIN + SPEAKER_VOL_MAX)/2
 Represents the current volume of audio stream speaker. More...
 
int16_t s16_usb_speaker_volume = (USB_SPEAKER_VOL_MIN + USB_SPEAKER_VOL_MAX)/2
 Represents a copy of the USB volume. More...
 

#define TARGET_MICRO   2
#define TARGET_SPEAKER   1
#define TARGET_UNDEFINED   0

st_audio_cmd check_audio_control_request ( uint16_t  wValue)

Checks if the audio control request is a Feature Unit Control request for the good feature unit and channel.

Returns
the target audio and the Control Selector from request

References AC_INTERFACE_NB, AUDIO_FU_CONTROL_CS_UNDEFINED, cmd, st_audio_cmd::cs, EP_CONTROL, length, LSB, MICRO_FEATURE_UNIT_ID, MSB, SPEAKER_FEATURE_UNIT_ID, st_audio_cmd::target, TARGET_MICRO, TARGET_SPEAKER, TARGET_UNDEFINED, Usb_ack_setup_received_free, and Usb_read_endpoint_data.

Referenced by usb_user_read_request().

static void hid_get_descriptor ( uint8_t  size_of_report,
const uint8_t *  p_usb_hid_report 
)
static

This function manages the HID Get_Descriptor request.

< clear the setup received flag

< zero length packet condition

< send only requested number of data bytes

< Send data until necessary

References data_to_transfer, EP_CONTROL, EP_CONTROL_LENGTH, Is_usb_control_in_ready, Is_usb_control_out_received, Is_usb_nak_out, pbuffer, Usb_ack_control_in_ready_send, Usb_ack_control_out_received_free, Usb_ack_nak_out, Usb_ack_setup_received_free, usb_format_usb_to_mcu_data, Usb_read_endpoint_data, Usb_reset_endpoint_fifo_access, and usb_write_ep_txpacket().

Referenced by usb_user_read_request().

static void usb_hid_get_idle ( uint8_t  u8_report_id)
static

This function manages hid get idle request.

Parameters
u8_report_id0 the idle rate applies to all input reports, else only applies to the Report ID

References EP_CONTROL, g_u8_report_rate, INTERFACE_NB_KBD, Is_usb_control_out_received, Usb_ack_control_in_ready_send, Usb_ack_control_out_received_free, Usb_ack_setup_received_free, usb_format_usb_to_mcu_data, Usb_read_endpoint_data, Usb_reset_endpoint_fifo_access, and Usb_write_endpoint_data.

Referenced by usb_user_read_request().

static void usb_hid_set_idle ( uint8_t  u8_report_id,
uint8_t  u8_duration 
)
static
static void usb_hid_set_report_ouput ( void  )
static
static int16_t volume_usb_to_appli ( int16_t  usb_volume)
static

This function converts the volume from the USB world to the application world.

[USB_SPEAKER_VOL_MIN; USB_SPEAKER_VOL_MAX] => [SPEAKER_VOL_MIN; SPEAKER_VOL_MAX]

References SPEAKER_VOL_MAX, SPEAKER_VOL_MIN, USB_SPEAKER_VOL_MAX, USB_SPEAKER_VOL_MIN, and volume.

Referenced by audio_speaker_set_volume().

bool b_micro_mute

Mute control of micro true when ACTIVE, false otherwise.

Referenced by audio_micro_get_mute(), and audio_micro_set_mute().

bool b_speaker_mute

Mute control of speaker true when ACTIVE, false otherwise.

Referenced by audio_speaker_get_mute(), and audio_speaker_set_mute().

uint8_t g_u8_report_rate =0

This function manages hid set idle request.

Parameters
DurationWhen the upper byte of wValue is 0 (zero), the duration is indefinite else from 0.004 to 1.020 seconds
ReportID 0 the idle rate applies to all input reports, else only applies to the Report ID

Referenced by usb_hid_get_idle(), and usb_hid_set_idle().

int16_t s16_micro_volume

Represents the current volume of audio stream micro No effect in this demo.

Referenced by audio_micro_get_vol_cur(), and audio_micro_set_volume().

int16_t s16_speaker_volume = (SPEAKER_VOL_MIN + SPEAKER_VOL_MAX)/2

Represents the current volume of audio stream speaker.

Referenced by audio_speaker_set_mute(), and audio_speaker_set_volume().

int16_t s16_usb_speaker_volume = (USB_SPEAKER_VOL_MIN + USB_SPEAKER_VOL_MAX)/2

Represents a copy of the USB volume.

The USB volume has a range [USB_SPEAKER_VOL_MIN; USB_SPEAKER_VOL_MAX] and must be converted to the volume of the DAC used. We keep back a copy of the last USB volume since Windows ask for the current volume and a double conversion USB -> appli -> USB may lead to imprecision.

Referenced by audio_speaker_get_vol_cur(), and audio_speaker_set_volume().