static void usb_handle_get_desc(struct usb_setup_req *req) { switch (req->wValue) { case USB_DESC_VALUE(USB_DESC_DEVICE, 0): usb_send_desc(_dev00, min(sizeof(_dev00),req->wLength)); break; case USB_DESC_VALUE(USB_DESC_CONFIG, 0): usb_send_desc(_cfg00, min(sizeof(_cfg00),req->wLength)); break; case USB_DESC_VALUE(USB_DESC_STRING, 0): usb_send_desc(lang_id, min(sizeof(lang_id),req->wLength)); break; case USB_DESC_VALUE(USB_DESC_STRING, 1): usb_send_desc(mfg_string, min(sizeof(mfg_string),req->wLength)); break; case USB_DESC_VALUE(USB_DESC_STRING, 2): usb_send_desc(prod_string, min(sizeof(prod_string),req->wLength)); break; default: usb_debug("unknown desc: %h\n", req->wValue); usb_nak(&usb_ep_data[0]); break; } }
static bool std_req(setup_t *sp) { switch(sp->req) { case SR_SET_ADDRESS: PUTS("set_addr\n"); rregn(FNADDR, NULL, 0, true); break; case SR_GET_DESCRIPTOR: PUTS("get_desc: "); usb_send_desc(sp); break; case SR_SET_FEATURE: /* this either sets that RWU is to be enabled or to halt an EP, * which is mandatory for bulk and interrupt EPs */ PUTS("set_feature\n"); break; case SR_CLEAR_FEATURE: /* clear one of the features which have been set by SET_FEATURE */ PUTS("clear_feature\n"); break; case SR_GET_STATUS: PUTS("get_status\n"); get_status(sp); break; case SR_SET_INTERFACE: /* this is used to set alternative interfaces. For example when * the CDC device will be put up */ PUTS("setif"); ACK(); break; case SR_GET_INTERFACE: PUTS("getif"); /* always report the same alternative: 1 */ { uint8_t i = 0x01; reg_t st = {0x00}; do { rreg(EPIRQ, &st); } while( !st.EPIRQ.IN0BAVIRQ ); wregn(EP0FIFO, &i, sizeof(uint8_t), false); i=sizeof(uint8_t); wregn(EP0BC, &i, i, true); } break; case SR_SET_CONFIGURATION: PUTS("set_conf\n"); usbdev.status.configuration = sp->asconfreq.conf; ACK(); return true; break; case SR_GET_CONFIGURATION: PUTS("get_conf\n"); { uint8_t len = sizeof(usbdev.status.configuration); reg_t st = {0x00}; do { rreg(EPIRQ, &st); } while( !st.EPIRQ.IN0BAVIRQ ); wregn(EP0FIFO, &usbdev.status.configuration, len, false); wregn(EP0BC, &len, sizeof(len), true); } break; default: PUTS("unknown std_req()"); STALLEP0(); } return false; }