geekhack

geekhack Projects => Making Stuff Together! => DIY Discussions ARCHIVE => Topic started by: Pyrolistical on Thu, 12 January 2012, 15:23:39

Title: Teensy as Keyboard Controller
Post by: Pyrolistical on Thu, 12 January 2012, 15:23:39
I've been looking at https://github.com/tmk/tmk_keyboard and trying to understand how to use it as a keyboard controller.

Here is just a collection of my learnings and thoughts.

As of https://github.com/tmk/tmk_keyboard/commit/579991b927483da884b2f22d43e91bb8550cd534 the readme gives tmk_keyboard/macway as the default example on how to use hasu's code.

The macway project uses a 9x8 matrix, which is unsuitable for most keyboard projects.  Also the code assumes the isolation diodes are on the rows (which happens to be backwards to http://www.dribin.org/dave/keyboard/one_html/).

The macway project needs to be modified to support full sized layouts like the common 104 keys Windows layout.

See the fourway project for a more flexible implementation of matrix.c: https://github.com/Pyrolistical/tmk_keyboard/tree/master/fourway

On the Teensy 2.0 there are 22 easily accessible IO pins:
B0 B1 B2 B3 B4 B5 B6 B7
C6 C7
D0 D1 D2 D3 D6* D7
F0 F1 F4 F5 F6 F7

* D6 is also attached to an LED, so if you use this port it will flicker as the state changes.

There are 3 extra pins which are harder to reach, but are fully usable:
D4 D5
E6

Here is the matrix sizes you need in order to achieve the desired number of keys for a NKRO keyboard
[table=width: 500, class: grid]
[tr]
   [td]Rows[/td]
   [td]Columns[/td]
   [td]Number of Keys[/td]
[/tr]
[tr]
   [td]1[/td]
   [td]24[/td]
   [td]24[/td]
[/tr]
[tr]
   [td]2[/td]
   [td]23[/td]
   [td]46[/td]
[/tr]
[tr]
   [td]3[/td]
   [td]22[/td]
   [td]66[/td]
[/tr]
[tr]
   [td]4[/td]
   [td]21[/td]
   [td]84[/td]
[/tr]
[tr]
   [td]5[/td]
   [td]20[/td]
   [td]100[/td]
[/tr]
[tr]
   [td]6[/td]
   [td]19[/td]
   [td]114[/td]
[/tr]
[tr]
   [td]7[/td]
   [td]18[/td]
   [td]126[/td]
[/tr]
[tr]
   [td]8[/td]
   [td]17[/td]
   [td]136[/td]
[/tr]
[tr]
   [td]9[/td]
   [td]16[/td]
   [td]144[/td]
[/tr]
[tr]
   [td]10[/td]
   [td]15[/td]
   [td]150[/td]
[/tr]
[tr]
   [td]11[/td]
   [td]14[/td]
   [td]154[/td]
[/tr]
[tr]
   [td]12[/td]
   [td]13[/td]
   [td]156[/td]
[/tr]
[tr]
   [td]13[/td]
   [td]12[/td]
   [td]156[/td]
[/tr]
[tr]
   [td]14[/td]
   [td]11[/td]
   [td]154[/td]
[/tr]
[tr]
   [td]15[/td]
   [td]10[/td]
   [td]150[/td]
[/tr]
[tr]
   [td]16[/td]
   [td]9[/td]
   [td]144[/td]
[/tr]
[tr]
   [td]17[/td]
   [td]8[/td]
   [td]136[/td]
[/tr]
[tr]
   [td]18[/td]
   [td]7[/td]
   [td]126[/td]
[/tr]
[tr]
   [td]19[/td]
   [td]6[/td]
   [td]114[/td]
[/tr]
[tr]
   [td]20[/td]
   [td]5[/td]
   [td]100[/td]
[/tr]
[tr]
   [td]21[/td]
   [td]4[/td]
   [td]84[/td]
[/tr]
[tr]
   [td]22[/td]
   [td]3[/td]
   [td]66[/td]
[/tr]
[tr]
   [td]23[/td]
   [td]2[/td]
   [td]46[/td]
[/tr]
[tr]
   [td]24[/td]
   [td]1[/td]
   [td]24[/td]
[/tr]
[/table]
Title: Teensy as Keyboard Controller
Post by: wcass on Mon, 16 January 2012, 00:20:41
i was planning to write a front end to Hasu's code, but couldn't figure out how pins were assigned. it is great that his code is open and that it has many great features, but there is not enough documentation on how to make it do what you want it to do.

if i had a clue how to program for the Atmel, i would make a front end like this:
 
  [FONT="]you could open up this file to edit any field. this would allow you to create macros (a HID code string) or to assign multiple keys to the same function. you could post these files for others to use.[/FONT]
Title: Teensy as Keyboard Controller
Post by: Pyrolistical on Mon, 16 January 2012, 00:53:27
You are on the ball.  When I first started to read Hasu's code my first thought was it was poorly designed for reuse.

My goal is to do a subset of what your have listed and hope that lays the framework for people to continue to build on top as they want more features.
Title: Teensy as Keyboard Controller
Post by: REVENGE on Mon, 16 January 2012, 02:02:12
matrix.c?
Title: Teensy as Keyboard Controller
Post by: Pyrolistical on Mon, 16 January 2012, 02:52:58
Here is what I want to be able to configure in 1 file and have a fixed matrix.c implementation.

Note the flow of the metal model from the user to the controller.

Code: [Select]
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    KEYMAP(
        ESC,    F1,    F2,   F3,   F4,    F5,    F6,    F7,   F8,    F9,     F10,    F11,    F12,     EJECT, \
        BTICK,  1,     2,    3,    4,     5,     6,     7,    8,     9,      0,      MINUS,  EQUAL,   BS, \
        TAB,    Q,     W,    E,    R,     T,     Y,     U,    I,     O,      P,      LSQR,   RSQR,    BSLASH}, \
        CAP,    A,     S,    D,    F,     G,     H,     J,    K,     L,      SEMI,   QUOTE,  ENTER, \
        LSHIFT, Z,     X,    C,    V,     B,     N,     M,    COMMA, PERIOD, FSLASH, RSHIFT, UP, \
        FUNC,   LCTRL, LALT, LCMD,        SPACE, SPACE,       RCMD,  RALT,   RCTRL,  LEFT,   DOWN,    RIGHT
    ),
};

#define KEYMAP( \
      R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, R0C12, R0C13, \
      R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, R1C12, R1C13, \
      R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, R2C12, R2C13, \
      R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11, R3C12, \
      R4C0, R4C1, R4C2, R4C3, R4C4, R4C5, R4C6, R4C7, R4C8, R4C9, R4C10, R4C11, R4C12, \
      R5C0, R5C1, R5C2, R5C3,       R5C5, R5C6,       R5C8, R5C9, R5C10, R5C11, R5C12, R5C13 }
) { \
    { R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7, R0C8, R0C9, R0C10, R0C11, R0C12, R0C13 }, \
    { R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7, R1C8, R1C9, R1C10, R1C11, R1C12, R1C13 }, \
    { R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, R2C12, R2C13 }, \
    { R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11, R3C12, NONE }, \
    { R4C0, R4C1, R4C2, R4C3, R4C4, R4C5, R4C6, R4C7, R4C8, R4C9, R4C10, R4C11, R4C12, NONE }, \
    { R5C0, R5C1, R5C2, R5C3, NONE, R5C5, R5C6, NONE, R5C8, R5C9, R5C10, R5C11, R5C12, R5C13 }
}

#define DIODE_DIRECTION ROW

static const uint8_t PROGMEM portmap[] = {
         /* GND---Vcc */
     R0, /* B0  T  F0 */ C0,
     R1, /* B1  E  F1 */ C1,
     R2, /* B2  E  F4 */ C2,
     R3, /* B3  N  F5 */ C3,
     R4, /* B7  S  F6 */ C4,
     R5, /* D0  Y  F7 */ C5,
    C13, /* D1     B6 */ C6,
    C12, /* D2  2  B5 */ C7,
    C11, /* D3  .  B4 */ C8,
    C10, /* C6  0  D7 */ C9,
     NC, /* C7-----D6 */ NC
}
Title: Teensy as Keyboard Controller
Post by: hasu on Mon, 16 January 2012, 08:05:02
subscribed. looking forward to seeing your code.
Title: Teensy as Keyboard Controller
Post by: Pyrolistical on Tue, 24 January 2012, 01:28:35
I finished the bare minimum implementation a flexible matrix.c.

Now the row/col mapping to the Teensy can be configured in config.h without any code changes to matrix.c

See here: https://github.com/Pyrolistical/tmk_keyboard/tree/master/fourway
Title: Teensy as Keyboard Controller
Post by: hasu on Tue, 24 January 2012, 02:56:46
Thanks for you codes. Nice work!
I just cloned your repository.
I'll look into them closely later.