[tuxdroid-svn] r1158 - in firmware/fuxusb/trunk: . src
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-05-15 15:10:32
|
Author: Paul_R Date: 2008-05-15 17:10:29 +0200 (Thu, 15 May 2008) New Revision: 1158 Modified: firmware/fuxusb/trunk/fuxusb.Opt firmware/fuxusb/trunk/src/usb_enum.c Log: * Added comments on usb_enum.c * Grouped the functions by requests type (standard, audio and hid specifics). Modified: firmware/fuxusb/trunk/fuxusb.Opt =================================================================== (Binary files differ) Modified: firmware/fuxusb/trunk/src/usb_enum.c =================================================================== --- firmware/fuxusb/trunk/src/usb_enum.c 2008-05-15 14:19:14 UTC (rev 1157) +++ firmware/fuxusb/trunk/src/usb_enum.c 2008-05-15 15:10:29 UTC (rev 1158) @@ -27,6 +27,7 @@ #include "usb_ep.h" #include "spi_task.h" #include "fifo_stt.h" +#include "rf.h" #include "lib_mcu\usb\usb_drv.h" @@ -50,38 +51,30 @@ static void usb_get_interface(void); static void usb_set_interface(void); +/* AUDIO SPECIFIC REQUESTS */ static void usb_get_current(void); static void usb_get_min(void); static void usb_get_max(void); static void usb_get_res(void); - static void usb_set_current(void); static void usb_set_min(void); static void usb_set_max(void); static void usb_set_res(void); +/* HID SPECIFIC REQUESTS */ static void usb_hid_set_report(void); static void usb_hid_set_idle(void); static void usb_hid_get_idle(void); +/* MISC COMMANDS */ static void stall_request(void); static void send_zlp(void); -/*F************************************************************************** - * NAME: usb_var_init - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function initializes the USB controller and resets the endpoints FIFOs. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ + +/** + * \brief Init usb variables. + * This function init the endpoints status, clear the configuration flag and + * clear the Bank variables. + */ void usb_var_init (void) { endpoint_status[1] = 0x00; @@ -94,89 +87,45 @@ CMD_OUT_Bank_Nb = 0; } - -/*F************************************************************************** - * NAME: usb_ep_init - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function configures the endpoints. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Init endpoints. + * Configure the endpoints and reset them. After this functions, the endpoints + * are configured and ready to be used. + */ static void usb_ep_init (void) { usb_configure_endpoint(EP_AUDIO_IN, ISOCHRONOUS_IN); usb_reset_endpoint(EP_AUDIO_IN); + usb_configure_endpoint(EP_AUDIO_OUT, ISOCHRONOUS_OUT); usb_reset_endpoint(EP_AUDIO_OUT); + usb_configure_endpoint(EP_AUDIO_OUT_TTS, ISOCHRONOUS_OUT); usb_reset_endpoint(EP_AUDIO_OUT_TTS); + usb_configure_endpoint(EP_CMD_IN, INTERRUPT_IN); usb_reset_endpoint(EP_CMD_IN); + usb_configure_endpoint(EP_CMD_OUT, INTERRUPT_OUT); usb_reset_endpoint(EP_CMD_OUT); } - - -/*F**************************************************************************** - * NAME: usb_enumeration_process - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the enumeration process - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Enumeration process - main function. + * This is the only one public function for the enumeration process. + * The CONTROL EP is selected, and the request can be parsed. + */ void usb_enumeration_process (void) { Usb_select_ep(EP_CONTROL); usb_read_request(); } - -/*F*************************************************************************** - * NAME: usb_read_request - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function reads the SETUP request sent to the default control endpoint - * and the appropriate function. When exiting of the usb_read_request - * function, the device is ready to manage the next request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: list of supported requests: - * GET_DESCRIPTOR - * GET_CONFIGURATION - * SET_ADDRESS - * SET_CONFIGURATION or SET_REPORT - * CLEAR_FEATURE - * SET_FEATURE - * GET_STATUS - * GET_MAX_LUN - * MASS_STORAGE_RESET - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Read the USB request. + * This function parse the bmRequestType and bRequest. It determine the request + * type, and call the appropriate function. + */ static void usb_read_request (void) { bmRequestType = Usb_read_byte(); /* read bmRequestType */ @@ -185,9 +134,7 @@ printf("RQ:: bmRequestType %BX bRequest %BX ",bmRequestType,bRequest); #endif - //---------------------------------------------------------------- - // Standard Requests - //---------------------------------------------------------------- + /* Standard requests */ if((bmRequestType & 0x60) == 0) { #ifdef USB_ENUM_DEBUG @@ -212,12 +159,11 @@ if (bmRequestType == 0x81) { usb_get_interface(); } else { usb_hid_set_idle(); } break; - case SET_INTERFACE: usb_set_interface(); break; - /* HID Specific request */ + /* HID Specific requests */ case HID_GET_IDLE: usb_hid_get_idle(); break; @@ -234,32 +180,26 @@ break; } } - //---------------------------------------------------------------- - // Class Requests - //---------------------------------------------------------------- + /* Audio specific requests */ else if((bmRequestType & 0x60) == 0x20) { #ifdef USB_ENUM_DEBUG printf(" Class Request "); #endif - switch (bRequest) /* test the bRequest value */ + switch (bRequest) { case GET_CURRENT: usb_get_current(); break; - case GET_MIN: usb_get_min(); break; - case GET_MAX: usb_get_max(); break; - case GET_RES: usb_get_res(); break; - default: #ifdef USB_ENUM_DEBUG printf("Unknown Request "); @@ -268,7 +208,6 @@ stall_request(); break; } - } else { @@ -278,130 +217,68 @@ Usb_clear_rx_setup(); stall_request(); } - #ifdef USB_ENUM_DEBUG printf("\n"); #endif - Usb_clear_DIR(); } - -/*F************************************************************************** - * NAME: usb_set_address - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the SET_ADDRESS request. The new address is stored - * in the USBADDR register - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** \brief Set the address. + * When a set adress request has been received, the adress must be stored in the + * USBADDR register. + */ static void usb_set_address (void) { - uint8_t add; + uint8_t address; - add = Usb_read_byte(); /* store the LSB of wValue = address */ + address = Usb_read_byte(); Usb_clear_rx_setup(); Usb_set_FADDEN(); send_zlp(); - Usb_configure_address(add); + Usb_configure_address(address); #ifdef USB_ENUM_DEBUG - printf("SET_ADDRESSE %BX",add); + printf("SET_ADDRESSE %BX",address); #endif } - -/*F*************************************************************************** - * NAME: usb_set_configuration - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the SET_CONFIGURATION request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Set configuration parser. + * When a SET_CONFIGURATION request has been received, the request is parsed. + * This allow to execute some specifics tasks depending of the config. + */ static void usb_set_configuration (void) { - // R modif - long tc; - // uint8_t configuration_number; - configuration_number = Usb_read_byte(); /* read the conf. num. in wValue */ + + configuration_number = Usb_read_byte(); Usb_clear_DIR(); Usb_clear_rx_setup(); if (configuration_number <= CONF_NB) { -// XXX usb_configuration_nb = configuration_number; if (configuration_number == 1) { -// uint16_t i; - // XXX - rf_reset_signal = 0; - // R modif - tc=32000; - while(tc) - tc--; - - rf_reset_signal = 1; - // Fin r modif - //Led_0_on(); -// XXX + reset_rf(); spi_task_init(); -// FIFO_MIC_init(); // Modif de test -// FIFO_SPK_init(); // Modif de test FIFO_STT_init(); -// spi_task_on_Flag = 1; } + send_zlp(); + usb_ep_init(); /* endpoints configuration */ + Usb_set_CONFG(); +#ifdef USB_ENUM_DEBUG + printf("SET_CONFIG configuration_number : %BX",configuration_number); +#endif } else - { stall_request(); - return; - } - - send_zlp(); - usb_ep_init(); /* endpoints configuration */ - Usb_set_CONFG(); - -#ifdef USB_ENUM_DEBUG - printf("SET_CONFIG configuration_number : %BX",configuration_number); -#endif } - -/*F*************************************************************************** - * NAME: usb_set_interface - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the SET_INTERFACE request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Set interface. + * When a SET_INTERFACE request has been received, the request is parsed. + * This allows to execute specific code depending of the interface. + */ static void usb_set_interface (void) { uint8_t LAlternateSetting; @@ -410,10 +287,10 @@ uint8_t Linterface_number; uint8_t Hinterface_number; - LAlternateSetting = Usb_read_byte(); /* read the conf. num. in wValue */ - HAlternateSetting = Usb_read_byte(); /* read the conf. num. in wValue */ - Linterface_number = Usb_read_byte(); /* read the conf. num. in wValue */ - Hinterface_number = Usb_read_byte(); /* read the conf. num. in wValue */ + LAlternateSetting = Usb_read_byte(); + HAlternateSetting = Usb_read_byte(); + Linterface_number = Usb_read_byte(); + Hinterface_number = Usb_read_byte(); Usb_clear_DIR(); Usb_clear_rx_setup(); @@ -425,22 +302,9 @@ #endif } -/*F*************************************************************************** - * NAME: usb_get_descriptor - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the GET_DESCRIPTOR request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Parse the GET_DESCRIPTOR request and send back the correct descriptor. + */ static void usb_get_descriptor (void) { uint16_t data_to_transfer; @@ -449,9 +313,10 @@ uint8_t string_type; zlp = False; /* no zero length packet */ - string_type = Usb_read_byte(); /* read LSB of wValue */ - descriptor_type = Usb_read_byte(); /* read MSB of wValue */ + string_type = Usb_read_byte(); + descriptor_type = Usb_read_byte(); + #ifdef USB_ENUM_DEBUG printf("GET_DESCRIPTOR %BX %BX ",descriptor_type,string_type); #endif @@ -466,7 +331,6 @@ #endif break; } - case CONFIGURATION: { data_to_transfer = sizeof (usb_configuration); @@ -476,14 +340,12 @@ #endif break; } - case REPORT: { data_to_transfer = SIZE_OF_REPORT; pbuffer = &(usb_configuration.rep[0]); break; } - case HID: { data_to_transfer = sizeof(usb_configuration.HIDStandardDescriptor); @@ -497,7 +359,6 @@ #endif switch (string_type) { - case LANG_ID: { data_to_transfer = sizeof (usb_language); @@ -507,7 +368,6 @@ #endif break; } - case MAN_STRING_INDEX: { data_to_transfer = sizeof (usb_manufacturer); @@ -600,8 +460,10 @@ ACC = Usb_read_byte(); /* don't care of wIndex field */ ACC = Usb_read_byte(); + ((uint8_t *)&wLength)[1] = Usb_read_byte(); /* read wLength */ ((uint8_t *)&wLength)[0] = Usb_read_byte(); + if (wLength > data_to_transfer) { if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = True; } @@ -628,7 +490,6 @@ #ifdef USB_ENUM_DEBUG printf("2"); #endif - return; } } @@ -644,10 +505,8 @@ #ifdef USB_ENUM_DEBUG printf("3"); #endif - return; } - if (zlp == True) { usb_send_ep0_packet(pbuffer, 0); @@ -660,7 +519,6 @@ #ifdef USB_ENUM_DEBUG printf("4"); #endif - return; } @@ -671,7 +529,6 @@ #ifdef USB_ENUM_DEBUG printf("5"); #endif - return; } @@ -686,22 +543,187 @@ } -/*F************************************************************************** - * NAME: usb_get_current - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Get configuration number. + * The host want to know what's the current configuration number. + */ +static void usb_get_configuration (void) +{ + Usb_clear_rx_setup(); + Usb_set_DIR(); + + Usb_write_byte(usb_configuration_nb); + + Usb_set_tx_ready(); + while (!(Usb_tx_complete())); + Usb_clear_tx_complete(); + while (!(Usb_rx_complete())); + Usb_clear_rx(); + Usb_clear_DIR(); +} + +/** + * \brief Get interface request. + * The host want to know the status of a specific interface. + * This function isn't implemented. + */ +static void usb_get_interface (void) +{ + Usb_clear_rx_setup(); + Usb_set_DIR(); + stall_request(); + Usb_clear_DIR(); +} + + +/** + * \brief GET_STATUS request. + * The host want to know the status of the device. + * The request is parsed to send back the wanted information. + */ +static void usb_get_status (void) +{ + uint8_t wIndex; + + ACC = Usb_read_byte(); /* dummy read */ + ACC = Usb_read_byte(); /* dummy read */ + wIndex = Usb_read_byte(); + Usb_clear_rx_setup(); + Usb_set_DIR(); + switch(bmRequestType) + { + case REQUEST_DEVICE_STATUS: + Usb_write_byte(SELF_POWERED); + break; + + case REQUEST_INTERFACE_STATUS: + Usb_write_byte(0x00); + break; + + case REQUEST_ENDPOINT_STATUS: + wIndex = wIndex & MSK_EP_DIR; + Usb_write_byte(endpoint_status[wIndex]); + break; + } + Usb_write_byte(0x00); + + Usb_set_tx_ready(); + while ((!(Usb_tx_complete())) || (Usb_setup_received())); + Usb_clear_tx_complete(); + while ((!(Usb_rx_complete())) || (Usb_setup_received())); + Usb_clear_rx(); + Usb_clear_DIR(); +} + +/** + * \brief SET_FEATURE request. + * The host want to enable a feature on a device, inteface or EP. + */ +static void usb_set_feature (void) +{ + if (bmRequestType == ZERO_TYPE) + { + Usb_clear_rx_setup(); + stall_request(); + } + if (bmRequestType == INTERFACE_TYPE) + { + Usb_clear_rx_setup(); + stall_request(); + } + if (bmRequestType == ENDPOINT_TYPE) + { + if (Usb_read_byte() == 0x00) + { + ACC = Usb_read_byte(); /* dummy read */ + switch (Usb_read_byte()) /* check wIndex */ + { + case ENDPOINT_1: + { + Usb_select_ep(EP_IN); + Usb_set_stall_request(); + Usb_select_ep(EP_CONTROL); + endpoint_status[EP_IN] = 0x01; + Usb_clear_rx_setup(); + Usb_set_tx_ready(); + while (!(Usb_tx_complete())); + Usb_clear_tx_complete(); + break; + } + default: + { + Usb_clear_rx_setup(); + stall_request(); + break; + } + } + } + } +} + +/** + * \brief CLEAR_FEATURE request. + * The host want to disable a feature on a device, interface or EP. + */ +static void usb_clear_feature (void) +{ + if (bmRequestType == ZERO_TYPE) + { + Usb_clear_rx_setup(); + stall_request(); + } + if (bmRequestType == INTERFACE_TYPE) + { + Usb_clear_rx_setup(); + stall_request(); + } + if (bmRequestType == ENDPOINT_TYPE) + { + if (Usb_read_byte() == 0x00) + { + ACC = Usb_read_byte(); /* dummy read */ + switch (Usb_read_byte()) /* check wIndex */ + { + case ENDPOINT_1: + { + Usb_select_ep(EP_IN); + Usb_clear_stall_request(); + usb_reset_endpoint(EP_IN); + Usb_select_ep(EP_CONTROL); + endpoint_status[EP_IN] = 0x00; + Usb_clear_rx_setup(); + Usb_set_tx_ready(); + while (!(Usb_tx_complete())); + Usb_clear_tx_complete(); + break; + } + case ENDPOINT_0: + { + Usb_clear_rx_setup(); + Usb_set_tx_ready(); + while (!(Usb_tx_complete())); + Usb_clear_tx_complete(); + break; + } + default: + { + Usb_clear_rx_setup(); + stall_request(); + break; + } + } + } + } +} + +/* AUDIO SPECIFIC REQUESTS */ + +/** + * \brief Get current setting attribute. + * This is an audio specific request. The host requests the current setting + * value. + * This function isn't implemented. The current level is 0. + */ static void usb_get_current (void) { uint8_t LwValue = Usb_read_byte(); @@ -725,15 +747,12 @@ printf("GET CURRENT %BX %BX %BX %BX Answer",LwValue,HwValue,\ LwIndex,HwIndex); #endif - - -#ifdef USB_ENUM_DEBUG - printf("GET CURRENT %BX %BX %BX %BX STALL",LwValue,HwValue,\ - LwIndex,HwIndex); -#endif - } +/** + * \brief Get the minimum setting attribute. + * This function isn't implemented. The min value is 0. + */ static void usb_get_min (void) { uint8_t LwValue = Usb_read_byte(); @@ -756,10 +775,12 @@ #ifdef USB_ENUM_DEBUG printf("GET MIN %BX %BX %BX %BX Answer",LwValue,HwValue,LwIndex,HwIndex); #endif - - } +/** + * \brief Get the maximum setting attribute. + * This function isn't implemented. The max value is 10. + */ static void usb_get_max (void) { uint8_t LwValue = Usb_read_byte(); @@ -782,10 +803,12 @@ #ifdef USB_ENUM_DEBUG printf("GET MAX %BX %BX %BX %BX Answer",LwValue,HwValue,LwIndex,HwIndex); #endif - - } +/** + * \brief Get the volume step setting attribute. + * This function isn't implemented, the resolution is 1. + */ static void usb_get_res (void) { uint8_t LwValue = Usb_read_byte(); @@ -808,27 +831,12 @@ #ifdef USB_ENUM_DEBUG printf("GET RES %BX %BX %BX %BX Answer",LwValue,HwValue,LwIndex,HwIndex); #endif - - } - -/*F************************************************************************** - * NAME: usb_set_current - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ +/** + * \brief Set the current setting attribute. + * This request define the current value. This function isn't implemented. + */ static void usb_set_current (void) { uint8_t LwValue = Usb_read_byte(); @@ -846,13 +854,12 @@ printf("SET CURRENT %BX %BX %BX %BX Answer",LwValue,HwValue,\ LwIndex,HwIndex); #endif - -#ifdef USB_ENUM_DEBUG - printf("GET CURRENT %BX %BX %BX %BX STALL",LwValue,HwValue,LwIndex,HwIndex); -#endif - } +/** + * \brief Set minimum setting attribute. + * This function isn't implemented. + */ static void usb_set_min (void) { uint8_t LwValue = Usb_read_byte(); @@ -869,10 +876,12 @@ #ifdef USB_ENUM_DEBUG printf("SET MIN %BX %BX %BX %BX Answer",LwValue,HwValue,LwIndex,HwIndex); #endif - - } +/** + * \brief Set maximum setting attribute. + * This function isn't implemented. + */ static void usb_set_max (void) { uint8_t LwValue = Usb_read_byte(); @@ -889,10 +898,12 @@ #ifdef USB_ENUM_DEBUG printf("SET MAX %BX %BX %BX %BX Answer",LwValue,HwValue,LwIndex,HwIndex); #endif - - } +/** + * \brief Set current setting attribute. + * This function isn't implemented. + */ static void usb_set_res (void) { uint8_t LwValue = Usb_read_byte(); @@ -909,259 +920,15 @@ #ifdef USB_ENUM_DEBUG printf("SET RES %BX %BX %BX %BX Answer",LwValue,HwValue,LwIndex,HwIndex); #endif - - } -/*F************************************************************************** - * NAME: usb_get_configuration - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the GET_CONFIGURATION request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ -static void usb_get_configuration (void) -{ - Usb_clear_rx_setup(); - Usb_set_DIR(); +/* HID SPECIFIC REQUESTS */ - Usb_write_byte(usb_configuration_nb); - - Usb_set_tx_ready(); - while (!(Usb_tx_complete())); - Usb_clear_tx_complete(); - while (!(Usb_rx_complete())); - Usb_clear_rx(); - Usb_clear_DIR(); -} - -/*F************************************************************************** - * NAME: usb_get_interface - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the GET_INTERFACE request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ -static void usb_get_interface (void) -{ - Usb_clear_rx_setup(); - Usb_set_DIR(); - stall_request(); - Usb_clear_DIR(); -} - - -/*F************************************************************************** - * NAME: usb_get_status - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the GET_STATUS request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ -static void usb_get_status (void) -{ - uint8_t wIndex; - - ACC = Usb_read_byte(); /* dummy read */ - ACC = Usb_read_byte(); /* dummy read */ - wIndex = Usb_read_byte(); - Usb_clear_rx_setup(); - Usb_set_DIR(); - switch(bmRequestType) - { - case REQUEST_DEVICE_STATUS: - Usb_write_byte(SELF_POWERED); - break; - - case REQUEST_INTERFACE_STATUS: - Usb_write_byte(0x00); - break; - - case REQUEST_ENDPOINT_STATUS: - wIndex = wIndex & MSK_EP_DIR; - Usb_write_byte(endpoint_status[wIndex]); - break; - } - Usb_write_byte(0x00); - - Usb_set_tx_ready(); - while ((!(Usb_tx_complete())) || (Usb_setup_received())); - Usb_clear_tx_complete(); - while ((!(Usb_rx_complete())) || (Usb_setup_received())); - Usb_clear_rx(); - Usb_clear_DIR(); -} - - -/*F************************************************************************** - * NAME: usb_set_feature - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the SET_FEATURE request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ -static void usb_set_feature (void) -{ - if (bmRequestType == ZERO_TYPE) - { - Usb_clear_rx_setup(); - stall_request(); - } - if (bmRequestType == INTERFACE_TYPE) - { - Usb_clear_rx_setup(); - stall_request(); - } - if (bmRequestType == ENDPOINT_TYPE) - { - if (Usb_read_byte() == 0x00) - { - ACC = Usb_read_byte(); /* dummy read */ - switch (Usb_read_byte()) /* check wIndex */ - { - case ENDPOINT_1: - { - Usb_select_ep(EP_IN); - Usb_set_stall_request(); - Usb_select_ep(EP_CONTROL); - endpoint_status[EP_IN] = 0x01; - Usb_clear_rx_setup(); - Usb_set_tx_ready(); - while (!(Usb_tx_complete())); - Usb_clear_tx_complete(); - break; - } - default: - { - Usb_clear_rx_setup(); - stall_request(); - break; - } - } - } - } -} - - -/*F************************************************************************** - * NAME: usb_clear_feature - *---------------------------------------------------------------------------- - * PARAMS: - * - * return: - *---------------------------------------------------------------------------- - * PURPOSE: - * This function manages the SET_FEATURE request. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ -static void usb_clear_feature (void) -{ - if (bmRequestType == ZERO_TYPE) - { - Usb_clear_rx_setup(); - stall_request(); - } - if (bmRequestType == INTERFACE_TYPE) - { - Usb_clear_rx_setup(); - stall_request(); - } - if (bmRequestType == ENDPOINT_TYPE) - { - if (Usb_read_byte() == 0x00) - { - ACC = Usb_read_byte(); /* dummy read */ - switch (Usb_read_byte()) /* check wIndex */ - { - case ENDPOINT_1: - { - Usb_select_ep(EP_IN); - Usb_clear_stall_request(); - usb_reset_endpoint(EP_IN); - Usb_select_ep(EP_CONTROL); - endpoint_status[EP_IN] = 0x00; - Usb_clear_rx_setup(); - Usb_set_tx_ready(); - while (!(Usb_tx_complete())); - Usb_clear_tx_complete(); - break; - } - case ENDPOINT_0: - { - Usb_clear_rx_setup(); - Usb_set_tx_ready(); - while (!(Usb_tx_complete())); - Usb_clear_tx_complete(); - break; - } - default: - { - Usb_clear_rx_setup(); - stall_request(); - break; - } - } - } - } -} - -/*F************************************************************************** -* NAME: usb_hid_set_report -*---------------------------------------------------------------------------- -* PARAMS: -* -* return: -*---------------------------------------------------------------------------- -* PURPOSE: -* This function manages the SET_REPORT request (HID Class) -*---------------------------------------------------------------------------- -* EXAMPLE: -*---------------------------------------------------------------------------- -* NOTE: -*---------------------------------------------------------------------------- -* REQUIREMENTS: -*****************************************************************************/ +/** + * \brief HID_SET_REPORT request. + * This function is used to receive a report using a control transfert. + * HID use interrupt transfert, so this function isn't implemented. + */ static void usb_hid_set_report (void) { Usb_clear_rx_setup(); @@ -1172,49 +939,24 @@ send_zlp(); } - - -/*F************************************************************************** -* NAME: usb_hid_set_idle -*---------------------------------------------------------------------------- -* PARAMS: -* -* return: -*---------------------------------------------------------------------------- -* PURPOSE: -* This function manages the HID_SET_IDLE request. -*---------------------------------------------------------------------------- -* EXAMPLE: -*---------------------------------------------------------------------------- -* NOTE: -*---------------------------------------------------------------------------- -* REQUIREMENTS: -*****************************************************************************/ +/** + * \brief SET_IDLE request. + * This request is used to save bandwidth by limiting the reporting frequency of + * an interrupt EP when data hasn't changed since the last report. + */ static void usb_hid_set_idle (void) { ACC = Usb_read_byte(); - hid_idle_duration = Usb_read_byte(); /* wValue contains the duration */ + hid_idle_duration = Usb_read_byte(); Usb_clear_rx_setup(); send_zlp(); } -/*F************************************************************************** -* NAME: usb_hid_get_idle -*---------------------------------------------------------------------------- -* PARAMS: -* -* return: -*---------------------------------------------------------------------------- -* PURPOSE: -* This function manages the GET_IDLE request. -*---------------------------------------------------------------------------- -* EXAMPLE: -*---------------------------------------------------------------------------- -* NOTE: -*---------------------------------------------------------------------------- -* REQUIREMENTS: -*****************************************************************************/ +/** + * \brief HID_GET_IDLE request. + * The host want to know the current idle rate. + */ static void usb_hid_get_idle (void) { Usb_clear_rx_setup(); @@ -1228,6 +970,11 @@ Usb_clear_DIR(); } +/* MISC FUNCTIONS */ + +/** + * \brief Send a stall request. (handshake). + */ static void stall_request(void) { Usb_set_stall_request(); @@ -1236,6 +983,9 @@ Usb_clear_stalled(); } +/** + * \brief This function send a zero length packet. + */ static void send_zlp(void) { Usb_set_tx_ready(); |