Merge branch 'adb_mouse_driver_release'
This commit is contained in:
commit
8cc3905122
5 changed files with 241 additions and 79 deletions
|
|
@ -79,7 +79,7 @@ ACTIONMAP_ENABLE ?= no # Use 16bit actionmap instead of 8bit keymap
|
||||||
KEYMAP_SECTION_ENABLE ?= yes # fixed address keymap for keymap editor
|
KEYMAP_SECTION_ENABLE ?= yes # fixed address keymap for keymap editor
|
||||||
|
|
||||||
# ADB Mice need acceleration for todays much bigger screens.
|
# ADB Mice need acceleration for todays much bigger screens.
|
||||||
ADB_MOUSE_MAXACC ?= 8
|
ADB_MOUSE_MAXACC ?= 1
|
||||||
OPT_DEFS += -DADB_MOUSE_MAXACC=$(ADB_MOUSE_MAXACC)
|
OPT_DEFS += -DADB_MOUSE_MAXACC=$(ADB_MOUSE_MAXACC)
|
||||||
|
|
||||||
# Enable scroll wheel functionality using the y-axis of the mouse
|
# Enable scroll wheel functionality using the y-axis of the mouse
|
||||||
|
|
@ -94,7 +94,7 @@ OPT_DEFS += -DADB_MOUSE_MAXACC=$(ADB_MOUSE_MAXACC)
|
||||||
# left click -> |1 2| <- right click
|
# left click -> |1 2| <- right click
|
||||||
# |________|
|
# |________|
|
||||||
#
|
#
|
||||||
ADB_MOUSE_SCROLL_BUTTON ?= 4 # Assign the button (1-8) (0 to disable)
|
ADB_MOUSE_SCROLL_BUTTON ?= 0 # Assign the button (1-8) (0 to disable)
|
||||||
ADB_MOUSE_SCROLL_SPEED ?= 10 # 1 (fastest) to 127 (slowest)
|
ADB_MOUSE_SCROLL_SPEED ?= 10 # 1 (fastest) to 127 (slowest)
|
||||||
|
|
||||||
# Optimize size but this may cause error "relocation truncated to fit"
|
# Optimize size but this may cause error "relocation truncated to fit"
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,30 @@
|
||||||
ADB to USB keyboard converter
|
ADB to USB keyboard converter
|
||||||
=============================
|
=============================
|
||||||
This firmware converts Apple ADB keyboard/mouse protocol to USB, you can use it to plug old ADB keyboard/mouse into modern computer. It works on prebuilt TMK ADB-USB Converter or generic dev board with USB AVR MCU(ATMega32U4/2) like Teensy2.0.
|
This firmware converts Apple ADB keyboard/mouse protocol to USB and you can use old ADB keyboard/mouse on modern computer. It works on TMK ADB-USB converter or AVR microcontroller(ATMega32U4/2).
|
||||||
|
|
||||||
Discuss about this here: http://geekhack.org/showwiki.php?title=Island:14290
|
Discussion and info: https://geekhack.org/index.php?topic=14290.0
|
||||||
|
|
||||||
Prebuilt TMK ADB-USB converter is available here: https://geekhack.org/index.php?topic=72052.0
|
TMK ADB-USB converter: https://geekhack.org/index.php?topic=72052.0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
README FIRST
|
Infos
|
||||||
------------
|
-----
|
||||||
https://github.com/tmk/tmk_keyboard
|
Wiki: https://github.com/tmk/tmk_keyboard/wiki
|
||||||
https://github.com/tmk/tmk_keyboard/tree/master/converter/adb_usb
|
|
||||||
|
|
||||||
Also check these when you are in trouble.
|
ADB protocol: https://github.com/tmk/tmk_keyboard/wiki/Apple-Desktop-Bus
|
||||||
|
|
||||||
|
Issues: https://github.com/tmk/tmk_keyboard/issues?q=is%3Aissue+ADB
|
||||||
|
|
||||||
|
Firmware Code: https://github.com/tmk/tmk_keyboard/tree/master/converter/adb_usb
|
||||||
|
|
||||||
https://github.com/tmk/tmk_keyboard/wiki
|
|
||||||
https://github.com/tmk/tmk_keyboard/issues
|
|
||||||
|
|
||||||
|
|
||||||
Wiring
|
Wiring
|
||||||
------
|
------
|
||||||
If you build this yourself you have to solder some wires.
|
Connect DATA, VCC and GND to microcontroller. Use port **PD0** for DATA. PSW is not used.
|
||||||
Connect ADB pins to controller just by 3 lines(Vcc, GND, Data) at least. By default Data line uses port PD0.
|
|
||||||
This is not needed but you can connect PSW to PD1 optionally.
|
You can change the port with `ADB_PORT`, `ADB_PIN`, `ADB_DDR`, `ADB_DATA_BIT` in `config.h`.
|
||||||
|
|
||||||
ADB female socket from the front:
|
ADB female socket from the front:
|
||||||
|
|
||||||
|
|
@ -33,10 +34,11 @@ ADB female socket from the front:
|
||||||
- === - 3: VCC
|
- === - 3: VCC
|
||||||
`-___-' 4: GND
|
`-___-' 4: GND
|
||||||
|
|
||||||
This converter uses AVR's internal pull-up, but it seems to be too weak, in particular when you want to use a long or coiled cable. The external pull-up resistor(1K-10K Ohm) on Data is strongly recommended.(It is almost must!)
|
|
||||||
https://github.com/tmk/tmk_keyboard/wiki/FAQ#pull-up-resistor
|
|
||||||
|
|
||||||
Pull-up resister:
|
### Pull-up resister:
|
||||||
|
The external **1k Ohm** pull-up resistor on DATA is **required**.
|
||||||
|
|
||||||
|
AVR microcontroller's internal pull-up is too weak for ADB in particular when you want to use a long coiled cable or daisy-chain devices.
|
||||||
|
|
||||||
Keyboard AVR MCU
|
Keyboard AVR MCU
|
||||||
,------.
|
,------.
|
||||||
|
|
@ -48,18 +50,14 @@ Pull-up resister:
|
||||||
| |
|
| |
|
||||||
GND------------|GND |
|
GND------------|GND |
|
||||||
`------'
|
`------'
|
||||||
R: 1K Ohm resistor
|
R: 1k Ohm resistor
|
||||||
|
|
||||||
|
https://github.com/tmk/tmk_keyboard/wiki/Apple-Desktop-Bus#pull-up-resistor
|
||||||
|
|
||||||
Define following macros for ADB connection in config.h if you use other than port PD0.
|
|
||||||
|
|
||||||
ADB_PORT, ADB_PIN, ADB_DDR, ADB_DATA_BIT
|
|
||||||
|
|
||||||
|
|
||||||
Build firmware and Program microcontroller
|
Build firmware and Program microcontroller
|
||||||
------------------------------------------
|
------------------------------------------
|
||||||
See [doc/build.md](../../tmk_core/doc/build.md).
|
|
||||||
|
|
||||||
To build firmware and program TMK ADB-USB Converter run these commands:
|
To build firmware and program TMK ADB-USB Converter run these commands:
|
||||||
|
|
||||||
$ make -f Makefile clean
|
$ make -f Makefile clean
|
||||||
|
|
@ -70,50 +68,50 @@ You can select keymap name with optional `KEYMAP=` ('plain' is default name). Pu
|
||||||
|
|
||||||
Use **Makefile.rev1** for old TMK Converter rev.1 and Teensy2.0 instead of **Makefile**.
|
Use **Makefile.rev1** for old TMK Converter rev.1 and Teensy2.0 instead of **Makefile**.
|
||||||
|
|
||||||
|
https://github.com/tmk/tmk_keyboard/wiki#build-firmware
|
||||||
|
|
||||||
|
|
||||||
Keymap
|
|
||||||
------
|
|
||||||
You can change keymap by editing code of unimap_plain.c directly, or copy it to your own keymap file like unimap_yourname.c and edit the file.
|
|
||||||
How to define the keymap is probably obvious. You can find key symbols in common/keycode.h. And see [doc/keymap.md](../../tmk_core/doc/keymap.md) for more detail.
|
|
||||||
|
|
||||||
|
Debug
|
||||||
Magic command
|
-----
|
||||||
-------------
|
Use hid_listen command line tool to see debug outputs.
|
||||||
To get help message in hid_listen press `h` holding Magic key. Magic key is `Power key`.
|
|
||||||
|
|
||||||
https://github.com/tmk/tmk_keyboard/wiki#debug
|
https://github.com/tmk/tmk_keyboard/wiki#debug
|
||||||
|
|
||||||
|
|
||||||
Locking CapsLock
|
|
||||||
----------------
|
|
||||||
Many of old ADB keyboards have mechanical push-lock switch for Capslock key and this converter supports the locking Capslock key by default. Use keycode `LCAP` instead of `CAPS` in your keymap in short. See README in top directory for more detail.
|
|
||||||
https://github.com/tmk/tmk_keyboard/blob/master/README.md#mechanical-locking-support
|
|
||||||
|
|
||||||
If you want to remap Capslock key you will have to remove locking pin or just replace with normal momentary switch. Some keyboards like Apple Adujstable keyboard use firmware-base locking with momentary switch for Capslock and remapping it won't be useful in most cases.
|
|
||||||
|
|
||||||
|
|
||||||
Notes for keyboard
|
Notes for keyboard
|
||||||
------------------
|
------------------
|
||||||
Not-extended ADB keyboards have no discrimination between right modifier and left one,
|
Apple Standard keyboard(M0116) can't discriminate between right and left modifiers
|
||||||
you will always see left control even if you press right control key.
|
while Apple Extended keyboard(M0115/M3501) can discriminate them except for Command key.
|
||||||
Apple Extended Keyboard and Apple Extended Keyboard II can discriminate both side
|
|
||||||
modifiers except for GUI key(Windows/Command).
|
|
||||||
|
|
||||||
And most of ADB keyboards have no diodes in its matrix so they are not NKRO unfortunately,
|
|
||||||
though ADB protocol itself supports it. See tmk_core/protocol/adb.c for more info.
|
|
||||||
|
|
||||||
|
|
||||||
Notes for mouse
|
Notes for mouse
|
||||||
---------------
|
---------------
|
||||||
ADB mouse support was added by @mek-apelsin on Apr,2015.
|
All one-button mouses should be supported and others will work as one-button mouse even if not supported.
|
||||||
https://github.com/tmk/tmk_keyboard/pull/207
|
|
||||||
|
|
||||||
All one-button mouses should be supported.
|
Mouse protocols(handler ID) below are curretnly supported.
|
||||||
|
|
||||||
As of 2019 June, the converter can handle multi-button mice and trackball up to eight buttons if the pointing device supports Apple Extended Mouse protocol. But some devices use their own specific protocol unfortunately and they will work as one-button mouse unless device specific code is added.
|
- Apple Classic Mouse protocol (1, 2)
|
||||||
|
- Apple Extended Mouse protocol (4)
|
||||||
|
- Kensington Turbo Mouse 5 #64210 and Thinking Mouse (0x32)
|
||||||
|
- Macally 2-button Mouse (0x42)
|
||||||
|
- Logitech MouseMan/TrackMan Proprietary protocol (0x4C*)
|
||||||
|
- Logitech MouseMan/TrackMan Extended protocol (0x4D*)
|
||||||
|
- Micrspeed MacTrac (0x2F, 0x5F) - Not confirmed
|
||||||
|
- Contour Design Countour Mouse (0x66) - Not confirmed
|
||||||
|
- Mouse Systems A3 Mouse/Trackball (0x03) - Not confirmed
|
||||||
|
- CH Products Tracball Pro/DT225 (0x42) - Not confirmed
|
||||||
|
|
||||||
Kensington Turbo Mouse 5(#64210) is supported now.
|
https://github.com/tmk/tmk_keyboard/wiki/Apple-Desktop-Bus#mouse
|
||||||
https://github.com/tmk/tmk_keyboard/issues/274#issuecomment-504726633
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
||||||
|
Locking CapsLock
|
||||||
|
----------------
|
||||||
|
Many of old ADB keyboards have mechanical push-lock switch for Capslock and some like Apple Adujstable keyboard use firmware-base locking with momentary switch for Capslock.
|
||||||
|
|
||||||
|
The converter supports the locking Capslock key. Use keycode `LCAP` instead of `CAPS` in your keymap.
|
||||||
|
|
||||||
|
https://github.com/tmk/tmk_keyboard/wiki/FAQ-Keymap#mechanical-lock-switch-support
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define LOCKING_RESYNC_ENABLE
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
// Mouse Extended Report
|
// Mouse Extended Report
|
||||||
#define MOUSE_EXT_REPORT
|
//#define MOUSE_EXT_REPORT
|
||||||
|
|
||||||
|
// Second button in Apple Classic Mouse protocol is ignored as Mac OS9 and OSX does.
|
||||||
|
// Without this some of 2-button mouses are unusable.
|
||||||
|
// https://github.com/tmk/tmk_keyboard/issues/724
|
||||||
|
#define ADB_MOUSE_2ND_BUTTON_QUIRK
|
||||||
|
|
||||||
|
|
||||||
/* ADB port setting */
|
/* ADB port setting */
|
||||||
|
|
|
||||||
|
|
@ -153,10 +153,10 @@ void matrix_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ADB_MOUSE_ENABLE
|
#ifdef ADB_MOUSE_ENABLE
|
||||||
|
static uint8_t mouse_handler;
|
||||||
static void mouse_init(void)
|
static void mouse_init(void)
|
||||||
{
|
{
|
||||||
uint16_t reg3;
|
uint16_t reg3;
|
||||||
uint8_t mouse_handler;
|
|
||||||
|
|
||||||
again:
|
again:
|
||||||
// Check if there is mouse device at default address 3
|
// Check if there is mouse device at default address 3
|
||||||
|
|
@ -173,19 +173,45 @@ again:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if there is mouse device to setup at temporary address 15
|
// Check if there is mouse device to setup at temporary address 15
|
||||||
mouse_handler = (reg3 = adb_host_talk(ADB_ADDR_MOUSE_TMP, ADB_REG_3)) & 0xFF;
|
reg3 = adb_host_talk(ADB_ADDR_MOUSE_TMP, ADB_REG_3);
|
||||||
if (!reg3) {
|
if (!reg3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dmprintf("TMP: reg3:%04X\n", reg3);
|
dmprintf("TMP: reg3:%04X\n", reg3);
|
||||||
|
mouse_handler = reg3 & 0xFF;
|
||||||
|
|
||||||
|
|
||||||
|
if (mouse_handler == ADB_HANDLER_MICROSPEED_MACTRAC ||
|
||||||
|
mouse_handler == ADB_HANDLER_MICROSPEED_UNKNOWN ||
|
||||||
|
mouse_handler == ADB_HANDLER_CONTOUR_MOUSE ||
|
||||||
|
mouse_handler == ADB_HANDLER_CHPRODUCTS_PRO) {
|
||||||
|
// https://github.com/NetBSD/src/blob/netbsd-9/sys/arch/macppc/dev/ams.c#L226-L255
|
||||||
|
// https://github.com/torvalds/linux/blob/v5.17/drivers/macintosh/adbhid.c#L1007-L1018
|
||||||
|
// https://github.com/torvalds/linux/blob/v5.17/drivers/macintosh/adbhid.c#L1204-L1239
|
||||||
|
uint8_t cmd[] = { 0x00, // alt speed max
|
||||||
|
0x00, // speed max
|
||||||
|
0x10, // ext protocol enabled
|
||||||
|
0x07 }; // buttons without locking
|
||||||
|
//adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
||||||
|
adb_host_listen_buf(ADB_ADDR_MOUSE_TMP, ADB_REG_1, cmd, sizeof(cmd));
|
||||||
|
}
|
||||||
|
|
||||||
// Try to escalate into extended/classic2 protocol
|
// Try to escalate into extended/classic2 protocol
|
||||||
if (mouse_handler == ADB_HANDLER_CLASSIC1_MOUSE || mouse_handler == ADB_HANDLER_CLASSIC2_MOUSE) {
|
if (mouse_handler == ADB_HANDLER_CLASSIC1_MOUSE || mouse_handler == ADB_HANDLER_CLASSIC2_MOUSE) {
|
||||||
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
||||||
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_EXTENDED_MOUSE);
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_EXTENDED_MOUSE);
|
||||||
mouse_handler = (reg3 = adb_host_talk(ADB_ADDR_MOUSE_TMP, ADB_REG_3)) & 0xFF;
|
mouse_handler = (reg3 = adb_host_talk(ADB_ADDR_MOUSE_TMP, ADB_REG_3)) & 0xFF;
|
||||||
|
|
||||||
|
if (mouse_handler != ADB_HANDLER_EXTENDED_MOUSE) {
|
||||||
|
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
||||||
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_MOUSESYSTEMS_A3);
|
||||||
|
mouse_handler = (reg3 = adb_host_talk(ADB_ADDR_MOUSE_TMP, ADB_REG_3)) & 0xFF;
|
||||||
|
|
||||||
|
if (mouse_handler == ADB_HANDLER_MOUSESYSTEMS_A3) {
|
||||||
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_2, 0x00, 0x07);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mouse_handler == ADB_HANDLER_CLASSIC1_MOUSE) {
|
if (mouse_handler == ADB_HANDLER_CLASSIC1_MOUSE) {
|
||||||
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
||||||
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_CLASSIC2_MOUSE);
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_CLASSIC2_MOUSE);
|
||||||
|
|
@ -224,8 +250,8 @@ again:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
dmprintf("EXT: [%02X %02X %02X %02X %02X %02X %02X %02X] cpi=%d\n",
|
dmprintf("EXT: [%02X %02X %02X %02X %02X %02X %02X %02X] cpi=%d btn=%d len=%d\n",
|
||||||
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], mouse_cpi);
|
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], mouse_cpi, buf[7], len);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kensington Turbo Mouse 5: default device
|
// Kensington Turbo Mouse 5: default device
|
||||||
|
|
@ -242,8 +268,35 @@ again:
|
||||||
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
||||||
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_0, 0xFE);
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_0, 0xFE);
|
||||||
goto again;
|
goto again;
|
||||||
|
} else if (buf[0] == 0x4B && buf[1] == 0x4F && buf[2] == 0x49 && buf[3] == 0x54) {
|
||||||
|
// https://elixir.bootlin.com/linux/v5.17/source/drivers/macintosh/adbhid.c#L1068
|
||||||
|
adb_host_flush(ADB_ADDR_MOUSE_TMP);
|
||||||
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, (reg3 >> 8), ADB_HANDLER_MACALLY2_MOUSE);
|
||||||
|
mouse_handler = (reg3 = adb_host_talk(ADB_ADDR_MOUSE_TMP, ADB_REG_3)) & 0xFF;
|
||||||
|
xprintf("M: reg3:%04X\n", reg3);
|
||||||
|
dmprintf("Macally2: found: %02X\n", mouse_handler);
|
||||||
|
} else if (buf[0] == 0x9A && (buf[1] == 0x20 || buf[1] == 0x21)) {
|
||||||
|
if (buf[1] == 0x20) {
|
||||||
|
xprintf("M:MouseMan\n");
|
||||||
|
} else {
|
||||||
|
xprintf("M:TrackMan\n");
|
||||||
|
}
|
||||||
|
// https://elixir.bootlin.com/linux/v5.17/source/drivers/macintosh/adbhid.c#L1047
|
||||||
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_1, 0x00, 0x81);
|
||||||
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_1, 0x01, 0x81);
|
||||||
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_1, 0x02, 0x81);
|
||||||
|
adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_1, 0x03, 0x38);
|
||||||
|
// set pseudo handler for Logitech
|
||||||
|
mouse_handler = ADB_HANDLER_LOGITECH;
|
||||||
|
} else if (buf[0] == 0x4C && buf[1] == 0x54) {
|
||||||
|
// Logitech Extended
|
||||||
|
// MouseMan - FCCID:DZLMAH32 'LT01'
|
||||||
|
// MouseMan Cordless - FCCID:DZLMRC33T 'LTW1'
|
||||||
|
xprintf("M:Logitech-Ext\n");
|
||||||
|
// set pseudo handler
|
||||||
|
mouse_handler = ADB_HANDLER_LOGITECH_EXT;
|
||||||
} else {
|
} else {
|
||||||
dmprintf("Unknown\n");
|
dmprintf("Extended\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,18 +391,6 @@ void adb_mouse_task(void)
|
||||||
mouse_init();
|
mouse_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extended Mouse Protocol data can be 2-5 bytes
|
|
||||||
// https://developer.apple.com/library/archive/technotes/hw/hw_01.html#Extended
|
|
||||||
//
|
|
||||||
// Byte 0: b00 y06 y05 y04 y03 y02 y01 y00
|
|
||||||
// Byte 1: b01 x06 x05 x04 x03 x02 x01 x00
|
|
||||||
// Byte 2: b02 y09 y08 y07 b03 x09 x08 x07
|
|
||||||
// Byte 3: b04 y12 y11 y10 b05 x12 x11 x10
|
|
||||||
// Byte 4: b06 y15 y14 y13 b07 x15 x14 x13
|
|
||||||
//
|
|
||||||
// b--: Button state.(0: on, 1: off)
|
|
||||||
// x--: X axis movement.
|
|
||||||
// y--: Y axis movement.
|
|
||||||
len = adb_host_talk_buf(ADB_ADDR_MOUSE_POLL, ADB_REG_0, buf, sizeof(buf));
|
len = adb_host_talk_buf(ADB_ADDR_MOUSE_POLL, ADB_REG_0, buf, sizeof(buf));
|
||||||
|
|
||||||
// If nothing received reset mouse acceleration, and quit.
|
// If nothing received reset mouse acceleration, and quit.
|
||||||
|
|
@ -357,36 +398,145 @@ void adb_mouse_task(void)
|
||||||
mouseacc = 1;
|
mouseacc = 1;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
dmprintf("[%02X %02X %02X %02X %02X]\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
|
|
||||||
|
|
||||||
// Store off-buttons and 0-movements in unused bytes
|
xprintf("M:[ ");
|
||||||
|
for (uint8_t i = 0; i < len; i++)
|
||||||
|
xprintf("%02X ", buf[i]);
|
||||||
|
xprintf("] mh:%02X\n", mouse_handler);
|
||||||
|
|
||||||
bool xneg = false;
|
bool xneg = false;
|
||||||
bool yneg = false;
|
bool yneg = false;
|
||||||
if (len == 2) {
|
if (mouse_handler == ADB_HANDLER_LOGITECH) {
|
||||||
|
// Logitech:
|
||||||
|
// Byte0: bbb y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: 1 x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: 0 0 0 0 0 BL BM BR
|
||||||
|
// Bx: button state(1:pressed, 1:released)
|
||||||
|
// bbb: 0 when either BL, BR or BM is pressed
|
||||||
if (buf[0] & 0x40) yneg = true;
|
if (buf[0] & 0x40) yneg = true;
|
||||||
if (buf[1] & 0x40) xneg = true;
|
if (buf[1] & 0x40) xneg = true;
|
||||||
} else {
|
if (buf[2] & 0x04) buf[0] &= 0x7F; else buf[0] |= 0x80;
|
||||||
|
if (buf[2] & 0x01) buf[1] &= 0x7F; else buf[1] |= 0x80;
|
||||||
|
if (buf[2] & 0x02) buf[2] = 0x08; else buf[2] = 0x88;
|
||||||
|
if (yneg) buf[2] |= 0x70;
|
||||||
|
if (xneg) buf[2] |= 0x07;
|
||||||
|
len = 3;
|
||||||
|
} else if (mouse_handler == ADB_HANDLER_LOGITECH_EXT) {
|
||||||
|
// Logitech Extended:
|
||||||
|
// Byte0: b00 y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: b02 x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: b01 y09 y08 y07 b03 x09 x08 x07
|
||||||
|
// L=b00, R=b01, M=b02
|
||||||
|
uint8_t tmp = buf[2];
|
||||||
|
if (buf[1] & 0x80) buf[2] |= 0x80; else buf[2] &= 0x7F;
|
||||||
|
if (tmp & 0x80) buf[1] |= 0x80; else buf[1] &= 0x7F;
|
||||||
if (buf[len - 1] & 0x40) yneg = true;
|
if (buf[len - 1] & 0x40) yneg = true;
|
||||||
if (buf[len - 1] & 0x04) xneg = true;
|
if (buf[len - 1] & 0x04) xneg = true;
|
||||||
|
} else if (mouse_handler == ADB_HANDLER_MACALLY2_MOUSE && len == 4) {
|
||||||
|
// Macally 2-button mouse:
|
||||||
|
// Byte0: b00 y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: b01 x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: 1 0 0 0 1 0 0 0
|
||||||
|
// Byte3: 1 0 0 0 1 0 0 0
|
||||||
|
// b--: button state(0:pressed, 1:released)
|
||||||
|
if (buf[0] & 0x40) yneg = true;
|
||||||
|
if (buf[1] & 0x40) xneg = true;
|
||||||
|
// Ignore Byte2 and 3
|
||||||
|
len = 2;
|
||||||
|
} else if (mouse_handler == ADB_HANDLER_MICROSPEED_MACTRAC ||
|
||||||
|
mouse_handler == ADB_HANDLER_MICROSPEED_UNKNOWN ||
|
||||||
|
mouse_handler == ADB_HANDLER_CONTOUR_MOUSE) {
|
||||||
|
// Microspeed:
|
||||||
|
// Byte0: ??? y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: ??? x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: ??? ??? ??? ??? ??? bM bR bL
|
||||||
|
// Contour Mouse:
|
||||||
|
// Byte0: bbb y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: 1 x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: 0 0 0 0 1 bM bR bL
|
||||||
|
// Byte3: 0 0 0 0 1 bM bR bL
|
||||||
|
// b--: button state(0:pressed, 1:released)
|
||||||
|
if (buf[0] & 0x40) yneg = true;
|
||||||
|
if (buf[1] & 0x40) xneg = true;
|
||||||
|
buf[0] = ((buf[2] & 1) << 7) | (buf[0] & 0x7F);
|
||||||
|
buf[1] = ((buf[2] & 2) << 6) | (buf[1] & 0x7F) ;
|
||||||
|
buf[2] = ((buf[2] & 4) << 5) | (buf[2] & 8) | (yneg ? 0x70 : 0x00) | (xneg ? 0x07 : 0x00);
|
||||||
|
len = 3;
|
||||||
|
} else if (mouse_handler == ADB_HANDLER_CHPRODUCTS_PRO) {
|
||||||
|
// CH Products Trackball Pro:
|
||||||
|
// Byte0: ??? y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: ??? x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: ??? ??? ??? ??? bL0 bL1 bR bM
|
||||||
|
// b--: button state(0:pressed, 1:released)
|
||||||
|
// L=(bL0 & bL1)
|
||||||
|
if (buf[0] & 0x40) yneg = true;
|
||||||
|
if (buf[1] & 0x40) xneg = true;
|
||||||
|
buf[0] = (((buf[2] & 4) << 5) & ((buf[2] & 8) << 4)) | (buf[0] & 0x7F);
|
||||||
|
buf[1] = ((buf[2] & 2) << 6) | (buf[1] & 0x7F) ;
|
||||||
|
buf[2] = ((buf[2] & 1) << 7) | (yneg ? 0x70 : 0x00) | (xneg ? 0x0F : 0x08);
|
||||||
|
len = 3;
|
||||||
|
} else if (mouse_handler == ADB_HANDLER_MOUSESYSTEMS_A3) {
|
||||||
|
// Mouse Systems A3: 3-button mouse/trackball:
|
||||||
|
// Byte0: ??? y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: ??? x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: ??? ??? ??? ??? ??? bR bM bL
|
||||||
|
// b--: button state(0:pressed, 1:released)
|
||||||
|
if (buf[0] & 0x40) yneg = true;
|
||||||
|
if (buf[1] & 0x40) xneg = true;
|
||||||
|
buf[0] = ((buf[2] & 1) << 7) | (buf[0] & 0x7F);
|
||||||
|
buf[1] = ((buf[2] & 4) << 5) | (buf[1] & 0x7F) ;
|
||||||
|
buf[2] = ((buf[2] & 2) << 6) | (yneg ? 0x70 : 0x00) | (xneg ? 0x0F : 0x08);
|
||||||
|
len = 3;
|
||||||
|
} else if (mouse_handler == ADB_HANDLER_EXTENDED_MOUSE ||
|
||||||
|
mouse_handler == ADB_HANDLER_TURBO_MOUSE) {
|
||||||
|
// Apple Extended Mouse:
|
||||||
|
// Byte0: b00 y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: b01 x06 x05 x04 x03 x02 x01 x00
|
||||||
|
// Byte2: b02 y09 y08 y07 b03 x09 x08 x07
|
||||||
|
// Byte3: b04 y12 y11 y10 b05 x12 x11 x10
|
||||||
|
// Byte4: b06 y15 y14 y13 b07 x15 x14 x13
|
||||||
|
// b--: button state(0:pressed, 1:released)
|
||||||
|
// Data can be 2-5 bytes.
|
||||||
|
// L=b00, R=b01, M=b02
|
||||||
|
if (buf[len - 1] & 0x40) yneg = true;
|
||||||
|
if (buf[len - 1] & 0x04) xneg = true;
|
||||||
|
} else {
|
||||||
|
// Apple Classic Mouse and Unknown devices:
|
||||||
|
// Byte0: b00 y06 y05 y04 y03 y02 y01 y00
|
||||||
|
// Byte1: b01 x06 x05 x04 x03 x02 x01 x00
|
||||||
|
if (buf[0] & 0x40) yneg = true;
|
||||||
|
if (buf[1] & 0x40) xneg = true;
|
||||||
|
len = 2;
|
||||||
|
|
||||||
|
#ifdef ADB_MOUSE_2ND_BUTTON_QUIRK
|
||||||
|
// Ignore b01('optional second button') as OSX/MacOS9 does.
|
||||||
|
// Some mouses misuse the bit and make it unusable.
|
||||||
|
// https://github.com/tmk/tmk_keyboard/issues/724
|
||||||
|
buf[1] |= 0x80;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make unused buf bytes compatible with Extended Mouse Protocol
|
||||||
for (int8_t i = len; i < sizeof(buf); i++) {
|
for (int8_t i = len; i < sizeof(buf); i++) {
|
||||||
buf[i] = 0x88;
|
buf[i] = 0x88;
|
||||||
if (yneg) buf[i] |= 0x70;
|
if (yneg) buf[i] |= 0x70;
|
||||||
if (xneg) buf[i] |= 0x07;
|
if (xneg) buf[i] |= 0x07;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 8 buttons at max
|
xprintf("M:[ ");
|
||||||
// TODO: Fix HID report descriptor for mouse to support button6-8
|
for (uint8_t i = 0; i < sizeof(buf); i++)
|
||||||
|
xprintf("%02X ", buf[i]);
|
||||||
|
xprintf("]\n");
|
||||||
|
|
||||||
uint8_t buttons = 0;
|
uint8_t buttons = 0;
|
||||||
if (!(buf[4] & 0x08)) buttons |= MOUSE_BTN8;
|
if (!(buf[4] & 0x08)) buttons |= MOUSE_BTN8;
|
||||||
if (!(buf[4] & 0x80)) buttons |= MOUSE_BTN7;
|
if (!(buf[4] & 0x80)) buttons |= MOUSE_BTN7;
|
||||||
if (!(buf[3] & 0x08)) buttons |= MOUSE_BTN6;
|
if (!(buf[3] & 0x08)) buttons |= MOUSE_BTN6;
|
||||||
if (!(buf[3] & 0x80)) buttons |= MOUSE_BTN5;
|
if (!(buf[3] & 0x80)) buttons |= MOUSE_BTN5;
|
||||||
if (!(buf[2] & 0x08)) buttons |= MOUSE_BTN4;
|
if (!(buf[2] & 0x08)) buttons |= MOUSE_BTN4;
|
||||||
if (!(buf[2] & 0x80)) buttons |= MOUSE_BTN3;
|
if (!(buf[2] & 0x80)) buttons |= MOUSE_BTN3; // Middle
|
||||||
if (!(buf[1] & 0x80)) buttons |= MOUSE_BTN2;
|
if (!(buf[1] & 0x80)) buttons |= MOUSE_BTN2; // Right
|
||||||
if (!(buf[0] & 0x80)) buttons |= MOUSE_BTN1;
|
if (!(buf[0] & 0x80)) buttons |= MOUSE_BTN1; // Left
|
||||||
|
|
||||||
// check if the scroll enable button is pressed
|
// check if the scroll enable button is pressed
|
||||||
bool scroll_enable = (bool)(buttons & scroll_button_mask);
|
bool scroll_enable = (bool)(buttons & scroll_button_mask);
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,15 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#define ADB_HANDLER_CLASSIC2_MOUSE 0x02
|
#define ADB_HANDLER_CLASSIC2_MOUSE 0x02
|
||||||
#define ADB_HANDLER_EXTENDED_MOUSE 0x04
|
#define ADB_HANDLER_EXTENDED_MOUSE 0x04
|
||||||
#define ADB_HANDLER_TURBO_MOUSE 0x32
|
#define ADB_HANDLER_TURBO_MOUSE 0x32
|
||||||
|
#define ADB_HANDLER_MACALLY2_MOUSE 0x42
|
||||||
|
#define ADB_HANDLER_MICROSPEED_MACTRAC 0x2F
|
||||||
|
#define ADB_HANDLER_MICROSPEED_UNKNOWN 0x5F
|
||||||
|
#define ADB_HANDLER_CONTOUR_MOUSE 0x66
|
||||||
|
#define ADB_HANDLER_CHPRODUCTS_PRO 0x42
|
||||||
|
#define ADB_HANDLER_MOUSESYSTEMS_A3 0x03
|
||||||
|
// pseudo handler
|
||||||
|
#define ADB_HANDLER_LOGITECH 0x4C
|
||||||
|
#define ADB_HANDLER_LOGITECH_EXT 0x4D
|
||||||
|
|
||||||
|
|
||||||
// ADB host
|
// ADB host
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue