/* The request_func_table[] is a table of all USB request handling functions. * Every entry in this table must have a corresponding index in the * request_function_index enumerated type list. */ const void (* request_func_table[])(void) = { USB_send_stall, ClearRemoteWakeup, SetRemoteWakeup, SetAddress, SetConfiguration, ClearEndpointStall, SetEndpointStall, GetDeviceStatus, GetDescriptor, GetConfiguration, GetInterfaceStatus, GetEndpointStatus, SetReport, SetIdle, SetProtocol, GetReport, GetIdle, GetProtocol }; enum request_function_index { USB_send_stall_index, ClearRemoteWakeup_index, SetRemoteWakeup_index, SetAddress_index, SetConfiguration_index, ClearEndpointStall_index, SetEndpointStall_index, GetDeviceStatus_index, GetDescriptor_index, GetConfiguration_index, GetInterfaceStatus_index, GetEndpointStatus_index, SetReport_index, SetIdle_index, SetProtocol_index, GetReport_index, GetIdle_index, GetProtocol_index }; enum request_function_index function_index; char far * table_ptr; /* The USB_request_table[] array has a table entry for every USB request handle by this application. * Each entry consists of a request type, a request and an index into the request_func_table[] */ const char USB_request_table[] = { HOST_TO_DEVICE | STANDARD | DEVICE , USB_CLEAR_FEATURE , ClearRemoteWakeup_index , /* 00 01 */ HOST_TO_DEVICE | STANDARD | DEVICE , USB_SET_FEATURE , SetRemoteWakeup_index , /* 00 03 */ HOST_TO_DEVICE | STANDARD | DEVICE , USB_SET_ADDRESS , SetAddress_index , /* 00 05 */ HOST_TO_DEVICE | STANDARD | DEVICE , USB_SET_CONFIGURATION, SetConfiguration_index , /* 00 09 */ HOST_TO_DEVICE | STANDARD | ENDPOINT , USB_CLEAR_FEATURE , ClearEndpointStall_index, /* 02 01 */ HOST_TO_DEVICE | STANDARD | ENDPOINT , USB_SET_FEATURE , SetEndpointStall_index , /* 02 03 */ DEVICE_TO_HOST | STANDARD | DEVICE , USB_GET_STATUS , GetDeviceStatus_index , /* 80 00 */ DEVICE_TO_HOST | STANDARD | DEVICE , USB_GET_DESCRIPTOR , GetDescriptor_index , /* 80 06 */ DEVICE_TO_HOST | STANDARD | DEVICE , USB_GET_CONFIGURATION, GetConfiguration_index , /* 80 08 */ DEVICE_TO_HOST | STANDARD | INTERFACE , USB_GET_STATUS , GetInterfaceStatus_index, /* 81 00 */ DEVICE_TO_HOST | STANDARD | INTERFACE , USB_GET_DESCRIPTOR , GetDescriptor_index , /* 81 06 */ DEVICE_TO_HOST | STANDARD | ENDPOINT , USB_GET_STATUS , GetEndpointStatus_index , /* 82 00 */ DEVICE_TO_HOST | STANDARD | ENDPOINT , USB_GET_DESCRIPTOR , GetDescriptor_index , /* 82 06 */ HOST_TO_DEVICE | CLASS | INTERFACE , USB_SET_REPORT , SetReport_index , /* 21 09 */ HOST_TO_DEVICE | CLASS | INTERFACE , USB_SET_IDLE , SetIdle_index , /* 21 0A */ HOST_TO_DEVICE | CLASS | INTERFACE , USB_SET_PROTOCOL , SetProtocol_index , /* 21 0B */ HOST_TO_DEVICE | CLASS | ENDPOINT , USB_SET_REPORT , SetReport_index , /* 22 09 */ HOST_TO_DEVICE | CLASS | ENDPOINT , USB_SET_IDLE , SetIdle_index , /* 22 0A */ HOST_TO_DEVICE | CLASS | ENDPOINT , USB_SET_PROTOCOL , SetProtocol_index , /* 22 0B */ DEVICE_TO_HOST | CLASS | INTERFACE , USB_GET_REPORT , GetReport_index , /* A1 01 */ DEVICE_TO_HOST | CLASS | INTERFACE , USB_GET_IDLE , GetIdle_index , /* A1 02 */ DEVICE_TO_HOST | CLASS | INTERFACE , USB_GET_PROTOCOL , GetProtocol_index /* A1 03 */ }; void USB_request_handler(void) { table_ptr = USB_request_table; /* reset table pointer to start of request table */ function_index = USB_send_stall_index; /* default to 'stall' function if request if not found */ do { if( *table_ptr == ENDPOINT_A0_FIFO[USB_bmRequestType] ) /* check for request type */ { if( *(table_ptr+1) == ENDPOINT_A0_FIFO[USB_bRequest] ) /* check for request */ function_index = *(table_ptr+2); /* get the function index for the request handler */ } table_ptr += 3; } while( table_ptr < (USB_request_table + sizeof(USB_request_table)) ); /* find the index for the function handler */ (*request_func_table[function_index])(); /* call function handler for USB request */ }