How to build your very own keyboard firmware

TenkaiX

18 Sep 2016, 07:50

Hey!
I'm new to all of this and am currently stuck on creating or making the actual Hex file. I have tried several ways and I still keep getting errors on both PC and Mac. I'm running out of options and was hoping that someone could be nice enough to compile my files <3

User avatar
hypkx
Chasing the Dream

18 Sep 2016, 08:56

The question is what errors you became and have you modified the files?

TenkaiX

18 Sep 2016, 09:03

Well, I have done everything twice. It's saying there is a pathing error or something like that in cmd.
It says:
makefile:132: ../../tmk_core/protocol/lufa.mk: No such file or directory
makefile:133 ../../tmk_core/common.mk: No such file or directory
makefile:134 ../../tmk_core/rules.mk: No such file or directory
make: *** No rule to make targt '../../tmk_core/rules.mk'. Stop.

And yes I have modified the files for my matrix.

User avatar
hypkx
Chasing the Dream

18 Sep 2016, 09:14

Have you copied the project folder out of the main folder? Because the compilation script cant find some needed files.

TenkaiX

18 Sep 2016, 09:15

Not sure what you mean?

Which folder am I taking out of ? Do you mean take the whole gh60 file out of the folder and just keep it separate?

User avatar
hypkx
Chasing the Dream

18 Sep 2016, 09:19

There is a folder with the name tmk kbd master in which every stuff is in. I think you modified the files in gh60 folder? To compile the stuff you need to go in your cmd and run the "make" script. I thought that you copied the gh60 folder outside the tmk master folder, because the script cant find the needed files (which should be in the tmk sub folders) to compile.

TenkaiX

18 Sep 2016, 09:20

I'm so lost. All the my MODIFIED gh60 files are still in the tmk_keyboard-master folder. But it's still giving me the error either way.

TenkaiX

18 Sep 2016, 09:21

When using the cmd make it's giving me that error.

TenkaiX

18 Sep 2016, 09:32

http://imgur.com/a/q9eEV < That's what it looks like.

TenkaiX

18 Sep 2016, 10:06

Don't worry! I found that I was missing a whole folder (tmk_core) and now I just have to fix a bit of coding with the keymap_poker.c where i have undeclared elements ;(

TenkaiX

18 Sep 2016, 11:14

Okay so now I'm stuck again. It's unable to determine if a key is a functionable or not in the keymap_poker.c file.
I tried my code and Matt3o but both came up with the same error. Could someone please try help me solve this, I've been working on this for over 7 hours with no luck.

TenkaiX

18 Sep 2016, 13:56

So I'm getting the (make:*** [gh60_lufa.efl] Error 1. My codes are:

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   
 * pin: F6  F5  F4  F3  F2  F1  F0    (Rev.A)
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    PORTF |=  (1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
}

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

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

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

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 /* 0: qwerty */
    KEYMAP(F1, F2, F3, F4, F5, \
	   1,    2,    3,   4,   BSPC,             P, \
           Q,    W,    E,   R,   T,    	Y,         C, \
           LCTL, S,    D,   F,   G,                B, \
           TAB,  LSFT, A,   V), 

    /* 1: FN 1 */
    KEYMAP(F1,	F2,	F3,	F4,	F5, \
           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),
};
and my
keymap_common.c:

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 "keycode.h"
#include "action.h"
#include "action_macro.h"
#include "report.h"
#include "host.h"
#include "print.h"
#include "debug.h"
#include "keymap.h"


/* GH60 keymap definition macro
 * K2C, K31 and  K3C are extra keys for ISO
 */
#define KEYMAP( \
    K00, K01, K02, K03, K04, \
    K10, K11, K12, K13, K14, 	 	  K17, \
    K20, K21, K22, K23, K24, K25, 	  K27, \
    K30, K31, K32, K33, K34, 	 	  K37, \
    K40, K41, K42, K43  \
) { \
    { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04,	KC_NO,	KC_NO,	KC_NO }, \
    { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_NO,	KC_NO,	KC_##K17 }, \
    { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24,	KC_##K25,	KC_NO,	KC_##K27 }, \
    { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_NO,  KC_NO, KC_##K37 }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_NO,	KC_NO,	KC_NO,	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

Please guys I've been doing this for over 10 hours and still no progress ;(

User avatar
matt3o
-[°_°]-

19 Sep 2016, 16:34

I need to know the exact error you are given

TenkaiX

20 Sep 2016, 01:26

So here is the error that it's giving me:
http://imgur.com/TJykA7I
And these are my files:
http://imgur.com/a/ga6Mz

Hope you can help :) <3

TenkaiX

22 Sep 2016, 03:42

New update on my errors:
I re unpacked the .rar file containing the tmk_keyboard-master files and then replaced the files with mine and I got this error: http://imgur.com/5eOlzzz

Not sure what I'm doing wrong..

User avatar
matt3o
-[°_°]-

22 Sep 2016, 08:51

okay post your keyboard directory, I'll try to compile it here.

User avatar
Wodan
ISO Advocate

22 Sep 2016, 09:12

matt3o wrote: okay post your keyboard directory, I'll try to compile it here.
I wish that kind of support was available in some areas of my daily job, commercially ;)

TenkaiX

22 Sep 2016, 13:05

matt3o wrote: okay post your keyboard directory, I'll try to compile it here.
How do I do that? Do I just post the codes or ? If so here you go:
keymap_common:

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 "keycode.h"
#include "action.h"
#include "action_macro.h"
#include "report.h"
#include "host.h"
#include "print.h"
#include "debug.h"
#include "keymap.h"


/* GH60 keymap definition macro
 * K2C, K31 and  K3C are extra keys for ISO
 */
#define KEYMAP( \
    K00, K01, K02, K03, K04, \
    K10, K11, K12, K13, K14, 	 	  K17, \
    K20, K21, K22, K23, K24, K25, 	  K27, \
    K30, K31, K32, K33, K34, 	 	  K37, \
    K40, K41, K42, K43  \
) { \
    { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04,	KC_NO,	KC_NO,	KC_NO }, \
    { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_NO,	KC_NO,	KC_##K17 }, \
    { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24,	KC_##K25,	KC_NO,	KC_##K27 }, \
    { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_NO,  KC_NO, KC_##K37 }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_##K43, KC_NO,	KC_NO,	KC_NO,	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
keymap_poker:

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
 /* 0: qwerty */
    KEYMAP(F1, F2, F3, F4, F5, \
	   1,    2,    3,   4,   BSPC,             P, \
           Q,    W,    E,   R,   T,    	Y,         C, \
           LCTL, S,    D,   F,   G,                B, \
           TAB,  LSFT, A,   V), 

    /* 1: FN 1 */
    KEYMAP(F1,	F2,	F3,	F4,	F5, \
           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),
};
Makefile:

Code: Select all

#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device.
#                Please customize your programmer settings(PROGRAM_CMD)
#
# make teensy = Download the hex file to the device, using teensy_loader_cli.
#               (must have teensy_loader_cli installed).
#
# make dfu = Download the hex file to the device, using dfu-programmer (must
#            have dfu-programmer installed).
#
# make flip = Download the hex file to the device, using Atmel FLIP (must
#             have Atmel FLIP installed).
#
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
#               (must have dfu-programmer installed).
#
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
#                (must have Atmel FLIP installed).
#
# make debug = Start either simulavr or avarice as specified for debugging, 
#              with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
#                   bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------

# Target file name (without extension).
TARGET = gh60_lufa

# Directory common source filess exist
TMK_DIR = ../../tmk_core

# Directory keyboard dependent files exist
TARGET_DIR = .

# project specific files
SRC =	matrix.c \
	led.c

ifdef KEYMAP
    SRC := keymap_$(KEYMAP).c $(SRC)
else
    SRC := keymap_poker.c $(SRC)
endif

CONFIG_H = config.h


# MCU name
MCU = at90usb1287
#MCU = atmega32u4

# Processor frequency.
#     This will define a symbol, F_CPU, in all source code files equal to the
#     processor frequency in Hz. You can then use this symbol in your source code to
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
#     automatically to create a 32-bit value in your source code.
#
#     This will be an integer division of F_USB below, as it is sourced by
#     F_USB after it has run through any CPU prescalers. Note that this value
#     does not *change* the processor frequency - it should merely be updated to
#     reflect the processor speed set externally so that the code can use accurate
#     software delays.
F_CPU = 16000000


#
# LUFA specific
#
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8

# Input clock frequency.
#     This will define a symbol, F_USB, in all source code files equal to the
#     input clock frequency (before any prescaling is performed) in Hz. This value may
#     differ from F_CPU if prescaling is used on the latter, and is required as the
#     raw input clock is fed directly to the PLL sections of the AVR for high speed
#     clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
#     at the end, this will be done automatically to create a 32-bit value in your
#     source code.
#
#     If no clock division is performed on the input clock inside the AVR (via the
#     CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_USB = $(F_CPU)

# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT


# Boot Section Size in *bytes*
#   Teensy halfKay   512
#   Teensy++ halfKay 1024
#   Atmel DFU loader 4096
#   LUFA bootloader  4096
#   USBaspLoader     2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096


# Build Options
#   comment out to disable the options.
#
BOOTMAGIC_ENABLE = yes	# Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = yes	# Mouse keys(+4700)
EXTRAKEY_ENABLE = yes	# Audio control and System control(+450)
CONSOLE_ENABLE = yes	# Console for debug(+400)
COMMAND_ENABLE = yes    # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes  # Breathing sleep LED during USB suspend
#NKRO_ENABLE = yes	# USB Nkey Rollover - not yet supported in LUFA


# Optimize size but this may cause error "relocation truncated to fit"
#EXTRALDFLAGS = -Wl,--relax

# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TMK_DIR)

include $(TMK_DIR)/protocol/lufa.mk
include $(TMK_DIR)/common.mk
include $(TMK_DIR)/rules.mk
matrix:

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   
 * pin: F6  F5  F4  F3  F2  F1  F0    (Rev.A)
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    PORTF |=  (1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
}

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

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

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

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/>.
*/

#ifndef CONFIG_H
#define CONFIG_H


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

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

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

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

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

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



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

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

/* disable print */
//#define NO_PRINT

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

#endif

Rejerh

22 Sep 2016, 17:37

Hi there!
First of all thanks a lot for the guide it is amazing!

Secondly, I am having a hard time to compile even the unchanged source code (I tried the GH60 and the HHKB). I am running WinAvr on windows 10 (I already updated the 'faulty' .dll mentionned in a previous page). When I execute make -f Makefile I get some weird (at least for me) error in the keymap.c file (or tree.c ?)
ErrorTree.png
Error when Compiling HHKB Same for GH60
ErrorTree.png (72.75 KiB) Viewed 2794 times
Also I created my own layout (a 68%) and when I run the make it gives me the exact same error. I am started to think that there might be something wrong with my version of WinAvr or something like that.
ErrorTreeOwn.png
Same error on my version of the source code
ErrorTreeOwn.png (134.43 KiB) Viewed 2794 times
Could someone please try to compile my folder on a different OS? (I have attached a zip of the folder with my keymap_poker.c, etc.)
Own 68%.zip
My folder with keymap, etc.
(412.5 KiB) Downloaded 58 times
Thanks a lot

TenkaiX

23 Sep 2016, 01:40

You have the same error as me brother.

Rejerh

23 Sep 2016, 03:55

flabbergast wrote: I like to go vanilla with installations, so:

1) Installed cygwin (one package to select on top of the 'recommended' installation is make; I also installed git). This is really an installer. After installation, the "Cygwin64 Terminal" icon drops one into a familiar shell (oh the relief...)

2) Downloaded avr-gcc. That's a zip, so just unpack it somewhere (I used d:\avr-gcc). Add d:\avr-gcc\bin to PATH (google. it's in 'advanced system settings' -> 'environment variables')

After this {EDIT: probably a reboot}, I just downloaded and unpacked tmk_keyboard, go into cygwin shell, cd to tmk_keyboard_master/keyboard/gh60 and run make. Compiles fine.

However Jack Humbert seems to recommend the inferno tools.
Ok, I finally manage to reach this post in my reading of all the posts and this is exactly the problem I was encountering.
Two thumbs up mate, this is the fix for the unstable WinAvr problem under new windowes. Like you mentionned, it would probably be wise if Matteo could tell people under windows to follow your fix!

Thanks a lot!

User avatar
hasu

23 Sep 2016, 11:05

Matt3o, what about removing WinAVR link from the first post?
It seems like many people have problem with WinAVR and report it here and there, while Mac and Linux users seldom do that. I don't think WinAVR is good option anymore.

User avatar
matt3o
-[°_°]-

23 Sep 2016, 11:37

hasu wrote: Matt3o, what about removing WinAVR link from the first post?
It seems like many people have problem with WinAVR and report it here and there, while Mac and Linux users seldom do that. I don't think WinAVR is good option anymore.
yeah that's probably a good idea :)

TenkaiX

23 Sep 2016, 14:03

Soo What am I meant to do?

TenkaiX

23 Sep 2016, 15:05

After trying to do everything in MAC Terminal, I came with these errors. Hopefully someone can help me fix this ;(
I've been working too long on this.
Attachments
Screen Shot 2016-09-23 at 11.04.25 PM.png
Screen Shot 2016-09-23 at 11.04.25 PM.png (250.87 KiB) Viewed 2758 times

axtran

24 Sep 2016, 23:58

TenkaiX wrote:After trying to do everything in MAC Terminal, I came with these errors. Hopefully someone can help me fix this ;(
I've been working too long on this.
Install homebrew, and then use it to install dfu-programmer.


Sent from my iPhone

TenkaiX

25 Sep 2016, 03:41

Im running into too much errors.

TenkaiX

25 Sep 2016, 06:48

Okay,
Progress: Everything was good until I got back to the keymap_common.h and keymap_poker.c
Something in my coding is screwing up the compile as I went through slowly and copied pasted the directory gh60 and kept trying to see if what I add was stopping the compile. Everything was good up to that.
Someone please for the love of god, Look through my code and tell me why I'm getting this.
keymap_common.h:

Code: Select all

 #ifndef KEYMAP_COMMON_H
#define KEYMAP_COMMON_H

#include <stdint.h>
#include <stdbool.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"


/* GH60 keymap definition macro
 * K2C, K31 and  K3C are extra keys for ISO
 */
#define KEYMAP( \
    K00, K01, K02, K03, K04, \
    K10, K11, K12, K13, K14, K16, \
    K20, K21, K22, K23, K24, K25, K26, \
    K30, K31, K32, K33, K34, K36, \
    K40, K41, K42, K43  \
) { \
    { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04 }, \
    { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_NO, KC_##K16 }, \
    { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26 }, \
    { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_NO, KC_##K36 }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_##K43 }  \
}

/* 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
and keymap_poker.c

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    KEYMAP(F1,  F2,   F3,   F4,   F5, \
           1,  2,   3,   4,   5,   P, \
           Q, W,   E,   R,   T,   Y,   C, \
           A, S,   D,   F,   G,   B, \
           V, LCTL, TAB, LSFT),
};
PS: I don't have an function layers. Here are some pictures of my actual designs and what not.
Attachments
Error.png
Error.png (227.62 KiB) Viewed 2650 times
Matrix 3.jpg
Matrix 3.jpg (933.51 KiB) Viewed 2674 times
Matrix 2.jpg
Matrix 2.jpg (805.94 KiB) Viewed 2674 times
Matrix.jpg
Matrix.jpg (933.46 KiB) Viewed 2674 times

Rejerh

25 Sep 2016, 16:31

TenkaiX wrote: Okay,
Progress: Everything was good until I got back to the keymap_common.h and keymap_poker.c
Something in my coding is screwing up the compile as I went through slowly and copied pasted the directory gh60 and kept trying to see if what I add was stopping the compile. Everything was good up to that.
Someone please for the love of god, Look through my code and tell me why I'm getting this.
keymap_common.h:

Code: Select all

 #ifndef KEYMAP_COMMON_H
#define KEYMAP_COMMON_H

#include <stdint.h>
#include <stdbool.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"


/* GH60 keymap definition macro
 * K2C, K31 and  K3C are extra keys for ISO
 */
#define KEYMAP( \
    K00, K01, K02, K03, K04, \
    K10, K11, K12, K13, K14, K16, \
    K20, K21, K22, K23, K24, K25, K26, \
    K30, K31, K32, K33, K34, K36, \
    K40, K41, K42, K43  \
) { \
    { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04 }, \
    { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_NO, KC_##K16 }, \
    { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26 }, \
    { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_##K34, KC_NO, KC_##K36 }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_##K43 }  \
}

/* 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
and keymap_poker.c

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    KEYMAP(F1,  F2,   F3,   F4,   F5, \
           1,  2,   3,   4,   5,   P, \
           Q, W,   E,   R,   T,   Y,   C, \
           A, S,   D,   F,   G,   B, \
           V, LCTL, TAB, LSFT),
};
PS: I don't have an function layers. Here are some pictures of my actual designs and what not.
In your keymap_poker.c, did you remove the following code?

Code: Select all

const action_t PROGMEM fn_actions[] = {
};
I think you have to have it no matter what, even if you don't have FN keys

Rejerh

25 Sep 2016, 16:43

Has anyone attempted to use some sort of backlight with just one PWM pin?
I saw the numerous posts from ROFLmonster which are quite interesting.
Unfortunately I don't understand much of what he did in the part where he manages the led strip and changes the colors and all.

In my current set up I have all my leds connected to the +5V while I have a transistor on a PWM pin (PD7 of the teensy 2.0).
The idea is to change the leds' intensity by changing the frequency at which the transistor opens and closes (pretty simple and classic stuff I think). All leds will have the same intensity but I don't mind at all.

I am not sure where to start. At the moment I have something a bit silly where I have set up the pin (PD7) to HIGH when I press the capslock key. This is allowing to have the keyboard lighted up but I cannot control intensity nor switch it back off without unplugging the keyboard.

Using layers and FN keys like ROFLmonster did sounds like a good idea but I am not sure how to manage the PWM value (Arduino made that really simple with the analogWrite(), not sure how to do that within AVR).

Can someone help me out please?

Post Reply

Return to “Workshop”