nkro interface (for later)

master
Stefan Dorn 2016-06-14 13:41:38 +01:00
parent 90bb49c27d
commit a0289831c1
1 changed files with 83 additions and 7 deletions

View File

@ -542,14 +542,21 @@ uint8_t twi_read(uint8_t *data) {
#define KEYBOARD_ENDPOINT 1
#define KEYBOARD_SIZE 8
#define KEYBOARD_BUFFER EP_DOUBLE_BUFFER
#define KBD_KEYS (KEYBOARD_SIZE - 2)
#define EXTRA_INTERFACE 1
#define EXTRA_ENDPOINT 2
#define EXTRA_SIZE 8
#define EXTRA_BUFFER EP_DOUBLE_BUFFER
#define DEBUG_INTERFACE 2
#define DEBUG_TX_ENDPOINT 3
#define NKRO_INTERFACE 2
#define NKRO_ENDPOINT 3
#define NKRO_SIZE 24
#define NKRO_BUFFER EP_DOUBLE_BUFFER
#define NKRO_KEYS (NKRO_SIZE - 1)
#define DEBUG_INTERFACE 3
#define DEBUG_TX_ENDPOINT 4
#define DEBUG_TX_SIZE 32
#define DEBUG_TX_BUFFER EP_DOUBLE_BUFFER
@ -557,8 +564,9 @@ static const uint8_t PROGMEM endpoint_config_table[] = {
// enable, UECFG0X(type, direction), UECFG1X(size, bank, allocation)
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(KEYBOARD_SIZE) | KEYBOARD_BUFFER, // 1
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(EXTRA_SIZE) | EXTRA_BUFFER, // 2
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(NKRO_SIZE) | NKRO_BUFFER, // 3
#ifdef KBD_DEBUG
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 3
1, EP_TYPE_INTERRUPT_IN, EP_SIZE(DEBUG_TX_SIZE) | DEBUG_TX_BUFFER, // 4
#endif
0
};
@ -648,6 +656,41 @@ static const uint8_t PROGMEM extra_hid_report_desc[] = {
0xc0, // END_COLLECTION
};
static const uint8_t PROGMEM nkro_hid_report_desc[] = {
0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
0xA1, 0x01, // Collection (Application),
// bitmap of modifiers
0x75, 0x01, // Report Size (1),
0x95, 0x08, // Report Count (8),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0xE0, // Usage Minimum (224),
0x29, 0xE7, // Usage Maximum (231),
0x15, 0x00, // Logical Minimum (0),
0x25, 0x01, // Logical Maximum (1),
0x81, 0x02, // Input (Data, Variable, Absolute), ;Modifier byte
// LED output report
0x95, 0x05, // Report Count (5),
0x75, 0x01, // Report Size (1),
0x05, 0x08, // Usage Page (LEDs),
0x19, 0x01, // Usage Minimum (1),
0x29, 0x05, // Usage Maximum (5),
0x91, 0x02, // Output (Data, Variable, Absolute),
0x95, 0x01, // Report Count (1),
0x75, 0x03, // Report Size (3),
0x91, 0x03, // Output (Constant),
// bitmap of keys
0x95, NKRO_KEYS * 8, // Report Count (),
0x75, 0x01, // Report Size (1),
0x15, 0x00, // Logical Minimum (0),
0x25, 0x01, // Logical Maximum(1),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0x00, // Usage Minimum (0),
0x29, NKRO_KEYS * 8 - 1, // Usage Maximum (),
0x81, 0x02, // Input (Data, Variable, Absolute),
0xc0 // End Collection
};
// debug messages
#ifdef KBD_DEBUG
static const uint8_t PROGMEM debug_hid_report_desc[] = {
@ -667,16 +710,19 @@ static const uint8_t PROGMEM debug_hid_report_desc[] = {
#ifdef KBD_DEBUG
#define KEYBOARD_HID_DESC_NUM 0
#define EXTRA_HID_DESC_NUM 1
#define DEBUG_HID_DESC_NUM 2
#define NUM_INTERFACES 3
#define NKRO_HID_DESC_NUM 2
#define DEBUG_HID_DESC_NUM 3
#define NUM_INTERFACES 4
#else
#define KEYBOARD_HID_DESC_NUM 0
#define EXTRA_HID_DESC_NUM 1
#define NUM_INTERFACES 2
#define NKRO_HID_DESC_NUM 2
#define NUM_INTERFACES 3
#endif
#define KEYBOARD_HID_DESC_OFFSET (9+(9+9+7)*KEYBOARD_HID_DESC_NUM+9)
#define EXTRA_HID_DESC_OFFSET (9+(9+9+7)*EXTRA_HID_DESC_NUM+9)
#define NKRO_HID_DESC_OFFSET (9+(9+9+7)*NKRO_HID_DESC_NUM+9)
#define DEBUG_HID_DESC_OFFSET (9+(9+9+7)*DEBUG_HID_DESC_NUM+9)
#define CONFIG1_DESC_SIZE (9+(9+9+7)*NUM_INTERFACES)
@ -746,6 +792,33 @@ static const uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = {
EXTRA_SIZE, 0, // wMaxPacketSize
10, // bInterval
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
4, // bDescriptorType
NKRO_INTERFACE, // bInterfaceNumber
0, // bAlternateSetting
1, // bNumEndpoints
0x03, // bInterfaceClass (0x03 = HID)
0x00, // bInterfaceSubClass (0x01 = Boot)
0x00, // bInterfaceProtocol (0x01 = Keyboard)
0, // iInterface
// HID descriptor, HID 1.11 spec, section 6.2.1
9, // bLength
0x21, // bDescriptorType
0x11, 0x01, // bcdHID
0, // bCountryCode
1, // bNumDescriptors
0x22, // bDescriptorType
sizeof(nkro_hid_report_desc), // wDescriptorLength
0,
// endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13
7, // bLength
5, // bDescriptorType
NKRO_ENDPOINT | 0x80, // bEndpointAddress
0x03, // bmAttributes (0x03=intr)
NKRO_SIZE, 0, // wMaxPacketSize
1, // bInterval
#ifdef KBD_DEBUG
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
@ -809,6 +882,9 @@ static struct descriptor_list_struct {
// Extra HID Descriptor
{0x2100, EXTRA_INTERFACE, config1_descriptor + EXTRA_HID_DESC_OFFSET, 9},
{0x2200, EXTRA_INTERFACE, extra_hid_report_desc, sizeof(extra_hid_report_desc)},
// NKRO
{0x2100, NKRO_INTERFACE, config1_descriptor+NKRO_HID_DESC_OFFSET, 9},
{0x2200, NKRO_INTERFACE, nkro_hid_report_desc, sizeof(nkro_hid_report_desc)},
#ifdef KBD_DEBUG
// debug descriptors
{0x2100, DEBUG_INTERFACE, config1_descriptor+DEBUG_HID_DESC_OFFSET, 9},
@ -836,7 +912,7 @@ static volatile uint8_t usb_configuration=0;
uint8_t keyboard_modifier_keys=0;
// which keys are currently pressed, up to 6 keys may be down at once
uint8_t keyboard_keys[6]={0,0,0,0,0,0};
uint8_t keyboard_keys[KBD_KEYS]={0,0,0,0,0,0};
// protocol setting from the host. We use exactly the same report
// either way, so this variable only stores the setting since we