Author Topic: TMK ADB to USB keyboard converter  (Read 712369 times)

0 Members and 1 Guest are viewing this topic.

Offline nevin

  • Posts: 1646
  • Location: US
Re: TMK ADB to USB keyboard converter
« Reply #1100 on: Thu, 17 February 2022, 19:46:15 »
Did you wire columns or using it as a converter?

The ++ 2.0 uses a different processor than teensy 2.0 or promicro. It's doable, just chase to change processor designation.
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline kungfu_jesus

  • Posts: 9
Re: TMK ADB to USB keyboard converter
« Reply #1101 on: Fri, 18 February 2022, 08:15:05 »
I am using it as a converter. Good news though, I got it working! I did end up wiring in the Teensy 2.0 and had the same issues which indicated a hardware problem. I actually traced the leads on the PCB and wouldn't you know the numpad 4 traces through the numpad 1 over and up through the affected keys. I had a poor solder job on the 0 key which affected everything else 'down the line.' Thank you for your help and suggestions!

Happily typing this on my M0116!  :thumb:

Offline nevin

  • Posts: 1646
  • Location: US
Re: TMK ADB to USB keyboard converter
« Reply #1102 on: Fri, 18 February 2022, 09:05:58 »
glad you got it figured out.

enjoy the board.
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Jiekebo

  • Posts: 2
  • Location: Sweden
Re: TMK ADB to USB keyboard converter
« Reply #1103 on: Sun, 20 February 2022, 06:22:39 »
Thank you for this amazing converter. Worked like a charm right away, and brought this board back into service :)
Only needed make some small changes to the default keymap before it was just right.
Since I wanted to use the power button to switch layer and have F1-F12 on the number row, I changed the COMMAND_ENABLE to no in the makefile.
Again big thanks!


Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1104 on: Mon, 21 March 2022, 10:11:01 »
Hi

I have a TMK adapter (and i have compiled the last firmware) and a Macally ADB Mouse with two buttons.

And the second button will not  work. I have tested with others USB/ADB adapter, with the same problem

After many search, i have found a thing : the Macally mouse use a special protocol. The GNU/Linux driver can use the mouse and the second button, is this possible to add support for that ? (https://elixir.bootlin.com/linux/latest/source/drivers/macintosh/adbhid.c)

I can try to compile.

Pierre


Offline nevin

  • Posts: 1646
  • Location: US
Re: TMK ADB to USB keyboard converter
« Reply #1105 on: Mon, 21 March 2022, 11:00:23 »
i know of the "Macally ADB Mouse", used to have one we used with our Power Macintosh 9600's. though i don't have one currently to test.
although, generally, the right click is usually a contol + click. so if it's registering as a normal click, you can set it as a macro to be "control + click"
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1106 on: Mon, 21 March 2022, 12:58:33 »
This mouse don't send a nomrla click on the right click, it's a special protocol. I have only the left click (on Mac OS 9, the mouse need a special extension)

Offline nevin

  • Posts: 1646
  • Location: US
Re: TMK ADB to USB keyboard converter
« Reply #1107 on: Mon, 21 March 2022, 14:20:02 »
i'd bet it's a modified left click. like i said, a control + click. so the right is just a modifier to the left.

yep. see below.
this is kinda backwards of what hasu's device is. but confirms my suspicion.
https://www.bigmessowires.com/2017/06/23/multi-button-mouse-support/

or if you just really like the shape of it, you could give it new guts, make it optical and get rid of the ball.

i'm sure @Hasu will comment as well
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1108 on: Mon, 21 March 2022, 18:40:57 »
Dandu,
did you check debug prints with hid_listen?
It would be helpful to see how the converter recognizes the mouse.
Can you share log?

It needs manufacture specific initialization code to enable its full function probably as you said.
If it happens to support Apple Extended protocol the second button will work as a middle button without 'specific initialization'. Though, many adb mouses don't support.

Anyway, I'm also interested in adding support for Macally mouse and happy to help.

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1109 on: Tue, 22 March 2022, 10:17:21 »
i'd bet it's a modified left click. like i said, a control + click. so the right is just a modifier to the left.

yep. see below.
this is kinda backwards of what hasu's device is. but confirms my suspicion.
https://www.bigmessowires.com/2017/06/23/multi-button-mouse-support/

or if you just really like the shape of it, you could give it new guts, make it optical and get rid of the ball.

i'm sure @Hasu will comment as well

Actually, i have tested many two button mouse. Many mouse dont't make "ctrl + clic", they make a "forced clic" The first press make a clic, the second release it.

With this mouse, i have nothing when i press the right clic (even with an old Mac, by the way). The only way to have a right clic is to install the extension on Mac OS 9 (i have write about this mouse, in french) : https://www.journaldulapin.com/2022/03/21/adb-souris-macally/

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1110 on: Tue, 22 March 2022, 10:23:00 »
Dandu,
did you check debug prints with hid_listen?
It would be helpful to see how the converter recognizes the mouse.
Can you share log?

It needs manufacture specific initialization code to enable its full function probably as you said.
If it happens to support Apple Extended protocol the second button will work as a middle button without 'specific initialization'. Though, many adb mouses don't support.

Anyway, I'm also interested in adding support for Macally mouse and happy to help.

Thank you

I have tried HID_listen (under macOS) and the left clic make a thing, but not the right clic.

I join a little sample (when i have tried, i have press the right clic). And the right clic work with Mac OS 9 and the extension.

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1111 on: Tue, 22 March 2022, 19:17:21 »
It seems to work as a one-button mouse.

Didn't you see oputputs like below? This part indicates how the converter initializes mouse.
To see this debug print you may have to hot-plug the mouse after plugging the converter into USB port.

For reference:
This is debug prints of 'Apple Desktop Bus Mouse II', which has only one button.
Quote

M:TMP: reg3:6B01
M:EXT: reg3:6902
M:Classic 200cpi
M:POL: done

Scan:
 addr:10, reg3:6D02


and this is Kensington TurboMouse 5.
Quote

TMP: reg3:6F01             
M:EXT: reg3:6104                                                                                                     
M:EXT: [4B 4D 4C 31 00 C8 02 04] cpi=200                                                                             
M:TM5: found                                                                                                         
M:TMP: reg3:6E32                                                                                                     
TM5: setup                                                                                                           
M:POL: done                                                                                                           
                                                                                                                     
Scan:                                                                                                                 
 addr:10, reg3:6232



« Last Edit: Tue, 22 March 2022, 19:38:30 by hasu »

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1112 on: Tue, 22 March 2022, 19:51:43 »
Dandu,
Can you try this patch?

Code: [Select]
diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index ee99d7d5..0c7f291d 100644
--- a/converter/adb_usb/matrix.c
+++ b/converter/adb_usb/matrix.c
@@ -242,6 +242,12 @@ again:
             adb_host_flush(ADB_ADDR_MOUSE_TMP);
             adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_0, 0xFE);
             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
+            dmprintf("Macally2: found\n");
+            adb_host_flush(ADB_ADDR_MOUSE_TMP);
+            adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, (reg3 >> 8), 0x42);
+            mouse_handler = (reg3 = adb_host_talk(ADB_ADDR_MOUSE_TMP, ADB_REG_3)) & 0xFF;
         } else {
             dmprintf("Unknown\n");
         }

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1113 on: Wed, 23 March 2022, 12:30:51 »
Hi

It works ! After the patch, i have a right clic. But there is a little problem : the mouse send the cursor à the bottom right of the display. Very weird (and only with this mouse, i suppose it's a problem with the patch).

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1114 on: Wed, 23 March 2022, 19:14:29 »
Try this patch then. Macally2 seems to need to be handled peculiarly.


Code: [Select]
diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index ee99d7d5..43368119 100644
--- a/converter/adb_usb/matrix.c
+++ b/converter/adb_usb/matrix.c
@@ -153,10 +153,10 @@ void matrix_init(void)
 }
 
 #ifdef ADB_MOUSE_ENABLE
+static uint8_t mouse_handler;
 static void mouse_init(void)
 {
     uint16_t reg3;
-    uint8_t mouse_handler;
 
 again:
     // Check if there is mouse device at default address 3
@@ -242,6 +242,12 @@ again:
             adb_host_flush(ADB_ADDR_MOUSE_TMP);
             adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_0, 0xFE);
             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
+            dmprintf("Macally2: found\n");
+            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;
         } else {
             dmprintf("Unknown\n");
         }
@@ -350,6 +356,13 @@ void adb_mouse_task(void)
     //   b--: Button state.(0: on, 1: off)
     //   x--: X axis movement.
     //   y--: Y axis movement.
+    //
+    // Macally2
+    //
+    //   Byte 0: b00 y06 y05 y04 y03 y02 y01 y00
+    //   Byte 1: b01 x06 x05 x04 x03 x02 x01 x00
+    //   Byte 2: 1   0   0   0   1   0   0   0
+    //   Byte 3: 1   0   0   0   1   0   0   0
     len = adb_host_talk_buf(ADB_ADDR_MOUSE_POLL, ADB_REG_0, buf, sizeof(buf));
 
     // If nothing received reset mouse acceleration, and quit.
@@ -365,6 +378,9 @@ void adb_mouse_task(void)
     if (len == 2) {
         if (buf[0] & 0x40) yneg = true;
         if (buf[1] & 0x40) xneg = true;
+    } else if (mouse_handler == ADB_HANDLER_MACALLY2_MOUSE) {
+        if (buf[0] & 0x40) yneg = true;
+        if (buf[1] & 0x40) xneg = true;
     } else {
         if (buf[len - 1] & 0x40) yneg = true;
         if (buf[len - 1] & 0x04) xneg = true;
diff --git a/tmk_core/protocol/adb.h b/tmk_core/protocol/adb.h
index 31c26fb9..578f9883 100644
--- a/tmk_core/protocol/adb.h
+++ b/tmk_core/protocol/adb.h
@@ -95,6 +95,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #define ADB_HANDLER_CLASSIC2_MOUSE      0x02
 #define ADB_HANDLER_EXTENDED_MOUSE      0x04
 #define ADB_HANDLER_TURBO_MOUSE         0x32
+#define ADB_HANDLER_MACALLY2_MOUSE      0x42
 
 
 // ADB host

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1115 on: Thu, 24 March 2022, 03:39:27 »
Same problem : the cursor go to the bottom right when i move the mouse (but the right clic is working)

For the patch, i have revert the first one and apply the second one. Is this right ?

(and thank you for your work)

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1116 on: Thu, 24 March 2022, 05:01:05 »
Right. Apply the patche to the latest 'master' branch.
Post debug log would be helpful.

Handling sign of mouse movement value is a cause probably.
If you can debug it see lines around this.
https://github.com/tmk/tmk_keyboard/blob/master/converter/adb_usb/matrix.c#L398-L400

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1117 on: Thu, 24 March 2022, 14:53:33 »
What can i do exactly ?

I join a log with debug "on" (i have chained a keyboard to do that).

I'm not an expert. I can compile, modify things if you explain me, but it's too hard for me : i don't understand all the code.

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1118 on: Thu, 24 March 2022, 16:25:20 »
Thanks for the log.

OK. Let me ask some.
What is your converter's mcu?  ATmega32u2, ATmega32u4 or other? I'll build the firmware for you next time.
What is your OS? MacOS, Windows or Linux?

Debug print is enabled by default in current firmware configuration, you don't have to turn it on by hand.


Added some debug prints to see how mouse movement data are processed. Try this patch and post debug log.
Code: [Select]
diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index ee99d7d5..6b03b71e 100644
--- a/converter/adb_usb/matrix.c
+++ b/converter/adb_usb/matrix.c
@@ -153,10 +153,10 @@ void matrix_init(void)
 }
 
 #ifdef ADB_MOUSE_ENABLE
+static uint8_t mouse_handler;
 static void mouse_init(void)
 {
     uint16_t reg3;
-    uint8_t mouse_handler;
 
 again:
     // Check if there is mouse device at default address 3
@@ -242,6 +242,12 @@ again:
             adb_host_flush(ADB_ADDR_MOUSE_TMP);
             adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_0, 0xFE);
             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
+            dmprintf("Macally2: found\n");
+            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;
         } else {
             dmprintf("Unknown\n");
         }
@@ -350,6 +356,13 @@ void adb_mouse_task(void)
     //   b--: Button state.(0: on, 1: off)
     //   x--: X axis movement.
     //   y--: Y axis movement.
+    //
+    // Macally2
+    //
+    //   Byte 0: b00 y06 y05 y04 y03 y02 y01 y00
+    //   Byte 1: b01 x06 x05 x04 x03 x02 x01 x00
+    //   Byte 2: 1   0   0   0   1   0   0   0
+    //   Byte 3: 1   0   0   0   1   0   0   0
     len = adb_host_talk_buf(ADB_ADDR_MOUSE_POLL, ADB_REG_0, buf, sizeof(buf));
 
     // If nothing received reset mouse acceleration, and quit.
@@ -357,7 +370,12 @@ void adb_mouse_task(void)
         mouseacc = 1;
         return;
     };
-    dmprintf("[%02X %02X %02X %02X %02X]\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
+
+    //dmprintf("[%02X %02X %02X %02X %02X] %02X\n", buf[0], buf[1], buf[2], buf[3], buf[4], len);
+    xprintf("M:[ ");
+    for (uint8_t i = 0; i < len; i++)
+        xprintf("%02X ", buf[i]);
+    xprintf("]\n");
 
     // Store off-buttons and 0-movements in unused bytes
     bool xneg = false;
@@ -365,6 +383,9 @@ void adb_mouse_task(void)
     if (len == 2) {
         if (buf[0] & 0x40) yneg = true;
         if (buf[1] & 0x40) xneg = true;
+    } else if (mouse_handler == ADB_HANDLER_MACALLY2_MOUSE) {
+        if (buf[0] & 0x40) yneg = true;
+        if (buf[1] & 0x40) xneg = true;
     } else {
         if (buf[len - 1] & 0x40) yneg = true;
         if (buf[len - 1] & 0x04) xneg = true;
@@ -376,6 +397,11 @@ void adb_mouse_task(void)
         if (xneg) buf[i] |= 0x07;
     }
 
+    xprintf("M:[ ");
+    for (uint8_t i = 0; i < sizeof(buf); i++)
+        xprintf("%02X ", buf[i]);
+    xprintf("]\n");
+
     // 8 buttons at max
     // TODO: Fix HID report descriptor for mouse to support button6-8
     uint8_t buttons = 0;
diff --git a/tmk_core/protocol/adb.h b/tmk_core/protocol/adb.h
index 31c26fb9..578f9883 100644
--- a/tmk_core/protocol/adb.h
+++ b/tmk_core/protocol/adb.h
@@ -95,6 +95,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #define ADB_HANDLER_CLASSIC2_MOUSE      0x02
 #define ADB_HANDLER_EXTENDED_MOUSE      0x04
 #define ADB_HANDLER_TURBO_MOUSE         0x32
+#define ADB_HANDLER_MACALLY2_MOUSE      0x42
 
 
 // ADB host

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1119 on: Fri, 25 March 2022, 06:51:26 »
Hi

Thank you !

I join the log.

For the adapter, it's an old model with a ATmega32u4 (Arduino Pro Micro, i mean), made by a friend many years ago.

And i'm testing with macOS (the last version) and i compile on a Mac too.



Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1120 on: Fri, 25 March 2022, 06:56:18 »
And i have many mouse and keyboard.

Can i post here to try to correct some problems ?

I have many mouse with a weird right clic too : they send a left clic for the right and the left button, but i don't know if it's a problem with the conversion, or a hardware thing. Is this possible to see that with the logs ?

Many mouse works correctly (thank you !) like Logitech mouse with 3 buttons.

But i have mouse who will not work, like NeXT ADB mouse and a trackpad (Glidepoint).

I can post logs and try things to verify that.

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1121 on: Fri, 25 March 2022, 18:08:39 »
Fixed signed integer handling for Macally 2. Apply this patch or try attached firmware.
Can you post debug log again?

Code: [Select]
diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index ee99d7d5..b4225a9f 100644
--- a/converter/adb_usb/matrix.c
+++ b/converter/adb_usb/matrix.c
@@ -153,10 +153,10 @@ void matrix_init(void)
 }
 
 #ifdef ADB_MOUSE_ENABLE
+static uint8_t mouse_handler;
 static void mouse_init(void)
 {
     uint16_t reg3;
-    uint8_t mouse_handler;
 
 again:
     // Check if there is mouse device at default address 3
@@ -242,6 +242,12 @@ again:
             adb_host_flush(ADB_ADDR_MOUSE_TMP);
             adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_0, 0xFE);
             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
+            dmprintf("Macally2: found\n");
+            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;
         } else {
             dmprintf("Unknown\n");
         }
@@ -350,6 +356,15 @@ void adb_mouse_task(void)
     //   b--: Button state.(0: on, 1: off)
     //   x--: X axis movement.
     //   y--: Y axis movement.
+    //
+    // Macally2
+    //
+    //   Byte 0: b00 y06 y05 y04 y03 y02 y01 y00
+    //   Byte 1: b01 x06 x05 x04 x03 x02 x01 x00
+    //   Byte 2: 1   0   0   0   1   0   0   0
+    //   Byte 3: 1   0   0   0   1   0   0   0
+    //
+    //   Byte 2 and 3 have no meaningful info.
     len = adb_host_talk_buf(ADB_ADDR_MOUSE_POLL, ADB_REG_0, buf, sizeof(buf));
 
     // If nothing received reset mouse acceleration, and quit.
@@ -357,7 +372,12 @@ void adb_mouse_task(void)
         mouseacc = 1;
         return;
     };
-    dmprintf("[%02X %02X %02X %02X %02X]\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
+
+    //dmprintf("[%02X %02X %02X %02X %02X] %02X\n", buf[0], buf[1], buf[2], buf[3], buf[4], len);
+    xprintf("M:[ ");
+    for (uint8_t i = 0; i < len; i++)
+        xprintf("%02X ", buf[i]);
+    xprintf("]\n");
 
     // Store off-buttons and 0-movements in unused bytes
     bool xneg = false;
@@ -365,17 +385,28 @@ void adb_mouse_task(void)
     if (len == 2) {
         if (buf[0] & 0x40) yneg = true;
         if (buf[1] & 0x40) xneg = true;
+    } else if (mouse_handler == ADB_HANDLER_MACALLY2_MOUSE) {
+        if (buf[0] & 0x40) yneg = true;
+        if (buf[1] & 0x40) xneg = true;
+        // Ignore Byte 2 and 3
+        len = 2;
     } else {
         if (buf[len - 1] & 0x40) yneg = true;
         if (buf[len - 1] & 0x04) xneg = true;
     }
 
+    // Make unused buf bytes compatible with Extended Mouse Protocol
     for (int8_t i = len; i < sizeof(buf); i++) {
         buf[i] = 0x88;
         if (yneg) buf[i] |= 0x70;
         if (xneg) buf[i] |= 0x07;
     }
 
+    xprintf("M:[ ");
+    for (uint8_t i = 0; i < sizeof(buf); i++)
+        xprintf("%02X ", buf[i]);
+    xprintf("]\n");
+
     // 8 buttons at max
     // TODO: Fix HID report descriptor for mouse to support button6-8
     uint8_t buttons = 0;
diff --git a/tmk_core/protocol/adb.h b/tmk_core/protocol/adb.h
index 31c26fb9..578f9883 100644
--- a/tmk_core/protocol/adb.h
+++ b/tmk_core/protocol/adb.h
@@ -95,6 +95,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #define ADB_HANDLER_CLASSIC2_MOUSE      0x02
 #define ADB_HANDLER_EXTENDED_MOUSE      0x04
 #define ADB_HANDLER_TURBO_MOUSE         0x32
+#define ADB_HANDLER_MACALLY2_MOUSE      0x42
 
 
 // ADB host

* adb_usb_rev1.hex (65.47 kB - downloaded 85 times.)

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1122 on: Fri, 25 March 2022, 19:12:12 »
Yes, sharing problem here would be helpful for us and future users.
Can you happen to have list of your keyboards and mouses with berief description of their result and problem?

As for keyboards, let me know if you find any problem. I definitely want to know.
I believe any ADB keyboards should work with current firmware. They don't require specific driver code.

As for mouses,  most of multi-button mouses will require specific driver code and many won't work with current firmware.
Any ADB mouses including multi-button ones work as one-button mouse at least. Let me know if you find exception.

I don't necessarily aim to support all multi-button mouses. But I'll try if you have enough time to debug.


As for  "weird" right button, I think many of two(multi)-button mouses had custom action(control+left click, for example) by default,  as nevin referred to before. Some of them are configurable with manufacturer driver and others are hard-coded.

It would be helpful if you have printed 'user's manual' or can find it on the net.




And i have many mouse and keyboard.

Can i post here to try to correct some problems ?

I have many mouse with a weird right clic too : they send a left clic for the right and the left button, but i don't know if it's a problem with the conversion, or a hardware thing. Is this possible to see that with the logs ?

Many mouse works correctly (thank you !) like Logitech mouse with 3 buttons.

But i have mouse who will not work, like NeXT ADB mouse and a trackpad (Glidepoint).

I can post logs and try things to verify that.


Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1123 on: Sun, 27 March 2022, 05:04:46 »
Fixed signed integer handling for Macally 2. Apply this patch or try attached firmware.
Can you post debug log again?


The mouse do the same thing : go directly to the bottom right (and the right clic is working). It's very annoying on my Mac, by the way : i have the "active corner" (i don't know the name in english) and the display go to sleep.

I have tried with the code (i have patched) and with your firmware.

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1124 on: Sun, 27 March 2022, 05:10:56 »
Yes, sharing problem here would be helpful for us and future users.
Can you happen to have list of your keyboards and mouses with berief description of their result and problem?

As for keyboards, let me know if you find any problem. I definitely want to know.
I believe any ADB keyboards should work with current firmware. They don't require specific driver code.

As for mouses,  most of multi-button mouses will require specific driver code and many won't work with current firmware.
Any ADB mouses including multi-button ones work as one-button mouse at least. Let me know if you find exception.

I don't necessarily aim to support all multi-button mouses. But I'll try if you have enough time to debug.

As for  "weird" right button, I think many of two(multi)-button mouses had custom action(control+left click, for example) by default,  as nevin referred to before. Some of them are configurable with manufacturer driver and others are hard-coded.

It would be helpful if you have printed 'user's manual' or can find it on the net.


Actually, i have tested all my mouse with 2 buttons or more (~20 mouse). All the mouse with one button are working. Many mouse will work as intended, like Logitech with three buttons.

I will made many post to separate the things, because i have different problem.

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1125 on: Sun, 27 March 2022, 05:31:47 »
First, three mouse with the same problem : there is a right clic, but the clic send the left clic. Honestly, i suppose it will be normal, but i'm not sure.

The first one (logs 01) is a noname mouse, i have not the manual. (https://www.journaldulapin.com/2019/03/22/une-souris-adb-avec-trois-boutons-et-une-fausse-molette/)

I have removed the ball and just press the left button (3 times) and the right button (three times). Its seems to be an hardware things (the logs seems identical).

The second one is a Logitech Kidz (https://www.journaldulapin.com/2017/06/28/logitech-kidz-mouse/)

Same thing : i have removed the ball and pressed three times at left, and three times at right. And i have not found the manual.

And the 3rd one : a mini trackball. https://www.journaldulapin.com/2019/04/04/mini-trackball-adb/

Actually, i have the manual, but it's weird : a version say the two button are the same, and a second version say "the first button change the speed". (i have join the page)
 

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1126 on: Sun, 27 March 2022, 05:40:17 »
Second, two trackballs with a weird problem (and probably an hardware things) : they send left and right clic when i press the button.

The trackball (https://www.journaldulapin.com/2019/10/23/un-trackball-adb-original-et-inutilisable-sur-un-mac-moderne/) send a left clic *and* a right clic when i press the button. I have pressed three times the button on the log.

The second trackball do the same things, but with a second problem : it's a keypad and a trackball into the same enclosure. And the keypad will not work. https://www.journaldulapin.com/2020/02/19/trackball-pad/




Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1127 on: Sun, 27 March 2022, 05:46:33 »
Weird problem :

A Logitech Trackball (https://www.journaldulapin.com/2017/09/23/le-trackball-adb-de-logitech/)

First thing : button 1 send a clic (seems OK), button 2 and 3 send keyboard command (left and right). I think it's the normal way.

But the ball don't move the mouse, and my HID test app' say it's the "Mouse Wheel". Very Weird.

I the log, i have pressed the three button three times, and i have move the ball.

It's a TrackMan Mouse, FCCID DZLTAA1, M/N : T-AA1-4MD.


Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1128 on: Sun, 27 March 2022, 05:51:36 »
Another weird mouse : a "wooden" mouse with two button, and when i connect the mouse, i cannot make a right clic with the other mouse on my Mac. (https://www.journaldulapin.com/2020/06/02/souris-plastique-bois/)

And the right clic on the mouse seems to send a left clic. I have removed the ball, too, so only 3 left clic and 3 right clic on the logs.



Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1129 on: Sun, 27 March 2022, 06:00:26 »
The last three are not working, at all.

First one is a GlidPoint trackpad : i have nothing. Nothing on the logs (https://www.journaldulapin.com/2020/07/29/trackpad-adb/)

The second is a Kensington Thinking Mouse. https://www.journaldulapin.com/2017/02/24/souris-adb-boutons-2/

It's Logs 08, and when i connect the mouse, i have RRRR on the logs, and a "s" every second or so.

And the last one is a NeXT mouse (the ADB one, obviously). Like the trackpad : nothing on logs.

The three mouse works with an iMate, and the NeXT mouse send a real right clic.

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1130 on: Sun, 27 March 2022, 07:08:36 »
Fixed signed integer handling for Macally 2. Apply this patch or try attached firmware.
Can you post debug log again?


The mouse do the same thing : go directly to the bottom right (and the right clic is working). It's very annoying on my Mac, by the way : i have the "active corner" (i don't know the name in english) and the display go to sleep.

I have tried with the code (i have patched) and with your firmware.



Can you try attached firmware again and do procedures below?

0. run hid_listen.
1. plugin only the converter  into USB port.
2. then pulgin Macally2 mouse into the converter.
3. move mouse

* adb_usb_rev1.hex (65.47 kB - downloaded 86 times.)
« Last Edit: Sun, 27 March 2022, 07:10:20 by hasu »

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1131 on: Sun, 27 March 2022, 08:31:53 »
Device 01, 02, 03: Agree. It seems they are working as intended.

Device 04, 05: Interesting. They are unusable with this converter.
How do these device behave with iMate? They registers left and right click at same time, or left only?
Do you happen to know how these devices works without driver on  classic Mac?

Device 07: This always registers right click. This is unusable.

Device 06: Logitech Trackman require driver. We know Linux have one for this.

If you still have classic Mac(OS9?) with ADB interface try Device 04, 05 and 07 to see how they work. It would be helpful.


For reference,
Debug Log lines indicates:
Quote

M:[ 80 80 ]  // Raw bytes in hexdecimal that device sends
M:[ 80 80 88 88 88 ] // Prcessed bytes internally by firmware
M:[B:00 X:0(0) Y:0(0) V:0 A:1]  // How firmware recogizes the bytes

The raw bytes(in Apple Mouse Classic protocol) should be recognized like this.

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

For example,
Quote

M:[ 80 80 ] // both buttons released
M:[ 00 80 ] // lert button depressed
M:[ 80 00 ] // right(optional) button depressed
M:[ 00 00 ] // both buttons deppressed

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1132 on: Sun, 27 March 2022, 08:32:42 »
Do they work well with iMate? Assuming you have Griffin iMate.
Ah, you said they work with iMate.

'RRR' is likely to displayed when the converter has no pull-up resistor, or when you hot-plug device(this is no harm).
Do you solder pull-up resistor on DATA line?

I can't know without debug log. But I guess they have different signal timing  and the converter miss.


The last three are not working, at all.

First one is a GlidPoint trackpad : i have nothing. Nothing on the logs (https://www.journaldulapin.com/2020/07/29/trackpad-adb/)

The second is a Kensington Thinking Mouse. https://www.journaldulapin.com/2017/02/24/souris-adb-boutons-2/

It's Logs 08, and when i connect the mouse, i have RRRR on the logs, and a "s" every second or so.

And the last one is a NeXT mouse (the ADB one, obviously). Like the trackpad : nothing on logs.

The three mouse works with an iMate, and the NeXT mouse send a real right clic.


« Last Edit: Sun, 27 March 2022, 08:42:43 by hasu »

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1133 on: Sun, 27 March 2022, 12:23:25 »
Fixed signed integer handling for Macally 2. Apply this patch or try attached firmware.
Can you post debug log again?


The mouse do the same thing : go directly to the bottom right (and the right clic is working). It's very annoying on my Mac, by the way : i have the "active corner" (i don't know the name in english) and the display go to sleep.

I have tried with the code (i have patched) and with your firmware.



Can you try attached firmware again and do procedures below?

0. run hid_listen.
1. plugin only the converter  into USB port.
2. then pulgin Macally2 mouse into the converter.
3. move mouse

(Attachment Link)

Done.

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1134 on: Sun, 27 March 2022, 12:49:28 »
Device 01, 02, 03: Agree. It seems they are working as intended.

Device 04, 05: Interesting. They are unusable with this converter.
How do these device behave with iMate? They registers left and right click at same time, or left only?
Do you happen to know how these devices works without driver on  classic Mac?

Device 07: This always registers right click. This is unusable.

Device 06: Logitech Trackman require driver. We know Linux have one for this.

If you still have classic Mac(OS9?) with ADB interface try Device 04, 05 and 07 to see how they work. It would be helpful.

For reference,
Debug Log lines indicates:
Quote

M:[ 80 80 ]  // Raw bytes in hexdecimal that device sends
M:[ 80 80 88 88 88 ] // Prcessed bytes internally by firmware
M:[B:00 X:0(0) Y:0(0) V:0 A:1]  // How firmware recogizes the bytes

The raw bytes(in Apple Mouse Classic protocol) should be recognized like this.
Show Image

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

For example,
Quote

M:[ 80 80 ] // both buttons released
M:[ 00 80 ] // lert button depressed
M:[ 80 00 ] // right(optional) button depressed
M:[ 00 00 ] // both buttons deppressed

Thanks !

For Device 4 (the Trackball) with left and right clic : it works the same with iMate (left and right when i press the button). No problem with Mac OS 9 on a Power Mac G3 (but Mac OS don't use the right clic, i suppose).

For Device 5 (the same trackball with a Keypad)  : same problem with iMate, but with iMate, the Keypad is working as intended. On a real Mac, no problem, and the Keypad is working.

For Device 7 (the mouse with right clic unusable) : same problem, the mouse seems to send a right clic when i connect the iMate, and after that, the right clic is unusable (i suppose the mouse is not releasing the clic ?). No problem on a real Mac.

For Device 6 (the Logitech TrackMan) : it works with the iMate, the cursor move. The two additional buttons send keyboard key (left and right, but i suppose it's normal). On a real old Mac : the cursor move very slowly and send clic (the cursor try to make a selection). It's unusable. I will try to find the driver for Mac OS 9.

I think it will be interessant to try to find the problem with the keypad on Device 5, and eventually to support the Logitech TrackMan.

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1135 on: Sun, 27 March 2022, 13:05:30 »
Do they work well with iMate? Assuming you have Griffin iMate.
Ah, you said they work with iMate.

'RRR' is likely to displayed when the converter has no pull-up resistor, or when you hot-plug device(this is no harm).
Do you solder pull-up resistor on DATA line?

I can't know without debug log. But I guess they have different signal timing  and the converter miss.


Actually, i have tried with hot-plug the first time.

This time :

-for the Kensington mouse, i have only the "s" when i connect the adapter with the mouse on it.

-for the NeXT mouse, i have this message :
Code: [Select]
Listening:

TMK:f67a6c/LUFA:d6a7df

Scan:
 addr:3, reg3:6501


USB configured.

Loop start.

For the trackpad, this message :

Code: [Select]
Waiting for device:....
Listening:

TMK:f67a6c/LUFA:d6a7df

Scan:
 addr:3, reg3:6001


USB configured.

Loop start.

For the resistor, i have not a resistor. I join two photos from my adapter. I can add the resistor : i must just solder a resistor on two pins, right ? I will try that this week if i have the correct value. Can you just indicate the pins and the value ?

Thank's !



Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1136 on: Sun, 27 March 2022, 18:56:59 »
Hmm, I'm missing something on Macally2.
Added debug prints to see what happens.

Can you try attached firmware with procedure below this time?


0. run hid_listen.
1. plugin only the converter  into USB port.
2. wait until you find 'Loop start.' on console.
3. then pulgin Macally2 mouse into the converter.
4. move mouse


You should see version string at procedure 2 with this firmware.
Code: [Select]
TMK:deaa49/LUFA:d6a7df


* adb_usb_rev1.hex (66.04 kB - downloaded 91 times.)

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1137 on: Sun, 27 March 2022, 19:37:20 »
For the resistor, i have not a resistor. I join two photos from my adapter. I can add the resistor : i must just solder a resistor on two pins, right ? I will try that this week if i have the correct value. Can you just indicate the pins and the value ?

I found design files of your converter here, it has already 10k pull-up resistor but it may be weak in some cases. Recently I found 1-4.7k resisitor is required for ADB.
https://github.com/tibounise/ADBUSB-0x1

And voltage drop is another concern because the converter uses Pro Micro.
https://github.com/tmk/tmk_keyboard/wiki/Pro-Micro#j1-solder-bridge


First, close J1 on Pro Micro with solder bridge.

Try this if first one doesn't change situation on GlidePoint/Kensington/NeXT.
Second, solder pull-up resistor between '3' pin and 'VCC' pin on Pro Micro.
Proper resistor value is 1.5k-4.7k in your case. But 1k is a bit strong but probably ok.


Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1138 on: Mon, 28 March 2022, 11:59:02 »
Hmm, I'm missing something on Macally2.
Added debug prints to see what happens.

Can you try attached firmware with procedure below this time?


0. run hid_listen.
1. plugin only the converter  into USB port.
2. wait until you find 'Loop start.' on console.
3. then pulgin Macally2 mouse into the converter.
4. move mouse


You should see version string at procedure 2 with this firmware.
Code: [Select]
TMK:deaa49/LUFA:d6a7df


(Attachment Link)

I have done that, i join the logs.


Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1139 on: Mon, 28 March 2022, 12:08:31 »
For the resistor, i have not a resistor. I join two photos from my adapter. I can add the resistor : i must just solder a resistor on two pins, right ? I will try that this week if i have the correct value. Can you just indicate the pins and the value ?

I found design files of your converter here, it has already 10k pull-up resistor but it may be weak in some cases. Recently I found 1-4.7k resisitor is required for ADB.
https://github.com/tibounise/ADBUSB-0x1

And voltage drop is another concern because the converter uses Pro Micro.
https://github.com/tmk/tmk_keyboard/wiki/Pro-Micro#j1-solder-bridge


First, close J1 on Pro Micro with solder bridge.

Try this if first one doesn't change situation on GlidePoint/Kensington/NeXT.
Second, solder pull-up resistor between '3' pin and 'VCC' pin on Pro Micro.
Proper resistor value is 1.5k-4.7k in your case. But 1k is a bit strong but probably ok.

The J1 don't change. But with a 4,7K ohm resistor, the NeXT mouse is working (and with a right clic).
The Kensington mouse, too, but with a little problem : the mouse has 4 buttons. The first three works as intended (button 1 to 3 on my HID test app'). The button 4 send a clic (the logs are OK) but on my HID test app', i have not the button 4. If i understand the code, the mouse send a button "0" ?

I have pressed the button 1 three times, the button 2 three times, etc.

And even with the resistor, the trackpad will not work.



Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1140 on: Mon, 28 March 2022, 23:57:17 »
For the resistor, i have not a resistor. I join two photos from my adapter. I can add the resistor : i must just solder a resistor on two pins, right ? I will try that this week if i have the correct value. Can you just indicate the pins and the value ?

I found design files of your converter here, it has already 10k pull-up resistor but it may be weak in some cases. Recently I found 1-4.7k resisitor is required for ADB.
https://github.com/tibounise/ADBUSB-0x1

And voltage drop is another concern because the converter uses Pro Micro.
https://github.com/tmk/tmk_keyboard/wiki/Pro-Micro#j1-solder-bridge


First, close J1 on Pro Micro with solder bridge.

Try this if first one doesn't change situation on GlidePoint/Kensington/NeXT.
Second, solder pull-up resistor between '3' pin and 'VCC' pin on Pro Micro.
Proper resistor value is 1.5k-4.7k in your case. But 1k is a bit strong but probably ok.

The J1 don't change. But with a 4,7K ohm resistor, the NeXT mouse is working (and with a right clic).
The Kensington mouse, too, but with a little problem : the mouse has 4 buttons. The first three works as intended (button 1 to 3 on my HID test app'). The button 4 send a clic (the logs are OK) but on my HID test app', i have not the button 4. If i understand the code, the mouse send a button "0" ?

I have pressed the button 1 three times, the button 2 three times, etc.

And even with the resistor, the trackpad will not work.

hmm, interesting. This bit Those devices requires that strong pull-up against what I expected.

As for fourth button, it is configured as 'scroll button' by current firmware. This is useful for Kensington Turbo Mouse5.
You can scroll vertically by holding the button and move mouse.
https://github.com/tmk/tmk_keyboard/blob/master/converter/adb_usb/Makefile#L85-L98


GlidPoint trackpad may require stronger pull-up?
You can try 2.2k, 1.5k or 1k(or even 470 ohm?) instead of 4.7k.

I looked into my iMate and found it uses 470 ohm. This value surprised me and I'm not sure it is totally safe for controller in ADB devices.
Checked schematics and Apple IIgs has 470 ohm on its ADB interface as pull-up resistor. So 470 is OK probably.

Offline nevin

  • Posts: 1646
  • Location: US
Re: TMK ADB to USB keyboard converter
« Reply #1141 on: Tue, 29 March 2022, 07:42:04 »
very cool. interesting about the pull-up resistor.

thank you two for really digging into this and for having such a vast collection of adb peripherals @Dandu & @hasu
Keeb.io Viterbi, Apple m0110, Apple m0120, Apple m0110a, Apple 658-4081, Apple M1242, Apple AEK II, MK96, GH60/Pure, Cherry g84-4100, Adesso AKP-220B, Magicforce 68

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1142 on: Tue, 29 March 2022, 11:13:31 »
@hasu : i have tried with a 470 ohms resistor and the GlidePoint is not recognised.

And thank's for the Kensington mouse, it works like that, excellent !

Actually, there is three mouse with a problem :

The Logitech TrackMan and the trackball with a keypad (tmk_keyboard only works with the trackball). And the Macally mouse with 2 buttons.

I will try my keyboards and joysticks next week (many ADB joystick works as mouse).

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1143 on: Tue, 29 March 2022, 20:24:01 »
I think I found a bug and fixed for Macally2 finally. With this Macally2 should move cursor correctly.

This firmware also includes fix for Device 4, 5 and 7, these pointing devices should work as expected(same behaviour on Mac OS9) now.
I described this issue on github: https://github.com/tmk/tmk_keyboard/issues/724

As for Keypad part of Device 5 and GlidePoint I don't have any idea at this point. Please post debug log when trying cold-plug and hot-plug the devices.

Also I like to check debug log of NeXT mouse and Thinking mouse.

I'll work on Logitech TrackMan specific support later.

As for keyboards and joysticks test, let's postpone until current mouse issues are resolved.


* adb_usb_rev1.hex (66.15 kB - downloaded 88 times.)

This is current patch, just for reference.
Code: [Select]
diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index ee99d7d5..f94e94d0 100644
--- a/converter/adb_usb/matrix.c
+++ b/converter/adb_usb/matrix.c
@@ -153,10 +153,10 @@ void matrix_init(void)
 }
 
 #ifdef ADB_MOUSE_ENABLE
+static uint8_t mouse_handler;
 static void mouse_init(void)
 {
     uint16_t reg3;
-    uint8_t mouse_handler;
 
 again:
     // Check if there is mouse device at default address 3
@@ -173,11 +173,12 @@ again:
     }
 
     // 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) {
         return;
     }
     dmprintf("TMP: reg3:%04X\n", reg3);
+    mouse_handler = reg3 & 0xFF;
 
 
     // Try to escalate into extended/classic2 protocol
@@ -242,6 +243,13 @@ again:
             adb_host_flush(ADB_ADDR_MOUSE_TMP);
             adb_host_listen(ADB_ADDR_MOUSE_TMP, ADB_REG_3, ((reg3 >> 8) & 0xF0) | ADB_ADDR_0, 0xFE);
             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("MM: reg3:%04X\n", reg3);
+            dmprintf("Macally2: found: %02X\n", mouse_handler);
         } else {
             dmprintf("Unknown\n");
         }
@@ -350,6 +358,15 @@ void adb_mouse_task(void)
     //   b--: Button state.(0: on, 1: off)
     //   x--: X axis movement.
     //   y--: Y axis movement.
+    //
+    // Macally2
+    //
+    //   Byte 0: b00 y06 y05 y04 y03 y02 y01 y00
+    //   Byte 1: b01 x06 x05 x04 x03 x02 x01 x00
+    //   Byte 2: 1   0   0   0   1   0   0   0
+    //   Byte 3: 1   0   0   0   1   0   0   0
+    //
+    //   Byte 2 and 3 have no meaningful info.
     len = adb_host_talk_buf(ADB_ADDR_MOUSE_POLL, ADB_REG_0, buf, sizeof(buf));
 
     // If nothing received reset mouse acceleration, and quit.
@@ -357,7 +374,12 @@ void adb_mouse_task(void)
         mouseacc = 1;
         return;
     };
-    dmprintf("[%02X %02X %02X %02X %02X]\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
+
+    dmprintf("[%02X %02X %02X %02X %02X] len:%02X\n", buf[0], buf[1], buf[2], buf[3], buf[4], len);
+    xprintf("MM:[ ");
+    for (uint8_t i = 0; i < len; i++)
+        xprintf("%02X ", buf[i]);
+    xprintf("] mh:%02X\n", mouse_handler);
 
     // Store off-buttons and 0-movements in unused bytes
     bool xneg = false;
@@ -365,17 +387,36 @@ void adb_mouse_task(void)
     if (len == 2) {
         if (buf[0] & 0x40) yneg = true;
         if (buf[1] & 0x40) xneg = true;
+    } else if (mouse_handler == ADB_HANDLER_MACALLY2_MOUSE) {
+        xprintf("MM: Macally2\n");
+        if (buf[0] & 0x40) yneg = true;
+        if (buf[1] & 0x40) xneg = true;
+        // Ignore Byte 2 and 3
+        len = 2;
     } else {
         if (buf[len - 1] & 0x40) yneg = true;
         if (buf[len - 1] & 0x04) xneg = true;
     }
 
+    // Make unused buf bytes compatible with Extended Mouse Protocol
     for (int8_t i = len; i < sizeof(buf); i++) {
         buf[i] = 0x88;
         if (yneg) buf[i] |= 0x70;
         if (xneg) buf[i] |= 0x07;
     }
 
+    if (mouse_handler == ADB_HANDLER_CLASSIC1_MOUSE ||
+        mouse_handler == ADB_HANDLER_CLASSIC2_MOUSE) {
+        // Some mouses misuse 'second button' bit we have to ignore it
+        // https://github.com/tmk/tmk_keyboard/issues/724
+        buf[1] |= 0x80;
+    }
+
+    xprintf("MM:[ ");
+    for (uint8_t i = 0; i < sizeof(buf); i++)
+        xprintf("%02X ", buf[i]);
+    xprintf("]\n");
+
     // 8 buttons at max
     // TODO: Fix HID report descriptor for mouse to support button6-8
     uint8_t buttons = 0;
diff --git a/tmk_core/protocol/adb.h b/tmk_core/protocol/adb.h
index 31c26fb9..578f9883 100644
--- a/tmk_core/protocol/adb.h
+++ b/tmk_core/protocol/adb.h
@@ -95,6 +95,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #define ADB_HANDLER_CLASSIC2_MOUSE      0x02
 #define ADB_HANDLER_EXTENDED_MOUSE      0x04
 #define ADB_HANDLER_TURBO_MOUSE         0x32
+#define ADB_HANDLER_MACALLY2_MOUSE      0x42
 
 
 // ADB host
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index a314e5c7..af45afa6 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -120,7 +120,7 @@ static bool console_is_ready(void)
 {
     static bool hid_listen_ready = false;
     if (!hid_listen_ready) {
-        if (timer_read32() < 2500)
+        if (timer_read32() < 5000)
             return false;
         hid_listen_ready = true;
     }
« Last Edit: Tue, 29 March 2022, 20:54:38 by hasu »

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1144 on: Wed, 30 March 2022, 03:57:36 »
So :

For the Macally Mouse, it works ! I have the two buttons, the cursor move, no problem.

For all the 3 devices with weird right clic, it works. No right clic when i press the main button. Thank's !

I join the Kensington Mouse logs (with 4 buttons).

I join the logs for the Keypad/Trackball too.
Actually, i have this Keypad + trackball and 2 others Keypad, and they are not working.

The trackpad "GlidePoint" make nothing on the logs.

And for the NeXT mouse, it's very weird : with this firmware, the mouse is not working (i have tried with the 470 ohm and the 4,7K ohm). It works with the precedent firmware (i join a log with the precedent firmware), but only with cold plug.

And finally, a things : the correction with the second button seems to break my Apple Pippin pad : there is a second button who send right clic, and now, it's disabled (i join the log)

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1145 on: Wed, 30 March 2022, 10:10:40 »
Fix for Device 4, 5 and 7, these pointing devices will affect properly implemented devices like NeXT mosue and Pippin.
This fix makes second button disabled on NeXT and Pippin while some broken devices usable. This is tradeoff and I don't think we can take both. I think NeXT and Pippin can't register second button on Mac OS9. This Fix emulates behaviour of classic Mac OS9.

As for keypad, I don't have idea now. They don't seem to appear as a keyboard in the log. What if cold-plug with new firmware?

NeXT mouse fails to startup several times before it starts working.

Some device may require power voltage. Can you try shorter USB cable or powered hub for GlidPoint and NeXT?

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1146 on: Wed, 30 March 2022, 11:21:51 »
Added code for Logitech device support.

Can you try attached firmware with these devices and take debug log?
- TrackMan: https://www.journaldulapin.com/2017/09/23/le-trackball-adb-de-logitech/
- MouseMan: https://www.journaldulapin.com/2020/11/03/adb-mouse-logitech/

Not supported yet but can you post debug log of Contour Mouse also?
- Contour Mouse: https://www.journaldulapin.com/2020/10/27/contour-mouse/

* adb_usb_rev1.hex (66.48 kB - downloaded 83 times.)

Offline Dandu

  • Posts: 43
Re: TMK ADB to USB keyboard converter
« Reply #1147 on: Wed, 30 March 2022, 16:48:36 »
For the NeXT mouse, it's weird : it works... after a few second. When i connect it, nothing appear, and after movements and clic, the mouse is working.

I'm not at home until monday, i will test all the things at that moment. Thank you !

Offline hasu

  • Thread Starter
  • Posts: 3484
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK ADB to USB keyboard converter
« Reply #1148 on: Wed, 30 March 2022, 21:55:59 »
In new firmware I added 5 second wait at startup temporarily to make sure the beginning of debug log shows up.
2.5 second wait works for Linux and Windows, but MacOS seems to require longer wait.

This 5 second wait may affect NexT mouse.


For the NeXT mouse, it's weird : it works... after a few second. When i connect it, nothing appear, and after movements and clic, the mouse is working.

I'm not at home until monday, i will test all the things at that moment. Thank you !


Offline jzw95

  • Posts: 11
  • Location: Edinburgh, Scotland
Re: TMK ADB to USB keyboard converter
« Reply #1149 on: Fri, 01 April 2022, 15:31:34 »
Sorry if this is a silly question, I'm still trying to assimilate all the excellent information and resources here, but haven't read every one of the 1,148 posts in this thread. Does this converter work both ways, also allowing the use of USB keyboards (and mice?) with old ADB Macs? Thanks for any info!