tmk / tmk_keyboard

Keyboard firmwares for Atmel AVR and Cortex-M
3.98k stars 1.7k forks source link

ADB: Optional second button in Classic Apple Mouse Protocol #724

Closed tmk closed 2 years ago

tmk commented 2 years ago

Mac OS9 seems to ignore the optional second button while TMK and iMate handle the button as right click. https://geekhack.org/index.php?topic=14290.msg3117448#msg3117448

Some(many?) of two-button pointing devices misuse the optional second button(bit7) and they are unusable with iMate and TMK in the result.

We should ignore the bit as same as classic Mac does? (Ignoring the bit can make second button unusable on other inocent pointing devices.)

https://developer.apple.com/library/archive/technotes/hw/hw_01.html#Section6

EDIT: Mac OS X ignores the 'optional second button' certainly and OS9 ignores too apparently. https://github.com/apple-oss-distributions/AppleADBMouse/blob/AppleADBMouse-212/AppleADBMouse.cpp#L146-L163

Griffin iMate handles the 'optional second buton'. This makes some of two-button devices unusable, and enables second button on a few properly implemented devices like NeXT mouse and Pippin. They are seemingly very few exceptions and not for Mac computer.

We will emulate behaviour of OS9 and OSX for better compatibility at expense of a few exceptions. To use second button of such NeXT and Pippin Pad disable build option ADB_MOUSE_2ND_BUTTON_QUIRK.

tmk commented 2 years ago

Pointing devices misuse the second button bit and unsuable on TMK(and iMate):

These devices register both clicks at same time when either button is depressed. https://geekhack.org/index.php?topic=14290.msg3117402#msg3117402

Waiting for device:
Listening:
RM:TMP: reg3:6101
M:EXT: reg3:6C02
M:Classic 200cpi
M:POL: done

Scan:
 addr:10, reg3:6402

M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 80 ]
M:[ 80 80 88 88 88 ]
M:[B:00 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 80 ]
M:[ 80 80 88 88 88 ]
M:[B:00 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 80 ]
M:[ 80 80 88 88 88 ]
M:[B:00 X:0(0) Y:0(0) V:0 A:1]

This mouse always registers second button. This has no problem on classic Mac.(no right click probably) https://geekhack.org/index.php?topic=14290.msg3117404#msg3117404

Waiting for device:
Listening:
M:TMP: reg3:6F01
M:EXT: reg3:6002
M:Classic 200cpi
M:POL: done

Scan:
 addr:10, reg3:6802

M:[ 80 00 ]
M:[ 80 00 88 88 88 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 00 ]
M:[ 80 00 88 88 88 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 00 ]
M:[ 80 00 88 88 88 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 00 ]
M:[ 80 00 88 88 88 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 00 ]
M:[ 80 00 88 88 88 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 00 ]
M:[ 80 00 88 88 88 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]
M:[ 00 00 ]
M:[ 00 00 88 88 88 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]
M:[ 80 00 ]
M:[ 80 00 88 88 88 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]
tmk commented 2 years ago

NeXT Mouse speaks with Classic protocol(100 cpi) and registers secode button properly.

Ignoring the 'optional second button' bit makes NeXT Mouse second button unusable. This fix is tradeoff betseen proper NeXT Mouse and devices that misuse Classic protocol like above.

MM:[ 80 80 ]
M:[B:00 X:0(0) Y:0(0) V:0 A:1]

MM:[ 00 80 ]
M:[B:01 X:0(0) Y:0(0) V:0 A:1]

MM:[ 00 00 ]
M:[B:03 X:0(0) Y:0(0) V:0 A:1]

MM:[ 80 00 ]
M:[B:02 X:0(0) Y:0(0) V:0 A:1]

Also Pippin speaks with Classic protocol(100 cpi) and registers secode button properly.

https://geekhack.org/index.php?topic=14290.msg3117929#msg3117929

tmk commented 2 years ago

'optional second button' is ignored and many erroneous mouses should work now. 0c25a46d

NeXT ADB mouse works as one-button mouse by default unfortunately now.

To make NeXT second button usable undef ADB_MOUSE_2ND_BUTTON_QUIRK.