//------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void myUsbDevice_request_handler(void) { switch (myUSB0_setup.wRequest) { case USB_REQUEST_STANDARD_DEVICE_GET_DESCRIPTOR: // Support device, configuration, string if (myUSB0_setup.wValue == 0x0100) { myUSB0_ep0_data_pointer = (uint8_t *)&myUsbDeviceDescriptor; myUSB0_ep0_data_size = _min(myUSB0_setup.wValue, sizeof(myUsbDeviceDescriptor)); myUSB0_ep0_state = EP0_START_IN_DATA; } else if (myUSB0_setup.wValue == 0x0200) { myUSB0_ep0_data_pointer = (uint8_t *)&myUsbConfigurationDescriptors; myUSB0_ep0_data_size = _min(myUSB0_setup.wValue, sizeof(myUsbConfigurationDescriptors)); myUSB0_ep0_state = EP0_START_IN_DATA; } else { myUSB0_ep0_state = EP0_SEND_STALL; } break; case USB_REQUEST_STANDARD_DEVICE_SET_ADDRESS: SI32_USB_A_write_faddr(SI32_USB_0, (0x7F & myUSB0_setup.wValue)); myUSB0_ep0_state = EP0_NODATA_STATUS; break; case USB_REQUEST_STANDARD_DEVICE_SET_CONFIG: case USB_REQUEST_STANDARD_DEVICE_SET_INTERFACE: SI32_USBEP_A_set_endpoint_direction_in(SI32_USB_0_EP1); SI32_USBEP_A_clear_in_data_underrun(SI32_USB_0_EP1); SI32_USBEP_A_select_in_bulk_interrupt_mode(SI32_USB_0_EP1); SI32_USBEP_A_stop_in_stall(SI32_USB_0_EP1); SI32_USBEP_A_reset_in_data_toggle(SI32_USB_0_EP1); SI32_USBEP_A_set_in_max_packet_size(SI32_USB_0_EP1, 64>>3); SI32_USB_A_enable_ep1(SI32_USB_0); myUSB0_ep1_state=EPN_IDLE; myUSB0_ep0_state = EP0_NODATA_STATUS; break; case USB_REQUEST_STANDARD_INTERFACE_GET_DESCRIPTOR: if (myUSB0_setup.wValue == 0x2200) { myUSB0_ep0_data_pointer = (uint8_t *)&myUsbHidKeypadUsage; myUSB0_ep0_data_size = _min(myUSB0_setup.wValue, sizeof(myUsbHidKeypadUsage)); myUSB0_ep0_state = EP0_START_IN_DATA; break; } default: myUSB0_ep0_state = EP0_SEND_STALL; break; } }
void ep_config(U8 ep_num, U8 type, U8 dir, U8 size) { // init the direction the fifo usb_buf_init(ep_num, dir); // select the endpoint and reset it // FIXME if( ep_num > 0 ) { if( dir == DIR_OUT ) { switch( type ) { case XFER_ISOCHRONOUS: SI32_USBEP_A_enable_out_isochronous_mode( usb_ep[ ep_num - 1 ] ); break; case XFER_BULK: case XFER_INTP: SI32_USBEP_A_enable_out_bulk_interrupt_mode( usb_ep[ ep_num - 1 ] ); break; case XFER_CONTROL: // only for EP0 break; default: break; } SI32_USBEP_A_set_endpoint_direction_out( usb_ep[ ep_num - 1 ] ); SI32_USBEP_A_clear_out_data_overrun( usb_ep[ ep_num - 1 ] ); SI32_USBEP_A_stop_out_stall( usb_ep[ ep_num - 1 ] ); SI32_USBEP_A_reset_out_data_toggle( usb_ep[ ep_num - 1 ] ); SI32_USBEP_A_set_out_max_packet_size(usb_ep[ ep_num - 1 ], (1 << size) ); } else { SI32_USBEP_A_set_endpoint_direction_in( usb_ep[ ep_num - 1 ] ); SI32_USBEP_A_clear_in_data_underrun( usb_ep[ ep_num - 1 ] ); switch( type ) { case XFER_ISOCHRONOUS: SI32_USBEP_A_select_in_isochronous_mode( usb_ep[ ep_num - 1 ] ); break; case XFER_BULK: case XFER_INTP: SI32_USBEP_A_select_in_bulk_interrupt_mode( usb_ep[ ep_num - 1 ] ); SI32_USBEP_A_stop_in_stall( usb_ep[ ep_num - 1 ] ); SI32_USBEP_A_reset_in_data_toggle( usb_ep[ ep_num - 1 ] ); break; case XFER_CONTROL: // only for EP0 break; default: break; } SI32_USBEP_A_set_in_max_packet_size(usb_ep[ ep_num - 1 ], (1 << size) ); } } // Enable endpoints switch ( ep_num ) { case 1: SI32_USB_A_enable_ep1( SI32_USB_0 ); break; case 2: SI32_USB_A_enable_ep2( SI32_USB_0 ); break; case 3: SI32_USB_A_enable_ep3( SI32_USB_0 ); break; case 4: SI32_USB_A_enable_ep4( SI32_USB_0 ); } //SI32_USB_A_reset_module (SI32_USB_0); /* if (ep_num == EP_CTRL) { RX_SETUP_INT_ENB(); RX_OUT_INT_ENB(); } else if (dir == DIR_OUT) { RX_OUT_INT_ENB(); }*/ }