исходники выложу на гитхаб на днях. но там мутенеько все на данный момент, торопился
у меня три интерфейса: стандартная клавиатура (boot keyboard), мышь с колесом и некая солянка из разных элементов. клавиатура и мышь (эмулируемая джойстиком и энкодером) - для системы. третий интерфейс для hal_input - определенные там юсаджи мапятся на хал пины. один из светодиодов деграется из hal, чтобы сообщить контроллеру что работает linuxcnc. в этом режиме контроллер перестает слать события о функциональных клвишах, мыши и энкодере через первые два интерфейса, а шлет их через третий.
сомнительное решение, на самом деле. мне почему-то непременно хотелось использовать input subsystem и hal_input... надо, наверное, не изгалаться и просто сделать третий интерфейс custom hid и свой hal модуль к нему. в котором все пины нормально обозвать.
Код: Выделить всё
__ALIGN_BEGIN static uint8_t HID_KEYBOARD_ReportDesc[] __ALIGN_END = {
// From p69 of http://www.usb.org/developers/devclass_docs/HID1_11.pdf
0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
0xA1, 0x01, // Collection (Application),
0x05, 0x07, // Usage Page (Key Codes);
0x19, 0xE0, // Usage Minimum (224), - CtrlL
0x29, 0xE7, // Usage Maximum (231), - WinR
0x15, 0x00, // Logical Minimum (0),
0x25, 0x01, // Logical Maximum (1),
0x75, 0x01, // Report Size (1),
0x95, 0x08, // Report Count (8), - 8 bits modifiers
0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
0x95, 0x01, // Report Count (1),
0x75, 0x08, // Report Size (8),
0x81, 0x01, // Input (Constant), Reserved byte
0x95, 0x05, // Report Count (5), ???
0x75, 0x01, // Report Size (1),
0x05, 0x08, // Usage Page (Page# for LEDs),
0x19, 0x01, // Usage Minimum (1),
0x29, 0x05, // Usage Maximum (5),
0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
0x95, 0x01, // Report Count (1),
0x75, 0x03, // Report Size (3),
0x91, 0x01, // Output (Constant), ;LED report padding
0x95, 0x06, // Report Count (6),
0x75, 0x08, // Report Size (8),
0x15, 0x00, // Logical Minimum (0),
0x25, 0x65, // Logical Maximum(101),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0x00, // Usage Minimum (0),
0x29, 0x65, // Usage Maximum (101),
0x81, 0x00, // Input (Data, Array), ;Key arrays (6 bytes)
0xc0 // End Collection
};
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[] __ALIGN_END = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x02, // USAGE_MAXIMUM (Button 2)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x02, // REPORT_COUNT (2)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs) left, right buttons
0x95, 0x01, // Report Count (1),
0x75, 0x06, // Report Size (6),
0x81, 0x01, // Input (Constant), Reserved byte buttons padding
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x09, 0x38, // USAGE (Wheel)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x06, // INPUT (Data,Var,Rel) x, y, encoder wheel
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
};
__ALIGN_BEGIN static uint8_t HID_CUSTOM_ReportDesc[] __ALIGN_END = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x21, // USAGE_MINIMUM (Button 1)
0x29, 0x23, // USAGE_MAXIMUM (Button 3)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x02, // INPUT (Data,Var,Abs) left-right-middle buttons:3
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x37, // USAGE (Dial)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x17, // LOGICAL_MAXIMUM (23)
0x75, 0x05, // REPORT_SIZE (5)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data,Var,Abs) dial:5
0x09, 0x33, // USAGE (RX)
0x09, 0x34, // USAGE (RY)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs) x, y joystick
0x09, 0x35, // USAGE (RZ)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x06, // INPUT (Data,Var,Rel) encoder wheel
// special keys and buttons
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0xc1, // USAGE_MINIMUM (0) KEY_FN ..
0x29, 0xd5, // USAGE_MAXIMUM (23) KEY_FN_B
0x1A, 0xB1, 0x01, // Usage Minimum (0x01B0) BTN_TRIGGER_HAPPY1 (linux hid_input.c bug exploit)
0x2A, 0xD8, 0x01, // Usage Maximum (0x01D7) BTN_TRIGGER_HAPPY40
0x15, 0x01, // LOGICAL_MINIMUM (1)
0x25, 0xff, // LOGICAL_MAXIMUM (40)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x04, // REPORT_COUNT (4) 4 simultaneous keys
0x81, 0x00, // INPUT (Data,Ary,Abs)
// LEDs
0x05, 0x08, // Usage Page (Page# for LEDs),
0x19, 0x01, // Usage Minimum (1),
0x29, 0x05, // Usage Maximum (5), NUML, CAPSL, SCROLLL, COMPOSE, KANA
0x09, 0x27, // USAGE LED SLEEP
0x09, 0x4c, // USAGE LED SUSPEND
0x09, 0x09, // USAGE LED MUTE
0x09, 0x4b, // 0x4b // misc - unused
0x09, 0x19, // 0x19 // mail - unused
0x09, 0x4d, // 0x4d // charging - watchdog
0x15, 0x00, // LOGICAL_MINIMUM
0x25, 0x01, // LOGICAL_MAXIMUM
0x75, 0x01, // Report Size (1),
0x95, 0x0b, // Report Count (11)
0x91, 0x02, // Output (Data, Variable, Absolute), ; LED report
0xc0, // END_COLLECTION
};
// USB HID device Configuration Descriptor
__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[] __ALIGN_END =
{
0x09, // bLength: Configuration Descriptor size
USB_DESC_TYPE_CONFIGURATION, // =2 bDescriptorType: Configuration
(0x5b), // (+0x02) wTotalLength: Bytes returned
0x00,
0x03, // bNumInterfaces: 3 interfaces
0x01, // bConfigurationValue: Configuration value
0x03, // iConfiguration: Index of string descriptor describing the configuration
0xa0, // bmAttributes: bus powered and Support Remote Wake-up
0x64, // MaxPower 200 mA: this current is used for detecting Vbus
// +0x09 Descriptor of Keyboard interface 1 ######################################
USB_LEN_IF_DESC, // =9 bLength: Interface Descriptor size
USB_DESC_TYPE_INTERFACE,// =4 bDescriptorType: Interface descriptor type
0x00, // bInte: Number of Interface
0x00, // bAlternateSetting: Alternate setting*/
0x01, // bNumEndpoints
0x03, // bInterfaceClass: HID
0x01, // bInterfaceSubClass : 1=BOOT, 0=no boot
0x01, // nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse
0x00, // iInterface: Index of string descriptor
// +0x12 - Descriptor of Keyboard HID
#define HID0_DESC_OFFS 0x12
USB_LEN_CFG_DESC, // =9 bLength: HID Descriptor size
HID_DESCRIPTOR_TYPE, // =0x21 bDescriptorType: HID
0x11, // bcdHID: HID Class Spec release number
0x01,
0x00, // bCountryCode: Hardware target country
0x01, // bNumDescriptors: Number of HID class descriptors to follow
HID_REPORT_DESC, // =0x22 bDescriptorType
sizeof(HID_KEYBOARD_ReportDesc),
0x00, // wItemLength: Total length of Report descriptor
#define HID0_DESC_END 0x1b
// +0x1b - Descriptor of Keyboard endpoint
USB_LEN_EP_DESC, // =7 bLength: Endpoint Descriptor size
USB_DESC_TYPE_ENDPOINT, // =5 bDescriptorType:
HID_EPIN_ADDR, // =0x81 bEndpointAddress: Endpoint Address (IN)
0x03, // bmAttributes: Interrupt endpoint
HID_EPIN_SIZE, // =8 wMaxPacketSize: 8 Byte max
0x00,
HID_FS_BINTERVAL, // =10 bInterval: Polling Interval (10 ms)
// +0x22 - Descriptor of Mouse interface 2 ######################################
USB_LEN_IF_DESC, // =9 bLength: Interface Descriptor size
USB_DESC_TYPE_INTERFACE,// =4 bDescriptorType: Interface descriptor type
0x01,//!!! // bInterfaceNumber: Number of Interface
0x00, // bAlternateSetting: Alternate setting
0x01, // bNumEndpoints
0x03, // bInterfaceClass: HID
0x00, // bInterfaceSubClass : 1=BOOT, 0=no boot
0x00, // nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse
0x00, // iInterface: Index of string descriptor
// +0x2b Descriptor of Keyboard HID 2
#define HID1_DESC_OFFS 0x2b
USB_LEN_CFG_DESC, // =9 bLength: HID Descriptor size
HID_DESCRIPTOR_TYPE, // =0x21 bDescriptorType: HID
0x11, // bcdHID: HID Class Spec release number
0x01,
0x00, // bCountryCode: Hardware target country
0x01, // bNumDescriptors: Number of HID class descriptors to follow
HID_REPORT_DESC, // =0x22 bDescriptorType
sizeof(HID_MOUSE_ReportDesc),
0x00, // wItemLength: Total length of Report descriptor
#define HID1_DESC_END 0x34
// +0x34 Descriptor of Keyboard endpoint 2
USB_LEN_EP_DESC, // =7 bLength: Endpoint Descriptor size
USB_DESC_TYPE_ENDPOINT, // =5 bDescriptorType:
HID_EPIN_ADDR+1, // =0x82 bEndpointAddress: Endpoint Address (IN)
0x03, // bmAttributes: Interrupt endpoint
HID_EPIN_SIZE, // =8 wMaxPacketSize: 8 Byte max
0,
HID_FS_BINTERVAL, // =10 bInterval: Polling Interval (10 ms)
// +0x3b - Descriptor of Custom interface 3 ######################################
USB_LEN_IF_DESC, // =9 bLength: Interface Descriptor size
USB_DESC_TYPE_INTERFACE,// =4 bDescriptorType: Interface descriptor type
0x02,//!!! // bInterfaceNumber: Number of Interface
0x00, // bAlternateSetting: Alternate setting
0x02, // bNumEndpoints
0x03, // bInterfaceClass: HID
0x00, // bInterfaceSubClass : 1=BOOT, 0=no boot
0x00, // nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse
0x00, // iInterface: Index of string descriptor
// +0x44 Descriptor of Custom HID 3
#define HID2_DESC_OFFS 0x44
USB_LEN_CFG_DESC, // =9 bLength: HID Descriptor size
HID_DESCRIPTOR_TYPE, // =0x21 bDescriptorType: HID
0x11, // bcdHID: HID Class Spec release number
0x01,
0x00, // bCountryCode: Hardware target country
0x01, // bNumDescriptors: Number of HID class descriptors to follow
HID_REPORT_DESC, // =0x22 bDescriptorType
sizeof(HID_CUSTOM_ReportDesc),
0x00, // wItemLength: Total length of Report descriptor
#define HID2_DESC_END 0x4d
// +0x4d Descriptor of Custom endpoint
USB_LEN_EP_DESC, // =7 bLength: Endpoint Descriptor size
USB_DESC_TYPE_ENDPOINT, // =5 bDescriptorType:
HID_EPIN_ADDR+2, // =0x83 bEndpointAddress: Endpoint Address (IN)
0x03, // bmAttributes: Interrupt endpoint
HID_EPIN_SIZE, // =8 wMaxPacketSize: 8 Byte max
0,
HID_FS_BINTERVAL, // =10 bInterval: Polling Interval (10 ms)
// +0x54 Out Endpoint
USB_LEN_EP_DESC, // =7 bLength: Endpoint Descriptor size
USB_DESC_TYPE_ENDPOINT, // =5 bDescriptorType:
HID_EPOUT_ADDR, // =0x01 bEndpointAddress: Endpoint Address (OUT)
0x03, // bmAttributes: Interrupt endpoint
HID_EPOUT_SIZE, // =1 wMaxPacketSize: 2 Byte max
0,
HID_FS_BINTERVAL, // =10 bInterval: Polling Interval (10 ms)
// 0x5b
};