Skip to content

Commit 0e1aeaa

Browse files
committed
serial_mouse: Add initial files
1 parent 4923f09 commit 0e1aeaa

File tree

4 files changed

+294
-0
lines changed

4 files changed

+294
-0
lines changed

converter/serial_mouse/Makefile

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Target file name (without extension).
2+
TARGET = serial_mouse
3+
4+
# Directory common source filess exist
5+
TMK_DIR = ../../tmk_core
6+
7+
# Directory keyboard dependent files exist
8+
TARGET_DIR = .
9+
10+
# project specific files
11+
SRC = serial_mouse.c
12+
13+
CONFIG_H = config.h
14+
15+
16+
# MCU name
17+
#MCU = at90usb1287
18+
MCU = atmega32u4
19+
20+
# Processor frequency.
21+
# This will define a symbol, F_CPU, in all source code files equal to the
22+
# processor frequency in Hz. You can then use this symbol in your source code to
23+
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
24+
# automatically to create a 32-bit value in your source code.
25+
#
26+
# This will be an integer division of F_USB below, as it is sourced by
27+
# F_USB after it has run through any CPU prescalers. Note that this value
28+
# does not *change* the processor frequency - it should merely be updated to
29+
# reflect the processor speed set externally so that the code can use accurate
30+
# software delays.
31+
F_CPU = 16000000
32+
33+
34+
#
35+
# LUFA specific
36+
#
37+
# Target architecture (see library "Board Types" documentation).
38+
ARCH = AVR8
39+
40+
# Input clock frequency.
41+
# This will define a symbol, F_USB, in all source code files equal to the
42+
# input clock frequency (before any prescaling is performed) in Hz. This value may
43+
# differ from F_CPU if prescaling is used on the latter, and is required as the
44+
# raw input clock is fed directly to the PLL sections of the AVR for high speed
45+
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
46+
# at the end, this will be done automatically to create a 32-bit value in your
47+
# source code.
48+
#
49+
# If no clock division is performed on the input clock inside the AVR (via the
50+
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
51+
F_USB = $(F_CPU)
52+
53+
# Interrupt driven control endpoint task(+60)
54+
#OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
55+
56+
57+
# Boot Section Size in *bytes*
58+
# Teensy halfKay 512
59+
# Teensy++ halfKay 1024
60+
# Atmel DFU loader 4096
61+
# LUFA bootloader 4096
62+
# USBaspLoader 2048
63+
OPT_DEFS += -DBOOTLOADER_SIZE=4096
64+
65+
66+
# Build Options
67+
# comment out to disable the options.
68+
#
69+
#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
70+
#MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
71+
#EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
72+
CONSOLE_ENABLE = yes # Console for debug(+400)
73+
#COMMAND_ENABLE = yes # Commands for debug and configuration
74+
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
75+
#NKRO_ENABLE = yes # USB Nkey Rollover
76+
77+
78+
NO_KEYBOARD = yes # disable keyboard
79+
SERIAL_MOUSE_MICROSOFT_ENABLE = yes
80+
SERIAL_MOUSE_USE_UART = yes
81+
#SERIAL_MOUSE_USE_SOFT = yes # Not work atm
82+
83+
84+
85+
# Search Path
86+
VPATH += $(TARGET_DIR)
87+
VPATH += $(TMK_DIR)
88+
89+
include $(TMK_DIR)/common.mk
90+
include $(TMK_DIR)/protocol.mk
91+
include $(TMK_DIR)/protocol/lufa.mk
92+
include $(TMK_DIR)/rules.mk

converter/serial_mouse/README

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Serial Mouse Converter
2+
======================
3+
This makes old serial mouse into modern USB one.
4+
5+
Tested by:
6+
- Microsoft green-eyed mouse
7+
- DELL mouse can work with DTR only.
8+
9+
10+
Pinout
11+
------
12+
13+
DE-9 DB-25 DTE DCE Description
14+
----------------------------------------------------------------
15+
2 3 RXD TXD data from mouse
16+
3 2 TXD RXD used by mouse as power source?
17+
4 20 DTR DSR used by mouse as power source
18+
5 7 GND GND
19+
7 4 RTS CTS used by mouse as power source
20+
*DTE=Converter, DCE=Mouse
21+
22+
23+
24+
## RS-232 Driver
25+
Microsoft mouse seems to need higher voltage for power source.
26+
SP3232E outputs only +-6V at charge pump output and didn't work.
27+
ADM232A works for both Microsoft and DELL.
28+
29+
Microsoft green-eyed mouse requires both while DELL mouse can work with DTR only.
30+
31+
32+
## Wiring
33+
Mouse RXD, TXD, DTR and RTS should be wired to RS-232 driver.
34+
Wire up RS-232 driver charge pump output V+ to DTR and RTS for power source purpose.
35+
36+
Connect Mouse TXD to AVR PD2(RXD) *through* RS-232 driver for mouse data.
37+
38+
39+
40+
UART Setting
41+
------------
42+
defined in config.h.
43+
44+
### Microsoft serial mouse
45+
1200 baud, 7-bit data, no parity, 1-bit stop, lsb-first
46+
47+
### MouseSystems
48+
1200 baud, 8-bit data, no parity, 1-bit stop, lsb-first(Not tested)
49+
50+
51+
Resources
52+
---------
53+
Get power out of PC RS-232 port:
54+
https://www.epanorama.net/circuits/rspower.html
55+
56+
Microsoft serial mouse:
57+
https://web.archive.org/web/20130307230349/www.kryslix.com/nsfaq/Q.12.html
58+
59+
Serial Mice Protocols:
60+
https://roborooter.com/post/serial-mice/

converter/serial_mouse/config.h

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
Copyright 2022 Jun Wako <[email protected]>
3+
*/
4+
5+
#ifndef CONFIG_H
6+
#define CONFIG_H
7+
8+
9+
/* USB Device descriptor parameter */
10+
#define VENDOR_ID 0xFEED
11+
#define PRODUCT_ID 0x31CE
12+
#define DEVICE_VER 0x0001
13+
#define MANUFACTURER TMK
14+
#define PRODUCT Serial Mouse
15+
#define DESCRIPTION TMK keyboard firmware
16+
17+
/* key matrix size */
18+
#define MATRIX_ROWS 1
19+
#define MATRIX_COLS 1
20+
21+
/* key combination for command */
22+
#define IS_COMMAND() ( \
23+
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
24+
)
25+
26+
27+
28+
/*
29+
* Feature disable options
30+
* These options are also useful to firmware size reduction.
31+
*/
32+
33+
/* disable debug print */
34+
//#define NO_DEBUG
35+
36+
/* disable print */
37+
//#define NO_PRINT
38+
39+
/* disable action features */
40+
//#define NO_ACTION_LAYER
41+
//#define NO_ACTION_TAPPING
42+
//#define NO_ACTION_ONESHOT
43+
//#define NO_ACTION_MACRO
44+
//#define NO_ACTION_FUNCTION
45+
46+
47+
48+
/*
49+
* Hardware Serial(UART)
50+
* Add protocol/serial_uart.c to SRC in Makefile
51+
*/
52+
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega32U2__)
53+
#define SERIAL_UART_BAUD 1200
54+
#define SERIAL_UART_DATA UDR1
55+
#define SERIAL_UART_UBRR ((F_CPU/(16UL*SERIAL_UART_BAUD))-1)
56+
#define SERIAL_UART_RXD_VECT USART1_RX_vect
57+
#define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1))
58+
#define SERIAL_UART_INIT() do { \
59+
UBRR1L = (uint8_t) SERIAL_UART_UBRR; /* baud rate */ \
60+
UBRR1H = (uint8_t) (SERIAL_UART_UBRR>>8); /* baud rate */ \
61+
UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); /* RX interrupt, RX: enable */ \
62+
UCSR1B |= (0<<TXCIE1) | (1<<TXEN1); /* TX interrupt, TX: enable */ \
63+
UCSR1C = (1<<UCSZ11) | (0<<UCSZ10) | /* data: 7-bit */ \
64+
(0<<UPM11) | (0<<UPM10); /* parity: none(00), even(01), odd(11) */ \
65+
DDRD &= ~(1<<2); PORTD |= (1<<2); /* Pull-up RXD pin */ \
66+
sei(); \
67+
} while(0)
68+
#else
69+
#error "USART configuration is needed."
70+
#endif
71+
72+
73+
/*
74+
* Software Serial
75+
* Add protocol/serial_soft.c to SRC in Makefile
76+
*/
77+
#define SERIAL_SOFT_BAUD 1200
78+
#define SERIAL_SOFT_PARITY_NONE
79+
#define SERIAL_SOFT_BIT_ORDER_MSB
80+
//#define SERIAL_SOFT_LOGIC_NEGATIVE
81+
#define SERIAL_SOFT_DATA_7BIT
82+
#define SERIAL_SOFT_DEBUG
83+
/* RXD Port */
84+
#define SERIAL_SOFT_RXD_DDR DDRD
85+
#define SERIAL_SOFT_RXD_PORT PORTD
86+
#define SERIAL_SOFT_RXD_PIN PIND
87+
#define SERIAL_SOFT_RXD_BIT 2
88+
#define SERIAL_SOFT_RXD_READ() (SERIAL_SOFT_RXD_PIN&(1<<SERIAL_SOFT_RXD_BIT))
89+
/* RXD Interupt */
90+
#define SERIAL_SOFT_RXD_VECT INT2_vect
91+
#define SERIAL_SOFT_RXD_INIT() do { \
92+
/* pin configuration: input with pull-up */ \
93+
SERIAL_SOFT_RXD_DDR &= ~(1<<SERIAL_SOFT_RXD_BIT); \
94+
SERIAL_SOFT_RXD_PORT |= (1<<SERIAL_SOFT_RXD_BIT); \
95+
/* enable interrupt: INT2(Positive:falling edge, Negative:rising edge) */ \
96+
EICRA |= ((1<<ISC21)|(1<<ISC20)); \
97+
/* EICRA |= ((1<<ISC21)|(0<<ISC20)); \ */ \
98+
EIMSK |= (1<<INT2); \
99+
sei(); \
100+
} while (0)
101+
#define SERIAL_SOFT_RXD_INT_ENTER()
102+
#define SERIAL_SOFT_RXD_INT_EXIT() do { \
103+
/* clear interrupt flag */ \
104+
EIFR = (1<<INTF2); \
105+
} while (0)
106+
/* TXD Port */
107+
#define SERIAL_SOFT_TXD_DDR DDRD
108+
#define SERIAL_SOFT_TXD_PORT PORTD
109+
#define SERIAL_SOFT_TXD_PIN PIND
110+
#define SERIAL_SOFT_TXD_BIT 3
111+
#define SERIAL_SOFT_TXD_HI() do { SERIAL_SOFT_TXD_PORT |= (1<<SERIAL_SOFT_TXD_BIT); } while (0)
112+
#define SERIAL_SOFT_TXD_LO() do { SERIAL_SOFT_TXD_PORT &= ~(1<<SERIAL_SOFT_TXD_BIT); } while (0)
113+
#define SERIAL_SOFT_TXD_INIT() do { \
114+
/* pin configuration: output */ \
115+
SERIAL_SOFT_TXD_DDR |= (1<<SERIAL_SOFT_TXD_BIT); \
116+
/* idle */ \
117+
SERIAL_SOFT_TXD_ON(); \
118+
} while (0)
119+
120+
121+
#endif

converter/serial_mouse/serial_mouse.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2022 Jun Wako <[email protected]>
3+
*/
4+
5+
#include <stdint.h>
6+
#include <stdbool.h>
7+
#include "debug.h"
8+
#include "serial_mouse.h"
9+
10+
11+
void hook_early_init(void)
12+
{
13+
debug_enable = true;
14+
debug_mouse = true;
15+
serial_mouse_init();
16+
}
17+
18+
void hook_main_loop(void)
19+
{
20+
serial_mouse_task();
21+
}

0 commit comments

Comments
 (0)