diff options
| author | tmk <nobody@nowhere> | 2014-08-26 05:02:37 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2014-08-26 05:02:37 +0900 |
| commit | b316f19871ab39e6a75146d74a3b5cca37165f3c (patch) | |
| tree | 66d06b895fea2e85da612d06604ab59234dc46b7 /protocol | |
| parent | 10eb70acb4c8a03fc5bda32d9c23fc41266aef7a (diff) | |
| parent | 03fd4a6ff0fcccf8d7683b7fac3d9e6ae4fb635e (diff) | |
| download | qmk_firmware-b316f19871ab39e6a75146d74a3b5cca37165f3c.tar.gz qmk_firmware-b316f19871ab39e6a75146d74a3b5cca37165f3c.zip | |
Merge branch 'serial-mouse' of git://github.com/rhaberkorn/tmk_keyboard into rhaberkorn-serial-mouse
Diffstat (limited to 'protocol')
| -rw-r--r-- | protocol/lufa/lufa.c | 12 | ||||
| -rw-r--r-- | protocol/serial_mouse.h | 33 | ||||
| -rw-r--r-- | protocol/serial_mouse_microsoft.c | 124 | ||||
| -rw-r--r-- | protocol/serial_mouse_mousesystems.c | 131 |
4 files changed, 300 insertions, 0 deletions
diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index 16a602df1..58201e5c9 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c | |||
| @@ -49,6 +49,10 @@ | |||
| 49 | #endif | 49 | #endif |
| 50 | #include "suspend.h" | 50 | #include "suspend.h" |
| 51 | 51 | ||
| 52 | #ifdef SERIAL_MOUSE_ENABLE | ||
| 53 | #include "serial_mouse.h" | ||
| 54 | #endif | ||
| 55 | |||
| 52 | #include "descriptor.h" | 56 | #include "descriptor.h" |
| 53 | #include "lufa.h" | 57 | #include "lufa.h" |
| 54 | 58 | ||
| @@ -571,6 +575,10 @@ int main(void) | |||
| 571 | sleep_led_init(); | 575 | sleep_led_init(); |
| 572 | #endif | 576 | #endif |
| 573 | 577 | ||
| 578 | #ifdef SERIAL_MOUSE_ENABLE | ||
| 579 | serial_mouse_init(); | ||
| 580 | #endif | ||
| 581 | |||
| 574 | print("Keyboard start.\n"); | 582 | print("Keyboard start.\n"); |
| 575 | while (1) { | 583 | while (1) { |
| 576 | while (USB_DeviceState == DEVICE_STATE_Suspended) { | 584 | while (USB_DeviceState == DEVICE_STATE_Suspended) { |
| @@ -582,6 +590,10 @@ int main(void) | |||
| 582 | 590 | ||
| 583 | keyboard_task(); | 591 | keyboard_task(); |
| 584 | 592 | ||
| 593 | #ifdef SERIAL_MOUSE_ENABLE | ||
| 594 | serial_mouse_task(); | ||
| 595 | #endif | ||
| 596 | |||
| 585 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | 597 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) |
| 586 | USB_USBTask(); | 598 | USB_USBTask(); |
| 587 | #endif | 599 | #endif |
diff --git a/protocol/serial_mouse.h b/protocol/serial_mouse.h new file mode 100644 index 000000000..226314fc0 --- /dev/null +++ b/protocol/serial_mouse.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef SERIAL_MOUSE_H | ||
| 19 | #define SERIAL_MOUSE_H | ||
| 20 | |||
| 21 | #include <stdint.h> | ||
| 22 | |||
| 23 | #include "serial.h" | ||
| 24 | |||
| 25 | static inline uint8_t serial_mouse_init(void) | ||
| 26 | { | ||
| 27 | serial_init(); | ||
| 28 | return 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | void serial_mouse_task(void); | ||
| 32 | |||
| 33 | #endif | ||
diff --git a/protocol/serial_mouse_microsoft.c b/protocol/serial_mouse_microsoft.c new file mode 100644 index 000000000..ab74b7cdd --- /dev/null +++ b/protocol/serial_mouse_microsoft.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdint.h> | ||
| 19 | #include <avr/io.h> | ||
| 20 | #include <util/delay.h> | ||
| 21 | |||
| 22 | #include "serial.h" | ||
| 23 | #include "serial_mouse.h" | ||
| 24 | #include "report.h" | ||
| 25 | #include "host.h" | ||
| 26 | #include "timer.h" | ||
| 27 | #include "print.h" | ||
| 28 | #include "debug.h" | ||
| 29 | |||
| 30 | #ifdef MAX | ||
| 31 | #undef MAX | ||
| 32 | #endif | ||
| 33 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) | ||
| 34 | |||
| 35 | static void print_usb_data(const report_mouse_t *report); | ||
| 36 | |||
| 37 | void serial_mouse_task(void) | ||
| 38 | { | ||
| 39 | /* 3 byte ring buffer */ | ||
| 40 | static uint8_t buffer[3]; | ||
| 41 | static int buffer_cur = 0; | ||
| 42 | |||
| 43 | static report_mouse_t report = {}; | ||
| 44 | |||
| 45 | int16_t rcv; | ||
| 46 | |||
| 47 | rcv = serial_recv2(); | ||
| 48 | if (rcv < 0) | ||
| 49 | /* no new data */ | ||
| 50 | return; | ||
| 51 | |||
| 52 | if (debug_mouse) | ||
| 53 | xprintf("serial_mouse: byte: %04X\n", rcv); | ||
| 54 | |||
| 55 | /* | ||
| 56 | * If bit 6 is one, this signals the beginning | ||
| 57 | * of a 3 byte sequence/packet. | ||
| 58 | */ | ||
| 59 | if (rcv & (1 << 6)) | ||
| 60 | buffer_cur = 0; | ||
| 61 | |||
| 62 | buffer[buffer_cur] = (uint8_t)rcv; | ||
| 63 | |||
| 64 | if (buffer_cur == 0 && buffer[buffer_cur] == 0x20) { | ||
| 65 | /* | ||
| 66 | * Logitech extension: This must be a follow-up on | ||
| 67 | * the last 3-byte packet signaling a middle button click | ||
| 68 | */ | ||
| 69 | report.buttons |= MOUSE_BTN3; | ||
| 70 | report.x = report.y = 0; | ||
| 71 | |||
| 72 | print_usb_data(&report); | ||
| 73 | host_mouse_send(&report); | ||
| 74 | return; | ||
| 75 | } | ||
| 76 | |||
| 77 | buffer_cur++; | ||
| 78 | |||
| 79 | if (buffer_cur < 3) | ||
| 80 | return; | ||
| 81 | buffer_cur = 0; | ||
| 82 | |||
| 83 | /* | ||
| 84 | * parse 3 byte packet. | ||
| 85 | * NOTE: We only get a complete packet | ||
| 86 | * if the mouse moved or the button states | ||
| 87 | * change. | ||
| 88 | */ | ||
| 89 | report.buttons = 0; | ||
| 90 | if (buffer[0] & (1 << 5)) | ||
| 91 | report.buttons |= MOUSE_BTN1; | ||
| 92 | if (buffer[0] & (1 << 4)) | ||
| 93 | report.buttons |= MOUSE_BTN2; | ||
| 94 | |||
| 95 | report.x = (buffer[0] << 6) | buffer[1]; | ||
| 96 | report.y = ((buffer[0] << 4) & 0xC0) | buffer[2]; | ||
| 97 | |||
| 98 | /* USB HID uses values from -127 to 127 only */ | ||
| 99 | report.x = MAX(report.x, -127); | ||
| 100 | report.y = MAX(report.y, -127); | ||
| 101 | |||
| 102 | #if 0 | ||
| 103 | if (!report.buttons && !report.x && !report.y) { | ||
| 104 | /* | ||
| 105 | * Microsoft extension: Middle mouse button pressed | ||
| 106 | * FIXME: I don't know how exactly this extension works. | ||
| 107 | */ | ||
| 108 | report.buttons |= MOUSE_BTN3; | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | |||
| 112 | print_usb_data(&report); | ||
| 113 | host_mouse_send(&report); | ||
| 114 | } | ||
| 115 | |||
| 116 | static void print_usb_data(const report_mouse_t *report) | ||
| 117 | { | ||
| 118 | if (!debug_mouse) | ||
| 119 | return; | ||
| 120 | |||
| 121 | xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n", | ||
| 122 | report->buttons, report->x, report->y, | ||
| 123 | report->v, report->h); | ||
| 124 | } | ||
diff --git a/protocol/serial_mouse_mousesystems.c b/protocol/serial_mouse_mousesystems.c new file mode 100644 index 000000000..cfe899621 --- /dev/null +++ b/protocol/serial_mouse_mousesystems.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <stdint.h> | ||
| 19 | #include <avr/io.h> | ||
| 20 | #include <util/delay.h> | ||
| 21 | |||
| 22 | #include "serial.h" | ||
| 23 | #include "serial_mouse.h" | ||
| 24 | #include "report.h" | ||
| 25 | #include "host.h" | ||
| 26 | #include "timer.h" | ||
| 27 | #include "print.h" | ||
| 28 | #include "debug.h" | ||
| 29 | |||
| 30 | #ifdef MAX | ||
| 31 | #undef MAX | ||
| 32 | #endif | ||
| 33 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) | ||
| 34 | |||
| 35 | //#define SERIAL_MOUSE_CENTER_SCROLL | ||
| 36 | |||
| 37 | static void print_usb_data(const report_mouse_t *report); | ||
| 38 | |||
| 39 | void serial_mouse_task(void) | ||
| 40 | { | ||
| 41 | /* 5 byte ring buffer */ | ||
| 42 | static uint8_t buffer[5]; | ||
| 43 | static int buffer_cur = 0; | ||
| 44 | |||
| 45 | int16_t rcv; | ||
| 46 | |||
| 47 | report_mouse_t report = {0, 0, 0, 0, 0}; | ||
| 48 | |||
| 49 | rcv = serial_recv2(); | ||
| 50 | if (rcv < 0) | ||
| 51 | /* no new data */ | ||
| 52 | return; | ||
| 53 | |||
| 54 | if (debug_mouse) | ||
| 55 | xprintf("serial_mouse: byte: %04X\n", rcv); | ||
| 56 | |||
| 57 | /* | ||
| 58 | * Synchronization: mouse(4) says that all | ||
| 59 | * bytes but the first one in the packet have | ||
| 60 | * bit 7 == 0, but this is untrue. | ||
| 61 | * Therefore we discard all bytes up to the | ||
| 62 | * first one with the characteristic bit pattern. | ||
| 63 | */ | ||
| 64 | if (buffer_cur == 0 && (rcv >> 3) != 0x10) | ||
| 65 | return; | ||
| 66 | |||
| 67 | buffer[buffer_cur++] = (uint8_t)rcv; | ||
| 68 | |||
| 69 | if (buffer_cur < 5) | ||
| 70 | return; | ||
| 71 | buffer_cur = 0; | ||
| 72 | |||
| 73 | #ifdef SERIAL_MOUSE_CENTER_SCROLL | ||
| 74 | if ((buffer[0] & 0x7) == 0x5 && (buffer[1] || buffer[2])) { | ||
| 75 | /* USB HID uses only values from -127 to 127 */ | ||
| 76 | report.h = MAX((int8_t)buffer[1], -127); | ||
| 77 | report.v = MAX((int8_t)buffer[2], -127); | ||
| 78 | |||
| 79 | print_usb_data(&report); | ||
| 80 | host_mouse_send(&report); | ||
| 81 | |||
| 82 | if (buffer[3] || buffer[4]) { | ||
| 83 | report.h = MAX((int8_t)buffer[3], -127); | ||
| 84 | report.v = MAX((int8_t)buffer[4], -127); | ||
| 85 | |||
| 86 | print_usb_data(&report); | ||
| 87 | host_mouse_send(&report); | ||
| 88 | } | ||
| 89 | |||
| 90 | return; | ||
| 91 | } | ||
| 92 | #endif | ||
| 93 | |||
| 94 | /* | ||
| 95 | * parse 5 byte packet. | ||
| 96 | * NOTE: We only get a complete packet | ||
| 97 | * if the mouse moved or the button states | ||
| 98 | * change. | ||
| 99 | */ | ||
| 100 | if (!(buffer[0] & (1 << 2))) | ||
| 101 | report.buttons |= MOUSE_BTN1; | ||
| 102 | if (!(buffer[0] & (1 << 1))) | ||
| 103 | report.buttons |= MOUSE_BTN3; | ||
| 104 | if (!(buffer[0] & (1 << 0))) | ||
| 105 | report.buttons |= MOUSE_BTN2; | ||
| 106 | |||
| 107 | /* USB HID uses only values from -127 to 127 */ | ||
| 108 | report.x = MAX((int8_t)buffer[1], -127); | ||
| 109 | report.y = MAX(-(int8_t)buffer[2], -127); | ||
| 110 | |||
| 111 | print_usb_data(&report); | ||
| 112 | host_mouse_send(&report); | ||
| 113 | |||
| 114 | if (buffer[3] || buffer[4]) { | ||
| 115 | report.x = MAX((int8_t)buffer[3], -127); | ||
| 116 | report.y = MAX(-(int8_t)buffer[4], -127); | ||
| 117 | |||
| 118 | print_usb_data(&report); | ||
| 119 | host_mouse_send(&report); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | static void print_usb_data(const report_mouse_t *report) | ||
| 124 | { | ||
| 125 | if (!debug_mouse) | ||
| 126 | return; | ||
| 127 | |||
| 128 | xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n", | ||
| 129 | report->buttons, report->x, report->y, | ||
| 130 | report->v, report->h); | ||
| 131 | } | ||
