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/>.
*/
#ifndef CONFIG_H
#define CONFIG_H
#pragma once
#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_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_COL_PINS { F0, F1, E6, C7 }
#define UNUSED_PINS
#define BACKLIGHT_PIN F7
/* COL2ROW or ROW2COL */
#define DIODE_DIRECTION COL2ROW
/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST
/* Backlight configuration */
#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 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 */
//#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#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
* 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_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 "led.h"
extern inline void cospad_bl_led_on(void);
extern inline void cospad_bl_led_off(void);
extern inline void cospad_bl_led_togg(void);
#ifdef BACKLIGHT_ENABLE
void matrix_init_kb(void) {
// put your keyboard start-up code here
// 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 backlight_init_ports(void) {
setPinOutput(F7);
}
void led_set_kb(uint8_t usb_led) {
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
// Turn numlock on
PORTB &= ~(1<<2);
} else {
// Turn numlock off
PORTB |= (1<<2);
}
void backlight_set(uint8_t level) {
writePin(F7, !!level);
}
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"
#define ___ KC_NO
// readability
#define XXX KC_NO
/* This a shortcut to help you visually see your layout.
*
* 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
* ,-------------------.
@ -21,40 +43,6 @@
* | 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( \
k00, k01, k02, k03, \
k10, k11, k12, k13, \
@ -72,6 +60,21 @@
{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( \
k00, k01, k02, k03, \
k10, k11, k12, k13, \
@ -84,11 +87,26 @@
{k00, k01, k02, k03}, \
{k10, k11, k12, k13}, \
{k20, k21, k22, k23}, \
{k30, k31, k32, KC_NO}, \
{k30, k31, k32, ___}, \
{k40, k41, k42, k43}, \
{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( \
k00, k01, k02, k03, \
k10, k11, k12, k13, \
@ -98,25 +116,15 @@
k50, k52, k43 \
) \
{ \
{k00, k01, k02, k03}, \
{k10, k11, k12, k13}, \
{k20, k21, k22, k23}, \
{k30, k31, k32, KC_NO}, \
{k40, k41, k42, k43}, \
{k50, KC_NO, k52, KC_NO} \
{k00, k01, k02, k03}, \
{k10, k11, k12, k13}, \
{k20, k21, k22, k23}, \
{k30, k31, k32, ___}, \
{k40, k41, k42, k43}, \
{k50, ___, k52, ___} \
}
void matrix_init_user(void);
void matrix_scan_user(void);
inline void cospad_bl_led_on(void) { PORTF &= ~(1<<7); }
inline void cospad_bl_led_off(void) { PORTF |= (1<<7); }
inline void cospad_bl_led_togg(void) {
uint8_t bl_mask = PORTF&(1<<7);
if (bl_mask) {
PORTF &= ~(1<<7);
} else {
PORTF |= (1<<7);
}
}
#endif
// Add backwards compatibility for existing keymaps
#define cospad_bl_led_on backlight_enable
#define cospad_bl_led_off backlight_disable
#define cospad_bl_led_togg backlight_toggle

View File

@ -7,6 +7,7 @@
"height": 6,
"layouts": {
"LAYOUT_numpad_6x4": {
"key_count": 21,
"layout": [
{"label":"Esc", "x":0, "y":0},
{"label":"Tab", "x":1, "y":0},
@ -33,35 +34,62 @@
},
"LAYOUT_gamepad_6x4": {
"key_count": 23,
"layout": [
{"label":"k00", "x":5, "y":0},
{"label":"k01", "x":5, "y":1},
{"label":"k02", "x":5, "y":2},
{"label":"k03", "x":5, "y":3},
{"label":"k10", "x":4, "y":0},
{"label":"k11", "x":4, "y":1},
{"label":"k12", "x":4, "y":2},
{"label":"k13", "x":4, "y":3},
{"label":"k20", "x":3, "y":0},
{"label":"k21", "x":3, "y":1},
{"label":"k22", "x":3, "y":2},
{"label":"k30", "x":2, "y":0},
{"label":"k31", "x":2, "y":1},
{"label":"k32", "x":2, "y":2},
{"label":"k23", "x":2, "y":3, "w":2},
{"label":"k40", "x":1, "y":0},
{"label":"k41", "x":1, "y":1},
{"label":"k42", "x":1, "y":2},
{"label":"k43", "x":1, "y":3},
{"label":"k50", "x":0, "y":0},
{"label":"k51", "x":0, "y":1},
{"label":"k52", "x":0, "y":2},
{"label":"k53", "x":0, "y":3}
{"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":"k30", "x":0, "y":3},
{"label":"k31", "x":1, "y":3},
{"label":"k32", "x":2, "y":3},
{"label":"k23", "x":3, "y":2, "h":2},
{"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}
]
},
"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,80 +1,60 @@
#include QMK_KEYBOARD_H
#include "led.h"
// 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.
// Layer names don't all need to be of the same length, obviously, and you can also skip them
// entirely and just use numbers.
#define _BL 0
#define _FL 1
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap _BL: (Base Layer) Default Layer
* ,-------------------.
* |Esc |TAB | FN | BS |
* |----|----|----|----|
* | NL | / | * | - |
* |----|----|----|----|
* | 7 | 8 | 9 | |
* |----|----|----| + |
* | 4 | 5 | 6 | |
* |----|----|----|----|
* | 1 | 2 | 3 | |
* |----|----|----| En |
* | 0 | . | |
* `-------------------'
*/
[_BL] = LAYOUT_numpad_6x4(
KC_ESC, KC_TAB, MO(_FL), KC_BSPC, \
KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, \
KC_P7, KC_P8, KC_P9, \
KC_P4, KC_P5, KC_P6, KC_PPLS, \
KC_P1, KC_P2, KC_P3, \
KC_P0, KC_PDOT, KC_PENT),
/* Keymap _FL: Function Layer
* ,-------------------.
* |RGBT|TAB | FN | BS |
* |----|----|----|----|
* |RGBM|RGBP|BTOG| - |
* |----|----|----|----|
* |HUD |HUI |BON | |
* |----|----|----| + |
* |SAD |SAI |BOFF| |
* |----|----|----|----|
* |VAD |VAS | 3 | |
* |----|----|----| En |
* | 0 |RST | |
* `-------------------'
*/
[_FL] = LAYOUT_numpad_6x4(
RGB_TOG, KC_TAB, KC_TRNS, KC_BSPC, \
RGB_MOD, RGB_M_P, BL_TOGG, KC_PMNS, \
RGB_HUD, RGB_HUI, BL_ON, \
RGB_SAD, RGB_SAI, BL_OFF, KC_PPLS, \
RGB_VAD, RGB_VAI, KC_P3, \
KC_P0, RESET, KC_PENT),
enum layers {
_BL = 0,
_FL
};
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;
}
}
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Keymap _BL: (Base Layer) Default Layer
* ,-------------------.
* |Esc |TAB | FN | BS |
* |----|----|----|----|
* | NL | / | * | - |
* |----|----|----|----|
* | 7 | 8 | 9 | |
* |----|----|----| + |
* | 4 | 5 | 6 | |
* |----|----|----|----|
* | 1 | 2 | 3 | |
* |----|----|----| En |
* | 0 | . | |
* `-------------------'
*/
[_BL] = LAYOUT_numpad_6x4(
KC_ESC, KC_TAB, MO(_FL), KC_BSPC, \
KC_NLCK, KC_PSLS, KC_PAST, KC_PMNS, \
KC_P7, KC_P8, KC_P9, \
KC_P4, KC_P5, KC_P6, KC_PPLS, \
KC_P1, KC_P2, KC_P3, \
KC_P0, KC_PDOT, KC_PENT
),
/* Keymap _FL: Function Layer
* ,-------------------.
* |RGBT| | | |
* |----|----|----|----|
* |RGBM|RGBP|BTOG| |
* |----|----|----|----|
* |HUD |HUI |BON | |
* |----|----|----| |
* |SAD |SAI |BOFF| |
* |----|----|----|----|
* |VAD |VAS |BSTP| |
* |----|----|----| |
* | |RST | |
* `-------------------'
*/
[_FL] = LAYOUT_numpad_6x4(
RGB_TOG, _______, _______, _______, \
RGB_MOD, RGB_M_P, BL_TOGG, _______, \
RGB_HUD, RGB_HUI, BL_ON, \
RGB_SAD, RGB_SAI, BL_OFF, _______, \
RGB_VAD, RGB_VAI, BL_STEP, \
_______, RESET, _______
),
};

View File

@ -1,6 +1,5 @@
# MCU name
#MCU = at90usb1287
MCU = atmega32u4
# Processor frequency.
@ -40,27 +39,43 @@ F_USB = $(F_CPU)
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*
# Teensy halfKay 512
# Teensy++ halfKay 1024
# Atmel DFU loader 4096
# LUFA bootloader 4096
# USBaspLoader 2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096
# OPT_DEFS += -DBOOTLOADER_SIZE=4096
# Build Options
# comment out to disable the options.
#
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400)
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
RGBLIGHT_ENABLE = yes # Enable keyboard underlight functionality (+4870)
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality (+1150)
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = no
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400)
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
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
BACKLIGHT_CUSTOM_DRIVER = yes
RGBLIGHT_ENABLE = yes # Enable keyboard underlight functionality (+4870)
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE = no # Unicode
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