How to build your very own keyboard firmware

campo123456789

20 Jun 2016, 06:33

Hi guys so i have been trying to use this tutrial to make firmware for my custom keyboard, but with not much luck, i have been able to get the hex file at the end, but when i burn it on the tennsy and plug it in, it starts typing random letters untill a i press a key. and when a key is pressed it is inputing all the keys in that column rather then just the one. i have had a look at my wiring and i think its ok with not shorts.

here is my code

matrix.c

Code: Select all

/*
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 B0  B1  B2  B3  B7  D0  D1  D2  D3  C6   C7  D5  F7  B6  B5  B4  D7
 */
 
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<7);
    PORTF |=  (1<<7);
    DDRD  &= ~(1<<7 | 1<<5 | 1<<3 | 1<<2 |1<<1 |1<<0);
    PORTD |=  (1<<7 | 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<<2 | 1<<1 | 1<<0);
    PORTB |=  (1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
}

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

 /* Row pin configuration
 * row: 0   1   2   3   4	
 * pin: F6  F5  F4  F1  F0
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRD  &= ~0b01110011;
    PORTD &= ~0b01110011;
}

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

Code: Select all

/*
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, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G,  \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F,	K1G, \
    K20,      K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D,    	         \
    K30,           K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D,      K3F,       \
    K40, K41,      K43,                K47,           K4A, K4B, K4C, K4D, K4E, K4F, K4G  \
) { \
    { 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_##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_##K20,	KC_NO,    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_NO,    KC_NO,    KC_NO     }, \
    { KC_##K30, KC_NO,    KC_NO,    KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_NO,    KC_##K3F, KC_NO     }, \
    { KC_##K40, KC_##K41, KC_NO,    KC_##K43, KC_NO,    KC_NO,    KC_NO,    KC_##K47, KC_NO,    KC_NO,    KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E, KC_##K4F, KC_##K4G  }  \
}

/* ANSI valiant. No extra keys for ISO */
#define KEYMAP_ANSI( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, \
    K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B,           K3D \
) KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO,  K2D, \
    K30, NO,  K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, NO,  K3D, \
    K40, K41, K42,           K45,                NO,  K4A, K4B, K4C, K4D  \
)


#define KEYMAP_HHKB( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K49,\
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, \
    K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B,      K3D, K3C, \
    K40, K41, K42,           K45,                     K4A, K4B, K4C, K4D  \
) KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO,  K2D, \
    K30, NO,  K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \
    K40, K41, K42,           K45,                K49, K4A, K4B, K4C, K4D  \
)

#endif
keymap_poker.c

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* 0: qwerty */
    KEYMAP( ESC,  1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINUS, EQL, BSPC, VOLD, VOLU, DELETE,  \
           TAB,  Q,   W,  E,   R,   T,   Y,   U,   I,   O,   P,   LBRC, RBRC, GRV, MPRV, PAUS, MNXT,  		\
           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, 		   			\
           LCTRL, LGUI, LALT,           SPC,           RALT, FN1, CALC, RCTRL,         LEFT,DOWN,RIGHT),

	/* 1: FN 1 */
	KEYMAP( MUTE,  F1,   F2,   F3,   F4,   F5,   F6,   F7,   F8,   F9,   F10,   F11, F12, TRNS, TRNS, TRNS, TRNS,  \
           TRNS, TRNS, TRNS,  TRNS,  TRNS, TRNS,   TRNS,TRNS,TRNS,TRNS,TRNS,   TRNS, TRNS, TRNS, TRNS,TRNS, TRNS, \
           TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,   TRNS, TRNS, TRNS,          			   	 	    \
           TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,  TRNS, TRNS, TRNS,    TRNS,           TRNS, 		   			\
           TRNS, TRNS, TRNS,           TRNS,          TRNS, TRNS,TRNS, TRNS,         TRNS,TRNS,TRNS),
};

  const uint16_t PROGMEM fn_actions[] = {
  [0] = ACTION_LAYER_MOMENTARY(1),
  [1] = ACTION_LAYER_TAP_KEY(1, KC_ESC),
};
please help me !! i have been trying for the last few days and i really want to get this done :( any suggestions?

I am running windows as well, please?

User avatar
armatus

20 Jun 2016, 13:36

campo123456789 wrote: and when a key is pressed it is inputing all the keys in that column rather then just the one.
Can you show your wiring? Is outer part of diodes black when you solder it?

campo123456789

20 Jun 2016, 13:47

i don't think so i have checked over them again but here is what they look like (please excuse the large blobs ) do you think that code it ok? i don't have an led either for the caps if that changes anything?

https://lh3.googleusercontent.com/5Lmz1 ... 53-h927-no

User avatar
redesigndavid

20 Jun 2016, 13:51

I think I had this problem once. In my case, what was supposed to be columns were my rows and vice versa.
Last edited by redesigndavid on 20 Jun 2016, 17:05, edited 1 time in total.

campo123456789

20 Jun 2016, 13:54

as in the matrix.c file?

User avatar
kbdfr
The Tiproman

20 Jun 2016, 14:31

redesigndavid wrote: I think I had this problem once. In my case, what was supposed to be columns were my rows and vice versa.


Sent from my iPhone using Tapatalk
off-topic-f10/tapatalk-sig-spam-pisses- ... 13807.html

User avatar
redesigndavid

20 Jun 2016, 16:33

campo123456789 wrote:as in the matrix.c file?
Yeap! Give it a try.

User avatar
redesigndavid

20 Jun 2016, 16:33

kbdfr wrote:
redesigndavid wrote: I think I had this problem once. In my case, what was supposed to be columns were my rows and vice versa.


Sent from my iPhone using Tapatalk
off-topic-f10/tapatalk-sig-spam-pisses- ... 13807.html
I didn't know there was such a thing. Thanks for the heads up! I took out the offensive signature.

gangolfus

21 Jun 2016, 20:33

Hello, this is a follow up to a string of posts from about a year ago: post240050.html#p240050.

I was successfully able to get everything working as recommended with a transistor and LED+470ohm resistors, however I keep blowing through transistors. I've tried both NTE123A and 2N2222 and both last a few weeks then die. Is there a beefier transistor I can use? Is it likely the amperage I'm trying to push (~447.3mA), or the pwm frequency that's killing them?

Thanks in advance for any help!

User avatar
kekstee

22 Jun 2016, 16:27

From what I understand I should be able to light the LEDs in caps lock and the Poker arrow cluster on a rev. C GH60.
I found some nice description in here and stuff in the issue tracker, but I wondered wether the standard function inside the GH60 folder shouldn't make use of the caps lock status LED already? Or how would I set that up to do anything?
(I wanted to get something working before modifying them for layer toggle status info)

buzzking00

29 Jun 2016, 18:19

What is the problem when I try to make hex file for my 40% Sebright?


C:\Users\BuzzKing\Desktop\tmk_keyboard-master\keyboard\gh60>make -f Makefile
0 [main] sh 2120 sync_with_child: child 8052(0x178) died before initialization with status code 0xC0000142
196 [main] sh 2120 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
0 [main] sh 2096 sync_with_child: child 7460(0x178) died before initialization with status code 0xC0000142
199 [main] sh 2096 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
0 [main] sh 3428 sync_with_child: child 8112(0x178) died before initialization with status code 0xC0000142
210 [main] sh 3428 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
0 [main] sh 7728 sync_with_child: child 7464(0x178) died before initialization with status code 0xC0000142
185 [main] sh 7728 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
0 [main] sh 4708 sync_with_child: child 4972(0x178) died before initialization with status code 0xC0000142
157 [main] sh 4708 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable

-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

make: *** No rule to make target `sebright_lufa.elf', needed by `elf'. Stop.

C:\Users\BuzzKing\Desktop\tmk_keyboard-master\keyboard\gh60>

matrix.c
/*
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
* pin: F6 F7 B6 B5 B4 D7 C7 C6 D3 D2 D1 D0
*/
static void init_cols(void)
{
// Input with pull-up(DDR:0, PORT:1)
DDRF &= ~(1<<6 | 1<<7);
PORTF |= (1<<6 | 1<<7);
DDRB &= ~(1<<6 | 1<< 5 | 1<<4);
PORTB |= (1<<6 | 1<< 5 | 1<<4);
DDRD &= ~(1<<7 | 1<<3 | 1<<2| 1<<1 | 1<<0 );
PORTD |= (1<<7 | 1<<3 | 1<<2| 1<<1 | 1<<0 );
DDRC &= ~(1<<7 | 1<<6);
PORTC |= (1<<7 | 1<<6);
}

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

/* Row pin configuration
* row: 0 1 2 3
* pin: F0 F1 F4 F5
*/
static void unselect_rows(void)
{
// Hi-Z(DDR:0, PORT:0) to unselect
DDRF &= ~0b00110011;
PORTF &= ~0b00110011;
}

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;
}
}


keymap_common.h
/*
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, K08, K09, K0A, K0B, \
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1B, \
K20, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, \
K31, K32, K34, K35, K37, K38, K39, K3A \
) { \
{ 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_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_NO , KC_##K1B }, \
{ KC_##K20, KC_NO, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_##K2B }, \
{ KC_NO, KC_##K31, KC_##K32, KC_NO, KC_##K34, KC_##K35, KC_NO, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_NO } \
}



#endif


keymap_poker.c
#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* 0: sebright */
KEYMAP(ESC, Q, W, E, R, T, Y, U, I, O, P, BSPC, \
TAB, A, S, D, F, G, H, J, K, L, ENT, \
LCTL, Z, X, C, V, B, N, M, SCLN, FN1, FN0, \
LSFT, LALT, FN2, SPC, COMM,DOT, QUOT,SLSH),

/* 1: arrow */
KEYMAP(ESC,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,FN1, FN0, \
TRNS, TRNS,FN2, TRNS, LEFT,UP, DOWN, RIGHT),
/* 2: numfunc */
KEYMAP(GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, DEL, \
CAPS, HOME,TRNS,TRNS,PGUP,HOME,MINS,EQL, LBRC,RBRC, ENT, \
TRNS, END, FN9, INS, PGDN, END, SCLN, BSLS, SCLN,FN1, FN0, \
TRNS, TRNS,FN2, SPC, LEFT,UP, DOWN, RIGHT),
/* 3: symbol */
KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, DEL, \
HOME, 4, 5, 6, PGUP,FN3, FN4, FN5, E, I, FN7, \
END, 7, 8, 9, PGDN, PSCR, LGUI, L, SCLN,FN1, FN0, \
LSFT, 0, FN2, FN6, LEFT,UP, DOWN, RIGHT),
/* 4: sebright flipped control and shift */
KEYMAP(ESC, Q, W, E, R, T, Y, U, I, O, P, BSPC, \
TAB, A, S, D, F, G, H, J, K, L, ENT, \
LSFT, Z, X, C, V, B, N, M, SCLN, FN1, FN0, \
LCTL, LALT, FN2, SPC, COMM,DOT, QUOT,SLSH),
/* 5: sebright */
KEYMAP(ESC, Q, W, E, R, T, Y, U, I, O, P, BSPC, \
TAB, A, S, LSFT,RSFT,PAUS, H, J, K, L, ENT, \
LCTL, Z, X, C, V, B, N, M, SCLN, FN1, FN0, \
LSFT, LALT, FN2, SPC, COMM,DOT, QUOT,SLSH),

};
const uint16_t PROGMEM fn_actions[] = {
/* sebright Layout */
[0] = ACTION_LAYER_MOMENTARY(2), // to numfunc overlay
[1] = ACTION_LAYER_TOGGLE(1), // toggle arrow overlay
[2] = ACTION_LAYER_TOGGLE(3), // to Layout selector
[3] = ACTION_LAYER_TOGGLE(4), // toggle ctrl/shift switch overlay
[4] = ACTION_LAYER_TOGGLE(2), // toggle OSX overlay
[5] = ACTION_LAYER_SET_CLEAR(0), // back to original sebright layout
[6] = ACTION_LAYER_SET_CLEAR(0), // back to original sebright layout
[7] = ACTION_LAYER_TOGGLE(5), // back to original sebright layout
};

User avatar
tentator

29 Jun 2016, 22:17

I think you messed up your makefile: can you download it again and doublecheck that you did not delete tabs or add spaces somewhere (basically keep edits to the minimum if you need to do)

cactusplants

01 Jul 2016, 16:36

Amazing guide. I'm nearly at the end but I am having massive issues.

I'm getting a plethora of error messages... this one is the current one (I'm a noob at code so If it is a simple mistake, I am sorry)

Code: Select all

Compiling C: keymap_poker.c
avr-gcc -c -mmcu=atmega32u4 -gdwarf-2 -DF_CPU=16000000UL -DINTERRUPT_CONTROL_ENDPOINT -DBOOTLOADER_SIZE=4096 -DF_USB=16000000UL -DARCH=ARCH_AVR8 -DUSB_DEVICE_ONLY -DUSE_FLASH_DESCRIPTORS -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -DFIXED_CONTROL_ENDPOINT_SIZE=8  -DFIXED_NUM_CONFIGURATIONS=1 -DPROTOCOL_LUFA -DBOOTMAGIC_ENABLE -DMOUSEKEY_ENABLE -DMOUSE_ENABLE -DEXTRAKEY_ENABLE -DCONSOLE_ENABLE -DCOMMAND_ENABLE -DNKRO_ENABLE -DVERSION=unknown -Os -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Wstrict-prototypes -Wa,-adhlns=obj_gh60_lufa/keymap_poker.lst -I. -I../../tmk_core -I../../tmk_core/protocol/lufa -I../../tmk_core/protocol/lufa/LUFA-git -I../../tmk_core/common -std=gnu99 -include config.h -MMD -MP -MF .dep/obj_gh60_lufa_keymap_poker.o.d  keymap_poker.c -o obj_gh60_lufa/keymap_poker.o
keymap_poker.c:9:85: error: macro "KEYMAP" requires 62 arguments, but only 61 given
keymap_poker.c:5: error: 'KEYMAP' undeclared here (not in a function)
keymap_poker.c:16:76: error: macro "KEYMAP" requires 62 arguments, but only 60 given
keymap_poker.c:18: error: conflicting types for 'fn_actions'
keymap_common.h:34: error: previous declaration of 'fn_actions' was here
keymap_poker.c:19: error: 'layer' undeclared here (not in a function)
keymap_poker.c:19: error: invalid operands to binary / (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary << (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary | (have 'int' and 'const uint8_t (*)[5][14]')
keymap_poker.c:19: error: invalid operands to binary % (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary << (have 'int' and 'const uint8_t (*)[5][14]')
keymap_poker.c:19: error: invalid operands to binary & (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary | (have 'const uint8_t (*)[5][14]' and 'const uint8_t (*)[5][14]')
keymap_poker.c:19: error: invalid operands to binary | (have 'int' and 'const uint8_t (*)[5][14]')
keymap_poker.c:20: error: initializer element is not constant
keymap_poker.c:20: error: (near initialization for 'fn_actions[1]')
make: *** [obj_gh60_lufa/keymap_poker.o] Error 1
I have no idea what it is asking for. Here are the other bits of codes

Here is keymap_poker.c

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 /* 0: qwerty */
     KEYMAP(ESC,  1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS, EQL, BSPC, \
           TAB,  Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC, RBRC,	   \
           LCTL, A,   S,   D,   F,   G,   H,   J,   K,   L, SCLN, QUOT, NUHS, ENT, \
           LSFT, NUBS,   Z,   X,   C,   V,   B,   N,   M,  COMM, DOT, SLSH, RSFT,        \
           LCTRL, LGUI, ALT          SPC,                     FN1, RGUI, RALT, RCTRL), 
		    
			/* 1: FN 1 */
     KEYMAP(GRV, F1,   F2,   F3,   F4,   F5,   F6,   F7,   F8,   F9,   F10,  VOLU, VOLD, DEL\
           TRNS, TRNS, UP, TRNS, TRNS, TRNS, TRNS, TRNS, TRNS, TRNS, PSCR, TRNS, TRNS,  \
           TRNS, LEFT, DOWN, RGHT, TRNS, TRNS, TRNS, TRNS, TRNS, PGDN, LEFT, RGHT, TRNS, TRNS  \
           TRNS, TRNS, TRNS, CALC, TRNS, TRNS, TRNS, TRNS, HOME, END,  DOWN, TRNS, TRNS, \
TRNS, TRNS, TRNS,            TRNS,                   TRNS, TRNS, TRNS, TRNS), 
};
const uint8_t PROGMEM fn_actions[] = {
  [1] = ACTION_LAYER_TOGGLE(layer)
};

And here is the keymap_common.h

Code: Select all

/*
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, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, \
    K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, \
    K40, K41, K42,           K45,                K49, K4A, K4B, K4C  \
) { \
    { 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_##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_NO }, \
    { 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_##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_NO }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_NO,    KC_NO,    KC_##K45, KC_NO,    KC_NO,    KC_NO,    KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_NO }  \
}

/* ANSI valiant. No extra keys for ISO */
#define KEYMAP_ANSI( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, \
    K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B,           K3D, \
    K40, K41, K42,           K45,                     K4A, K4B, K4C, K4D  \
) KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO,  K2D, \
    K30, NO,  K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, NO,  K3D, \
    K40, K41, K42,           K45,                NO,  K4A, K4B, K4C, K4D  \
)


#define KEYMAP_HHKB( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K49,\
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B,      K2D, \
    K30, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B,      K3D, K3C, \
    K40, K41, K42,           K45,                     K4A, K4B, K4C, K4D  \
) KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, NO,  K2D, \
    K30, NO,  K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, \
    K40, K41, K42,           K45,                K49, K4A, K4B, K4C, K4D  \
)

#endif
I'm pouring over it trying to make some sense, but I can't seem to do so. If someone could point out what I'm doing wrong, I'd really appreciate it. I'm sick of typing on this rubber dome keyboard, I want to use my mech.

User avatar
tentator

01 Jul 2016, 16:38

you missed a , between ALT SPC,

do not worry.. it's just C that does not forgive missing comas.. :)

tent:wq

cactusplants

01 Jul 2016, 16:56

tentator wrote: you missed a , between ALT SPC,

do not worry.. it's just C that does not forgive missing comas.. :)

tent:wq
How did i miss that?! Haha.

Re-compiled and I'm still getting a gnarly error message...

Code: Select all

mkdir -p obj_gh60_lufa
Compiling C: keymap_poker.c
avr-gcc -c -mmcu=atmega32u4 -gdwarf-2 -DF_CPU=16000000UL -DINTERRUPT_CONTROL_ENDPOINT -DBOOTLOADER_SIZE=4096 -DF_USB=16000000UL -DARCH=ARCH_AVR8 -DUSB_DEVICE_ONLY -DUSE_FLASH_DESCRIPTORS -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -DFIXED_CONTROL_ENDPOINT_SIZE=8  -DFIXED_NUM_CONFIGURATIONS=1 -DPROTOCOL_LUFA -DBOOTMAGIC_ENABLE -DMOUSEKEY_ENABLE -DMOUSE_ENABLE -DEXTRAKEY_ENABLE -DCONSOLE_ENABLE -DCOMMAND_ENABLE -DNKRO_ENABLE -DVERSION=unknown -Os -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Wstrict-prototypes -Wa,-adhlns=obj_gh60_lufa/keymap_poker.lst -I. -I../../tmk_core -I../../tmk_core/protocol/lufa -I../../tmk_core/protocol/lufa/LUFA-git -I../../tmk_core/common -std=gnu99 -include config.h -MMD -MP -MF .dep/obj_gh60_lufa_keymap_poker.o.d  keymap_poker.c -o obj_gh60_lufa/keymap_poker.o
keymap_poker.c:9: error: 'KC_ALT' undeclared here (not in a function)
keymap_poker.c:16:87: error: macro "KEYMAP" requires 62 arguments, but only 60 given
keymap_poker.c:12: error: expected '}' before 'KEYMAP'
keymap_poker.c:19: error: 'layer' undeclared here (not in a function)
keymap_poker.c:19: error: invalid operands to binary / (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary << (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary | (have 'int' and 'const uint8_t (*)[5][14]')
keymap_poker.c:19: error: invalid operands to binary % (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary << (have 'int' and 'const uint8_t (*)[5][14]')
keymap_poker.c:19: error: invalid operands to binary & (have 'const uint8_t (*)[5][14]' and 'int')
keymap_poker.c:19: error: invalid operands to binary | (have 'const uint8_t (*)[5][14]' and 'const uint8_t (*)[5][14]')
keymap_poker.c:19: error: invalid operands to binary | (have 'int' and 'const uint8_t (*)[5][14]')
keymap_poker.c:20: error: initializer element is not constant
keymap_poker.c:20: error: (near initialization for 'fn_actions[1]')
make: *** [obj_gh60_lufa/keymap_poker.o] Error 1


User avatar
tentator

01 Jul 2016, 17:02

and by the way isn't it LALT instead of ALT??
If still having issues then I'd suggest you to start from the original file again and redo the changes by only editing what you need to change if you think there are other comas or closed parentheses that could have gone wild.. :)

cactusplants

01 Jul 2016, 17:21

tentator wrote: and by the way isn't it LALT instead of ALT??
If still having issues then I'd suggest you to start from the original file again and redo the changes by only editing what you need to change if you think there are other comas or closed parentheses that could have gone wild.. :)
I'm no good at this, haha.

I've sorted out more of it. It's just those tiny mistakes make it feel like the world is about to end.

I'm here now....

Code: Select all

mkdir -p obj_gh60_lufa
Compiling C: keymap_poker.c
avr-gcc -c -mmcu=atmega32u4 -gdwarf-2 -DF_CPU=16000000UL -DINTERRUPT_CONTROL_ENDPOINT -DBOOTLOADER_SIZE=4096 -DF_USB=16000000UL -DARCH=ARCH_AVR8 -DUSB_DEVICE_ONLY -DUSE_FLASH_DESCRIPTORS -DUSE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" -DFIXED_CONTROL_ENDPOINT_SIZE=8  -DFIXED_NUM_CONFIGURATIONS=1 -DPROTOCOL_LUFA -DBOOTMAGIC_ENABLE -DMOUSEKEY_ENABLE -DMOUSE_ENABLE -DEXTRAKEY_ENABLE -DCONSOLE_ENABLE -DCOMMAND_ENABLE -DNKRO_ENABLE -DVERSION=unknown -Os -funsigned-char -funsigned-bitfields -ffunction-sections -fdata-sections -fno-inline-small-functions -fpack-struct -fshort-enums -fno-strict-aliasing -Wall -Wstrict-prototypes -Wa,-adhlns=obj_gh60_lufa/keymap_poker.lst -I. -I../../tmk_core -I../../tmk_core/protocol/lufa -I../../tmk_core/protocol/lufa/LUFA-git -I../../tmk_core/common -std=gnu99 -include config.h -MMD -MP -MF .dep/obj_gh60_lufa_keymap_poker.o.d  keymap_poker.c -o obj_gh60_lufa/keymap_poker.o
keymap_poker.c:12: error: expected '}' before '{' token
make: *** [obj_gh60_lufa/keymap_poker.o] Error 1
Which to me is saying that there should be a '}' before '{' on line 12. But that makes no sense what so ever

cactusplants

03 Jul 2016, 04:04

tentator wrote: and by the way isn't it LALT instead of ALT??
If still having issues then I'd suggest you to start from the original file again and redo the changes by only editing what you need to change if you think there are other comas or closed parentheses that could have gone wild.. :)
Pinout

Col : 0 1 2 3 4 5 6 7 8 9 10 11 12 13
pin : b3 b7 b2 d0 d1 d2 d3 c6 c7 f7 b6 b5 b4 d7

Row : 0 1 2 3 4
pin : f6 f5 f4 f1 f0


Here are some photos of the underside and topside...

http://imgur.com/a/Ulcbh

And the code...

Keymap_poker.c
http://pastebin.com/T4kLEcM4

Keymap_common.h
http://pastebin.com/dfBZZMjW

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

UPDATE

tinkered with the code and it "works" It doesn't comply with my desktop pc running windows, but I plugged it into my macbook and "most" of the keys work. Some feel a bit funny but i assume the contacts need to be cleaned as these were salvaged keys. The ones that dont work have poor connections from where ive broken the contact from the column wire (I ran out of flux for a decent solder)

That aside, what could be causing it to play up on my pc but not my mac?

Andster29

12 Jul 2016, 04:12

hasu wrote: Hmm, infomation given is not enough, in particular when you don't know the cuase.
1) Post pics of your keyboard; all over appearance, upside and downside of internal(PCB or hand wiring) at least.(we never can see your *custom* keyboard without pics)
2) Show your schematic of circuit if possible(handwriting is no problem). Or your key matrix table at least.
3) Show all of your code used to build your firmware; set up your repository in github.com(preferable) or other service you like.
4) Describe your problem more deail. Can you describe procedure to get undesired '8'? Can you reporduce the problem? Or it seems to be completely "random" without rules?

EDIT: Your English is no problem if you can read my Engrish :D
I have been trying to build a 60% keyboard before I return to school in 2 days. I finally got the programming stage and I am stuck. I'm a hardware guy. Code and I don't go together well. I tried the programming myself and got the matrix file adjusted. When I try to compile I get the error below.
Error
Error
Error.PNG (70.12 KiB) Viewed 1677 times
I have also added a picture of the back of my keyboard. Sorry for the mess. If anybody has wired their keyboard the same, the .hex file would be greatly appreciated.
Keyboard
Keyboard
Back of Keyboard.jpg (4.57 MiB) Viewed 1677 times
To make it easier, here is my row and column set up.

* col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
* pin: F7 B6 B5 B4 D7 D6 C7 C6 D3 D2 D1 D0 B7 B3

* row: 0 1 2 3 4
* pin: F0 F1 F4 F5 F6

Thank you for the help guys. I will be eternally grateful to anyone who has a solution for me.

User avatar
redesigndavid

12 Jul 2016, 08:18

I'm not very good in debugging c code, but those look like typo errors. It keeps on saying it expects this or that character. If no body else could help, try starting from a fresh working version and make changes bit by bit, and always compiling the code after every change. That way you could spot where it went wrong. Hope that helps!

Andster29

12 Jul 2016, 14:18

redesigndavid wrote: I'm not very good in debugging c code, but those look like typo errors. It keeps on saying it expects this or that character. If no body else could help, try starting from a fresh working version and make changes bit by bit, and always compiling the code after every change. That way you could spot where it went wrong. Hope that helps!
I have tried every version of the tmk firmware. I have also tried compiling a fresh version with nothing changed. Both gave the same error.

User avatar
Laser
emacs -nw

12 Jul 2016, 16:47

Is that a recent version of avr-gcc? (it looks rather old to me - 2010). Maybe that's the problem.

Andster29

12 Jul 2016, 17:22

Laser wrote: Is that a recent version of avr-gcc? (it looks rather old to me - 2010). Maybe that's the problem.
I used the version that came with the tmk firmware from github that is linked on the first page.

User avatar
redesigndavid

13 Jul 2016, 01:32

Andster29 wrote: I used the version that came with the tmk firmware from github that is linked on the first page.
Are you using a teensy? There's a winavr link in this page that the makers of teensy say would have everything you'd need. https://www.pjrc.com/teensy/gcc.html

Andster29

13 Jul 2016, 14:10

redesigndavid wrote:
Andster29 wrote: I used the version that came with the tmk firmware from github that is linked on the first page.
Are you using a teensy? There's a winavr link in this page that the makers of teensy say would have everything you'd need. https://www.pjrc.com/teensy/gcc.html
Yes, I am using a Teensy 2.0

Andster29

14 Jul 2016, 03:52

Laser wrote: Is that a recent version of avr-gcc? (it looks rather old to me - 2010). Maybe that's the problem.
Is there anything that is newer? Can you link me to an install that works on Windows 10 or should I move to Linux?

User avatar
richfiles

19 Jul 2016, 22:28

So, I'm pretty new to C programming. The last time I touched programming was TI-BASIC in the 90s, and TRS-80/Commodore BASIC in the 80s. C is not proving to flow all that intuitively through my tangled jumble of neurons. :roll: No, my profession and life long hobby has always been hardware. I've built walking robots with no CPUs, no software at all. Just hardware. It's what I do, so it comes as no surprise that I'd go all out on the hardware aspect of my keyboard... and run into a brick wall at the software side of things. :?:

So, belive I've successfully defined the rows and columns (first section). I'm now on to the second section, where I need to define the matrix and the key map. I have a question regarding this stage. The following image is my matrix layout, as viewed from above the keyboard.
Keyboard_DZ_75+1_Matrix.png
Keyboard_DZ_75+1_Matrix.png (69.07 KiB) Viewed 1630 times

Code: Select all

/* Column pin configuration
 * col: 0   1   2   3   4   5   6   7   8   9   10  11  12
 * pin: F0  F1  F4  F5  F6  D4  D5  D2  B7  B3  B2  B1  B0

Code: Select all

/* Row pin configuration
 * row: 0   1   2   3   4   5   6
 * pin: F7  B6  B5  B4  C7  C6  D3
I have a VERY dense matrix of 13x7. It was necessary to keep enough I/O pins open for the Caps Lock LED, Backlight LED, pair of I2C pins, and a sense pin. The sense pin and I2C is so it can detect if a yet to be built, magnetically attachable number pad is attached, and whether or not it should poll a port expander over I2C. I figure, software is changeable, so i can re-do code later, once I actually have the number pad built, and have half a clue what the heck I'm actually doing.

Anyway, in order to keep the matrix small, I have a super dense layout with almost no gaps, and row 6 is actually a tight cluster of keys in the top right corner. Only three intersections in the entire matrix go unused (c0-r6, c1-r6, and c12-r4). This means my matrix does not directly conform to the physical key layout in some areas (all of Row 6 is in the top right corner, and the bottom row is "electrically" compressed to one side, and then includes the bottom right corner keys as well).

What I want to know, is where the matrix definitions need to be ordered by electrical sequence, or if the values are arbitrary, and allow for physical sequence (as long as the values are correctly defined). The obviously functional way is to lay the matrix out electrically. This seems to be what's assumed.

My question then is which (if either, or both, or neither, or 42 :mrgreen: ) would be correct?

Electrically based layout:

Code: Select all

#define KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, \
    K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, \
    K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B,     \
    K50, K51, K52, K53, K54, K55, K56, K57, K58, K59, K5A, K5B, K5C, \
              K62, K63, K64, K65, K66, K67, K68, K69, K6A, K6B, K6C  \
) { \
    { 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_##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_##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_##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_##K40, KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47, KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_NO    }, \
    { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57, KC_##K58, KC_##K59, KC_##K5A, KC_##K5B, KC_##K5C }, \
    { KC_NO,    KC_NO,    KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_##K66, KC_##K67, KC_##K68, KC_##K69, KC_##K6A, KC_##K6B, KC_##K6C }  \
}
or...

Physically based layout

Code: Select all

#define KEYMAP( \
    K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K62, K6B, K6C, K65, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K63,      K69, K6A, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K64,      K67, K68, \
    K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C,           K5C, K66, \
    K40,      K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B,           K5A, K5B, \
    K50, K51, K52,                K53,                K54, K55, K56,      K57, K58, K59  \
) { \
    { 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_##K62, KC_##K6B, KC_##K6C, KC_##K65 }, \
    { 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_##K63, KC_NO,    KC_##K69, KC_##K6A }, \
    { 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_##K64, KC_NO,    KC_##K67, KC_##K68 }, \
    { 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_NO,    KC_NO,    KC_##K5C, KC_##K66 }, \
    { KC_##K40, KC_NO,    KC_##K41, KC_##K42, KC_##K43, KC_##K44, KC_##K45, KC_##K46, KC_##K47, KC_##K48, KC_##K49, KC_##K4A, KC_##K4B, KC_NO,    KC_NO,    KC_##K5A, KC_##K5B}, \
    { KC_##K50, KC_##K51, KC_##K52, KC_NO,    KC_NO,    KC_NO,    KC_##K53, KC_NO,    KC_NO,    KC_NO,    KC_##K54, KC_##K55, KC_##K56, KC_NO,    KC_##K57, KC_##K58, KC_##K59 }  \

}
My question is, are the values entered into the table above dependent on position in the list, or just by content. It'd be FAR easier to follow the second layout, but I don't know if it screws with the code to mix and match rows and columns like that, or whether it's all good, as long as the numbers match.

Basically, is the code expecting all the rows and columns to be in a neat and orderly incrementing layout (all the columns, in order, 0 to the maximum, for row one, then repeating for row two, and so on), or is this list arbitrarily defining the intersection values based not he numbers entered (arbitrarily defining what key labels are to be used for each matrix intersection, without regard to were in the list the sit, so long as row and column numbers match up)?

Does that make sense? :?:

I suppose I should add, I know software is flexible, and I can always integrate new features later on. For now, i just wanna get my keyboard up and running. Int he long term though, I want to have the code check whether a pin (E6) changes states. Depending on whether it is high or low, I want to have it scan a 6x6 matrix on a port expander connected over I2C, or to skip the I2C part of the code and ignore that part of the matrix. I don't yet know how I would go about doing this in the code, and I don't even know if this firmware can be modded to support it at all. Of course, that's the nice thing about software... There's always room for change.

I also have transistor driven LEDs in each switch housing, to under-light the keys (the keys are opaque, so no backlighting, sadly). It's just a single channel for the entire keyboard. I haven't gotten far enough through the tutorial to get to backlight controls, but I skimmed the posts and saw people controlling backlights, so I suppose that should be simple. I just want to have a default max brightness setting at power up, and the option to change the brightness with the keyboard.
Attachments
Keyboard_DZ_75+1_Top.jpg
Keyboard_DZ_75+1_Top.jpg (411.13 KiB) Viewed 1630 times
Keyboard75+1WireLacingFinal.jpg
Keyboard75+1WireLacingFinal.jpg (411.7 KiB) Viewed 1630 times

User avatar
MassivFotze

23 Jul 2016, 14:43

I'm having the problem where when you press a key, it also outputs all the other keys in that column (ie, pressing "a" outputs 1qaz). However, this only affects my 1st, 3rd, and 4th rows. My 2nd and 5th rows behave like they should. I went over my wiring and can't tell anything that is wrong (ie diodes are in the right direction). As far as I could tell, the problematic rows look identical to the working rows.

If it helps, here are my matrix.c and keymap_common.h files.

matrix.c

Code: Select all

/*
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
 * pin: B6  B5  B4  D7  C6  D3  D2  D1  D0  B7  B3  B2  B1  B0  (Rev.A)
 * pin:                                 B7                      (Rev.B)
 */
static void  init_cols(void)
{
	// Input with pull-up(DDR:0, PORT:1)
	DDRB  &= ~(1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
	PORTB |=  (1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
	DDRC  &= ~(1<<6);
	PORTC |=  (1<<6);
	DDRD  &= ~(1<<7 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
	PORTD |=  (1<<7 | 1<<3 | 1<<2 | 1<<1 | 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)) |
	   (PIND&(1<<7) ? 0 : (1<<3)) |
	   (PINC&(1<<6) ? 0 : (1<<4)) |
	   (PIND&(1<<3) ? 0 : (1<<5)) |
	   (PIND&(1<<2) ? 0 : (1<<6)) |
	   (PIND&(1<<1) ? 0 : (1<<7)) |
	   (PIND&(1<<0) ? 0 : (1<<8)) |
	   (PINB&(1<<7) ? 0 : (1<<9)) |
   	   (PINB&(1<<3) ? 0 : (1<<10)) |
	   (PINB&(1<<2) ? 0 : (1<<11)) |
	   (PINB&(1<<1) ? 0 : (1<<12)) |
   	   (PINB&(1<<0) ? 0 : (1<<13));
	  
}

/* Row pin configuration
 * row: 0   1   2   3   4
 * pin: F1  F4  F5  F6  F7
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRF  &= ~0b01001111;
    PORTF &= ~0b01001111;
}

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

Code: Select all

/*
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, K08, K09, K0A, K0B, K0C, K0D, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A,      K2C, K2D, \
    K30,      K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B,      K3D, \
    K40, K41, K42,                K46,                K4A, K4B, K4C, K4D  \
) { \
    { 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_##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_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27, KC_##K28, KC_##K29, KC_##K2A, KC_NO,    KC_##K2C, KC_##K2D }, \
    { KC_##K30, KC_NO,    KC_##K32, KC_##K33, KC_##K34, KC_##K35, KC_##K36, KC_##K37, KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_NO,    KC_##K3D }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_NO,    KC_NO,    KC_NO,	  KC_##K46, KC_NO,    KC_NO,    KC_NO,    KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D }  \
}


#endif

hihihi8

21 Aug 2016, 12:13

Hi guys, first time here. I've been working on my own custom CAD-usage keyboard, and so far i've been able to get everything working except for the 15th Column. The layout of the keyboard is near fullsize (101keys), and so i've had to do a lot of weird wiring of traces in order to meet the I/O pin count of the teensy, thus confusing myself.. haha..

Pics for a general idea of layout first:
Image

Those are the columns of the PCB, flipped. it is a custom PCB, and the numpad is on the left for easy CAD value inputs.

Previously, Column 16 as a whole would not work, and would only be activated by keypressing column 15, and so I added the 1UL<<16 to my matrix.c, fixing column 16, but the issue with column 15 did not go away.

heres my config.h

Code: Select all

/* key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 17
my matrix.c

Code: Select all

/* Column pin configuration
 * col: 0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16
 * pin: F0  F1  F5  B5  D7  D4  F4  F6  F7  B6  B2  B4  D5  C7  D3  D2  D0
*/
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<0 | 1<<1 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
    PORTF |=  (1<<0 | 1<<1 | 1<<4 | 1<<5 | 1<<6 | 1<<7);
    DDRD  &= ~(1<<0 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<7);
    PORTD |=  (1<<0 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<7);
    DDRC  &= ~(1<<7);
    PORTC |=  (1<<7);
    DDRB  &= ~(1<<2 | 1<<4 | 1<<5 | 1<<6);
    PORTB |=  (1<<2 | 1<<4 | 1<<5 | 1<<6);
}

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

/* Row pin configuration
 * row: 0   1   2   3   4   5
 * pin: B1  B3  B7  R4  R5  R6
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRD  &= ~0b00000010;
    PORTD &= ~0b00000010;
    DDRB  &= ~0b10001011;
    PORTB &= ~0b10001011;
    DDRC  &= ~0b01000000;
    PORTC &= ~0b01000000;
}

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

Code: Select all

#define KEYMAP( \
         K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F, K1G, \
    K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2C, K2D, K2E, K2F, K2G, \
    K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D, K3E, K3F, K3G, \
    K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B, K4C, K4D, K4E, K4F, K4G, \
    K50, K51, K52, K53, K54, K55, K56, K57, K58, K59, K5A, K5B, K5C, K5D, K5E, K5F, K5G  \
) { \
    { 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_##K0G }, \
    { 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_##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_##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_##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_##K4G }, \
    { KC_##K50, KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57, KC_##K58, KC_##K59, KC_##K5A, KC_##K5B, KC_##K5C, KC_##K5D, KC_##K5E, KC_##K5F, KC_##K5G }  \
}
and finally my keymap_poker.c

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* 0: qwerty */
    KEYMAP(RGHT, DOWN, LEFT, RCTL, APP, RGUI, RALT, SPC, PPLS, PMNS, LALT, LGUI, LCTL, P0, PDOT, PENT, \
           END, UP, RSFT, SLSH, DOT, COMM, M, N, B, V, C, X, Z, LSFT, P3, P2, KP_1, \
           DEL, ENT, QUOT, SCLN, L, K, J, H, G, F, D, S, A, CAPS, P6, P5, P4, \
           BSLS, RBRC, LBRC, P, O, I, U, Y, T, R, E, W, Q, TAB, P9, P8, P7, \
           BSPC, EQL, MINS, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, GRV, NLCK, SLSH, PAST, \
           PGDOWN, F12, F11, F10, F9, F8, F7, F6, F5, F4, F3, F2, F1, ESC, INS, HOME, PGUP),
};
const uint16_t PROGMEM fn_actions[] = {
};
I have used a multimeter to check all connections, and there seems to be no short between col 15 and 16 so please tell me if you see anything wrong with the code. I can post more pics if needed, I don't have a schematic, but basically the schematic is: rows connected so that each row contains 17 keys (with exception of bottom row having 16), and 17 columns, making sure that each column touches each row only once. Thanks!

dohmain

01 Sep 2016, 04:56

:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :evilgeek: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek:
Last edited by dohmain on 26 Oct 2016, 06:31, edited 1 time in total.

Post Reply

Return to “Workshop”