From 83314aeb78825394cd420f36b48853fbb5765378 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 26 May 2014 11:20:17 +0900 Subject: [PATCH 01/29] kimera: New branch for kimera --- keyboard/kimera/Makefile | 148 ++++++++++++++++++ keyboard/kimera/Makefile.pjrc | 116 ++++++++++++++ keyboard/kimera/backlight.c | 106 +++++++++++++ keyboard/kimera/config.h | 80 ++++++++++ keyboard/kimera/keymap_common.c | 49 ++++++ keyboard/kimera/keymap_common.h | 253 +++++++++++++++++++++++++++++++ keyboard/kimera/keymap_default.c | 78 ++++++++++ keyboard/kimera/kimera.c | 186 +++++++++++++++++++++++ keyboard/kimera/kimera.h | 186 +++++++++++++++++++++++ keyboard/kimera/led.c | 52 +++++++ keyboard/kimera/matrix.c | 137 +++++++++++++++++ 11 files changed, 1391 insertions(+) create mode 100644 keyboard/kimera/Makefile create mode 100644 keyboard/kimera/Makefile.pjrc create mode 100644 keyboard/kimera/backlight.c create mode 100644 keyboard/kimera/config.h create mode 100644 keyboard/kimera/keymap_common.c create mode 100644 keyboard/kimera/keymap_common.h create mode 100644 keyboard/kimera/keymap_default.c create mode 100644 keyboard/kimera/kimera.c create mode 100644 keyboard/kimera/kimera.h create mode 100644 keyboard/kimera/led.c create mode 100644 keyboard/kimera/matrix.c diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile new file mode 100644 index 00000000..d02ae3a2 --- /dev/null +++ b/keyboard/kimera/Makefile @@ -0,0 +1,148 @@ +#---------------------------------------------------------------------------- +# 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 = kimera_lufa + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC = keymap_common.c \ + matrix.c \ + led.c \ + backlight.c \ + kimera.c + +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_default.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 + +# Additional definitions from command line +ifdef DEFS + OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) +endif + +# 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 +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#PS2_USE_BUSYWAIT = yes +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality +KEYMAP_EX_ENABLE = yes # External keymap in eeprom +KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +BREATHING_LED_ENABLE = yes # Enable breathing backlight + +# Optimize size but this may cause error "relocation truncated to fit" +#EXTRALDFLAGS = -Wl,--relax + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/keyboard/kimera/Makefile.pjrc b/keyboard/kimera/Makefile.pjrc new file mode 100644 index 00000000..5c0aaea2 --- /dev/null +++ b/keyboard/kimera/Makefile.pjrc @@ -0,0 +1,116 @@ +#---------------------------------------------------------------------------- +# 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 = kimera_pjrc + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC = keymap_common.c \ + matrix.c \ + led.c \ + backlight.c \ + kimera.c + +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_poker.c $(SRC) +endif + +CONFIG_H = config.h + + +# MCU name, you MUST set this to match the board you are using +# type "make clean" after changing this, so all files will be rebuilt +MCU = atmega32u4 +#MCU = at90usb1286 + + +# Processor frequency. +# Normally the first thing your program should do is set the clock prescaler, +# so your program will run at the correct speed. You should also set this +# variable to same clock speed. The _delay_ms() macro uses this, and many +# examples use this variable to calculate timings. Do not add a "UL" here. +F_CPU = 16000000 + + +# Boot Section Size in *bytes* +# Teensy halfKay 512 +# Atmel DFU loader 4096 +# LUFA bootloader 4096 +OPT_DEFS += -DBOOTLOADER_SIZE=4096 + +# Additional definitions from command line +ifdef DEFS + OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) +endif + +# 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 +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#PS2_USE_BUSYWAIT = yes +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality +KEYMAP_EX_ENABLE = yes # External keymap in eeprom +KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +BREATHING_LED_ENABLE = yes # Enable breathing backlight + + + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/pjrc.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk diff --git a/keyboard/kimera/backlight.c b/keyboard/kimera/backlight.c new file mode 100644 index 00000000..10564411 --- /dev/null +++ b/keyboard/kimera/backlight.c @@ -0,0 +1,106 @@ +/* +Copyright 2014 Kai Ryu + +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 . +*/ + +#include +#include +#include +#include "backlight.h" +#include "breathing_led.h" +#include "kimera.h" + +#ifdef BACKLIGHT_ENABLE + +void backlight_enable(void); +void backlight_disable(void); +inline void backlight_set_raw(uint8_t raw); + +static const uint8_t backlight_table[] PROGMEM = { + 0, 16, 128, 255 +}; + +/* Backlight pin configuration + * BL: PB5 (D9) + */ +void backlight_enable(void) +{ + // Turn on PWM + BL_DDR |= (1< 0) { + backlight_enable(); + backlight_set_raw(pgm_read_byte(&backlight_table[level])); + } + else { + backlight_disable(); + } +#endif +} + +#ifdef BREATHING_LED_ENABLE +void breathing_led_set_raw(uint8_t raw) +{ + backlight_set_raw(raw); +} +#endif + +inline void backlight_set_raw(uint8_t raw) +{ + OCR1A = raw; +} + +#endif diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h new file mode 100644 index 00000000..cb6ac7c3 --- /dev/null +++ b/keyboard/kimera/config.h @@ -0,0 +1,80 @@ +/* +Copyright 2014 Kai Ryu + +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 . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0x16c0 +#define PRODUCT_ID 0x27db +#define DEVICE_VER 0x0001 +#define MANUFACTURER kai1103@gmail.com +#define PRODUCT Kimera +#define DESCRIPTION t.m.k. keyboard firmware for Kimera + +/* key matrix size */ +#define MATRIX_ROWS 24 +#define MATRIX_COLS 24 + +/* keymap in eeprom */ +#define FN_ACTIONS_COUNT 32 +#define KEYMAPS_COUNT 3 + +/* define if matrix has ghost */ +//#define MATRIX_HAS_GHOST + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCE 5 + +/* number of backlight levels */ +#ifdef BREATHING_LED_ENABLE +#define BACKLIGHT_LEVELS 6 +#else +#define BACKLIGHT_LEVELS 3 +#endif + +/* 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 diff --git a/keyboard/kimera/keymap_common.c b/keyboard/kimera/keymap_common.c new file mode 100644 index 00000000..f4b96bbf --- /dev/null +++ b/keyboard/kimera/keymap_common.c @@ -0,0 +1,49 @@ +/* +Copyright 2014 Kai Ryu + +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 . +*/ +#include "keymap_common.h" + +/* translates key to keycode */ +uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +{ +#ifndef KEYMAP_EX_ENABLE + return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); +#else + return eeconfig_read_keymap_key(layer, key.row, key.col); +#endif +} + +/* translates Fn keycode to action */ +action_t keymap_fn_to_action(uint8_t keycode) +{ + return (action_t) { +#ifndef KEYMAP_EX_ENABLE + .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) +#else + .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) +#endif + }; +} + +#ifdef KEYMAP_EX_ENABLE +const uint8_t* keymaps_pointer(void) { + return (const uint8_t*)keymaps; +} + +const uint16_t* fn_actions_pointer(void) { + return fn_actions; +} +#endif diff --git a/keyboard/kimera/keymap_common.h b/keyboard/kimera/keymap_common.h new file mode 100644 index 00000000..777c4f78 --- /dev/null +++ b/keyboard/kimera/keymap_common.h @@ -0,0 +1,253 @@ +/* +Copyright 2014 Kai Ryu + +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 . +*/ +#ifndef KEYMAP_COMMON_H +#define KEYMAP_COMMON_H + +#include +#include +#include +#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" +#include "keymap_ex.h" + + +extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; +extern const uint16_t fn_actions[]; + + +/* Full keymap definition macro */ +#define KEYMAP( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, KAS, KAT, KAU, KAV, KAW, KAX, KAY, KAZ, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, KBS, KBT, KBU, KBV, KBW, KBX, KBY, KBZ, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, KCS, KCT, KCU, KCV, KCW, KCX, KCY, KCZ, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, KDS, KDT, KDU, KDV, KDW, KDX, KDY, KDZ, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, KES, KET, KEU, KEV, KEW, KEX, KEY, KEZ, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, KFS, KFT, KFU, KFV, KFW, KFX, KFY, KFZ, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, KGS, KGT, KGU, KGV, KGW, KGX, KGY, KGZ, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ, \ + KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, KJJ, KJK, KJL, KJM, KJN, KJP, KJQ, KJR, KJS, KJT, KJU, KJV, KJW, KJX, KJY, KJZ, \ + KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, KKJ, KKK, KKL, KKM, KKN, KKP, KKQ, KKR, KKS, KKT, KKU, KKV, KKW, KKX, KKY, KKZ, \ + KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, KLJ, KLK, KLL, KLM, KLN, KLP, KLQ, KLR, KLS, KLT, KLU, KLV, KLW, KLX, KLY, KLZ, \ + KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, KMJ, KMK, KML, KMM, KMN, KMP, KMQ, KMR, KMS, KMT, KMU, KMV, KMW, KMX, KMY, KMZ, \ + KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, KNJ, KNK, KNL, KNM, KNN, KNP, KNQ, KNR, KNS, KNT, KNU, KNV, KNW, KNX, KNY, KNZ, \ + KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, KPJ, KPK, KPL, KPM, KPN, KPP, KPQ, KPR, KPS, KPT, KPU, KPV, KPW, KPX, KPY, KPZ, \ + KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, KQJ, KQK, KQL, KQM, KQN, KQP, KQQ, KQR, KQS, KQT, KQU, KQV, KQW, KQX, KQY, KQZ, \ + KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, KRJ, KRK, KRL, KRM, KRN, KRP, KRQ, KRR, KRS, KRT, KRU, KRV, KRW, KRX, KRY, KRZ, \ + KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, KSJ, KSK, KSL, KSM, KSN, KSP, KSQ, KSR, KSS, KST, KSU, KSV, KSW, KSX, KSY, KSZ, \ + KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, KTJ, KTK, KTL, KTM, KTN, KTP, KTQ, KTR, KTS, KTT, KTU, KTV, KTW, KTX, KTY, KTZ, \ + KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, KUJ, KUK, KUL, KUM, KUN, KUP, KUQ, KUR, KUS, KUT, KUU, KUV, KUW, KUX, KUY, KUZ, \ + KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, KVJ, KVK, KVL, KVM, KVN, KVP, KVQ, KVR, KVS, KVT, KVU, KVV, KVW, KVX, KVY, KVZ, \ + KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, KWJ, KWK, KWL, KWM, KWN, KWP, KWQ, KWR, KWS, KWT, KWU, KWV, KWW, KWX, KWY, KWZ, \ + KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, KXJ, KXK, KXL, KXM, KXN, KXP, KXQ, KXR, KXS, KXT, KXU, KXV, KXW, KXX, KXY, KXZ, \ + KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, KYJ, KYK, KYL, KYM, KYN, KYP, KYQ, KYR, KYS, KYT, KYU, KYV, KYW, KYX, KYY, KYZ, \ + KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH, KZJ, KZK, KZL, KZM, KZN, KZP, KZQ, KZR, KZS, KZT, KZU, KZV, KZW, KZX, KZY, KZZ \ +) { \ + { KC_##KAA, KC_##KAB, KC_##KAC, KC_##KAD, KC_##KAE, KC_##KAF, KC_##KAG, KC_##KAH, KC_##KAJ, KC_##KAK, KC_##KAL, KC_##KAM, KC_##KAN, KC_##KAP, KC_##KAQ, KC_##KAR, KC_##KAS, KC_##KAT, KC_##KAU, KC_##KAV, KC_##KAW, KC_##KAX, KC_##KAY, KC_##KAZ }, \ + { KC_##KBA, KC_##KBB, KC_##KBC, KC_##KBD, KC_##KBE, KC_##KBF, KC_##KBG, KC_##KBH, KC_##KBJ, KC_##KBK, KC_##KBL, KC_##KBM, KC_##KBN, KC_##KBP, KC_##KBQ, KC_##KBR, KC_##KBS, KC_##KBT, KC_##KBU, KC_##KBV, KC_##KBW, KC_##KBX, KC_##KBY, KC_##KBZ }, \ + { KC_##KCA, KC_##KCB, KC_##KCC, KC_##KCD, KC_##KCE, KC_##KCF, KC_##KCG, KC_##KCH, KC_##KCJ, KC_##KCK, KC_##KCL, KC_##KCM, KC_##KCN, KC_##KCP, KC_##KCQ, KC_##KCR, KC_##KCS, KC_##KCT, KC_##KCU, KC_##KCV, KC_##KCW, KC_##KCX, KC_##KCY, KC_##KCZ }, \ + { KC_##KDA, KC_##KDB, KC_##KDC, KC_##KDD, KC_##KDE, KC_##KDF, KC_##KDG, KC_##KDH, KC_##KDJ, KC_##KDK, KC_##KDL, KC_##KDM, KC_##KDN, KC_##KDP, KC_##KDQ, KC_##KDR, KC_##KDS, KC_##KDT, KC_##KDU, KC_##KDV, KC_##KDW, KC_##KDX, KC_##KDY, KC_##KDZ }, \ + { KC_##KEA, KC_##KEB, KC_##KEC, KC_##KED, KC_##KEE, KC_##KEF, KC_##KEG, KC_##KEH, KC_##KEJ, KC_##KEK, KC_##KEL, KC_##KEM, KC_##KEN, KC_##KEP, KC_##KEQ, KC_##KER, KC_##KES, KC_##KET, KC_##KEU, KC_##KEV, KC_##KEW, KC_##KEX, KC_##KEY, KC_##KEZ }, \ + { KC_##KFA, KC_##KFB, KC_##KFC, KC_##KFD, KC_##KFE, KC_##KFF, KC_##KFG, KC_##KFH, KC_##KFJ, KC_##KFK, KC_##KFL, KC_##KFM, KC_##KFN, KC_##KFP, KC_##KFQ, KC_##KFR, KC_##KFS, KC_##KFT, KC_##KFU, KC_##KFV, KC_##KFW, KC_##KFX, KC_##KFY, KC_##KFZ }, \ + { KC_##KGA, KC_##KGB, KC_##KGC, KC_##KGD, KC_##KGE, KC_##KGF, KC_##KGG, KC_##KGH, KC_##KGJ, KC_##KGK, KC_##KGL, KC_##KGM, KC_##KGN, KC_##KGP, KC_##KGQ, KC_##KGR, KC_##KGS, KC_##KGT, KC_##KGU, KC_##KGV, KC_##KGW, KC_##KGX, KC_##KGY, KC_##KGZ }, \ + { KC_##KHA, KC_##KHB, KC_##KHC, KC_##KHD, KC_##KHE, KC_##KHF, KC_##KHG, KC_##KHH, KC_##KHJ, KC_##KHK, KC_##KHL, KC_##KHM, KC_##KHN, KC_##KHP, KC_##KHQ, KC_##KHR, KC_##KHS, KC_##KHT, KC_##KHU, KC_##KHV, KC_##KHW, KC_##KHX, KC_##KHY, KC_##KHZ }, \ + { KC_##KJA, KC_##KJB, KC_##KJC, KC_##KJD, KC_##KJE, KC_##KJF, KC_##KJG, KC_##KJH, KC_##KJJ, KC_##KJK, KC_##KJL, KC_##KJM, KC_##KJN, KC_##KJP, KC_##KJQ, KC_##KJR, KC_##KJS, KC_##KJT, KC_##KJU, KC_##KJV, KC_##KJW, KC_##KJX, KC_##KJY, KC_##KJZ }, \ + { KC_##KKA, KC_##KKB, KC_##KKC, KC_##KKD, KC_##KKE, KC_##KKF, KC_##KKG, KC_##KKH, KC_##KKJ, KC_##KKK, KC_##KKL, KC_##KKM, KC_##KKN, KC_##KKP, KC_##KKQ, KC_##KKR, KC_##KKS, KC_##KKT, KC_##KKU, KC_##KKV, KC_##KKW, KC_##KKX, KC_##KKY, KC_##KKZ }, \ + { KC_##KLA, KC_##KLB, KC_##KLC, KC_##KLD, KC_##KLE, KC_##KLF, KC_##KLG, KC_##KLH, KC_##KLJ, KC_##KLK, KC_##KLL, KC_##KLM, KC_##KLN, KC_##KLP, KC_##KLQ, KC_##KLR, KC_##KLS, KC_##KLT, KC_##KLU, KC_##KLV, KC_##KLW, KC_##KLX, KC_##KLY, KC_##KLZ }, \ + { KC_##KMA, KC_##KMB, KC_##KMC, KC_##KMD, KC_##KME, KC_##KMF, KC_##KMG, KC_##KMH, KC_##KMJ, KC_##KMK, KC_##KML, KC_##KMM, KC_##KMN, KC_##KMP, KC_##KMQ, KC_##KMR, KC_##KMS, KC_##KMT, KC_##KMU, KC_##KMV, KC_##KMW, KC_##KMX, KC_##KMY, KC_##KMZ }, \ + { KC_##KNA, KC_##KNB, KC_##KNC, KC_##KND, KC_##KNE, KC_##KNF, KC_##KNG, KC_##KNH, KC_##KNJ, KC_##KNK, KC_##KNL, KC_##KNM, KC_##KNN, KC_##KNP, KC_##KNQ, KC_##KNR, KC_##KNS, KC_##KNT, KC_##KNU, KC_##KNV, KC_##KNW, KC_##KNX, KC_##KNY, KC_##KNZ }, \ + { KC_##KPA, KC_##KPB, KC_##KPC, KC_##KPD, KC_##KPE, KC_##KPF, KC_##KPG, KC_##KPH, KC_##KPJ, KC_##KPK, KC_##KPL, KC_##KPM, KC_##KPN, KC_##KPP, KC_##KPQ, KC_##KPR, KC_##KPS, KC_##KPT, KC_##KPU, KC_##KPV, KC_##KPW, KC_##KPX, KC_##KPY, KC_##KPZ }, \ + { KC_##KQA, KC_##KQB, KC_##KQC, KC_##KQD, KC_##KQE, KC_##KQF, KC_##KQG, KC_##KQH, KC_##KQJ, KC_##KQK, KC_##KQL, KC_##KQM, KC_##KQN, KC_##KQP, KC_##KQQ, KC_##KQR, KC_##KQS, KC_##KQT, KC_##KQU, KC_##KQV, KC_##KQW, KC_##KQX, KC_##KQY, KC_##KQZ }, \ + { KC_##KRA, KC_##KRB, KC_##KRC, KC_##KRD, KC_##KRE, KC_##KRF, KC_##KRG, KC_##KRH, KC_##KRJ, KC_##KRK, KC_##KRL, KC_##KRM, KC_##KRN, KC_##KRP, KC_##KRQ, KC_##KRR, KC_##KRS, KC_##KRT, KC_##KRU, KC_##KRV, KC_##KRW, KC_##KRX, KC_##KRY, KC_##KRZ }, \ + { KC_##KSA, KC_##KSB, KC_##KSC, KC_##KSD, KC_##KSE, KC_##KSF, KC_##KSG, KC_##KSH, KC_##KSJ, KC_##KSK, KC_##KSL, KC_##KSM, KC_##KSN, KC_##KSP, KC_##KSQ, KC_##KSR, KC_##KSS, KC_##KST, KC_##KSU, KC_##KSV, KC_##KSW, KC_##KSX, KC_##KSY, KC_##KSZ }, \ + { KC_##KTA, KC_##KTB, KC_##KTC, KC_##KTD, KC_##KTE, KC_##KTF, KC_##KTG, KC_##KTH, KC_##KTJ, KC_##KTK, KC_##KTL, KC_##KTM, KC_##KTN, KC_##KTP, KC_##KTQ, KC_##KTR, KC_##KTS, KC_##KTT, KC_##KTU, KC_##KTV, KC_##KTW, KC_##KTX, KC_##KTY, KC_##KTZ }, \ + { KC_##KUA, KC_##KUB, KC_##KUC, KC_##KUD, KC_##KUE, KC_##KUF, KC_##KUG, KC_##KUH, KC_##KUJ, KC_##KUK, KC_##KUL, KC_##KUM, KC_##KUN, KC_##KUP, KC_##KUQ, KC_##KUR, KC_##KUS, KC_##KUT, KC_##KUU, KC_##KUV, KC_##KUW, KC_##KUX, KC_##KUY, KC_##KUZ }, \ + { KC_##KVA, KC_##KVB, KC_##KVC, KC_##KVD, KC_##KVE, KC_##KVF, KC_##KVG, KC_##KVH, KC_##KVJ, KC_##KVK, KC_##KVL, KC_##KVM, KC_##KVN, KC_##KVP, KC_##KVQ, KC_##KVR, KC_##KVS, KC_##KVT, KC_##KVU, KC_##KVV, KC_##KVW, KC_##KVX, KC_##KVY, KC_##KVZ }, \ + { KC_##KWA, KC_##KWB, KC_##KWC, KC_##KWD, KC_##KWE, KC_##KWF, KC_##KWG, KC_##KWH, KC_##KWJ, KC_##KWK, KC_##KWL, KC_##KWM, KC_##KWN, KC_##KWP, KC_##KWQ, KC_##KWR, KC_##KWS, KC_##KWT, KC_##KWU, KC_##KWV, KC_##KWW, KC_##KWX, KC_##KWY, KC_##KWZ }, \ + { KC_##KXA, KC_##KXB, KC_##KXC, KC_##KXD, KC_##KXE, KC_##KXF, KC_##KXG, KC_##KXH, KC_##KXJ, KC_##KXK, KC_##KXL, KC_##KXM, KC_##KXN, KC_##KXP, KC_##KXQ, KC_##KXR, KC_##KXS, KC_##KXT, KC_##KXU, KC_##KXV, KC_##KXW, KC_##KXX, KC_##KXY, KC_##KXZ }, \ + { KC_##KYA, KC_##KYB, KC_##KYC, KC_##KYD, KC_##KYE, KC_##KYF, KC_##KYG, KC_##KYH, KC_##KYJ, KC_##KYK, KC_##KYL, KC_##KYM, KC_##KYN, KC_##KYP, KC_##KYQ, KC_##KYR, KC_##KYS, KC_##KYT, KC_##KYU, KC_##KYV, KC_##KYW, KC_##KYX, KC_##KYY, KC_##KYZ }, \ + { KC_##KZA, KC_##KZB, KC_##KZC, KC_##KZD, KC_##KZE, KC_##KZF, KC_##KZG, KC_##KZH, KC_##KZJ, KC_##KZK, KC_##KZL, KC_##KZM, KC_##KZN, KC_##KZP, KC_##KZQ, KC_##KZR, KC_##KZS, KC_##KZT, KC_##KZU, KC_##KZV, KC_##KZW, KC_##KZX, KC_##KZY, KC_##KZZ }, \ +} + +/* 8 rows, 24 cols */ +#define KEYMAP_8x24( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, KAS, KAT, KAU, KAV, KAW, KAX, KAY, KAZ, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, KBS, KBT, KBU, KBV, KBW, KBX, KBY, KBZ, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, KCS, KCT, KCU, KCV, KCW, KCX, KCY, KCZ, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, KDS, KDT, KDU, KDV, KDW, KDX, KDY, KDZ, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, KES, KET, KEU, KEV, KEW, KEX, KEY, KEZ, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, KFS, KFT, KFU, KFV, KFW, KFX, KFY, KFZ, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, KGS, KGT, KGU, KGV, KGW, KGX, KGY, KGZ, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ \ +) KEYMAP( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, KAS, KAT, KAU, KAV, KAW, KAX, KAY, KAZ, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, KBS, KBT, KBU, KBV, KBW, KBX, KBY, KBZ, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, KCS, KCT, KCU, KCV, KCW, KCX, KCY, KCZ, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, KDS, KDT, KDU, KDV, KDW, KDX, KDY, KDZ, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, KES, KET, KEU, KEV, KEW, KEX, KEY, KEZ, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, KFS, KFT, KFU, KFV, KFW, KFX, KFY, KFZ, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, KGS, KGT, KGU, KGV, KGW, KGX, KGY, KGZ, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ +) + +/* 16 rows, 16 cols */ +#define KEYMAP_16x16( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, KAS, KAT, KAU, KAV, KAW, KAX, KAY, KAZ, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, KBS, KBT, KBU, KBV, KBW, KBX, KBY, KBZ, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, KCS, KCT, KCU, KCV, KCW, KCX, KCY, KCZ, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, KDS, KDT, KDU, KDV, KDW, KDX, KDY, KDZ, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, KES, KET, KEU, KEV, KEW, KEX, KEY, KEZ, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, KFS, KFT, KFU, KFV, KFW, KFX, KFY, KFZ, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, KGS, KGT, KGU, KGV, KGW, KGX, KGY, KGZ, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ, \ + KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, KJJ, KJK, KJL, KJM, KJN, KJP, KJQ, KJR, KJS, KJT, KJU, KJV, KJW, KJX, KJY, KJZ, \ + KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, KKJ, KKK, KKL, KKM, KKN, KKP, KKQ, KKR, KKS, KKT, KKU, KKV, KKW, KKX, KKY, KKZ, \ + KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, KLJ, KLK, KLL, KLM, KLN, KLP, KLQ, KLR, KLS, KLT, KLU, KLV, KLW, KLX, KLY, KLZ, \ + KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, KMJ, KMK, KML, KMM, KMN, KMP, KMQ, KMR, KMS, KMT, KMU, KMV, KMW, KMX, KMY, KMZ, \ + KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, KNJ, KNK, KNL, KNM, KNN, KNP, KNQ, KNR, KNS, KNT, KNU, KNV, KNW, KNX, KNY, KNZ, \ + KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, KPJ, KPK, KPL, KPM, KPN, KPP, KPQ, KPR, KPS, KPT, KPU, KPV, KPW, KPX, KPY, KPZ, \ + KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, KQJ, KQK, KQL, KQM, KQN, KQP, KQQ, KQR, KQS, KQT, KQU, KQV, KQW, KQX, KQY, KQZ, \ + KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, KRJ, KRK, KRL, KRM, KRN, KRP, KRQ, KRR, KRS, KRT, KRU, KRV, KRW, KRX, KRY, KRZ, \ + KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, KSJ, KSK, KSL, KSM, KSN, KSP, KSQ, KSR, KSS, KST, KSU, KSV, KSW, KSX, KSY, KSZ, \ + KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, KTJ, KTK, KTL, KTM, KTN, KTP, KTQ, KTR, KTS, KTT, KTU, KTV, KTW, KTX, KTY, KTZ, \ + KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, KUJ, KUK, KUL, KUM, KUN, KUP, KUQ, KUR, KUS, KUT, KUU, KUV, KUW, KUX, KUY, KUZ, \ + KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, KVJ, KVK, KVL, KVM, KVN, KVP, KVQ, KVR, KVS, KVT, KVU, KVV, KVW, KVX, KVY, KVZ, \ + KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, KWJ, KWK, KWL, KWM, KWN, KWP, KWQ, KWR, KWS, KWT, KWU, KWV, KWW, KWX, KWY, KWZ, \ + KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, KXJ, KXK, KXL, KXM, KXN, KXP, KXQ, KXR, KXS, KXT, KXU, KXV, KXW, KXX, KXY, KXZ, \ + KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, KYJ, KYK, KYL, KYM, KYN, KYP, KYQ, KYR, KYS, KYT, KYU, KYV, KYW, KYX, KYY, KYZ, \ + KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH, KZJ, KZK, KZL, KZM, KZN, KZP, KZQ, KZR, KZS, KZT, KZU, KZV, KZW, KZX, KZY, KZZ \ +) KEYMAP( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, NO, NO, NO, NO, NO, NO, NO, NO, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, KJJ, KJK, KJL, KJM, KJN, KJP, KJQ, KJR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, KKJ, KKK, KKL, KKM, KKN, KKP, KKQ, KKR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, KLJ, KLK, KLL, KLM, KLN, KLP, KLQ, KLR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, KMJ, KMK, KML, KMM, KMN, KMP, KMQ, KMR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, KNJ, KNK, KNL, KNM, KNN, KNP, KNQ, KNR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, KPJ, KPK, KPL, KPM, KPN, KPP, KPQ, KPR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, KQJ, KQK, KQL, KQM, KQN, KQP, KQQ, KQR, NO, NO, NO, NO, NO, NO, NO, NO, \ + KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, KRJ, KRK, KRL, KRM, KRN, KRP, KRQ, KRR, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ +) + +/* 24 rows, 8 cols */ +#define KEYMAP_24x8( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, \ + KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, \ + KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, \ + KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, \ + KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, \ + KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, \ + KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, \ + KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, \ + KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, \ + KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, \ + KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, \ + KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, \ + KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, \ + KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, \ + KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, \ + KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, \ + KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH \ +) KEYMAP( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ +) + +/* ANSI 104 keymap */ +#define KEYMAP_ANSI_104( \ + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PRS, SCL, PAU, \ + GRV, _1, _2, _3, _4, _5, _6, _7, _8, _9, _0, MNS, EQU, BSP, INS, HOM, PGU, NUM, PSL, PAS, PMN, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBR, RBR, BSL, DEL, END, PGD, P7, P8, P9, PPL, \ + CAP, A, S, D, F, G, H, J, K, L, SCN, QUT, ENT, P4, P5, P6, \ + LSF, Z, X, C, V, B, N, M, COM, DOT, SLS, RSF, UP, P1, P2, P3, PEN, \ + LCT, LGU, LAL, SPC, RAL, RGU, APP, RCT, LFT, DOW, RGT, P0, PDT \ +) KEYMAP_8x24( \ + ESC, NO, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PRS, SCL, PAU, NO, NO, NO, NO, NO, NO, NO, \ + GRV, _1, _2, _3, _4, _5, _6, _7, _8, _9, _0, MNS, EQU, BSP, INS, HOM, PGU, NUM, PSL, PAS, PMN, NO, NO, NO, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBR, RBR, BSL, DEL, END, PGD, P7, P8, P9, PPL, NO, NO, NO, \ + CAP, A, S, D, F, G, H, J, K, L, SCN, QUT, NO, ENT, NO, NO, NO, P4, P5, P6, NO, NO, NO, NO, \ + LSF, Z, X, C, V, B, N, M, COM, DOT, SLS, NO, NO, RSF, NO, UP, NO, P1, P2, P3, PEN, NO, NO, NO, \ + LCT, LGU, LAL, NO, NO, NO, SPC, NO, NO, NO, RAL, RGU, APP, RCT, LFT, DOW, RGT, P0, NO, PDT, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ +) + +#endif diff --git a/keyboard/kimera/keymap_default.c b/keyboard/kimera/keymap_default.c new file mode 100644 index 00000000..d1c2134a --- /dev/null +++ b/keyboard/kimera/keymap_default.c @@ -0,0 +1,78 @@ +#include "keymap_common.h" + +// Default +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +#else +const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,---------------------------------------------------------------------------------------. + * |Esc| | F1| F2| F3| F4| | F5| F6| F7| F8| | F9|F10|F11|F12|Psc|Slk|Pus| | + * |---------------------------------------------------------------------------------------| + * | `| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |Ins|Hom|PgU|Num| /| *| -| + * |---------------------------------------------------------------------------------------| + * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|Del|End|PgD| 7| 8| 9| | + * |-----------------------------------------------------------------------------------| +| + * |Caps | A| S| D| F| G| H| J| K| L| ;| '|Return | | 4| 5| 6| | + * |-----------------------------------------------------------| ,---. |---------------| + * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |Up | | 1| 2| 3| | + * |-----------------------------------------------------------------------------------|Ent| + * |Ctrl|Gui |Alt | Space |Alt |Gui |Fn0 |Ctrl|Lef|Dow|Rig| 0| .| | + * `---------------------------------------------------------------------------------------' + */ + KEYMAP_ANSI_104( + ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,PAUS, \ + GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, INS, HOME,PGUP, NLCK,PSLS,PAST,PMNS, \ + TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, DEL, END, PGDN, P7, P8, P9, PPLS, \ + CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, \ + LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, PENT, \ + LCTL,LGUI,LALT, SPC, RALT,RGUI,FN0, RCTL, LEFT,DOWN,RGHT, P0, PDOT ), + /* Keymap 1: Fn Layer + * ,---------------------------------------------------------------------------------------. + * | | | | | | | | | | | | | | | | | | | | + * |---------------------------------------------------------------------------------------| + * | | | | | | | | | | | | | | | | | | | | | | + * |---------------------------------------------------------------------------------------| + * | |Fn1|Fn2|Fn3| | | | | | | | | | | | | | | | | | + * |-----------------------------------------------------------------------------------| | + * | | | | | | | | | | | | | | | | | | | + * |-----------------------------------------------------------| ,---. |---------------- + * | | | | | | | | | | | | | | | | | | | | + * |-----------------------------------------------------------------------------------| | + * | | | | | | | | | | | | | | | | + * `---------------------------------------------------------------------------------------' + */ + KEYMAP_ANSI_104( + TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, \ + TRNS,FN1, FN2, FN3, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, NLCK,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, \ + TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, TRNS, TRNS ), +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +const uint16_t fn_actions[] PROGMEM = { +#endif + /* Poker2 Layout */ + [0] = ACTION_LAYER_MOMENTARY(1), + [1] = ACTION_BACKLIGHT_TOGGLE(), + [2] = ACTION_BACKLIGHT_DECREASE(), + [3] = ACTION_BACKLIGHT_INCREASE(), +}; + +#ifdef KEYMAP_EX_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c new file mode 100644 index 00000000..596e9135 --- /dev/null +++ b/keyboard/kimera/kimera.c @@ -0,0 +1,186 @@ +/* +Copyright 2014 Kai Ryu + +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 . +*/ + +#define KIMERA_C + +#include +#include +#include "kimera.h" + +uint8_t mux_mapping[MUX_COUNT] = { + MUX_FOR_ROW, MUX_FOR_COL, MUX_FOR_COL, MUX_FOR_COL +}; +uint8_t row_mapping[MATRIX_ROWS] = { + 0, 1, 2, 3, 4, 5, 6, 7, + UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, + UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED +}; +uint8_t col_mapping[MATRIX_COLS] = { + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31 +}; +uint16_t shift_out_cache = 0; + +void kimera_init(void) +{ + // read config + if (read_matrix_mapping()) { + write_matrix_mapping(); + } + + // init shift out pins + MOSI_DDR |= (1<>8) & 0xFF); + while (!(SPSR & (1< + +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 . +*/ + +#ifndef KIMERA_H +#define KIMERA_H + +#include +#include +#include "matrix.h" + +/* + Pro Micro + ,----------------. + TX --| TX0(PD3) RAW |-- + RX --| RX1(PD2) GND |-- + --| GND RESET |-- RST + --| GND VCC |-- + SDA --| 2(PD1) (PF4)A3 |-- (Z4) + SCL --| 3(PD0) (PF5)A2 |-- (Z1) + (RCK) --| 4(PD4) (PF6)A1 |-- (Z2) + LED1 --| 5(PC6) (PF7)A0 |-- (Z3) + LED2 --| 6(PD7) (PB1)15 |-- SCK + (SJ1) --| 7(PE6) (PB3)14 |-- MISO + (SJ2) --| 8(PB4) (PB2)16 |-- MOSI + BL --| 9(PB5) (PB6)10 |-- LED3 + `----------------' +*/ + +#define LED1_PORT PORTC +#define LED1_PIN PINC +#define LED1_DDR DDRC +#define LED1_BIT PC6 + +#define LED2_PORT PORTD +#define LED2_PIN PIND +#define LED2_DDR DDRD +#define LED2_BIT PD7 + +#define LED3_PORT PORTB +#define LED3_PIN PINB +#define LED3_DDR DDRB +#define LED3_BIT PB6 + +#define BL_PORT PORTB +#define BL_PIN PINB +#define BL_DDR DDRB +#define BL_BIT PB5 +#define BL_OCR OCR1A + +#define RCK_PORT PORTD +#define RCK_PIN PIND +#define RCK_DDR DDRD +#define RCK_BIT PD4 + +#define SCK_PORT PORTB +#define SCK_PIN PINB +#define SCK_DDR DDRB +#define SCK_BIT PB1 + +#define MOSI_PORT PORTB +#define MOSI_PIN PINB +#define MOSI_DDR DDRB +#define MOSI_BIT PB2 + +#define MISO_PORT PORTB +#define MISO_PIN PINB +#define MISO_DDR DDRB +#define MISO_BIT PB3 + +#define ZX_PORT PORTF +#define ZX_PIN PINF +#define ZX_DDR DDRF +#ifdef KIMERA_C +const uint8_t PROGMEM zx_bit[] = { + PF5, PF6, PF7, PF4 +}; +#endif + +/* + Shift Register Multiplexer + ,----------. ,------------. + MOSI --| SER 0 |----| INH X0~X7 |===============. + SCK --|>SCK 1 |----| A | | + RCK --|>RCK 2 |----| B | ,-------------+-------------. + | 3 |----| C | | | | | | | | | + | | `------------' P26 P27 P28 P25 P29 P32 P30 P31 + | | ,------------. + | 4 |----| A X0~X7 |===============. + | 5 |----| B | | + | 6 |----| C | ,-------------+-------------. + | 7 |----| INH | | | | | | | | | + | | `------------' P2 P3 P4 P1 P5 P8 P6 P7 + | | ,------------. + | 8 |----| INH X0~X7 |===============. + | 9 |----| A | | + | 10 |----| B | ,-------------+-------------. + | 11 |----| C | | | | | | | | | + | | `------------' P10 P11 P12 P9 P13 P16 P14 P15 + | | ,------------. + | 12 |----| A X0~X7 |===============. + | 13 |----| B | | + | 14 |----| C | ,-------------+-------------. + | 15 |----| INH | | | | | | | | | + `----------' `------------' P18 P19 P20 P17 P21 P24 P22 P23 +*/ + +#define MUX_COUNT 4 +#define MUX_PORTS 8 +#define PX_TO_MUX(x) (x>>3) // (x / MUX_PORTS) + +enum { + MUX4_INH = 0, + MUX4_A, + MUX4_B, + MUX4_C, + MUX1_A, + MUX1_B, + MUX1_C, + MUX1_INH, + MUX2_INH, + MUX2_A, + MUX2_B, + MUX2_C, + MUX3_A, + MUX3_B, + MUX3_C, + MUX3_INH +}; + +#ifdef KIMERA_C +const uint16_t PROGMEM px_to_shift_out[] = { + 3< + +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 . +*/ + +#include +#include "stdint.h" +#include "led.h" +#include "kimera.h" + +void led_set(uint8_t usb_led) +{ + if (usb_led & (1< + +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 . +*/ + +/* + * scan matrix + */ +#include +#include +#include +#include +#include "print.h" +#include "debug.h" +#include "util.h" +#include "matrix.h" +#include "kimera.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]; + + +inline +uint8_t matrix_rows(void) +{ + return MATRIX_ROWS; +} + +inline +uint8_t matrix_cols(void) +{ + return MATRIX_COLS; +} + +void matrix_init(void) +{ + // disable JTAG + MCUCR = (1< Date: Mon, 26 May 2014 16:52:36 +0900 Subject: [PATCH 02/29] kimera: Correct macro define to match keymap_in_eeprom --- keyboard/kimera/Makefile | 2 +- keyboard/kimera/Makefile.pjrc | 2 +- keyboard/kimera/keymap_common.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index d02ae3a2..1b8a6d7d 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -131,7 +131,7 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support #PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality -KEYMAP_EX_ENABLE = yes # External keymap in eeprom +KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor BREATHING_LED_ENABLE = yes # Enable breathing backlight diff --git a/keyboard/kimera/Makefile.pjrc b/keyboard/kimera/Makefile.pjrc index 5c0aaea2..afbb0a03 100644 --- a/keyboard/kimera/Makefile.pjrc +++ b/keyboard/kimera/Makefile.pjrc @@ -101,7 +101,7 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support #PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality -KEYMAP_EX_ENABLE = yes # External keymap in eeprom +KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor BREATHING_LED_ENABLE = yes # Enable breathing backlight diff --git a/keyboard/kimera/keymap_common.c b/keyboard/kimera/keymap_common.c index f4b96bbf..68d55d7d 100644 --- a/keyboard/kimera/keymap_common.c +++ b/keyboard/kimera/keymap_common.c @@ -19,7 +19,7 @@ along with this program. If not, see . /* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { -#ifndef KEYMAP_EX_ENABLE +#ifndef KEYMAP_IN_EEPROM_ENABLE return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); #else return eeconfig_read_keymap_key(layer, key.row, key.col); @@ -30,7 +30,7 @@ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) action_t keymap_fn_to_action(uint8_t keycode) { return (action_t) { -#ifndef KEYMAP_EX_ENABLE +#ifndef KEYMAP_IN_EEPROM_ENABLE .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) #else .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) @@ -38,7 +38,7 @@ action_t keymap_fn_to_action(uint8_t keycode) }; } -#ifdef KEYMAP_EX_ENABLE +#ifdef KEYMAP_IN_EEPROM_ENABLE const uint8_t* keymaps_pointer(void) { return (const uint8_t*)keymaps; } From 1f93c275533541d0bb6478791cfa4e2100b66785 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 26 May 2014 16:58:34 +0900 Subject: [PATCH 03/29] kimera: Reduce memory cost of keymap --- keyboard/kimera/config.h | 3 +- keyboard/kimera/keymap_common.c | 3 +- keyboard/kimera/keymap_common.h | 216 ++++++++++--------------------- keyboard/kimera/keymap_default.c | 8 +- keyboard/kimera/kimera.c | 10 +- keyboard/kimera/kimera.h | 2 +- keyboard/kimera/matrix.c | 16 ++- 7 files changed, 95 insertions(+), 163 deletions(-) diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index cb6ac7c3..19fe83de 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -32,8 +32,9 @@ along with this program. If not, see . #define MATRIX_COLS 24 /* keymap in eeprom */ +#define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 -#define KEYMAPS_COUNT 3 +#define KEYMAPS_COUNT 8 /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST diff --git a/keyboard/kimera/keymap_common.c b/keyboard/kimera/keymap_common.c index 68d55d7d..f51dfdbe 100644 --- a/keyboard/kimera/keymap_common.c +++ b/keyboard/kimera/keymap_common.c @@ -15,12 +15,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "keymap_common.h" +#include "matrix.h" /* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { #ifndef KEYMAP_IN_EEPROM_ENABLE - return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); + return pgm_read_byte(&keymaps[(layer)][(key.row) * matrix_cols() + (key.col)]); #else return eeconfig_read_keymap_key(layer, key.row, key.col); #endif diff --git a/keyboard/kimera/keymap_common.h b/keyboard/kimera/keymap_common.h index 777c4f78..9654304d 100644 --- a/keyboard/kimera/keymap_common.h +++ b/keyboard/kimera/keymap_common.h @@ -28,64 +28,47 @@ along with this program. If not, see . #include "print.h" #include "debug.h" #include "keymap.h" -#include "keymap_ex.h" +#include "keymap_in_eeprom.h" -extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; +extern const uint8_t keymaps[][MATRIX_SIZE]; extern const uint16_t fn_actions[]; - -/* Full keymap definition macro */ -#define KEYMAP( \ - KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, KAS, KAT, KAU, KAV, KAW, KAX, KAY, KAZ, \ - KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, KBS, KBT, KBU, KBV, KBW, KBX, KBY, KBZ, \ - KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, KCS, KCT, KCU, KCV, KCW, KCX, KCY, KCZ, \ - KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, KDS, KDT, KDU, KDV, KDW, KDX, KDY, KDZ, \ - KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, KES, KET, KEU, KEV, KEW, KEX, KEY, KEZ, \ - KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, KFS, KFT, KFU, KFV, KFW, KFX, KFY, KFZ, \ - KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, KGS, KGT, KGU, KGV, KGW, KGX, KGY, KGZ, \ - KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ, \ - KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, KJJ, KJK, KJL, KJM, KJN, KJP, KJQ, KJR, KJS, KJT, KJU, KJV, KJW, KJX, KJY, KJZ, \ - KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, KKJ, KKK, KKL, KKM, KKN, KKP, KKQ, KKR, KKS, KKT, KKU, KKV, KKW, KKX, KKY, KKZ, \ - KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, KLJ, KLK, KLL, KLM, KLN, KLP, KLQ, KLR, KLS, KLT, KLU, KLV, KLW, KLX, KLY, KLZ, \ - KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, KMJ, KMK, KML, KMM, KMN, KMP, KMQ, KMR, KMS, KMT, KMU, KMV, KMW, KMX, KMY, KMZ, \ - KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, KNJ, KNK, KNL, KNM, KNN, KNP, KNQ, KNR, KNS, KNT, KNU, KNV, KNW, KNX, KNY, KNZ, \ - KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, KPJ, KPK, KPL, KPM, KPN, KPP, KPQ, KPR, KPS, KPT, KPU, KPV, KPW, KPX, KPY, KPZ, \ - KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, KQJ, KQK, KQL, KQM, KQN, KQP, KQQ, KQR, KQS, KQT, KQU, KQV, KQW, KQX, KQY, KQZ, \ - KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, KRJ, KRK, KRL, KRM, KRN, KRP, KRQ, KRR, KRS, KRT, KRU, KRV, KRW, KRX, KRY, KRZ, \ - KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, KSJ, KSK, KSL, KSM, KSN, KSP, KSQ, KSR, KSS, KST, KSU, KSV, KSW, KSX, KSY, KSZ, \ - KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, KTJ, KTK, KTL, KTM, KTN, KTP, KTQ, KTR, KTS, KTT, KTU, KTV, KTW, KTX, KTY, KTZ, \ - KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, KUJ, KUK, KUL, KUM, KUN, KUP, KUQ, KUR, KUS, KUT, KUU, KUV, KUW, KUX, KUY, KUZ, \ - KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, KVJ, KVK, KVL, KVM, KVN, KVP, KVQ, KVR, KVS, KVT, KVU, KVV, KVW, KVX, KVY, KVZ, \ - KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, KWJ, KWK, KWL, KWM, KWN, KWP, KWQ, KWR, KWS, KWT, KWU, KWV, KWW, KWX, KWY, KWZ, \ - KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, KXJ, KXK, KXL, KXM, KXN, KXP, KXQ, KXR, KXS, KXT, KXU, KXV, KXW, KXX, KXY, KXZ, \ - KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, KYJ, KYK, KYL, KYM, KYN, KYP, KYQ, KYR, KYS, KYT, KYU, KYV, KYW, KYX, KYY, KYZ, \ - KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH, KZJ, KZK, KZL, KZM, KZN, KZP, KZQ, KZR, KZS, KZT, KZU, KZV, KZW, KZX, KZY, KZZ \ +/* 16 rows, 16 cols */ +#define KEYMAP_16x16( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, \ + KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, KJJ, KJK, KJL, KJM, KJN, KJP, KJQ, KJR, \ + KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, KKJ, KKK, KKL, KKM, KKN, KKP, KKQ, KKR, \ + KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, KLJ, KLK, KLL, KLM, KLN, KLP, KLQ, KLR, \ + KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, KMJ, KMK, KML, KMM, KMN, KMP, KMQ, KMR, \ + KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, KNJ, KNK, KNL, KNM, KNN, KNP, KNQ, KNR, \ + KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, KPJ, KPK, KPL, KPM, KPN, KPP, KPQ, KPR, \ + KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, KQJ, KQK, KQL, KQM, KQN, KQP, KQQ, KQR, \ + KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, KRJ, KRK, KRL, KRM, KRN, KRP, KRQ, KRR \ ) { \ - { KC_##KAA, KC_##KAB, KC_##KAC, KC_##KAD, KC_##KAE, KC_##KAF, KC_##KAG, KC_##KAH, KC_##KAJ, KC_##KAK, KC_##KAL, KC_##KAM, KC_##KAN, KC_##KAP, KC_##KAQ, KC_##KAR, KC_##KAS, KC_##KAT, KC_##KAU, KC_##KAV, KC_##KAW, KC_##KAX, KC_##KAY, KC_##KAZ }, \ - { KC_##KBA, KC_##KBB, KC_##KBC, KC_##KBD, KC_##KBE, KC_##KBF, KC_##KBG, KC_##KBH, KC_##KBJ, KC_##KBK, KC_##KBL, KC_##KBM, KC_##KBN, KC_##KBP, KC_##KBQ, KC_##KBR, KC_##KBS, KC_##KBT, KC_##KBU, KC_##KBV, KC_##KBW, KC_##KBX, KC_##KBY, KC_##KBZ }, \ - { KC_##KCA, KC_##KCB, KC_##KCC, KC_##KCD, KC_##KCE, KC_##KCF, KC_##KCG, KC_##KCH, KC_##KCJ, KC_##KCK, KC_##KCL, KC_##KCM, KC_##KCN, KC_##KCP, KC_##KCQ, KC_##KCR, KC_##KCS, KC_##KCT, KC_##KCU, KC_##KCV, KC_##KCW, KC_##KCX, KC_##KCY, KC_##KCZ }, \ - { KC_##KDA, KC_##KDB, KC_##KDC, KC_##KDD, KC_##KDE, KC_##KDF, KC_##KDG, KC_##KDH, KC_##KDJ, KC_##KDK, KC_##KDL, KC_##KDM, KC_##KDN, KC_##KDP, KC_##KDQ, KC_##KDR, KC_##KDS, KC_##KDT, KC_##KDU, KC_##KDV, KC_##KDW, KC_##KDX, KC_##KDY, KC_##KDZ }, \ - { KC_##KEA, KC_##KEB, KC_##KEC, KC_##KED, KC_##KEE, KC_##KEF, KC_##KEG, KC_##KEH, KC_##KEJ, KC_##KEK, KC_##KEL, KC_##KEM, KC_##KEN, KC_##KEP, KC_##KEQ, KC_##KER, KC_##KES, KC_##KET, KC_##KEU, KC_##KEV, KC_##KEW, KC_##KEX, KC_##KEY, KC_##KEZ }, \ - { KC_##KFA, KC_##KFB, KC_##KFC, KC_##KFD, KC_##KFE, KC_##KFF, KC_##KFG, KC_##KFH, KC_##KFJ, KC_##KFK, KC_##KFL, KC_##KFM, KC_##KFN, KC_##KFP, KC_##KFQ, KC_##KFR, KC_##KFS, KC_##KFT, KC_##KFU, KC_##KFV, KC_##KFW, KC_##KFX, KC_##KFY, KC_##KFZ }, \ - { KC_##KGA, KC_##KGB, KC_##KGC, KC_##KGD, KC_##KGE, KC_##KGF, KC_##KGG, KC_##KGH, KC_##KGJ, KC_##KGK, KC_##KGL, KC_##KGM, KC_##KGN, KC_##KGP, KC_##KGQ, KC_##KGR, KC_##KGS, KC_##KGT, KC_##KGU, KC_##KGV, KC_##KGW, KC_##KGX, KC_##KGY, KC_##KGZ }, \ - { KC_##KHA, KC_##KHB, KC_##KHC, KC_##KHD, KC_##KHE, KC_##KHF, KC_##KHG, KC_##KHH, KC_##KHJ, KC_##KHK, KC_##KHL, KC_##KHM, KC_##KHN, KC_##KHP, KC_##KHQ, KC_##KHR, KC_##KHS, KC_##KHT, KC_##KHU, KC_##KHV, KC_##KHW, KC_##KHX, KC_##KHY, KC_##KHZ }, \ - { KC_##KJA, KC_##KJB, KC_##KJC, KC_##KJD, KC_##KJE, KC_##KJF, KC_##KJG, KC_##KJH, KC_##KJJ, KC_##KJK, KC_##KJL, KC_##KJM, KC_##KJN, KC_##KJP, KC_##KJQ, KC_##KJR, KC_##KJS, KC_##KJT, KC_##KJU, KC_##KJV, KC_##KJW, KC_##KJX, KC_##KJY, KC_##KJZ }, \ - { KC_##KKA, KC_##KKB, KC_##KKC, KC_##KKD, KC_##KKE, KC_##KKF, KC_##KKG, KC_##KKH, KC_##KKJ, KC_##KKK, KC_##KKL, KC_##KKM, KC_##KKN, KC_##KKP, KC_##KKQ, KC_##KKR, KC_##KKS, KC_##KKT, KC_##KKU, KC_##KKV, KC_##KKW, KC_##KKX, KC_##KKY, KC_##KKZ }, \ - { KC_##KLA, KC_##KLB, KC_##KLC, KC_##KLD, KC_##KLE, KC_##KLF, KC_##KLG, KC_##KLH, KC_##KLJ, KC_##KLK, KC_##KLL, KC_##KLM, KC_##KLN, KC_##KLP, KC_##KLQ, KC_##KLR, KC_##KLS, KC_##KLT, KC_##KLU, KC_##KLV, KC_##KLW, KC_##KLX, KC_##KLY, KC_##KLZ }, \ - { KC_##KMA, KC_##KMB, KC_##KMC, KC_##KMD, KC_##KME, KC_##KMF, KC_##KMG, KC_##KMH, KC_##KMJ, KC_##KMK, KC_##KML, KC_##KMM, KC_##KMN, KC_##KMP, KC_##KMQ, KC_##KMR, KC_##KMS, KC_##KMT, KC_##KMU, KC_##KMV, KC_##KMW, KC_##KMX, KC_##KMY, KC_##KMZ }, \ - { KC_##KNA, KC_##KNB, KC_##KNC, KC_##KND, KC_##KNE, KC_##KNF, KC_##KNG, KC_##KNH, KC_##KNJ, KC_##KNK, KC_##KNL, KC_##KNM, KC_##KNN, KC_##KNP, KC_##KNQ, KC_##KNR, KC_##KNS, KC_##KNT, KC_##KNU, KC_##KNV, KC_##KNW, KC_##KNX, KC_##KNY, KC_##KNZ }, \ - { KC_##KPA, KC_##KPB, KC_##KPC, KC_##KPD, KC_##KPE, KC_##KPF, KC_##KPG, KC_##KPH, KC_##KPJ, KC_##KPK, KC_##KPL, KC_##KPM, KC_##KPN, KC_##KPP, KC_##KPQ, KC_##KPR, KC_##KPS, KC_##KPT, KC_##KPU, KC_##KPV, KC_##KPW, KC_##KPX, KC_##KPY, KC_##KPZ }, \ - { KC_##KQA, KC_##KQB, KC_##KQC, KC_##KQD, KC_##KQE, KC_##KQF, KC_##KQG, KC_##KQH, KC_##KQJ, KC_##KQK, KC_##KQL, KC_##KQM, KC_##KQN, KC_##KQP, KC_##KQQ, KC_##KQR, KC_##KQS, KC_##KQT, KC_##KQU, KC_##KQV, KC_##KQW, KC_##KQX, KC_##KQY, KC_##KQZ }, \ - { KC_##KRA, KC_##KRB, KC_##KRC, KC_##KRD, KC_##KRE, KC_##KRF, KC_##KRG, KC_##KRH, KC_##KRJ, KC_##KRK, KC_##KRL, KC_##KRM, KC_##KRN, KC_##KRP, KC_##KRQ, KC_##KRR, KC_##KRS, KC_##KRT, KC_##KRU, KC_##KRV, KC_##KRW, KC_##KRX, KC_##KRY, KC_##KRZ }, \ - { KC_##KSA, KC_##KSB, KC_##KSC, KC_##KSD, KC_##KSE, KC_##KSF, KC_##KSG, KC_##KSH, KC_##KSJ, KC_##KSK, KC_##KSL, KC_##KSM, KC_##KSN, KC_##KSP, KC_##KSQ, KC_##KSR, KC_##KSS, KC_##KST, KC_##KSU, KC_##KSV, KC_##KSW, KC_##KSX, KC_##KSY, KC_##KSZ }, \ - { KC_##KTA, KC_##KTB, KC_##KTC, KC_##KTD, KC_##KTE, KC_##KTF, KC_##KTG, KC_##KTH, KC_##KTJ, KC_##KTK, KC_##KTL, KC_##KTM, KC_##KTN, KC_##KTP, KC_##KTQ, KC_##KTR, KC_##KTS, KC_##KTT, KC_##KTU, KC_##KTV, KC_##KTW, KC_##KTX, KC_##KTY, KC_##KTZ }, \ - { KC_##KUA, KC_##KUB, KC_##KUC, KC_##KUD, KC_##KUE, KC_##KUF, KC_##KUG, KC_##KUH, KC_##KUJ, KC_##KUK, KC_##KUL, KC_##KUM, KC_##KUN, KC_##KUP, KC_##KUQ, KC_##KUR, KC_##KUS, KC_##KUT, KC_##KUU, KC_##KUV, KC_##KUW, KC_##KUX, KC_##KUY, KC_##KUZ }, \ - { KC_##KVA, KC_##KVB, KC_##KVC, KC_##KVD, KC_##KVE, KC_##KVF, KC_##KVG, KC_##KVH, KC_##KVJ, KC_##KVK, KC_##KVL, KC_##KVM, KC_##KVN, KC_##KVP, KC_##KVQ, KC_##KVR, KC_##KVS, KC_##KVT, KC_##KVU, KC_##KVV, KC_##KVW, KC_##KVX, KC_##KVY, KC_##KVZ }, \ - { KC_##KWA, KC_##KWB, KC_##KWC, KC_##KWD, KC_##KWE, KC_##KWF, KC_##KWG, KC_##KWH, KC_##KWJ, KC_##KWK, KC_##KWL, KC_##KWM, KC_##KWN, KC_##KWP, KC_##KWQ, KC_##KWR, KC_##KWS, KC_##KWT, KC_##KWU, KC_##KWV, KC_##KWW, KC_##KWX, KC_##KWY, KC_##KWZ }, \ - { KC_##KXA, KC_##KXB, KC_##KXC, KC_##KXD, KC_##KXE, KC_##KXF, KC_##KXG, KC_##KXH, KC_##KXJ, KC_##KXK, KC_##KXL, KC_##KXM, KC_##KXN, KC_##KXP, KC_##KXQ, KC_##KXR, KC_##KXS, KC_##KXT, KC_##KXU, KC_##KXV, KC_##KXW, KC_##KXX, KC_##KXY, KC_##KXZ }, \ - { KC_##KYA, KC_##KYB, KC_##KYC, KC_##KYD, KC_##KYE, KC_##KYF, KC_##KYG, KC_##KYH, KC_##KYJ, KC_##KYK, KC_##KYL, KC_##KYM, KC_##KYN, KC_##KYP, KC_##KYQ, KC_##KYR, KC_##KYS, KC_##KYT, KC_##KYU, KC_##KYV, KC_##KYW, KC_##KYX, KC_##KYY, KC_##KYZ }, \ - { KC_##KZA, KC_##KZB, KC_##KZC, KC_##KZD, KC_##KZE, KC_##KZF, KC_##KZG, KC_##KZH, KC_##KZJ, KC_##KZK, KC_##KZL, KC_##KZM, KC_##KZN, KC_##KZP, KC_##KZQ, KC_##KZR, KC_##KZS, KC_##KZT, KC_##KZU, KC_##KZV, KC_##KZW, KC_##KZX, KC_##KZY, KC_##KZZ }, \ + KC_##KAA, KC_##KAB, KC_##KAC, KC_##KAD, KC_##KAE, KC_##KAF, KC_##KAG, KC_##KAH, KC_##KAJ, KC_##KAK, KC_##KAL, KC_##KAM, KC_##KAN, KC_##KAP, KC_##KAQ, KC_##KAR, \ + KC_##KBA, KC_##KBB, KC_##KBC, KC_##KBD, KC_##KBE, KC_##KBF, KC_##KBG, KC_##KBH, KC_##KBJ, KC_##KBK, KC_##KBL, KC_##KBM, KC_##KBN, KC_##KBP, KC_##KBQ, KC_##KBR, \ + KC_##KCA, KC_##KCB, KC_##KCC, KC_##KCD, KC_##KCE, KC_##KCF, KC_##KCG, KC_##KCH, KC_##KCJ, KC_##KCK, KC_##KCL, KC_##KCM, KC_##KCN, KC_##KCP, KC_##KCQ, KC_##KCR, \ + KC_##KDA, KC_##KDB, KC_##KDC, KC_##KDD, KC_##KDE, KC_##KDF, KC_##KDG, KC_##KDH, KC_##KDJ, KC_##KDK, KC_##KDL, KC_##KDM, KC_##KDN, KC_##KDP, KC_##KDQ, KC_##KDR, \ + KC_##KEA, KC_##KEB, KC_##KEC, KC_##KED, KC_##KEE, KC_##KEF, KC_##KEG, KC_##KEH, KC_##KEJ, KC_##KEK, KC_##KEL, KC_##KEM, KC_##KEN, KC_##KEP, KC_##KEQ, KC_##KER, \ + KC_##KFA, KC_##KFB, KC_##KFC, KC_##KFD, KC_##KFE, KC_##KFF, KC_##KFG, KC_##KFH, KC_##KFJ, KC_##KFK, KC_##KFL, KC_##KFM, KC_##KFN, KC_##KFP, KC_##KFQ, KC_##KFR, \ + KC_##KGA, KC_##KGB, KC_##KGC, KC_##KGD, KC_##KGE, KC_##KGF, KC_##KGG, KC_##KGH, KC_##KGJ, KC_##KGK, KC_##KGL, KC_##KGM, KC_##KGN, KC_##KGP, KC_##KGQ, KC_##KGR, \ + KC_##KHA, KC_##KHB, KC_##KHC, KC_##KHD, KC_##KHE, KC_##KHF, KC_##KHG, KC_##KHH, KC_##KHJ, KC_##KHK, KC_##KHL, KC_##KHM, KC_##KHN, KC_##KHP, KC_##KHQ, KC_##KHR, \ + KC_##KJA, KC_##KJB, KC_##KJC, KC_##KJD, KC_##KJE, KC_##KJF, KC_##KJG, KC_##KJH, KC_##KJJ, KC_##KJK, KC_##KJL, KC_##KJM, KC_##KJN, KC_##KJP, KC_##KJQ, KC_##KJR, \ + KC_##KKA, KC_##KKB, KC_##KKC, KC_##KKD, KC_##KKE, KC_##KKF, KC_##KKG, KC_##KKH, KC_##KKJ, KC_##KKK, KC_##KKL, KC_##KKM, KC_##KKN, KC_##KKP, KC_##KKQ, KC_##KKR, \ + KC_##KLA, KC_##KLB, KC_##KLC, KC_##KLD, KC_##KLE, KC_##KLF, KC_##KLG, KC_##KLH, KC_##KLJ, KC_##KLK, KC_##KLL, KC_##KLM, KC_##KLN, KC_##KLP, KC_##KLQ, KC_##KLR, \ + KC_##KMA, KC_##KMB, KC_##KMC, KC_##KMD, KC_##KME, KC_##KMF, KC_##KMG, KC_##KMH, KC_##KMJ, KC_##KMK, KC_##KML, KC_##KMM, KC_##KMN, KC_##KMP, KC_##KMQ, KC_##KMR, \ + KC_##KNA, KC_##KNB, KC_##KNC, KC_##KND, KC_##KNE, KC_##KNF, KC_##KNG, KC_##KNH, KC_##KNJ, KC_##KNK, KC_##KNL, KC_##KNM, KC_##KNN, KC_##KNP, KC_##KNQ, KC_##KNR, \ + KC_##KPA, KC_##KPB, KC_##KPC, KC_##KPD, KC_##KPE, KC_##KPF, KC_##KPG, KC_##KPH, KC_##KPJ, KC_##KPK, KC_##KPL, KC_##KPM, KC_##KPN, KC_##KPP, KC_##KPQ, KC_##KPR, \ + KC_##KQA, KC_##KQB, KC_##KQC, KC_##KQD, KC_##KQE, KC_##KQF, KC_##KQG, KC_##KQH, KC_##KQJ, KC_##KQK, KC_##KQL, KC_##KQM, KC_##KQN, KC_##KQP, KC_##KQQ, KC_##KQR, \ + KC_##KRA, KC_##KRB, KC_##KRC, KC_##KRD, KC_##KRE, KC_##KRF, KC_##KRG, KC_##KRH, KC_##KRJ, KC_##KRK, KC_##KRL, KC_##KRM, KC_##KRN, KC_##KRP, KC_##KRQ, KC_##KRR \ } /* 8 rows, 24 cols */ @@ -98,7 +81,7 @@ extern const uint16_t fn_actions[]; KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, KFS, KFT, KFU, KFV, KFW, KFX, KFY, KFZ, \ KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, KGS, KGT, KGU, KGV, KGW, KGX, KGY, KGZ, \ KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ \ -) KEYMAP( \ +) KEYMAP_16x16( \ KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, KAS, KAT, KAU, KAV, KAW, KAX, KAY, KAZ, \ KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, KBS, KBT, KBU, KBV, KBW, KBX, KBY, KBZ, \ KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, KCS, KCT, KCU, KCV, KCW, KCX, KCY, KCZ, \ @@ -109,74 +92,9 @@ extern const uint16_t fn_actions[]; KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ, \ NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ ) -/* 16 rows, 16 cols */ -#define KEYMAP_16x16( \ - KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, KAS, KAT, KAU, KAV, KAW, KAX, KAY, KAZ, \ - KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, KBS, KBT, KBU, KBV, KBW, KBX, KBY, KBZ, \ - KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, KCS, KCT, KCU, KCV, KCW, KCX, KCY, KCZ, \ - KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, KDS, KDT, KDU, KDV, KDW, KDX, KDY, KDZ, \ - KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, KES, KET, KEU, KEV, KEW, KEX, KEY, KEZ, \ - KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, KFS, KFT, KFU, KFV, KFW, KFX, KFY, KFZ, \ - KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, KGS, KGT, KGU, KGV, KGW, KGX, KGY, KGZ, \ - KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, KHS, KHT, KHU, KHV, KHW, KHX, KHY, KHZ, \ - KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, KJJ, KJK, KJL, KJM, KJN, KJP, KJQ, KJR, KJS, KJT, KJU, KJV, KJW, KJX, KJY, KJZ, \ - KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, KKJ, KKK, KKL, KKM, KKN, KKP, KKQ, KKR, KKS, KKT, KKU, KKV, KKW, KKX, KKY, KKZ, \ - KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, KLJ, KLK, KLL, KLM, KLN, KLP, KLQ, KLR, KLS, KLT, KLU, KLV, KLW, KLX, KLY, KLZ, \ - KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, KMJ, KMK, KML, KMM, KMN, KMP, KMQ, KMR, KMS, KMT, KMU, KMV, KMW, KMX, KMY, KMZ, \ - KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, KNJ, KNK, KNL, KNM, KNN, KNP, KNQ, KNR, KNS, KNT, KNU, KNV, KNW, KNX, KNY, KNZ, \ - KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, KPJ, KPK, KPL, KPM, KPN, KPP, KPQ, KPR, KPS, KPT, KPU, KPV, KPW, KPX, KPY, KPZ, \ - KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, KQJ, KQK, KQL, KQM, KQN, KQP, KQQ, KQR, KQS, KQT, KQU, KQV, KQW, KQX, KQY, KQZ, \ - KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, KRJ, KRK, KRL, KRM, KRN, KRP, KRQ, KRR, KRS, KRT, KRU, KRV, KRW, KRX, KRY, KRZ, \ - KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, KSJ, KSK, KSL, KSM, KSN, KSP, KSQ, KSR, KSS, KST, KSU, KSV, KSW, KSX, KSY, KSZ, \ - KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, KTJ, KTK, KTL, KTM, KTN, KTP, KTQ, KTR, KTS, KTT, KTU, KTV, KTW, KTX, KTY, KTZ, \ - KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, KUJ, KUK, KUL, KUM, KUN, KUP, KUQ, KUR, KUS, KUT, KUU, KUV, KUW, KUX, KUY, KUZ, \ - KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, KVJ, KVK, KVL, KVM, KVN, KVP, KVQ, KVR, KVS, KVT, KVU, KVV, KVW, KVX, KVY, KVZ, \ - KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, KWJ, KWK, KWL, KWM, KWN, KWP, KWQ, KWR, KWS, KWT, KWU, KWV, KWW, KWX, KWY, KWZ, \ - KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, KXJ, KXK, KXL, KXM, KXN, KXP, KXQ, KXR, KXS, KXT, KXU, KXV, KXW, KXX, KXY, KXZ, \ - KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, KYJ, KYK, KYL, KYM, KYN, KYP, KYQ, KYR, KYS, KYT, KYU, KYV, KYW, KYX, KYY, KYZ, \ - KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH, KZJ, KZK, KZL, KZM, KZN, KZP, KZQ, KZR, KZS, KZT, KZU, KZV, KZW, KZX, KZY, KZZ \ -) KEYMAP( \ - KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, KAJ, KAK, KAL, KAM, KAN, KAP, KAQ, KAR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, KBJ, KBK, KBL, KBM, KBN, KBP, KBQ, KBR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, KCJ, KCK, KCL, KCM, KCN, KCP, KCQ, KCR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, KDJ, KDK, KDL, KDM, KDN, KDP, KDQ, KDR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, KEJ, KEK, KEL, KEM, KEN, KEP, KEQ, KER, NO, NO, NO, NO, NO, NO, NO, NO, \ - KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, KFJ, KFK, KFL, KFM, KFN, KFP, KFQ, KFR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, KGJ, KGK, KGL, KGM, KGN, KGP, KGQ, KGR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, KHJ, KHK, KHL, KHM, KHN, KHP, KHQ, KHR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, KJJ, KJK, KJL, KJM, KJN, KJP, KJQ, KJR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, KKJ, KKK, KKL, KKM, KKN, KKP, KKQ, KKR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, KLJ, KLK, KLL, KLM, KLN, KLP, KLQ, KLR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, KMJ, KMK, KML, KMM, KMN, KMP, KMQ, KMR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, KNJ, KNK, KNL, KNM, KNN, KNP, KNQ, KNR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, KPJ, KPK, KPL, KPM, KPN, KPP, KPQ, KPR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, KQJ, KQK, KQL, KQM, KQN, KQP, KQQ, KQR, NO, NO, NO, NO, NO, NO, NO, NO, \ - KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, KRJ, KRK, KRL, KRM, KRN, KRP, KRQ, KRR, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ -) /* 24 rows, 8 cols */ #define KEYMAP_24x8( \ @@ -204,31 +122,39 @@ extern const uint16_t fn_actions[]; KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, \ KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, \ KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH \ -) KEYMAP( \ - KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO \ +) KEYMAP_16x16( \ + KAA, KAB, KAC, KAD, KAE, KAF, KAG, KAH, \ + KBA, KBB, KBC, KBD, KBE, KBF, KBG, KBH, \ + KCA, KCB, KCC, KCD, KCE, KCF, KCG, KCH, \ + KDA, KDB, KDC, KDD, KDE, KDF, KDG, KDH, \ + KEA, KEB, KEC, KED, KEE, KEF, KEG, KEH, \ + KFA, KFB, KFC, KFD, KFE, KFF, KFG, KFH, \ + KGA, KGB, KGC, KGD, KGE, KGF, KGG, KGH, \ + KHA, KHB, KHC, KHD, KHE, KHF, KHG, KHH, \ + KJA, KJB, KJC, KJD, KJE, KJF, KJG, KJH, \ + KKA, KKB, KKC, KKD, KKE, KKF, KKG, KKH, \ + KLA, KLB, KLC, KLD, KLE, KLF, KLG, KLH, \ + KMA, KMB, KMC, KMD, KME, KMF, KMG, KMH, \ + KNA, KNB, KNC, KND, KNE, KNF, KNG, KNH, \ + KPA, KPB, KPC, KPD, KPE, KPF, KPG, KPH, \ + KQA, KQB, KQC, KQD, KQE, KQF, KQG, KQH, \ + KRA, KRB, KRC, KRD, KRE, KRF, KRG, KRH, \ + KSA, KSB, KSC, KSD, KSE, KSF, KSG, KSH, \ + KTA, KTB, KTC, KTD, KTE, KTF, KTG, KTH, \ + KUA, KUB, KUC, KUD, KUE, KUF, KUG, KUH, \ + KVA, KVB, KVC, KVD, KVE, KVF, KVG, KVH, \ + KWA, KWB, KWC, KWD, KWE, KWF, KWG, KWH, \ + KXA, KXB, KXC, KXD, KXE, KXF, KXG, KXH, \ + KYA, KYB, KYC, KYD, KYE, KYF, KYG, KYH, \ + KZA, KZB, KZC, KZD, KZE, KZF, KZG, KZH, \ + NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO \ ) /* ANSI 104 keymap */ diff --git a/keyboard/kimera/keymap_default.c b/keyboard/kimera/keymap_default.c index d1c2134a..0764aa54 100644 --- a/keyboard/kimera/keymap_default.c +++ b/keyboard/kimera/keymap_default.c @@ -2,9 +2,9 @@ // Default #ifdef KEYMAP_SECTION_ENABLE -const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = { +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_SIZE] __attribute__ ((section (".keymap.keymaps"))) = { #else -const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = { +const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = { #endif /* Keymap 0: Default Layer * ,---------------------------------------------------------------------------------------. @@ -67,9 +67,9 @@ const uint16_t fn_actions[] PROGMEM = { [3] = ACTION_BACKLIGHT_INCREASE(), }; -#ifdef KEYMAP_EX_ENABLE +#ifdef KEYMAP_IN_EEPROM_ENABLE uint16_t keys_count(void) { - return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_SIZE; } uint16_t fn_actions_count(void) { diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 596e9135..a911c496 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -34,6 +34,8 @@ uint8_t col_mapping[MATRIX_COLS] = { 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; +uint8_t row_max_count = MUX_PORTS * 1; +uint8_t col_max_count = MUX_PORTS * (MUX_COUNT - 1); uint16_t shift_out_cache = 0; void kimera_init(void) @@ -58,8 +60,8 @@ uint8_t read_matrix_mapping(void) { uint8_t error = 0; uint8_t mux_config = 0; - uint8_t row_max_count = 0; - uint8_t col_max_count = 0; + row_max_count = 0; + col_max_count = 0; mux_config = eeprom_read_byte(EECONFIG_MUX_MAPPING); if (mux_config & (1<<7)) { @@ -106,8 +108,8 @@ uint8_t read_matrix_mapping(void) void write_matrix_mapping(void) { uint8_t mux_config = 0; - uint8_t row_max_count = 0; - uint8_t col_max_count = 0; + row_max_count = 0; + col_max_count = 0; for (uint8_t i = 0; i < MUX_COUNT; i++) { mux_config |= (mux_mapping[i] << i); diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index e96a142d..735a18ab 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -159,7 +159,7 @@ const uint16_t PROGMEM mux_inh_to_shift_out[] = { #define EECONFIG_MUX_MAPPING (uint8_t *)7 #define EECONFIG_ROW_COL_MAPPING (uint8_t *)8 #define MATRIX_MAPPING_SIZE MUX_COUNT * MUX_PORTS -#define EECONFIG_KEYMAP_EX 40 +#define EECONFIG_KEYMAP_IN_EEPROM 40 typedef struct { uint8_t mux_mapping; diff --git a/keyboard/kimera/matrix.c b/keyboard/kimera/matrix.c index 4e4f9f67..f7146e97 100644 --- a/keyboard/kimera/matrix.c +++ b/keyboard/kimera/matrix.c @@ -38,17 +38,19 @@ static uint8_t debouncing = DEBOUNCE; static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS]; +extern uint8_t row_max_count; +extern uint8_t col_max_count; inline uint8_t matrix_rows(void) { - return MATRIX_ROWS; + return row_max_count; } inline uint8_t matrix_cols(void) { - return MATRIX_COLS; + return col_max_count; } void matrix_init(void) @@ -64,7 +66,7 @@ void matrix_init(void) init_cols(); // initialize matrix state: all keys off - for (uint8_t i=0; i < MATRIX_ROWS; i++) { + for (uint8_t i=0; i < matrix_rows(); i++) { matrix[i] = 0; matrix_debouncing[i] = 0; } @@ -72,7 +74,7 @@ void matrix_init(void) uint8_t matrix_scan(void) { - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + 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(); @@ -90,7 +92,7 @@ uint8_t matrix_scan(void) if (--debouncing) { _delay_ms(1); } else { - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + for (uint8_t i = 0; i < matrix_rows(); i++) { matrix[i] = matrix_debouncing[i]; } } @@ -120,7 +122,7 @@ matrix_row_t matrix_get_row(uint8_t row) void matrix_print(void) { print("\nr/c 0123456789ABCDEF\n"); - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t row = 0; row < matrix_rows(); row++) { phex(row); print(": "); pbin_reverse16(matrix_get_row(row)); print("\n"); @@ -130,7 +132,7 @@ void matrix_print(void) uint8_t matrix_key_count(void) { uint8_t count = 0; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + for (uint8_t i = 0; i < matrix_rows(); i++) { count += bitpop16(matrix[i]); } return count; From c2a86959095756f9d0262dbac494d9cf1aeb7a5b Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 30 May 2014 10:54:16 +0900 Subject: [PATCH 04/29] kimera: Move keymap address definition to config.h --- keyboard/kimera/config.h | 3 ++- keyboard/kimera/kimera.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index 19fe83de..ef315b79 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -34,7 +34,8 @@ along with this program. If not, see . /* keymap in eeprom */ #define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 -#define KEYMAPS_COUNT 8 +#define KEYMAPS_COUNT 3 +#define EECONFIG_KEYMAP_IN_EEPROM 38 /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 735a18ab..3c29936b 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -159,7 +159,6 @@ const uint16_t PROGMEM mux_inh_to_shift_out[] = { #define EECONFIG_MUX_MAPPING (uint8_t *)7 #define EECONFIG_ROW_COL_MAPPING (uint8_t *)8 #define MATRIX_MAPPING_SIZE MUX_COUNT * MUX_PORTS -#define EECONFIG_KEYMAP_IN_EEPROM 40 typedef struct { uint8_t mux_mapping; From e5bf80061e14906c468877d61af3f8d12fe5eb19 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 30 May 2014 10:56:57 +0900 Subject: [PATCH 05/29] kimera: Reset matrix mapping also when config is 0 --- keyboard/kimera/kimera.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index a911c496..73d97892 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -20,6 +20,7 @@ along with this program. If not, see . #include #include #include "kimera.h" +#include "debug.h" uint8_t mux_mapping[MUX_COUNT] = { MUX_FOR_ROW, MUX_FOR_COL, MUX_FOR_COL, MUX_FOR_COL @@ -64,7 +65,7 @@ uint8_t read_matrix_mapping(void) col_max_count = 0; mux_config = eeprom_read_byte(EECONFIG_MUX_MAPPING); - if (mux_config & (1<<7)) { + if (mux_config == 0 || (mux_config & (1<<7))) { error++; return error; } From 1b76a97ff034ac1e8a32689b2095791d34038e00 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 30 May 2014 19:50:38 +0900 Subject: [PATCH 06/29] kimera: Add a makefie for 8M/3.3V board --- keyboard/kimera/Makefile_3300 | 149 ++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 keyboard/kimera/Makefile_3300 diff --git a/keyboard/kimera/Makefile_3300 b/keyboard/kimera/Makefile_3300 new file mode 100644 index 00000000..8b465f74 --- /dev/null +++ b/keyboard/kimera/Makefile_3300 @@ -0,0 +1,149 @@ +#---------------------------------------------------------------------------- +# 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 = kimera_lufa_3300 + +# Directory common source filess exist +TOP_DIR = ../.. + +# Directory keyboard dependent files exist +TARGET_DIR = . + +# project specific files +SRC = keymap_common.c \ + matrix.c \ + led.c \ + backlight.c \ + kimera.c + +ifdef KEYMAP + SRC := keymap_$(KEYMAP).c $(SRC) +else + SRC := keymap_default.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 +F_CPU = 8000000 + + +# +# 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 + +# Additional definitions from command line +ifdef DEFS + OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) +endif + +# 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 +#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#PS2_USE_BUSYWAIT = yes +BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality +KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom +KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +BREATHING_LED_ENABLE = yes # Enable breathing backlight + +# Optimize size but this may cause error "relocation truncated to fit" +#EXTRALDFLAGS = -Wl,--relax + +# Search Path +VPATH += $(TARGET_DIR) +VPATH += $(TOP_DIR) + +include $(TOP_DIR)/protocol/lufa.mk +include $(TOP_DIR)/protocol.mk +include $(TOP_DIR)/common.mk +include $(TOP_DIR)/rules.mk From e939c9d7a63cf6074c4f1c6e2dc5848cad9f0d39 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 30 May 2014 19:51:37 +0900 Subject: [PATCH 07/29] kimera: Correct the address of keymap in eeprom --- keyboard/kimera/config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index ef315b79..6850da15 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -35,7 +35,7 @@ along with this program. If not, see . #define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 -#define EECONFIG_KEYMAP_IN_EEPROM 38 +#define EECONFIG_KEYMAP_IN_EEPROM 40 /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST From 9365e693018fa794e92b37a866ee32c5c3a61928 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 30 May 2014 19:52:06 +0900 Subject: [PATCH 08/29] kimera: Fix a bug of program memory const --- keyboard/kimera/kimera.c | 71 +++++++++++++++++++++------------------- keyboard/kimera/kimera.h | 3 ++ 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 73d97892..edfaae14 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -19,6 +19,7 @@ along with this program. If not, see . #include #include +#include #include "kimera.h" #include "debug.h" @@ -42,6 +43,7 @@ uint16_t shift_out_cache = 0; void kimera_init(void) { // read config + write_matrix_mapping(); if (read_matrix_mapping()) { write_matrix_mapping(); } @@ -70,9 +72,9 @@ uint8_t read_matrix_mapping(void) return error; } - for (uint8_t i = 0; i < MUX_COUNT; i++) { - mux_mapping[i] = mux_config & (1< Date: Wed, 4 Jun 2014 00:57:00 +0900 Subject: [PATCH 09/29] kimera: Fix bugs of keymap and mux driving --- keyboard/kimera/kimera.c | 18 ++++++++++-------- keyboard/kimera/kimera.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index edfaae14..7c0f4aca 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -136,10 +136,10 @@ void write_matrix_mapping(void) void shift_out_word(uint16_t data) { - SPDR = (data & 0xFF); - while (!(SPSR & (1<>8) & 0xFF); while (!(SPSR & (1< Date: Thu, 17 Jul 2014 12:07:13 +0900 Subject: [PATCH 10/29] kimera: Add support for Kimera v2 --- keyboard/kimera/Makefile | 7 ++++++ keyboard/kimera/kimera.h | 48 +++++++++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index 1b8a6d7d..96f7dd28 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -113,6 +113,13 @@ OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT # USBaspLoader 2048 OPT_DEFS += -DBOOTLOADER_SIZE=4096 +# PCB Version +ifdef VER + OPT_DEFS += -DKIMERA_$(REV) +else + OPT_DEFS += -DKIMERA_V2 +endif + # Additional definitions from command line ifdef DEFS OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 809a170d..45f1c3b8 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -92,29 +92,30 @@ const uint8_t PROGMEM zx_bit[] = { #define MUX_TO_ZX_BIT(x) (pgm_read_byte(zx_bit + (x))) /* + Shift Register Multiplexer ,----------. ,------------. MOSI --| SER 0 |----| INH X0~X7 |===============. - SCK --|>SCK 1 |----| A | | + SCK --|>SCK 1 |----| C | | RCK --|>RCK 2 |----| B | ,-------------+-------------. - | 3 |----| C | | | | | | | | | + | 3 |----| A | | | | | | | | | | | `------------' P26 P27 P28 P25 P29 P32 P30 P31 | | ,------------. - | 4 |----| A X0~X7 |===============. + | 4 |----| C X0~X7 |===============. | 5 |----| B | | - | 6 |----| C | ,-------------+-------------. + | 6 |----| A | ,-------------+-------------. | 7 |----| INH | | | | | | | | | | | `------------' P2 P3 P4 P1 P5 P8 P6 P7 | | ,------------. | 8 |----| INH X0~X7 |===============. - | 9 |----| A | | + | 9 |----| C | | | 10 |----| B | ,-------------+-------------. - | 11 |----| C | | | | | | | | | + | 11 |----| A | | | | | | | | | | | `------------' P10 P11 P12 P9 P13 P16 P14 P15 | | ,------------. - | 12 |----| A X0~X7 |===============. + | 12 |----| C X0~X7 |===============. | 13 |----| B | | - | 14 |----| C | ,-------------+-------------. + | 14 |----| A | ,-------------+-------------. | 15 |----| INH | | | | | | | | | `----------' `------------' P18 P19 P20 P17 P21 P24 P22 P23 */ @@ -123,6 +124,7 @@ const uint8_t PROGMEM zx_bit[] = { #define MUX_PORTS 8 #define PX_TO_MUX(x) (x>>3) // (x / MUX_PORTS) +#if defined(KIMERA_V1) enum { MUX4_INH = 0, MUX4_A, @@ -141,14 +143,44 @@ enum { MUX3_C, MUX3_INH }; +#elif defined(KIMERA_V2) +enum { + MUX4_INH = 0, + MUX4_C, + MUX4_B, + MUX4_A, + MUX1_C, + MUX1_B, + MUX1_A, + MUX1_INH, + MUX2_INH, + MUX2_C, + MUX2_B, + MUX2_A, + MUX3_C, + MUX3_B, + MUX3_A, + MUX3_INH +}; +#endif #ifdef KIMERA_C +#if defined(KIMERA_V1) const uint16_t PROGMEM px_to_shift_out[] = { 3< Date: Mon, 27 Oct 2014 16:10:13 +0900 Subject: [PATCH 11/29] kimera: Initial implement for Kimera v5 --- keyboard/kimera/Makefile | 3 +- keyboard/kimera/Makefile.pjrc | 3 +- .../kimera/{Makefile_3300 => Makefile_8M} | 3 +- keyboard/kimera/backlight.c | 14 +- keyboard/kimera/config.h | 2 +- keyboard/kimera/i2cmaster.h | 178 ++++++++++++ keyboard/kimera/kimera.c | 258 +++++++++++------- keyboard/kimera/kimera.h | 231 +++++----------- keyboard/kimera/matrix.c | 11 +- keyboard/kimera/twimaster.c | 203 ++++++++++++++ 10 files changed, 628 insertions(+), 278 deletions(-) rename keyboard/kimera/{Makefile_3300 => Makefile_8M} (99%) create mode 100644 keyboard/kimera/i2cmaster.h create mode 100644 keyboard/kimera/twimaster.c diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index 96f7dd28..cccec58c 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -52,6 +52,7 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ + twimaster.c \ kimera.c ifdef KEYMAP @@ -117,7 +118,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096 ifdef VER OPT_DEFS += -DKIMERA_$(REV) else - OPT_DEFS += -DKIMERA_V2 + OPT_DEFS += -DKIMERA_V5 endif # Additional definitions from command line diff --git a/keyboard/kimera/Makefile.pjrc b/keyboard/kimera/Makefile.pjrc index afbb0a03..140e64c4 100644 --- a/keyboard/kimera/Makefile.pjrc +++ b/keyboard/kimera/Makefile.pjrc @@ -52,12 +52,13 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ + twimaster.c \ kimera.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) else - SRC := keymap_poker.c $(SRC) + SRC := keymap_default.c $(SRC) endif CONFIG_H = config.h diff --git a/keyboard/kimera/Makefile_3300 b/keyboard/kimera/Makefile_8M similarity index 99% rename from keyboard/kimera/Makefile_3300 rename to keyboard/kimera/Makefile_8M index 8b465f74..bced6dee 100644 --- a/keyboard/kimera/Makefile_3300 +++ b/keyboard/kimera/Makefile_8M @@ -39,7 +39,7 @@ #---------------------------------------------------------------------------- # Target file name (without extension). -TARGET = kimera_lufa_3300 +TARGET = kimera_8m_lufa # Directory common source filess exist TOP_DIR = ../.. @@ -52,6 +52,7 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ + twimaster.c \ kimera.c ifdef KEYMAP diff --git a/keyboard/kimera/backlight.c b/keyboard/kimera/backlight.c index 10564411..a0a6f473 100644 --- a/keyboard/kimera/backlight.c +++ b/keyboard/kimera/backlight.c @@ -33,14 +33,14 @@ static const uint8_t backlight_table[] PROGMEM = { }; /* Backlight pin configuration - * BL: PB5 (D9) + * LED4: PB6 (D10) OC1B */ void backlight_enable(void) { // Turn on PWM - BL_DDR |= (1<. /* USB Device descriptor parameter */ #define VENDOR_ID 0x16c0 #define PRODUCT_ID 0x27db -#define DEVICE_VER 0x0001 +#define DEVICE_VER 0x0005 #define MANUFACTURER kai1103@gmail.com #define PRODUCT Kimera #define DESCRIPTION t.m.k. keyboard firmware for Kimera diff --git a/keyboard/kimera/i2cmaster.h b/keyboard/kimera/i2cmaster.h new file mode 100644 index 00000000..70f51fd3 --- /dev/null +++ b/keyboard/kimera/i2cmaster.h @@ -0,0 +1,178 @@ +#ifndef _I2CMASTER_H +#define _I2CMASTER_H 1 +/************************************************************************* +* Title: C include file for the I2C master interface +* (i2cmaster.S or twimaster.c) +* Author: Peter Fleury http://jump.to/fleury +* File: $Id: i2cmaster.h,v 1.10 2005/03/06 22:39:57 Peter Exp $ +* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 +* Target: any AVR device +* Usage: see Doxygen manual +**************************************************************************/ + +#ifdef DOXYGEN +/** + @defgroup pfleury_ic2master I2C Master library + @code #include @endcode + + @brief I2C (TWI) Master Software Library + + Basic routines for communicating with I2C slave devices. This single master + implementation is limited to one bus master on the I2C bus. + + This I2c library is implemented as a compact assembler software implementation of the I2C protocol + which runs on any AVR (i2cmaster.S) and as a TWI hardware interface for all AVR with built-in TWI hardware (twimaster.c). + Since the API for these two implementations is exactly the same, an application can be linked either against the + software I2C implementation or the hardware I2C implementation. + + Use 4.7k pull-up resistor on the SDA and SCL pin. + + Adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module + i2cmaster.S to your target when using the software I2C implementation ! + + Adjust the CPU clock frequence F_CPU in twimaster.c or in the Makfile when using the TWI hardware implementaion. + + @note + The module i2cmaster.S is based on the Atmel Application Note AVR300, corrected and adapted + to GNU assembler and AVR-GCC C call interface. + Replaced the incorrect quarter period delays found in AVR300 with + half period delays. + + @author Peter Fleury pfleury@gmx.ch http://jump.to/fleury + + @par API Usage Example + The following code shows typical usage of this library, see example test_i2cmaster.c + + @code + + #include + + + #define Dev24C02 0xA2 // device address of EEPROM 24C02, see datasheet + + int main(void) + { + unsigned char ret; + + i2c_init(); // initialize I2C library + + // write 0x75 to EEPROM address 5 (Byte Write) + i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode + i2c_write(0x05); // write address = 5 + i2c_write(0x75); // write value 0x75 to EEPROM + i2c_stop(); // set stop conditon = release bus + + + // read previously written value back from EEPROM address 5 + i2c_start_wait(Dev24C02+I2C_WRITE); // set device address and write mode + + i2c_write(0x05); // write address = 5 + i2c_rep_start(Dev24C02+I2C_READ); // set device address and read mode + + ret = i2c_readNak(); // read one byte from EEPROM + i2c_stop(); + + for(;;); + } + @endcode + +*/ +#endif /* DOXYGEN */ + +/**@{*/ + +#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304 +#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !" +#endif + +#include + +/** defines the data direction (reading from I2C device) in i2c_start(),i2c_rep_start() */ +#define I2C_READ 1 + +/** defines the data direction (writing to I2C device) in i2c_start(),i2c_rep_start() */ +#define I2C_WRITE 0 + + +/** + @brief initialize the I2C master interace. Need to be called only once + @param void + @return none + */ +extern void i2c_init(void); + + +/** + @brief Terminates the data transfer and releases the I2C bus + @param void + @return none + */ +extern void i2c_stop(void); + + +/** + @brief Issues a start condition and sends address and transfer direction + + @param addr address and transfer direction of I2C device + @retval 0 device accessible + @retval 1 failed to access device + */ +extern unsigned char i2c_start(unsigned char addr); + + +/** + @brief Issues a repeated start condition and sends address and transfer direction + + @param addr address and transfer direction of I2C device + @retval 0 device accessible + @retval 1 failed to access device + */ +extern unsigned char i2c_rep_start(unsigned char addr); + + +/** + @brief Issues a start condition and sends address and transfer direction + + If device is busy, use ack polling to wait until device ready + @param addr address and transfer direction of I2C device + @return none + */ +extern void i2c_start_wait(unsigned char addr); + + +/** + @brief Send one byte to I2C device + @param data byte to be transfered + @retval 0 write successful + @retval 1 write failed + */ +extern unsigned char i2c_write(unsigned char data); + + +/** + @brief read one byte from the I2C device, request more data from device + @return byte read from I2C device + */ +extern unsigned char i2c_readAck(void); + +/** + @brief read one byte from the I2C device, read is followed by a stop condition + @return byte read from I2C device + */ +extern unsigned char i2c_readNak(void); + +/** + @brief read one byte from the I2C device + + Implemented as a macro, which calls either i2c_readAck or i2c_readNak + + @param ack 1 send ack, request more data from device
+ 0 send nak, read is followed by a stop condition + @return byte read from I2C device + */ +extern unsigned char i2c_read(unsigned char ack); +#define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak(); + + +/**@}*/ +#endif diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 7c0f4aca..d79c13ca 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -20,88 +20,73 @@ along with this program. If not, see . #include #include #include +#include "i2cmaster.h" #include "kimera.h" #include "debug.h" -uint8_t mux_mapping[MUX_COUNT] = { - MUX_FOR_ROW, MUX_FOR_COL, MUX_FOR_COL, MUX_FOR_COL -}; -uint8_t row_mapping[MATRIX_ROWS] = { +uint8_t row_mapping[PX_COUNT] = { 0, 1, 2, 3, 4, 5, 6, 7, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, + UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED }; -uint8_t col_mapping[MATRIX_COLS] = { +uint8_t col_mapping[PX_COUNT] = { 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31 + 24, 25, 26, 27, 28, 29, 30, 31, + UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED }; -uint8_t row_max_count = MUX_PORTS * 1; -uint8_t col_max_count = MUX_PORTS * (MUX_COUNT - 1); -uint16_t shift_out_cache = 0; +uint8_t row_count = 8; +uint8_t col_count = 24; +uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; void kimera_init(void) { - // read config - write_matrix_mapping(); + /* read config */ + write_matrix_mapping(); /* debug */ if (read_matrix_mapping()) { write_matrix_mapping(); } - // init shift out pins - MOSI_DDR |= (1< PX_COUNT) error++; - for (uint8_t mux = 0; mux < MUX_COUNT; mux++) { - mux_mapping[mux] = mux_config & (1 << mux); - if (mux_mapping[mux] == MUX_FOR_COL) { - col_max_count += MUX_PORTS; + /* read row mapping */ + uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; + for (uint8_t i = 0; i < PX_COUNT; i++) { + if (i < row_count) { + row_mapping[i] = eeprom_read_byte(mapping++); + if (row_mapping[i] >= PX_COUNT) error++; } else { - row_max_count += MUX_PORTS; + row_mapping[i] = UNCONFIGURED; } } - if ((col_max_count == 0) || (row_max_count == 0)) { - error++; - } - - uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; - for (uint8_t row = 0; row < row_max_count; row++) { - row_mapping[row] = eeprom_read_byte(mapping++); - if (row_mapping[row] != UNCONFIGURED) { - if (mux_mapping[PX_TO_MUX(row_mapping[row])] != MUX_FOR_ROW) { - row_mapping[row] = UNCONFIGURED; - error++; - } + /* read col mapping*/ + for (uint8_t i = 0; i < PX_COUNT; i++) { + if (i < col_count) { + col_mapping[i] = eeprom_read_byte(mapping++); + if (col_mapping[i] >= PX_COUNT) error++; } - } - for (uint8_t col = 0; col < col_max_count; col++) { - col_mapping[col] = eeprom_read_byte(mapping++); - if (col_mapping[col] != UNCONFIGURED) { - if (mux_mapping[PX_TO_MUX(col_mapping[col])] != MUX_FOR_COL) { - col_mapping[col] = UNCONFIGURED; - error++; - } + else { + col_mapping[i] = UNCONFIGURED; } } @@ -110,66 +95,36 @@ uint8_t read_matrix_mapping(void) void write_matrix_mapping(void) { - uint8_t mux_config = 0; - row_max_count = 0; - col_max_count = 0; - - for (uint8_t mux = 0; mux < MUX_COUNT; mux++) { - mux_config |= (mux_mapping[mux] << mux); - if (mux_mapping[mux] == MUX_FOR_COL) { - col_max_count += MUX_PORTS; - } - else { - row_max_count += MUX_PORTS; - } - } - eeprom_write_byte(EECONFIG_MUX_MAPPING, mux_config); + /* write number of rows and cols */ + eeprom_write_byte(EECONFIG_ROW_COUNT, row_count); + eeprom_write_byte(EECONFIG_COL_COUNT, col_count); + /* write row mapping */ uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; - for (uint8_t row = 0; row < row_max_count; row++) { + for (uint8_t row = 0; row < row_count; row++) { eeprom_write_byte(mapping++, row_mapping[row]); } - for (uint8_t col = 0; col < col_max_count; col++) { + /* write col mapping */ + for (uint8_t col = 0; col < col_count; col++) { eeprom_write_byte(mapping++, col_mapping[col]); } } -void shift_out_word(uint16_t data) -{ - SPDR = ((data>>8) & 0xFF); - while (!(SPSR & (1<. #include "matrix.h" /* - Pro Micro + U1 (Pro Micro) ,----------------. TX --| TX0(PD3) RAW |-- RX --| RX1(PD2) GND |-- --| GND RESET |-- RST --| GND VCC |-- - SDA --| 2(PD1) (PF4)A3 |-- (Z4) - SCL --| 3(PD0) (PF5)A2 |-- (Z1) - (RCK) --| 4(PD4) (PF6)A1 |-- (Z2) - LED1 --| 5(PC6) (PF7)A0 |-- (Z3) - LED2 --| 6(PD7) (PB1)15 |-- SCK - (SJ1) --| 7(PE6) (PB3)14 |-- MISO - (SJ2) --| 8(PB4) (PB2)16 |-- MOSI - BL --| 9(PB5) (PB6)10 |-- LED3 + SDA --| 2(PD1) (PF4)A3 |-- + SCL --| 3(PD0) (PF5)A2 |-- + (INT) --| 4(PD4) (PF6)A1 |-- + --| 5(PC6) (PF7)A0 |-- + --| 6(PD7) (PB1)15 |-- SCK + LED2 --| 7(PE6) (PB3)14 |-- MISO + LED1 --| 8(PB4) (PB2)16 |-- MOSI + LED3 --| 9(PB5) (PB6)10 |-- LED4 `----------------' */ -#define LED1_PORT PORTC -#define LED1_PIN PINC -#define LED1_DDR DDRC -#define LED1_BIT PC6 +#define LED1_PORT PORTB +#define LED1_PIN PINB +#define LED1_DDR DDRB +#define LED1_BIT PB4 -#define LED2_PORT PORTD -#define LED2_PIN PIND -#define LED2_DDR DDRD -#define LED2_BIT PD7 +#define LED2_PORT PORTE +#define LED2_PIN PINE +#define LED2_DDR DDRE +#define LED2_BIT PE6 #define LED3_PORT PORTB #define LED3_PIN PINB #define LED3_DDR DDRB -#define LED3_BIT PB6 +#define LED3_BIT PB5 -#define BL_PORT PORTB -#define BL_PIN PINB -#define BL_DDR DDRB -#define BL_BIT PB5 -#define BL_OCR OCR1A - -#define RCK_PORT PORTD -#define RCK_PIN PIND -#define RCK_DDR DDRD -#define RCK_BIT PD4 - -#define SCK_PORT PORTB -#define SCK_PIN PINB -#define SCK_DDR DDRB -#define SCK_BIT PB1 - -#define MOSI_PORT PORTB -#define MOSI_PIN PINB -#define MOSI_DDR DDRB -#define MOSI_BIT PB2 - -#define MISO_PORT PORTB -#define MISO_PIN PINB -#define MISO_DDR DDRB -#define MISO_BIT PB3 - -#define ZX_PORT PORTF -#define ZX_PIN PINF -#define ZX_DDR DDRF -#ifdef KIMERA_C -const uint8_t PROGMEM zx_bit[] = { - PF5, PF6, PF7, PF4 -}; -#endif -#define MUX_TO_ZX_BIT(x) (pgm_read_byte(zx_bit + (x))) +#define LED4_PORT PORTB +#define LED4_PIN PINB +#define LED4_DDR DDRB +#define LED4_BIT PB6 +#define LED4_OCR OCR1B /* - - Shift Register Multiplexer - ,----------. ,------------. - MOSI --| SER 0 |----| INH X0~X7 |===============. - SCK --|>SCK 1 |----| C | | - RCK --|>RCK 2 |----| B | ,-------------+-------------. - | 3 |----| A | | | | | | | | | - | | `------------' P26 P27 P28 P25 P29 P32 P30 P31 - | | ,------------. - | 4 |----| C X0~X7 |===============. - | 5 |----| B | | - | 6 |----| A | ,-------------+-------------. - | 7 |----| INH | | | | | | | | | - | | `------------' P2 P3 P4 P1 P5 P8 P6 P7 - | | ,------------. - | 8 |----| INH X0~X7 |===============. - | 9 |----| C | | - | 10 |----| B | ,-------------+-------------. - | 11 |----| A | | | | | | | | | - | | `------------' P10 P11 P12 P9 P13 P16 P14 P15 - | | ,------------. - | 12 |----| C X0~X7 |===============. - | 13 |----| B | | - | 14 |----| A | ,-------------+-------------. - | 15 |----| INH | | | | | | | | | - `----------' `------------' P18 P19 P20 P17 P21 P24 P22 P23 + IC1 (PCA9555) IC2 (PCA9555) + ,----------. ,----------. + SDA --| SDA P00 |-- P1 SDA --| SDA P00 |-- P9 + SCL --| SCL P01 |-- P2 SCL --| SCL P01 |-- P10 + INT --| INT P02 |-- P3 INT --| INT P02 |-- P11 + | P03 |-- P4 | P03 |-- P12 + GND --| A0 P04 |-- P5 VCC --| A0 P04 |-- P13 + SJ1 --| A1 P05 |-- P6 SJ1 --| A1 P05 |-- P14 + SJ2 --| A2 P06 |-- P7 SJ2 --| A2 P06 |-- P15 + | P07 |-- P8 | P07 |-- P16 + | | | | + | P10 |-- P25 | P10 |-- P17 + | P11 |-- P26 | P11 |-- P18 + | P12 |-- P27 | P12 |-- P19 + | P13 |-- P28 | P13 |-- P20 + | P14 |-- P29 | P14 |-- P21 + | P15 |-- P30 | P15 |-- P22 + | P16 |-- P31 | P16 |-- P23 + | P17 |-- P32 | P17 |-- P24 + `----------' `----------' */ -#define MUX_COUNT 4 -#define MUX_PORTS 8 -#define PX_TO_MUX(x) (x>>3) // (x / MUX_PORTS) - -#if defined(KIMERA_V1) +#define EXP_COUNT 2 +#define EXP_ADDR(n) ((0x20+(n))<<1) +#define EXP_OUTPUT 0 +#define EXP_INPUT 1 +#define EXP_PORT_COUNT 2 +#define EXP_PIN_PER_PORT 8 enum { - MUX4_INH = 0, - MUX4_A, - MUX4_B, - MUX4_C, - MUX1_A, - MUX1_B, - MUX1_C, - MUX1_INH, - MUX2_INH, - MUX2_A, - MUX2_B, - MUX2_C, - MUX3_A, - MUX3_B, - MUX3_C, - MUX3_INH + EXP_COMM_INPUT_0 = 0, + EXP_COMM_INPUT_1, + EXP_COMM_OUTPUT_0, + EXP_COMM_OUTPUT_1, + EXP_COMM_INVERSION_0, + EXP_COMM_INVERSION_1, + EXP_COMM_CONFIG_0, + EXP_COMM_CONFIG_1 }; -#elif defined(KIMERA_V2) -enum { - MUX4_INH = 0, - MUX4_C, - MUX4_B, - MUX4_A, - MUX1_C, - MUX1_B, - MUX1_A, - MUX1_INH, - MUX2_INH, - MUX2_C, - MUX2_B, - MUX2_A, - MUX3_C, - MUX3_B, - MUX3_A, - MUX3_INH -}; -#endif +#define PX_TO_EXP(x) (((x)>>5<<1)+((((x)>>3)&1)^(((x)>>4)&1))) +#define PX_TO_PORT(x) (((x)>>4)&1) +#define PX_TO_PIN(x) ((x)&7) +#define PX_COUNT (EXP_PIN_PER_PORT * EXP_PORT_COUNT * EXP_COUNT) #ifdef KIMERA_C -#if defined(KIMERA_V1) -const uint16_t PROGMEM px_to_shift_out[] = { - 3< http://jump.to/fleury +* File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $ +* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 +* Target: any AVR device with hardware TWI +* Usage: API compatible with I2C Software Library i2cmaster.h +**************************************************************************/ +#include +#include + +#include +#include "debug.h" + + +/* define CPU frequency in Mhz here if not defined in Makefile */ +#ifndef F_CPU +#define F_CPU 4000000UL +#endif + +/* I2C clock in Hz */ +#define SCL_CLOCK 400000L + + +/************************************************************************* + Initialization of the I2C bus interface. Need to be called only once +*************************************************************************/ +void i2c_init(void) +{ + /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ + + TWSR = 0; /* no prescaler */ + TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ + +}/* i2c_init */ + + +/************************************************************************* + Issues a start condition and sends address and transfer direction. + return 0 = device accessible, 1= failed to access device +*************************************************************************/ +unsigned char i2c_start(unsigned char address) +{ + uint8_t twst; + + // send START condition + TWCR = (1< Date: Fri, 31 Oct 2014 15:30:32 +0900 Subject: [PATCH 12/29] kimera: Implement i2c auto-scan and timeout --- keyboard/kimera/Makefile | 2 +- keyboard/kimera/kimera.c | 83 ++++++++++++-- keyboard/kimera/kimera.h | 5 +- keyboard/kimera/matrix.c | 4 + keyboard/kimera/twimaster.c | 220 ++++++++++++++++++------------------ 5 files changed, 194 insertions(+), 120 deletions(-) diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index cccec58c..e6ecf532 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -140,7 +140,7 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA #PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom -KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor BREATHING_LED_ENABLE = yes # Enable breathing backlight # Optimize size but this may cause error "relocation truncated to fit" diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index d79c13ca..5f02a87c 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -19,11 +19,18 @@ along with this program. If not, see . #include #include +#include +#include #include +#include "action.h" +#include "suspend.h" #include "i2cmaster.h" #include "kimera.h" #include "debug.h" +#define SCL_CLOCK 400000L +extern uint8_t i2c_force_stop; + uint8_t row_mapping[PX_COUNT] = { 0, 1, 2, 3, 4, 5, 6, 7, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, @@ -39,6 +46,7 @@ uint8_t col_mapping[PX_COUNT] = { uint8_t row_count = 8; uint8_t col_count = 24; uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; +uint8_t exp_status = 0; void kimera_init(void) { @@ -51,8 +59,19 @@ void kimera_init(void) /* init i2c */ i2c_init(); - /* init i/o expander */ - expander_init(); + /* init i/o expanders */ + kimera_scan(); + + /* init watch dog */ + wdt_init(); +} + +void wdt_init(void) +{ + cli(); + wdt_reset(); + wdt_intr_enable(WDTO_1S); + sei(); } uint8_t read_matrix_mapping(void) @@ -110,9 +129,34 @@ void write_matrix_mapping(void) } } +void kimera_scan(void) +{ + wdt_reset(); + uint8_t ret; + for (uint8_t exp = 0; exp < EXP_COUNT; exp++) { + ret = i2c_start(EXP_ADDR(exp) | I2C_READ); + if (exp_status & (1< http://jump.to/fleury -* File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $ -* Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 -* Target: any AVR device with hardware TWI -* Usage: API compatible with I2C Software Library i2cmaster.h -**************************************************************************/ + * Title: I2C master library using hardware TWI interface + * Author: Peter Fleury http://jump.to/fleury + * File: $Id: twimaster.c,v 1.3 2005/07/02 11:14:21 Peter Exp $ + * Software: AVR-GCC 3.4.3 / avr-libc 1.2.3 + * Target: any AVR device with hardware TWI + * Usage: API compatible with I2C Software Library i2cmaster.h + **************************************************************************/ #include #include @@ -21,60 +21,62 @@ /* I2C clock in Hz */ #define SCL_CLOCK 400000L +volatile uint8_t i2c_force_stop = 0; +#define CHECK_FORCE_STOP() if(i2c_force_stop){i2c_force_stop=0;break;} /************************************************************************* - Initialization of the I2C bus interface. Need to be called only once -*************************************************************************/ + Initialization of the I2C bus interface. Need to be called only once + *************************************************************************/ void i2c_init(void) { - /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ - - TWSR = 0; /* no prescaler */ - TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ + /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */ + + TWSR = 0; /* no prescaler */ + TWBR = ((F_CPU/SCL_CLOCK)-16)/2; /* must be > 10 for stable operation */ }/* i2c_init */ -/************************************************************************* +/************************************************************************* Issues a start condition and sends address and transfer direction. return 0 = device accessible, 1= failed to access device -*************************************************************************/ + *************************************************************************/ unsigned char i2c_start(unsigned char address) { uint8_t twst; - // send START condition - TWCR = (1< Date: Fri, 31 Oct 2014 15:31:41 +0900 Subject: [PATCH 13/29] kimera: Improve robustness of output port of IO expander - Avoid output pin short to GND issue --- keyboard/kimera/kimera.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 5f02a87c..7318ab9a 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -181,7 +181,7 @@ void unselect_rows(void) /* set all output registers to 0xFF */ init_data(0xFF); for (uint8_t exp = 0; exp < EXP_COUNT; exp++) { - expander_write_output(exp, data[exp]); + expander_write_config(exp, data[exp]); } } @@ -193,13 +193,13 @@ void select_row(uint8_t row) if (px != UNCONFIGURED) { uint8_t exp = PX_TO_EXP(px); data[exp][PX_TO_PORT(px)] &= ~(1 << PX_TO_PIN(px)); - expander_write_output(exp, data[exp]); + expander_write_config(exp, data[exp]); } } void expander_init(uint8_t exp) { - init_data(0xFF); + init_data(0x00); /* write inversion register */ /* @@ -209,15 +209,20 @@ void expander_init(uint8_t exp) */ /* set output bit */ + /* for (uint8_t row = 0; row < row_count; row++) { uint8_t px = row_mapping[row]; if (px != UNCONFIGURED) { data[PX_TO_EXP(px)][PX_TO_PORT(px)] &= ~(1 << PX_TO_PIN(px)); } } + */ /* write config registers */ - expander_write_config(exp, data[exp]); + //expander_write_config(exp, data[exp]); + + /* write output registers */ + expander_write_output(exp, data[exp]); } uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data) From 34de691cde3d030f1a6c5ea33e2632013c4701c9 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 4 Nov 2014 10:36:03 +0900 Subject: [PATCH 14/29] kimera: Change procedure when i2c timeout --- keyboard/kimera/kimera.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 7318ab9a..d4987ade 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -28,7 +28,8 @@ along with this program. If not, see . #include "kimera.h" #include "debug.h" -#define SCL_CLOCK 400000L +#define SCL_CLOCK 400000L +#define SCL_DURATION (1000000L/SCL_CLOCK)/2 extern uint8_t i2c_force_stop; uint8_t row_mapping[PX_COUNT] = { @@ -296,18 +297,21 @@ ISR(WDT_vect) { dprintf("i2c timeout\n"); + /* let slave to release SDA */ + TWCR = 0; + DDRD |= (1< Date: Wed, 5 Nov 2014 16:58:37 +0900 Subject: [PATCH 15/29] kimera: Add support for two-handed split keyboard - Enable with 'TWO_HEADED_KIMERA' --- keyboard/kimera/config.h | 6 +- keyboard/kimera/keymap_two_headed.c | 102 ++++++++++++++++++++++++++++ keyboard/kimera/kimera.c | 21 +++++- keyboard/kimera/kimera.h | 4 ++ keyboard/kimera/matrix.c | 15 ++++ 5 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 keyboard/kimera/keymap_two_headed.c diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index 97140f3d..40c7192e 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -28,14 +28,14 @@ along with this program. If not, see . #define DESCRIPTION t.m.k. keyboard firmware for Kimera /* key matrix size */ -#define MATRIX_ROWS 24 -#define MATRIX_COLS 24 +#define MATRIX_ROWS 32 +#define MATRIX_COLS 32 /* keymap in eeprom */ #define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 -#define EECONFIG_KEYMAP_IN_EEPROM 40 +#define EECONFIG_KEYMAP_IN_EEPROM 41 /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST diff --git a/keyboard/kimera/keymap_two_headed.c b/keyboard/kimera/keymap_two_headed.c new file mode 100644 index 00000000..df48664d --- /dev/null +++ b/keyboard/kimera/keymap_two_headed.c @@ -0,0 +1,102 @@ +#include "keymap_common.h" + +// Two-headed +#ifdef KEYMAP_SECTION_ENABLE +const uint8_t keymaps[KEYMAPS_COUNT][MATRIX_SIZE] __attribute__ ((section (".keymap.keymaps"))) = { +#else +const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = { +#endif + /* Keymap 0: Default Layer + * ,----------------------------------------. ,------------------------------------------------. + * | ||Esc| | F1| F2| F3| F4| | | F5| F6| F7| F8| | F9|F10|F11|F12||Psc|Slk|Pus| + * |---------------||-----------------------| |-----------------------------------||-----------| + * |Num| /| *| -|| `| 1| 2| 3| 4| 5| | 6| 7| 8| 9| 0| -| =|Backsp ||Ins|Hom|PgU| + * |---------------||-------------------------. `-----------------------------------||-----------| + * | 7| 8| 9| ||Tab | Q| W| E| R| T| | Y| U| I| O| P| [| ]| \||Del|End|PgD| + * |-----------| +||--------------------------. `---------------------------------||-----------| + * | 4| 5| 6| ||Caps | A| S| D| F| G| | H| J| K| L| ;| '|Return || | + * |---------------||----------------------------. `-------------------------------|| ,---. | + * | 1| 2| 3| ||Shift | Z| X| C| V| B| | N| M| ,| .| /|Shift || |Up | | + * |-----------|Ent||----------------------------| |------------------------------||-----------| + * | 0| .| ||Ctrl|Gui |Alt | Space | | Space |Alt |Gui |Fn0 |Ctrl||Lef|Dow|Rig| + * `---------------------------------------------' `-------------------------------------------' + */ + KEYMAP_16x16( + NO, NO, NO, NO, ESC, NO, F1, F2, F3, F4, NO, NO, NO, NO, NO, NO, \ + NLCK,PSLS,PAST,PMNS,GRV, 1, 2, 3, 4, 5, NO, NO, NO, NO, NO, NO, \ + P7, P8, P9, PPLS,TAB, Q, W, E, R, T, NO, NO, NO, NO, NO, NO, \ + P4, P5, P6, NO, CAPS,A, S, D, F, G, NO, NO, NO, NO, NO, NO, \ + P1, P2, P3, PENT,LSFT,Z, X, C, V, B, NO, NO, NO, NO, NO, NO, \ + P0, NO, PDOT,NO, LCTL,LGUI,LALT,NO, SPC, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + + F5, F6, F7, F8, F9, F10, F11, F12, PSCR,SLCK,PAUS,NO, NO, NO, NO, NO, \ + 6, 7, 8, 9, 0, MINS,EQL, BSPC,INS, HOME,PGUP,NO, NO, NO, NO, NO, \ + Y, U, I, O, P, LBRC,RBRC,BSLS,DEL, END, PGDN,NO, NO, NO, NO, NO, \ + H, J, K, L, SCLN,QUOT,NO, ENT, NO, NO, NO, NO, NO, NO, NO, NO, \ + N, M, COMM,DOT, SLSH,NO, NO, RSFT,NO, UP, NO, NO, NO, NO, NO, NO, \ + NO, SPC, NO, RALT,RGUI,FN0, RCTL,NO, LEFT,DOWN,RGHT,NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO ), + + /* Keymap 1: Fn Layer + * ,----------------------------------------. ,------------------------------------------------. + * | || | | | | | | | | | | | | | | | | ||Fn2|Fn1|Fn3| + * |---------------||-----------------------| |-----------------------------------||-----------| + * | | | | || | | | | | | | | | | | | | | || | | | + * |---------------||-------------------------. `-----------------------------------||-----------| + * | | | | || | | | | | | | | | | | | | | || | | | + * |-----------| ||--------------------------. `---------------------------------||-----------| + * | | | | || | | | | | | | | | | | | | || | + * |---------------||----------------------------. `-------------------------------|| ,---. | + * | | | | || | | | | | | | | | | | | || | | | + * |-----------| ||----------------------------| |------------------------------||-----------| + * | | | || | | | | | | | | | || | | | + * `---------------------------------------------' `-------------------------------------------' + */ + KEYMAP_16x16( + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + + NO, NO, NO, NO, NO, NO, NO, NO, FN2, FN1, FN3, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ + NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO ), + +}; + +/* + * Fn action definition + */ +#ifdef KEYMAP_SECTION_ENABLE +const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn_actions"))) = { +#else +const uint16_t fn_actions[] PROGMEM = { +#endif + /* Poker2 Layout */ + [0] = ACTION_LAYER_MOMENTARY(1), + [1] = ACTION_BACKLIGHT_TOGGLE(), + [2] = ACTION_BACKLIGHT_DECREASE(), + [3] = ACTION_BACKLIGHT_INCREASE(), +}; + +#ifdef KEYMAP_IN_EEPROM_ENABLE +uint16_t keys_count(void) { + return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_SIZE; +} + +uint16_t fn_actions_count(void) { + return sizeof(fn_actions) / sizeof(fn_actions[0]); +} +#endif diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index d4987ade..4f33ea78 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -33,26 +33,45 @@ along with this program. If not, see . extern uint8_t i2c_force_stop; uint8_t row_mapping[PX_COUNT] = { +#ifndef TWO_HEADED_KIMERA 0, 1, 2, 3, 4, 5, 6, 7, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED +#else + 0, 1, 2, 3, 4, 5, 6, 7, + 32, 33, 34, 35, 36, 37, 38, 39, + UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, + UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED +#endif }; uint8_t col_mapping[PX_COUNT] = { +#ifndef TWO_HEADED_KIMERA 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED +#else + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55 +#endif }; +#ifndef TWO_HEADED_KIMERA uint8_t row_count = 8; uint8_t col_count = 24; +#else +uint8_t row_count = 16; +uint8_t col_count = 32; +#endif uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; uint8_t exp_status = 0; void kimera_init(void) { /* read config */ - write_matrix_mapping(); /* debug */ + //write_matrix_mapping(); /* debug */ if (read_matrix_mapping()) { write_matrix_mapping(); } diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index f6519fd7..f46ea5bf 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -84,7 +84,11 @@ along with this program. If not, see . `----------' `----------' */ +#ifndef TWO_HEADED_KIMERA #define EXP_COUNT 2 +#else +#define EXP_COUNT 4 +#endif #define EXP_ADDR(n) ((0x20+(n))<<1) #define EXP_OUTPUT 0 #define EXP_INPUT 1 diff --git a/keyboard/kimera/matrix.c b/keyboard/kimera/matrix.c index b803c5f4..b7a3e49a 100644 --- a/keyboard/kimera/matrix.c +++ b/keyboard/kimera/matrix.c @@ -27,6 +27,7 @@ along with this program. If not, see . #include "util.h" #include "matrix.h" #include "kimera.h" +#include "keymap_in_eeprom.h" #ifndef DEBOUNCE @@ -51,7 +52,11 @@ uint8_t matrix_rows(void) inline uint8_t matrix_cols(void) { +#ifndef TWO_HEADED_KIMERA return col_count; +#else + return col_count / 2; +#endif } void matrix_init(void) @@ -82,7 +87,17 @@ 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. +#ifndef TWO_HEADED_KIMERA matrix_row_t cols = read_cols(); +#else + matrix_row_t cols = read_cols(); + if (i < 8) { + cols &= 0xFFFFUL; + } + else { + cols >>= 16; + } +#endif if (matrix_debouncing[i] != cols) { matrix_debouncing[i] = cols; if (debouncing) { From f9e449f7cffd4862307b865f3d93634fe4e8e301 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 11 Nov 2014 16:16:53 +0900 Subject: [PATCH 16/29] kimera: Fix the error handling of reading matrix mapping --- keyboard/kimera/kimera.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 4f33ea78..b852c272 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -78,7 +78,7 @@ void kimera_init(void) /* init i2c */ i2c_init(); - + /* init i/o expanders */ kimera_scan(); @@ -99,13 +99,16 @@ uint8_t read_matrix_mapping(void) uint8_t error = 0; /* read number of rows and cols */ - row_count = eeprom_read_byte(EECONFIG_ROW_COUNT); - col_count = eeprom_read_byte(EECONFIG_COL_COUNT); - if (row_count == 0) error++; - if (row_count == UNCONFIGURED) error++; - if (col_count == 0) error++; - if (col_count == UNCONFIGURED) error++; - if (row_count + col_count > PX_COUNT) error++; + uint8_t rows = eeprom_read_byte(EECONFIG_ROW_COUNT); + uint8_t cols = eeprom_read_byte(EECONFIG_COL_COUNT); + if (rows == 0) error++; + if (rows == UNCONFIGURED) error++; + if (cols == 0) error++; + if (cols == UNCONFIGURED) error++; + if (rows + cols > PX_COUNT) error++; + if (error) return error; + row_count = rows; + col_count = cols; /* read row mapping */ uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; @@ -224,8 +227,8 @@ void expander_init(uint8_t exp) /* write inversion register */ /* for (uint8_t exp = 0; exp < EXP_COUNT; exp++) { - expander_write_inversion(exp, data[exp]); - } + expander_write_inversion(exp, data[exp]); + } */ /* set output bit */ From de3e1c3538d0f9a6db2f66a6786a6991966d6878 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 11 Nov 2014 16:21:13 +0900 Subject: [PATCH 17/29] kimera: Fix a serious bug that init of i/o expander freeze sometimes --- keyboard/kimera/kimera.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index b852c272..e738fc98 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -79,11 +79,11 @@ void kimera_init(void) /* init i2c */ i2c_init(); - /* init i/o expanders */ - kimera_scan(); - /* init watch dog */ wdt_init(); + + /* init i/o expanders */ + kimera_scan(); } void wdt_init(void) From 030658e5f420fdc793d73c0b7d65043ef69a11f3 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 11 Nov 2014 16:42:09 +0900 Subject: [PATCH 18/29] kimera: Update features for Kimera v5 + USB 6KRO + SoftPWM LED + Breathing LED + Fading LED + Typing LED + Ledmap + Ledmap in EEPROM --- keyboard/kimera/Makefile | 7 +++ keyboard/kimera/Makefile.pjrc | 9 ++- keyboard/kimera/Makefile_8M | 8 ++- keyboard/kimera/backlight.c | 104 ++++++++++++++++++++++++++++++++++ keyboard/kimera/config.h | 14 ++++- keyboard/kimera/kimera.h | 6 +- keyboard/kimera/led.c | 10 +++- keyboard/kimera/ledmap.c | 84 +++++++++++++++++++++++++++ 8 files changed, 232 insertions(+), 10 deletions(-) create mode 100644 keyboard/kimera/ledmap.c diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index e6ecf532..238e2455 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -52,6 +52,7 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ + ledmap.c \ twimaster.c \ kimera.c @@ -136,12 +137,18 @@ 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 +USB_6KRO_ENABLE = yes # USB 6key Rollover #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support #PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight +FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight +LEDMAP_ENABLE = yes # Enable LED mapping +LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom + # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/keyboard/kimera/Makefile.pjrc b/keyboard/kimera/Makefile.pjrc index 140e64c4..5818baca 100644 --- a/keyboard/kimera/Makefile.pjrc +++ b/keyboard/kimera/Makefile.pjrc @@ -52,6 +52,7 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ + ledmap.c \ twimaster.c \ kimera.c @@ -99,13 +100,17 @@ 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 +USB_6KRO_ENABLE = yes # USB 6key Rollover #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support #PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom -KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight +FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight - +LEDMAP_ENABLE = yes # Enable LED mapping +LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom # Search Path diff --git a/keyboard/kimera/Makefile_8M b/keyboard/kimera/Makefile_8M index bced6dee..fe60c6cc 100644 --- a/keyboard/kimera/Makefile_8M +++ b/keyboard/kimera/Makefile_8M @@ -52,6 +52,7 @@ SRC = keymap_common.c \ matrix.c \ led.c \ backlight.c \ + ledmap.c \ twimaster.c \ kimera.c @@ -130,12 +131,17 @@ 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 +USB_6KRO_ENABLE = yes # USB 6key Rollover #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support #PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom -KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight +FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight +LEDMAP_ENABLE = yes # Enable LED mapping +LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/keyboard/kimera/backlight.c b/keyboard/kimera/backlight.c index a0a6f473..1603d5d2 100644 --- a/keyboard/kimera/backlight.c +++ b/keyboard/kimera/backlight.c @@ -19,7 +19,12 @@ along with this program. If not, see . #include #include #include "backlight.h" +#ifdef SOFTPWM_LED_ENABLE +#include "softpwm_led.h" +#else #include "breathing_led.h" +#endif +#include "action.h" #include "kimera.h" #ifdef BACKLIGHT_ENABLE @@ -32,9 +37,16 @@ static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; +#ifdef SOFTPWM_LED_ENABLE +#ifdef FADING_LED_ENABLE +static uint8_t backlight_mode; +#endif +#endif + /* Backlight pin configuration * LED4: PB6 (D10) OC1B */ +#ifndef SOFTPWM_LED_ENABLE void backlight_enable(void) { // Turn on PWM @@ -44,7 +56,9 @@ void backlight_enable(void) TCCR1B |= ((1<. #define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 -#define EECONFIG_KEYMAP_IN_EEPROM 41 +#define EECONFIG_KEYMAP_IN_EEPROM 45 /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST @@ -45,11 +45,21 @@ along with this program. If not, see . /* number of backlight levels */ #ifdef BREATHING_LED_ENABLE +#ifdef FADING_LED_ENABLE +#define BACKLIGHT_LEVELS 8 +#else #define BACKLIGHT_LEVELS 6 +#endif #else #define BACKLIGHT_LEVELS 3 #endif +/* enable customized backlight logic */ +#define BACKLIGHT_CUSTOM + +/* number of leds */ +#define LED_COUNT 4 + /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ #define LOCKING_SUPPORT_ENABLE @@ -79,4 +89,6 @@ along with this program. If not, see . //#define NO_ACTION_MACRO //#define NO_ACTION_FUNCTION +#define NO_SUSPEND_POWER_DOWN + #endif diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index f46ea5bf..5ece9f84 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -116,9 +116,9 @@ const uint16_t PROGMEM dummy[] = { /* Matrix Mapping in EEPROM */ -#define EECONFIG_ROW_COUNT (uint8_t *)7 -#define EECONFIG_COL_COUNT (uint8_t *)8 -#define EECONFIG_ROW_COL_MAPPING (uint8_t *)9 +#define EECONFIG_ROW_COUNT (uint8_t *)11 +#define EECONFIG_COL_COUNT (uint8_t *)12 +#define EECONFIG_ROW_COL_MAPPING (uint8_t *)13 #define UNCONFIGURED 0xFF /* Functions */ diff --git a/keyboard/kimera/led.c b/keyboard/kimera/led.c index 009640d3..1b6f6a0b 100644 --- a/keyboard/kimera/led.c +++ b/keyboard/kimera/led.c @@ -20,9 +20,11 @@ along with this program. If not, see . #include "led.h" #include "kimera.h" +#ifndef LEDMAP_ENABLE + void led_set(uint8_t usb_led) { - if (usb_led & (1< + +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 . +*/ + +#include +#include "ledmap.h" +#include "kimera.h" + +#ifdef LEDMAP_ENABLE + +static const uint8_t ledmaps[LED_COUNT] PROGMEM = { + [0] = LEDMAP_NUM_LOCK, // LED1 + [1] = LEDMAP_CAPS_LOCK, // LED2 + [2] = LEDMAP_SCROLL_LOCK, // LED3 + [3] = LEDMAP_NO | LEDMAP_BACKLIGHT, // LED4 +}; + +uint8_t ledmap_get_code(uint8_t index) +{ + return pgm_read_byte(&ledmaps[index]); +} + +void ledmap_led_init(void) +{ + LED1_DDR |= (1< Date: Wed, 12 Nov 2014 14:33:21 +0900 Subject: [PATCH 19/29] kimera: Reduce memory usage - Disable Fading LED by default - Remove layer1 and fns --- keyboard/kimera/Makefile | 2 +- keyboard/kimera/Makefile.pjrc | 2 +- keyboard/kimera/Makefile_8M | 2 +- keyboard/kimera/keymap_default.c | 27 ------------------- keyboard/kimera/keymap_two_headed.c | 40 ----------------------------- 5 files changed, 3 insertions(+), 70 deletions(-) diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index 238e2455..468dc314 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -144,7 +144,7 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight -FADING_LED_ENABLE = yes # Enable fading backlight +#FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight LEDMAP_ENABLE = yes # Enable LED mapping LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom diff --git a/keyboard/kimera/Makefile.pjrc b/keyboard/kimera/Makefile.pjrc index 5818baca..9c49208f 100644 --- a/keyboard/kimera/Makefile.pjrc +++ b/keyboard/kimera/Makefile.pjrc @@ -107,7 +107,7 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight -FADING_LED_ENABLE = yes # Enable fading backlight +#FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight LEDMAP_ENABLE = yes # Enable LED mapping LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom diff --git a/keyboard/kimera/Makefile_8M b/keyboard/kimera/Makefile_8M index fe60c6cc..a40a3100 100644 --- a/keyboard/kimera/Makefile_8M +++ b/keyboard/kimera/Makefile_8M @@ -138,7 +138,7 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight -FADING_LED_ENABLE = yes # Enable fading backlight +#FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight LEDMAP_ENABLE = yes # Enable LED mapping LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom diff --git a/keyboard/kimera/keymap_default.c b/keyboard/kimera/keymap_default.c index 0764aa54..4045ef45 100644 --- a/keyboard/kimera/keymap_default.c +++ b/keyboard/kimera/keymap_default.c @@ -28,28 +28,6 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = { CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, P4, P5, P6, \ LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, UP, P1, P2, P3, PENT, \ LCTL,LGUI,LALT, SPC, RALT,RGUI,FN0, RCTL, LEFT,DOWN,RGHT, P0, PDOT ), - /* Keymap 1: Fn Layer - * ,---------------------------------------------------------------------------------------. - * | | | | | | | | | | | | | | | | | | | | - * |---------------------------------------------------------------------------------------| - * | | | | | | | | | | | | | | | | | | | | | | - * |---------------------------------------------------------------------------------------| - * | |Fn1|Fn2|Fn3| | | | | | | | | | | | | | | | | | - * |-----------------------------------------------------------------------------------| | - * | | | | | | | | | | | | | | | | | | | - * |-----------------------------------------------------------| ,---. |---------------- - * | | | | | | | | | | | | | | | | | | | | - * |-----------------------------------------------------------------------------------| | - * | | | | | | | | | | | | | | | | - * `---------------------------------------------------------------------------------------' - */ - KEYMAP_ANSI_104( - TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, \ - TRNS,FN1, FN2, FN3, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, NLCK,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, \ - TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS, TRNS,TRNS,TRNS, TRNS, TRNS ), }; /* @@ -60,11 +38,6 @@ const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn #else const uint16_t fn_actions[] PROGMEM = { #endif - /* Poker2 Layout */ - [0] = ACTION_LAYER_MOMENTARY(1), - [1] = ACTION_BACKLIGHT_TOGGLE(), - [2] = ACTION_BACKLIGHT_DECREASE(), - [3] = ACTION_BACKLIGHT_INCREASE(), }; #ifdef KEYMAP_IN_EEPROM_ENABLE diff --git a/keyboard/kimera/keymap_two_headed.c b/keyboard/kimera/keymap_two_headed.c index df48664d..f1f55d19 100644 --- a/keyboard/kimera/keymap_two_headed.c +++ b/keyboard/kimera/keymap_two_headed.c @@ -39,41 +39,6 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = { NO, SPC, NO, RALT,RGUI,FN0, RCTL,NO, LEFT,DOWN,RGHT,NO, NO, NO, NO, NO, \ NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO ), - - /* Keymap 1: Fn Layer - * ,----------------------------------------. ,------------------------------------------------. - * | || | | | | | | | | | | | | | | | | ||Fn2|Fn1|Fn3| - * |---------------||-----------------------| |-----------------------------------||-----------| - * | | | | || | | | | | | | | | | | | | | || | | | - * |---------------||-------------------------. `-----------------------------------||-----------| - * | | | | || | | | | | | | | | | | | | | || | | | - * |-----------| ||--------------------------. `---------------------------------||-----------| - * | | | | || | | | | | | | | | | | | | || | - * |---------------||----------------------------. `-------------------------------|| ,---. | - * | | | | || | | | | | | | | | | | | || | | | - * |-----------| ||----------------------------| |------------------------------||-----------| - * | | | || | | | | | | | | | || | | | - * `---------------------------------------------' `-------------------------------------------' - */ - KEYMAP_16x16( - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - - NO, NO, NO, NO, NO, NO, NO, NO, FN2, FN1, FN3, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ - NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO ), - }; /* @@ -84,11 +49,6 @@ const uint16_t fn_actions[FN_ACTIONS_COUNT] __attribute__ ((section (".keymap.fn #else const uint16_t fn_actions[] PROGMEM = { #endif - /* Poker2 Layout */ - [0] = ACTION_LAYER_MOMENTARY(1), - [1] = ACTION_BACKLIGHT_TOGGLE(), - [2] = ACTION_BACKLIGHT_DECREASE(), - [3] = ACTION_BACKLIGHT_INCREASE(), }; #ifdef KEYMAP_IN_EEPROM_ENABLE From 7a1eeebaa7b7ffe8a13d5b40a3fd1b87ba741d35 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 13 Nov 2014 19:28:03 +0900 Subject: [PATCH 20/29] kimera: Make two-handed kimera can work with keymap-in-eeprom --- keyboard/kimera/config.h | 4 +++ keyboard/kimera/keymap_two_headed.c | 6 ++-- keyboard/kimera/kimera.c | 56 +++++++++++++++++++++++------ keyboard/kimera/kimera.h | 8 +++-- keyboard/kimera/matrix.c | 30 ++++------------ 5 files changed, 63 insertions(+), 41 deletions(-) diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index 14542ee2..38ceef65 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -35,7 +35,11 @@ along with this program. If not, see . #define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 +#ifndef TWO_HEADED_KIMERA #define EECONFIG_KEYMAP_IN_EEPROM 45 +#else +#define EECONFIG_KEYMAP_IN_EEPROM 77 +#endif /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST diff --git a/keyboard/kimera/keymap_two_headed.c b/keyboard/kimera/keymap_two_headed.c index f1f55d19..6f09142d 100644 --- a/keyboard/kimera/keymap_two_headed.c +++ b/keyboard/kimera/keymap_two_headed.c @@ -8,7 +8,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = { #endif /* Keymap 0: Default Layer * ,----------------------------------------. ,------------------------------------------------. - * | ||Esc| | F1| F2| F3| F4| | | F5| F6| F7| F8| | F9|F10|F11|F12||Psc|Slk|Pus| + * | | | | ||Esc| | F1| F2| F3| F4| | | F5| F6| F7| F8| | F9|F10|F11|F12||Psc|Slk|Pus| * |---------------||-----------------------| |-----------------------------------||-----------| * |Num| /| *| -|| `| 1| 2| 3| 4| 5| | 6| 7| 8| 9| 0| -| =|Backsp ||Ins|Hom|PgU| * |---------------||-------------------------. `-----------------------------------||-----------| @@ -18,7 +18,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = { * |---------------||----------------------------. `-------------------------------|| ,---. | * | 1| 2| 3| ||Shift | Z| X| C| V| B| | N| M| ,| .| /|Shift || |Up | | * |-----------|Ent||----------------------------| |------------------------------||-----------| - * | 0| .| ||Ctrl|Gui |Alt | Space | | Space |Alt |Gui |Fn0 |Ctrl||Lef|Dow|Rig| + * | 0| .| ||Ctrl|Gui |Alt | Space | | Space |Alt |Gui |App |Ctrl||Lef|Dow|Rig| * `---------------------------------------------' `-------------------------------------------' */ KEYMAP_16x16( @@ -36,7 +36,7 @@ const uint8_t keymaps[][MATRIX_SIZE] PROGMEM = { Y, U, I, O, P, LBRC,RBRC,BSLS,DEL, END, PGDN,NO, NO, NO, NO, NO, \ H, J, K, L, SCLN,QUOT,NO, ENT, NO, NO, NO, NO, NO, NO, NO, NO, \ N, M, COMM,DOT, SLSH,NO, NO, RSFT,NO, UP, NO, NO, NO, NO, NO, NO, \ - NO, SPC, NO, RALT,RGUI,FN0, RCTL,NO, LEFT,DOWN,RGHT,NO, NO, NO, NO, NO, \ + NO, SPC, NO, RALT,RGUI,APP, RCTL,NO, LEFT,DOWN,RGHT,NO, NO, NO, NO, NO, \ NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, \ NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO, NO ), }; diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index e738fc98..e75ea8ac 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -32,7 +32,7 @@ along with this program. If not, see . #define SCL_DURATION (1000000L/SCL_CLOCK)/2 extern uint8_t i2c_force_stop; -uint8_t row_mapping[PX_COUNT] = { +static uint8_t row_mapping[PX_COUNT] = { #ifndef TWO_HEADED_KIMERA 0, 1, 2, 3, 4, 5, 6, 7, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, @@ -45,7 +45,7 @@ uint8_t row_mapping[PX_COUNT] = { UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED #endif }; -uint8_t col_mapping[PX_COUNT] = { +static uint8_t col_mapping[PX_COUNT] = { #ifndef TWO_HEADED_KIMERA 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, @@ -59,14 +59,17 @@ uint8_t col_mapping[PX_COUNT] = { #endif }; #ifndef TWO_HEADED_KIMERA -uint8_t row_count = 8; -uint8_t col_count = 24; +static uint8_t row_count = 8; +static uint8_t col_count = 24; #else -uint8_t row_count = 16; -uint8_t col_count = 32; +static uint8_t row_count = 16; +static uint8_t col_count = 32; +static uint8_t row_left_count = 8; +static uint8_t col_left_count = 16; +static matrix_row_t col_left_mask; #endif -uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; -uint8_t exp_status = 0; +static uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; +static uint8_t exp_status = 0; void kimera_init(void) { @@ -109,6 +112,11 @@ uint8_t read_matrix_mapping(void) if (error) return error; row_count = rows; col_count = cols; +#ifdef TWO_HEADED_KIMERA + row_left_count = (rows + 1) / 2; + col_left_count = (cols + 1) / 2; + col_left_mask = (1 << row_left_count) - 1; +#endif /* read row mapping */ uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; @@ -177,7 +185,23 @@ void kimera_scan(void) } } -matrix_row_t read_cols(void) +inline +uint8_t kimera_matrix_rows(void) +{ + return row_count; +} + +inline +uint8_t kimera_matrix_cols(void) +{ +#ifndef TWO_HEADED_KIMERA + return col_count; +#else + return col_left_count; +#endif +} + +matrix_row_t kimera_read_cols(uint8_t row) { init_data(0xFF); @@ -196,10 +220,20 @@ matrix_row_t read_cols(void) } } } + +#ifdef TWO_HEADED_KIMERA + if (row < row_left_count) { + cols &= col_left_mask; + } + else { + cols >>= col_left_count; + } +#endif + return cols; } -void unselect_rows(void) +void kimera_unselect_rows(void) { /* set all output registers to 0xFF */ init_data(0xFF); @@ -208,7 +242,7 @@ void unselect_rows(void) } } -void select_row(uint8_t row) +void kimera_select_row(uint8_t row) { /* set selected row to low */ init_data(0xFF); diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 5ece9f84..d4e1943a 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -128,9 +128,11 @@ void wdt_init(void); uint8_t read_matrix_mapping(void); void write_matrix_mapping(void); void kimera_scan(void); -matrix_row_t read_cols(void); -void unselect_rows(void); -void select_row(uint8_t row); +uint8_t kimera_matrix_rows(void); +uint8_t kimera_matrix_cols(void); +matrix_row_t kimera_read_cols(uint8_t row); +void kimera_unselect_rows(void); +void kimera_select_row(uint8_t row); void expander_init(uint8_t exp); uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data); uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data); diff --git a/keyboard/kimera/matrix.c b/keyboard/kimera/matrix.c index b7a3e49a..677c4d81 100644 --- a/keyboard/kimera/matrix.c +++ b/keyboard/kimera/matrix.c @@ -39,24 +39,16 @@ static uint8_t debouncing = DEBOUNCE; static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS]; -extern uint8_t row_count; -extern uint8_t col_count; -extern uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; - inline uint8_t matrix_rows(void) { - return row_count; + return kimera_matrix_rows(); } inline uint8_t matrix_cols(void) { -#ifndef TWO_HEADED_KIMERA - return col_count; -#else - return col_count / 2; -#endif + return kimera_matrix_cols(); } void matrix_init(void) @@ -68,7 +60,7 @@ void matrix_init(void) kimera_init(); // initialize row and col - unselect_rows(); + kimera_unselect_rows(); // initialize matrix state: all keys off for (uint8_t i=0; i < matrix_rows(); i++) { @@ -85,19 +77,9 @@ uint8_t matrix_scan(void) kimera_scan(); for (uint8_t i = 0; i < matrix_rows(); i++) { - select_row(i); + kimera_select_row(i); _delay_us(30); // without this wait read unstable value. -#ifndef TWO_HEADED_KIMERA - matrix_row_t cols = read_cols(); -#else - matrix_row_t cols = read_cols(); - if (i < 8) { - cols &= 0xFFFFUL; - } - else { - cols >>= 16; - } -#endif + matrix_row_t cols = kimera_read_cols(i); if (matrix_debouncing[i] != cols) { matrix_debouncing[i] = cols; if (debouncing) { @@ -105,7 +87,7 @@ uint8_t matrix_scan(void) } debouncing = DEBOUNCE; } - unselect_rows(); + kimera_unselect_rows(); } if (debouncing) { From 827eec13d2fa26db8eaba866824d99491a8878a1 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 13 Nov 2014 19:40:21 +0900 Subject: [PATCH 21/29] kimera: Print whole matrix when debugging --- keyboard/kimera/matrix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keyboard/kimera/matrix.c b/keyboard/kimera/matrix.c index 677c4d81..7754f239 100644 --- a/keyboard/kimera/matrix.c +++ b/keyboard/kimera/matrix.c @@ -123,10 +123,10 @@ matrix_row_t matrix_get_row(uint8_t row) void matrix_print(void) { - print("\nr/c 0123456789ABCDEF\n"); + print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n"); for (uint8_t row = 0; row < matrix_rows(); row++) { phex(row); print(": "); - pbin_reverse16(matrix_get_row(row)); + pbin_reverse32(matrix_get_row(row)); print("\n"); } } @@ -135,7 +135,7 @@ uint8_t matrix_key_count(void) { uint8_t count = 0; for (uint8_t i = 0; i < matrix_rows(); i++) { - count += bitpop16(matrix[i]); + count += bitpop32(matrix[i]); } return count; } From 422cfac490c9aa88c2a0c48bdee15462866df07b Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 28 Nov 2014 14:49:25 +0900 Subject: [PATCH 22/29] kimera: Change code to fit master branch --- keyboard/kimera/Makefile | 11 +++++------ keyboard/kimera/backlight.c | 4 ++-- keyboard/kimera/config.h | 6 +++--- keyboard/kimera/keymap_common.c | 2 +- keyboard/kimera/kimera.c | 17 ++++++++++++++++- keyboard/kimera/kimera.h | 6 +++--- keyboard/kimera/ledmap.c | 8 ++++---- keyboard/kimera/matrix.c | 2 +- 8 files changed, 35 insertions(+), 21 deletions(-) diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index 468dc314..b2a308fe 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -42,7 +42,7 @@ TARGET = kimera_lufa # Directory common source filess exist -TOP_DIR = ../.. +TMK_DIR = ../../tmk_core_custom # Directory keyboard dependent files exist TARGET_DIR = . @@ -155,9 +155,8 @@ LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom # Search Path VPATH += $(TARGET_DIR) -VPATH += $(TOP_DIR) +VPATH += $(TMK_DIR) -include $(TOP_DIR)/protocol/lufa.mk -include $(TOP_DIR)/protocol.mk -include $(TOP_DIR)/common.mk -include $(TOP_DIR)/rules.mk +include $(TMK_DIR)/protocol/lufa.mk +include $(TMK_DIR)/common.mk +include $(TMK_DIR)/rules.mk diff --git a/keyboard/kimera/backlight.c b/keyboard/kimera/backlight.c index 1603d5d2..6cc3f0b6 100644 --- a/keyboard/kimera/backlight.c +++ b/keyboard/kimera/backlight.c @@ -115,14 +115,14 @@ void backlight_set(uint8_t level) softpwm_led_enable(); fading_led_enable_all(); breathing_led_disable_all(); - fading_led_set_direction(FADING_LED_FADE_IN); + fading_led_set_direction_all(FADING_LED_FADE_IN); fading_led_set_duration(3); break; case 8: softpwm_led_enable(); fading_led_enable_all(); breathing_led_disable_all(); - fading_led_set_direction(FADING_LED_FADE_OUT); + fading_led_set_direction_all(FADING_LED_FADE_OUT); fading_led_set_duration(3); break; #endif diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index 38ceef65..b08002e7 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -36,9 +36,9 @@ along with this program. If not, see . #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 #ifndef TWO_HEADED_KIMERA -#define EECONFIG_KEYMAP_IN_EEPROM 45 +#define EECONFIG_KEYMAP_IN_EEPROM 49 #else -#define EECONFIG_KEYMAP_IN_EEPROM 77 +#define EECONFIG_KEYMAP_IN_EEPROM 81 #endif /* define if matrix has ghost */ @@ -90,7 +90,7 @@ along with this program. If not, see . //#define NO_ACTION_LAYER //#define NO_ACTION_TAPPING //#define NO_ACTION_ONESHOT -//#define NO_ACTION_MACRO +#define NO_ACTION_MACRO //#define NO_ACTION_FUNCTION #define NO_SUSPEND_POWER_DOWN diff --git a/keyboard/kimera/keymap_common.c b/keyboard/kimera/keymap_common.c index f51dfdbe..cab3f88d 100644 --- a/keyboard/kimera/keymap_common.c +++ b/keyboard/kimera/keymap_common.c @@ -18,7 +18,7 @@ along with this program. If not, see . #include "matrix.h" /* translates key to keycode */ -uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) +uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { #ifndef KEYMAP_IN_EEPROM_ENABLE return pgm_read_byte(&keymaps[(layer)][(key.row) * matrix_cols() + (key.col)]); diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index e75ea8ac..c4c42f8d 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -23,11 +23,26 @@ along with this program. If not, see . #include #include #include "action.h" -#include "suspend.h" #include "i2cmaster.h" #include "kimera.h" #include "debug.h" +#define wdt_intr_enable(value) \ +__asm__ __volatile__ ( \ + "in __tmp_reg__,__SREG__" "\n\t" \ + "cli" "\n\t" \ + "wdr" "\n\t" \ + "sts %0,%1" "\n\t" \ + "out __SREG__,__tmp_reg__" "\n\t" \ + "sts %0,%2" "\n\t" \ + : /* no outputs */ \ + : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ + "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ + _BV(WDIE) | (value & 0x07)) ) \ + : "r0" \ +) + #define SCL_CLOCK 400000L #define SCL_DURATION (1000000L/SCL_CLOCK)/2 extern uint8_t i2c_force_stop; diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index d4e1943a..3f5ff9f9 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -116,9 +116,9 @@ const uint16_t PROGMEM dummy[] = { /* Matrix Mapping in EEPROM */ -#define EECONFIG_ROW_COUNT (uint8_t *)11 -#define EECONFIG_COL_COUNT (uint8_t *)12 -#define EECONFIG_ROW_COL_MAPPING (uint8_t *)13 +#define EECONFIG_ROW_COUNT (uint8_t *)15 +#define EECONFIG_COL_COUNT (uint8_t *)16 +#define EECONFIG_ROW_COL_MAPPING (uint8_t *)17 #define UNCONFIGURED 0xFF /* Functions */ diff --git a/keyboard/kimera/ledmap.c b/keyboard/kimera/ledmap.c index 6c173e9d..a2794068 100644 --- a/keyboard/kimera/ledmap.c +++ b/keyboard/kimera/ledmap.c @@ -21,16 +21,16 @@ along with this program. If not, see . #ifdef LEDMAP_ENABLE -static const uint8_t ledmaps[LED_COUNT] PROGMEM = { +static const uint16_t ledmaps[LED_COUNT] PROGMEM = { [0] = LEDMAP_NUM_LOCK, // LED1 [1] = LEDMAP_CAPS_LOCK, // LED2 [2] = LEDMAP_SCROLL_LOCK, // LED3 - [3] = LEDMAP_NO | LEDMAP_BACKLIGHT, // LED4 + [3] = LEDMAP_BACKLIGHT, // LED4 }; -uint8_t ledmap_get_code(uint8_t index) +ledmap_t ledmap_get_code(uint8_t index) { - return pgm_read_byte(&ledmaps[index]); + return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) }; } void ledmap_led_init(void) diff --git a/keyboard/kimera/matrix.c b/keyboard/kimera/matrix.c index 7754f239..bc7b9387 100644 --- a/keyboard/kimera/matrix.c +++ b/keyboard/kimera/matrix.c @@ -126,7 +126,7 @@ void matrix_print(void) print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n"); for (uint8_t row = 0; row < matrix_rows(); row++) { phex(row); print(": "); - pbin_reverse32(matrix_get_row(row)); + print_bin_reverse32(matrix_get_row(row)); print("\n"); } } From 24614640e3d6aef6a214bf28e9bbbfde52334af5 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 21 Sep 2015 00:10:57 +0900 Subject: [PATCH 23/29] kimera: Add support for Kimera Core --- keyboard/kimera/Makefile | 6 +++--- keyboard/kimera/kimera.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index b2a308fe..bc6f5613 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -119,7 +119,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096 ifdef VER OPT_DEFS += -DKIMERA_$(REV) else - OPT_DEFS += -DKIMERA_V5 + OPT_DEFS += -DKIMERA_CORE endif # Additional definitions from command line @@ -131,7 +131,7 @@ endif # comment out to disable the options. # BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) -MOUSEKEY_ENABLE = yes # Mouse keys(+4700) +#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 @@ -144,7 +144,7 @@ BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality KEYMAP_IN_EEPROM_ENABLE = yes # External keymap in eeprom #KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight -#FADING_LED_ENABLE = yes # Enable fading backlight +FADING_LED_ENABLE = yes # Enable fading backlight BREATHING_LED_ENABLE = yes # Enable breathing backlight LEDMAP_ENABLE = yes # Enable LED mapping LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 3f5ff9f9..387b5157 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -40,6 +40,8 @@ along with this program. If not, see . `----------------' */ +#ifndef KIMERA_CORE + #define LED1_PORT PORTB #define LED1_PIN PINB #define LED1_DDR DDRB @@ -61,6 +63,31 @@ along with this program. If not, see . #define LED4_BIT PB6 #define LED4_OCR OCR1B +#else + +#define LED1_PORT PORTB +#define LED1_PIN PINB +#define LED1_DDR DDRB +#define LED1_BIT PB5 + +#define LED2_PORT PORTB +#define LED2_PIN PINB +#define LED2_DDR DDRB +#define LED2_BIT PB6 + +#define LED3_PORT PORTC +#define LED3_PIN PINC +#define LED3_DDR DDRC +#define LED3_BIT PC6 + +#define LED4_PORT PORTC +#define LED4_PIN PINC +#define LED4_DDR DDRC +#define LED4_BIT PC7 +#define LED4_OCR OCR4D + +#endif + /* IC1 (PCA9555) IC2 (PCA9555) ,----------. ,----------. @@ -104,8 +131,13 @@ enum { EXP_COMM_CONFIG_0, EXP_COMM_CONFIG_1 }; +#ifndef KIMERA_CORE #define PX_TO_EXP(x) (((x)>>5<<1)+((((x)>>3)&1)^(((x)>>4)&1))) #define PX_TO_PORT(x) (((x)>>4)&1) +#else +#define PX_TO_EXP(x) ((x)>>4) +#define PX_TO_PORT(x) (((x)>>3)&1) +#endif #define PX_TO_PIN(x) ((x)&7) #define PX_COUNT (EXP_PIN_PER_PORT * EXP_PORT_COUNT * EXP_COUNT) From 41741230b841780b2a4d74f54f400643ba682c6b Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 18 Jan 2016 11:59:50 +0900 Subject: [PATCH 24/29] kimera: Add a simple rgb led and ws2812 support --- keyboard/kimera/Makefile | 4 +- keyboard/kimera/backlight.c | 63 +++++--- keyboard/kimera/config.h | 6 +- keyboard/kimera/keymap_default.c | 30 ++++ keyboard/kimera/kimera.h | 6 +- keyboard/kimera/ledmap.c | 4 + keyboard/kimera/light_ws2812.c | 170 ++++++++++++++++++++++ keyboard/kimera/light_ws2812.h | 63 ++++++++ keyboard/kimera/rgb.c | 237 +++++++++++++++++++++++++++++++ keyboard/kimera/rgb.h | 60 ++++++++ keyboard/kimera/ws2812_config.h | 21 +++ 11 files changed, 637 insertions(+), 27 deletions(-) create mode 100644 keyboard/kimera/light_ws2812.c create mode 100644 keyboard/kimera/light_ws2812.h create mode 100644 keyboard/kimera/rgb.c create mode 100644 keyboard/kimera/rgb.h create mode 100644 keyboard/kimera/ws2812_config.h diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index bc6f5613..74264b49 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -54,7 +54,9 @@ SRC = keymap_common.c \ backlight.c \ ledmap.c \ twimaster.c \ - kimera.c + kimera.c \ + light_ws2812.c \ + rgb.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) diff --git a/keyboard/kimera/backlight.c b/keyboard/kimera/backlight.c index 6cc3f0b6..bef3be13 100644 --- a/keyboard/kimera/backlight.c +++ b/keyboard/kimera/backlight.c @@ -26,6 +26,7 @@ along with this program. If not, see . #endif #include "action.h" #include "kimera.h" +#include "rgb.h" #ifdef BACKLIGHT_ENABLE @@ -37,11 +38,8 @@ static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; -#ifdef SOFTPWM_LED_ENABLE -#ifdef FADING_LED_ENABLE -static uint8_t backlight_mode; -#endif -#endif +extern backlight_config_t backlight_config; +uint8_t backlight_brightness; /* Backlight pin configuration * LED4: PB6 (D10) OC1B @@ -73,17 +71,15 @@ void backlight_disable(void) void backlight_set(uint8_t level) { -#ifdef FADING_LED_ENABLE - backlight_mode = level; +#ifdef SOFTPWM_LED_ENABLE + softpwm_led_enable(); #endif - #ifdef BREATHING_LED_ENABLE switch (level) { case 1: case 2: case 3: #ifdef SOFTPWM_LED_ENABLE - softpwm_led_enable(); #ifdef FADING_LED_ENABLE fading_led_disable_all(); #endif @@ -92,13 +88,16 @@ void backlight_set(uint8_t level) backlight_enable(); breathing_led_disable(); #endif - backlight_set_raw(pgm_read_byte(&backlight_table[level])); + backlight_brightness = pgm_read_byte(&backlight_table[level]); +#ifdef RGB_LED_ENABLE + rgb_set_brightness(backlight_brightness); +#endif + backlight_set_raw(backlight_brightness); break; case 4: case 5: case 6: #ifdef SOFTPWM_LED_ENABLE - softpwm_led_enable(); #ifdef FADING_LED_ENABLE fading_led_disable_all(); #endif @@ -112,14 +111,12 @@ void backlight_set(uint8_t level) #ifdef SOFTPWM_LED_ENABLE #ifdef FADING_LED_ENABLE case 7: - softpwm_led_enable(); fading_led_enable_all(); breathing_led_disable_all(); fading_led_set_direction_all(FADING_LED_FADE_IN); fading_led_set_duration(3); break; case 8: - softpwm_led_enable(); fading_led_enable_all(); breathing_led_disable_all(); fading_led_set_direction_all(FADING_LED_FADE_OUT); @@ -134,7 +131,8 @@ void backlight_set(uint8_t level) fading_led_disable_all(); #endif breathing_led_disable_all(); - softpwm_led_disable(); + backlight_brightness = 0; + backlight_set_raw(backlight_brightness); #else breathing_led_disable(); backlight_disable(); @@ -193,18 +191,41 @@ void softpwm_led_off(uint8_t index) #ifdef FADING_LED_ENABLE void action_keyevent(keyevent_t event) { - if (backlight_mode == 7) { - if (event.pressed) { - softpwm_led_decrease_all(32); + if (backlight_config.enable) { + if (backlight_config.level == 7) { + if (event.pressed) { + fading_led_set_delay_all(64); + softpwm_led_decrease_all(32); + } } - } - if (backlight_mode == 8) { - if (event.pressed) { - softpwm_led_increase_all(32); + if (backlight_config.level == 8) { + if (event.pressed) { + fading_led_set_delay_all(64); + softpwm_led_increase_all(32); + } } } } #endif + +#ifdef RGB_LED_ENABLE +#ifdef CUSTOM_LED_ENABLE +void softpwm_led_custom(void) +{ + rgb_fading(); +} + +void fading_led_custom(uint8_t *value) +{ + rgb_set_brightness(value[0]); +} + +void breathing_led_custom(uint8_t *value) +{ + rgb_set_brightness(value[0]); +} +#endif +#endif #endif #endif diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index b08002e7..8fef70fb 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -36,9 +36,9 @@ along with this program. If not, see . #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 #ifndef TWO_HEADED_KIMERA -#define EECONFIG_KEYMAP_IN_EEPROM 49 +#define EECONFIG_KEYMAP_IN_EEPROM 50 #else -#define EECONFIG_KEYMAP_IN_EEPROM 81 +#define EECONFIG_KEYMAP_IN_EEPROM 82 #endif /* define if matrix has ghost */ @@ -60,6 +60,8 @@ along with this program. If not, see . /* enable customized backlight logic */ #define BACKLIGHT_CUSTOM +#define CUSTOM_LED_ENABLE +#define RGB_LED_ENABLE /* number of leds */ #define LED_COUNT 4 diff --git a/keyboard/kimera/keymap_default.c b/keyboard/kimera/keymap_default.c index 4045ef45..7e750b4f 100644 --- a/keyboard/kimera/keymap_default.c +++ b/keyboard/kimera/keymap_default.c @@ -1,4 +1,5 @@ #include "keymap_common.h" +#include "rgb.h" // Default #ifdef KEYMAP_SECTION_ENABLE @@ -49,3 +50,32 @@ uint16_t fn_actions_count(void) { return sizeof(fn_actions) / sizeof(fn_actions[0]); } #endif + +#ifndef NO_ACTION_FUNCTION +enum function_id { + AF_RGB_TOGGLE = 0, + AF_RGB_DECREASE, + AF_RGB_INCREASE, + AF_RGB_STEP +}; + +void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) +{ + if (record->event.pressed) { + switch (id) { + case AF_RGB_TOGGLE: + rgb_toggle(); + break; + case AF_RGB_DECREASE: + rgb_decrease(); + break; + case AF_RGB_INCREASE: + rgb_increase(); + break; + case AF_RGB_STEP: + rgb_step(); + break; + } + } +} +#endif diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 387b5157..24d3c132 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -148,9 +148,9 @@ const uint16_t PROGMEM dummy[] = { /* Matrix Mapping in EEPROM */ -#define EECONFIG_ROW_COUNT (uint8_t *)15 -#define EECONFIG_COL_COUNT (uint8_t *)16 -#define EECONFIG_ROW_COL_MAPPING (uint8_t *)17 +#define EECONFIG_ROW_COUNT (uint8_t *)16 +#define EECONFIG_COL_COUNT (uint8_t *)17 +#define EECONFIG_ROW_COL_MAPPING (uint8_t *)18 #define UNCONFIGURED 0xFF /* Functions */ diff --git a/keyboard/kimera/ledmap.c b/keyboard/kimera/ledmap.c index a2794068..753b3dc2 100644 --- a/keyboard/kimera/ledmap.c +++ b/keyboard/kimera/ledmap.c @@ -55,7 +55,9 @@ void ledmap_led_on(uint8_t index) LED2_PORT &= ~(1< +#include +#include + +void inline ws2812_setleds(struct cRGB *ledarray, uint16_t leds) +{ + ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin)); +} + +void inline ws2812_setleds_pin(struct cRGB *ledarray, uint16_t leds, uint8_t pinmask) +{ + ws2812_DDRREG |= pinmask; // Enable DDR + ws2812_sendarray_mask((uint8_t*)ledarray,leds+leds+leds,pinmask); + _delay_us(50); +} + +void ws2812_sendarray(uint8_t *data,uint16_t datlen) +{ + ws2812_sendarray_mask(data,datlen,_BV(ws2812_pin)); +} + +/* + This routine writes an array of bytes with RGB values to the Dataout pin + using the fast 800kHz clockless WS2811/2812 protocol. +*/ + +// Timing in ns +#define w_zeropulse 350 +#define w_onepulse 900 +#define w_totalperiod 1250 + +// Fixed cycles used by the inner loop +#define w_fixedlow 2 +#define w_fixedhigh 4 +#define w_fixedtotal 8 + +// Insert NOPs to match the timing, if possible +#define w_zerocycles (((F_CPU/1000)*w_zeropulse )/1000000) +#define w_onecycles (((F_CPU/1000)*w_onepulse +500000)/1000000) +#define w_totalcycles (((F_CPU/1000)*w_totalperiod +500000)/1000000) + +// w1 - nops between rising edge and falling edge - low +#define w1 (w_zerocycles-w_fixedlow) +// w2 nops between fe low and fe high +#define w2 (w_onecycles-w_fixedhigh-w1) +// w3 nops to complete loop +#define w3 (w_totalcycles-w_fixedtotal-w1-w2) + +#if w1>0 + #define w1_nops w1 +#else + #define w1_nops 0 +#endif + +// The only critical timing parameter is the minimum pulse length of the "0" +// Warn or throw error if this timing can not be met with current F_CPU settings. +#define w_lowtime ((w1_nops+w_fixedlow)*1000000)/(F_CPU/1000) +#if w_lowtime>550 + #error "Light_ws2812: Sorry, the clock speed is too low. Did you set F_CPU correctly?" +#elif w_lowtime>450 + #warning "Light_ws2812: The timing is critical and may only work on WS2812B, not on WS2812(S)." + #warning "Please consider a higher clockspeed, if possible" +#endif + +#if w2>0 +#define w2_nops w2 +#else +#define w2_nops 0 +#endif + +#if w3>0 +#define w3_nops w3 +#else +#define w3_nops 0 +#endif + +#define w_nop1 "nop \n\t" +#define w_nop2 "rjmp .+0 \n\t" +#define w_nop4 w_nop2 w_nop2 +#define w_nop8 w_nop4 w_nop4 +#define w_nop16 w_nop8 w_nop8 + +void inline ws2812_sendarray_mask(uint8_t *data,uint16_t datlen,uint8_t maskhi) +{ + uint8_t curbyte,ctr,masklo; + uint8_t sreg_prev; + + masklo =~maskhi&ws2812_PORTREG; + maskhi |= ws2812_PORTREG; + sreg_prev=SREG; + cli(); + + while (datlen--) { + curbyte=*data++; + + asm volatile( + " ldi %0,8 \n\t" + "loop%=: \n\t" + " out %2,%3 \n\t" // '1' [01] '0' [01] - re +#if (w1_nops&1) +w_nop1 +#endif +#if (w1_nops&2) +w_nop2 +#endif +#if (w1_nops&4) +w_nop4 +#endif +#if (w1_nops&8) +w_nop8 +#endif +#if (w1_nops&16) +w_nop16 +#endif + " sbrs %1,7 \n\t" // '1' [03] '0' [02] + " out %2,%4 \n\t" // '1' [--] '0' [03] - fe-low + " lsl %1 \n\t" // '1' [04] '0' [04] +#if (w2_nops&1) + w_nop1 +#endif +#if (w2_nops&2) + w_nop2 +#endif +#if (w2_nops&4) + w_nop4 +#endif +#if (w2_nops&8) + w_nop8 +#endif +#if (w2_nops&16) + w_nop16 +#endif + " out %2,%4 \n\t" // '1' [+1] '0' [+1] - fe-high +#if (w3_nops&1) +w_nop1 +#endif +#if (w3_nops&2) +w_nop2 +#endif +#if (w3_nops&4) +w_nop4 +#endif +#if (w3_nops&8) +w_nop8 +#endif +#if (w3_nops&16) +w_nop16 +#endif + + " dec %0 \n\t" // '1' [+2] '0' [+2] + " brne loop%=\n\t" // '1' [+3] '0' [+4] + : "=&d" (ctr) + : "r" (curbyte), "I" (_SFR_IO_ADDR(ws2812_PORTREG)), "r" (maskhi), "r" (masklo) + ); + } + + SREG=sreg_prev; +} diff --git a/keyboard/kimera/light_ws2812.h b/keyboard/kimera/light_ws2812.h new file mode 100644 index 00000000..bc2c4e86 --- /dev/null +++ b/keyboard/kimera/light_ws2812.h @@ -0,0 +1,63 @@ +/* + * light weight WS2812 lib include + * + * Version 2.0a3 - Jan 18th 2014 + * Author: Tim (cpldcpu@gmail.com) + * + * Please do not change this file! All configuration is handled in "ws2812_config.h" + * + * License: GNU GPL v2 (see License.txt) + + + */ + +#ifndef LIGHT_WS2812_H_ +#define LIGHT_WS2812_H_ + +#include +#include +#include "ws2812_config.h" + +/* + * Structure of the LED array + */ + +struct cRGB { uint8_t g; uint8_t r; uint8_t b; }; + +/* User Interface + * + * Input: + * ledarray: An array of GRB data describing the LED colors + * number_of_leds: The number of LEDs to write + * pinmask (optional): Bitmask describing the output bin. e.g. _BV(PB0) + * + * The functions will perform the following actions: + * - Set the data-out pin as output + * - Send out the LED data + * - Wait 50µs to reset the LEDs + */ + +void ws2812_setleds (struct cRGB *ledarray, uint16_t number_of_leds); +void ws2812_setleds_pin(struct cRGB *ledarray, uint16_t number_of_leds,uint8_t pinmask); + +/* + * Old interface / Internal functions + * + * The functions take a byte-array and send to the data output as WS2812 bitstream. + * The length is the number of bytes to send - three per LED. + */ + +void ws2812_sendarray (uint8_t *array,uint16_t length); +void ws2812_sendarray_mask(uint8_t *array,uint16_t length, uint8_t pinmask); + + +/* + * Internal defines + */ + +#define CONCAT(a, b) a ## b +#define CONCAT_EXP(a, b) CONCAT(a, b) + +#define ws2812_PORTREG CONCAT_EXP(PORT,ws2812_port) +#define ws2812_DDRREG CONCAT_EXP(DDR,ws2812_port) + +#endif /* LIGHT_WS2812_H_ */ diff --git a/keyboard/kimera/rgb.c b/keyboard/kimera/rgb.c new file mode 100644 index 00000000..4954a996 --- /dev/null +++ b/keyboard/kimera/rgb.c @@ -0,0 +1,237 @@ +/* +Copyright 2016 Kai Ryu + +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 . +*/ + +#include +#include +#include "softpwm_led.h" +#include "backlight.h" +#include "rgb.h" +#include "light_ws2812.h" +#include "debug.h" + +#ifdef RGB_LED_ENABLE + +volatile static uint8_t rgb_fading_enable = 0; +static rgb_config_t rgb_config; +static struct cRGB rgb_color[RGB_LED_COUNT]; +static uint16_t rgb_hue = 0; +static uint8_t rgb_saturation = 255; +static uint8_t rgb_brightness = 16; +static uint8_t rgb_rainbow = 0; + +extern backlight_config_t backlight_config; +extern uint8_t backlight_brightness; + +static void rgb_write_config(void); +static void rgb_read_config(void); +static void rgb_set_level(uint8_t level); +static void rgb_refresh(void); +static void hue_to_rgb(uint16_t hue, struct cRGB *rgb); +static void hsb_to_rgb(uint16_t hue, uint8_t saturation, uint8_t brightness, struct cRGB *rgb); + +void rgb_init(void) +{ + rgb_read_config(); + if (rgb_config.raw == RGB_UNCONFIGURED) { + rgb_config.enable = 0; + rgb_config.level = RGB_OFF; + rgb_write_config(); + } + if (rgb_config.enable) { + rgb_set_level(rgb_config.level); + } +} + +void rgb_read_config(void) +{ + rgb_config.raw = eeprom_read_byte(EECONFIG_RGB); +} + +void rgb_write_config(void) +{ + eeprom_write_byte(EECONFIG_RGB, rgb_config.raw); +} + +void rgb_toggle(void) +{ + if (rgb_config.enable) { + rgb_off(); + } + else { + rgb_on(); + } +} + +void rgb_on(void) +{ + rgb_config.enable = 1; + rgb_set_level(rgb_config.level); + rgb_write_config(); +} + +void rgb_off(void) +{ + rgb_config.enable = 0; + rgb_set_level(RGB_OFF); + rgb_write_config(); +} + +void rgb_decrease(void) +{ + if(rgb_config.level > 0) { + rgb_config.level--; + rgb_config.enable = (rgb_config.level != 0); + rgb_write_config(); + } + rgb_set_level(rgb_config.level); +} + +void rgb_increase(void) +{ + if(rgb_config.level < RGB_LEVELS) { + rgb_config.level++; + rgb_config.enable = 1; + rgb_write_config(); + } + rgb_set_level(rgb_config.level); +} + +void rgb_step(void) +{ + rgb_config.level++; + if(rgb_config.level > RGB_LEVELS) + { + rgb_config.level = 0; + } + rgb_config.enable = (rgb_config.level != 0); + rgb_set_level(rgb_config.level); +} + +void rgb_set_level(uint8_t level) +{ + dprintf("RGB Level: %d\n", level); + if (level <= RGB_WHITE) { + rgb_fading_enable = 0; + rgb_rainbow = 0; + if (level == RGB_OFF) { + rgb_brightness = 0; + } + else { + if (level == RGB_WHITE) { + rgb_saturation = 0; + } + else { + rgb_hue = (level - 1) * 128; + rgb_saturation = 255; + } + if (backlight_config.enable) { + if (backlight_config.level >= 1 && backlight_config.level <= 3) { + rgb_brightness = backlight_brightness; + } + } + else { + rgb_brightness = 16; + } + } + rgb_refresh(); + } + else { + rgb_saturation = 255; + rgb_fading_enable = 1; + rgb_rainbow = (level >= RGB_RAINBOW) ? 1 : 0; + } +} + +void rgb_set_brightness(uint8_t brightness) +{ + if (rgb_config.enable) { + rgb_brightness = brightness; + rgb_refresh(); + } +} + +void rgb_refresh(void) +{ + struct cRGB rgb; + uint16_t hue; + uint8_t i; + if (rgb_rainbow) { + for (i = 0; i < RGB_LED_COUNT; i++) { + hue = rgb_hue + (768 / RGB_LED_COUNT) * i; + hsb_to_rgb(hue, rgb_saturation, rgb_brightness, &rgb); + rgb_color[i] = rgb; + } + } + else { + hsb_to_rgb(rgb_hue, rgb_saturation, rgb_brightness, &rgb); + for (i = 0; i < RGB_LED_COUNT; i++) { + rgb_color[i] = rgb; + } + } + /* xprintf("R%d G%d B%d\n", rgb_color[0].r, rgb_color[0].g, rgb_color[0].b); */ + ws2812_setleds(rgb_color, RGB_LED_COUNT); +} + +void hue_to_rgb(uint16_t hue, struct cRGB *rgb) +{ + uint8_t hi = hue / 60; + uint16_t f = (hue % 60) * 425 / 100; + uint8_t q = 255 - f; + switch (hi) { + case 0: rgb->r = 255; rgb->g = f; rgb->b = 0; break; + case 1: rgb->r = q; rgb->g = 255; rgb->b = 0; break; + case 2: rgb->r = 0; rgb->g = 255; rgb->b = f; break; + case 3: rgb->r = 0; rgb->g = q; rgb->b = 255; break; + case 4: rgb->r = f; rgb->g = 0; rgb->b = 255; break; + case 5: rgb->r = 255; rgb->g = 0; rgb->b = q; break; + } +} + +/* + * original code: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/ + */ +void hsb_to_rgb(uint16_t hue, uint8_t saturation, uint8_t brightness, struct cRGB *rgb) +{ + uint8_t temp[5]; + uint8_t n = (hue >> 8) % 3; + uint8_t x = ((((hue & 255) * saturation) >> 8) * brightness) >> 8; + uint8_t s = ((256 - saturation) * brightness) >> 8; + temp[0] = temp[3] = s; + temp[1] = temp[4] = x + s; + temp[2] = brightness - x; + rgb->r = temp[n + 2]; + rgb->g = temp[n + 1]; + rgb->b = temp[n]; +} + +void rgb_fading(void) +{ + static uint8_t step = 0; + static uint16_t hue = 0; + if (rgb_fading_enable) { + if (++step > rgb_fading_enable) { + step = 0; + rgb_hue = hue; + rgb_refresh(); + if (++hue >= 768) { + hue = 0; + } + } + } +} + +#endif diff --git a/keyboard/kimera/rgb.h b/keyboard/kimera/rgb.h new file mode 100644 index 00000000..bde1db75 --- /dev/null +++ b/keyboard/kimera/rgb.h @@ -0,0 +1,60 @@ +/* +Copyright 2016 Kai Ryu + +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 . +*/ + +#ifndef RGB_H +#define RGB_H + +#include +#include + +typedef union { + uint8_t raw; + struct { + uint8_t level :7; + bool enable :1; + }; +} rgb_config_t; + +enum { + RGB_OFF = 0, + RGB_RED, + RGB_YELLOW, + RGB_GREEN, + RGB_CYAN, + RGB_BLUE, + RGB_MAGENTA, + RGB_WHITE, + RGB_FADE, + RGB_RAINBOW, + RGB_LEVELS = RGB_RAINBOW +}; + +#define EECONFIG_RGB (uint8_t *)15 +#define RGB_UNCONFIGURED 0xFF +#define RGB_LED_COUNT 16 + +void rgb_init(void); +void rgb_toggle(void); +void rgb_on(void); +void rgb_off(void); +void rgb_decrease(void); +void rgb_increase(void); +void rgb_step(void); +void rgb_set_brightness(uint8_t brightness); +void rgb_fading(void); + +#endif diff --git a/keyboard/kimera/ws2812_config.h b/keyboard/kimera/ws2812_config.h new file mode 100644 index 00000000..1d5a6738 --- /dev/null +++ b/keyboard/kimera/ws2812_config.h @@ -0,0 +1,21 @@ +/* + * light_ws2812_config.h + * + * Created: 18.01.2014 09:58:15 + * + * User Configuration file for the light_ws2812_lib + * + */ + + +#ifndef WS2812_CONFIG_H_ +#define WS2812_CONFIG_H_ + +/////////////////////////////////////////////////////////////////////// +// Define I/O pin +/////////////////////////////////////////////////////////////////////// + +#define ws2812_port C // Data port +#define ws2812_pin 6 // Data out pin + +#endif /* WS2812_CONFIG_H_ */ From e2773c801abccbf99ebd649d47cd66d258d1b3e4 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 17 Mar 2016 22:06:24 +0900 Subject: [PATCH 25/29] kimera: Support new softpwm change --- keyboard/kimera/backlight.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keyboard/kimera/backlight.c b/keyboard/kimera/backlight.c index bef3be13..24777bc0 100644 --- a/keyboard/kimera/backlight.c +++ b/keyboard/kimera/backlight.c @@ -72,7 +72,7 @@ void backlight_disable(void) void backlight_set(uint8_t level) { #ifdef SOFTPWM_LED_ENABLE - softpwm_led_enable(); + softpwm_enable(); #endif #ifdef BREATHING_LED_ENABLE switch (level) { @@ -80,6 +80,7 @@ void backlight_set(uint8_t level) case 2: case 3: #ifdef SOFTPWM_LED_ENABLE + softpwm_led_enable_all(); #ifdef FADING_LED_ENABLE fading_led_disable_all(); #endif @@ -98,6 +99,7 @@ void backlight_set(uint8_t level) case 5: case 6: #ifdef SOFTPWM_LED_ENABLE + softpwm_led_enable_all(); #ifdef FADING_LED_ENABLE fading_led_disable_all(); #endif @@ -111,12 +113,14 @@ void backlight_set(uint8_t level) #ifdef SOFTPWM_LED_ENABLE #ifdef FADING_LED_ENABLE case 7: + softpwm_led_enable_all(); fading_led_enable_all(); breathing_led_disable_all(); fading_led_set_direction_all(FADING_LED_FADE_IN); fading_led_set_duration(3); break; case 8: + softpwm_led_enable_all(); fading_led_enable_all(); breathing_led_disable_all(); fading_led_set_direction_all(FADING_LED_FADE_OUT); @@ -133,6 +137,7 @@ void backlight_set(uint8_t level) breathing_led_disable_all(); backlight_brightness = 0; backlight_set_raw(backlight_brightness); + softpwm_led_disable_all(); #else breathing_led_disable(); backlight_disable(); From 93029977a898c2bf6cbbfc61ae550c907c75e2e5 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 31 Mar 2016 18:52:43 +0900 Subject: [PATCH 26/29] kimera: Improve matrix scanning frequency - Implement improved debounce algorithm - Change combining of keymap for two-headed kimera --- keyboard/kimera/kimera.c | 68 ++++++++++++++++-- keyboard/kimera/kimera.h | 15 +--- keyboard/kimera/matrix.c | 146 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 210 insertions(+), 19 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index c4c42f8d..7082ab42 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -86,6 +86,17 @@ static matrix_row_t col_left_mask; static uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; static uint8_t exp_status = 0; +static uint8_t read_matrix_mapping(void); +static void write_matrix_mapping(void); +static void expander_init(uint8_t exp); +static uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data); +static uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data); +static uint8_t expander_write_output(uint8_t exp, uint8_t *data); +static uint8_t expander_write_inversion(uint8_t exp, uint8_t *data); +static uint8_t expander_write_config(uint8_t exp, uint8_t *data); +static uint8_t expander_read_input(uint8_t exp, uint8_t *data); +static void init_data(uint8_t value); + void kimera_init(void) { /* read config */ @@ -130,7 +141,7 @@ uint8_t read_matrix_mapping(void) #ifdef TWO_HEADED_KIMERA row_left_count = (rows + 1) / 2; col_left_count = (cols + 1) / 2; - col_left_mask = (1 << row_left_count) - 1; + col_left_mask = (1 << col_left_count) - 1; #endif /* read row mapping */ @@ -200,30 +211,68 @@ void kimera_scan(void) } } +#define CHANGE_COMBINING 1 + inline uint8_t kimera_matrix_rows(void) { +#if CHANGE_COMBINING +#ifndef TWO_HEADED_KIMERA return row_count; +#else + return row_left_count; +#endif +#else + return row_count; +#endif } inline uint8_t kimera_matrix_cols(void) { +#if CHANGE_COMBINING + return col_count; +#else #ifndef TWO_HEADED_KIMERA return col_count; #else return col_left_count; #endif +#endif } -matrix_row_t kimera_read_cols(uint8_t row) +void kimera_read_cols(void) { - init_data(0xFF); - /* read all input registers */ + init_data(0xFF); for (uint8_t exp = 0; exp < EXP_COUNT; exp++) { expander_read_input(exp, data[exp]); } +} + +uint8_t kimera_get_col(uint8_t row, uint8_t col) +{ +#if CHANGE_COMBINING +#else +#ifdef TWO_HEADED_KIMERA + if (row >= row_left_count) { + col += col_left_count; + } +#endif +#endif + + uint8_t px = col_mapping[col]; + if (px != UNCONFIGURED) { + if (!(data[PX_TO_EXP(px)][PX_TO_PORT(px)] & (1 << PX_TO_PIN(px)))) { + return 1; + } + } + return 0; +} + +matrix_row_t kimera_read_row(uint8_t row) +{ + kimera_read_cols(); /* make cols */ matrix_row_t cols = 0; @@ -236,6 +285,8 @@ matrix_row_t kimera_read_cols(uint8_t row) } } +#if CHANGE_COMBINING +#else #ifdef TWO_HEADED_KIMERA if (row < row_left_count) { cols &= col_left_mask; @@ -243,6 +294,7 @@ matrix_row_t kimera_read_cols(uint8_t row) else { cols >>= col_left_count; } +#endif #endif return cols; @@ -267,6 +319,13 @@ void kimera_select_row(uint8_t row) data[exp][PX_TO_PORT(px)] &= ~(1 << PX_TO_PIN(px)); expander_write_config(exp, data[exp]); } +#if CHANGE_COMBINING +#ifdef TWO_HEADED_KIMERA + if (row < row_left_count) { + kimera_select_row(row + row_left_count); + } +#endif +#endif } void expander_init(uint8_t exp) @@ -349,6 +408,7 @@ uint8_t expander_write_config(uint8_t exp, uint8_t *data) { return expander_write(exp, EXP_COMM_CONFIG_0, data); } + inline uint8_t expander_read_input(uint8_t exp, uint8_t *data) { diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 24d3c132..7769efe3 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -156,22 +156,13 @@ const uint16_t PROGMEM dummy[] = { /* Functions */ void kimera_init(void); -void wdt_init(void); -uint8_t read_matrix_mapping(void); -void write_matrix_mapping(void); void kimera_scan(void); uint8_t kimera_matrix_rows(void); uint8_t kimera_matrix_cols(void); -matrix_row_t kimera_read_cols(uint8_t row); +void kimera_read_cols(void); +uint8_t kimera_get_col(uint8_t row, uint8_t col); +matrix_row_t kimera_read_row(uint8_t row); void kimera_unselect_rows(void); void kimera_select_row(uint8_t row); -void expander_init(uint8_t exp); -uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data); -uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data); -uint8_t expander_write_output(uint8_t exp, uint8_t *data); -uint8_t expander_write_inversion(uint8_t exp, uint8_t *data); -uint8_t expander_write_config(uint8_t exp, uint8_t *data); -uint8_t expander_read_input(uint8_t exp, uint8_t *data); -void init_data(uint8_t value); #endif diff --git a/keyboard/kimera/matrix.c b/keyboard/kimera/matrix.c index bc7b9387..83d2975b 100644 --- a/keyboard/kimera/matrix.c +++ b/keyboard/kimera/matrix.c @@ -28,16 +28,29 @@ along with this program. If not, see . #include "matrix.h" #include "kimera.h" #include "keymap_in_eeprom.h" +#include "timer.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]; + +#define IMPROVED_DEBOUNCE 1 + +#if IMPROVED_DEBOUNCE +#define DEBOUNCE_MASK ((1 << DEBOUNCE) - 1) +static uint8_t matrix_current_row; +static uint16_t matrix_row_timestamp[MATRIX_ROWS]; +static uint8_t matrix_debouncing[MATRIX_ROWS][MATRIX_COLS]; +#else +static uint8_t debouncing = DEBOUNCE; static matrix_row_t matrix_debouncing[MATRIX_ROWS]; +#endif + +static uint16_t kimera_scan_timestamp; inline uint8_t matrix_rows(void) @@ -58,15 +71,27 @@ void matrix_init(void) MCUCR = (1<= 1000) { + xprintf("Scan, %u\n", kimera_scan_timestamp); + kimera_scan_timestamp = timer_read(); + kimera_scan(); + } + +#if IMPROVED_DEBOUNCE + uint16_t elapsed = timer_elapsed(matrix_row_timestamp[matrix_current_row]); + if (elapsed >= 1) { + matrix_row_timestamp[matrix_current_row] = timer_read(); + kimera_select_row(matrix_current_row); + _delay_us(30); + kimera_read_cols(); + for (uint8_t i = 0; i < matrix_cols(); i++) { + uint8_t *debounce = &matrix_debouncing[matrix_current_row][i]; + uint8_t col = kimera_get_col(matrix_current_row, i); + uint8_t count = elapsed; + do { + *debounce <<= 1; + *debounce |= col; + } while (--count); + matrix_row_t *row = &matrix[matrix_current_row]; + matrix_row_t mask = ((matrix_row_t)1 << i); + switch (*debounce & DEBOUNCE_MASK) { + case DEBOUNCE_MASK: +#if DEBOUNCE > 1 + case (DEBOUNCE_MASK >> 1): +#if DEBOUNCE > 2 + case (DEBOUNCE_MASK >> 2): +#if DEBOUNCE > 3 + case (DEBOUNCE_MASK >> 3): +#if DEBOUNCE > 4 + case (DEBOUNCE_MASK >> 4): +#if DEBOUNCE > 5 + case (DEBOUNCE_MASK >> 5): +#if DEBOUNCE > 6 + case (DEBOUNCE_MASK >> 6): +#if DEBOUNCE > 7 + case (DEBOUNCE_MASK >> 7): +#if DEBOUNCE > 8 + case (DEBOUNCE_MASK >> 8): +#if DEBOUNCE > 9 + case (DEBOUNCE_MASK >> 9): +#if DEBOUNCE > 10 + case (DEBOUNCE_MASK >> 10): +#endif +#endif +#endif +#endif +#endif +#endif +#endif +#endif +#endif +#endif + if ((*row & mask) == 0) { + *row |= mask; + } + break; +#if DEBOUNCE > 1 + case ((DEBOUNCE_MASK << 1) & DEBOUNCE_MASK): +#if DEBOUNCE > 2 + case ((DEBOUNCE_MASK << 2) & DEBOUNCE_MASK): +#if DEBOUNCE > 3 + case ((DEBOUNCE_MASK << 3) & DEBOUNCE_MASK): +#if DEBOUNCE > 4 + case ((DEBOUNCE_MASK << 4) & DEBOUNCE_MASK): +#if DEBOUNCE > 5 + case ((DEBOUNCE_MASK << 5) & DEBOUNCE_MASK): +#if DEBOUNCE > 6 + case ((DEBOUNCE_MASK << 6) & DEBOUNCE_MASK): +#if DEBOUNCE > 7 + case ((DEBOUNCE_MASK << 7) & DEBOUNCE_MASK): +#if DEBOUNCE > 8 + case ((DEBOUNCE_MASK << 8) & DEBOUNCE_MASK): +#if DEBOUNCE > 9 + case ((DEBOUNCE_MASK << 9) & DEBOUNCE_MASK): +#if DEBOUNCE > 10 + case ((DEBOUNCE_MASK << 10) & DEBOUNCE_MASK): +#endif +#endif +#endif +#endif +#endif +#endif +#endif +#endif +#endif +#endif + break; + case 0: + if ((*row & mask) != 0) { + *row &= ~mask; + } + break; + default: + debug("bounce!: "); + debug_bin8(*debounce & DEBOUNCE_MASK); + debug("\n"); + break; + } + } + kimera_unselect_rows(); + } + + matrix_current_row++; + if (matrix_current_row >= matrix_rows()) { + matrix_current_row = 0; + } +#else for (uint8_t i = 0; i < matrix_rows(); i++) { kimera_select_row(i); _delay_us(30); // without this wait read unstable value. - matrix_row_t cols = kimera_read_cols(i); + matrix_row_t cols = kimera_read_row(i); if (matrix_debouncing[i] != cols) { matrix_debouncing[i] = cols; if (debouncing) { @@ -99,15 +235,19 @@ uint8_t matrix_scan(void) } } } +#endif return 1; } +#if IMPROVED_DEBOUNCE +#else bool matrix_is_modified(void) { if (debouncing) return false; return true; } +#endif inline bool matrix_is_on(uint8_t row, uint8_t col) From 6508d8d7b8179b6464ea349d25758ab317767f80 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 31 Mar 2016 19:01:31 +0900 Subject: [PATCH 27/29] kimera: Reduce communication with unused expander --- keyboard/kimera/kimera.c | 80 +++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 7082ab42..66fbeeb6 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -84,7 +84,8 @@ static uint8_t col_left_count = 16; static matrix_row_t col_left_mask; #endif static uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; -static uint8_t exp_status = 0; +static uint8_t exp_in_use = 0; +static uint8_t exp_online = 0; static uint8_t read_matrix_mapping(void); static void write_matrix_mapping(void); @@ -146,10 +147,17 @@ uint8_t read_matrix_mapping(void) /* read row mapping */ uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; + uint8_t exp; for (uint8_t i = 0; i < PX_COUNT; i++) { if (i < row_count) { row_mapping[i] = eeprom_read_byte(mapping++); - if (row_mapping[i] >= PX_COUNT) error++; + if (row_mapping[i] >= PX_COUNT) { + error++; + } + else { + exp = PX_TO_EXP(row_mapping[i]); + exp_in_use |= (1<= PX_COUNT) error++; + if (col_mapping[i] >= PX_COUNT) { + error++; + } + else { + exp = PX_TO_EXP(col_mapping[i]); + exp_in_use |= (1< Date: Thu, 31 Mar 2016 19:08:50 +0900 Subject: [PATCH 28/29] kimera: Restructure i2c init and force stop --- keyboard/kimera/Makefile | 1 + keyboard/kimera/i2c_wrapper.c | 95 +++++++++++++++++++++++++++++++++++ keyboard/kimera/i2c_wrapper.h | 25 +++++++++ keyboard/kimera/kimera.c | 63 ----------------------- keyboard/kimera/matrix.c | 5 ++ 5 files changed, 126 insertions(+), 63 deletions(-) create mode 100644 keyboard/kimera/i2c_wrapper.c create mode 100644 keyboard/kimera/i2c_wrapper.h diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index 74264b49..227af26a 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -54,6 +54,7 @@ SRC = keymap_common.c \ backlight.c \ ledmap.c \ twimaster.c \ + i2c_wrapper.c \ kimera.c \ light_ws2812.c \ rgb.c diff --git a/keyboard/kimera/i2c_wrapper.c b/keyboard/kimera/i2c_wrapper.c new file mode 100644 index 00000000..07f87838 --- /dev/null +++ b/keyboard/kimera/i2c_wrapper.c @@ -0,0 +1,95 @@ +/* +Copyright 2016 Kai Ryu + +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 . +*/ + +#include +#include +#include +#include "i2cmaster.h" +#include "i2c_wrapper.h" +#include "debug.h" + +#define wdt_intr_enable(value) \ +__asm__ __volatile__ ( \ + "in __tmp_reg__,__SREG__" "\n\t" \ + "cli" "\n\t" \ + "wdr" "\n\t" \ + "sts %0,%1" "\n\t" \ + "out __SREG__,__tmp_reg__" "\n\t" \ + "sts %0,%2" "\n\t" \ + : /* no outputs */ \ + : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ + "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ + "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ + _BV(WDIE) | (value & 0x07)) ) \ + : "r0" \ +) + +#define SCL_CLOCK 400000L +#define SCL_DURATION (1000000L/SCL_CLOCK)/2 + +static uint8_t i2c_wdt_enabled = 0; + +extern uint8_t i2c_force_stop; + +static void wdt_init(void); + +void i2c_wrapper_init(void) +{ + /* init i2c */ + i2c_init(); + + /* init watch dog */ + wdt_init(); +} + +void i2c_wrapper_task(void) +{ + /* reset watch dog counter */ + wdt_reset(); +} + +void wdt_init(void) +{ + cli(); + wdt_reset(); + wdt_intr_enable(WDTO_2S); + sei(); +} + +ISR(WDT_vect) +{ + xprintf("i2c timeout\n"); + + /* let slave to release SDA */ + TWCR = 0; + DDRD |= (1< + +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 . +*/ + +#ifndef I2C_WRAPPER_H +#define I2C_WRAPPER_H + +void i2c_wrapper_init(void); +void i2c_wrapper_task(void); + +#endif + diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index 66fbeeb6..af85685c 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -19,34 +19,11 @@ along with this program. If not, see . #include #include -#include -#include -#include #include "action.h" #include "i2cmaster.h" #include "kimera.h" #include "debug.h" -#define wdt_intr_enable(value) \ -__asm__ __volatile__ ( \ - "in __tmp_reg__,__SREG__" "\n\t" \ - "cli" "\n\t" \ - "wdr" "\n\t" \ - "sts %0,%1" "\n\t" \ - "out __SREG__,__tmp_reg__" "\n\t" \ - "sts %0,%2" "\n\t" \ - : /* no outputs */ \ - : "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \ - "r" (_BV(_WD_CHANGE_BIT) | _BV(WDE)), \ - "r" ((uint8_t) ((value & 0x08 ? _WD_PS3_MASK : 0x00) | \ - _BV(WDIE) | (value & 0x07)) ) \ - : "r0" \ -) - -#define SCL_CLOCK 400000L -#define SCL_DURATION (1000000L/SCL_CLOCK)/2 -extern uint8_t i2c_force_stop; - static uint8_t row_mapping[PX_COUNT] = { #ifndef TWO_HEADED_KIMERA 0, 1, 2, 3, 4, 5, 6, 7, @@ -106,24 +83,10 @@ void kimera_init(void) write_matrix_mapping(); } - /* init i2c */ - i2c_init(); - - /* init watch dog */ - wdt_init(); - /* init i/o expanders */ kimera_scan(); } -void wdt_init(void) -{ - cli(); - wdt_reset(); - wdt_intr_enable(WDTO_1S); - sei(); -} - uint8_t read_matrix_mapping(void) { uint8_t error = 0; @@ -396,7 +359,6 @@ void expander_init(uint8_t exp) uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data) { - wdt_reset(); if ((exp_online & (1<. #include "debug.h" #include "util.h" #include "matrix.h" +#include "i2c_wrapper.h" #include "kimera.h" #include "keymap_in_eeprom.h" #include "timer.h" @@ -70,6 +71,9 @@ void matrix_init(void) MCUCR = (1< Date: Wed, 27 Apr 2016 10:15:28 +0900 Subject: [PATCH 29/29] kimera: Improve flexibility of combining of keymap - Assign combining in row/col mapping - Remove macro TWO_HEADED_KIMERA - Now Kimera and Two Headed Kimera can use a common firmware --- keyboard/kimera/config.h | 4 -- keyboard/kimera/kimera.c | 142 ++++++++++++++------------------------- keyboard/kimera/kimera.h | 11 +-- 3 files changed, 56 insertions(+), 101 deletions(-) diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index 8fef70fb..c08c676d 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -35,11 +35,7 @@ along with this program. If not, see . #define MATRIX_SIZE 16 * 16 #define FN_ACTIONS_COUNT 32 #define KEYMAPS_COUNT 3 -#ifndef TWO_HEADED_KIMERA -#define EECONFIG_KEYMAP_IN_EEPROM 50 -#else #define EECONFIG_KEYMAP_IN_EEPROM 82 -#endif /* define if matrix has ghost */ //#define MATRIX_HAS_GHOST diff --git a/keyboard/kimera/kimera.c b/keyboard/kimera/kimera.c index af85685c..500437a8 100644 --- a/keyboard/kimera/kimera.c +++ b/keyboard/kimera/kimera.c @@ -25,41 +25,23 @@ along with this program. If not, see . #include "debug.h" static uint8_t row_mapping[PX_COUNT] = { -#ifndef TWO_HEADED_KIMERA - 0, 1, 2, 3, 4, 5, 6, 7, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED -#else 0, 1, 2, 3, 4, 5, 6, 7, 32, 33, 34, 35, 36, 37, 38, 39, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED -#endif }; static uint8_t col_mapping[PX_COUNT] = { -#ifndef TWO_HEADED_KIMERA - 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED, UNCONFIGURED -#else 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55 -#endif }; -#ifndef TWO_HEADED_KIMERA -static uint8_t row_count = 8; -static uint8_t col_count = 24; -#else static uint8_t row_count = 16; static uint8_t col_count = 32; static uint8_t row_left_count = 8; static uint8_t col_left_count = 16; static matrix_row_t col_left_mask; -#endif +static uint8_t combining = COMBINING_NONE; static uint8_t data[EXP_COUNT][EXP_PORT_COUNT]; static uint8_t exp_in_use = 0; static uint8_t exp_online = 0; @@ -95,18 +77,28 @@ uint8_t read_matrix_mapping(void) uint8_t rows = eeprom_read_byte(EECONFIG_ROW_COUNT); uint8_t cols = eeprom_read_byte(EECONFIG_COL_COUNT); if (rows == 0) error++; - if (rows == UNCONFIGURED) error++; + else if (rows == UNCONFIGURED) error++; + else if (rows & COMBINING_BIT) { + if (combining != COMBINING_NONE) error++; + combining = COMBINING_ROW; + rows -= COMBINING_BIT; + } if (cols == 0) error++; - if (cols == UNCONFIGURED) error++; + else if (cols == UNCONFIGURED) error++; + else if (cols & COMBINING_BIT) { + if (combining != COMBINING_NONE) error++; + combining = COMBINING_COL; + cols -= COMBINING_BIT; + } if (rows + cols > PX_COUNT) error++; if (error) return error; row_count = rows; col_count = cols; -#ifdef TWO_HEADED_KIMERA - row_left_count = (rows + 1) / 2; - col_left_count = (cols + 1) / 2; - col_left_mask = (1 << col_left_count) - 1; -#endif + if (combining != COMBINING_NONE) { + row_left_count = (rows + 1) / 2; + col_left_count = (cols + 1) / 2; + col_left_mask = (1 << col_left_count) - 1; + } /* read row mapping */ uint8_t *mapping = EECONFIG_ROW_COL_MAPPING; @@ -166,8 +158,8 @@ void write_matrix_mapping(void) void kimera_scan(void) { uint8_t ret; - xprintf("exp in use: %d\n", exp_in_use); - xprintf("exp online: %d\n", exp_online); + dprintf("exp in use: %d\n", exp_in_use); + dprintf("exp online: %d\n", exp_online); for (uint8_t exp = 0; exp < EXP_COUNT; exp++) { if (exp_in_use & (1<= row_left_count) { - col += col_left_count; + if (combining == COMBINING_ROW) { + if (row >= row_left_count) { + col += col_left_count; + } } -#endif -#endif uint8_t px = col_mapping[col]; if (px != UNCONFIGURED) { @@ -286,17 +246,14 @@ matrix_row_t kimera_read_row(uint8_t row) } } -#if CHANGE_COMBINING -#else -#ifdef TWO_HEADED_KIMERA - if (row < row_left_count) { - cols &= col_left_mask; + if (combining == COMBINING_COL) { + if (row < row_left_count) { + cols &= col_left_mask; + } + else { + cols >>= col_left_count; + } } - else { - cols >>= col_left_count; - } -#endif -#endif return cols; } @@ -320,13 +277,12 @@ void kimera_select_row(uint8_t row) data[exp][PX_TO_PORT(px)] &= ~(1 << PX_TO_PIN(px)); expander_write_config(exp, data[exp]); } -#if CHANGE_COMBINING -#ifdef TWO_HEADED_KIMERA - if (row < row_left_count) { - kimera_select_row(row + row_left_count); + + if (combining == COMBINING_ROW) { + if (row < row_left_count) { + kimera_select_row(row + row_left_count); + } } -#endif -#endif } void expander_init(uint8_t exp) @@ -387,7 +343,7 @@ uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data) if (ret) goto stop; ret = i2c_write(command); if (ret) goto stop; - ret = i2c_start(addr | I2C_READ); + ret = i2c_rep_start(addr | I2C_READ); if (ret) goto stop; *data++ = i2c_readAck(); *data = i2c_readNak(); diff --git a/keyboard/kimera/kimera.h b/keyboard/kimera/kimera.h index 7769efe3..74c1127c 100644 --- a/keyboard/kimera/kimera.h +++ b/keyboard/kimera/kimera.h @@ -111,11 +111,7 @@ along with this program. If not, see . `----------' `----------' */ -#ifndef TWO_HEADED_KIMERA -#define EXP_COUNT 2 -#else #define EXP_COUNT 4 -#endif #define EXP_ADDR(n) ((0x20+(n))<<1) #define EXP_OUTPUT 0 #define EXP_INPUT 1 @@ -153,6 +149,13 @@ const uint16_t PROGMEM dummy[] = { #define EECONFIG_ROW_COL_MAPPING (uint8_t *)18 #define UNCONFIGURED 0xFF +enum { + COMBINING_NONE = 0, + COMBINING_COL, + COMBINING_ROW +}; +#define COMBINING_BIT (0x80) + /* Functions */ void kimera_init(void);