1
0
Fork 0

Refactor cospad to current standards and enable support for backlight keycodes (#5582)

This commit is contained in:
zvecr 2019-04-24 19:13:07 +01:00 committed by MechMerlin
parent eda924d7dc
commit e6f4173aec
6 changed files with 253 additions and 224 deletions

View file

@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CONFIG_H #pragma once
#define CONFIG_H
#include "config_common.h" #include "config_common.h"
@ -32,42 +31,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_ROWS 6 #define MATRIX_ROWS 6
#define MATRIX_COLS 4 #define MATRIX_COLS 4
// ROWS: Top to bottom, COLS: Left to right /*
* Keyboard Matrix Assignments
*
* Change this to how you wired your keyboard
* COLS: AVR pins used for columns, left to right
* ROWS: AVR pins used for rows, top to bottom
* DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
*
*/
#define MATRIX_ROW_PINS { D0, D1, D2, D3, D4, D5 } #define MATRIX_ROW_PINS { D0, D1, D2, D3, D4, D5 }
#define MATRIX_COL_PINS { F0, F1, E6, C7 } #define MATRIX_COL_PINS { F0, F1, E6, C7 }
#define UNUSED_PINS #define UNUSED_PINS
#define BACKLIGHT_PIN F7
/* COL2ROW or ROW2COL */ /* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW #define DIODE_DIRECTION COL2ROW
/* define if matrix has ghost */ /* Backlight configuration */
//#define MATRIX_HAS_GHOST #define BACKLIGHT_PIN F7
#define BACKLIGHT_LEVELS 1
/* Set 0 if debouncing isn't needed */ /* Underlight configuration */
#define RGB_DI_PIN F6
#define RGBLED_NUM 4
#define RGBLIGHT_ANIMATIONS
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCING_DELAY 5 #define DEBOUNCING_DELAY 5
/* define if matrix has ghost (lacks anti-ghosting diodes) */
//#define MATRIX_HAS_GHOST
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
//#define LOCKING_SUPPORT_ENABLE //#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */ /* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE #define LOCKING_RESYNC_ENABLE
/* Backlight configuration
*/
#define BACKLIGHT_LEVELS 4
/* Underlight configuration
*/
#define RGB_DI_PIN F6
#define RGBLIGHT_ANIMATIONS
#define RGBLED_NUM 4 // Number of LEDs
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_VAL_STEP 17
/* /*
* Feature disable options * Feature disable options
* These options are also useful to firmware size reduction. * These options are also useful to firmware size reduction.
@ -86,4 +86,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_MACRO //#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION //#define NO_ACTION_FUNCTION
#endif /* Bootmagic Lite key configuration */
// #define BOOTMAGIC_LITE_ROW 0
// #define BOOTMAGIC_LITE_COLUMN 0

View file

@ -1,37 +1,33 @@
/* Copyright 2019
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cospad.h" #include "cospad.h"
#include "led.h"
extern inline void cospad_bl_led_on(void); #ifdef BACKLIGHT_ENABLE
extern inline void cospad_bl_led_off(void);
extern inline void cospad_bl_led_togg(void);
void matrix_init_kb(void) { void backlight_init_ports(void) {
// put your keyboard start-up code here setPinOutput(F7);
// runs once when the firmware starts up
matrix_init_user();
led_init_ports();
};
void matrix_scan_kb(void) {
// put your looping keyboard code here
// runs every cycle (a lot)
matrix_scan_user();
};
void led_init_ports(void) {
// * Set our LED pins as output
DDRB |= (1<<2);
DDRF |= (1<<7);
// * Setting BL LEDs to init as off
PORTF |= (1<<7);
} }
void led_set_kb(uint8_t usb_led) { void backlight_set(uint8_t level) {
if (usb_led & (1<<USB_LED_NUM_LOCK)) { writePin(F7, !!level);
// Turn numlock on
PORTB &= ~(1<<2);
} else {
// Turn numlock off
PORTB |= (1<<2);
}
} }
void backlight_task(void) {
// do nothing - as default implementation of software PWM does not work
}
#endif //BACKLIGHT_ENABLE

View file

@ -1,10 +1,32 @@
#ifndef COSPAD_H
#define COSPAD_H /* Copyright 2019
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "quantum.h" #include "quantum.h"
#define ___ KC_NO
// readability /* This a shortcut to help you visually see your layout.
#define XXX KC_NO *
* The first section contains all of the arguments representing the physical
* layout of the board and position of the keys.
*
* The second converts the arguments into a two-dimensional array which
* represents the switch matrix.
*/
/* COSPAD ortho matrix layout /* COSPAD ortho matrix layout
* ,-------------------. * ,-------------------.
@ -21,40 +43,6 @@
* | 50 | 51 | 52 | 53 | * | 50 | 51 | 52 | 53 |
* `-------------------' * `-------------------'
*/ */
/* COSPAD gamepad matrix layout
* ,-------------------.
* | 00 | 01 | 02 | 03 |
* |----|----|----|----|
* | 10 | 11 | 12 | 13 |
* |----|----|----|----|
* | 20 | 21 | 22 | |
* |----|----|----| 23 |
* | 30 | 31 | 32 | |
* |----|----|----|----|
* | 40 | 41 | 42 | 43 |
* |----|----|----|----|
* | 50 | 51 | 52 | 53 |
* `-------------------'
*/
/* COSPAD numpad matrix layout
* ,-------------------.
* | 00 | 01 | 02 | 03 |
* |----|----|----|----|
* | 10 | 11 | 12 | 13 |
* |----|----|----|----|
* | 20 | 21 | 22 | |
* |----|----|----| 23 |
* | 30 | 31 | 32 | |
* |----|----|----|----|
* | 40 | 41 | 42 | |
* |----|----|----| 43 |
* | 50 | 52 | |
* `-------------------'
*/
// The first section contains all of the arguments
// The second converts the arguments into a two-dimensional array
#define LAYOUT_ortho_6x4( \ #define LAYOUT_ortho_6x4( \
k00, k01, k02, k03, \ k00, k01, k02, k03, \
k10, k11, k12, k13, \ k10, k11, k12, k13, \
@ -72,6 +60,21 @@
{k50, k51, k52, k53} \ {k50, k51, k52, k53} \
} }
/* COSPAD gamepad matrix layout
* ,-------------------.
* | 00 | 01 | 02 | 03 |
* |----|----|----|----|
* | 10 | 11 | 12 | 13 |
* |----|----|----|----|
* | 20 | 21 | 22 | |
* |----|----|----| 23 |
* | 30 | 31 | 32 | |
* |----|----|----|----|
* | 40 | 41 | 42 | 43 |
* |----|----|----|----|
* | 50 | 51 | 52 | 53 |
* `-------------------'
*/
#define LAYOUT_gamepad_6x4( \ #define LAYOUT_gamepad_6x4( \
k00, k01, k02, k03, \ k00, k01, k02, k03, \
k10, k11, k12, k13, \ k10, k11, k12, k13, \
@ -84,11 +87,26 @@
{k00, k01, k02, k03}, \ {k00, k01, k02, k03}, \
{k10, k11, k12, k13}, \ {k10, k11, k12, k13}, \
{k20, k21, k22, k23}, \ {k20, k21, k22, k23}, \
{k30, k31, k32, KC_NO}, \ {k30, k31, k32, ___}, \
{k40, k41, k42, k43}, \ {k40, k41, k42, k43}, \
{k50, k51, k52, k53} \ {k50, k51, k52, k53} \
} }
/* COSPAD numpad matrix layout
* ,-------------------.
* | 00 | 01 | 02 | 03 |
* |----|----|----|----|
* | 10 | 11 | 12 | 13 |
* |----|----|----|----|
* | 20 | 21 | 22 | |
* |----|----|----| 23 |
* | 30 | 31 | 32 | |
* |----|----|----|----|
* | 40 | 41 | 42 | |
* |----|----|----| 43 |
* | 50 | 52 | |
* `-------------------'
*/
#define LAYOUT_numpad_6x4( \ #define LAYOUT_numpad_6x4( \
k00, k01, k02, k03, \ k00, k01, k02, k03, \
k10, k11, k12, k13, \ k10, k11, k12, k13, \
@ -101,22 +119,12 @@
{k00, k01, k02, k03}, \ {k00, k01, k02, k03}, \
{k10, k11, k12, k13}, \ {k10, k11, k12, k13}, \
{k20, k21, k22, k23}, \ {k20, k21, k22, k23}, \
{k30, k31, k32, KC_NO}, \ {k30, k31, k32, ___}, \
{k40, k41, k42, k43}, \ {k40, k41, k42, k43}, \
{k50, KC_NO, k52, KC_NO} \ {k50, ___, k52, ___} \
} }
void matrix_init_user(void);
void matrix_scan_user(void);
inline void cospad_bl_led_on(void) { PORTF &= ~(1<<7); } // Add backwards compatibility for existing keymaps
inline void cospad_bl_led_off(void) { PORTF |= (1<<7); } #define cospad_bl_led_on backlight_enable
#define cospad_bl_led_off backlight_disable
inline void cospad_bl_led_togg(void) { #define cospad_bl_led_togg backlight_toggle
uint8_t bl_mask = PORTF&(1<<7);
if (bl_mask) {
PORTF &= ~(1<<7);
} else {
PORTF |= (1<<7);
}
}
#endif

View file

@ -7,6 +7,7 @@
"height": 6, "height": 6,
"layouts": { "layouts": {
"LAYOUT_numpad_6x4": { "LAYOUT_numpad_6x4": {
"key_count": 21,
"layout": [ "layout": [
{"label":"Esc", "x":0, "y":0}, {"label":"Esc", "x":0, "y":0},
{"label":"Tab", "x":1, "y":0}, {"label":"Tab", "x":1, "y":0},
@ -33,35 +34,62 @@
}, },
"LAYOUT_gamepad_6x4": { "LAYOUT_gamepad_6x4": {
"key_count": 23,
"layout": [ "layout": [
{"label":"k00", "x":5, "y":0}, {"label":"k00", "x":0, "y":0},
{"label":"k01", "x":5, "y":1}, {"label":"k01", "x":1, "y":0},
{"label":"k02", "x":5, "y":2}, {"label":"k02", "x":2, "y":0},
{"label":"k03", "x":5, "y":3}, {"label":"k03", "x":3, "y":0},
{"label":"k10", "x":4, "y":0}, {"label":"k10", "x":0, "y":1},
{"label":"k11", "x":4, "y":1}, {"label":"k11", "x":1, "y":1},
{"label":"k12", "x":4, "y":2}, {"label":"k12", "x":2, "y":1},
{"label":"k13", "x":4, "y":3}, {"label":"k13", "x":3, "y":1},
{"label":"k20", "x":3, "y":0}, {"label":"k20", "x":0, "y":2},
{"label":"k21", "x":3, "y":1}, {"label":"k21", "x":1, "y":2},
{"label":"k22", "x":3, "y":2}, {"label":"k22", "x":2, "y":2},
{"label":"k30", "x":2, "y":0}, {"label":"k30", "x":0, "y":3},
{"label":"k31", "x":2, "y":1}, {"label":"k31", "x":1, "y":3},
{"label":"k32", "x":2, "y":2}, {"label":"k32", "x":2, "y":3},
{"label":"k23", "x":2, "y":3, "w":2}, {"label":"k23", "x":3, "y":2, "h":2},
{"label":"k40", "x":1, "y":0}, {"label":"k40", "x":0, "y":4},
{"label":"k41", "x":1, "y":1}, {"label":"k41", "x":1, "y":4},
{"label":"k42", "x":1, "y":2}, {"label":"k42", "x":2, "y":4},
{"label":"k43", "x":1, "y":3}, {"label":"k43", "x":3, "y":4},
{"label":"k50", "x":0, "y":0}, {"label":"k50", "x":0, "y":5},
{"label":"k51", "x":0, "y":1}, {"label":"k51", "x":1, "y":5},
{"label":"k52", "x":0, "y":2}, {"label":"k52", "x":2, "y":5},
{"label":"k53", "x":0, "y":3} {"label":"k53", "x":3, "y":5}
] ]
}, },
"LAYOUT_ortho_6x4": { "LAYOUT_ortho_6x4": {
"layout": [{"label":"Esc", "x":0, "y":0}, {"label":"Tab", "x":1, "y":0}, {"label":"Fn", "x":2, "y":0}, {"label":"Back", "x":3, "y":0}, {"label":"Num Lock", "x":0, "y":1}, {"label":"/", "x":1, "y":1}, {"label":"*", "x":2, "y":1}, {"label":"-", "x":3, "y":1}, {"label":"7", "x":0, "y":2}, {"label":"8", "x":1, "y":2}, {"label":"9", "x":2, "y":2}, {"label":"+", "x":3, "y":2}, {"label":"4", "x":0, "y":3}, {"label":"5", "x":1, "y":3}, {"label":"6", "x":2, "y":3}, {"x":3, "y":3}, {"label":"1", "x":0, "y":4}, {"label":"2", "x":1, "y":4}, {"label":"3", "x":2, "y":4}, {"label":"Enter", "x":3, "y":4}, {"label":"0", "x":0, "y":5}, {"x":1, "y":5}, {"label":".", "x":2, "y":5}, {"x":3, "y":5}] "key_count": 24,
"layout": [
{"label":"k00", "x":0, "y":0},
{"label":"k01", "x":1, "y":0},
{"label":"k02", "x":2, "y":0},
{"label":"k03", "x":3, "y":0},
{"label":"k10", "x":0, "y":1},
{"label":"k11", "x":1, "y":1},
{"label":"k12", "x":2, "y":1},
{"label":"k13", "x":3, "y":1},
{"label":"k20", "x":0, "y":2},
{"label":"k21", "x":1, "y":2},
{"label":"k22", "x":2, "y":2},
{"label":"k23", "x":3, "y":2},
{"label":"k30", "x":0, "y":3},
{"label":"k31", "x":1, "y":3},
{"label":"k32", "x":2, "y":3},
{"label":"k33", "x":3, "y":3},
{"label":"k40", "x":0, "y":4},
{"label":"k41", "x":1, "y":4},
{"label":"k42", "x":2, "y":4},
{"label":"k43", "x":3, "y":4},
{"label":"k50", "x":0, "y":5},
{"label":"k51", "x":1, "y":5},
{"label":"k52", "x":2, "y":5},
{"label":"k53", "x":3, "y":5}
]
} }
} }
} }

View file

@ -1,15 +1,16 @@
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
#include "led.h"
// Each layer gets a name for readability, which is then used in the keymap matrix below. // Each layer gets a name for readability, which is then used in the keymap matrix below.
// The underscores don't mean anything - you can have a layer called STUFF or any other name. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
// Layer names don't all need to be of the same length, obviously, and you can also skip them // Layer names don't all need to be of the same length, obviously, and you can also skip them
// entirely and just use numbers. // entirely and just use numbers.
#define _BL 0 enum layers {
#define _FL 1 _BL = 0,
_FL
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap _BL: (Base Layer) Default Layer /* Keymap _BL: (Base Layer) Default Layer
* ,-------------------. * ,-------------------.
* |Esc |TAB | FN | BS | * |Esc |TAB | FN | BS |
* |----|----|----|----| * |----|----|----|----|
@ -24,57 +25,36 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* | 0 | . | | * | 0 | . | |
* `-------------------' * `-------------------'
*/ */
[_BL] = LAYOUT_numpad_6x4(
[_BL] = LAYOUT_numpad_6x4(
KC_ESC, KC_TAB, MO(_FL), KC_BSPC, \ KC_ESC, KC_TAB, MO(_FL), KC_BSPC, \
KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, \ KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, \
KC_P7, KC_P8, KC_P9, \ KC_P7, KC_P8, KC_P9, \
KC_P4, KC_P5, KC_P6, KC_PPLS, \ KC_P4, KC_P5, KC_P6, KC_PPLS, \
KC_P1, KC_P2, KC_P3, \ KC_P1, KC_P2, KC_P3, \
KC_P0, KC_PDOT, KC_PENT), KC_P0, KC_PDOT, KC_PENT
),
/* Keymap _FL: Function Layer /* Keymap _FL: Function Layer
* ,-------------------. * ,-------------------.
* |RGBT|TAB | FN | BS | * |RGBT| | | |
* |----|----|----|----| * |----|----|----|----|
* |RGBM|RGBP|BTOG| - | * |RGBM|RGBP|BTOG| |
* |----|----|----|----| * |----|----|----|----|
* |HUD |HUI |BON | | * |HUD |HUI |BON | |
* |----|----|----| + | * |----|----|----| |
* |SAD |SAI |BOFF| | * |SAD |SAI |BOFF| |
* |----|----|----|----| * |----|----|----|----|
* |VAD |VAS | 3 | | * |VAD |VAS |BSTP| |
* |----|----|----| En | * |----|----|----| |
* | 0 |RST | | * | |RST | |
* `-------------------' * `-------------------'
*/ */
[_FL] = LAYOUT_numpad_6x4( [_FL] = LAYOUT_numpad_6x4(
RGB_TOG, KC_TAB, KC_TRNS, KC_BSPC, \ RGB_TOG, _______, _______, _______, \
RGB_MOD, RGB_M_P, BL_TOGG, KC_PMNS, \ RGB_MOD, RGB_M_P, BL_TOGG, _______, \
RGB_HUD, RGB_HUI, BL_ON, \ RGB_HUD, RGB_HUI, BL_ON, \
RGB_SAD, RGB_SAI, BL_OFF, KC_PPLS, \ RGB_SAD, RGB_SAI, BL_OFF, _______, \
RGB_VAD, RGB_VAI, KC_P3, \ RGB_VAD, RGB_VAI, BL_STEP, \
KC_P0, RESET, KC_PENT), _______, RESET, _______
),
}; };
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case BL_TOGG:
if (record->event.pressed) {
cospad_bl_led_togg();
}
return false;
case BL_ON:
if (record->event.pressed) {
cospad_bl_led_on();
}
return false;
case BL_OFF:
if(record->event.pressed) {
cospad_bl_led_off();
}
return false;
default:
return true;
}
}

View file

@ -1,6 +1,5 @@
# MCU name # MCU name
#MCU = at90usb1287
MCU = atmega32u4 MCU = atmega32u4
# Processor frequency. # Processor frequency.
@ -40,27 +39,43 @@ F_USB = $(F_CPU)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# Bootloader selection
# Teensy halfkay
# Pro Micro caterina
# Atmel DFU atmel-dfu
# LUFA DFU lufa-dfu
# QMK DFU qmk-dfu
# atmega32a bootloadHID
BOOTLOADER = atmel-dfu
# Boot Section Size in *bytes* # Boot Section Size in *bytes*
# Teensy halfKay 512 # Teensy halfKay 512
# Teensy++ halfKay 1024 # Teensy++ halfKay 1024
# Atmel DFU loader 4096 # Atmel DFU loader 4096
# LUFA bootloader 4096 # LUFA bootloader 4096
# USBaspLoader 2048 # USBaspLoader 2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096 # OPT_DEFS += -DBOOTLOADER_SIZE=4096
# Build Options # Build Options
# comment out to disable the options. # comment out to disable the options.
# #
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700) MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450) EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400) CONSOLE_ENABLE = no # Console for debug(+400)
COMMAND_ENABLE = no # Commands for debug and configuration COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
BACKLIGHT_CUSTOM_DRIVER = yes
RGBLIGHT_ENABLE = yes # Enable keyboard underlight functionality (+4870) RGBLIGHT_ENABLE = yes # Enable keyboard underlight functionality (+4870)
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality (+1150) MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = no
UNICODE_ENABLE = no # Unicode UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
LAYOUTS = numpad_6x4 ortho_6x4