USB device vendor request如何调用接口去做应用层面的开发

发布于 2020-12-01 07:35:53

STM32
RT-Thread USB device
在componentsdriversusbusbdevicecorecore.c中vendor_request有接口去给应用层开发吗?不然vendor的代码就得写在驱动里了。。。

static rt_err_t _vendor_request(udevice_t device, ureq_t setup)
{
    static rt_uint8_t * usb_comp_id_desc = RT_NULL;
    static rt_uint32_t  usb_comp_id_desc_size = 0;
    usb_os_func_comp_id_desc_t func_comp_id_desc;
    uintf_t intf;
    ufunction_t func;
    switch(setup->bRequest)
    {
        case 'A':
        switch(setup->wIndex)
        {
            case 0x04:
                if(rt_list_len(&device->os_comp_id_desc->func_desc) == 0)
                {
                    rt_usbd_ep0_set_stall(device);
                    return RT_EOK;
                }
                if(usb_comp_id_desc == RT_NULL)
                {
                    rt_uint8_t * pusb_comp_id_desc;
                    rt_list_t *p;
                    usb_comp_id_desc_size = sizeof(struct usb_os_header_comp_id_descriptor) + 
                    (sizeof(struct usb_os_function_comp_id_descriptor)-sizeof(rt_list_t))*rt_list_len(&device->os_comp_id_desc->func_desc);

                    usb_comp_id_desc = (rt_uint8_t *)rt_malloc(usb_comp_id_desc_size);
                    RT_ASSERT(usb_comp_id_desc != RT_NULL);
                    device->os_comp_id_desc->head_desc.dwLength = usb_comp_id_desc_size;
                    pusb_comp_id_desc = usb_comp_id_desc;
                    rt_memcpy((void *)pusb_comp_id_desc,(void *)&device->os_comp_id_desc->head_desc,sizeof(struct usb_os_header_comp_id_descriptor));
                    pusb_comp_id_desc += sizeof(struct usb_os_header_comp_id_descriptor);
                    
                    for (p = device->os_comp_id_desc->func_desc.next; p != &device->os_comp_id_desc->func_desc; p = p->next)
                    {
                        func_comp_id_desc = rt_list_entry(p,struct usb_os_function_comp_id_descriptor,list);
                        rt_memcpy(pusb_comp_id_desc,(void *)&func_comp_id_desc->bFirstInterfaceNumber,
                        sizeof(struct usb_os_function_comp_id_descriptor)-sizeof(rt_list_t));
                        pusb_comp_id_desc += sizeof(struct usb_os_function_comp_id_descriptor)-sizeof(rt_list_t);
                    }
                }
                rt_usbd_ep0_write(device, (void*)usb_comp_id_desc, setup->wLength);
            break;
            case 0x05:
                intf = rt_usbd_find_interface(device, setup->wValue & 0xFF, &func);
                if(intf != RT_NULL)
                {
                    intf->handler(func, setup);
                }
                break;
        }
            
        break;
    }
    return RT_EOK;
}

查看更多

关注者
0
被浏览
211
1 个回答
james_s
james_s 2021-04-12

应该按照rt-thread的usb驱动栈(这个我也在看,rt-threa的相关文档不多)来实现,比如看看实现一个usb device class driver是否能满足要求

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览