62 #define PRINTF_P printf_P
66 static void usb_get_descriptor(
void);
67 static void usb_set_address(
void);
68 static void usb_set_configuration(
void);
69 static void usb_clear_feature(
void);
70 static void usb_set_feature(
void);
71 static void usb_get_status(
void);
72 static void usb_get_configuration(
void);
73 static void usb_get_interface (
void);
74 static void usb_set_interface (
void);
80 static U8 endpoint_status[NB_ENDPOINTS];
91 static U8 bmRequestType;
95 usb_mode_t usb_mode = rndis_debug;
99 extern FLASH S_usb_user_configuration_descriptor_network usb_user_configuration_descriptor_network;
101 extern FLASH S_usb_user_configuration_descriptor_composite usb_user_configuration_descriptor_composite;
128 if (0x80 == bmRequestType) { usb_get_descriptor(); }
132 case GET_CONFIGURATION:
133 if (0x80 == bmRequestType) { usb_get_configuration(); }
138 if (0x00 == bmRequestType) { usb_set_address(); }
142 case SET_CONFIGURATION:
143 if (0x00 == bmRequestType) { usb_set_configuration(); }
148 if (0x02 >= bmRequestType) { usb_clear_feature(); }
153 if (0x02 >= bmRequestType) { usb_set_feature(); }
158 if ((0x7F < bmRequestType) & (0x82 >= bmRequestType))
159 { usb_get_status(); }
164 if (bmRequestType == 0x81) { usb_get_interface(); }
170 if (bmRequestType == 0x01) {usb_set_interface();}
202 void usb_set_address(
void)
223 void usb_set_configuration(
void )
225 U8 configuration_number;
237 Usb_set_configuration_action();
245 U16 requested_length;
247 const char* user_str;
249 user_str = usb_user_get_string_sram(string_type);
260 const U8 actual_descriptor_size = 2+strlen(user_str)*2;
262 if (requested_length > actual_descriptor_size) {
263 zlp = ((actual_descriptor_size % EP_CONTROL_LENGTH) == 0);
264 requested_length = actual_descriptor_size;
269 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
280 requested_length -= 2;
283 if(!requested_length) {
289 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
294 while(requested_length != 0)
296 if(nb_byte==EP_CONTROL_LENGTH)
305 requested_length -=2;
319 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
326 usb_endpoint_wait_for_receive_out();
332 U16 requested_length;
336 user_str = usb_user_get_string(string_type);
350 const U8 actual_descriptor_size = 2+strlen_P(user_str)*2;
352 if (requested_length > actual_descriptor_size) {
353 zlp = ((actual_descriptor_size % EP_CONTROL_LENGTH) == 0);
354 requested_length = actual_descriptor_size;
359 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
366 if(requested_length) {
373 if(requested_length) {
379 if(!requested_length) {
385 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
390 while(requested_length != 0)
392 if(nb_byte==EP_CONTROL_LENGTH) {
400 if(requested_length) {
418 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
425 usb_endpoint_wait_for_receive_out();
440 void usb_get_descriptor(
void)
442 U8 LSBwLength, MSBwLength;
453 switch (descriptor_type)
455 case DEVICE_DESCRIPTOR:
456 data_to_transfer = Usb_get_dev_desc_length();
457 pbuffer = Usb_get_dev_desc_pointer();
459 case CONFIGURATION_DESCRIPTOR:
460 data_to_transfer = Usb_get_conf_desc_length(string_type);
461 pbuffer = Usb_get_conf_desc_pointer(string_type);
464 case STRING_DESCRIPTOR:
465 if(string_type!=LANG_ID) {
484 if (byteswereread==0) {
493 if ((LSBwLength > data_to_transfer) || (MSBwLength)) {
494 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp =
TRUE; }
495 else { zlp =
FALSE; }
497 LSBwLength = data_to_transfer;
500 data_to_transfer = LSBwLength;
505 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
511 while(data_to_transfer != 0) {
513 if(nb_byte++==EP_CONTROL_LENGTH)
530 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
537 usb_endpoint_wait_for_receive_out();
548 void usb_get_configuration(
void)
555 usb_endpoint_wait_for_receive_out();
566 void usb_get_status(
void)
576 switch(bmRequestType)
587 wIndex = wIndex & MSK_EP_DIR;
599 usb_endpoint_wait_for_receive_out();
610 void usb_set_feature(
void)
616 if (bmRequestType == INTERFACE_TYPE)
620 else if (bmRequestType == ENDPOINT_TYPE)
626 if (wValue == FEATURE_ENDPOINT_HALT)
630 if (wIndex == EP_CONTROL)
640 endpoint_status[wIndex] = 0x01;
663 void usb_clear_feature(
void)
669 if (bmRequestType == ZERO_TYPE)
673 else if (bmRequestType == INTERFACE_TYPE)
677 else if (bmRequestType == ENDPOINT_TYPE)
683 if (wValue == FEATURE_ENDPOINT_HALT)
690 if(wIndex != EP_CONTROL)
697 endpoint_status[wIndex] = 0x00;
720 void usb_get_interface (
void)
731 void usb_set_interface (
void)
742 if(usb_user_set_alt_interface(interface, alt_setting)) {
747 usb_endpoint_wait_for_receive_out();
#define Is_usb_endpoint_enabled()
tests if the current endpoint is enabled
void usb_get_string_descriptor(U8 string_type)
void usb_get_string_descriptor_sram(U8 string_type)
#define Usb_configure_address(addr)
sets the USB device address
#define Usb_reset_endpoint(ep)
resets the selected endpoint
#define Usb_read_byte()
returns FIFO byte for current endpoint
#define Usb_disable_stall_handshake()
disables the STALL handshake
This file contains the user callback functions corresponding to the application.
This file contains the USB driver routines.
#define Usb_write_byte(byte)
writes byte in FIFO for current endpoint
void usb_process_request(void)
usb_process_request.
#define Usb_ack_in_ready()
acks IN ready
U8 usb_configuration_nb
Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device w...
#define Usb_ack_receive_setup()
acks receive SETUP
#define Usb_enable_address()
enables USB device address
#define TRUE
An alias for one, used for clarity.
bit usb_connected
Public : (bit) usb_connected usb_connected is set to TRUE when VBUS has been detected usb_connected i...
#define Usb_send_control_in()
sends IN on control endpoint
#define Is_usb_receive_setup()
tests if SETUP received
void usb_user_endpoint_init(U8 conf_nb)
usb_user_endpoint_init.
#define Usb_reset_data_toggle()
resets the data toggle sequence
#define CLEAR_FEATURE
see FEATURES below
This file contains the usb parameters that uniquely identify the application through descriptor table...
#define Is_usb_in_ready()
tests if IN ready
#define FALSE
An alias for zero, used for clarity.
#define Usb_select_endpoint(ep)
selects the endpoint number to interface with the CPU
Bool usb_user_read_request(U8 type, U8 request)
This function is called by the standard usb read request function when the Usb request is not support...
#define Is_usb_receive_out()
tests if OUT received
#define SET_FEATURE
see FEATURES below
#define Usb_ack_receive_out()
acks reveive OUT
#define Usb_enable_stall_handshake()
enables the STALL handshake for the next transaction
Bool usb_user_get_descriptor(U8 type, U8 string)
usb_user_get_descriptor.