[Keyboard] LFKPad refactor (#8079)

This commit is contained in:
fauxpark 2020-02-05 13:41:19 +11:00 committed by GitHub
parent 74e3cad728
commit efe8bd8e92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 241 additions and 171 deletions

View file

@ -15,31 +15,56 @@ 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"
/* USB Device descriptor parameter */
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6060
#define DEVICE_VER 0x0001
#define MANUFACTURER LFKeyboards
#define PRODUCT LFKPad 21
#define DESCRIPTION QMK keyboard firmware for LFKPad LFK_REV_STRING
#define DESCRIPTION QMK keyboard firmware for LFKPad
#define DIODE_DIRECTION COL2ROW
/* key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 4
#define MATRIX_ROW_PINS { D5, F4, F6, F7, C7, C6}
#define MATRIX_COL_PINS { F1, F0, D4, D6}
#define UNUSED_PINS { }
#define RGBLED_NUM 28 // Number of LEDs
/*
* 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 { D5, F4, F6, F7, C7, C6 }
#define MATRIX_COL_PINS { F1, F0, D4, D6 }
#define UNUSED_PINS
/* COL2ROW, ROW2COL*/
#define DIODE_DIRECTION COL2ROW
/*
* Split Keyboard specific options, make sure you have 'SPLIT_KEYBOARD = yes' in your rules.mk, and define SOFT_SERIAL_PIN.
*/
//#define SOFT_SERIAL_PIN D0 // or D1, D2, D3, E6
// #define BACKLIGHT_PIN B7
// #define BACKLIGHT_BREATHING
// #define BACKLIGHT_LEVELS 3
#define RGB_DI_PIN C7 // Have to set it to something to get the ws2812 code to compile
#define RGBLIGHT_ANIMATIONS
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_VAL_STEP 17
#ifdef RGB_DI_PIN
# define RGBLED_NUM 28
# define RGBLIGHT_HUE_STEP 10
# define RGBLIGHT_SAT_STEP 17
# define RGBLIGHT_VAL_STEP 17
# define RGBLIGHT_ANIMATIONS
#endif
#define TAPPING_TERM 200
@ -49,13 +74,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* define if matrix has ghost (lacks anti-ghosting diodes) */
//#define MATRIX_HAS_GHOST
/* number of backlight levels */
/* 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
/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
* This is userful for the Windows task manager shortcut (ctrl+shift+esc).
*/
// #define GRAVE_ESC_CTRL_OVERRIDE
/*
* Force NKRO
*
@ -89,6 +117,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* key combination for magic key command */
/* defined by default; to change, uncomment and set to the combination you want */
// #define IS_COMMAND() (get_mods() == MOD_MASK_SHIFT)
/* control how magic key switches layers */
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true
@ -98,8 +130,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
//#define MAGIC_KEY_HELP1 H
//#define MAGIC_KEY_HELP2 SLASH
//#define MAGIC_KEY_HELP H
//#define MAGIC_KEY_HELP_ALT SLASH
//#define MAGIC_KEY_DEBUG D
//#define MAGIC_KEY_DEBUG_MATRIX X
//#define MAGIC_KEY_DEBUG_KBD K
@ -107,9 +139,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define MAGIC_KEY_VERSION V
//#define MAGIC_KEY_STATUS S
//#define MAGIC_KEY_CONSOLE C
//#define MAGIC_KEY_LAYER0_ALT1 ESC
//#define MAGIC_KEY_LAYER0_ALT2 GRAVE
//#define MAGIC_KEY_LAYER0 0
//#define MAGIC_KEY_LAYER0_ALT GRAVE
//#define MAGIC_KEY_LAYER1 1
//#define MAGIC_KEY_LAYER2 2
//#define MAGIC_KEY_LAYER3 3
@ -119,9 +150,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define MAGIC_KEY_LAYER7 7
//#define MAGIC_KEY_LAYER8 8
//#define MAGIC_KEY_LAYER9 9
//#define MAGIC_KEY_BOOTLOADER PAUSE
//#define MAGIC_KEY_BOOTLOADER B
//#define MAGIC_KEY_BOOTLOADER_ALT ESC
//#define MAGIC_KEY_LOCK CAPS
//#define MAGIC_KEY_EEPROM E
//#define MAGIC_KEY_EEPROM_CLEAR BSPACE
//#define MAGIC_KEY_NKRO N
//#define MAGIC_KEY_SLEEP_LED Z
@ -140,7 +173,63 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
/* disable these deprecated features by default */
#ifndef LINK_TIME_OPTIMIZATION_ENABLE
#define NO_ACTION_MACRO
#define NO_ACTION_FUNCTION
#endif
/*
* MIDI options
*/
/* Prevent use of disabled MIDI features in the keymap */
//#define MIDI_ENABLE_STRICT 1
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
//#define MIDI_BASIC
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
- Octave shift and transpose
- Virtual sustain, portamento, and modulation wheel
- etc.
*/
//#define MIDI_ADVANCED
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
//#define MIDI_TONE_KEYCODE_OCTAVES 1
/*
* HD44780 LCD Display Configuration
*/
/*
#define LCD_LINES 2 //< number of visible lines of the display
#define LCD_DISP_LENGTH 16 //< visibles characters per line of the display
#define LCD_IO_MODE 1 //< 0: memory mapped mode, 1: IO port mode
#if LCD_IO_MODE
#define LCD_PORT PORTB //< port for the LCD lines
#define LCD_DATA0_PORT LCD_PORT //< port for 4bit data bit 0
#define LCD_DATA1_PORT LCD_PORT //< port for 4bit data bit 1
#define LCD_DATA2_PORT LCD_PORT //< port for 4bit data bit 2
#define LCD_DATA3_PORT LCD_PORT //< port for 4bit data bit 3
#define LCD_DATA0_PIN 4 //< pin for 4bit data bit 0
#define LCD_DATA1_PIN 5 //< pin for 4bit data bit 1
#define LCD_DATA2_PIN 6 //< pin for 4bit data bit 2
#define LCD_DATA3_PIN 7 //< pin for 4bit data bit 3
#define LCD_RS_PORT LCD_PORT //< port for RS line
#define LCD_RS_PIN 3 //< pin for RS line
#define LCD_RW_PORT LCD_PORT //< port for RW line
#define LCD_RW_PIN 2 //< pin for RW line
#define LCD_E_PORT LCD_PORT //< port for Enable line
#define LCD_E_PIN 1 //< pin for Enable line
#endif
*/
/* Bootmagic Lite key configuration */
// #define BOOTMAGIC_LITE_ROW 0
// #define BOOTMAGIC_LITE_COLUMN 0

View file

@ -6,7 +6,29 @@
"height": 6,
"layouts": {
"LAYOUT_numpad_6x4": {
"layout": [{"label":"Esc", "x":0, "y":0}, {"label":"Tab", "x":1, "y":0}, {"label":"=", "x":2, "y":0}, {"label":"Fn", "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":"4", "x":0, "y":3}, {"label":"5", "x":1, "y":3}, {"label":"6", "x":2, "y":3}, {"label":"+", "x":3, "y":2, "h":2}, {"label":"1", "x":0, "y":4}, {"label":"2", "x":1, "y":4}, {"label":"3", "x":2, "y":4}, {"label":"0", "x":0, "y":5, "w":2}, {"label":".", "x":2, "y":5}, {"label":"Enter", "x":3, "y":4, "h":2}]
"layout": [
{"x":0, "y":0},
{"x":1, "y":0},
{"x":2, "y":0},
{"x":3, "y":0},
{"x":0, "y":1},
{"x":1, "y":1},
{"x":2, "y":1},
{"x":3, "y":1},
{"x":0, "y":2},
{"x":1, "y":2},
{"x":2, "y":2},
{"x":0, "y":3},
{"x":1, "y":3},
{"x":2, "y":3},
{"x":3, "y":2, "h":2},
{"x":0, "y":4},
{"x":1, "y":4},
{"x":2, "y":4},
{"x":0, "y":5, "w":2},
{"x":2, "y":5},
{"x":3, "y":4, "h":2}
]
}
}
}

View file

@ -1,3 +0,0 @@
#pragma once
// place overrides here

View file

@ -1,41 +1,31 @@
#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT_numpad_6x4( /* Base */
KC_ESC, KC_TAB, KC_PEQL, MO(1), \
KC_LNUM, 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 \
/* Base */
[0] = LAYOUT_numpad_6x4(
KC_ESC, KC_TAB, KC_PEQL, MO(1),
KC_LNUM, 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
),
[1] = LAYOUT_numpad_6x4( /* RGB */
RGB_SAI, RGB_VAI, RGB_HUI, _______, \
RGB_SAD, RGB_VAD, RGB_HUD, _______, \
RGB_M_X, RGB_M_G, RGB_MOD, \
RGB_M_SW, RGB_M_SN, RGB_M_K, RGB_RMOD, \
RGB_M_P, RGB_M_B, RGB_M_R, \
XXXXXXX, XXXXXXX, RGB_TOG \
),
/* RGB */
[1] = LAYOUT_numpad_6x4(
RGB_SAI, RGB_VAI, RGB_HUI, _______,
RGB_SAD, RGB_VAD, RGB_HUD, _______,
RGB_M_X, RGB_M_G, RGB_MOD,
RGB_M_SW,RGB_M_SN,RGB_M_K, RGB_RMOD,
RGB_M_P, RGB_M_B, RGB_M_R,
XXXXXXX, XXXXXXX, RGB_TOG
)
};
void matrix_init_user(void) {
// This keymap only has a single base layer, so reset the default if needed
if(eeconfig_read_default_layer() > 1){
if (eeconfig_read_default_layer() > 1) {
eeconfig_update_default_layer(1);
default_layer_set(1);
}
}
void matrix_scan_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
void led_set_user(uint8_t usb_led) {
}

View file

@ -1 +1 @@
# The default keymap LFKPad 21
# The default keymap for the LFKPad 21

View file

@ -1,112 +1,117 @@
#include <avr/sfr_defs.h>
#include "lfkpad.h"
#include "quantum.h"
#include <avr/timer_avr.h>
#include <avr/wdt.h>
#include "lfkpad.h"
#include "keymap.h"
#include "issi.h"
#include "TWIlib.h"
#include "lighting.h"
#include "debug.h"
#include "quantum.h"
uint16_t click_hz = CLICK_HZ;
uint16_t click_time = CLICK_MS;
uint8_t click_toggle = CLICK_ENABLED;
void matrix_init_kb(void)
{
void matrix_init_kb(void) {
matrix_init_user();
#ifndef AUDIO_ENABLE
// If we're not using the audio pin, drive it low
sbi(DDRC, 6);
cbi(PORTC, 6);
setPinOutput(C6);
writePinLow(C6);
#endif
#ifdef ISSI_ENABLE
issi_init();
#endif
#ifdef WATCHDOG_ENABLE
// This is done after turning the layer LED red, if we're caught in a loop
// we should get a flashing red light
wdt_enable(WDTO_500MS);
#endif
}
void matrix_scan_kb(void)
{
void matrix_scan_kb(void) {
#ifdef WATCHDOG_ENABLE
wdt_reset();
#endif
#ifdef ISSI_ENABLE
// switch/underglow lighting update
static uint32_t issi_device = 0;
static uint32_t twi_last_ready = 0;
if(twi_last_ready > 1000){
// Its been way too long since the last ISSI update, reset the I2C bus and start again
if (twi_last_ready > 1000) {
// It's been way too long since the last ISSI update, reset the I2C bus and start again
dprintf("TWI failed to recover, TWI re-init\n");
twi_last_ready = 0;
TWIInit();
force_issi_refresh();
}
if(isTWIReady()){
if (isTWIReady()) {
twi_last_ready = 0;
// If the i2c bus is available, kick off the issi update, alternate between devices
update_issi(issi_device, issi_device);
if(issi_device){
if (issi_device) {
issi_device = 0;
}else{
} else {
issi_device = 3;
}
}else{
} else {
twi_last_ready++;
}
#endif
matrix_scan_user();
}
void click(uint16_t freq, uint16_t duration){
void click(uint16_t freq, uint16_t duration) {
#ifdef AUDIO_ENABLE
if(freq >= 100 && freq <= 20000 && duration < 100){
if (freq >= 100 && freq <= 20000 && duration < 100) {
play_note(freq, 10);
for (uint16_t i = 0; i < duration; i++){
for (uint16_t i = 0; i < duration; i++) {
_delay_ms(1);
}
stop_all_notes();
}
#endif
}
bool process_record_kb(uint16_t keycode, keyrecord_t* record)
{
if (click_toggle && record->event.pressed){
bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
if (click_toggle && record->event.pressed) {
click(click_hz, click_time);
}
if (keycode == RESET) {
reset_keyboard_kb();
} else {
}
return process_record_user(keycode, record);
}
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
{
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt) {
#ifdef AUDIO_ENABLE
int8_t sign = 1;
#endif
if(id == LFK_ESC_TILDE){
if (id == LFK_ESC_TILDE) {
// Send ~ on shift-esc
void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key;
uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
if(layer_state == 0){
uint8_t shifted = get_mods() & MOD_MASK_SHIFT;
if (layer_state == 0) {
method(shifted ? KC_GRAVE : KC_ESCAPE);
}else{
} else {
method(shifted ? KC_ESCAPE : KC_GRAVE);
}
send_keyboard_report();
}else if(event->event.pressed){
switch(id){
} else if (event->event.pressed) {
switch (id) {
case LFK_SET_DEFAULT_LAYER:
// set/save the current base layer to eeprom, falls through to LFK_CLEAR
eeconfig_update_default_layer(1UL << opt);
@ -123,11 +128,11 @@ void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
click(click_hz, click_time);
break;
case LFK_CLICK_TOGGLE:
if(click_toggle){
if (click_toggle) {
click_toggle = 0;
click(4000, 100);
click(1000, 100);
}else{
} else {
click_toggle = 1;
click(1000, 100);
click(4000, 100);
@ -144,22 +149,18 @@ void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
}
}
void reset_keyboard_kb(){
void reset_keyboard_kb() {
#ifdef WATCHDOG_ENABLE
MCUSR = 0;
wdt_disable();
wdt_reset();
#endif
reset_keyboard();
}
void led_set_kb(uint8_t usb_led)
{
led_set_user(usb_led);
}
// LFK lighting info
const uint8_t rgb_matrices[] = {0, 1};
const uint8_t rgb_matrices[] = { 0, 1 };
const uint8_t rgb_sequence[] = {
32, 1, 2, 3,
31, 30, 5, 6,
@ -172,5 +173,4 @@ const uint8_t rgb_sequence[] = {
4, 25,
13, 24,
20
};

View file

@ -1,23 +1,6 @@
#ifndef LFKPAD_H
#define LFKPAD_H
/* if the kb.h file exists (because we're running from qmkbuilder) include it */
#if __has_include("kb.h")
#include "kb.h"
#endif
#pragma once
#include "quantum.h"
#include "matrix.h"
#include <avr/sfr_defs.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
typedef struct RGB_Color {
uint16_t red;
@ -57,7 +40,6 @@ void click(uint16_t freq, uint16_t duration);
// readability
#define ___ KC_NO
#define LAYOUT_numpad_6x4( \
k00, k01, k02, k03, \
k10, k11, k12, k13, \
@ -73,5 +55,3 @@ void click(uint16_t freq, uint16_t duration);
{ k40, k41, k42, k43 }, \
{ k50, ___, k52, ___ } \
}
#endif //LFKPAD_H

View file

@ -1,28 +1,15 @@
bluepad keyboard firmware
======================
# LFKPad
## Quantum MK Firmware
![LFKPad](https://cdn11.bigcommerce.com/s-dvx2zpcx7r/images/stencil/500x659/products/118/385/img_0256__06462.1546304848.jpg)
For the full Quantum feature list, see [the parent readme.md](/docs/README.md).
Hotswap 21-key numpad PCB with USB-C, per-key RGB and underglow.
## Building
* Keyboard Maintainer: QMK community
* Hardware Supported: LFKPad HS21 PCB
* Hardware Availability: [LFKeyboards](https://www.lfkeyboards.com/lfkpad/)
Download or clone the whole firmware and navigate to the keyboards/bluepad folder. Once your dev env is setup, you'll be able to type `make` to generate your .hex - you can then use the Teensy Loader to program your .hex file.
Make example for this keyboard (after setting up your build environment):
Depending on which keymap you would like to use, you will have to compile slightly differently.
make lfkeyboards/lfkpad:default
### Default
To build with the default keymap, simply run `make`.
### Other Keymaps
Several version of keymap are available in advance but you are recommended to define your favorite layout yourself. To define your own keymap create a folder with the name of your keymap in the keymaps folder, and see keymap documentation (you can find in top readme.md) and existant keymap files.
To build the firmware binary hex file with a keymap just do `make` with `keymap` option like:
```
$ make keymap=[default|jack|<name>]
```
Keymaps follow the format **__keymap.c__** and are stored in folders in the `keymaps` folder, eg `keymaps/my_keymap/`
See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).

View file

@ -11,26 +11,29 @@ MCU = atmega32u4
# ATmega328P USBasp
BOOTLOADER = atmel-dfu
LAYOUTS = numpad_6x4
# Build Options
# change yes to no to disable
#
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration
MOUSEKEY_ENABLE = no # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
CONSOLE_ENABLE = no # Console for debug
COMMAND_ENABLE = no # Commands for debug and configuration
NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = no # Audio output on port C6
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = yes # Enable WS2812 RGB underlight.
RGBLIGHT_CUSTOM_DRIVER = yes # RGB code is implemented in lefkeyboards, not qmk base
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
TAP_DANCE_ENABLE = no
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
NKRO_ENABLE = no # USB Nkey Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
RGBLIGHT_CUSTOM_DRIVER = yes # RGB code is implemented in lefkeyboards, not qmk base
MIDI_ENABLE = no # MIDI support
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
ISSI_ENABLE = yes # If the I2C pullup resistors aren't install this must be disabled
WATCHDOG_ENABLE = no # Resets keyboard if matrix_scan isn't run every 250ms
ISSI_ENABLE = yes # If the I2C pullup resistors aren't installed this must be disabled
WATCHDOG_ENABLE = no # Resets keyboard if matrix_scan() isn't run every 250ms
SRC = TWIlib.c issi.c lighting.c
@ -41,3 +44,5 @@ endif
ifeq ($(strip $(WATCHDOG_ENABLE)), yes)
TMK_COMMON_DEFS += -DWATCHDOG_ENABLE
endif
LAYOUTS = numpad_6x4