?? usb_specific_request.c
字號:
//! @file usb_specific_request.c,v
//!
//! Copyright (c) 2004 Atmel.
//!
//! Use of this program is subject to Atmel's End User License Agreement.
//! Please read file license.txt for copyright notice.
//!
//! @brief user call-back functions
//!
//! This file contains the user call-back functions corresponding to the
//! application:
//! AUDIO MICROPHONE
//!
//! @version 1.1 at90usb128-demo-audio-1_0_2 $Id: usb_specific_request.c,v 1.1 2006/03/17 09:15:46 rletendu Exp $
//!
//! @todo
//! @bug
//_____ I N C L U D E S ____________________________________________________
#include "config.h"
#include "conf_usb.h"
#include "lib_mcu\usb\usb_drv.h"
#include "usb_descriptors.h"
#include "modules\usb\device_chap9\usb_standard_request.h"
#include "usb_specific_request.h"
//_____ M A C R O S ________________________________________________________
//_____ D E F I N I T I O N ________________________________________________
//_____ P R I V A T E D E C L A R A T I O N ______________________________
#ifdef AVRGCC
extern PGM_VOID_P pbuffer;
#else
extern U8 code *pbuffer;
#endif
extern U8 data_to_transfer;
extern bit mute;
extern S16 volume;
//_____ D E C L A R A T I O N ______________________________________________
//! This function is called by the standard usb read request function when
//! the Usb request is not supported. This function returns TRUE when the
//! request is processed. This function returns FALSE if the request is not
//! supported. In this case, a STALL handshake will be automatically
//! sent by the standard usb read request function.
//!
//! @param none
//!
//! @return none
//!
Bool usb_user_read_request(U8 type, U8 request)
{
switch(request)
{
case SET_CUR:
audio_set_cur();
return TRUE;
case SET_MIN: //! Set MIN,MAX and RES not supported
case SET_MAX:
case SET_RES:
return FALSE;
break;
case GET_CUR:
audio_get_cur();
return TRUE;
break;
case GET_MIN:
audio_get_min();
return TRUE;
break;
case GET_MAX:
audio_get_max();
return TRUE;
break;
case GET_RES:
audio_get_res();
return TRUE;
break;
default:
return FALSE;
break;
}
return FALSE;
}
//! @brief This function configures the endpoints.
//!
//! @warning Code:xx bytes (function code length)
//!
//! @param none
//!
//! @return none
//!
void usb_user_endpoint_init(U8 conf_nb)
{
usb_configure_endpoint(EP_AUDIO_IN, \
TYPE_ISOCHRONOUS, \
DIRECTION_IN, \
SIZE_16, \
TWO_BANKS, \
NYET_ENABLED);
}
//! @brief This function returns the size and the pointer on a user information
//! structure
//!
//! @param none
//!
//! @return none
//!
Bool usb_user_get_descriptor(U8 type, U8 string)
{
switch(type)
{
case STRING_DESCRIPTOR:
switch (string)
{
case LANG_ID:
data_to_transfer = sizeof (usb_user_language_id);
pbuffer = &(usb_user_language_id.bLength);
return TRUE;
break;
case MAN_INDEX:
data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor);
pbuffer = &(usb_user_manufacturer_string_descriptor.bLength);
return TRUE;
break;
case PROD_INDEX:
data_to_transfer = sizeof (usb_user_product_string_descriptor);
pbuffer = &(usb_user_product_string_descriptor.bLength);
return TRUE;
break;
case SN_INDEX:
data_to_transfer = sizeof (usb_user_serial_number);
pbuffer = &(usb_user_serial_number.bLength);
return TRUE;
break;
default:
return FALSE;
}
default:
return FALSE;
}
return FALSE;
}
void audio_get_min(void)
{
U16 ep_num;
U16 length;
U16 cs;
LSB(cs)=Usb_read_byte();
MSB(cs)=Usb_read_byte();
LSB(ep_num)=Usb_read_byte();
MSB(ep_num)=Usb_read_byte();
LSB(length)=Usb_read_byte();
MSB(length)=Usb_read_byte();
Usb_ack_receive_setup();
switch (cs)
{
case CS_MUTE:
Usb_write_byte(mute);
break;
case CS_VOLUME:
Usb_write_byte(LOW(VOL_MIN));
Usb_write_byte(HIGH(VOL_MIN));
break;
}
Usb_send_control_in(); /* send a ZLP for STATUS phase */
while(!Is_usb_receive_out());
Usb_ack_receive_out();
}
void audio_get_max(void)
{
U16 ep_num;
U16 length;
U16 cs;
LSB(cs)=Usb_read_byte();
MSB(cs)=Usb_read_byte();
LSB(ep_num)=Usb_read_byte();
MSB(ep_num)=Usb_read_byte();
LSB(length)=Usb_read_byte();
MSB(length)=Usb_read_byte();
Usb_ack_receive_setup();
switch (cs)
{
case CS_MUTE:
Usb_write_byte(mute);
break;
case CS_VOLUME:
Usb_write_byte(LOW(VOL_MAX));
Usb_write_byte(HIGH(VOL_MAX));
break;
}
Usb_send_control_in(); /* send a ZLP for STATUS phase */
while(!Is_usb_receive_out());
Usb_ack_receive_out();
}
void audio_get_res(void)
{
U16 ep_num;
U16 length;
U16 cs;
LSB(cs)=Usb_read_byte();
MSB(cs)=Usb_read_byte();
LSB(ep_num)=Usb_read_byte();
MSB(ep_num)=Usb_read_byte();
LSB(length)=Usb_read_byte();
MSB(length)=Usb_read_byte();
Usb_ack_receive_setup();
switch (cs)
{
case CS_MUTE:
Usb_write_byte(mute);
break;
case CS_VOLUME:
Usb_write_byte(LOW(VOL_RES));
Usb_write_byte(HIGH(VOL_RES));
break;
}
Usb_send_control_in(); /* send a ZLP for STATUS phase */
while(!Is_usb_receive_out());
Usb_ack_receive_out();
}
void audio_get_cur(void)
{
U16 ep_num;
U16 length;
U16 cs;
LSB(cs)=Usb_read_byte();
MSB(cs)=Usb_read_byte();
LSB(ep_num)=Usb_read_byte();
MSB(ep_num)=Usb_read_byte();
LSB(length)=Usb_read_byte();
MSB(length)=Usb_read_byte();
Usb_ack_receive_setup();
switch (cs)
{
case CS_MUTE:
Usb_write_byte(mute);
break;
case CS_VOLUME:
Usb_write_byte(LSB(volume));
Usb_write_byte(MSB(volume));
break;
}
Usb_send_control_in(); /* send a ZLP for STATUS phase */
while(!Is_usb_receive_out());
Usb_ack_receive_out();
}
void audio_set_cur(void)
{
U16 ep_num;
U16 length;
U16 cs;
LSB(cs)=Usb_read_byte();
MSB(cs)=Usb_read_byte();
LSB(ep_num)=Usb_read_byte();
MSB(ep_num)=Usb_read_byte();
LSB(length)=Usb_read_byte();
MSB(length)=Usb_read_byte();
Usb_ack_receive_setup();
Usb_send_control_in();
while(!Is_usb_receive_out());
switch (cs)
{
case CS_MUTE:
mute=Usb_read_byte();
break;
case CS_VOLUME:
LSB(volume)=Usb_read_byte();
MSB(volume)=Usb_read_byte();
break;
}
Usb_ack_receive_out();
Usb_send_control_in();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -