Author Topic: TMK keyboard firmware  (Read 828179 times)

0 Members and 1 Guest are viewing this topic.

Offline e_l_tang

  • Posts: 260
Re: TMK keyboard firmware
« Reply #1400 on: Mon, 25 April 2016, 13:38:55 »
@goflo Could you post your pin configuration and your code, please?

Offline a-c

  • Posts: 196
  • Location: USA
Re: TMK keyboard firmware
« Reply #1401 on: Mon, 25 April 2016, 13:42:01 »
Got 7 rows and 19 columns, so I had to use the 1UL<<16 for responses of my last 3 columns.
Now I got the following problem....if I press a key from column 16 I get multiple key presses.
Mostly the next 2 keys to the right, one key gives me the next 3 keys to the right.

Code: [Select]
1UL<<16
1UL<<17
1UL<<18
1UL<<19

Offline goflo

  • Posts: 69
  • Location: Germany
Re: TMK keyboard firmware
« Reply #1402 on: Mon, 25 April 2016, 13:49:17 »
@Eric-T
No prob....just didn't want to post it all at once, maybe someone would have a clue just by the description of the problem.

matrix.c Part
Code: [Select]
/* Column pin configuration (left to right from behind)
 * col: 0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18
 * pin: F7  F6  F5  F4  F3  D0  F2  F1  F0  E6  E7  B0  B1  B7  B2  B3  B4  B5  B6 
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
    PORTF |=  (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
    DDRB  &= ~(1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
    PORTB |=  (1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
    DDRE  &= ~(1<<6 | 1<<7 );
    PORTE |=  (1<<6 | 1<<7 );
    DDRD  &= ~(1<<0);
    PORTD |=  (1<<0);
}


static matrix_row_t read_cols(void)
{
    return (PINB&(1<<6) ? 0 : (1<<0)) |
           (PINB&(1<<5) ? 0 : (1<<1)) |
           (PINB&(1<<4) ? 0 : (1<<2)) |
           (PINB&(1<<3) ? 0 : (1<<3)) |
           (PINB&(1<<2) ? 0 : (1<<4)) |
   (PINB&(1<<7) ? 0 : (1<<5)) |
           (PINB&(1<<1) ? 0 : (1<<6)) |
           (PINB&(1<<0) ? 0 : (1<<7)) |
           (PINE&(1<<7) ? 0 : (1<<8)) |
           (PINE&(1<<6) ? 0 : (1<<9)) |     
           (PINF&(1<<0) ? 0 : (1<<10)) |
           (PINF&(1<<1) ? 0 : (1<<11)) |
           (PINF&(1<<2) ? 0 : (1<<12)) |
           (PIND&(1<<0) ? 0 : (1<<13)) |
   (PINF&(1<<3) ? 0 : (1<<14)) |
           (PINF&(1<<4) ? 0 : (1<<15)) |
   (PINF&(1<<5) ? 0 : (1UL<<16)) |
   (PINF&(1<<6) ? 0 : (1UL<<17)) |
   (PINF&(1<<7) ? 0 : (1UL<<18));
}

/* Row pin configuration (up to down)
 * row: 0   1   2   3   4   5   6
 * pin: C7  C6  C5  C4  C3  C2  C1
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRC  &= ~(1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 |1<<1 );
    PORTC |=  (1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 |1<<1 );
}

static void select_row(uint8_t row)
{
    // Output low(DDR:1, PORT:0) to select
    switch (row) {
        case 0:
            DDRC  |= (1<<7);
            PORTC &= ~(1<<7);
            break;
        case 1:
            DDRC  |= (1<<6);
            PORTC &= ~(1<<6);
            break;
        case 2:
            DDRC  |= (1<<5);
            PORTC &= ~(1<<5);
            break;
        case 3:
            DDRC  |= (1<<4);
            PORTC &= ~(1<<4);
            break;
        case 4:
            DDRC  |= (1<<3);
            PORTC &= ~(1<<3);
            break;
        case 5:
            DDRC  |= (1<<2);
            PORTC &= ~(1<<2);
            break;
case 6:
            DDRC  |= (1<<1);
            PORTC &= ~(1<<1);
            break;
case 7:
            DDRC  |= (1<<0);
            PORTC &= ~(1<<0);
            break;
    }
}


keymap_common.h
Code: [Select]
#ifndef KEYMAP_COMMON_H
#define KEYMAP_COMMON_H

#include <stdint.h>
#include <stdbool.h>
#include <avr/pgmspace.h>
#include "keycode.h"
#include "action.h"
#include "action_macro.h"
#include "report.h"
#include "host.h"
#include "print.h"
#include "debug.h"
#include "keymap.h"


extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const uint16_t fn_actions[];


/* Maltron keymap definition macro
 * K2C, K31 and  K3C are extra keys for ISO
 */
#define KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, K0H, K0I, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, K1I, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, K2F, K2G, K2H, K2I, \
    K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, K3F, K3G, K3H, K3I, \
    K40, K41, K42, K43, K44, K45, K46, K47, K48,      K4A, K4B, K4C, K4D, K4E, K4F, K4G, K4H, K4I, \
         K51, K52, K53, K54,      K56, K57, K58,      K5A, K5B, K5C,      K5E, K5F, K5G, K5H,  \
                                    K68,      K6A \
) { \
    { KC_##K00, 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_##K0G, KC_##K0H, KC_##K0I }, \
    { 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_##K1G, KC_##K1H, KC_##K1I }, \
    { 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_##K2G, KC_##K2H, KC_##K2I }, \
    { 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_##K3G, KC_##K3H, KC_##K3I }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47, KC_##K48, KC_NO   , KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F, KC_##K4G, KC_##K4H, KC_##K4I }, \
    { KC_NO   , KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_NO   , KC_##K56, KC_##K57, KC_##K58, KC_NO   , KC_##K5A, KC_##K5B, KC_##K5C, KC_NO   , KC_##K5E, KC_##K5F, KC_##K5G, KC_##K5H, KC_NO    },  \
    { KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_##K68, KC_NO   , KC_##K6A, KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO   , KC_NO    }  \
}


#endif


keymap_maltron.c
Code: [Select]
#include "keymap_common.h"
// Maltron DE
const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* 0: qwerty */
    KEYMAP(
          F1,   F2,   F3,  F4,  F5,  F6,   ESC, NUMLOCK, KP_7,   KP_8,     KP_9,    KP_SLASH, PAUS,  F7,   F8,   F9,  F10,  F11,  F12,  \
           1,    2,    3,   4,   5,   6,  CAPS,     EQL, KP_4,   KP_5,     KP_6, KP_ASTERISK, VOLU,   7,    8,    9,    0, MINS,  EQL,  \
         TAB,    Q,    W,   E,   R,   T,  PSCR,    SLCK, KP_1,   KP_2,     KP_3,    KP_MINUS, VOLD,   Y,    U,    I,    O,    P, LBRC,  \
        LCTL,    A,    S,   D,   F,   G,  PAUS,     INS, KP_0, KP_DOT, KP_ENTER,     KP_PLUS, MUTE,   H,    J,    K,    L, SCLN, RSFT,  \
        LSFT,    Z,    X,   C,   V,   B,   DEL,    HOME,  END,             PGUP,        PGDN,  DEL,   N,    M, COMM,  DOT, SLSH, RSFT,  \
              RALT, LEFT,RGHT, FN0,       BSPC,     DEL, LALT,             RALT,         ENT,  SPC,       FN0,   UP, DOWN, NUBS, \
         LCTL,             RCTL ),
     Function layer left out.
};

- Ergodox Classic/Browns/Grifiti Rests  | - IBM Model M Blue Label |  - Poker II MX Blue | - Ergodox Classic/Blues/Grifiti Rests

Offline e_l_tang

  • Posts: 260
Re: TMK keyboard firmware
« Reply #1403 on: Mon, 25 April 2016, 15:10:40 »
You counted your columns backwards! The columns are counted left to right from the front.
« Last Edit: Mon, 25 April 2016, 15:17:02 by Eric-T »

Offline goflo

  • Posts: 69
  • Location: Germany
Re: TMK keyboard firmware
« Reply #1404 on: Mon, 25 April 2016, 15:35:51 »
That shouldn't be the problem as all other columns and rows are functional and printing the right characters that they are meant to print.
I just turned that around in the allocation further down.

It is just one column that doesn't like me  :))
Btw: The layout isn't ready for use yet, just if you are wondering ;) Some keys are just mapped with senseless stuff  ;D
« Last Edit: Mon, 25 April 2016, 15:38:37 by goflo »
- Ergodox Classic/Browns/Grifiti Rests  | - IBM Model M Blue Label |  - Poker II MX Blue | - Ergodox Classic/Blues/Grifiti Rests

Offline e_l_tang

  • Posts: 260
Re: TMK keyboard firmware
« Reply #1405 on: Mon, 25 April 2016, 16:12:56 »
How are you testing your keyboard? I'd be surprised if each of its keys wasn't doing what the same key on the other side of it is supposed to do.

Offline a-c

  • Posts: 196
  • Location: USA
Re: TMK keyboard firmware
« Reply #1406 on: Mon, 25 April 2016, 16:30:26 »
Use 1UL for all of the columns. You are mixing different types.

Offline e_l_tang

  • Posts: 260
Re: TMK keyboard firmware
« Reply #1407 on: Mon, 25 April 2016, 18:24:30 »
@a-c I don't think that's the problem.

@goflo Did you change the definitions of MATRIX_ROWS and MATRIX_COLS in your config.h file? If you didn't, matrix_row_t, which is the return type of the function that's giving you trouble, might not be wide enough.

Offline goflo

  • Posts: 69
  • Location: Germany
Re: TMK keyboard firmware
« Reply #1408 on: Tue, 26 April 2016, 11:38:21 »
a-c was right. After using 1UL at all columns, not just the ones above 15, everything works fine  :thumb:
I just used it for 16 upwards and that seemed to be the problem.

Thanks alot.
My third tmk keyboard is officially up and running  :cool:
- Ergodox Classic/Browns/Grifiti Rests  | - IBM Model M Blue Label |  - Poker II MX Blue | - Ergodox Classic/Blues/Grifiti Rests

Offline e_l_tang

  • Posts: 260
Re: TMK keyboard firmware
« Reply #1409 on: Tue, 26 April 2016, 12:02:49 »
Interesting.

Offline vivalarevolución

  • Posts: 2146
  • Location: Naptown, Indiana, USA
  • Keep it real b/c any other way is too stressful
Re: TMK keyboard firmware
« Reply #1410 on: Wed, 27 April 2016, 20:29:00 »
Potentially dumb/repetitive question here.  Is it possible to upload the keymap from a keyboard to see what layout is on there?  I accidentally deleted my keymap file, and I had some fancy layers on there that I don't remember.
Wish I had some gif or quote for this space, but I got nothing

Offline e_l_tang

  • Posts: 260
Re: TMK keyboard firmware
« Reply #1411 on: Wed, 27 April 2016, 21:18:32 »
@vivalarevolución Are you using git in your tmk_keyboard folder? If so, you might be be able to recover your keymap file.

Offline vivalarevolución

  • Posts: 2146
  • Location: Naptown, Indiana, USA
  • Keep it real b/c any other way is too stressful
Re: TMK keyboard firmware
« Reply #1412 on: Thu, 28 April 2016, 19:44:49 »
@vivalarevolución Are you using git in your tmk_keyboard folder? If so, you might be be able to recover your keymap file.

I don't know.  I'm not sure how to figure that out.
Wish I had some gif or quote for this space, but I got nothing

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1413 on: Fri, 29 April 2016, 00:43:02 »
Potentially dumb/repetitive question here.  Is it possible to upload the keymap from a keyboard to see what layout is on there?  I accidentally deleted my keymap file, and I had some fancy layers on there that I don't remember.

TMK doens't have a feature like that.

Offline goflo

  • Posts: 69
  • Location: Germany
Re: TMK keyboard firmware
« Reply #1414 on: Fri, 29 April 2016, 10:04:31 »
I'm fiddling around with the LEDs on my maltron. I got the usual Caps, Num and Scrollock working, but got 2 LEDs left unused.
I just found the definitons for the three LED above. Is it possible to use a LED if a function toggle is pressed?
Like FN0 is a LED and FN1 another one?
- Ergodox Classic/Browns/Grifiti Rests  | - IBM Model M Blue Label |  - Poker II MX Blue | - Ergodox Classic/Blues/Grifiti Rests

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1415 on: Fri, 29 April 2016, 10:11:31 »
I'm fiddling around with the LEDs on my maltron. I got the usual Caps, Num and Scrollock working, but got 2 LEDs left unused.
I just found the definitons for the three LED above. Is it possible to use a LED if a function toggle is pressed?
Like FN0 is a LED and FN1 another one?

Post shcematic or pics, and your code.

Offline goflo

  • Posts: 69
  • Location: Germany
Re: TMK keyboard firmware
« Reply #1416 on: Fri, 29 April 2016, 10:21:43 »
Hmm, there's no special schematic.
I wired all LEDs to a port on the teensy with a resistor in between.
Is it possble to define something like USB_LED_FN0 and USB_LED_FN1 for use in the spots labeled "XXX" and "YYY"?

My current led.c looks like this:

Code: [Select]
void led_set(uint8_t usb_led)
{
    if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
        // Output high
        DDRD |= (1<<1);
        PORTD |= (1<<1);
      } else {
        // output low
        DDRD &= ~(1<<1);
        PORTD &= ~(1<<1);
     }
     
    if (usb_led & (1<<USB_LED_SCROLL_LOCK))
    {
        // Output high.
        DDRD |= (1<<2);
        PORTD |= (1<<2);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<2);
        PORTD &= ~(1<<2);
    }

    if (usb_led & (1<<USB_LED_NUM_LOCK))
    {
        // Output high.
        DDRD |= (1<<3);
        PORTD |= (1<<3);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<3);
        PORTD &= ~(1<<3);
    }

    if (usb_led & (1<<USB_LED_YYY))
    {
        // Output high.
        DDRD |= (1<<4);
        PORTD |= (1<<4);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<4);
        PORTD &= ~(1<<4);
    }

    if (usb_led & (1<<USB_LED_XXX))
    {
        // Output high.
        DDRD |= (1<<5);
        PORTD |= (1<<5);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<5);
        PORTD &= ~(1<<5);
    }
}
- Ergodox Classic/Browns/Grifiti Rests  | - IBM Model M Blue Label |  - Poker II MX Blue | - Ergodox Classic/Blues/Grifiti Rests

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1417 on: Fri, 29 April 2016, 11:05:52 »
led_set() is used for standard indicators(capslock, numlock and etc.). You have to define custom action in keymap file to control the LEDs.
Someone wrote similar action somewhere, FAQ on github may have related entry, but not sure.

Offline a-c

  • Posts: 196
  • Location: USA

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1419 on: Fri, 29 April 2016, 13:02:30 »
No, it deosn't work like that.
Instead, I think you can use 'hook_layer_change()' to run arbitrary code when layer is changed.
https://github.com/tmk/tmk_keyboard/issues/304


Hmm, there's no special schematic.
I wired all LEDs to a port on the teensy with a resistor in between.
Is it possble to define something like USB_LED_FN0 and USB_LED_FN1 for use in the spots labeled "XXX" and "YYY"?

My current led.c looks like this:

Code: [Select]
void led_set(uint8_t usb_led)
{
    if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
        // Output high
        DDRD |= (1<<1);
        PORTD |= (1<<1);
      } else {
        // output low
        DDRD &= ~(1<<1);
        PORTD &= ~(1<<1);
     }
     
    if (usb_led & (1<<USB_LED_SCROLL_LOCK))
    {
        // Output high.
        DDRD |= (1<<2);
        PORTD |= (1<<2);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<2);
        PORTD &= ~(1<<2);
    }

    if (usb_led & (1<<USB_LED_NUM_LOCK))
    {
        // Output high.
        DDRD |= (1<<3);
        PORTD |= (1<<3);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<3);
        PORTD &= ~(1<<3);
    }

    if (usb_led & (1<<USB_LED_YYY))
    {
        // Output high.
        DDRD |= (1<<4);
        PORTD |= (1<<4);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<4);
        PORTD &= ~(1<<4);
    }

    if (usb_led & (1<<USB_LED_XXX))
    {
        // Output high.
        DDRD |= (1<<5);
        PORTD |= (1<<5);
    }
    else
    {
        // Output low.
        DDRD &= ~(1<<5);
        PORTD &= ~(1<<5);
    }
}

Offline goflo

  • Posts: 69
  • Location: Germany
Re: TMK keyboard firmware
« Reply #1420 on: Fri, 29 April 2016, 13:54:37 »
The post by a-c worked. Thanks again  :thumb:
Now I almost got the functionality of my ergodox.

At moment I'm figuring out how to define a "key" that gives me things like "ALT+8".
I got this to work with to ergodox firmware from benblazak, but not yet with the tmk firmware.

Right now the maltron is a bit strange to me...the 3D molds feel quite good, but at the moment I like my ergodoxes more.  :eek:
- Ergodox Classic/Browns/Grifiti Rests  | - IBM Model M Blue Label |  - Poker II MX Blue | - Ergodox Classic/Blues/Grifiti Rests

Offline goflo

  • Posts: 69
  • Location: Germany
Re: TMK keyboard firmware
« Reply #1421 on: Sat, 30 April 2016, 10:38:37 »
Got it.  :))
Now I got a maltron clone of my ergodox. Now the layout is no longer an excuse. :-X
- Ergodox Classic/Browns/Grifiti Rests  | - IBM Model M Blue Label |  - Poker II MX Blue | - Ergodox Classic/Blues/Grifiti Rests

Offline chupanibre

  • Posts: 7
Re: TMK keyboard firmware
« Reply #1422 on: Wed, 04 May 2016, 11:59:33 »
hi!

i'm trying to get an old keyboard off an electric typewriter to work with hasu's firmware (thanks for making that, btw!).
that should in theory be possible, right?

i followed matt3o's very informative thread over at deskthority to get everything configured, compiled it and loaded it onto the teensy.
my .hex kinda works, but the keypresses it sends are all wrong. i'm only getting a few of the keys i configured, and always 4 or 5 at once (for a single keypress).

here are my config files, it would be awesome if somebody with eagle eyes could spot my mistake(s)..

matrix.c
More
/*
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/>.
*/

/*
 * scan matrix
 */
#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 = 0;
        matrix_debouncing = 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 != cols) {
            matrix_debouncing = 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 = matrix_debouncing;
            }
        }
    }

    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);
    }
    return count;
}

/* Column pin configuration
 * col: 0   1   2   3   4   5   6   7   8   9   10  11  12  13
 * pin: F0  F1  E6  C7  C6  B6  D4  B1  B0  B5  B4  D7  D6  B3  (Rev.A)
 * pin:                                 B7                      (Rev.B)
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<7 | 1<<6 | 1<<5 | 1<<4);
    PORTF |=  (1<<7 | 1<<6 | 1<<5 | 1<<4);
    DDRD  &= ~(1<<7);
    PORTD |=  (1<<7);
    DDRB  &= ~(1<<6 | 1<< 5 | 1<<4);
    PORTB |=  (1<<6 | 1<< 5 | 1<<4);
}

static matrix_row_t read_cols(void)
{
    return (PINF&(1<<4) ? 0 : (1<<0)) |
           (PINF&(1<<5) ? 0 : (1<<1)) |
           (PINF&(1<<6) ? 0 : (1<<2)) |
           (PINF&(1<<7) ? 0 : (1<<3)) |
           (PINB&(1<<6) ? 0 : (1<<4)) |
           (PINB&(1<<5) ? 0 : (1<<5)) |
           (PINB&(1<<4) ? 0 : (1<<6)) |
           (PIND&(1<<7) ? 0 : (1<<7));
}

/* Row pin configuration
 * row: 0   1   2   3   4
 * pin: D0  D1  D2  D3  D5
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRB  &= ~0b00010001;
    PORTB &= ~0b00010001;
    DDRD  &= ~0b11110000;
    PORTD &= ~0b11110000;
    DDRC  &= ~0b00000011;
    PORTC &= ~0b00000011;
}

static void select_row(uint8_t row)
{
    // Output low(DDR:1, PORT:0) to select
    switch (row) {
        case 0:
            DDRB  |= (1<<3);
            PORTB &= ~(1<<3);
            break;
        case 1:
            DDRB  |= (1<<7);
            PORTB &= ~(1<<7);
            break;
        case 2:
            DDRD  |= (1<<0);
            PORTD &= ~(1<<0);
            break;
        case 3:
            DDRD  |= (1<<1);
            PORTD &= ~(1<<1);
            break;
        case 4:
            DDRD  |= (1<<2);
            PORTD &= ~(1<<2);
            break;
        case 5:
            DDRD  |= (1<<3);
            PORTD &= ~(1<<3);
            break;
        case 6:
            DDRC  |= (1<<6);
            PORTD &= ~(1<<6);
            break;
        case 7:
            DDRC  |= (1<<7);
            PORTC &= ~(1<<7);
            break;
    }
}

keymap.common
More
/*
Copyright 2012,2013 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/>.
*/
#ifndef KEYMAP_COMMON_H
#define KEYMAP_COMMON_H

#include <stdint.h>
#include <stdbool.h>
#include <avr/pgmspace.h>
#include "keycode.h"
#include "action.h"
#include "action_macro.h"
#include "report.h"
#include "host.h"
#include "print.h"
#include "debug.h"
#include "keymap.h"


extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
extern const uint16_t fn_actions[];


/* GH60 keymap definition macro
 * K2C, K31 and  K3C are extra keys for ISO
 */
#define KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, \
   K10, K11, K12, K13, K14, K15, K16, K17, \
   K20, K21, K22, K23, K24, K25, K26, K27, \
   K30, K31, K32, K33, K34, K35, K36, K37, \
   K40, K41, K42, K43, K44, K45, K46, K47, \
   K50, K51, K52, K53, K54, K55,           \
   K60, K61, K62, K63, K64, K65, K66, K67, \
   K70, K71, K72, K73, K74, K75, K76, K77  \
) { \
    { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
   { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
   { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
   { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37 }, \
   { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47 }, \
   { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_NO,    KC_NO    }, \
   { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_##K67 }, \
   { KC_##K70, KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_##K77 }  \
}

#endif

keymap_poker.c
More
#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    KEYMAP(
        0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, \
        0, 0, Q, W, E, R, T, Z, U, I, O, P, U, 0, 0,    \
        0, 0, A, S, D, F, G, H, J, K, L, O, A, 0, 0,    \
        0, 0, LSFT, Y, X, C, V, B, N, M, 0, 0, 0,       \
        LCTL, SPC, RCTL),
};

const uint16_t PROGMEM fn_actions[] = {};



Offline a-c

  • Posts: 196
  • Location: USA
Re: TMK keyboard firmware
« Reply #1423 on: Wed, 04 May 2016, 12:14:37 »
Your bits are backwards. LSB is on the right.

Code: [Select]
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRB  &= ~0b00010001;
    PORTB &= ~0b00010001;
    DDRD  &= ~0b11110000;
    PORTD &= ~0b11110000;
    DDRC  &= ~0b00000011;
    PORTC &= ~0b00000011;

Offline chupanibre

  • Posts: 7
Re: TMK keyboard firmware
« Reply #1424 on: Wed, 04 May 2016, 12:53:37 »
Your bits are backwards. LSB is on the right.

arrgh! thanks!
i fixed my bits, recompiled, but i still get the exact same keys in aqua's key test.. huh?
i guess there are some more errors in my files, maybe it's best to start over..

edit. i started over with a fresh copy from the tmk repo, and i'm back at the same output as before.
i probably do something very stupid somewhere, but i can't figure out what.
i measured the outputs with a voltmeter, and wrote down the matrix.
e.g. when i press key 1, the resistance between the leftmost wires drops, and so on.
i've attached a picture:


edit.2 i found my mistake!! i had a 15x4 matrix defined in my keymap_common.h but i needed a 8x8.. it's working, wooohoo!! and now for some serious tweaking, i need all the fn layers, leds and special keys!
« Last Edit: Thu, 05 May 2016, 07:26:56 by chupanibre »

Offline BorisYeltsin

  • Posts: 3
Re: TMK keyboard firmware
« Reply #1425 on: Fri, 06 May 2016, 19:31:49 »
Hello,

I am currently building a custom keyboard and am having some problems with the firmware.  I am using a Teensy lc with a matrix with 16 outputs and 6 inputs.  I meant for it to be the opposite of that, but I guess I messed up the direction of the diodes even though I checked before soldering.  I have gotten all of the keys to work, however when I try to type at more than ~2 keys per second, the keyboard pauses then starts outputting a whole bunch of a single character.  For example, if I alternate between g and h quickly, it will type a g and an h then pause then type multiple g's or h's in a row almost as if I was holding the key down.  This works with any 2 keys.  I'm using the teensy_lc_onekey example in the keyboards directory but I have added a keymap_common.h and .c and have changed matrix.c and keymap_plain.c

any help would be appreciated and if you need any more info just ask.

keymap_common.c:
http://pastebin.com/JxQeyqfe

keymap_common.h:
http://pastebin.com/3hYe6qrM

matrix.c
http://pastebin.com/AxUZxCrf

keymap_plain.c
http://pastebin.com/XYve6ni7

keyboard pictures:
http://imgur.com/a/rNCds
« Last Edit: Sat, 07 May 2016, 00:21:24 by BorisYeltsin »

Offline e_l_tang

  • Posts: 260
Re: TMK keyboard firmware
« Reply #1426 on: Sat, 07 May 2016, 14:49:36 »
@BorisYeltsin Did you follow the instructions to build TMK for ARM chips at https://github.com/tmk/tmk_keyboard/tree/master/tmk_core/protocol/chibios?

Offline BorisYeltsin

  • Posts: 3
Re: TMK keyboard firmware
« Reply #1427 on: Sat, 07 May 2016, 16:41:30 »
I was able to figure get my matrix to be the right dimensions by making keys active high instead of active low.  I had a small problem with the capslock led being on the same pin as a column but that is fixed as well.  basically when the caps lock was turned on, all of the keys in the column would be pressed.  Now I am getting the same symptom with the scroll lock led but I have made sure that they are on different pins (scroll lock led on 17, column on 12).  I am also getting some strange behavior by the pause break key in which the key doesnt work but it is pressed seemingly randomly.  I'm fairly sure this is a software issue since I have checked the rows and columns for shorts multiple times.  If you can think of anything that might help I would love to hear it.

led.c
http://pastebin.com/iyNdhwXr

matrix.c
http://pastebin.com/3AcQDGvJ

keymap_common.h
http://pastebin.com/Veg4BT4k

keymap_plain.c
http://pastebin.com/yM5PLm8Q

Also, I followed the directions in instructions.md in the teensy_lc_onekey folder, which seem to be more or less the same as those in the link you posted

Edit: also found out that pressing asd or sdf at the same time toggles caps lock, which is weird and I cant really explain it. I have tried a bunch of other key configurations and nothing else does this.  I have also found that most of my problems seem to be centered around the pause/break key, all the other keys are fine but it gets held down randomly.  none of the other keys on its column or row are affected.  I could just disable this key but I would like to have it in order to get to the bootloader without having to press the button on the teensy
« Last Edit: Sat, 07 May 2016, 20:57:37 by BorisYeltsin »

Offline flabbergast

  • Posts: 234
  • Location: UK
Re: TMK keyboard firmware
« Reply #1428 on: Sun, 08 May 2016, 14:19:54 »
Not sure what the problem could be. Just a couple of comments: your mileage may vary with PIN13 - the Teensy has a LED on it. If you want to have the pause/break key just for getting into the bootloader (and you don't normally use it), you can ditch it completely and define a 'BTLD' keycode for some combination. That will get you into the bootloader just as well.

EDIT: Just tested PIN13 - and *almost always* when set as input with the internal pullup, it does read high. So you can probably use it. However if you have another spare pin, I'd rewire that row/column there. BTW having a LED on that pin is fine (you'll simply have 2 LEDs on at the same time).
« Last Edit: Sun, 08 May 2016, 14:31:07 by flabbergast »

Offline BorisYeltsin

  • Posts: 3
Re: TMK keyboard firmware
« Reply #1429 on: Wed, 11 May 2016, 21:59:39 »
I moved the column connected to pin 13 and used a different USB cable and all of the problems went away! thanks for the help

Offline RavenII

  • Posts: 191
Re: TMK keyboard firmware
« Reply #1430 on: Thu, 12 May 2016, 08:00:03 »
How can I make a key do the following...

When held it's LALT, but when tapped twice (and held on the second tap), it becomes Fn1?

ACTION_LAYER_TAP_KEY(KC_LALT, 2) doesn't work, I thought if I swapped the Layer number with the modifier it would...but no go.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1431 on: Thu, 12 May 2016, 15:04:11 »
How can I make a key do the following...

When held it's LALT, but when tapped twice (and held on the second tap), it becomes Fn1?

ACTION_LAYER_TAP_KEY(KC_LALT, 2) doesn't work, I thought if I swapped the Layer number with the modifier it would...but no go.

you cannot do this with existent keymap action, you have to write function code in your keymap file. You can use tap_count to know how many it taps.
http://www.tmk-kbd.com/tmk_keyboard/editor/alps64/index.html

Offline ProCarpet

  • Posts: 60
Re: TMK keyboard firmware
« Reply #1432 on: Fri, 13 May 2016, 09:15:20 »
Yet again i have to request your help. Ive soldered in my diodes the wrong way. Now ive read that it is possible to reverse them in software but how? Can anybody tell me?

Offline a-c

  • Posts: 196
  • Location: USA
Re: TMK keyboard firmware
« Reply #1433 on: Fri, 13 May 2016, 11:52:03 »
Yet again i have to request your help. Ive soldered in my diodes the wrong way. Now ive read that it is possible to reverse them in software but how? Can anybody tell me?

Look at the matrix.c from the phantom keyboard for an example of wiring with the diodes in the opposite direction to the GH60. https://github.com/tmk/tmk_keyboard/blob/master/keyboard/phantom/matrix.c

Offline ProCarpet

  • Posts: 60
Re: TMK keyboard firmware
« Reply #1434 on: Fri, 13 May 2016, 12:45:22 »
Yet again i have to request your help. Ive soldered in my diodes the wrong way. Now ive read that it is possible to reverse them in software but how? Can anybody tell me?

Look at the matrix.c from the phantom keyboard for an example of wiring with the diodes in the opposite direction to the GH60. https://github.com/tmk/tmk_keyboard/blob/master/keyboard/phantom/matrix.c
So i would need to switch all rows for cols and do the same in the matrix? If so id rather desolder the switches and turn the diode

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1435 on: Fri, 13 May 2016, 17:56:10 »
Yet again i have to request your help. Ive soldered in my diodes the wrong way. Now ive read that it is possible to reverse them in software but how? Can anybody tell me?

Look at the matrix.c from the phantom keyboard for an example of wiring with the diodes in the opposite direction to the GH60. https://github.com/tmk/tmk_keyboard/blob/master/keyboard/phantom/matrix.c
So i would need to switch all rows for cols and do the same in the matrix? If so id rather desolder the switches and turn the diode


Resolder them, it seems to be easy to you.

Offline wolfv

  • Posts: 269
Re: TMK keyboard firmware
« Reply #1436 on: Sat, 14 May 2016, 00:46:11 »
I want to try hasu's firmware on a key matrix that is active-high, pull down resistors on the columns, and uses Teensy 2.0.
Is there a TMK firmware with a similar setup that I could modify?
Where in the TMK code is the active-high or active-low configured?

Thank you.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1437 on: Sat, 14 May 2016, 01:03:08 »
I want to try hasu's firmware on a key matrix that is active-high, pull down resistors on the columns, and uses Teensy 2.0.
Is there a TMK firmware with a similar setup that I could modify?
Where in the TMK code is the active-high or active-low configured?

Thank you.

No such configuration option, you basically have to write code for the matrix with TMK. I can't remember if there is project using active-high matrix in TMK repository.

Offline ProCarpet

  • Posts: 60
Re: TMK keyboard firmware
« Reply #1438 on: Sat, 14 May 2016, 02:04:58 »
Yet again i have to request your help. Ive soldered in my diodes the wrong way. Now ive read that it is possible to reverse them in software but how? Can anybody tell me?

Look at the matrix.c from the phantom keyboard for an example of wiring with the diodes in the opposite direction to the GH60. https://github.com/tmk/tmk_keyboard/blob/master/keyboard/phantom/matrix.c
ok ill do that thanks you both for the help :D
So i would need to switch all rows for cols and do the same in the matrix? If so id rather desolder the switches and turn the diode


Resolder them, it seems to be easy to you.

Offline wolfv

  • Posts: 269
Re: TMK keyboard firmware
« Reply #1439 on: Sat, 14 May 2016, 02:10:57 »
I want to try hasu's firmware on a key matrix that is active-high, pull down resistors on the columns, and uses Teensy 2.0.
Is there a TMK firmware with a similar setup that I could modify?
Where in the TMK code is the active-high or active-low configured?

Thank you.

No such configuration option, you basically have to write code for the matrix with TMK. I can't remember if there is project using active-high matrix in TMK repository.
Thanks for the quick response hasu.
Is there an example TMK firmware with a Teensy LC and active-low key matrix, that I could modify?

« Last Edit: Sat, 14 May 2016, 02:12:57 by wolfv »

Offline mike52787

  • Posts: 1030
  • Location: South-West Florida
  • Alps Aficionado
Re: TMK keyboard firmware
« Reply #1440 on: Sat, 14 May 2016, 22:30:12 »
Having some trouble compiling my firmware. I tried it on windows and on a linux vm and got different errors each time. Here is my code. check my work!
matrix.c
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/>.
*/

/*
 * scan matrix
 */
#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   7   8   9   10  11  12  13  14  15  16
 * pin: B6  B5  B4  D7  D6  D4  D5  C7  C6  D3  D2  D1  D0  B7  B3  B2  B1                                                 
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRD  &= ~(1<<7 | 1<<6 | 1<<4 | 1<<5 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    PORTD |=  (1<<7 | 1<<6 | 1<<4 | 1<<5 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    DDRC  &= ~(1<<7 | 1<<6);
    PORTC |=  (1<<7 | 1<<6);
    DDRB  &= ~(1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<2);
    PORTB |=  (1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<2);
}

static matrix_row_t read_cols(void)
{
    return (PINB&(1<<6) ? 0 : (1<<0)) |
           (PINB&(1<<5) ? 0 : (1<<1)) |
           (PINB&(1<<4) ? 0 : (1<<2)) |
           (PIND&(1<<7) ? 0 : (1<<3)) |
           (PIND&(1<<6) ? 0 : (1<<4)) |
           (PIND&(1<<4) ? 0 : (1<<5)) |
           (PIND&(1<<5) ? 0 : (1<<6)) |
           (PINC&(1<<7) ? 0 : (1<<7)) |
           (PINC&(1<<6) ? 0 : (1<<8)) |
           (PIND&(1<<3) ? 0 : (1<<9)) |
           (PIND&(1<<2) ? 0 : (1<<10)) |
   (PIND&(1<<1) ? 0 : (1<<11)) |
   (PIND&(1<<0) ? 0 : (1<<12)) |
   (PINB&(1<<7) ? 0 : (1<<13)) |
   (PINB&(1<<3) ? 0 : (1<<14)) |
   (PINB&(1<<2) ? 0 : (1<<15)) |
           (PINB&(1<<1) ? 0 : (1<<16));
}

/* 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
    DDRF  &= ~0b11001111;
    PORTF &= ~0b11001111;
}

static void select_row(uint8_t row)
{
    // Output low(DDR:1, PORT:0) to select
    switch (row) {
        case 0:
            DDRF  |= (1<<0);
            PORTF &= ~(1<<0);
            break;
        case 1:
            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;
    }
}
keymap_poker.c
Code: [Select]
#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* 0: qwerty */
KEYMAP(\
    ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11,  F12,        PSCR,SLCK,PAUS,                         \
    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,FN0,LALT,               SPC,                RALT,RGUI,RCTL,         LEFT,DOWN,RGHT,    ),
};

const uint16_t PROGMEM fn_actions[] = {

};
here is the board.

Here is the error i get when compiling.

please help!
« Last Edit: Sat, 14 May 2016, 22:42:21 by mike52787 »

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1441 on: Sat, 14 May 2016, 23:43:45 »
mike52787, did you see if default source codes can be compiled in your environment yet? I like to know if your enviroment is correct before inspecting your codes.

Offline xevz

  • Posts: 1
Re: TMK keyboard firmware
« Reply #1442 on: Sun, 15 May 2016, 06:02:38 »
So, I'm trying to implement translation from Swedish QWERTY to Svorak A5 using TMK on my Ergodox.
Almost everything works, except for the combinations that require Right Alt (AltGr) + keys on the left hand side of the keyboard in Swedish QWERTY, which means that neither $ nor @ works.

Tried both LUFA and PJRC libraries.

Any pointers on how to debug this further?

Output from xev when sending @:
Code: [Select]
MappingNotify event, serial 33, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyPress event, serial 33, synthetic NO, window 0x3200001,
    root 0xd9, subw 0x0, time 616870409, (-492,511), root:(195,531),
    state 0x0, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

FocusOut event, serial 34, synthetic NO, window 0x3200001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 34, synthetic NO, window 0x3200001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 34, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   16  0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeyRelease event, serial 34, synthetic NO, window 0x3200001,
    root 0xd9, subw 0x0, time 616870497, (-492,511), root:(195,531),
    state 0x80, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

hid_listen:
Code: [Select]
---- action_exec: start -----
EVENT: 0705d(39579)
ACTION: ACT_LAYER_TAP[1:F1] layer_state: 00000000(0) default_layer_state: 00000000(0)
layer_state: 00000000(0) to 00000002(1)
keyboard_report: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
processed: 0705d(39579):0


---- action_exec: start -----
EVENT: 0303d(40171)
ACTION: ACT_RMODS[4:1F] layer_state: 00000002(1) default_layer_state: 00000000(0)
keyboard_report: 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
keyboard_report: 40 00 1F 00 00 00 00 00 00 00 00 00 00 00 00 00
processed: 0303d(40171):0


---- action_exec: start -----
EVENT: 0303u(40261)
ACTION: ACT_RMODS[4:1F] layer_state: 00000002(1) default_layer_state: 00000000(0)
keyboard_report: 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
keyboard_report: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
processed: 0303u(40261):0


---- action_exec: start -----
EVENT: 0705u(41107)
ACTION: ACT_LAYER_TAP[1:F1] layer_state: 00000002(1) default_layer_state: 00000000(0)
layer_state: 00000002(1) to 00000000(0)
keyboard_report: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
processed: 0705u(41107):0

keymap:
Code: [Select]
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    KEYMAP(  // Layer0: default, leftled:none
        // left hand
        NO,   1,   2,      3,   4,   5,   NO,
        TAB,  LBRC,QUOT,SCLN,   P,   Y,   NO,
        ESC,  A,      O,   E,   U,   I,
        LSFT, DOT,    Q,   J,   K,   X,   NO,
        NO,          NO,  NO,  NO,  NO,
                                       LCTL,  LALT,
                                                NO,
                                     BSPC, DEL, NO,
        // right hand
             NO,  6,   7,   8,    9,   0,   NO,
             NO,  F,   G,   C,    R,   L,   NO,
                  D,   H,   T,    N,   S,   NO,
             NO,  B,   M,   W,    V,   Z,   RSFT,
                       NO, NO, COMM,   NO,  NO,
        FN1,  RCTL,
        NO,
        NO, ENT, SPC
    ),

    KEYMAP(  // Layer1: AltGr
        // left hand
        NO,   NO,    NO,      NO,   NO,   NO,   NO,
        NO,  FN2,   FN3,     FN4,  FN5,  FN6,   NO,
        NO,  FN12, FN13,    FN14, FN15, FN16,
        NO,  FN22, FN23,    FN24, FN25, FN26,   NO,
        NO,          NO,  NO,  NO,  NO,
                                       NO,  NO,
                                                NO,
                                     NO, NO, NO,
        // right hand
             NO,    NO,    NO,   NO,   NO,   NO,   NO,
             NO,   FN7,   FN8,  FN9, FN10, FN11,   NO,
                  FN17,  FN18, FN19, FN20, FN21,   NO,
             NO,  FN27,    NO,   NO,   NO,   NO,   NO,
                    NO,    NO,   NO,   NO,   NO,
        FN1,  NO,
        NO,
        NO, NO, NO
    ),
};

/* id for user defined functions */
enum function_id {
    TEENSY_KEY,
};

enum macro_id {
    NODEAD_TILDE,
    NODEAD_CARET,
};

/*
 * Fn action definition
 */
static const uint16_t PROGMEM fn_actions[] = {
    [0]  = ACTION_FUNCTION(TEENSY_KEY),                       // FN0  - Teensy key

    // AltGr toogle
    [1]  = ACTION_LAYER_MOMENTARY(1),                         // FN1 = Temporarily switch to layer 1

    // AltGr, top row
    [2]  = ACTION_MODS_KEY(MOD_RALT, KC_7),                   // FN2  = {
    [3]  = ACTION_MODS_KEY(MOD_RALT, KC_0),                   // FN3  = }
    [4]  = ACTION_MODS_KEY(MOD_RALT, KC_8),                   // FN4  = [
    [5]  = ACTION_MODS_KEY(MOD_RALT, KC_9),                   // FN5  = ]
    [6]  = ACTION_MODS_KEY(MOD_RALT, KC_4),                   // FN6  = $ XXX: NOT WORKING
    [7]  = ACTION_MODS_KEY(MOD_RSFT, KC_2),                   // FN7  = "
    [8]  = ACTION_MODS_KEY(MOD_RSFT, KC_MINUS),               // FN8  = ?
    [9]  = ACTION_MODS_KEY(MOD_RSFT, KC_6),                   // FN9  = &
    [10] = ACTION_KEY(KC_NONUS_BSLASH),                       // FN10 = <, not necessary, just easier to keep track
    [11] = ACTION_MODS_KEY(MOD_RSFT, KC_NONUS_BSLASH),        // FN11 = >

    // Middle row
    [12] = ACTION_MODS_KEY(MOD_RSFT, KC_COMMA),               // FN12 = ;
    [13] = ACTION_MODS_KEY(MOD_RSFT, KC_7),                   // FN13 = /
    [14] = ACTION_MODS_KEY(MOD_RSFT, KC_8),                   // FN14 = (
    [15] = ACTION_MODS_KEY(MOD_RSFT, KC_9),                   // FN15 = )
    [16] = ACTION_MODS_KEY(MOD_RALT, KC_NONUS_BSLASH),        // FN16 = |
    [17] = ACTION_MODS_KEY(MOD_RSFT, KC_3),                   // FN17 = #
    [18] = ACTION_MACRO(NODEAD_CARET),                        // FN18 = ^
    [19] = ACTION_MODS_KEY(MOD_RSFT, KC_3),                   // FN19 = #
    [20] = ACTION_MODS_KEY(MOD_RSFT, KC_2),                   // FN20 = "
    [21] = ACTION_MACRO(NODEAD_TILDE),                        // FN21 = ~

    // Last row
    [22] = ACTION_MODS_KEY(MOD_RSFT, KC_DOT),                 // FN22 = :
    [23] = ACTION_MODS_KEY(MOD_RSFT, KC_0),                   // FN23 = =
    [24] = ACTION_MODS_KEY(MOD_RALT, KC_2),                   // FN24 = @ XXX: NOT WORKING
    [25] = ACTION_MODS_KEY(MOD_RSFT, KC_1),                   // FN25 = !
    [26] = ACTION_MODS_KEY(MOD_RALT, KC_MINUS),               // FN26 = backslash
    [27] = ACTION_MODS_KEY(MOD_RSFT, KC_5),                   // FN27 = %
};

const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
    if (record->event.pressed) {
        switch (id) {
            case NODEAD_TILDE:
                return MACRO(D(RALT), T(RBRACKET), U(RALT), T(SPACE), END);
                break;
            case NODEAD_CARET:
                return MACRO(D(RSHIFT), T(RBRACKET), U(RSHIFT), T(SPACE), END);
                break;
        }
    }
    return MACRO_NONE;
}


void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
{
    print("action_function called\n");
    print("id  = "); phex(id); print("\n");
    print("opt = "); phex(opt); print("\n");
    if (id == TEENSY_KEY) {
        clear_keyboard();
        print("\n\nJump to bootloader... ");
        _delay_ms(250);
        bootloader_jump(); // should not return
        print("not supported.\n");
    }
}

EDIT: Just noticed that they don't work with the swedish layout using the laptop keyboard either, so it seems to be a X.org related problem.
« Last Edit: Sun, 15 May 2016, 06:29:38 by xevz »

Offline mike52787

  • Posts: 1030
  • Location: South-West Florida
  • Alps Aficionado
Re: TMK keyboard firmware
« Reply #1443 on: Sun, 15 May 2016, 13:15:48 »
mike52787, did you see if default source codes can be compiled in your environment yet? I like to know if your enviroment is correct before inspecting your codes.
I tried compiling the alps64 files and no success. What could be wrong? I am running a fresh install of mint 17.3.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1444 on: Sun, 15 May 2016, 16:45:30 »
I don't know about mint but seems like toolchain is not correctly setup. Maybe avr libc?
You can Google to know how to install packages required for avr toolchain.

Sent from my Nexus 5X using Tapatalk


Offline TD22057

  • Posts: 177
  • Location: Southern California
Re: TMK keyboard firmware
« Reply #1445 on: Sun, 15 May 2016, 19:38:49 »
Hey hasu,
I'd like to try and support the following features.  Any ideas on if they've been done before or how hard they would be to implement?

1) key to turn oneshot mods on and off for all mods (or a list of mods).  I want to be able to try out oneshot mods for shift, alt, ctrl but I may want to turn them off if I decide I don't like them so I'd like to have a key that globally enables and disables them (using an fn_actions function).

2) oneshot mod when a mod is tapped and normal mod when held - like ACTION_MODS_TAP_KEY( LSFT, LSFT ).  So tap left shift and get a normal oneshot behavior, hold it to get regular shift behavior (oneshot might already work this way - I haven't tried it yet).

3) oneshot layer switch.  Tap FN key which switches to layer 2 and after any key press switches back to layer 1.  Similar to 2) - if FN is held down, layer 2 is active until FN is released - i.e. if FN is held down and another key is pressed, that key from layer 2 is used and the layer switches back to 1 when FN is released but if FN is tapped, then the next key is from layer 2.

I noticed that action_util.h contains these function prototypes but they aren't defined or used anywhere.  I'm guessing these declarations should be removed.
Code: [Select]
void oneshot_toggle(void);
void oneshot_enable(void);
void oneshot_disable(void);
« Last Edit: Sun, 15 May 2016, 20:14:52 by TD22057 »

Offline TD22057

  • Posts: 177
  • Location: Southern California
Re: TMK keyboard firmware
« Reply #1446 on: Sun, 15 May 2016, 22:48:25 »
One more question (for now) - if I'm running out of function slots (32 limit), is there any reason to not move to a uint16_t matrix storing action_t objects for each key and override the action_for_key() function in keymap.c?  It seems like there is plenty of flash available and that would basically allow me to customize each key with an action object.  I'd need to do something different for the KEYMAP macro but that shouldn't be too hard.

Offline alienman82

  • * Elevated Elder
  • Posts: 4051
Re: TMK keyboard firmware
« Reply #1447 on: Tue, 17 May 2016, 12:28:45 »
removed.
« Last Edit: Thu, 01 March 2018, 15:11:58 by alienman82 »

Offline TD22057

  • Posts: 177
  • Location: Southern California
Re: TMK keyboard firmware
« Reply #1448 on: Tue, 17 May 2016, 12:43:23 »
One more question (for now) - if I'm running out of function slots (32 limit), is there any reason to not move to a uint16_t matrix storing action_t objects for each key and override the action_for_key() function in keymap.c?  It seems like there is plenty of flash available and that would basically allow me to customize each key with an action object.  I'd need to do something different for the KEYMAP macro but that shouldn't be too hard.

Answering my own question:  See alps64/Makefile which defines ACTIONMAP_ENABLE which triggers swapping keymap.c with actionmap.c to handle this.   This requires that the keyboard define a uint16_t matrix of actions to use instead of the keymap which is what I'm trying to do.   The alps64 directory has examples for doing this already.

Offline hasu

  • Thread Starter
  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: TMK keyboard firmware
« Reply #1449 on: Tue, 17 May 2016, 16:16:27 »
One more question (for now) - if I'm running out of function slots (32 limit), is there any reason to not move to a uint16_t matrix storing action_t objects for each key and override the action_for_key() function in keymap.c?  It seems like there is plenty of flash available and that would basically allow me to customize each key with an action object.  I'd need to do something different for the KEYMAP macro but that shouldn't be too hard.

Answering my own question:  See alps64/Makefile which defines ACTIONMAP_ENABLE which triggers swapping keymap.c with actionmap.c to handle this.   This requires that the keyboard define a uint16_t matrix of actions to use instead of the keymap which is what I'm trying to do.   The alps64 directory has examples for doing this already.

Right, no reason to hesitate actionmap except for twice usage of flash memory and conventinalism.