Skip to content

Commit

Permalink
Fix PS2 pin definitions for qmk#14745
Browse files Browse the repository at this point in the history
Replace serial_mouse removed by qmk#14969
  • Loading branch information
MMcM committed Oct 22, 2022
1 parent 10bc011 commit 4cc0a26
Show file tree
Hide file tree
Showing 13 changed files with 317 additions and 77 deletions.
32 changes: 6 additions & 26 deletions keyboards/converter/amtelco_kb163/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@
*/
#ifdef PS2_USE_USART
/* XCK for clock line */
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 5
#define PS2_CLOCK_PIN D5
/* RXD for data line */
#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 2
#define PS2_DATA_PIN D2

/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
/* set DDR of CLOCK as input to be slave */
Expand Down Expand Up @@ -61,15 +55,8 @@
*/
#ifdef PS2_USE_INT
/* uses INT1 for clock line(ATMega32U4) */
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 1

#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 0
#define PS2_CLOCK_PIN D1
#define PS2_DATA_PIN D0

#define PS2_INT_INIT() do { \
EICRA |= ((1<<ISC11) | \
Expand All @@ -89,13 +76,6 @@
* PS/2 Busywait configuration
*/
#ifdef PS2_USE_BUSYWAIT
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 1

#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 0
#define PS2_CLOCK_PIN D1
#define PS2_DATA_PIN D0
#endif
1 change: 1 addition & 0 deletions keyboards/converter/amtelco_kb163/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ uint8_t matrix_scan(void) {
}

dprintf("%02X%c", code, sent ? '\n' : ' ');
matrix_scan_quantum();
return 1;
}

Expand Down
32 changes: 6 additions & 26 deletions keyboards/converter/deko_fak/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@
*/
#ifdef PS2_USE_USART
/* XCK for clock line */
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 5
#define PS2_CLOCK_PIN D5
/* RXD for data line */
#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 2
#define PS2_DATA_PIN D2

/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
/* set DDR of CLOCK as input to be slave */
Expand Down Expand Up @@ -67,15 +61,8 @@
*/
#ifdef PS2_USE_INT
/* uses INT1 for clock line(ATMega32U4) */
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 1

#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 0
#define PS2_CLOCK_PIN D1
#define PS2_DATA_PIN D0

#define PS2_INT_INIT() do { \
EICRA |= ((1<<ISC11) | \
Expand All @@ -95,13 +82,6 @@
* PS/2 Busywait configuration
*/
#ifdef PS2_USE_BUSYWAIT
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 1

#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 0
#define PS2_CLOCK_PIN D1
#define PS2_DATA_PIN D0
#endif
1 change: 1 addition & 0 deletions keyboards/converter/deko_fak/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ uint8_t matrix_scan(void) {
}

dprintf("r%02X%c", code, sent ? '\n' : ' ');
matrix_scan_quantum();
return 1;
}

Expand Down
31 changes: 8 additions & 23 deletions keyboards/converter/ps2_serial_mouse/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@
*/
#ifdef PS2_USE_INT
/* uses INT1 for clock line(ATMega32U4) */
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 1

#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 0
#define PS2_CLOCK_PIN D1
#define PS2_DATA_PIN D0

#define PS2_INT_INIT() do { \
EICRA |= ((1<<ISC11) | \
Expand All @@ -49,15 +42,8 @@
* PS/2 Busywait configuration
*/
#ifdef PS2_USE_BUSYWAIT
#define PS2_CLOCK_PORT PORTD
#define PS2_CLOCK_PIN PIND
#define PS2_CLOCK_DDR DDRD
#define PS2_CLOCK_BIT 1

#define PS2_DATA_PORT PORTD
#define PS2_DATA_PIN PIND
#define PS2_DATA_DDR DDRD
#define PS2_DATA_BIT 0
#define PS2_CLOCK_PIN D1
#define PS2_DATA_PIN D0
#endif

/*
Expand All @@ -67,8 +53,7 @@
#define SERIAL_UART_INIT_CUSTOM \
/* enable TX and RX with interrupt */ \
UCSR1B = _BV(TXEN1) | _BV(RXEN1) | _BV(RXCIE1); \
/* 7-bit data, two stop bits (ignored on receive) */ \
UCSR1C = _BV(UCSZ11) | _BV(USBS1); \
/* Turn on DTR via PC6 */ \
DDRC |= (1 << 6); \
PORTC |= (1 << 6);
/* 8-bit data */ \
UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
/* Turn on DTR via PC6 by setting T2IN low = space = asserted */ \
DDRC |= (1 << 6);
1 change: 0 additions & 1 deletion keyboards/converter/ps2_serial_mouse/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"mousekey": false,
"nkro": false,
"rgblight": false,
"serial_mouse_microsoft": true,
"sleep_led": false,
"unicode": false
},
Expand Down
1 change: 1 addition & 0 deletions keyboards/converter/ps2_serial_mouse/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ uint8_t matrix_scan(void) {
}

dprintf("%02X%c", code, sent ? '\n' : ' ');
matrix_scan_quantum();
return 1;
}

Expand Down
15 changes: 15 additions & 0 deletions keyboards/converter/ps2_serial_mouse/ps2_serial_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
#include "ps2_serial_mouse.h"
#include <avr/io.h>
#include "quantum.h"

#ifdef SERIAL_MOUSE_ENABLE

#include "serial_mouse.h"

void keyboard_post_init_kb(void) {
serial_mouse_init();
keyboard_post_init_user();
}

void housekeeping_task_kb(void) {
serial_mouse_task();
}

#endif
2 changes: 1 addition & 1 deletion keyboards/converter/ps2_serial_mouse/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ The DIN-5 keyboard connector has Data on D0 and Clock on D1.

The serial port needs an RS-232 level shifter like a MAX232 and is then connected to RXD1 (D2) and TXD1 (D3).

RTS and DTR also need to be set, since that is how the mouse gets power. RTS can be wired to Vs+ from the MAX232 and DTS to the second transmit line, controlled by GPIO C6.
RTS and DTR also need to be set, since that is how the mouse gets power. RTS can be wired to Vs+ from the MAX232 and DTR to the second transmit line, controlled by GPIO C6.
15 changes: 15 additions & 0 deletions keyboards/converter/ps2_serial_mouse/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ HARDWARE_SERIAL = yes
SRC = matrix.c led.c

SRC += protocol/serial_uart.c

SERIAL_MOUSE_MICROSOFT_ENABLE ?= no
SERIAL_MOUSE_MOUSESYSTEMS_ENABLE ?= yes

ifeq ($(strip $(SERIAL_MOUSE_MICROSOFT_ENABLE)), yes)
SRC += serial_mouse_microsoft.c
OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MICROSOFT \
-DMOUSE_ENABLE
endif

ifeq ($(strip $(SERIAL_MOUSE_MOUSESYSTEMS_ENABLE)), yes)
SRC += serial_mouse_mousesystems.c
OPT_DEFS += -DSERIAL_MOUSE_ENABLE -DSERIAL_MOUSE_MOUSESYSTEMS \
-DMOUSE_ENABLE
endif
29 changes: 29 additions & 0 deletions keyboards/converter/ps2_serial_mouse/serial_mouse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2014 Robin Haberkorn <[email protected]>
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/>.
*/

#pragma once

#include <stdint.h>

#include "protocol/serial.h"

static inline uint8_t serial_mouse_init(void) {
serial_init();
return 0;
}

void serial_mouse_task(void);
115 changes: 115 additions & 0 deletions keyboards/converter/ps2_serial_mouse/serial_mouse_microsoft.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Copyright 2014 Robin Haberkorn <[email protected]>
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 "protocol/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;

rcv &= 0x7F;

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);
}
Loading

0 comments on commit 4cc0a26

Please sign in to comment.