#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"#include "lib_mcu/flash/flash_drv.h"
Go to the source code of this file.
Functions | |
| void | hid_get_report_descriptor (void) |
| void | usb_hid_set_report_ouput (void) |
| void | usb_hid_set_idle (U8 u8_report_id, U8 u8_duration) |
| void | usb_hid_get_idle (U8 u8_report_id) |
| void | hid_get_hid_descriptor (void) |
| Bool | usb_user_read_request (U8 type, U8 request) |
| This function checks the specific request and if known then processes it | |
| void | usb_user_endpoint_init (U8 conf_nb) |
| U8 | usb_user_interface_get (U16 wInterface) |
| void | usb_user_interface_reset (U16 wInterface, U8 alternate_setting) |
| Bool | usb_user_get_descriptor (U8 type, U8 string) |
| This function fills the global descriptor. | |
Variables | |
| U8 code * | pbuffer |
| U8 | data_to_transfer |
| code S_usb_hid_report_descriptor_mouse | usb_hid_report_descriptor_mouse |
| U8 | g_u8_report_rate = 0 |
Definition in file usb_specific_request.c.
| void hid_get_report_descriptor | ( | void | ) |
This function manages hit get repport request.
Definition at line 268 of file usb_specific_request.c.
References data_to_transfer, EP_CONTROL_LENGTH, FALSE, Is_usb_read_control_enabled, Is_usb_receive_out, LSB, MSB, pbuffer, S_usb_hid_report_descriptor_mouse::report, TRUE, Usb_ack_receive_out, Usb_ack_receive_setup, usb_hid_report_descriptor_mouse, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.
Referenced by usb_user_read_request().
00269 { 00270 U16 wLength; 00271 U8 nb_byte; 00272 bit zlp = FALSE; 00273 U16 wInterface; 00274 00275 LSB(wInterface)=Usb_read_byte(); 00276 MSB(wInterface)=Usb_read_byte(); 00277 00278 data_to_transfer = sizeof(usb_hid_report_descriptor_mouse); 00279 pbuffer = &(usb_hid_report_descriptor_mouse.report[0]); 00280 00281 LSB(wLength) = Usb_read_byte(); 00282 MSB(wLength) = Usb_read_byte(); 00283 Usb_ack_receive_setup(); 00284 00285 if (wLength > data_to_transfer) 00286 { 00287 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; } 00288 else { zlp = FALSE; } 00289 } 00290 else 00291 { 00292 data_to_transfer = (U8)wLength; // send only requested number of data 00293 } 00294 00295 while((data_to_transfer != 0) && (!Is_usb_receive_out())) 00296 { 00297 while(!Is_usb_read_control_enabled()); 00298 00299 nb_byte=0; 00300 while(data_to_transfer != 0) // Send data until necessary 00301 { 00302 if(nb_byte++==EP_CONTROL_LENGTH) // Check endpoint 0 size 00303 { 00304 break; 00305 } 00306 #ifndef __GNUC__ 00307 Usb_write_byte(*pbuffer++); 00308 #else // AVRGCC does not support point to PGM space 00309 //warning with AVRGCC assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory 00310 Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++)); 00311 #endif 00312 data_to_transfer --; 00313 } 00314 Usb_send_control_in(); 00315 } 00316 00317 if(Is_usb_receive_out()) 00318 { 00319 // abort from Host 00320 Usb_ack_receive_out(); 00321 return; 00322 } 00323 if(zlp == TRUE) 00324 { 00325 while(!Is_usb_read_control_enabled()); 00326 Usb_send_control_in(); 00327 } 00328 00329 while(!Is_usb_receive_out()); 00330 Usb_ack_receive_out(); 00331 }
| void usb_hid_set_report_ouput | ( | void | ) |
This function manages hit set report request.
Definition at line 336 of file usb_specific_request.c.
References Is_usb_receive_out, Usb_ack_receive_out, Usb_ack_receive_setup, and Usb_send_control_in.
Referenced by usb_user_read_request().
00337 { 00338 Usb_ack_receive_setup(); 00339 Usb_send_control_in(); 00340 00341 while(!Is_usb_receive_out()); 00342 Usb_ack_receive_out(); 00343 Usb_send_control_in(); 00344 }
This function manages hid set idle request.
| Duration | When the upper byte of wValue is 0 (zero), the duration is indefinite else from 0.004 to 1.020 seconds | |
| Report | ID 0 the idle rate applies to all input reports, else only applies to the Report ID |
Definition at line 352 of file usb_specific_request.c.
References g_u8_report_rate, Is_usb_in_ready, LSB, MSB, Usb_ack_receive_setup, Usb_read_byte, and Usb_send_control_in.
Referenced by usb_user_read_request().
00353 { 00354 U16 wInterface; 00355 00356 // Get interface number to put in idle mode 00357 LSB(wInterface)=Usb_read_byte(); 00358 MSB(wInterface)=Usb_read_byte(); 00359 Usb_ack_receive_setup(); 00360 00361 g_u8_report_rate = u8_duration; 00362 00363 Usb_send_control_in(); 00364 while(!Is_usb_in_ready()); 00365 }
| void usb_hid_get_idle | ( | U8 | u8_report_id | ) |
This function manages hid get idle request.
| Report | ID 0 the idle rate applies to all input reports, else only applies to the Report ID |
Definition at line 372 of file usb_specific_request.c.
References g_u8_report_rate, Is_usb_receive_out, LSB, MSB, Usb_ack_receive_out, Usb_ack_receive_setup, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.
Referenced by usb_user_read_request().
00373 { 00374 U16 wLength; 00375 U16 wInterface; 00376 00377 // Get interface number to put in idle mode 00378 LSB(wInterface)= Usb_read_byte(); 00379 MSB(wInterface)= Usb_read_byte(); 00380 LSB(wLength) = Usb_read_byte(); 00381 MSB(wLength) = Usb_read_byte(); 00382 Usb_ack_receive_setup(); 00383 00384 if( wLength != 0 ) 00385 { 00386 Usb_write_byte(g_u8_report_rate); 00387 Usb_send_control_in(); 00388 } 00389 00390 while(!Is_usb_receive_out()); 00391 Usb_ack_receive_out(); 00392 }
| void hid_get_hid_descriptor | ( | void | ) |
This function manages hid get hid descriptor request.
Definition at line 397 of file usb_specific_request.c.
References S_usb_hid_descriptor::bLength, data_to_transfer, EP_CONTROL_LENGTH, FALSE, S_usb_user_configuration_descriptor::hid_mouse, Is_usb_read_control_enabled, Is_usb_receive_out, LSB, MSB, pbuffer, TRUE, Usb_ack_receive_out, Usb_ack_receive_setup, usb_conf_desc, Usb_read_byte, Usb_send_control_in, and Usb_write_byte.
Referenced by usb_user_read_request().
00398 { 00399 U16 wLength; 00400 U8 nb_byte; 00401 bit zlp=FALSE; 00402 U16 wInterface; 00403 00404 LSB(wInterface)=Usb_read_byte(); 00405 MSB(wInterface)=Usb_read_byte(); 00406 00407 data_to_transfer = sizeof(usb_conf_desc.hid_mouse); 00408 pbuffer = &(usb_conf_desc.hid_mouse.bLength); 00409 00410 LSB(wLength) = Usb_read_byte(); 00411 MSB(wLength) = Usb_read_byte(); 00412 Usb_ack_receive_setup(); 00413 00414 if (wLength > data_to_transfer) 00415 { 00416 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; } 00417 else { zlp = FALSE; } // no need of zero length packet 00418 } 00419 else 00420 { 00421 data_to_transfer = (U8)wLength; // send only requested number of data 00422 } 00423 00424 while((data_to_transfer != 0) && (!Is_usb_receive_out())) 00425 { 00426 while(!Is_usb_read_control_enabled()); 00427 00428 nb_byte=0; 00429 while(data_to_transfer != 0) // Send data until necessary 00430 { 00431 if(nb_byte++==EP_CONTROL_LENGTH) // Check endpoint 0 size 00432 { 00433 break; 00434 } 00435 #ifndef __GNUC__ 00436 Usb_write_byte(*pbuffer++); 00437 #else // AVRGCC does not support point to PGM space 00438 //warning with AVRGCC assumes devices descriptors are stored in the lower 64Kbytes of on-chip flash memory 00439 Usb_write_byte(pgm_read_byte_near((unsigned int)pbuffer++)); 00440 #endif 00441 data_to_transfer --; 00442 } 00443 Usb_send_control_in(); 00444 } 00445 00446 if(Is_usb_receive_out()) 00447 { 00448 // abort from Host 00449 Usb_ack_receive_out(); 00450 return; 00451 } 00452 if(zlp == TRUE) 00453 { 00454 while(!Is_usb_read_control_enabled()); 00455 Usb_send_control_in(); 00456 } 00457 00458 while(!Is_usb_receive_out()); 00459 Usb_ack_receive_out(); 00460 }
This function checks the specific request and if known then processes it
| type | corresponding at bmRequestType (see USB specification) | |
| request | corresponding at bRequest (see USB specification) |
FALSE, if the request is'nt know (STALL handshake is managed by the main standard request function).
Definition at line 86 of file usb_specific_request.c.
Referenced by usb_process_request().
00087 { 00088 U8 wValue_msb; 00089 U8 wValue_lsb; 00090 00091 // Read wValue 00092 wValue_lsb = Usb_read_byte(); 00093 wValue_msb = Usb_read_byte(); 00094 00095 //** Specific request from Class HID 00096 if( USB_SETUP_GET_STAND_INTERFACE == type ) 00097 { 00098 switch( request ) 00099 { 00100 case SETUP_GET_DESCRIPTOR: 00101 switch( wValue_msb ) // Descriptor ID 00102 { 00103 case DESCRIPTOR_HID: 00104 hid_get_hid_descriptor(); 00105 return TRUE; 00106 break; 00107 00108 case DESCRIPTOR_REPORT: 00109 hid_get_report_descriptor(); 00110 return TRUE; 00111 00112 case DESCRIPTOR_PHYSICAL: 00113 // TODO 00114 break; 00115 } 00116 break; 00117 } 00118 } 00119 if( USB_SETUP_SET_CLASS_INTER == type ) 00120 { 00121 switch( request ) 00122 { 00123 case SETUP_HID_SET_REPORT: 00124 // The MSB wValue field specifies the Report Type 00125 // The LSB wValue field specifies the Report ID 00126 switch (wValue_msb) 00127 { 00128 case REPORT_TYPE_INPUT: 00129 // TODO 00130 break; 00131 00132 case REPORT_TYPE_OUTPUT: 00133 usb_hid_set_report_ouput(); 00134 return TRUE; 00135 break; 00136 00137 case REPORT_TYPE_FEATURE: 00138 break; 00139 } 00140 break; 00141 00142 case SETUP_HID_SET_IDLE: 00143 usb_hid_set_idle(wValue_lsb,wValue_msb); 00144 return TRUE; 00145 00146 case SETUP_HID_SET_PROTOCOL: 00147 // TODO 00148 break; 00149 } 00150 } 00151 if( USB_SETUP_GET_CLASS_INTER == type ) 00152 { 00153 switch( request ) 00154 { 00155 case SETUP_HID_GET_REPORT: 00156 // TODO 00157 break; 00158 case SETUP_HID_GET_IDLE: 00159 usb_hid_get_idle(wValue_lsb); 00160 return TRUE; 00161 case SETUP_HID_GET_PROTOCOL: 00162 // TODO 00163 break; 00164 } 00165 } 00166 return FALSE; // No supported request 00167 }
| void usb_user_endpoint_init | ( | U8 | conf_nb | ) |
This function configures the endpoints
| conf_nb | configuration number choosed by USB host |
Definition at line 174 of file usb_specific_request.c.
Referenced by usb_set_configuration().
00175 { 00176 usb_configure_endpoint( EP_MOUSE_IN, \ 00177 TYPE_INTERRUPT,\ 00178 DIRECTION_IN, \ 00179 SIZE_8, \ 00180 ONE_BANK, \ 00181 NYET_ENABLED); 00182 }
This function returns the interface alternate setting
| wInterface | Interface selected |
Definition at line 191 of file usb_specific_request.c.
Referenced by usb_get_interface().
This function selects (and resets) the interface alternate setting
| wInterface | Interface selected | |
| alternate_setting | alternate setting selected |
Definition at line 202 of file usb_specific_request.c.
Referenced by usb_set_interface().
00203 { 00204 // default setting selected = reset data toggle 00205 if( INTERFACE_NB_MOUSE == wInterface ) 00206 { 00207 // Interface mouse 00208 Usb_select_endpoint(EP_MOUSE_IN); 00209 Usb_disable_stall_handshake(); 00210 Usb_reset_endpoint(EP_MOUSE_IN); 00211 Usb_reset_data_toggle(); 00212 } 00213 }
This function fills the global descriptor.
| type | corresponding at MSB of wValue (see USB specification) | |
| string | corresponding at LSB of wValue (see USB specification) |
Definition at line 223 of file usb_specific_request.c.
Referenced by usb_get_descriptor().
00224 { 00225 switch(type) 00226 { 00227 case DESCRIPTOR_STRING: 00228 switch (string) 00229 { 00230 case LANG_ID: 00231 data_to_transfer = sizeof (usb_user_language_id); 00232 pbuffer = &(usb_user_language_id.bLength); 00233 return TRUE; 00234 break; 00235 00236 case MAN_INDEX: 00237 data_to_transfer = sizeof (usb_user_manufacturer_string_descriptor); 00238 pbuffer = &(usb_user_manufacturer_string_descriptor.bLength); 00239 return TRUE; 00240 break; 00241 00242 case PROD_INDEX: 00243 data_to_transfer = sizeof (usb_user_product_string_descriptor); 00244 pbuffer = &(usb_user_product_string_descriptor.bLength); 00245 return TRUE; 00246 break; 00247 00248 #if (USB_DEVICE_SN_USE==ENABLE) 00249 case SN_INDEX: 00250 data_to_transfer = sizeof (usb_user_serial_number); 00251 pbuffer = &(usb_user_serial_number.bLength); 00252 #if (USE_DEVICE_SN_UNIQUE==ENABLE) 00253 f_get_serial_string=TRUE; 00254 data_to_transfer += (SN_LENGTH*4); 00255 #endif 00256 return TRUE; 00257 break; 00258 #endif 00259 } 00260 break; 00261 } 00262 return FALSE; 00263 }
Definition at line 91 of file usb_standard_request.c.
Referenced by hid_get_hid_descriptor(), hid_get_report_descriptor(), usb_get_descriptor(), and usb_user_get_descriptor().
Definition at line 96 of file usb_standard_request.c.
Referenced by hid_get_hid_descriptor(), hid_get_report_descriptor(), usb_get_descriptor(), and usb_user_get_descriptor().
Definition at line 170 of file usb_descriptors.c.
| U8 g_u8_report_rate = 0 |
Definition at line 67 of file usb_specific_request.c.
Referenced by usb_hid_get_idle(), and usb_hid_set_idle().
1.5.3