#define LED_PIN 7 #define CONTROL_INTERFACE 0 #define DATA_INTERFACE 1 #define INTERRUPT_ENDPOINT_LOGICAL 0x82 #define INTERRUPT_ENDPOINT_PHYSICAL 5 #define DATA_OUT_ENDPOINT_LOGICAL 0x01 #define DATA_OUT_ENDPOINT_PHYSICAL 2 #define DATA_IN_ENDPOINT_LOGICAL 0x81 #define DATA_IN_ENDPOINT_PHYSICAL 3 #define FIFO_SIZE 256 const uint8_t deviceDescriptor[] = { 18, //bLength: length of this structure in bytes (18) USB_DESC_DEVICE, //bDescriptorType: usb device descriptor I16_TO_LE_BA(0x0200), //bcdUSB - USB 2.0 USB_CLASS_CDC, //bDeviceClass: CDC 0x00, //bDeviceSubClass: Device subclass (must be 0 if bDeviceClass is 0) 0x00, //bDeviceProtocol: 0 for no specific device-level protocols USB_MAX_COMMAND_PACKET_SIZE, //bMaxPacketSize0: Max packet size for control endpoint I16_TO_LE_BA(0x1234), //idVendor: 16 bit vendor id I16_TO_LE_BA(0x5678), //idProduct: 16 bit product id I16_TO_LE_BA(0x0100), //bcdDevice: Device release version 0x01, //iManufacturer: Manufacturer string index 0x02, //iProduct: Product string index 0x03, //iSerialNumber: Serial number string index 0x01 //bNumConfigurations: Number of configurations }; const uint8_t languages[] = { 0x04, //bLength: length of this descriptor in bytes (4)
0x05, 0x01, // USAGE_PAGE (Generic Desktop) 0x09, 0x30, // USAGE (X) 0x09, 0x31, // USAGE (Y) 0x15, 0x81, // LOGICAL_MINIMUM (-127) 0x25, 0x7f, // LOGICAL_MAXIMUM (127) 0x75, 0x08, // REPORT_SIZE (8) 0x95, 0x02, // REPORT_COUNT (2) 0x81, 0x06, // INPUT (Data,Var,Rel) 0xc0, // END_COLLECTION 0xc0 // END_COLLECTION }; const uint8_t mouse_configDescriptor[] = { 0x09, //bLength: length of this descriptor in bytes (9) USB_DESC_CONFIGURATION, //bDescriptorType: configuration descriptor I16_TO_LE_BA(34), //wTotalLen: Total length, including attached interface and endpoint descriptors 0x01, //bNumInterfaces: Number of interfaces (1) 0x01, //bConfigurationValue: Number to set to activate this config 0x00, //iConfiguration: configuration string index (0 = not available) 0x80, //bmAttributes: Not self-powered, no remote wakeup 0x32, //bMaxPower: Max power in 2mA steps (0x32 = 50 = 100mA) // Interface 0: HID 0x09, //bLength: length of this descriptor in bytes (9) USB_DESC_INTERFACE, //bDescriptorType: configuration descriptor 0x00, //bInterfaceNumber: Interface index, 0-based 0x00, //bAlternateSetting 0x01, //bNumEndpoints: Number of endpoints excluding control endpoint USB_CLASS_HID, //bInterfaceClass: interface class 0x01, //bInterfaceSubClass 1 = boot interface (0 for non-boot interface) 0x02, //bInterfaceProtocol 2 = boot mouse (1 for boot keyboard, 0 for all others)
0x00, 0x02, //bcdUSB: 0200 (Little Endian) - USB 2.0 compliant USB_CLASS_DEVICE, //bDeviceClass: Device class (0 = interfaces specify class) 0x00, //bDeviceSubClass: Device subclass (must be 0 if bDeviceClass is 0) 0x00, //bDeviceProtocol: 0 for no specific device-level protocols USB_MAX_COMMAND_PACKET_SIZE, //bMaxPacketSize0: Max packet size for control endpoint 0x34, 0x12, //idVendor: 16 bit vendor id 0x78, 0x56, //idProduct: 16 bit product id 0x00, 0x01, //bcdDevice: Device release version 0x01, //iManufacturer: Manufacturer string index 0x02, //iProduct: Product string index 0x03, //iSerialNumber: Serial number string index 0x01 //bNumConfigurations: Number of configurations }; const uint8_t reportDescriptor[] = { 0x06,I16_TO_LE_BA(0xff01), // Usage Page (Vendor-defined 1) 0x09,0x01, //usage: vendor 1 0xa1,0x01, //start of app collection 0x15,0x00, //min: 0 0x26,0xff,0x00, //max: 0xff 0x75,0x08, //report size: 8 bits 0x95,IN_REPORT_SIZE, //report count: # bytes 0x09,0x01, //usage: vendor usage 1 0x81,0x02, //input (data, variable, absolute) 0x95,OUT_REPORT_SIZE, //report count # out 0x09,0x02, //usage: vendor usage 2 0x91,0x02, //output (data, variable, absolute) 0xc0 //end of collection }; const uint8_t configDescriptor[] = {