aboutsummaryrefslogtreecommitdiffstats
path: root/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'protocol')
-rw-r--r--protocol/pjrc/usb_keyboard.c2
-rw-r--r--protocol/serial_mouse.h33
-rw-r--r--protocol/serial_mouse_microsoft.c124
-rw-r--r--protocol/serial_mouse_mousesystems.c131
-rw-r--r--protocol/serial_soft.c20
-rw-r--r--protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h2
-rw-r--r--protocol/usb_hid/override_wiring.c1
-rw-r--r--protocol/usb_hid/parser.cpp2
-rw-r--r--protocol/vusb/usbdrv/usbdrv.c8
-rw-r--r--protocol/vusb/usbdrv/usbdrv.h14
-rw-r--r--protocol/vusb/vusb.c17
11 files changed, 332 insertions, 22 deletions
diff --git a/protocol/pjrc/usb_keyboard.c b/protocol/pjrc/usb_keyboard.c
index d16833187..758a4edc6 100644
--- a/protocol/pjrc/usb_keyboard.c
+++ b/protocol/pjrc/usb_keyboard.c
@@ -39,7 +39,7 @@ uint8_t keyboard_protocol=1;
// the idle configuration, how often we send the report to the
// host (ms * 4) even when it hasn't changed
// Windows and Linux set 0 while OS X sets 6(24ms) by SET_IDLE request.
-uint8_t keyobard_idle=125;
+uint8_t keyboard_idle=125;
// count until idle timeout
uint8_t usb_keyboard_idle_count=0;
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 @@
+/*
+Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SERIAL_MOUSE_H
+#define SERIAL_MOUSE_H
+
+#include <stdint.h>
+
+#include "serial.h"
+
+static inline uint8_t serial_mouse_init(void)
+{
+ serial_init();
+ return 0;
+}
+
+void serial_mouse_task(void);
+
+#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 @@
+/*
+Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <avr/io.h>
+#include <util/delay.h>
+
+#include "serial.h"
+#include "serial_mouse.h"
+#include "report.h"
+#include "host.h"
+#include "timer.h"
+#include "print.h"
+#include "debug.h"
+
+#ifdef MAX
+#undef MAX
+#endif
+#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+
+static void print_usb_data(const report_mouse_t *report);
+
+void serial_mouse_task(void)
+{
+ /* 3 byte ring buffer */
+ static uint8_t buffer[3];
+ static int buffer_cur = 0;
+
+ static report_mouse_t report = {};
+
+ int16_t rcv;
+
+ rcv = serial_recv2();
+ if (rcv < 0)
+ /* no new data */
+ return;
+
+ if (debug_mouse)
+ xprintf("serial_mouse: byte: %04X\n", rcv);
+
+ /*
+ * If bit 6 is one, this signals the beginning
+ * of a 3 byte sequence/packet.
+ */
+ if (rcv & (1 << 6))
+ buffer_cur = 0;
+
+ buffer[buffer_cur] = (uint8_t)rcv;
+
+ if (buffer_cur == 0 && buffer[buffer_cur] == 0x20) {
+ /*
+ * Logitech extension: This must be a follow-up on
+ * the last 3-byte packet signaling a middle button click
+ */
+ report.buttons |= MOUSE_BTN3;
+ report.x = report.y = 0;
+
+ print_usb_data(&report);
+ host_mouse_send(&report);
+ return;
+ }
+
+ buffer_cur++;
+
+ if (buffer_cur < 3)
+ return;
+ buffer_cur = 0;
+
+ /*
+ * parse 3 byte packet.
+ * NOTE: We only get a complete packet
+ * if the mouse moved or the button states
+ * change.
+ */
+ report.buttons = 0;
+ if (buffer[0] & (1 << 5))
+ report.buttons |= MOUSE_BTN1;
+ if (buffer[0] & (1 << 4))
+ report.buttons |= MOUSE_BTN2;
+
+ report.x = (buffer[0] << 6) | buffer[1];
+ report.y = ((buffer[0] << 4) & 0xC0) | buffer[2];
+
+ /* USB HID uses values from -127 to 127 only */
+ report.x = MAX(report.x, -127);
+ report.y = MAX(report.y, -127);
+
+#if 0
+ if (!report.buttons && !report.x && !report.y) {
+ /*
+ * Microsoft extension: Middle mouse button pressed
+ * FIXME: I don't know how exactly this extension works.
+ */
+ report.buttons |= MOUSE_BTN3;
+ }
+#endif
+
+ print_usb_data(&report);
+ host_mouse_send(&report);
+}
+
+static void print_usb_data(const report_mouse_t *report)
+{
+ if (!debug_mouse)
+ return;
+
+ xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n",
+ report->buttons, report->x, report->y,
+ report->v, report->h);
+}
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 @@
+/*
+Copyright 2014 Robin Haberkorn <robin.haberkorn@googlemail.com>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <avr/io.h>
+#include <util/delay.h>
+
+#include "serial.h"
+#include "serial_mouse.h"
+#include "report.h"
+#include "host.h"
+#include "timer.h"
+#include "print.h"
+#include "debug.h"
+
+#ifdef MAX
+#undef MAX
+#endif
+#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
+
+//#define SERIAL_MOUSE_CENTER_SCROLL
+
+static void print_usb_data(const report_mouse_t *report);
+
+void serial_mouse_task(void)
+{
+ /* 5 byte ring buffer */
+ static uint8_t buffer[5];
+ static int buffer_cur = 0;
+
+ int16_t rcv;
+
+ report_mouse_t report = {0, 0, 0, 0, 0};
+
+ rcv = serial_recv2();
+ if (rcv < 0)
+ /* no new data */
+ return;
+
+ if (debug_mouse)
+ xprintf("serial_mouse: byte: %04X\n", rcv);
+
+ /*
+ * Synchronization: mouse(4) says that all
+ * bytes but the first one in the packet have
+ * bit 7 == 0, but this is untrue.
+ * Therefore we discard all bytes up to the
+ * first one with the characteristic bit pattern.
+ */
+ if (buffer_cur == 0 && (rcv >> 3) != 0x10)
+ return;
+
+ buffer[buffer_cur++] = (uint8_t)rcv;
+
+ if (buffer_cur < 5)
+ return;
+ buffer_cur = 0;
+
+#ifdef SERIAL_MOUSE_CENTER_SCROLL
+ if ((buffer[0] & 0x7) == 0x5 && (buffer[1] || buffer[2])) {
+ /* USB HID uses only values from -127 to 127 */
+ report.h = MAX((int8_t)buffer[1], -127);
+ report.v = MAX((int8_t)buffer[2], -127);
+
+ print_usb_data(&report);
+ host_mouse_send(&report);
+
+ if (buffer[3] || buffer[4]) {
+ report.h = MAX((int8_t)buffer[3], -127);
+ report.v = MAX((int8_t)buffer[4], -127);
+
+ print_usb_data(&report);
+ host_mouse_send(&report);
+ }
+
+ return;
+ }
+#endif
+
+ /*
+ * parse 5 byte packet.
+ * NOTE: We only get a complete packet
+ * if the mouse moved or the button states
+ * change.
+ */
+ if (!(buffer[0] & (1 << 2)))
+ report.buttons |= MOUSE_BTN1;
+ if (!(buffer[0] & (1 << 1)))
+ report.buttons |= MOUSE_BTN3;
+ if (!(buffer[0] & (1 << 0)))
+ report.buttons |= MOUSE_BTN2;
+
+ /* USB HID uses only values from -127 to 127 */
+ report.x = MAX((int8_t)buffer[1], -127);
+ report.y = MAX(-(int8_t)buffer[2], -127);
+
+ print_usb_data(&report);
+ host_mouse_send(&report);
+
+ if (buffer[3] || buffer[4]) {
+ report.x = MAX((int8_t)buffer[3], -127);
+ report.y = MAX(-(int8_t)buffer[4], -127);
+
+ print_usb_data(&report);
+ host_mouse_send(&report);
+ }
+}
+
+static void print_usb_data(const report_mouse_t *report)
+{
+ if (!debug_mouse)
+ return;
+
+ xprintf("serial_mouse usb: [%02X|%d %d %d %d]\n",
+ report->buttons, report->x, report->y,
+ report->v, report->h);
+}
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c
index e8870bcd7..44822b7e4 100644
--- a/protocol/serial_soft.c
+++ b/protocol/serial_soft.c
@@ -122,7 +122,11 @@ void serial_send(uint8_t data)
/* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */
#ifdef SERIAL_SOFT_BIT_ORDER_MSB
+ #ifdef SERIAL_SOFT_DATA_7BIT
+ uint8_t mask = 0x40;
+ #else
uint8_t mask = 0x80;
+ #endif
#else
uint8_t mask = 0x01;
#endif
@@ -133,7 +137,11 @@ void serial_send(uint8_t data)
SERIAL_SOFT_TXD_OFF();
_delay_us(WAIT_US);
- while (mask) {
+#ifdef SERIAL_SOFT_DATA_7BIT
+ while (mask&0x7F) {
+#else
+ while (mask&0xFF) {
+#endif
if (data&mask) {
SERIAL_SOFT_TXD_ON();
parity ^= 1;
@@ -173,7 +181,11 @@ ISR(SERIAL_SOFT_RXD_VECT)
uint8_t data = 0;
#ifdef SERIAL_SOFT_BIT_ORDER_MSB
+ #ifdef SERIAL_SOFT_DATA_7BIT
+ uint8_t mask = 0x40;
+ #else
uint8_t mask = 0x80;
+ #endif
#else
uint8_t mask = 0x01;
#endif
@@ -197,7 +209,11 @@ ISR(SERIAL_SOFT_RXD_VECT)
#else
mask <<= 1;
#endif
- } while (mask);
+#ifdef SERIAL_SOFT_DATA_7BIT
+ } while (mask&0x7F);
+#else
+ } while (mask&0xFF);
+#endif
#if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD)
/* to center of parity bit */
diff --git a/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h b/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h
index d76d2a33d..947325e5f 100644
--- a/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h
+++ b/protocol/usb_hid/arduino-1.0.1/cores/arduino/WString.h
@@ -35,7 +35,7 @@
// -std=c++0x
class __FlashStringHelper;
-#define F(string_literal) (reinterpret_cast<__FlashStringHelper *>(PSTR(string_literal)))
+#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
// An inherited class for holding the result of a concatenation. These
// result objects are assumed to be writable by subsequent concatenations.
diff --git a/protocol/usb_hid/override_wiring.c b/protocol/usb_hid/override_wiring.c
index 3b3f5e302..1e9a94ce2 100644
--- a/protocol/usb_hid/override_wiring.c
+++ b/protocol/usb_hid/override_wiring.c
@@ -1,6 +1,7 @@
/*
* To keep Timer0 for common/timer.c override arduino/wiring.c.
*/
+#define __DELAY_BACKWARD_COMPATIBLE__
#include <util/delay.h>
#include "common/timer.h"
#include "Arduino.h"
diff --git a/protocol/usb_hid/parser.cpp b/protocol/usb_hid/parser.cpp
index 66e949518..28151f9d5 100644
--- a/protocol/usb_hid/parser.cpp
+++ b/protocol/usb_hid/parser.cpp
@@ -1,5 +1,3 @@
-#include <cstring.h>
-
#include "parser.h"
#include "usb_hid.h"
diff --git a/protocol/vusb/usbdrv/usbdrv.c b/protocol/vusb/usbdrv/usbdrv.c
index 21ed554f8..2e8dd8756 100644
--- a/protocol/vusb/usbdrv/usbdrv.c
+++ b/protocol/vusb/usbdrv/usbdrv.c
@@ -67,7 +67,7 @@ optimizing hints:
#if USB_CFG_DESCR_PROPS_STRING_0 == 0
#undef USB_CFG_DESCR_PROPS_STRING_0
#define USB_CFG_DESCR_PROPS_STRING_0 sizeof(usbDescriptorString0)
-PROGMEM char usbDescriptorString0[] = { /* language descriptor */
+const PROGMEM char usbDescriptorString0[] = { /* language descriptor */
4, /* sizeof(usbDescriptorString0): length of descriptor in bytes */
3, /* descriptor type */
0x09, 0x04, /* language index (0x0409 = US-English) */
@@ -77,7 +77,7 @@ PROGMEM char usbDescriptorString0[] = { /* language descriptor */
#if USB_CFG_DESCR_PROPS_STRING_VENDOR == 0 && USB_CFG_VENDOR_NAME_LEN
#undef USB_CFG_DESCR_PROPS_STRING_VENDOR
#define USB_CFG_DESCR_PROPS_STRING_VENDOR sizeof(usbDescriptorStringVendor)
-PROGMEM int usbDescriptorStringVendor[] = {
+const PROGMEM int usbDescriptorStringVendor[] = {
USB_STRING_DESCRIPTOR_HEADER(USB_CFG_VENDOR_NAME_LEN),
USB_CFG_VENDOR_NAME
};
@@ -86,7 +86,7 @@ PROGMEM int usbDescriptorStringVendor[] = {
#if USB_CFG_DESCR_PROPS_STRING_PRODUCT == 0 && USB_CFG_DEVICE_NAME_LEN
#undef USB_CFG_DESCR_PROPS_STRING_PRODUCT
#define USB_CFG_DESCR_PROPS_STRING_PRODUCT sizeof(usbDescriptorStringDevice)
-PROGMEM int usbDescriptorStringDevice[] = {
+const PROGMEM int usbDescriptorStringDevice[] = {
USB_STRING_DESCRIPTOR_HEADER(USB_CFG_DEVICE_NAME_LEN),
USB_CFG_DEVICE_NAME
};
@@ -108,7 +108,7 @@ PROGMEM int usbDescriptorStringSerialNumber[] = {
#if USB_CFG_DESCR_PROPS_DEVICE == 0
#undef USB_CFG_DESCR_PROPS_DEVICE
#define USB_CFG_DESCR_PROPS_DEVICE sizeof(usbDescriptorDevice)
-PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */
+const PROGMEM char usbDescriptorDevice[] = { /* USB device descriptor */
18, /* sizeof(usbDescriptorDevice): length of descriptor in bytes */
USBDESCR_DEVICE, /* descriptor type */
0x10, 0x01, /* USB version supported */
diff --git a/protocol/vusb/usbdrv/usbdrv.h b/protocol/vusb/usbdrv/usbdrv.h
index 3a78f307b..42fe16372 100644
--- a/protocol/vusb/usbdrv/usbdrv.h
+++ b/protocol/vusb/usbdrv/usbdrv.h
@@ -452,43 +452,43 @@ extern
#if !(USB_CFG_DESCR_PROPS_DEVICE & USB_PROP_IS_RAM)
PROGMEM
#endif
-char usbDescriptorDevice[];
+const char usbDescriptorDevice[];
extern
#if !(USB_CFG_DESCR_PROPS_CONFIGURATION & USB_PROP_IS_RAM)
PROGMEM
#endif
-char usbDescriptorConfiguration[];
+const char usbDescriptorConfiguration[];
extern
#if !(USB_CFG_DESCR_PROPS_HID_REPORT & USB_PROP_IS_RAM)
PROGMEM
#endif
-char usbDescriptorHidReport[];
+const char usbDescriptorHidReport[];
extern
#if !(USB_CFG_DESCR_PROPS_STRING_0 & USB_PROP_IS_RAM)
PROGMEM
#endif
-char usbDescriptorString0[];
+const char usbDescriptorString0[];
extern
#if !(USB_CFG_DESCR_PROPS_STRING_VENDOR & USB_PROP_IS_RAM)
PROGMEM
#endif
-int usbDescriptorStringVendor[];
+const int usbDescriptorStringVendor[];
extern
#if !(USB_CFG_DESCR_PROPS_STRING_PRODUCT & USB_PROP_IS_RAM)
PROGMEM
#endif
-int usbDescriptorStringDevice[];
+const int usbDescriptorStringDevice[];
extern
#if !(USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER & USB_PROP_IS_RAM)
PROGMEM
#endif
-int usbDescriptorStringSerialNumber[];
+const int usbDescriptorStringSerialNumber[];
#endif /* __ASSEMBLER__ */
diff --git a/protocol/vusb/vusb.c b/protocol/vusb/vusb.c
index 328885a9b..7d0292ed1 100644
--- a/protocol/vusb/vusb.c
+++ b/protocol/vusb/vusb.c
@@ -35,6 +35,13 @@ static report_keyboard_t kbuf[KBUF_SIZE];
static uint8_t kbuf_head = 0;
static uint8_t kbuf_tail = 0;
+typedef struct {
+ uint8_t modifier;
+ uint8_t reserved;
+ uint8_t keycode[6];
+} keyboard_report_t;
+
+static keyboard_report_t keyboard_report; // sent to PC
/* transfer keyboard report from buffer */
void vusb_transfer_keyboard(void)
@@ -168,8 +175,8 @@ usbRequest_t *rq = (void *)data;
if(rq->bRequest == USBRQ_HID_GET_REPORT){
debug("GET_REPORT:");
/* we only have one report type, so don't look at wValue */
- usbMsgPtr = (void *)keyboard_report;
- return sizeof(*keyboard_report);
+ usbMsgPtr = (void *)&keyboard_report;
+ return sizeof(keyboard_report);
}else if(rq->bRequest == USBRQ_HID_GET_IDLE){
debug("GET_IDLE: ");
//debug_hex(vusb_idle_rate);
@@ -232,7 +239,7 @@ uchar usbFunctionWrite(uchar *data, uchar len)
*
* from an example in HID spec appendix
*/
-PROGMEM uchar keyboard_hid_report[] = {
+const PROGMEM uchar keyboard_hid_report[] = {
0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
0xA1, 0x01, // Collection (Application),
@@ -275,7 +282,7 @@ PROGMEM uchar keyboard_hid_report[] = {
* http://www.keil.com/forum/15671/
* http://www.microsoft.com/whdc/device/input/wheel.mspx
*/
-PROGMEM uchar mouse_hid_report[] = {
+const PROGMEM uchar mouse_hid_report[] = {
/* mouse */
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
@@ -358,7 +365,7 @@ PROGMEM uchar mouse_hid_report[] = {
* contains: device, interface, HID and endpoint descriptors
*/
#if USB_CFG_DESCR_PROPS_CONFIGURATION
-PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */
+const PROGMEM char usbDescriptorConfiguration[] = { /* USB configuration descriptor */
9, /* sizeof(usbDescriptorConfiguration): length of descriptor in bytes */
USBDESCR_CONFIG, /* descriptor type */
9 + (9 + 9 + 7) + (9 + 9 + 7), 0,