62 #define PRINTF_P printf_P
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;
132 case GET_CONFIGURATION:
142 case SET_CONFIGURATION:
158 if ((0x7F < bmRequestType) & (0x82 >= bmRequestType))
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();
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();
555 usb_endpoint_wait_for_receive_out();
576 switch(bmRequestType)
587 wIndex = wIndex & MSK_EP_DIR;
599 usb_endpoint_wait_for_receive_out();
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;
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;
742 if(usb_user_set_alt_interface(interface, alt_setting)) {
747 usb_endpoint_wait_for_receive_out();
This file contains the USB driver routines.
#define TRUE
An alias for one, used for clarity.
static void usb_set_feature(void)
usb_set_feature.
U8 usb_configuration_nb
Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device w...
#define SET_FEATURE
see FEATURES below
#define Usb_ack_receive_setup()
acks receive SETUP
#define Usb_select_endpoint(ep)
selects the endpoint number to interface with the CPU
#define Usb_enable_address()
enables USB device address
bit usb_connected
Public : (bit) usb_connected usb_connected is set to TRUE when VBUS has been detected usb_connected i...
#define Usb_ack_receive_out()
acks reveive OUT
static void usb_set_interface(void)
usb_set_interface.
#define Usb_reset_data_toggle()
resets the data toggle sequence
This file contains the user callback functions corresponding to the application.
#define Is_usb_receive_setup()
tests if SETUP received
#define Usb_disable_stall_handshake()
disables the STALL handshake
static void usb_set_configuration(void)
usb_set_configuration.
static void usb_clear_feature(void)
usb_clear_feature.
#define Usb_send_control_in()
sends IN on control endpoint
#define Usb_read_byte()
returns FIFO byte for current endpoint
static void usb_get_status(void)
usb_get_status.
#define Usb_ack_in_ready()
acks IN ready
This file contains the usb parameters that uniquely identify the application through descriptor table...
#define Usb_write_byte(byte)
writes byte in FIFO for current endpoint
#define Is_usb_receive_out()
tests if OUT received
#define CLEAR_FEATURE
see FEATURES below
static void usb_set_address(void)
usb_set_address.
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...
Bool usb_user_get_descriptor(U8 type, U8 string)
usb_user_get_descriptor.
void usb_process_request(void)
usb_process_request.
static void usb_get_configuration(void)
usb_get_configuration.
#define FALSE
An alias for zero, used for clarity.
#define Usb_reset_endpoint(ep)
resets the selected endpoint
static void usb_get_interface(void)
usb_get_interface.
#define Usb_enable_stall_handshake()
enables the STALL handshake for the next transaction
void usb_get_string_descriptor_sram(U8 string_type)
void usb_user_endpoint_init(U8 conf_nb)
usb_user_endpoint_init.
#define Is_usb_endpoint_enabled()
tests if the current endpoint is enabled
static void usb_get_descriptor(void)
usb_get_descriptor.
#define Is_usb_in_ready()
tests if IN ready
#define Usb_configure_address(addr)
sets the USB device address
void usb_get_string_descriptor(U8 string_type)