Author Topic: TMK keyboard firmware  (Read 819862 times)

0 Members and 2 Guests are viewing this topic.

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1950 on: Sat, 27 July 2019, 14:22:16 »
I'm trying to wrap my head around TMK, and am having some trouble. Hasu directed me here to get help.

I'm hoping this will inform me generally on how to do this, but I'll stick to a concrete example for this discussion.

Recently, I was successful in using TMK to convert my Zenith Z-150 to usb. What I did was download the TMK repo and used the xt_usb (https://github.com/tmk/tmk_keyboard/tree/master/converter/xt_usb) converter to produce a hex file for my Zenith. Note that I built the hex from source, just cause I prefer doing it that way. This worked really well, and I am now at the point where I'm working remapping the keys.


Note that I understand how to remap the keys with the default xt layout - just find the key you want to remap in the  keymap.c file and change it's function.

That being said, I'd like to be able to change the physical layout in the keymap.c file, as I've encountered this problem before. That is, the keymap.c file for the xt_usb converter matches the physical layout of the IBM F XT identically:
Code: [Select]
    /* IBM XT keyboard layout
     * ,-------.  ,--------------------------------------------------------------------------.
     * | F1| F2|  |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  BS  |NumLck |ScrLck |
     * |-------|  |--------------------------------------------------------------------------|
     * | F3| F4|  | Tab |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ] |   |  7|  8|  9|  -|
     * |-------|  |------------------------------------------------------|Ent|---------------|
     * | F5| F6|  | Ctrl |  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|  `|   |  4|  5|  6|   |
     * |-------|  |----------------------------------------------------------------------|   |
     * | F7| F8|  |Shif|  \|  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift|  *|  1|  2|  3|  +|
     * |-------|  |----------------------------------------------------------------------|   |
     * | F9|F10|  |  Alt  |               Space                  |CapsLck|   0   |   .   |   |
     * `-------'  `--------------------------------------------------------------------------'
     */

for which the keymap is
Code: [Select]
    KEYMAP_XT( \
    F1,  F2,    ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,     NLCK,     SLCK,
    F3,  F4,    TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,     P7,  P8,  P9,  PMNS,
    F5,  F6,    LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,GRV, ENT, P4,  P5,  P6,
    F7,  F8,    LSFT,BSLS,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,PAST,P1,  P2,  P3,  PPLS,
    F9,  F10,   LALT,                    SPC,                          CAPS,          P0,       PDOT
    ),

On the other hand, the Zenith Z150's physical layout is

Code: [Select]
    /* Zenith Z150
     * ,-------.  ,--------------------------------------------------------------------------.
     * | F1| F2|  |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  BS  |NumLck |ScrLck |
     * |-------|  |--------------------------------------------------------------------------|
     * | F3| F4|  | Tab |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ] |   |  7|  8|  9|  -|
     * |-------|  |------------------------------------------------------|Ent|---------------|
     * | F5| F6|  | Ctrl |  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|       |  4|  5|  6|  +|
     * |-------|  |--------------------------------------------------------------------------|
     * | F7| F8|  | Shift  |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift|  *|  1|  2|  3|Ent|
     * |-------|  |----------------------------------------------------------------------|   |
     * | F9|F10|  |  Alt  | \|            Space                  |CapsLck|   0   |   .   |   |
     * `-------'  `--------------------------------------------------------------------------'
     */   

For which I'd like the corresponding keymap to be
Code: [Select]
    KEYMAP_ZENITHZ150( \
    F1,  F2,    ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC, GRV,NLCK,     SLCK,
    F3,  F4,    TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,     P7,  P8,  P9,  PMNS,
    F5,  F6,    LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT, ENT, P4,  P5,  P6,PPLS.
    F7,  F8,    LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,PAST,P1,  P2,  P3,  PADENT(?),
    F9,  F10,   LALT,BSLS,                SPC,                          CAPS,          P0,       PDOT
    ),

I'm not sure what I need to modify to make this change though, and was really hoping you could help me work through the process. I'd love to learn about this!

Let me know if you have any questions or would like me to clarify anything. Thanks so much!

**************************************************************************
Additionally, I ran into a problem while trying to remap that I'm having trouble solving. I'd like to have the caps lock key on my Zenith behave like a layer toggle button. I've come up with the following

Code: [Select]
const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* IBM XT keyboard layout
     * ,-------.  ,--------------------------------------------------------------------------.
     * | F1| F2|  |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  BS  |NumLck |ScrLck |
     * |-------|  |--------------------------------------------------------------------------|
     * | F3| F4|  | Tab |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ] |   |  7|  8|  9|  -|
     * |-------|  |------------------------------------------------------|Ent|---------------|
     * | F5| F6|  | Ctrl |  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|  `|   |  4|  5|  6|   |
     * |-------|  |----------------------------------------------------------------------|   |
     * | F7| F8|  |Shif|  \|  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift|  *|  1|  2|  3|  +|
     * |-------|  |----------------------------------------------------------------------|   |
     * | F9|F10|  |  Alt  |               Space                  |CapsLck|   0   |   .   |   |
     * `-------'  `--------------------------------------------------------------------------'
     */

    KEYMAP_XT( \
    F1,  F2,    ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,     NLCK,     SLCK,
    F3,  F4,    TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,     P7,  P8,  P9,  PMNS,
    F5,  F6,    CAPS,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,GRV, ENT, P4,  P5,  P6,
    F7,  F8,    LSFT,LALT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,PAST,P1,  P2,  P3,  PPLS,
    F9,  F10,   LCTRL,                    SPC,                          FN2,          P0,       PDOT
    ),   

    KEYMAP_XT( \
    F1,  F2,    ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10,   MINS,EQL, BSPC,     NLCK,     SLCK,
    F3,  F4,    TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,     P7,  P8,  P9,  PMNS,
    F5,  F6,    CAPS,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,GRV, ENT, P4,  P5,  P6,
    F7,  F8,    LSFT,LGUI,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,PAST,P1,  P2,  P3,  PPLS,
    F9,  F10,   LCTRL,                    SPC,                          TRNS,          P0,       PDOT
    ),       


};

with

Code: [Select]
const action_t PROGMEM fn_actions[] = {
        ACTION_LAYER_TOGGLE(1), //FN2
};

But it's not working, and I can't figure out why. Does someone know what's going on here?
   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1951 on: Sun, 28 July 2019, 18:03:10 »
To define KEYMAP_ZENITHZ150 in keymap_common.h or unimap_common.h for your Zenith 150:

For keymap_common.h, see how KEYMAP_XT is defined in the file. I hope that this looks obvious for coders.

It is macro definition which takes 83 parameters(IBM XT has that number of physiical keys).
https://en.wikipedia.org/wiki/C_preprocessor#Macro_definition_and_expansion

For example, XT protocol scan code for 'F1' is 0x3B and 'Space' is 0x39. So it uses 'K3B' and 'K39' as parameter for the keys respectively in first part of the '#define'. You can rearrange the first part for your keyboard physical layout.

The second part defines array of keymapping which conveters XT scan codes to TMK keycodes. The array has 8x16 space and its 128 elements correspond to XT scan codes 0x00-7F in order. Place 'KC_NO' in element if your keyboard doesn't have key for scan code the element indicates. Otherwise use 'KC_##Kxx', which is expanded for TMK keycode when it is compiled, as you define in your keymap.


Code: [Select]
/* IBM XT keyobard layout
 * ,-------.  ,--------------------------------------------------------------------------.
 * | F1| F2|  |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  BS  |NumLck |ScrLck |
 * |-------|  |--------------------------------------------------------------------------|
 * | F3| F4|  | Tab |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ] |   |  7|  8|  9|  -|
 * |-------|  |------------------------------------------------------|Ent|---------------|
 * | F5| F6|  | Ctrl |  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|  `|   |  4|  5|  6|   |
 * |-------|  |----------------------------------------------------------------------|   |
 * | F7| F8|  |Shif|  \|  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift|  *|  1|  2|  3|  +|
 * |-------|  |----------------------------------------------------------------------|   |
 * | F9|F10|  |  Alt  |               Space                  |CapsLck|   0   |   .   |   |
 * `-------'  `--------------------------------------------------------------------------'
 * Scan code set 1
 * ,-------.  ,--------------------------------------------------------------------------.
 * | 3B| 3C|  | 01| 02| 03| 04| 05| 06| 07| 08| 09| 0A| 0B| 0C| 0D|  0E  |  45   |  46   |
 * |-------|  |--------------------------------------------------------------------------|
 * | 3D| 3E|  | 0F  | 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 1A| 1B |   | 47| 48| 49| 4A|
 * |-------|  |------------------------------------------------------| 1C|---------------|
 * | 3F| 40|  | 1D   | 1E| 1F| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29|   | 4B| 4C| 4D|   |
 * |-------|  |----------------------------------------------------------------------|   |
 * | 41| 42|  | 2A | 2B| 2C| 2D| 2E| 2F| 30| 31| 32| 33| 34| 35|  36 | 37| 4F| 50| 51| 4E|
 * |-------|  |----------------------------------------------------------------------|   |
 * | 43| 44|  |  38   |              39                      |  3A   |  52   |  53   |   |
 * `-------'  `--------------------------------------------------------------------------'
 */
#define KEYMAP_XT( \
    K3B,K3C,  K01,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,K0E,    K45,    K46, \
    K3D,K3E,  K0F,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B,    K47,K48,K49,K4A, \
    K3F,K40,  K1D,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K1C,K4B,K4C,K4D,     \
    K41,K42,  K2A,K2B,K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34,K35,K36,K37,K4F,K50,K51,K4E, \
    K43,K44,  K38,                    K39,                    K3A,    K52,    K53      \
) { \
    { KC_NO,    KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
    { KC_##K08, KC_##K09, KC_##K0A, KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_##K0F }, \
    { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
    { KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \
    { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
    { KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
    { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
    { KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47 }, \
    { KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F }, \
    { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_NO,    KC_NO,    KC_NO,    KC_NO    }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO    }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO    }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO    }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO    }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO,    KC_NO    }  \
}


**************************************************************************
It is FN0. Use FN0 instead of FN2.

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1952 on: Mon, 29 July 2019, 09:11:16 »
Thanks hasu. Info is very useful, I'll try working with it and get back to you.
   

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1953 on: Sun, 04 August 2019, 16:37:29 »
Got it! Thanks Hasu!
   

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1954 on: Sat, 07 September 2019, 13:32:10 »
Having a new problem with TMK (and QMK, but hopefully solving the problem in TMK will help solve the problem in QMK).

I'm trying to convert a NMB (Hi-Tek) RT101+ to USB. It has a switch that can toggle between AT/XT. I have it set to AT mode and I'm trying to use TMK's ps2-usb converter to convert it to USB. Note that the keyboard works flawlessly with a blue cube ps2/usb converter.

I'm trying to use a pro micro, which is possibly causing problems. I don't have a teensy 2.0 on hand to test, but I'd prefer to get this working with a pro micro anyway as I have some other AT/ps2 keyboards to convert and if I can use a pro micro it's a lot cheaper.

NOTE: I JUST noticed that I'm supposed to have pull up resistors, which I DO NOT have soldered in. I will test this, but I'm also not sure where to put them. Can anyone tell me where they are supposed to go? Thanks

This image shows how I've wired things up.

Here's what I've tried (with TMK at least, I've done some testing with Soarer's and QMK and neither of those are working either):

- Tried building TMK ps2usb firmware (just make in tmk_keyboard/converter/ps2_usb)
Behavior: No output, no device recognized by windows (i.e. no "device plugged in" ding).
I tried this both with the default pinout (Clock PD1, Data PD0) and with the pins assigned as I actually have them wired (Clock PD3, Data PD2). Both versions exhibit identical behavior.


- Tried building ps2_usb rev1, which is supposed to use USART engine (make -f Makefile.rev1).
Behavior: Device recognized ding/jingle from windows, but no output from keyboard. HID listen shows the following:
Code: [Select]
Waiting for device:.......
Listening:
TMK:unknown/LUFA
USB configured.
Keyboard start.
Again, I tried this with the default pinout (Clock PD5, Data PD2) and my wiring (Clock PD3, Data PD2). Same behavior.

- Tried building ps2_usb rev2, which is supposed to use USART engine (make -f Makefile.rev2). I think the behavior is identical to rev1.
As usual, I tried this with the default pinout (Clock PD5, Data PD2) and my wiring (Clock PD3, Data PD2).


So, ideally, I'd like to get the interrupt (default?) method working, since it's "recommended," and failing that I'd like to get any version working. I'll give pull up resistors a try and see if that does it, but otherwise I'm at a loss and need help.

Thanks! And please let me know if I need to clarify anything!


--------------------------------------------------------------------------------
Update: Still not working
--------------------------------------------------------------------------------

Changed wiring to this and added pull up resistors. Tried all three ps2_usb variants (default make, make rev1, and make rev2), and none work. I also tried jumping J1 for 5V operation, to no effect.

- For default make (just running make in the ps2_usb directory), I get nothing at all. When I plug it into my windows computer I don't even get the "Device connected" sound. So, no change to behavior.

- For make rev1 (#make -f Makefile.rev1), at least windows recognizes that something was plugged in (Device connected sound plays), and HID listen sees something plugged in, but I can't get any output.

- Behavior for make rev2 (#make -f Makefile.rev2) is identical to default make, i.e. windows doesn't even think anything got plugged in.






« Last Edit: Sat, 07 September 2019, 18:35:00 by PancakeMSTR »
   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1955 on: Sat, 07 September 2019, 19:54:13 »
PancakeMSTR,
Use rev1 firmware for pro micro. (rev2 is for newer TMK converter with ATMega32u2, not for you at all.)

By default pin configuration for rev1 are PD2 and PD5 with USART. BTW, rev1 firmware is for old TMK converter with ATMega32u4.
https://github.com/tmk/tmk_keyboard/blob/master/converter/ps2_usb/Makefile.rev1#L13-L15

So you have to use PD2 and PD5 with default rev1 firmware and the covnerter should work.

And try other ps/2 keyboard than  NMB (Hi-Tek) RT101+ if it doesn't work.

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1956 on: Sun, 08 September 2019, 17:49:17 »
Hasu,

Thanks for getting back to me. I tested the ps2_usb converter with a different keyboard, one that's labeled "AT only" and has a ps2 connector. Long story short, I'm getting the same behavior, i.e. no output.

Here's a diagram of how I have things wired up. I didn't draw the GND and VCC line but they just run to GND and VCC on the pro micro.

As you can see, I wired the clock line into PD3 (TX0), because the pro micro does not have a PD5 pin. I correspondingly adjusted the pinout for PS2_USE_USART in config_rev1.h to use PD3 for clock:

Code: [Select]
/*
 * PS/2 USART
 */
#ifdef PS2_USE_USART
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
/* XCK for clock line and RXD for data line */
#define PS2_CLOCK_PORT  PORTD
#define PS2_CLOCK_PIN   PIND
#define PS2_CLOCK_DDR   DDRD
#define PS2_CLOCK_BIT   3//5
#define PS2_DATA_PORT   PORTD
#define PS2_DATA_PIN    PIND
#define PS2_DATA_DDR    DDRD
#define PS2_DATA_BIT    2

Then, to build the firmware, I ran

Code: [Select]
make -f clean Makefile.rev1
make -f Makefile.rev1

and wrote the hex file ps2_usb_rev1.hex to my pro micro.

I'm still hoping we can figure out how to get this working on a pro micro. What can I try next?
« Last Edit: Sun, 08 September 2019, 18:03:40 by PancakeMSTR »
   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1957 on: Sun, 08 September 2019, 19:07:54 »
You can't configure pins for USART, pins for USART is fixed and not configurable.
If PD5 is not available on pro micro then, you have to use BUSYWAIT or INT backend.
You can configure pins freely for BUSYWAIT in config_rev1.h.
Or copy INT pin configuration in config_rev2.h to config_rev.h. And use PD0 and PD1. Don't change pins if you are not familiar with the MCU.

I think this works but I don't have time and pro miro available in hand to test this at this point.
Apparently current README and pin configuration is not useful for usual DIYers, I'll update them when I get time.



Hasu,

Thanks for getting back to me. I tested the ps2_usb converter with a different keyboard, one that's labeled "AT only" and has a ps2 connector. Long story short, I'm getting the same behavior, i.e. no output.

Here's a diagram of how I have things wired up. I didn't draw the GND and VCC line but they just run to GND and VCC on the pro micro.

As you can see, I wired the clock line into PD3 (TX0), because the pro micro does not have a PD5 pin. I correspondingly adjusted the pinout for PS2_USE_USART in config_rev1.h to use PD3 for clock:

Code: [Select]
/*
 * PS/2 USART
 */
#ifdef PS2_USE_USART
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
/* XCK for clock line and RXD for data line */
#define PS2_CLOCK_PORT  PORTD
#define PS2_CLOCK_PIN   PIND
#define PS2_CLOCK_DDR   DDRD
#define PS2_CLOCK_BIT   3//5
#define PS2_DATA_PORT   PORTD
#define PS2_DATA_PIN    PIND
#define PS2_DATA_DDR    DDRD
#define PS2_DATA_BIT    2

Then, to build the firmware, I ran

Code: [Select]
make -f clean Makefile.rev1
make -f Makefile.rev1

and wrote the hex file ps2_usb_rev1.hex to my pro micro.

I'm still hoping we can figure out how to get this working on a pro micro. What can I try next?



Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1958 on: Sun, 08 September 2019, 20:31:57 »
You can't configure pins for USART, pins for USART is fixed and not configurable.
If PD5 is not available on pro micro then, you have to use BUSYWAIT or INT backend.
You can configure pins freely for BUSYWAIT in config_rev1.h.
Or copy INT pin configuration in config_rev2.h to config_rev.h. And use PD0 and PD1. Don't change pins if you are not familiar with the MCU.

I think this works but I don't have time and pro miro available in hand to test this at this point.
Apparently current README and pin configuration is not useful for usual DIYers, I'll update them when I get time.

I'll give it a try, see what I can do. Thanks for working with me, Hasu.


Hasu - I'm having a little trouble understanding exactly what you mean by "copy INT pin configuration in config_rev2.h to config_rev.h"? Would you mind elaborating?
« Last Edit: Sun, 08 September 2019, 21:53:47 by PancakeMSTR »
   

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1959 on: Sun, 08 September 2019, 22:25:58 »
--------------------------------
Update: Got it working
--------------------------------

Hasu -
Gave what you said to try a shot. Here's precisely what I did:

Copied the following from config_rev2.h

Code: [Select]
/*
 * PS/2 Pin interrupt
 */
#ifdef PS2_USE_INT
/* uses INT1 for clock line(ATMega32U4) */
#define PS2_CLOCK_PORT  PORTD
#define PS2_CLOCK_PIN   PIND
#define PS2_CLOCK_DDR   DDRD
#define PS2_CLOCK_BIT   1
#define PS2_DATA_PORT   PORTD
#define PS2_DATA_PIN    PIND
#define PS2_DATA_DDR    DDRD
#define PS2_DATA_BIT    0
#define PS2_INT_INIT()  do {    \
    EICRA |= ((1<<ISC11) |      \
              (0<<ISC10));      \
} while (0)
#define PS2_INT_ON()  do {      \
    EIMSK |= (1<<INT1);         \
} while (0)
#define PS2_INT_OFF() do {      \
    EIMSK &= ~(1<<INT1);        \
} while (0)
#define PS2_INT_VECT    INT1_vect
#endif

Into config_rev1.h (literally just copy-pasted it at the bottom).

Then, in Makefile.rev1, I changed it to use interrupt method instead of USART, i.e. changed the following lines

Code: [Select]
PS2_USE_USART = yes
PS2_USE_INT = no
PS2_USE_BUSYWAIT = no

to

Code: [Select]
PS2_USE_USART = no
PS2_USE_INT = yes
PS2_USE_BUSYWAIT = no

rebuild everything, flashed, and everything is working perfectly. I typed this comment using the second AT keyboard I switched to.

Here is the wiring diagram, for reference.

As usual, Thanks so much for working with me Hasu! I really appreciate the help, I probably would not have been able to get these keyboards converted without it.



   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1960 on: Sun, 08 September 2019, 22:36:48 »
PancakeMSTR,
Great.

I just updated github repository and first post of TMK PS/2 converter thread. It may make a bit easier for those unfamiliar with TMK and AVR controllers hoepfully... This update may break your changes in your repo, though.

https://geekhack.org/index.php?topic=14618.0

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1961 on: Mon, 09 September 2019, 09:46:18 »
Hasu -

I wanted to try your new version of ps2_usb, which mentions using Makefile.32u4, but I don't see any such file in the ps2_usb folder. Am I missing something?
   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1962 on: Mon, 09 September 2019, 17:57:38 »
Ah, thanks for letting me know. Pushed the file to repo now.
Post in the TMK PS/2 converter if you have further PS/2 converter specific topic.

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1963 on: Sat, 21 September 2019, 18:03:12 »
Hi Hasu,
I'm hoping you can help me understand Unimap a little bit. I'm trying to set it up with the xt_usb converter to remap my Model F XT.

I've played around with it a bit and I'm just hoping you could give a short explanation of each piece.

I'm looking at (my slightly edited version) of unimap_common.h. There are three arrays, and I'd like to better understand each of them.

The first is #define UNIMAP_XT. I'm guessing that this array just specifies all the keycodes for the keys physically on the keyboard, so this is like the "physical keycode map":
Code: [Select]
#define UNIMAP_XT( \
    K3B,K3C,  K01,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,K0E,    K45,    K46, \
    K3D,K3E,  K0F,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B,K1C,K47,K48,K49,K4A, \
    K3F,K40,  K1D,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,    K4B,K4C,K4D,K4E, \
    K41,K42,  K2A,K2B,K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34,K35,K36,K37,K4F,K50,K51,    \
    K43,K44,  K38,                    K39,                    K3A,    K52,    K53      \
)

I don't, however, understand how this relates to the "UNIMAP" array directly below it
Code: [Select]
UNIMAP( \
            NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO,                                      \
    K01,    K3B,K3C,K3D,K3E,K3F,K40,K41,K42,K43,K44,NO, NO,       NO, K46,NO,       NO, NO, NO,  \
    K29,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,NO, K0E,  NO, NO, NO,   K45,NO, K37,K4A, \
    K0F,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B,    K2B,  NO, NO, NO,   K47,K48,K49,K4E, \
    K3A,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,    NO, K1C,                K4B,K4C,K4D,NO,  \
    K2A,NO, K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34,K35,    NO, K36,      NO,       K4F,K50,K51,NO,  \
    K1D,NO, NO, NO,         K39,        NO, NO, NO, NO, NO, NO,   NO, NO, NO,       K52,K53,NO   \
)

Nor do I understand what role the last array, "unimap_trans", plays
Code: [Select]
const uint8_t PROGMEM unimap_trans[MATRIX_ROWS][MATRIX_COLS] = {
    { UNIMAP_NO,    UNIMAP_ESC,   UNIMAP_1,     UNIMAP_2,     UNIMAP_3,     UNIMAP_4,     UNIMAP_5,     UNIMAP_6     }, /* 00-07 */
    { UNIMAP_7,     UNIMAP_8,     UNIMAP_9,     UNIMAP_0,     UNIMAP_MINUS, UNIMAP_EQUAL, UNIMAP_BSPACE,UNIMAP_TAB   }, /* 08-0F */
    { UNIMAP_Q,     UNIMAP_W,     UNIMAP_E,     UNIMAP_R,     UNIMAP_T,     UNIMAP_Y,     UNIMAP_U,     UNIMAP_I     }, /* 10-17 */
    { UNIMAP_O,     UNIMAP_P,     UNIMAP_LBRC,  UNIMAP_RBRC,  UNIMAP_ENTER, UNIMAP_LCTL,  UNIMAP_A,     UNIMAP_S,    }, /* 18-1F */
    { UNIMAP_D,     UNIMAP_F,     UNIMAP_G,     UNIMAP_H,     UNIMAP_J,     UNIMAP_K,     UNIMAP_L,     UNIMAP_SCLN  }, /* 20-27 */
    { UNIMAP_QUOTE, UNIMAP_GRAVE, UNIMAP_LSHIFT,UNIMAP_BSLASH,UNIMAP_Z,     UNIMAP_X,     UNIMAP_C,     UNIMAP_V,    }, /* 28-2F */
    { UNIMAP_B,     UNIMAP_N,     UNIMAP_M,     UNIMAP_COMMA, UNIMAP_DOT,   UNIMAP_SLASH, UNIMAP_RSHIFT,UNIMAP_PAST  }, /* 30-37 */
    { UNIMAP_LALT,  UNIMAP_SPACE, UNIMAP_CAPS,  UNIMAP_F1,    UNIMAP_F2,    UNIMAP_F3,    UNIMAP_F4,    UNIMAP_F5    }, /* 38-3F */
    { UNIMAP_F6,    UNIMAP_F7,    UNIMAP_F8,    UNIMAP_F9,    UNIMAP_F10,   UNIMAP_NLCK,  UNIMAP_SLCK,  UNIMAP_P7    }, /* 40-47 */
    { UNIMAP_P8,    UNIMAP_P9,    UNIMAP_PMNS,  UNIMAP_P4,    UNIMAP_P5,    UNIMAP_P6,    UNIMAP_PPLS,  UNIMAP_P1    }, /* 48-4F */
    { UNIMAP_P2,    UNIMAP_P3,    UNIMAP_P0,    UNIMAP_PDOT,  UNIMAP_PSCR,  UNIMAP_PAUSE, UNIMAP_NUHS,  UNIMAP_F11   }, /* 50-57 */
    { UNIMAP_F12,   UNIMAP_PEQL,  UNIMAP_LGUI,  UNIMAP_RGUI,  UNIMAP_APP,   UNIMAP_NO,    UNIMAP_NO,    UNIMAP_NO    }, /* 58-5F */
    { UNIMAP_UP,    UNIMAP_LEFT,  UNIMAP_DOWN,  UNIMAP_RIGHT, UNIMAP_F13,   UNIMAP_F14,   UNIMAP_F15,   UNIMAP_F16   }, /* 60-67 */
    { UNIMAP_F17,   UNIMAP_F18,   UNIMAP_F19,   UNIMAP_F20,   UNIMAP_F21,   UNIMAP_F22,   UNIMAP_F23,   UNIMAP_PENT  }, /* 68-6F */
    { UNIMAP_KANA,  UNIMAP_INSERT,UNIMAP_DELETE,UNIMAP_RO,    UNIMAP_HOME,  UNIMAP_END,   UNIMAP_F24,   UNIMAP_PGUP  }, /* 70-77 */
    { UNIMAP_PGDN,  UNIMAP_HENK,  UNIMAP_RCTL,  UNIMAP_MHEN,  UNIMAP_RALT,  UNIMAP_JYEN,  UNIMAP_PCMM,  UNIMAP_PSLS  }, /* 78-7F */
};

I'd really appreciate it if you could just give me a quick overview of what the purpose of these arrays is. Thank you !
   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1964 on: Tue, 24 September 2019, 02:00:49 »
This 'UNIMAP_XT' macro definition would be just useful if your keyboard is IBM XT keyboard because the definition corresponds to physical layout of the keyboard.

https://github.com/tmk/tmk_keyboard/blob/master/converter/xt_usb/unimap_common.h#L45-L84

But it is not necessarily required, you can use universal layout macro 'UNIMAP' as you can see in unimap.c. In fact the 'UNIMAP_XT' is not used anywhere and not useful for XT keyboard that has more keys than IBM XT.

https://github.com/tmk/tmk_keyboard/blob/master/converter/xt_usb/unimap.c#L48-L75

Universal 128-key layout 'UNIMAP()' macro is defined in tmk_core/common/unimap.h and you can use the layout for all of keyobards and converters with unimap.

https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/common/unimap.h#L18-L74

Array  'unimap_trans' defines how key of keyboard matrix is mapped to key of the universal 128-key layout. For example, 'A'(0x1E) key of XT keyboard which is lcoated in [3][6] of matrix is mapped to 'A' key of unimap(UNIMAP_A).

https://github.com/tmk/tmk_keyboard/blob/master/converter/xt_usb/unimap_common.h#L90

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1965 on: Tue, 24 September 2019, 09:47:55 »
Okay, thanks for the explanation Hasu. I've started to figure it out a bit on my own but this information is still very useful
   

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1966 on: Sat, 19 October 2019, 17:55:24 »
Hi Hasu,
I've encountered a new problem that, despite my best efforts, I can't seem to solve.

I have an SSK I'm trying to convert to USB and I've successfully gotten it to work with the tmk terminal-to-usb converter. Unfortunately, this particular converter seems kind of old, and I can't get macros or action functions or layers to work the way I need them to. Hoping you can look at my keymap and identify any sources of error.

For example, I've assigned FN0 to ACTION_LAYER_MOMENTARY(1), which should switch to layer 1, but it doesn't seem to actually do anything. I don't know why.

Anyway, hope you can help. Let me know if you'd like me to clarify anything.

Code: [Select]
/*
Copyright 2012 Jun Wako <wakojun@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>
#include <stdbool.h>
#include "keycode.h"
#include "print.h"
#include "debug.h"
#include "util.h"
#include "keymap.h"
#include "report.h"
#include "print.h"

#include "action.h"
#include "action_macro.h"
#include "action_util.h"



/*
 * IBM Terminal keyboard 6110345(122keys)/1392595(102keys)
 * http://geekhack.org/showthread.php?10737-What-Can-I-Do-With-a-Terminal-Model-M
 * http://www.seasip.info/VintagePC/ibm_1391406.html
 *
 * Keymap array:
 *     8 bytes
 *   +---------+
 *  0|         |
 *  :|         | 0x00-0x87
 *  ;|         |
 * 17|         |
 *   +---------+
 */
/*
 * IBM Terminal keyboard 1399625, 101-key
 */

#define KEYMAP_SSK( \
    K08,    K07,K0F,K17,K1F,K27,K2F,K37,K3F,K47,K4F,K56,K5E,  K57,K5F,K62, \
                                                                          \
    K0E,K16,K1E,K26,K25,K2E,K36,K3D,K3E,K46,K45,K4E,K55,K66,  K67,K6E,K6F, \
    K0D,K15,K1D,K24,K2D,K2C,K35,K3C,K43,K44,K4D,K54,K5B,K5C,  K64,K65,K6D, \
    K14,K1C,K1B,K23,K2B,K34,K33,K3B,K42,K4B,K4C,K52,    K5A, \
    K12,    K1A,K22,K21,K2A,K32,K31,K3A,K41,K49,K4A,    K59,      K63, \
    K11,    K19,            K29,                K39,    K58,  K61,K60,K6A \
) { \
    { KC_NO,    KC_NO   , KC_NO,    KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_##K07 }, \
    { KC_##K08, KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_##K0D, KC_##K0E, KC_##K0F }, \
    { KC_NO   , KC_##K11, KC_##K12, KC_NO   , KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
    { KC_NO   , KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \
    { KC_NO   , KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
    { KC_NO   , KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
    { KC_NO   , KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
    { KC_NO   , KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_##K3F }, \
    { KC_NO   , KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47 }, \
    { KC_NO   , KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F }, \
    { KC_NO   , KC_NO   , KC_##K52, KC_NO   , KC_##K54, KC_##K55, KC_##K56, KC_##K57 }, \
    { KC_##K58, KC_##K59, KC_##K5A, KC_##K5B, KC_##K5C, KC_NO   , KC_##K5E, KC_##K5F }, \
    { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_##K67 }, \
    { KC_NO   , KC_NO, KC_##K6A, KC_NO, KC_NO, KC_##K6D, KC_##K6E, KC_##K6F }, \
    { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
    { KC_NO   , KC_NO, KC_NO, KC_NO   , KC_NO, KC_NO, KC_NO, KC_NO    }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_NO   , KC_NO, KC_NO,    KC_NO,    KC_NO,   }, \
}


const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* 101-key keymaps
 */
    /* 0: default
     * ,---.   ,---------------. ,---------------. ,---------------. ,-----------.
     * |Esc|   |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|
     * `---'   `---------------' `---------------' `---------------' `-----------'
     * ,-----------------------------------------------------------. ,-----------. ,---------------.
     * |  `|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|Backspa| |Ins|Hom|PgU| |NmL|  /|  *|  -|
     * |-----------------------------------------------------------| |-----------| |---------------|
     * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|    \| |Del|End|PgD| |  7|  8|  9|   |
     * |-----------------------------------------------------------| `-----------' |-----------|  +|
     * |CapsLo|  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|Return  |               |  4|  5|  6|   |
     * |-----------------------------------------------------------|     ,---.     |---------------|
     * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  ,|  /|Shift     |     |Up |     |  1|  2|  3|   |
     * |-----------------------------------------------------------| ,-----------. |-----------|Ent|
     * |Ctrl|    |Alt |          Space              |Alt |    |Ctrl| |Lef|Dow|Rig| |      0|  .|   |
     * `----'    `---------------------------------------'    `----' `-----------' `---------------'
     */

    // Default
    KEYMAP_SSK(
     ESC,       F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9, F10, F11, F12,     PSCR,SLCK, BRK,

     GRV,   1,   2,   3,   4,   5,   6,   7,   8,   9,   0,MINS, EQL,BSPC,      INS,HOME,PGUP,
     TAB,   Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,LBRC,RBRC,BSLS,      DEL, END,PGDN,
    CAPS,   A,   S,   D,   F,   G,   H,   J,   K,   L,SCLN,QUOT,      ENT,                   
    LSFT,        Z,   X,   C,   V,   B,   N,   M,COMM, DOT,SLSH,     RSFT,            UP,     
    LCTL,     LALT,                SPC,                    FN0,     RCTL,     LEFT,DOWN,RGHT
    ),

    // Momentary
    KEYMAP_SSK(
     ESC,       F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9, F10, F11, F12,     FN1,FN2,FN3,

     GRV,   1,   2,   3,   4,   5,   6,   7,   8,   9,   0,MINS, EQL,BSPC,      INS,HOME,PGUP,
     TAB,   Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,LBRC,RBRC,BSLS,      DEL, END,PGDN,
    CAPS,   A,   S,   D,   F,   G,   H,   J,   K,   L,SCLN,QUOT,      ENT,                   
    LSFT,        Z,   X,   C,   V,   B,   N,   M,COMM, DOT,SLSH,     RSFT,            UP,     
    LCTL,     LALT,                A,                    TRNS,     RCTL,     LEFT,DOWN,RGHT
    ),   

};

/* id for user defined functions */
enum function_id {
    PROMICRO_RESET,
    PROMICRO_PROGRAM,   
    TEST,
};

const action_t PROGMEM fn_actions[] = {   
    [0] = ACTION_LAYER_MOMENTARY(1),   
    [1] = ACTION_FUNCTION(PROMICRO_RESET),
    [2] = ACTION_FUNCTION_TAP(PROMICRO_PROGRAM),
    [3] = ACTION_FUNCTION_TAP(TEST),

};

const uint8_t PROGMEM fn_layer[] = {
};

const uint8_t PROGMEM fn_keycode[] = {
};



void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
    switch(id) {
        case PROMICRO_RESET:
            promicro_bootloader_jmp(false);
            break;
        case PROMICRO_PROGRAM:
            promicro_bootloader_jmp(true);
            break;
        case TEST:
          return (record->event.pressed ?
              MACRO( T(T),T(E),T(S),T(T), END ) :
              MACRO_NONE);
        default:
            break;
    }
}


   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1967 on: Sat, 19 October 2019, 18:33:38 »
You will have to start with its keymap.c then, change and test it gradually. Don't change much at once.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1968 on: Sat, 19 October 2019, 18:41:43 »

Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1969 on: Sun, 20 October 2019, 01:29:29 »
Okay - so I'm not sure if the action stuff works with legacy keymap. Is there some way I can execute the pro micro reset function with legacy keymap?
   

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1970 on: Tue, 22 October 2019, 06:34:49 »
You cannot use user defined action with the legacy keymap.
Keycode KC_BTLD may work for the purpose.

Okay - so I'm not sure if the action stuff works with legacy keymap. Is there some way I can execute the pro micro reset function with legacy keymap?


Offline PancakeMSTR

  • Posts: 491
Re: TMK keyboard firmware
« Reply #1971 on: Tue, 22 October 2019, 11:35:57 »
You cannot use user defined action with the legacy keymap.
Keycode KC_BTLD may work for the purpose.

Okay - so I'm not sure if the action stuff works with legacy keymap. Is there some way I can execute the pro micro reset function with legacy keymap?

Saved my life again. Thanks Hasu, worked perfectly.
   

Offline Zustiur

  • Posts: 235
Re: TMK keyboard firmware
« Reply #1972 on: Wed, 25 March 2020, 07:36:12 »
For some reason I'm only getting row0 and row 1 to work and my one LED only glows very dimly, which I suspect means it's being strobed instead of just being on. I'm certain that it's a firmware issue because I can't find any electrical errors and even tried shorting a wire between the relevant pins on the chip to trigger key presses from other rows. Can someone help me spot the error please? I'm sure I'm missing something simple here. I just can't see it.
My pins are as follows:
Row0=F0
Row1=F1
Row2=F4
Row3=F5
Row4=F6
Row5=F7

Col0=D0
Col1=D1
Col2=D2
Col3=D3
Col4=D5
Col5=D4
Col6=D7

LED = B6

Config.h
Code: [Select]
#ifndef CONFIG_H
#define CONFIG_H


/* USB Device descriptor parameter */
#define VENDOR_ID       0xFEED
#define PRODUCT_ID      0x6060
#define DEVICE_VER      0x0001
#define MANUFACTURER    geekhack
#define PRODUCT         OneHandRevA4
#define DESCRIPTION     t.m.k. keyboard firmware for OneHandRevA4

/* key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 7

/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST

/* Set 0 if debouncing isn't needed */
#define DEBOUNCE    5

/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE

/* key combination for command */
#define IS_COMMAND() ( \
    keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
)



/*
 * Feature disable options
 *  These options are also useful to firmware size reduction.
 */

/* disable debug print */
//#define NO_DEBUG

/* disable print */
//#define NO_PRINT

/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION

#endif

LED.c
Code: [Select]
#include <avr/io.h>
#include "stdint.h"
#include "led.h"

void led_set(uint8_t usb_led)
{
    if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
        // output low
        DDRB &= ~(1<<6);
PORTB |= (1<<6); //Switch LED On


    } else {
        // Hi-Z
        DDRB |= (1<<6);
        PORTB &= ~(1<<6); //Switch LED Off
    }
}

Matrix.c
Code: [Select]
#include <stdint.h>
#include <stdbool.h>
#include <avr/io.h>
#include <util/delay.h>
#include "print.h"
#include "debug.h"
#include "util.h"
#include "matrix.h"


#ifndef DEBOUNCE
#   define DEBOUNCE 5
#endif
static uint8_t debouncing = DEBOUNCE;

/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

static matrix_row_t read_cols(void);
static void init_cols(void);
static void unselect_rows(void);
static void select_row(uint8_t row);


inline
uint8_t matrix_rows(void)
{
    return MATRIX_ROWS;
}

inline
uint8_t matrix_cols(void)
{
    return MATRIX_COLS;
}

void matrix_init(void)
{
    // initialize row and col
    unselect_rows();
    init_cols();

    // initialize matrix state: all keys off
    for (uint8_t i=0; i < MATRIX_ROWS; i++) {
        matrix[i] = 0;
        matrix_debouncing[i] = 0;
    }
}

uint8_t matrix_scan(void)
{
    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        select_row(i);
        _delay_us(30);  // without this wait read unstable value.
        matrix_row_t cols = read_cols();
        if (matrix_debouncing[i] != cols) {
            matrix_debouncing[i] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    return 1;
}

bool matrix_is_modified(void)
{
    if (debouncing) return false;
    return true;
}

inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
    return (matrix[row] & ((matrix_row_t)1<<col));
}

inline
matrix_row_t matrix_get_row(uint8_t row)
{
    return matrix[row];
}

void matrix_print(void)
{
    print("\nr/c 0123456789ABCDEF\n");
    for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
        phex(row); print(": ");
        pbin_reverse16(matrix_get_row(row));
        print("\n");
    }
}

uint8_t matrix_key_count(void)
{
    uint8_t count = 0;
    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        count += bitpop16(matrix[i]);
    }
    return count;
}

/* Column pin configuration
 * col: 0   1   2   3   4   5   6
 * pin: D0  D1  D2  D3  D5  D4  D7
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRD  &= ~(1<<7 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0); //F7, F4, F1, F0 and so on...
PORTD |=  (1<<7 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
}

static matrix_row_t read_cols(void)
{
    return (PIND&(1<<0) ? 0 : (1<<0)) | //Pin D0 = Col0
           (PIND&(1<<1) ? 0 : (1<<1)) | //Pin D1 = Col 1 and so on.
           (PIND&(1<<2) ? 0 : (1<<2)) |
           (PIND&(1<<3) ? 0 : (1<<3)) |
           (PIND&(1<<5) ? 0 : (1<<4)) |
           (PIND&(1<<4) ? 0 : (1<<5)) |
   (PIND&(1<<7) ? 0 : (1<<6));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* Row pin configuration
 * row: 0   1   2   3   4   5
 * pin: F0  F1  F4  F5  F6  F7
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
//These are unselected with a binary code, in reverse column order: 76543210
//          76543210
DDRF  &= ~0b11110011;
PORTF &= ~0b11110011;

}


static void select_row(uint8_t row)
{
    // Output low(DDR:1, PORT:0) to select
    switch (row) {
        case 0: //Row 0 = Pin F0
            DDRF  |= (1<<0);
            PORTF &= ~(1<<0);
            break;
        case 1: //Row 1 = Pin F1... and so on
            DDRF  |= (1<<1);
            PORTF &= ~(1<<1);
            break;
        case 2:
            DDRF  |= (1<<4);
            PORTF &= ~(1<<4);
            break;
        case 3:
            DDRF  |= (1<<5);
            PORTF &= ~(1<<5);
            break;
        case 4:
            DDRF  |= (1<<6);
            PORTF &= ~(1<<6);
            break;
case 5:
DDRF  |= (1<<7);
            PORTF &= ~(1<<7);
            break;
    }
}


Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1973 on: Wed, 25 March 2020, 08:43:23 »
By default part of Port F(4-7 probably) is reserved for JTAG or something in some AVR, if I can remember correctly. You have to fiddle some register to use the Port F  pins as general IO instead of JTAG debug.
Check data sheet or use google. This is kind of FAQ you can find info easily.

Offline Zustiur

  • Posts: 235
Re: TMK keyboard firmware
« Reply #1974 on: Thu, 26 March 2020, 03:21:34 »
Ahhh of course, that will be it. Thanks Hasu. I was tricked by it being whole rows and convinced myself it was an error in my code. I forgot about JTAG! I knew about that weeks ago but forgot while I waited for my boards to arrive from JLCPCB.
You're a legend.
I don't know where I'd be without your awesome firmware.
« Last Edit: Thu, 26 March 2020, 03:24:09 by Zustiur »

Offline Crossharu

  • Posts: 1
Re: TMK keyboard firmware
« Reply #1975 on: Wed, 15 April 2020, 02:34:08 »
Hi all -

I’ve been having some trouble with my custom keyboard that uses TMK firmware and have come to my wits end so I’m hoping one of you may be able to help!

I initially built (hand soldered) the board a few years ago and after a bit of messing around with the code it worked perfectly for years. Then one summer I noticed that it started malfunctioning in a weird way - when pressing any key on a particular column, either some or all of the other keys in that column would fire. I couldn’t solve it so I put the keyboard aside for a few months. The next winter I came back to it and it was working fine again but then when the summer came around I had further problems (making me think it was heat related) so I had a play around with denounce and got it to catch any additional key presses that were triggered.

Fast forward to earlier this week and the problems start up again during a patch of particularly warm weather. Once the weather got a bit cooler again it seemed to resolve itself. I thought about buying a heat sink for the teensy controller but then decided first to flash a new version of TMK to it. I did that yesterday and unfortunately that seemed to break my LGUI key but everything else works fine. I tried various fixes but in the end reverted to my old firmware backup. Now the LGUI key is broken in that firmware as well when it worked perfectly previously! I’ve checked the soldering and it’s all good and all other keys are working.

I’d be really really grateful if anyone has any idea on either of these issues. I’m starting to think that I might need to get a new controller and solder it in...

Thanks!

Offline ississ

  • Posts: 3
  • Location: Finland
Re: TMK keyboard firmware
« Reply #1976 on: Wed, 15 April 2020, 15:04:32 »
Hi

I just completed my third keyboard build with tmk firmware.
This last one is a keyboard-mouse combo for my engraver (to save table space and make something useful from old parts lying around).
I decided to add a middle button to the touchpad which can normally handle only 2 buttons and connected it to the keyboard matrix.

The problem is, if I press the middle button and move the mouse the firmware sends middle button release. The original mouse buttons stay pressed until released independent of mouse movement.
Middle button works as it should as long as the mouse is not moved.

Have anyone tried this kind of setup before (ps/2 mouse with added buttons) ?
Any other ideas ?

Firmware runs on A-Star 32U4 mini SV
Touchpad controller is Synaptics T1006 connected to controller with INT version (for some reason uart version didn't work).
Keyboard matrix is from an old laptop.

239951-0

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1977 on: Wed, 15 April 2020, 17:33:39 »
Scroll with middle button seems to be enabled. Check this.

https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/protocol/ps2_mouse.h#L46

Offline ississ

  • Posts: 3
  • Location: Finland
Re: TMK keyboard firmware
« Reply #1978 on: Thu, 16 April 2020, 13:35:21 »
Yes, that seems to be set on my header file too.

Is this setting related to scrolling text terminal/web browser by clicking middle button and then moving the mouse ?
Should I unset it to be able to keep the middle button pressed independent of mouse movement ?

What I'm after is that the middle button stays pressed as long as the physical button is pressed. This is required for the programs, for example Autodesk fusion 360 the model is rotated by pressing the middle button and then moving the mouse. Same for Repetier-Host (middle = pan) and Linuxcnc Axis interface.

I checked with xinput and the kbd/mouse sends a middle button release as soon as the mouse is moved with the button still pressed.
Same functionality in Linux and Windows (10), functionality is same on both environments.

Here is a simple event viewer output, #184 & #185 show immediate mouseup and move after that for middle button. The athers work ok and the butt6on stays pressed while moving.240045-0

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1979 on: Thu, 16 April 2020, 16:12:41 »
Yes and yes.

Offline ississ

  • Posts: 3
  • Location: Finland
Re: TMK keyboard firmware
« Reply #1980 on: Thu, 16 April 2020, 17:11:51 »
Yes and yes.

Thanks for the quick answer.
I tested a couple of configurations and found out that disabling PS2_MOUSE_SCROLL_BTN_MASK and setting MOUSEKEY_ENABLE = yes results in same behaviour, button is released when moved. Without mouse keys the middle button is not sent at all.

So I ended up disabling both mouse keys and PS2_MOUSE_SCROLL_BTN_MASK and tweaking a bit in ps2_mouse.c and keyboard.c so that the middle mouse button state is saved while checking the matrix and added to every mouse packet read from the touchpad.

This is not-so-nice way but now it works, I'll live with that.

Offline marcosalcocer

  • Posts: 4
  • Location: Mexico City
Re: TMK keyboard firmware
« Reply #1981 on: Tue, 09 June 2020, 07:05:49 »
Hi, I am having a hard time programming the Spanish characters " ñ " and " ´ " through the tmk-kbd editor. Overall I have placed all the other keys where I want them. Is there a way to do this through the editor?

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: TMK keyboard firmware
« Reply #1982 on: Tue, 09 June 2020, 07:19:47 »
Are you using a Spanish layout setting on your operating system?  If so you need to pretend you have an American keyboard and use the names as seen on that and they will output correctly.
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1983 on: Tue, 09 June 2020, 08:09:32 »
Hi, I am having a hard time programming the Spanish characters " ñ " and " ´ " through the tmk-kbd editor. Overall I have placed all the other keys where I want them. Is there a way to do this through the editor?

What is your OS and keyobard layout on your OS?
How do you usually get the charactors?

Offline marcosalcocer

  • Posts: 4
  • Location: Mexico City
Re: TMK keyboard firmware
« Reply #1984 on: Wed, 10 June 2020, 19:08:19 »
I'm running MacOS... I am used to programming the output on the OS but I wanted to use the controller to not have to do that every time I switch my computer.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1985 on: Wed, 10 June 2020, 19:35:57 »
I'm running MacOS... I am used to programming the output on the OS but I wanted to use the controller to not have to do that every time I switch my computer.

I don't have Mac and don't know Spanish at all.
But I think you can register 'ñ' with a key next to 'L'(regardless of its marking, ';' on US layout) if you are using default keymap. Your keyboard should work as normal Spanish keyboard with default keymap.




Offline marcosalcocer

  • Posts: 4
  • Location: Mexico City
Re: TMK keyboard firmware
« Reply #1986 on: Thu, 11 June 2020, 08:08:28 »
Yes this is how I normally use it but this only happens when the output is set in the computer OS not directly from the board. I want  native layout that has the ñ next to the L, and the ; to be moved elsewhere. The problems is that when I move the ; key my ñ appears where ever I moved the ;

Offline Zustiur

  • Posts: 235
Re: TMK keyboard firmware
« Reply #1987 on: Fri, 12 June 2020, 08:13:38 »
I'm not sure if this is the appropriate thread for my current problem, but I don't know where else to post it right now.

I've just received 5 boards from JLCPCB and have soldered on the USB and SPI plugs on two of the 5 so that I can program and test them. For some reason, they are not being detected by USB, but only after I program them. This has me very puzzled. The first one I didn't test before programming. The second I did.

Specifically:
Board 1 steps:
Soldered on the USB and 6 pin header.
Connected SPI programmer
Attempted to disable JTAG fuse bit. AVRDude stated that it detected a change and would I like to roll back. I tried saying No, but this just sat there doing nothing until I hit Ctrl-C.
Programmed the hex file.
Disabled the JTAG fuse bit- no problem this time. (I've noticed this before, I don't seem to be able to disable JTAG until the chip has a hex on it?)
Disconnected SPI programmer, plugged in USB. Windows does not detect it.

Board 2 steps:
Soldered on the USB and 6 pin header.
Tested USB connectivity multiple times. Confirmed in Event Viewer that it detected and installed the driver for Atmel usb dfu.
Removed from USB, Connected SPI programmer
Programmed the hex file.
Disconnected SPI programmer, plugged in USB. Windows does not detect it.
Connected SPI programmer again, programmed with a different hex which I know is valid (albeit not the right columns etc for this keyboard).
Disconnected SPI programmer, plugged in USB. Windows does not detect it.

Am I missing something obvious again? Does this sound like a firmware error?



Nevermind. I WAS missing something so extremely obvious, I'm surprised the error message didn't jump out at me more.
I hadn't actually gone to the folder that my .hex files were in, so when I programmed the ISP it got erased and then nothing got programmed.
« Last Edit: Fri, 12 June 2020, 09:16:47 by Zustiur »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1988 on: Fri, 12 June 2020, 08:38:44 »
Yes this is how I normally use it but this only happens when the output is set in the computer OS not directly from the board. I want  native layout that has the ñ next to the L, and the ; to be moved elsewhere. The problems is that when I move the ; key my ñ appears where ever I moved the ;



I'm assuming you are using 'Spanish' layout on your computer and you have to press shift key and ',' key to get character ';' on computer. Is that right.

If so you can use 'ACTION_MODS_KEY' to send Shift and ',' key at same time. See a key next to 'L' in this Editor.

https://bit.ly/3dVLSTp

You can edit action like that with 'Code Edit' tab. Try it.

Offline marcosalcocer

  • Posts: 4
  • Location: Mexico City
Re: TMK keyboard firmware
« Reply #1989 on: Fri, 12 June 2020, 08:46:48 »
Perfect! This is the sort of workaround I will be very comfortable with. I'll check it out and get back if there are any issues.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1990 on: Fri, 12 June 2020, 08:54:33 »
I think you need help for your hardware first  before firmware?
You may need to create new thread for your project anyway.

Posting source code, photo of the pcb, schematics and microcontroller model number in your thread would be useful to get help. Also AVRdude message output may be helpful.
Provide information as much as possible there.


I'm not sure if this is the appropriate thread for my current problem, but I don't know where else to post it right now.

I've just received 5 boards from JLCPCB and have soldered on the USB and SPI plugs on two of the 5 so that I can program and test them. For some reason, they are not being detected by USB, but only after I program them. This has me very puzzled. The first one I didn't test before programming. The second I did.

Specifically:
Board 1 steps:
Soldered on the USB and 6 pin header.
Connected SPI programmer
Attempted to disable JTAG fuse bit. AVRDude stated that it detected a change and would I like to roll back. I tried saying No, but this just sat there doing nothing until I hit Ctrl-C.
Programmed the hex file.
Disabled the JTAG fuse bit- no problem this time. (I've noticed this before, I don't seem to be able to disable JTAG until the chip has a hex on it?)
Disconnected SPI programmer, plugged in USB. Windows does not detect it.

Board 2 steps:
Soldered on the USB and 6 pin header.
Tested USB connectivity multiple times. Confirmed in Event Viewer that it detected and installed the driver for Atmel usb dfu.
Removed from USB, Connected SPI programmer
Programmed the hex file.
Disconnected SPI programmer, plugged in USB. Windows does not detect it.
Connected SPI programmer again, programmed with a different hex which I know is valid (albeit not the right columns etc for this keyboard).
Disconnected SPI programmer, plugged in USB. Windows does not detect it.

Am I missing something obvious again? Does this sound like a firmware error?


Offline Zustiur

  • Posts: 235
Re: TMK keyboard firmware
« Reply #1991 on: Fri, 12 June 2020, 09:18:56 »
Thanks Hasu. I think I've worked on too many things today. My brain is fried. It was a really stupid mistake. I've edited my post above.

I've got most of the board working now. Think there may be an issue in my matrix file somewhere because my thumb keys aren't registering. I'll figure that out tomorrow though.

Offline Alectardy98

  • Posts: 17
  • Location: United States
  • Pre Dental
Re: TMK keyboard firmware
« Reply #1992 on: Mon, 04 January 2021, 21:37:23 »
Need some help with LED toggle on layer switching.

I want to use my layer one as a num lock, and indicate it though the num lock led. It seems to work but when I hit the Caps lock it turns off the num lock led but the keyboard stays in layer 1. How can I modify my code to make it work
Code: [Select]
bool my_led_status = 0;

hook_layer_change(uint32_t layer_state)
{

    if (layer_state & (1L<<1)) {
            // LED is off, so let's turn it on
            led_set(host_keyboard_leds() | (1<<USB_LED_NUM_LOCK));
            my_led_status = 1;
     } else {
            // LED is on, so let's turn it off
            led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));
            my_led_status = 0;
     }

}
« Last Edit: Mon, 04 January 2021, 21:39:15 by Alectardy98 »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1993 on: Mon, 04 January 2021, 22:46:59 »
You can change default lock indicator behaviour with:
Code: [Select]
void hook_keyboard_leds_change(uint8_t led_status);

Offline Alectardy98

  • Posts: 17
  • Location: United States
  • Pre Dental
Re: TMK keyboard firmware
« Reply #1994 on: Mon, 04 January 2021, 23:27:27 »
I am new to C and dont Realy know how I would apply that to do what I want

Offline Alectardy98

  • Posts: 17
  • Location: United States
  • Pre Dental
Re: TMK keyboard firmware
« Reply #1995 on: Mon, 04 January 2021, 23:28:10 »
could you link where i can find more info

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1996 on: Mon, 04 January 2021, 23:37:20 »
You can find the function here.
https://github.com/tmk/tmk_keyboard/blob/6271878a021fcf578b71e2b7e97cd43786efa7dd/tmk_core/common/hook.h#L82

And there is documentation about hook API here. But you will have read source codes to get more info somehow.
https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/doc/hook.md

Offline Alectardy98

  • Posts: 17
  • Location: United States
  • Pre Dental
Re: TMK keyboard firmware
« Reply #1997 on: Mon, 04 January 2021, 23:49:08 »
My code is working how I want it to, It is just the caps lock that is reseting the nun lock light, how can I disable that?



« Last Edit: Tue, 05 January 2021, 00:23:04 by Alectardy98 »

Offline Alectardy98

  • Posts: 17
  • Location: United States
  • Pre Dental
Re: TMK keyboard firmware
« Reply #1998 on: Tue, 05 January 2021, 12:32:42 »
I Think what I have to do is disassociate the Num Lock led from the AT scan, so the num lock would no longer trigger the light
I think when the caps lock key is pressed, it checks to see what toggles are set pc side and changes the LEDs accordingly, which turns off my fake num lock light

Offline Alectardy98

  • Posts: 17
  • Location: United States
  • Pre Dental
Re: TMK keyboard firmware
« Reply #1999 on: Tue, 05 January 2021, 15:29:25 »
This almost works, but the caps lock will triger the num lock and the caps lock led on first press and only the first press, otherwise, it works as it should

Code: [Select]
bool my_led_status = 1;

hook_layer_change(uint32_t layer_state)
{
    if (my_led_status);

        if (layer_state & (1L<<1)) {
            // LED is off, so let's turn it on
            led_set(host_keyboard_leds() | (1<<USB_LED_NUM_LOCK));
            my_led_status = 1;
        } else {
            // LED is on, so let's turn it off
            led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));
            my_led_status = 0;
           
     }
   
}

hook_keyboard_leds_change(uint8_t led_status)
{
    if (my_led_status)
            {
                // LED is on, so let's turn it off
                led_set(host_keyboard_leds() | (1<<USB_LED_NUM_LOCK));
            }
            else
            {
                // LED is off, so let's turn it on
                led_set(host_keyboard_leds() & ~(1<<USB_LED_NUM_LOCK));            }
        }