目录
1、参考现有打印机的枚举过程
2、接口描述符
如下,简单配置好接口及端点描述符,打印机设备就出来了
#if 1//打印机接口
/************** Descriptor of Printer interface ****************/
0x09, /* bLength: Interface Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface descriptor type */
0x03, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints */
0x07, /* bInterfaceClass: USB_CLASS_PRINTER */
0x01, /* bInterfaceSubClass : USB_SUBCLASS_PRINTER */
0x02, /* nInterfaceProtocol : PROTOCOL_BI_DIRECTIONAL_ITF */
0, /* iInterface: Index of string descriptor */
/******************** Descriptor of Custom HID endpoints ******************/
#if 1 //端点4 IN
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
0x84, /* bEndpointAddress: Endpoint Address (IN) */
0x02, /* bmAttributes: USB_EP_ATTR_BULK endpoint */
64, /* wMaxPacketSize: 64 Bytes max */
0x00,
0x00, /* bInterval: Polling Interval (32 ms) */
#endif //端点
#if 1 //端点4 OUT
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
/* Endpoint descriptor type */
0x04, /* bEndpointAddress: */
/* Endpoint Address (OUT) */
0x02, /* bmAttributes: USB_EP_ATTR_BULK endpoint */
64, /* wMaxPacketSize: 64 Bytes max */
0x00,
00,//0x20, /* bInterval: Polling Interval (30 ms) */
#endif //端点
但设备列表里提示 没有连接打印机
3、GET DEVICE ID
对比发现,打印机有个类请求GET DEVICE ID需要实现
标准请求数据:a1 00 00 00 00 00 f1 03
通过Printer_GetDeviceID返回下面的数据
const uint8_t Printer_DEVICE_ID[ ] =
{
0x00,0x50,0x4d,0x46,0x47,0x3a,0x50,0x6f,0x73,0x74,0x65,0x4b,0x50,0x72,0x69,0x6e,
0x74,0x65,0x72,0x73,0x3b,0x4d,0x44,0x4c,0x3a,0x50,0x4f,0x53,0x54,0x45,0x4b,0x20,
0x51,0x38,0x2f,0x32,0x30,0x30,0x3b,0x43,0x4d,0x44,0x3a,0x50,0x50,0x4c,0x49,0x3b,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
ONE_DESCRIPTOR Custom_PrinterDeviceID =
{
(uint8_t*)Printer_DEVICE_ID,
sizeof(Printer_DEVICE_ID)
};
打印机设备就能正常显示了
4、发送数据测试
选中Out端点,Data Length回车有效,Run发送
至此,算是基本完成打印机设备的初步配置