Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[adb2usb] weird Keyboard recognition #640

Closed
waszqba opened this issue Jan 29, 2020 · 39 comments
Closed

[adb2usb] weird Keyboard recognition #640

waszqba opened this issue Jan 29, 2020 · 39 comments

Comments

@waszqba
Copy link

waszqba commented Jan 29, 2020

Hello,
I have built the adb2tmk converter using Pro Micro Arduino compatible and TMK with the unimap_plain slightly tailored to suit my needs and config.h suited with VID and DEV_ID to match my ISO AEK II directly soldered to the pro micro with 1KOhm pull-up resistor.

There are 3 scenarios which occur:

  • Directly after flash:
    • L/R Modifiers are distinguished
    • § and grave keys are swapped
      jumping to bootloader and back has no effect
  • Unplugged and plugged USB
    • L/R modifiers are not distinguished
    • § and grave keys are still swapped
      at this stage, jumping to bootloader and waiting 8 seconds for the controller to reboot brings us to scenario Debouncing support #3
  • Replugged and rebooted
    • L/R modifiers are distinguished
    • § and grave keys seem to be in their places
      rebooting gives no further effect safely looping us back to scenario Debouncing support #3

Another weird thing is that the § is being sent when the GRV is set in keymap and the grave key is emitted when defined as KC_NUBS, but that's a small thing I can cope with and don't mind as long as I can just set the keymap and rely on it

Any way I can at least try to find out what happened?

@tmk
Copy link
Owner

tmk commented Jan 29, 2020

Can you test with default firmware downloaded from TMK keymap editor without edit?
http://www.tmk-kbd.com/tmk_keyboard/editor/unimap/?adb_usb_rev1

And share output from hid_listen when the problems occurs.
https://github.com/tmk/tmk_keyboard/wiki#debug-console

And show me pic of your ISO AEK, I don't know much where the § is.

@waszqba
Copy link
Author

waszqba commented Jan 31, 2020

Sure, will try on weekend and let you know :)

@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

I wasn't able to run the PJRC debug tool, I got an error stating I have a bad CPU (???)

However after flashing the rev1 you linked I got similar results:

  • Flashed -> correct position
  • Replugged - wrong position
  • rebooted - correct position

Bad news is that I cannot flash my device anymore, since trying to jump into bootloader simply reboots the keyboard without any time to actually spend in bootloader. Any help?
[edit]luckily shorting reset pin still worked, so I got it flashed again, what's strange tho is that the controller's id's changed from cu.usbmodem14201 to tty.usbmodem14101[/edit]

This is my layout:
photo5890886176242512930

@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

I tried the second revision from the editor, but I got nothing, the keyboard wasn't even recognized as a HID, so I'm back to my version for now, but open to experiments to help identify the issue

@tmk
Copy link
Owner

tmk commented Feb 3, 2020

hmm, I guess your hardware of converter has something wrong. Show me photo of your pro micro and wiring this time. Rev2 firmware is not for your converter, it features different controller ATmega32u2.

And how did you change files when you built firmware? Patch output of diff command would be helpful if the difference is slight.

@tmk
Copy link
Owner

tmk commented Feb 3, 2020

And I am just curious, the AEK layout is for German or other language?

@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

Here are changes

Index: converter/adb_usb/Makefile
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- converter/adb_usb/Makefile	(revision 3b21f85e9bb731adcbd40be1b93b7d39ef7748c5)
+++ converter/adb_usb/Makefile	(date 1579631679439)
@@ -1,5 +1,5 @@
 # Target file name (without extension).
-TARGET ?= adb_usb
+TARGET ?= adb_usb_pro_micro
 
 # Directory common source filess exist
 TMK_DIR ?= ../../tmk_core
@@ -18,7 +18,7 @@
 # atmega32u4 	Teensy2.0
 # atemga32u4	TMK Converter rev.1
 # atemga32u2	TMK Converter rev.2
-MCU ?= atmega32u2
+MCU ?= atmega32u4
 
 # Processor frequency.
 #     This will define a symbol, F_CPU, in all source code files equal to the
 
Index: converter/adb_usb/config.h
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- converter/adb_usb/config.h	(revision 3b21f85e9bb731adcbd40be1b93b7d39ef7748c5)
+++ converter/adb_usb/config.h	(date 1580189587373)
@@ -19,12 +19,12 @@
 #define CONFIG_H
 
 
-#define VENDOR_ID       0xFEED
-#define PRODUCT_ID      0x0ADB
+#define VENDOR_ID       0x05AC
+#define PRODUCT_ID      0x020C
 #define DEVICE_VER      0x0101
-#define MANUFACTURER    t.m.k.
-#define PRODUCT         ADB keyboard converter
-#define DESCRIPTION     convert ADB keyboard to USB
+#define MANUFACTURER    Apple
+#define PRODUCT         Extended Keyboard II
+#define DESCRIPTION     ISO Apple Extended Keyboard II
 
 /* matrix size */
 #define MATRIX_ROWS 16  // keycode bit: 3-0
Index: converter/adb_usb/unimap_plain.c
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- converter/adb_usb/unimap_plain.c	(revision 3b21f85e9bb731adcbd40be1b93b7d39ef7748c5)
+++ converter/adb_usb/unimap_plain.c	(date 1580298227427)
@@ -16,10 +16,33 @@
 */
 #include "unimap_common.h"
 
+/* id for user defined functions */
+enum function_id {
+    LSHIFT_LPAREN,
+};
+
+enum macro_id {
+    RAMBOX,
+    TEAMS,
+    ITERM,
+    WSTORM,
+    DEEZ,
+};
 
-#define AC_FN0  ACTION_LAYER_TAP_KEY(1, KC_GRV)
+#define SPOTLIGHT I(0), D(LGUI), T(SPC), U(LGUI)
+
+#define AC_FN0  ACTION_LAYER_TAP_KEY(1, KC_NUBS)
 #define AC_FN1  ACTION_LAYER_TAP_KEY(2, KC_BSLS)
 #define AC_PKEY ACTION_MODS_TAP_KEY(MOD_NONE, KC_POWER)
+// Function: LShift with tap '('
+#define AC_LSOP ACTION_FUNCTION_TAP(LSHIFT_LPAREN)
+
+// Macros:
+#define AC_RMBX     ACTION_MACRO(RAMBOX)
+#define AC_TIMS     ACTION_MACRO(TEAMS)
+#define AC_ITRM     ACTION_MACRO(ITERM)
+#define AC_STRM     ACTION_MACRO(WSTORM)
+#define AC_DEEZ     ACTION_MACRO(DEEZ)
 
 #ifdef KEYMAP_SECTION_ENABLE
 const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
@@ -31,13 +54,13 @@
      * |Esc|   |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|             |Pwr|
      * `---'   `---------------' `---------------' `---------------' `-----------'             `---'
      * ,-----------------------------------------------------------. ,-----------. ,---------------. ,---.
-     * |  `|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|Backspa| |Ins|Hom|PgU| |NmL|  =|  /|  *| |VUp|
+     * |  §|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|Backspa| |Ins|Hom|PgU| |NmL|  =|  /|  *| |VUp|
      * |-----------------------------------------------------------| |-----------| |---------------| |---|
-     * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|    \| |Del|End|PgD| |  7|  8|  9|  -| |VDn|
-     * |-----------------------------------------------------------| `-----------' |---------------| |---|
-     * |CapsLo|  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|#  |Retn|               |  4|  5|  6|  +| |Mut|
+     * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|     | |Del|End|PgD| |  7|  8|  9|  -| |VDn|
+     * |------------------------------------------------------| Ret| `-----------' |---------------| |---|
+     * |CapsLo|  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '| \ |    |               |  4|  5|  6|  +| |Mut|
      * |-----------------------------------------------------------|     ,---.     |---------------| `---'
-     * |Shif|\  |  Z|  X|  C|  V|  B|  N|  M|  ,|  ,|  /|Shift     |     |Up |     |  1|  2|  3|   |
+     * |Sft(|`  |  Z|  X|  C|  V|  B|  N|  M|  ,|  ,|  /|Shift     |     |Up |     |  1|  2|  3|   |
      * |-----------------------------------------------------------| ,-----------. |-----------|Ent| ,---.
      * |Ctrl |Opt |Gui |         Space           |Gui* |Opt |Ctrl  | |Lef|Dow|Rig| |      0|  .|   | |Ply|
      * `-----------------------------------------------------------' `-----------' `---------------' `---'
@@ -47,10 +70,10 @@
      */
     [0] = UNIMAP_ADB(
     ESC,      F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12,        PSCR,SLCK,PAUS,                 PKEY,
-    FN0, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL,      BSPC,  INS, HOME,PGUP,  NLCK,PEQL,PSLS,PAST,  VOLU,
+    GRV, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL,      BSPC,  INS, HOME,PGUP,  NLCK,PEQL,PSLS,PAST,  VOLU,
     TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,     FN1,   DEL, END, PGDN,  P7,  P8,  P9,  PMNS,  VOLD,
     LCAP,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,     NUHS,ENT,                    P4,  P5,  P6,  PPLS,  MUTE,
-    LSFT,NUBS,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,          RSFT,       UP,         P1,  P2,  P3,  PENT,
+    LSOP,FN0 ,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,          RSFT,       UP,         P1,  P2,  P3,  PENT,
     LCTL,LALT,LGUI,               SPC,                               RALT,RCTL,  LEFT,DOWN,RGHT,  P0,       PDOT,       MPLY
     ),
 
@@ -65,7 +88,7 @@
      * |-----------------------------------------------------------| `-----------' |---------------| |---|
      * |CapsLo|VoD|VoU|Mut|   |   |   |   |Hom|PgU|Lef|Rig|#  |Retn|               |   |   |   |   | |   |
      * |-----------------------------------------------------------|     ,---.     |---------------| `---'
-     * |    |   |   |   |   |   |   |   |   |End|PgD|Dow|Shift     |     |PgU|     |   |   |   |   |
+     * |    |   |<< | |>| >>|   |   |   |   |End|PgD|Dow|Shift     |     |PgU|     |   |   |   |   |
      * |-----------------------------------------------------------| ,-----------. |-----------|   | ,---.
      * |     |    |    |                         |     |    |      | |Hom|PgD|End| |       |   |   | |   |
      * `-----------------------------------------------------------' `-----------' `---------------' `---'
@@ -75,7 +98,7 @@
     ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12,      DEL,   TRNS,TRNS,TRNS,  TRNS,TRNS,TRNS,TRNS,  TRNS,
     TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP,  INS,      TRNS,  TRNS,TRNS,TRNS,  TRNS,TRNS,TRNS,TRNS,  TRNS,
     TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,LEFT,RGHT,     TRNS,TRNS,                   TRNS,TRNS,TRNS,TRNS,  TRNS,
-    TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,END, PGDN,DOWN,          TRNS,       PGUP,       TRNS,TRNS,TRNS,TRNS,
+    TRNS,TRNS,MRWD,MPLY,MFFD,TRNS,TRNS,TRNS,TRNS,END, PGDN,DOWN,          TRNS,       PGUP,       TRNS,TRNS,TRNS,TRNS,
     TRNS,TRNS,TRNS,               TRNS,                              TRNS,TRNS,  HOME,PGDN,END,   TRNS,     TRNS,       TRNS
     ),
 
@@ -86,9 +109,9 @@
      * ,-----------------------------------------------------------. ,-----------. ,---------------. ,---.
      * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete | |   |   |   | |   |   |   |   | |   |
      * |-----------------------------------------------------------| |-----------| |---------------| |---|
-     * |     |   |   |   |   |   |   |   |PrS|ScL|Pau|Up |INS|     | |   |   |   | |   |   |   |   | |   |
+     * |     |   |   |   |RBX|TMS|   |   |ITM|ScL|Pau|Up |INS|     | |   |   |   | |   |   |   |   | |   |
      * |-----------------------------------------------------------| `-----------' |---------------| |---|
-     * |CapsLo|VoD|VoU|Mut|   |   |   |   |Hom|PgU|Lef|Rig|#  |Retn|               |   |   |   |   | |   |
+     * |CapsLo|VoD|VoU|Dzr|   |   |   |   |Hom|PgU|Lef|Rig|#  |Retn|               |   |   |   |   | |   |
      * |-----------------------------------------------------------|     ,---.     |---------------| `---'
      * |    |   |   |   |   |   |   |   |   |End|PgD|Dow|Shift     |     |PgU|     |   |   |   |   |
      * |-----------------------------------------------------------| ,-----------. |-----------|   | ,---.
@@ -98,9 +121,71 @@
     [2] = UNIMAP_ADB(
     GRV,      TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,       TRNS,TRNS,TRNS,                 TRNS,
     ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12,      DEL,   TRNS,TRNS,TRNS,  TRNS,TRNS,TRNS,TRNS,  TRNS,
-    TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP,  INS,      TRNS,  TRNS,TRNS,TRNS,  TRNS,TRNS,TRNS,TRNS,  TRNS,
-    TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,LEFT,RGHT,     TRNS,TRNS,                   TRNS,TRNS,TRNS,TRNS,  TRNS,
+    TRNS,TRNS,STRM,TRNS,RMBX,TIMS,TRNS,TRNS,ITRM,SLCK,PAUS,UP,  INS,      TRNS,  TRNS,TRNS,TRNS,  TRNS,TRNS,TRNS,TRNS,  TRNS,
+    TRNS,VOLD,VOLU,DEEZ,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,LEFT,RGHT,     TRNS,TRNS,                   TRNS,TRNS,TRNS,TRNS,  TRNS,
     TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,END, PGDN,DOWN,          TRNS,       PGUP,       TRNS,TRNS,TRNS,TRNS,
     TRNS,TRNS,TRNS,               TRNS,                              TRNS,TRNS,  HOME,PGDN,END,   TRNS,     TRNS,       TRNS
     ),
 };
+
+/*
+ * Macro definition
+ */
+const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
+{
+    switch (id) {
+        case RAMBOX:
+            return (record->event.pressed ?
+                    MACRO( SPOTLIGHT, T(R), T(A), T(M), W(100), T(ENT), END ) :
+                    MACRO_NONE );
+        case TEAMS:
+            return (record->event.pressed ?
+                    MACRO( SPOTLIGHT, T(T), T(E), T(A), T(M), T(S), W(100), T(ENT), END ) :
+                    MACRO_NONE );
+        case ITERM:
+            return (record->event.pressed ?
+                    MACRO( SPOTLIGHT, T(I), T(T), T(E), T(R), W(100), T(ENT), END ) :
+                    MACRO_NONE );
+        case WSTORM:
+            return (record->event.pressed ?
+                    MACRO( SPOTLIGHT, T(W), T(E), T(B), T(S), T(T), W(100), T(ENT), END ) :
+                    MACRO_NONE );
+        case DEEZ:
+            return (record->event.pressed ?
+                    MACRO( SPOTLIGHT, T(D), T(E), T(E), T(Z), T(E), T(R), W(100), T(ENT), END ) :
+                    MACRO_NONE );
+    }
+    return MACRO_NONE;
+}
+
+/*
+ * user defined action function
+ */
+void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
+{
+    switch (id) {
+        case LSHIFT_LPAREN:
+            // XXX: doesn't work with other tap key. iffy at least
+            // Shift parentheses example: LShft + tap '('
+            // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses
+            // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899
+            if (record->event.pressed) {
+                if (record->tap.count == 0 || record->tap.interrupted) {
+                    register_mods(MOD_BIT(KC_LSHIFT));
+                }
+                return;
+            }
+            if (record->tap.count == 0 || record->tap.interrupted) {
+                return unregister_mods(MOD_BIT(KC_LSHIFT));
+            }
+            add_weak_mods(MOD_BIT(KC_LSHIFT));
+            send_keyboard_report();
+            register_code(KC_9);
+            unregister_code(KC_9);
+            del_weak_mods(MOD_BIT(KC_LSHIFT));
+            send_keyboard_report();
+            record->tap.count = 0;  // ad hoc: cancel tap
+
+            break;
+    }
+}

@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

This is the version I hardwired later on, with 1KOhm resistor connecting 5V and the 3rd pin
I'll take the photo tomorrow as I left my board at work. Regarding your question: according to this article it seems to be international English ISO layout

@tmk
Copy link
Owner

tmk commented Feb 3, 2020

Ah, It is 3.3V version, you have to close J1 solder jumper to supply 5V probably.

@tmk tmk closed this as completed Feb 3, 2020
@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

It's 5v version, I double-checked that with a multimeter before the whole operation

@tmk
Copy link
Owner

tmk commented Feb 3, 2020

How did you checked?
You have to check voltage of VCC pin of the microcontroller.

@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

yup, and it showed me 4.9V which I consider close enough since my multimeter tend's to lower the results, also, it has 16MHz quartz and AFAIK they are only made in 8MHz/3.3v and 16MHz/5v variants

@tmk
Copy link
Owner

tmk commented Feb 3, 2020

Are you sure? Pro Micro is totally mess for users unless you got it from Sparkfun or reliable sources.
Try close J1.

With Pro Micro you can save little money but often waste time :(

@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

Well, anywhere I check there's info that 16MHz (present in my model) requires 5v to be reliable, when powering of USB I get the readings mentioned above, but I'll short the J1 just in case, after all it can't hurt it with the desired 5v, can it? :)

I'll let you know tomorrow how it went

@tmk
Copy link
Owner

tmk commented Feb 3, 2020

And you had better not to use the Apple's vendor/product ID with this converter, perticular on MacOS. It may make the OS confused.

@waszqba
Copy link
Author

waszqba commented Feb 3, 2020

well my goal was to make it actually work as an apple keyboard so the OS won't ask me to go through that silly layout check routine, however I only changed it recently already after I noticed the issue with the keymap scramble (sounds like a title of some adventure movie :D)

@waszqba
Copy link
Author

waszqba commented Feb 4, 2020

INB4 I know my soldering is no engineering marvel

I tried shorting out the J1 connector but no luck, the issue persists. About the wiring: I wired the pro micro directly to the lines the connector was wired to, everything was checked with multimeter and noted for reference in order not to mix the wires, so I'm pretty certain about that. All the keys, including Magic key, work and the CapsLock LED lights up properly, which drives me to assumption it get's enough voltage, but this could be inferred from previous messages.

I'm afraid we'll have to reopen this issue :(

Still wondering though, why would it mess up the keyboard detection on power up but work correctly after soft reboot?

@tmk
Copy link
Owner

tmk commented Feb 4, 2020

Yes, if the problem still be there, your firmware setup causes probably. Then, I don't know why the default firmware didn't work for your converter.

The converter detects if keyboard is ANSI or ISO only when startup and MacOS does dirty trick under the hood to hide their trivial keyboard wierdness from users. See HID driver source code from Apple in this comments, it may explain.
#35 (comment)

The converter does the trick for you, so that it will be problem if MacOS does it again.
Windows, Linux or other OSes except for MacOS don't have the trick, the converter have to do that for them. This is why.

The default firmware or plain built firmware(without the VID/PID setting) should work on MacOS.

@waszqba
Copy link
Author

waszqba commented Feb 4, 2020

But the thing is not only the characters are messed up on macOS, it seems that the controller itself messes up the keymap, as the momentary layer key changes places, so I don't think that it's the OS's thing. Also, modifiers are nod being distinguished properly in some cases, but after reboot they are, so there must be something in the detection mechanism. If there only was some way to actually debug it in code... I'll try the stock firmware on the bridged J1 at home and let you know if it changes anything.

  • stock firmware on J1 open
  • My firmware on J1 open
  • My firmware on J1 closed
  • Stock firmware on J1 closed

@waszqba
Copy link
Author

waszqba commented Feb 4, 2020

Huh, funny thing, I tried stock firmware on another board and a fresh controller with J1 open, now it acts like this, but I'm unsure if this occurred on my main board, didn't test it, but probably acts the same:

  • reconnect -> keys in place
  • reboot -> keys swapped

Edit:
Ok, many weird things happened:
after I actually soldered the J1 together the board behaved as expected when flashed fresh, after reconnect it seemed to mess up the mentioned keys but recognized left/right modifiers, after reboot there was no change to that, but then after reconnect it worked properly. all on my firmware... Now I am really confused... gotta try it on my main board
Note: The effect only took place when I flashed the controller with the J1 closed, being flashed open and booted closed brought no effect whatsoever
edit2:
stock firmware on J1 closed tested. If it works properly is quite random. When flashed it can go both ways, when reconnected quickly (about 1 second of being disconnected) it works improperly, when given some time between disconnecting and connecting (2s+) it has quite a chance to operate properly, I'd rate that chance for about 9/10, but still not 100%
edit 3:
And so the confusion continues... I now flashed my firmware onto the controller and... It actually performs even better than the stock! Even fast reconnecting doesn't bother the board and it works perfectly well. I tested the stock-mine-stock-mine cycle couple of times and this statement holds true. I'm extremely confused now.
Note 2:
I think adding this resolution of closing the J1 when powered directly and only from USB to FAQ about pro micro (or elsewhere in the wiring docs) could be a good idea to save you some time in the future.

@waszqba
Copy link
Author

waszqba commented Feb 5, 2020

tested on my main board with J1 closed and actually... it seems to work properly when quickly reconnected, but when slowly, the keymap is scrambled... the behavior of this seems so random... I don't actually know if the J1 is actually doing anything now.
I reverted my code to stock, just as freshly pulled from master. On slow reconnect it acts well, on fast it's messed, and, what's interesting to me, after slow reconnect and magic key reboot it's scrambled again, and that changes every cycle like the reboot was toggling between two handlers.. Ain't that a marvel, @tmk ? Also the keys registered on 'my stock' build match the layout of my aekii but the function-tap key actually is in the wrong place.

@waszqba
Copy link
Author

waszqba commented Feb 5, 2020

I tried to flash my firmware with stock config on J1 closed and now GRV is being read as actual GRV, but the overall behavior hasn't changed, keys are swapped and modifiers are mixed on long reconnect and correct on quick
I can share my code/hex/whatever is needed to you. this is how my map looks in the editor
What's also interesting is that only the GRV/NUBS keys are swapped, my other layer tap key (being my actual backslash) stays in place and functions properly

@tmk
Copy link
Owner

tmk commented Feb 5, 2020

What do you mean by 'reconnect'? Plug into USB port or hot-plug keyboard into the converter? You better connect keyboard to converter first and then plug into USB port every time.

Stock firmware should work for the grave and ISO key when you plug as mentioned above. For ISO keyboard, hot-plugging(without power cycle of the converter) is not supported at this time.

Bootloader of ProMicro by magic command is not officially supported yet, it is another issue. Use reset pin or button for a while.

@tmk
Copy link
Owner

tmk commented Feb 5, 2020

And output from hid_listen would be helpful. The tool shoul work if your setup is ok.

Test with Windows and Linux and know difference from MacOS, that would be helpful to understnad the problem also. I don't have any MacOS to test, btw.

I'm assuming you are testing this on MacOS, is that right?

@waszqba
Copy link
Author

waszqba commented Feb 6, 2020

yup, testing on macOS
although not supported, the magic bootloader jump works fine in my case
by replugging I mean the USB, the keyboard is hard-wired to the controller, so hot pluging is not an option
I'll try to get the hid_listen to work, but I need to tinker around it, because it throws me that CPU error of sort...

@waszqba
Copy link
Author

waszqba commented Feb 11, 2020

Sooo I tried many ways on many macs, but the only version of hid_listen I got working is the one wrapped in node.js

Couldn't find any info on what should normally be expected on the output, but I hope this will be somewhat informational. I can parse the data returned from hid_listen ofc and make id read anything you want
@tmk is there anything I can do to help you finding the source of the issue?

debug_diff.txt
debug_improper.txt
debug_proper.txt

@tmk
Copy link
Owner

tmk commented Feb 11, 2020

hmm, it looks something wrong with hid_listen on MacOS. What's is your MacOS version? I guess the tools is not compatible with the latest MacOS, pherhaps. But I never heard it from the comunity yet. Compiling hid_listen yourself on your MacOS may solve this. You can get soruce of the tool here: https://github.com/PaulStoffregen/hid_listen

Also test on Windows may tell you something useful.

For example, this is output from the tool when the converter start up with M0116 keyboard.

Device disconnected.
Waiting for new device:......
Listening:


TMK:fb84cac5/LUFA


Scan:
 addr:2, reg3:6601

Keyboard:
hadler: 01, ISO: no

Mouse:

Scan:
 addr:2, reg3:6E01

USB configured.

Keyboard start.

@waszqba
Copy link
Author

waszqba commented Feb 11, 2020

I'm on Catalina 10.15.3
Will try to compile @ home & share the output. As far as I understand you wand just the output from the keyboard boot, right?

@waszqba
Copy link
Author

waszqba commented Feb 11, 2020

well, I got this darn thing compiled and working
At first I was unsure of the output given by the node version, but it seems to be pretty much the same. However, here it is, the output of the original hid_listen, when I plug in the board:

Waiting for device:.......
Listening:


TMK:d8228a37+/LUFA


Scan:
RRRRRRRRRRRRRRRR
Keyboard:
Rhadler: 00, ISO: no
R
Mouse:
R
Scan:
RRRRRRRRRRRRRRRR
USB configured.

Keyboard start.
RRR

and this is that I see after quickly reconnecting the keyboard:

Waiting for new device:.
Listening:


TMK:d8228a37+/LUFA


Scan:
 addr:2, reg3:6A05

Keyboard:
hadler: 05, ISO: yes

Mouse:

Scan:
 addr:2, reg3:6803

USB configured.

Keyboard start.

just after this I made a soft reboot and this version came up:

Waiting for new device:.........
Listening:


TMK:d8228a37+/LUFA


Scan:
 addr:2, reg3:6103

Keyboard:
hadler: 03, ISO: no

Mouse:

Scan:
 addr:2, reg3:6703

USB configured.

Keyboard start.

after normal, slow replug, result of which can be seen in the first paste, soft reboot seems to result in exactly the same situation as directly after hot-replug:

Waiting for new device:.........
Listening:


TMK:d8228a37+/LUFA


Scan:
 addr:2, reg3:6805

Keyboard:
hadler: 05, ISO: yes

Mouse:

Scan:
 addr:2, reg3:6203

USB configured.

Keyboard start.

@tmk
Copy link
Owner

tmk commented Feb 11, 2020

It doesn't recognize your keyobard as ISO correctly for some reason.

R in the first log means connection is not stable basically, I also see a few R when plugin-in keyboard but the R's in the log seem to me be too many. If you don't use proper connector and solder them, instead of using jumper wires.

Also pro micro's startup sequence may causes. Pro micro has two variant of its bootloader, old bootloader requires 8sec before start user application or converter firmware in our case while new Sparkfun one takes only 750ms. I think pro Micro is shipped with new one even if it is a clone but I'm sure.
https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/troubleshooting-and-faq#ts-reset

Meanwhile, Teensy and my TMK converters start up user application immediately without bootloader intervention. I'm not sure this causes acctually, though.

Keyboard is recognized by this part of code, and you can tweak its timing by changing this wait line.
https://github.com/tmk/tmk_keyboard/blob/master/converter/adb_usb/matrix.c#L83-L97
https://github.com/tmk/tmk_keyboard/blob/master/converter/adb_usb/matrix.c#L76

I don't have any Pro Micro, MacOS and ISO ADB keyboard to test this ufnortunately. You may want to ask help from other ISO keyboard users with MacOS in the thread in Geekhack.

Let us know if you have some clue.

TMK:d8228a37+/LUFA

Are you including your change for this test?
Please test with plain firmware without any of your change till we get default firmware worked in your environment as expected. I don't want to be confused.
You can use Makefile.rev1 to build firmware for your pro micro like make -f Makefile.rev1

@tmk
Copy link
Owner

tmk commented Feb 12, 2020

Can you share hid_listen binary you built?
It seems that MacOS 10.15 drops support for 32-bit binary and hid_listen for Mac hosted in PJRC site is 32-bit. Users on Catalina will have same problem with the tool. If you can share it would be helpful for them.

@waszqba
Copy link
Author

waszqba commented Feb 12, 2020

I'll test with stock firmware. One tap on reset has no visible effect, only doubletap lands me in bootloader on my board, so I guess I have the newer version. I also have everything soldered with short wires to the board itself.
By stock/plain you mean the one downloaded from editor or just to compile a clean one from source at master?

@waszqba
Copy link
Author

waszqba commented Feb 12, 2020

Can you share hid_listen binary you built?
It seems that MacOS 10.15 drops support for 32-bit binary and hid_listen for Mac hosted in PJRC site is 32-bit. Users on Catalina will have same problem with the tool. If you can share it would be helpful for them.

Sure, how do you want it shared? I can either host it on Mega and share a link or put it somewhere else

@waszqba
Copy link
Author

waszqba commented Feb 12, 2020

stock firmware from editor:
after plug in:

TMK:fb84cac5+/LUFA


Scan:
RRRRRRRRRRRRRRRR
Keyboard:
Rhadler: 00, ISO: no
R
Mouse:
R
Scan:
RRRRRRRRRRRRRRRR
USB configured.

Keyboard start.

after hot-replug:

TMK:fb84cac5+/LUFA


Scan:
RRRR
Keyboard:
hadler: 05, ISO: yes

Mouse:

Scan:
 addr:2, reg3:6A03

USB configured.

Keyboard start.

Soft reboot directly after that:

TMK:fb84cac5+/LUFA


Scan:
 addr:2, reg3:6503

Keyboard:
hadler: 03, ISO: no

Mouse:

Scan:
 addr:2, reg3:6403

USB configured.

Keyboard start.

slow plugin, soft reboot (like hot-replug):

TMK:fb84cac5+/LUFA


Scan:
 addr:2, reg3:6005

Keyboard:
hadler: 05, ISO: yes

Mouse:

Scan:
 addr:2, reg3:6003

USB configured.

Keyboard start.

@waszqba
Copy link
Author

waszqba commented Feb 12, 2020

freshly pulled master, built from scratch, completely clean, built using makefile.rev1:
after plug-in

TMK:6209ceeb/LUFA


Scan:
RRRRRRRRRRRRRRRR
Keyboard:
Rhadler: 00, ISO: no
R
USB configured.

Keyboard start.
RR

after hot-replug:

TMK:6209ceeb/LUFA


Scan:
 addr:2, reg3:6405

Keyboard:
hadler: 05, ISO: yes

USB configured.

Keyboard start.

Soft reboot directly after that ( this time the listener catches the boot loader command)

bootloade
Device disconnected.
Waiting for new device:.........
Listening:


TMK:6209ceeb/LUFA


Scan:
 addr:2, reg3:6103

Keyboard:
hadler: 03, ISO: no

USB configured.

Keyboard start.

slow plugin, soft reboot (like hot-replug):

TMK:6209ceeb/LUFA


Scan:
 addr:2, reg3:6905

Keyboard:
hadler: 05, ISO: yes

USB configured.

Keyboard start.

@waszqba
Copy link
Author

waszqba commented Feb 12, 2020

ok, The initialization wait time seems to be a viable workaround for me for now. I've tried 150 ms but 1 oof 3 times the keyboard wouldn't boot properly, so I set it to 200ms and now it works like magic, no hiccups, every boot, hard or soft, is correct with handler 5 and iso detected :D
Thank you @tmk for all the time you've spent on this topic and the help you provided <3
I am really grateful and I hope I can pay the favor back somehow. If there is any way I can help figuring out bugs or contributing anyhow to this project, I am willing to. Giant Kudos to you!

@tmk
Copy link
Owner

tmk commented Feb 12, 2020

Great to hear that.
I see, if you don't see the 'R' error with the longer delay works the errors meant slow ISO AEK startup, not your wiring problem nor pro micro bootloader. It seems the converter starts talking too early before the keyboard wakes up.
I'll update code to make the delay longer, probably 1000ms would be safe for other boards considering Pro micro booloader 750ms wait.

And again, could you share your hid_listen binary you built and run on Catalina?

tmk added a commit that referenced this issue Feb 13, 2020
Without proper delay keyboard the converter starts talking too early
before keyboard wakes up. ISO recognition and enabling Extention protocol
would be failed in the result.
#640 (comment)
200ms is enough for AEKs but 1000ms is used here for safety.
@waszqba
Copy link
Author

waszqba commented Feb 13, 2020

In my experience 200ms would be just enough, I don't see a single R in the log with this setting :)
And with the 150ms Even when I got a couple of Rs in the first row the keyboard worked properly (those 2 of 3 times), so I think those 200ms will be sufficient for most, if not all boards.
and here's the binary you asked for. It's in my 'Public Domain' directory so I won't delete it when cleaning my cloud someday

@tmk
Copy link
Owner

tmk commented Feb 13, 2020

I confirmed that there is the problem even with US ANSI layout AEK/AEKII, and 200ms is enough for AEKs. AEK startup is a bit slower than other ADB keyboards for some reason. I updated the delay codes in repo with commit ce5e565 for AEKS using 1000ms for safety of unknown devices.

And thanks for the hid_listen binary. That would be helpful for users on the latest MacOS.

tmk added a commit to tmk/hid_listen that referenced this issue Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants