static void get_endpoint_status() { static uint16_t status; PRINTF("get_endpoint_status\r\n"); if ((usb_setup_buffer.wIndex & 0x7f) == 0) { usb_send_ctrl_response((const unsigned char*)&zero_word, sizeof(zero_word)); } else { status = usb_arch_get_ep_status(usb_setup_buffer.wIndex); usb_send_ctrl_response((uint8_t*)&status, sizeof(status)); } }
static void get_string_descriptor() { #if OLD_STRING_DESCR if(LOW_BYTE(usb_setup_buffer.wValue) == 0) { usb_send_ctrl_response((const unsigned char *)string_languages-> lang_descr, string_languages->lang_descr->bLength); } else { const struct usb_st_string_descriptor *descriptor; unsigned char l; const struct usb_st_string_descriptor *const *table; const struct usb_st_string_language_map *map; if(LOW_BYTE(usb_setup_buffer.wValue) > string_languages->max_index) { usb_error_stall(); return; } l = string_languages->num_lang; map = string_languages->map; table = map->descriptors; /* Use first table if language not found */ while(l > 0) { if(map->lang_id == usb_setup_buffer.wIndex) { table = map->descriptors; break; } map++; l--; } PRINTF("Lang id %04x = table %p\n", usb_setup_buffer.wIndex, (void *)table); descriptor = table[LOW_BYTE(usb_setup_buffer.wValue) - 1]; usb_send_ctrl_response((const unsigned char *)descriptor, descriptor->bLength); } #else const struct usb_st_string_descriptor *descriptor; descriptor = (struct usb_st_string_descriptor *) usb_class_get_string_descriptor(usb_setup_buffer.wIndex, LOW_BYTE(usb_setup_buffer.wValue)); if(!descriptor) { usb_error_stall(); return; } usb_send_ctrl_response((const unsigned char *)descriptor, descriptor->bLength); #endif }
static void get_interface_status() { PRINTF("get_interface_status\r\n"); usb_send_ctrl_response((const unsigned char*)&zero_word, sizeof(zero_word)); }
static void get_device_status() { PRINTF("get_device_status\r\n"); usb_send_ctrl_response((const unsigned char*)&usb_device_status, sizeof(usb_device_status)); }
static void get_interface() { PRINTF("get_interface\r\n"); if (usb_configuration_value == 0) usb_error_stall(); else { usb_send_ctrl_response(&zero_byte, sizeof(zero_byte)); } }
static unsigned int handle_hid_requests() { printf("HID request %02x %02x\n", usb_setup_buffer.bmRequestType, usb_setup_buffer.bRequest); switch(usb_setup_buffer.bmRequestType) { case 0x81: switch(usb_setup_buffer.bRequest) { case GET_DESCRIPTOR: printf("Get HID report decriptor\n"); if (usb_setup_buffer.wValue == 0x2200 && usb_setup_buffer.wLength >= sizeof(HID_REPORT_DESCRIPTOR_BLOCK)) { usb_send_ctrl_response((const uint8_t*)&HID_REPORT_DESCRIPTOR_BLOCK, sizeof(HID_REPORT_DESCRIPTOR_BLOCK)); return 1; } else if (usb_setup_buffer.wValue == 0x2100 && usb_setup_buffer.wLength >= sizeof(HID_DESCRIPTOR_BLOCK)) { usb_send_ctrl_response((const uint8_t*)&HID_DESCRIPTOR_BLOCK, sizeof(HID_DESCRIPTOR_BLOCK)); return 1; } return 0; } break; case 0x21: switch(usb_setup_buffer.bRequest) { case SET_IDLE: if (usb_setup_buffer.wLength == 0) { if ((usb_setup_buffer.wValue & 0xff) < 4) { idle_rate[usb_setup_buffer.wValue & 0xff] = usb_setup_buffer.wValue>>8; printf("Dur: %d, id: %d\n", usb_setup_buffer.wValue>>8, usb_setup_buffer.wValue & 0xff); } usb_send_ctrl_status(); return 1; } break; case SET_REPORT: { unsigned int len = usb_setup_buffer.wLength; if (len > sizeof(blit_buffer)) len = sizeof(blit_buffer); usb_get_ctrl_data(blit_buffer, len, handle_blit); printf("Got blit report: %d\n",len); return 1; } break; } break; case 0xa1: switch(usb_setup_buffer.bRequest) { case GET_REPORT: printf("GET_REPORT\n"); if (usb_setup_buffer.wValue == 0x0301 && usb_setup_buffer.wLength >= sizeof(display_report)) { usb_send_ctrl_response((const uint8_t*)&display_report, sizeof(display_report)); return 1; } return 0; case GET_IDLE: if (usb_setup_buffer.wValue < 4) { usb_send_ctrl_response((const uint8_t*) &idle_rate[usb_setup_buffer.wValue], sizeof(uint8_t)); return 1; } return 0; } break; }
static void get_configuration() { usb_send_ctrl_response((unsigned char*)&usb_configuration_value, sizeof(usb_configuration_value)); }
static void get_configuration_descriptor() { usb_send_ctrl_response((unsigned char*)configuration_head, configuration_head->wTotalLength); }
static void get_device_descriptor() { usb_send_ctrl_response((unsigned char*)&device_descriptor, sizeof(device_descriptor)); }