TMK keyboard firmware collection

User avatar
snacksthecat
✶✶✶✶

13 Oct 2018, 22:04

Sorry, I never got around to doing the leafspring board yet but I will post the keymap here once I do.

I eventually figured out the LED issue with my other keyboard. It turned out I had it wired incorrectly. After I fixed the wiring issue, it worked perfectly with that snippet.

Thank you for this great software!

User avatar
snacksthecat
✶✶✶✶

06 Jan 2019, 00:32

I have an IBM model M industrial with an integrated mouse nub thingy. Could anyone point me in the right direction for getting that two work with TMK? I haven't been able to figure it out so far. Also, would it be possible to use a single microcontroller or would it require two? Thanks!

User avatar
snacksthecat
✶✶✶✶

06 Jan 2019, 20:35

Update: I got just the trackpoint working with the "onekey" configuration. But still unsure about how I would enable this feature in addition to using the "ps2_usb" converter. It seems like the converter and the ps2 mouse support both use the same pin definitions. My main question now is whether I'd need to use two microcontrollers or if it's possible to do both on the same chip.

User avatar
hasu

08 Jan 2019, 04:06

Current firmeware(ps2_interrupt.c) doesn't support two instances of PS/2 device(keyboard and mouse) unfortunately. I believe it is possible to support the two PS/2 devices with some fixes on the related source codes, though. You will have to parameterize clock and data pin configuration to give to PS/2 initialization function.

trey1901

12 Jan 2019, 05:37

was able to fix some errors still need some help here are current error codes, posted in another forum this one was linked there and seemed more active!
Spoiler:

Code: Select all

Trey@GHOST MINGW64 ~/qmk_firmware/tmk_keyboard-master/keyboard/gh60
$ make -f Makefile


avr-gcc.exe (AVR_8_bit_GNU_Toolchain_3.6.1_1752) 5.4.0
Copyright (C) 2015 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.


mkdir -p obj_gh60_lufa
Compiling C: keymap_poker.c
avr-gcc -c -mmcu=at90usb1287 -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 -DVERSION=preonic-1.0-7068-g9c2d77612-dirty -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
In file included from keymap_poker.c:1:0:
keymap_common.h:46:147: error: 'KC_' undeclared here (not in a function)
     { KC_##K40, KC_##K41, KC_##K42, KC_NO,    KC_##K44,    KC_NO, KC_NO,    KC_NO,    KC_NO,    KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E }  \
                                                                                                                                                   ^
keymap_poker.c:5:5: note: in expansion of macro 'KEYMAP'
     KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,\
     ^
keymap_common.h:46:147: warning: excess elements in array initializer
     { KC_##K40, KC_##K41, KC_##K42, KC_NO,    KC_##K44,    KC_NO, KC_NO,    KC_NO,    KC_NO,    KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E }  \
                                                                                                                                                   ^
keymap_poker.c:5:5: note: in expansion of macro 'KEYMAP'
     KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,\
     ^
keymap_common.h:46:147: note: (near initialization for 'keymaps[0][4]')
     { KC_##K40, KC_##K41, KC_##K42, KC_NO,    KC_##K44,    KC_NO, KC_NO,    KC_NO,    KC_NO,    KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E }  \
                                                                                                                                                   ^
keymap_poker.c:5:5: note: in expansion of macro 'KEYMAP'
     KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,\
     ^
make: *** [../../tmk_core/rules.mk:557: obj_gh60_lufa/keymap_poker.o] Error 1
here is my poker.c file
Spoiler:

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,BSLS, \
        CAPS,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,     ENT, \
        LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,          RSFT,UP, \
        LCTL,LGUI,LALT,          SPC,                     RALT,RCTL,GRV, LEFT,DOWN,RGHT,),
};

const uint16_t PROGMEM fn_actions[] = {

};
here is the config file
Spoiler:

Code: Select all

#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 14

/* 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
and finally the keymap common file
Spoiler:

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, 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, K2C, \
    K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3B, K3C, K3D,\
    K40, K41, K42,      K44,                     K49, K4A, K4B, K4C, K4D, K4E \
) { \
    { 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_##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_##K3D }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_NO,    KC_##K44,    KC_NO, KC_NO,    KC_NO,    KC_NO,    KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E }  \
}

/* ANSI variant. 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
will still be trying to solve it but any help would be great!

User avatar
hasu

12 Jan 2019, 06:07

Parameters of KEYMAP in your poker.c doesn't match for keymap common.
Check fourth line and the last(fifth) line of your KEYMAP().

trey1901

12 Jan 2019, 08:01

hasu wrote:
12 Jan 2019, 06:07
Parameters of KEYMAP in your poker.c doesn't match for keymap common.
Check fourth line and the last(fifth) line of your KEYMAP().
okay now i seem to get an error about my matrix file
Spoiler:

Code: Select all

atrix.o.d  matrix.c -o obj_gh60_lufa/matrix.o
matrix.c: In function 'read_cols':
matrix.c:128:41: error: expected expression before ')' token
            (PINF&(1<<7) ? 0 : (1<<14)) |);
                                         ^
matrix.c:128:41: error: expected statement before ')' token
matrix.c:129:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make: *** [../../tmk_core/rules.mk:557: obj_gh60_lufa/matrix.o] Error 1
here is the matrix file with lines mentioned
Spoiler:

Code: Select all

/* Column pin configuration
 * col: 0   1   2   3   4   5   6   7   8   9   10 11 12 13 14
 * pin: B6  B5  B4  B3  B2  B1  B0  E7  E6  F0  F1 F2 F3 F4 F7  (Rev.A)
 * pin:                                 B7                      (Rev.B)
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<1 | 1<<0);
    PORTF |=  (1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<1 | 1<<0);
    DDRE  &= ~(1<<7 | 1<<6);
    PORTE |=  (1<<7 | 1<<6);
    DDRC  &= ~(1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3);
    PORTC |=  (1<<7 | 1<<6 | 1<<5 | 1<<4 | 1<<3);
    DDRB  &= ~(1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<1 | 1<<0);
    PORTB |=  (1<<6 | 1<<5 | 1<<4 | 1<<3 | 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)) |
           (PINB&(1<<3) ? 0 : (1<<3)) |
           (PINB&(1<<2) ? 0 : (1<<4)) |
           (PINB&(1<<1) ? 0 : (1<<5)) |
           (PINB&(1<<0) ? 0 : (1<<6)) |
           (PINE&(1<<7) ? 0 : (1<<7)) |
           (PINE&(1<<6) ? 0 : (1<<8)) |     
           (PINF&(1<<0) ? 0 : (1<<9)) |
           (PINF&(1<<1) ? 0 : (1<<10)) |
           (PINF&(1<<2) ? 0 : (1<<11)) |
           (PINF&(1<<3) ? 0 : (1<<12)) |
           (PINF&(1<<4) ? 0 : (1<<13)) |
           (PINF&(1<<7) ? 0 : (1<<14)) |);
}

/* Row pin configuration
 * row: 0   1   2   3   4
 * pin: C3  C4  C5  C6  C7
 */
static void unselect_rows(void)

trey1901

12 Jan 2019, 08:11

well i got it to compile, but it doesnt type just random stings of letters and shit.

trey1901

12 Jan 2019, 09:44

trey1901 wrote:
12 Jan 2019, 08:11
well i got it to compile, but it doesnt type just random stings of letters and shit.
if someone would like to look at my files and maybe see if they can tell that'd be great cause im sorta at a loss.

config
Spoiler:

Code: Select all

#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 14

/* 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
keymap common
Spoiler:

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, 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, K2C, \
    K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A,      K3C, K3D,\
    K40, K41, K42,      K44,                     K49, K4A, K4B, K4C, K4D, K4E \
) { \
    { 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_##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_NO,    KC_##K3C, KC_##K3D }, \
    { KC_##K40, KC_##K41, KC_##K42, KC_NO,    KC_##K44,    KC_NO, KC_NO,    KC_NO,    KC_NO,    KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D, KC_##K4E }  \
}

/* ANSI variant. 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
Spoiler:

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,BSLS, \
        CAPS,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,ENT,    \
        LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,     RSFT, UP, \
        LCTL,LGUI,LALT,     SPC,                     RALT,RCTL,GRV, LEFT,DOWN,RIGHT),
};

const uint16_t PROGMEM fn_actions[] = {

};
and the matrix
Spoiler:

Code: Select all

#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);


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

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

/* Column pin configuration
 * col: 0   1   2   3   4   5   6   7   8   9   10 11 12 13 14
 * pin: B6  B5  B4  B3  B2  B1  B0  E7  E6  F0  F1 F2 F3 F4 F7  (Rev.A)
 * pin:                                 B7                      (Rev.B)
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
	DDRB  &= ~(1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    PORTB |=  (1<<6 | 1<<5 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    DDRE  &= ~(1<<7 | 1<<6);
    PORTE |=  (1<<7 | 1<<6);
	DDRF  &= ~(1<<7 | 1<<4 | 1<<3 | 1<<2 | 1<<1 | 1<<0);
    PORTF |=  (1<<7 | 1<<4 | 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)) |
           (PINB&(1<<3) ? 0 : (1<<3)) |
           (PINB&(1<<2) ? 0 : (1<<4)) |
           (PINB&(1<<1) ? 0 : (1<<5)) |
           (PINB&(1<<0) ? 0 : (1<<6)) |
           (PINE&(1<<7) ? 0 : (1<<7)) |
           (PINE&(1<<6) ? 0 : (1<<8)) |     
           (PINF&(1<<0) ? 0 : (1<<9)) |
           (PINF&(1<<4) ? 0 : (1<<10)) |
           (PINF&(1<<3) ? 0 : (1<<11)) |
           (PINF&(1<<2) ? 0 : (1<<12)) |
           (PINF&(1<<1) ? 0 : (1<<13)) |
           (PINF&(1<<7) ? 0 : (1<<14));
}

/* Row pin configuration
 * row: 0   1   2   3   4
 * pin: C3  C4  C5  C6  C7
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRC  &= ~0b01111100;
    PORTC &= ~0b01111100;
}

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

User avatar
snacksthecat
✶✶✶✶

12 Jan 2019, 20:00

hasu wrote:
08 Jan 2019, 04:06
Current firmeware(ps2_interrupt.c) doesn't support two instances of PS/2 device(keyboard and mouse) unfortunately. I believe it is possible to support the two PS/2 devices with some fixes on the related source codes, though. You will have to parameterize clock and data pin configuration to give to PS/2 initialization function.
Thank you! I'll give it a shot

User avatar
Muirium
µ

15 Jan 2019, 05:35

Hey Hasu (and anyone else with more clues than me!),

Here's my current HHKB layout in Unimap. I'm trying to add an integrated numpad mode (like my Realforce 87U) and even some mouse keys while I'm at it. The mystery is how best to access those layers. Here's what I'm trying: a whole line of layer shortcuts along the unused ZXC and V keys in Layer 1:

Screenshot 2019-01-14 at 8.29.36 pm.png
Screenshot 2019-01-14 at 8.29.36 pm.png (42.31 KiB) Viewed 17925 times
What I'd really like is to fall back to Layer 0 whenever I want to get out of numpad or mouse modes. But layer toggles don't work like that. They seem to be a stack where you pop things on and off. But I don't want to wind up "stuck" in numpad mode or mouse mode, or indeed a hybrid of both, which is what it feels like using this! I don't want to memorise the "route" I took to get to a given state.

I'd much rather have a sanity key that takes me back to layer 0 and the HHKB I love! Any idea how to do that?

User avatar
hasu

15 Jan 2019, 06:46

Can't you disable the numpad and mouse layer with pressing L1+{C, V}?
Layer1 is disabled when you release L1(on layer 0), so Toggle keys(T*) on Layer1 is not available on Layer2(numpad) and 3(mouse) without pressing L1.

Or you want to place real toggle keys on those layers instead of 'TRNS' so that you can press just C and V without L1 to leave the layer?

User avatar
Muirium
µ

15 Jan 2019, 07:06

Hi Hasu! Strange things happen…

Just now, for instance, I noticed your reply in the Forum Spy, so I toggled the mouse keys layer with Fn + V to mouse over and click the link to this thread. Which worked fine.

Then I tried to get back to Layer 0 to write this response. But I couldn't! I was stuck in mouse keys. I could only disable them with a power cycle of the keyboard. Let's try a numpad example…

So I'm in Layer 0. I press Fn + C to enter Layer 2: numpad. 123456789. I press Fn + C again to exit it. Works good. But what I really want is to tell the keyboard where I want to *go*, not to "undo where I am". So let's try that. I press Fn + C 987654321 And then Fn = wa5t a 05n45t+ No, needs to be Fn + C. Fn + Z actually puts me in a weird hybrid layer where, as you can see, the keys specified in the numpad layer act as a numpad while the others are still regular alphas; falling back to TRNS I suppose. The only way to escape this is by popping the stack with Fn + C, not Z.

Real problems begin when I've already switched layers a few times. That's when I can get completely trapped, I guess because I'm adding *more* layers to the stack by toggling them off in an incorrect sequence. It's very weird when you wind up trapped!


Edit: I get what you're saying about putting layer toggle keys inside the alternate layers. I tried that with Z always being T0 on every layer. Didn't seem to help.

What I'd really like is to change (with layers) what the Fn key does. Because to me it feels more natural holding Fn when using the mouse keys and numpad. And whenever Fn is not pressed? Layer 0, of course. Perhaps I'm looking for Fn + C <hold Fn> press keys for numpad function <release Fn> return to normal HHKB Layer 0; with subsequent presses of Fn going back to Layer 1 as usual.

User avatar
hasu

15 Jan 2019, 09:13

Muirium wrote:
15 Jan 2019, 07:06
Hi Hasu! Strange things happen…

Just now, for instance, I noticed your reply in the Forum Spy, so I toggled the mouse keys layer with Fn + V to mouse over and click the link to this thread. Which worked fine.

Then I tried to get back to Layer 0 to write this response. But I couldn't! I was stuck in mouse keys. I could only disable them with a power cycle of the keyboard. Let's try a numpad example…
How did you leave the mouse keys layer?
I assume you used Fn+V, this doesn't work for you? This shouldn't be stuck in the layer.

Or You are using T0? No, T0 doens't work like that and it is not useful at all in most use cases. I don't think using T0 is harmful here, though.

So I'm in Layer 0. I press Fn + C to enter Layer 2: numpad. 123456789. I press Fn + C again to exit it. Works good. But what I really want is to tell the keyboard where I want to *go*, not to "undo where I am". So let's try that. I press Fn + C 987654321 And then Fn = wa5t a 05n45t+ No, needs to be Fn + C. Fn + Z actually puts me in a weird hybrid layer where, as you can see, the keys specified in the numpad layer act as a numpad while the others are still regular alphas; falling back to TRNS I suppose. The only way to escape this is by popping the stack with Fn + C, not Z.
I'm still not completely sure but probably you want to use 'ACTION_LAYER_SET(layer, on)' to enable a layer at a time. Unfortunately the action is not support in Keymap Editor at this point, you have write keymapping file and build firmware from source.
https://github.com/tmk/tmk_core/blob/ma ... -set-layer

Real problems begin when I've already switched layers a few times. That's when I can get completely trapped, I guess because I'm adding *more* layers to the stack by toggling them off in an incorrect sequence. It's very weird when you wind up trapped!


Edit: I get what you're saying about putting layer toggle keys inside the alternate layers. I tried that with Z always being T0 on every layer. Didn't seem to help.

What I'd really like is to change (with layers) what the Fn key does. Because to me it feels more natural holding Fn when using the mouse keys and numpad. And whenever Fn is not pressed? Layer 0, of course. Perhaps I'm looking for Fn + C <hold Fn> press keys for numpad function <release Fn> return to normal HHKB Layer 0; with subsequent presses of Fn going back to Layer 1 as usual.
You may find useful actions in this document for your needs, otherwise, you will have to write you own function for the key.
https://github.com/tmk/tmk_core/blob/ma ... /keymap.md

User avatar
Muirium
µ

15 Jan 2019, 09:33

Thanks for the pointers, Hasu. I may get good and nerdy and redefine the Fn key for real, someday…

For now, I'm using this keymap which is working better. I changed Z in the other layers to ACTION_LAYER_CLEAR in Unimap's Code tab. That actually shows up as ACTION_LAYER_BIT_AND but works as I thought: the layer toggles are dropped and you're back in Layer 0. I don't seem to be getting "lost" now, phew!

Incidentally, I'm doing all this firmware flashing with QMK Toolbox. Works great. A much friendlier GUI experience for me.

User avatar
Muirium
µ

16 Jan 2019, 02:22

All right! Here's today's fresh attempt, this time using tap layers:

Screenshot 2019-01-15 at 5.17.03 pm.png
Screenshot 2019-01-15 at 5.17.03 pm.png (29.3 KiB) Viewed 17857 times
LT = layer tap. The key works like normal, unless held down in which case it becomes an Fn key for a whole other layer.

Works really nicely! Hasu's link to the documentation got me reading about tap keys, and the example in there using semicolon as a second function key made me try the same. Brilliant! So now ; = mouse key layer, and ' = numpad layer. Those two keys are well placed and aren't alphas I often need to type quickly in succession. So far so nifty.

User avatar
Hypersphere

25 Jan 2019, 20:54

Has anyone here tried the 3D printed enclosure for the Hasu USB to USB converter? I had mine printed recently. It does not fit the converter with the shrink wrap installed. I assume it is meant to fit the bare converter with no shrink wrap. Is this so? Thanks.

User avatar
Muirium
µ

20 Feb 2019, 14:09

Hasu, I’d like to use the Num Lock LED on an AEK with your ADB converter (running on a Teensy 2). The keyboard has the light but Macs have no use for it. I’d like to tie that LED to a layer—like mouse emulation mode—so it’s a useful layer indicator.

Possible? I don’t see anything on Unimap about controlling LEDs. Ideally, Num Lock and Scroll Lock could both be controlled.

User avatar
hasu

20 Feb 2019, 22:50

Unimap itself doesn't support custom control of keyboard LEDs. By default TMK firmware controls the indicators with led_set() in led.c depending on request from host computer.

You have to write C code in you unimap/keymap file.
You can control keyboard indicators on ADB keyboard using 'adb_host_kbd_led()' in adb.c.
https://github.com/tmk/tmk_keyboard/blo ... adb.c#L174

And you can know when layer changes with hook_layer_change() in hook.h.
https://github.com/tmk/tmk_keyboard/blo ... hook.h#L61

User avatar
Hypersphere

20 Feb 2019, 22:57

@hasu: I've been using your splendid USB-USB converter with my new RF R2 TKL PFE Edition keyboard. It works fine, but when I reboot my Win 10 computer, I then have to unplug the converter from the computer and replug it in order for the keyboard to function. Is this normal for the USB-USB converter, or is it a quirk of this new R2 keyboard in not working entirely correctly with the converter?

User avatar
hasu

20 Feb 2019, 23:09

Hypersphere wrote:
20 Feb 2019, 22:57
@hasu: I've been using your splendid USB-USB converter with my new RF R2 TKL PFE Edition keyboard. It works fine, but when I reboot my Win 10 computer, I then have to unplug the converter from the computer and replug it in order for the keyboard to function. Is this normal for the USB-USB converter, or is it a quirk of this new R2 keyboard in not working entirely correctly with the converter?
No, I'd expect that the converter works well across reboots. I'll look into this later.
The issue happens only with the Realforce R2? Can you try with other keyboard?

User avatar
Hypersphere

21 Feb 2019, 00:44

hasu wrote:
20 Feb 2019, 23:09
Hypersphere wrote:
20 Feb 2019, 22:57
@hasu: I've been using your splendid USB-USB converter with my new RF R2 TKL PFE Edition keyboard. It works fine, but when I reboot my Win 10 computer, I then have to unplug the converter from the computer and replug it in order for the keyboard to function. Is this normal for the USB-USB converter, or is it a quirk of this new R2 keyboard in not working entirely correctly with the converter?
No, I'd expect that the converter works well across reboots. I'll look into this later.
The issue happens only with the Realforce R2? Can you try with other keyboard?
I tried with another keyboard, a WASD TKL USB keyboard. The same thing happened as with the RF R2. It also happens with a PC running Linux as well as a Mac Pro running Windows 10. It also happens with a Northgate PS/2 using an Adesso active PS/2 to USB converter and then the Hasu USB-USB converter.

Maybe the problem is due to the fact that I am not connecting the Hasu USB-USB converter directly to the computers. Instead, I am connecting through a KM switch and several USB Hubs. I will try again with a direct connection to the computer and report back.

Okay, I have now tried connecting the converter directly to the computer, but I have the same problem. If I reboot, I need to unplug and replug the converter into the computer in order for the keyboard to work. This is with both a WASB keyboards keyboard and the RF R2 keyboard.

Luckily, I can do this via the KM switch and several hubs as well -- this makes unplugging and replugging easier, because the hubs are easier to reach than the computer in my setup.

User avatar
hasu

21 Feb 2019, 01:25

hasu wrote:
20 Feb 2019, 23:09
Hypersphere wrote:
20 Feb 2019, 22:57
@hasu: I've been using your splendid USB-USB converter with my new RF R2 TKL PFE Edition keyboard. It works fine, but when I reboot my Win 10 computer, I then have to unplug the converter from the computer and replug it in order for the keyboard to function. Is this normal for the USB-USB converter, or is it a quirk of this new R2 keyboard in not working entirely correctly with the converter?
No, I'd expect that the converter works well across reboots. I'll look into this later.
The issue happens only with the Realforce R2? Can you try with other keyboard?
Ah, OK. I confirmed that issue on my environment, it is not specific to your keyboard or computer.
I'll look into it closely but it may takes long to setup debug fixture to see USB lowlevel activites.

I'll follow up with the issue later in this thread on geekhack.org.
https://geekhack.org/index.php?topic=69 ... msg2726404

User avatar
Hypersphere

21 Feb 2019, 14:32

hasu wrote:
21 Feb 2019, 01:25
hasu wrote:
20 Feb 2019, 23:09
Hypersphere wrote:
20 Feb 2019, 22:57
@hasu: I've been using your splendid USB-USB converter with my new RF R2 TKL PFE Edition keyboard. It works fine, but when I reboot my Win 10 computer, I then have to unplug the converter from the computer and replug it in order for the keyboard to function. Is this normal for the USB-USB converter, or is it a quirk of this new R2 keyboard in not working entirely correctly with the converter?
No, I'd expect that the converter works well across reboots. I'll look into this later.
The issue happens only with the Realforce R2? Can you try with other keyboard?
Ah, OK. I confirmed that issue on my environment, it is not specific to your keyboard or computer.
I'll look into it closely but it may takes long to setup debug fixture to see USB lowlevel activites.

I'll follow up with the issue later in this thread on geekhack.org.
https://geekhack.org/index.php?topic=69 ... msg2726404
Thanks for letting me know. I am relieved that the problem is not specific to my keyboards or computers.

Looking forward to a solution to this when you have had time to look into it.

User avatar
Hypersphere

19 Mar 2019, 00:11

@hasu: Any progress yet on the issue with the USB-USB converter and a RF R2 keyboard not being recognized when rebooting or when using a KM switch to switch among computers that are sharing the keyboard?

I am still finding it necessary to unplug and replug the USB-USB converter whenever I reboot or switch to another computer.

I had wondered if the problem could be due to some sort of signal interference, so I tried putting ferrite cores on the cables on each side of the converter, but this did not help.

Thanks.

User avatar
Hypersphere

24 Mar 2019, 23:06

hasu wrote:
21 Feb 2019, 01:25
hasu wrote:
20 Feb 2019, 23:09
Hypersphere wrote:
20 Feb 2019, 22:57
@hasu: I've been using your splendid USB-USB converter with my new RF R2 TKL PFE Edition keyboard. It works fine, but when I reboot my Win 10 computer, I then have to unplug the converter from the computer and replug it in order for the keyboard to function. Is this normal for the USB-USB converter, or is it a quirk of this new R2 keyboard in not working entirely correctly with the converter?
No, I'd expect that the converter works well across reboots. I'll look into this later.
The issue happens only with the Realforce R2? Can you try with other keyboard?
Ah, OK. I confirmed that issue on my environment, it is not specific to your keyboard or computer.
I'll look into it closely but it may takes long to setup debug fixture to see USB lowlevel activites.

I'll follow up with the issue later in this thread on geekhack.org.
https://geekhack.org/index.php?topic=69 ... msg2726404
@hasu: Today, after a reboot of my Windows 10 machine, I was unable to get the keyboard to work with the USB-USB converter even after unplugging and replugging the converter or rebooting again.

I finally reinstalled Flip and reinstalled my hex file into the converter. Then, after a reboot and unplugging/replugging the converter, I got the keyboard to work again. (BTW, in order to get Flip working again, I had to uninstall it and install the version that is bundled with the Java Runtime. Otherwise, I would get errors saying that no Java virtual machine could be found).

I hope that you are able to fix this problem. I really like the converter when it is working, and I need the remapping in order to use my RF R2 keyboards with the layout that I want to use.

Thanks for your ongoing efforts to solve this problem. I have also posted this on the relevant thread over on GH.

User avatar
hasu

24 Mar 2019, 23:35

@Hypersphere, thanks for the report.
You don't need post both forum. Use thread on Geekhack for USB-USB converter related topic.

User avatar
Hypersphere

24 Mar 2019, 23:51

hasu wrote:
24 Mar 2019, 23:35
@Hypersphere, thanks for the report.
You don't need post both forum. Use thread on Geekhack for USB-USB converter related topic.
Okay. I mostly visit DT these days and visit GH very rarely. However, per your request, I will post USB-USB converter issues on the GH thread for this topic.

User avatar
snacksthecat
✶✶✶✶

05 Jun 2019, 14:59

Hi, I'm hoping someone may be able to help me. I'm facing an issue that I haven't seen before.

I made a PCB that uses atmega32u4 MCU. I built TMK starting from the gh60 project and modifying it to my board.

TMK builds appears to build fine with no warnings. Flashing also looks to be successful, either using Flip or QMK Toolbox. However, when the flash ends and I re-plug the board back into my PC, it's again recognized as atmega32u4 rather than an HID device. So I think TMK is not starting or it is crashing. It looks like this (note I'm using QMK Toolbox as a visual but I don't believe it's a problem with that software).

Image

Some other interesting things that I played around with:
  • If I try flashing to a Teensy instead, I do not have the issue
  • I tried building and flashing with the onekey project and that works fine
  • I tried flashing/using Soarer's controller and that works fine as well
Here are the files for my keyboard:

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


# 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

config.h

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 6
#define MATRIX_COLS 18

/* 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
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);


void matrix_init(void)
{
	
	// debug mode
	debug_enable=true;
	
	// JTAG disable for PORT F. write JTD bit twice within four cycles.
    MCUCR |= (1<<JTD);
    MCUCR |= (1<<JTD);
	
    // 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;
}

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

/* Column pin configuration
 * col: 0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17
 * pin: B0  E6  F0  F1  F4  F5  F6  F7  C7  C6  B6  B5  B4  D7  D6  D4  B2  B3
 */
static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRB  &= ~(1<<0 | 1<<6 | 1<<5 | 1<<4 | 1<<2 | 1<<3);
    PORTB |=  (1<<0 | 1<<6 | 1<<5 | 1<<4 | 1<<2 | 1<<3);
    DDRE  &= ~(1<<6);
    PORTE |=  (1<<6);
    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);
    DDRC  &= ~(1<<7 | 1<<6);
    PORTC |=  (1<<7 | 1<<6);
    DDRD  &= ~(1<<7 | 1<<6 | 1<<4);
    PORTD |=  (1<<7 | 1<<6 | 1<<4);
}

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

/* Row pin configuration
 * row: 0   1   2   3   4   5
 * pin: D5  D3  D2  D1  D0  B7
 */
static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    DDRD  &= ~0b00101111;
    PORTD &= ~0b00101111;
    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<<5);
            PORTD &= ~(1<<5);
            break;
        case 1:
            DDRD  |= (1<<3);
            PORTD &= ~(1<<3);
            break;
        case 2:
            DDRD  |= (1<<2);
            PORTD &= ~(1<<2);
            break;
        case 3:
            DDRD  |= (1<<1);
            PORTD &= ~(1<<1);
            break;
        case 4:
            DDRD  |= (1<<0);
            PORTD &= ~(1<<0);
            break;
        case 5:
            DDRB  |= (1<<7);
            PORTB &= ~(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 "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,      K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D,      K0F, K0G, K0H, \
    K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, \
    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,           \
    K40, K41, K42, K43, K44, K45, K46, K47, K48, K49, K4A, K4B, K4C, K4D, K4E, K4F, K4G,      \
	K50, K51, K52,                K56,                K5A, K5B, K5C,      K5E, K5F, K5G       \
) { \
    { KC_##K00, KC_NO,    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_NO,    KC_##K0F, KC_##K0G, KC_##K0H }, \
    { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17, KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F, KC_##K1G, KC_##K1H }, \
    { KC_##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_NO    }, \
	{ 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_NO,    KC_NO    }, \
    { 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_NO    }, \
    { KC_##K50, KC_##K51, KC_##K52, KC_NO,    KC_NO,    KC_NO,    KC_##K56, KC_NO,    KC_NO,    KC_NO,    KC_##K5A, KC_##K5B, KC_##K5C, KC_NO,    KC_##K5E, KC_##K5F, KC_##K5G, KC_NO    }  \
}


#endif
keymap_poker.c

Code: Select all

#include "keymap_common.h"

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* 0: qwerty */
    KEYMAP(ESC,                F1,     F2,     F3,     F4,     F5,     F6,     F7,     F8,     F9,     F10,        F11,      F12,                            PSCREEN,            NUMLOCK,   PAUSE,\
           GRAVE,     1,       2,      3,      4,      5,      6,      7,      8,      9,      0,      MINUS,      EQUAL,    BSPACE,       BSPACE,           INSERT,             HOME,      PGUP, \
           TAB,       Q,       W,      E,      R,      T,      Y,      U,      I,      O,      P,      LBRACKET,   RBRACKET, BSLASH,       DELETE,           END,                PGDOWN,          \
           CAPSLOCK,  A,       S,      D,      F,      G,      H,      J,      K,      L,      SCOLON, QUOTE,      ENTER,    MEDIA_REWIND, MEDIA_PLAY_PAUSE, MEDIA_FAST_FORWARD,                  \
           LSHIFT,    LSHIFT,  Z,      X,      C,      V,      B,      N,      M,      COMMA,  DOT,    SLASH,      RSHIFT,   RSHIFT,       _VOLDOWN,         UP,                 _VOLUP,          \
           LCTRL,     LGUI,    LALT,                           SPACE,                          RALT,   RGUI,       RCTRL,    LEFT,         DOWN,             RIGHT),             
};
const action_t PROGMEM fn_actions[] = {};
led.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/>.
*/

#include <avr/io.h>
#include "stdint.h"
#include "led.h"


void led_set(uint8_t usb_led)
{

}

User avatar
hasu

05 Jun 2019, 21:51

what's your pcb exactly? And is it really compatible to GH60?

GH60 is used just for promotional word by some vendors these days and some of them don't seem to retain its spirit of openess at all. There seems to be some variants different from original GH60 in the market.

And, try disabling BOOTMAGIC with commenting it out in Makefile. I guess bootmagic may start bootloader at plug-in if the pcb is not compatible to the GH60 code.

Post Reply

Return to “Workshop”