X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=usb.c;h=3011ecb2a90b909497140fb2f24c242f7c01fd52;hb=74b3e591fcf296f0b363ab8289b2531a7cd44b64;hp=c910a977ed47d86ca24947145caa5cbb4c3655d6;hpb=d3b1af9572e123c939fc355474bf12402c86d292;p=max%2Ftmk_keyboard.git diff --git a/usb.c b/usb.c index c910a977..3011ecb2 100644 --- a/usb.c +++ b/usb.c @@ -28,6 +28,8 @@ #include "usb_keyboard.h" #include "usb_mouse.h" #include "usb_debug.h" +#include "print.h" +#include "util.h" /************************************************************************** @@ -37,16 +39,29 @@ **************************************************************************/ // You can change these to give your code its own name. -#define STR_MANUFACTURER L"t.m.k." -#define STR_PRODUCT L"t.m.k. keyboard" +#ifndef MANUFACTURER +# define STR_MANUFACTURER L"t.m.k." +#else +# define STR_MANUFACTURER LSTR(MANUFACTURER) +#endif +#ifndef PRODUCT +# define STR_PRODUCT L"t.m.k. keyboard" +#else +# define STR_PRODUCT LSTR(PRODUCT) +#endif // Mac OS-X and Linux automatically load the correct drivers. On // Windows, even though the driver is supplied by Microsoft, an // INF file is needed to load the driver. These numbers need to // match the INF file. -#define VENDOR_ID 0xFEED -#define PRODUCT_ID 0xBABE +#ifndef VENDOR_ID +# define VENDOR_ID 0xFEED +#endif + +#ifndef PRODUCT_ID +# define PRODUCT_ID 0xBABE +#endif // USB devices are supposed to implment a halt feature, which is @@ -145,33 +160,80 @@ static uint8_t PROGMEM keyboard_hid_report_desc[] = { }; // Mouse Protocol 1, HID 1.11 spec, Appendix B, page 59-60, with wheel extension +// http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521 +// http://www.keil.com/forum/15671/ +// http://www.microsoft.com/whdc/device/input/wheel.mspx static uint8_t PROGMEM mouse_hid_report_desc[] = { - 0x05, 0x01, // Usage Page (Generic Desktop) - 0x09, 0x02, // Usage (Mouse) - 0xA1, 0x01, // Collection (Application) - 0x05, 0x09, // Usage Page (Button) - 0x19, 0x01, // Usage Minimum (Button #1) - 0x29, 0x03, // Usage Maximum (Button #3) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0x01, // Logical Maximum (1) - 0x95, 0x03, // Report Count (3) - 0x75, 0x01, // Report Size (1) - 0x81, 0x02, // Input (Data, Variable, Absolute) - 0x95, 0x01, // Report Count (1) - 0x75, 0x05, // Report Size (5) - 0x81, 0x03, // Input (Constant) - 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, Variable, Relative) - 0x09, 0x38, // Usage (Wheel) - 0x95, 0x01, // Report Count (1), - 0x81, 0x06, // Input (Data, Variable, Relative) - 0xC0 // End Collection + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x02, // COLLECTION (Logical) + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + // ------------------------------ Buttons + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x05, // USAGE_MAXIMUM (Button 5) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x05, // REPORT_COUNT (5) + 0x81, 0x02, // INPUT (Data,Var,Abs) + // ------------------------------ Padding + 0x75, 0x03, // REPORT_SIZE (3) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x03, // INPUT (Cnst,Var,Abs) + // ------------------------------ X,Y position + 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) + 0xa1, 0x02, // COLLECTION (Logical) + // ------------------------------ Vertical wheel res multiplier + 0x09, 0x48, // USAGE (Resolution Multiplier) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x35, 0x01, // PHYSICAL_MINIMUM (1) + 0x45, 0x04, // PHYSICAL_MAXIMUM (4) + 0x75, 0x02, // REPORT_SIZE (2) + 0x95, 0x01, // REPORT_COUNT (1) + 0xa4, // PUSH + 0xb1, 0x02, // FEATURE (Data,Var,Abs) + // ------------------------------ Vertical wheel + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical + 0x45, 0x00, // PHYSICAL_MAXIMUM (0) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xa1, 0x02, // COLLECTION (Logical) + // ------------------------------ Horizontal wheel res multiplier + 0x09, 0x48, // USAGE (Resolution Multiplier) + 0xb4, // POP + 0xb1, 0x02, // FEATURE (Data,Var,Abs) + // ------------------------------ Padding for Feature report + 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical + 0x45, 0x00, // PHYSICAL_MAXIMUM (0) + 0x75, 0x04, // REPORT_SIZE (4) + 0xb1, 0x03, // FEATURE (Cnst,Var,Abs) + // ------------------------------ Horizontal wheel + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x0a, 0x38, 0x02, // USAGE (AC Pan) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION + 0xc0, // END_COLLECTION + 0xc0 // END_COLLECTION }; static uint8_t PROGMEM debug_hid_report_desc[] = { @@ -254,7 +316,7 @@ static uint8_t PROGMEM config1_descriptor[CONFIG1_DESC_SIZE] = { 5, // bDescriptorType MOUSE_ENDPOINT | 0x80, // bEndpointAddress 0x03, // bmAttributes (0x03=intr) - 4, 0, // wMaxPacketSize + MOUSE_SIZE, 0, // wMaxPacketSize 1, // bInterval // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 @@ -416,16 +478,16 @@ ISR(USB_GEN_vect) UEINTX = 0x3A; } } - if (keyboard_idle_config && (++div4 & 3) == 0) { + if (usb_keyboard_idle_config && (++div4 & 3) == 0) { UENUM = KEYBOARD_ENDPOINT; if (UEINTX & (1<> 8); - keyboard_idle_count = 0; + usb_keyboard_idle_config = (wValue >> 8); + usb_keyboard_idle_count = 0; //usb_wait_in_ready(); usb_send_in(); return; } if (bRequest == HID_SET_PROTOCOL) { - keyboard_protocol = wValue; + usb_keyboard_protocol = wValue; //usb_wait_in_ready(); usb_send_in(); return; @@ -643,6 +705,7 @@ ISR(USB_COM_vect) if (wIndex == MOUSE_INTERFACE) { if (bmRequestType == 0xA1) { if (bRequest == HID_GET_REPORT) { + if (wValue == HID_REPORT_INPUT) { usb_wait_in_ready(); UEDATX = mouse_buttons; UEDATX = 0; @@ -650,6 +713,13 @@ ISR(USB_COM_vect) UEDATX = 0; usb_send_in(); return; + } + if (wValue == HID_REPORT_FEATURE) { + usb_wait_in_ready(); + UEDATX = 0x05; + usb_send_in(); + return; + } } if (bRequest == HID_GET_PROTOCOL) { usb_wait_in_ready(); @@ -689,5 +759,3 @@ ISR(USB_COM_vect) } UECONX = (1<