Merge branch 'rhaberkorn-serial-mouse'
This commit is contained in:
commit
9772e2cc56
@ -37,6 +37,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#ifdef PS2_MOUSE_ENABLE
|
#ifdef PS2_MOUSE_ENABLE
|
||||||
# include "ps2_mouse.h"
|
# include "ps2_mouse.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SERIAL_MOUSE_ENABLE
|
||||||
|
#include "serial_mouse.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef MATRIX_HAS_GHOST
|
#ifdef MATRIX_HAS_GHOST
|
||||||
@ -64,6 +67,10 @@ void keyboard_init(void)
|
|||||||
#ifdef PS2_MOUSE_ENABLE
|
#ifdef PS2_MOUSE_ENABLE
|
||||||
ps2_mouse_init();
|
ps2_mouse_init();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SERIAL_MOUSE_ENABLE
|
||||||
|
serial_mouse_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef BOOTMAGIC_ENABLE
|
#ifdef BOOTMAGIC_ENABLE
|
||||||
bootmagic();
|
bootmagic();
|
||||||
@ -126,6 +133,10 @@ MATRIX_LOOP_END:
|
|||||||
ps2_mouse_task();
|
ps2_mouse_task();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SERIAL_MOUSE_ENABLE
|
||||||
|
serial_mouse_task();
|
||||||
|
#endif
|
||||||
|
|
||||||
// update LED
|
// update LED
|
||||||
if (led_status != host_keyboard_leds()) {
|
if (led_status != host_keyboard_leds()) {
|
||||||
led_status = host_keyboard_leds();
|
led_status = host_keyboard_leds();
|
||||||
|
20
protocol.mk
20
protocol.mk
@ -23,5 +23,25 @@ ifdef PS2_USE_USART
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
ifdef SERIAL_MOUSE_MICROSOFT_ENABLE
|
||||||
|
SRC += $(PROTOCOL_DIR)/serial_mouse_microsoft.c
|
||||||
|
OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MICROSOFT \
|
||||||
|
-DMOUSE_ENABLE
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef SERIAL_MOUSE_MOUSESYSTEMS_ENABLE
|
||||||
|
SRC += $(PROTOCOL_DIR)/serial_mouse_mousesystems.c
|
||||||
|
OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MOUSESYSTEMS \
|
||||||
|
-DMOUSE_ENABLE
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef SERIAL_MOUSE_USE_SOFT
|
||||||
|
SRC += $(PROTOCOL_DIR)/serial_soft.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef SERIAL_MOUSE_USE_UART
|
||||||
|
SRC += $(PROTOCOL_DIR)/serial_uart.c
|
||||||
|
endif
|
||||||
|
|
||||||
# Search Path
|
# Search Path
|
||||||
VPATH += $(TOP_DIR)/protocol
|
VPATH += $(TOP_DIR)/protocol
|
||||||
|
33
protocol/serial_mouse.h
Normal file
33
protocol/serial_mouse.h
Normal file
@ -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
|
124
protocol/serial_mouse_microsoft.c
Normal file
124
protocol/serial_mouse_microsoft.c
Normal file
@ -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);
|
||||||
|
}
|
131
protocol/serial_mouse_mousesystems.c
Normal file
131
protocol/serial_mouse_mousesystems.c
Normal file
@ -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);
|
||||||
|
}
|
@ -122,7 +122,11 @@ void serial_send(uint8_t data)
|
|||||||
/* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */
|
/* signal state: IDLE: ON, START: OFF, STOP: ON, DATA0: OFF, DATA1: ON */
|
||||||
|
|
||||||
#ifdef SERIAL_SOFT_BIT_ORDER_MSB
|
#ifdef SERIAL_SOFT_BIT_ORDER_MSB
|
||||||
|
#ifdef SERIAL_SOFT_DATA_7BIT
|
||||||
|
uint8_t mask = 0x40;
|
||||||
|
#else
|
||||||
uint8_t mask = 0x80;
|
uint8_t mask = 0x80;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
uint8_t mask = 0x01;
|
uint8_t mask = 0x01;
|
||||||
#endif
|
#endif
|
||||||
@ -133,7 +137,11 @@ void serial_send(uint8_t data)
|
|||||||
SERIAL_SOFT_TXD_OFF();
|
SERIAL_SOFT_TXD_OFF();
|
||||||
_delay_us(WAIT_US);
|
_delay_us(WAIT_US);
|
||||||
|
|
||||||
while (mask) {
|
#ifdef SERIAL_SOFT_DATA_7BIT
|
||||||
|
while (mask&0x7F) {
|
||||||
|
#else
|
||||||
|
while (mask&0xFF) {
|
||||||
|
#endif
|
||||||
if (data&mask) {
|
if (data&mask) {
|
||||||
SERIAL_SOFT_TXD_ON();
|
SERIAL_SOFT_TXD_ON();
|
||||||
parity ^= 1;
|
parity ^= 1;
|
||||||
@ -173,7 +181,11 @@ ISR(SERIAL_SOFT_RXD_VECT)
|
|||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
|
|
||||||
#ifdef SERIAL_SOFT_BIT_ORDER_MSB
|
#ifdef SERIAL_SOFT_BIT_ORDER_MSB
|
||||||
|
#ifdef SERIAL_SOFT_DATA_7BIT
|
||||||
|
uint8_t mask = 0x40;
|
||||||
|
#else
|
||||||
uint8_t mask = 0x80;
|
uint8_t mask = 0x80;
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
uint8_t mask = 0x01;
|
uint8_t mask = 0x01;
|
||||||
#endif
|
#endif
|
||||||
@ -197,7 +209,11 @@ ISR(SERIAL_SOFT_RXD_VECT)
|
|||||||
#else
|
#else
|
||||||
mask <<= 1;
|
mask <<= 1;
|
||||||
#endif
|
#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)
|
#if defined(SERIAL_SOFT_PARITY_EVEN) || defined(SERIAL_SOFT_PARITY_ODD)
|
||||||
/* to center of parity bit */
|
/* to center of parity bit */
|
||||||
|
Reference in New Issue
Block a user