Files
qmk_firmware/keyboards/annepro2/keymaps/bla/keymap.c
T
Tomasz bla FortunaandTomasz bla Fortuna f771cb545f Asynchronous, robust serial protocol. (#39)
* bla personal ap2-c18 keymap.

* Bidirectional, asynchronous message-based communication with Shine.

- Requires a matching Shine version.
- Protocol is resiliant to loosing bytes during communication, chips won't lock
  waiting for bytes that aren't coming.
- Chips resynchronize in event of loosing a byte using a AA0D header.

Regressions:
- Key masking/locking doesn't work right now. (did it work before?)
- Not all user keymaps build against it.

* Clang-format + code to ease reducing speed of LED UART.

- Did clang-format --style=file -i on multiple files according to
  coding_conventions_c.md

- Added separate serial speed for IAP boot and Led communication, it's possible
  that reducing this to 9600 helped someone with faulty HW. With this code they
  can do it with simple replacing of a value.

* Main chip can set/clear foreground using a mask mechanism.

- Some preparations for selective colouring.

* Selective mask works - tested on capslock.

- Migrated personal keymaps to new status API.

* Clear the foreground colors to show profile when it's modified.

- Show example of achieving selective caps-lock painting + foreground painting
  for layers.
- annepro2LedMaskSetRow is implemented, but still requires testing.

* Implement the QMK side of led blinking to indicate the command was received.

- This stupidly blinks the key when user presses one of the bluetooth commands
to let the user know that the command was received and forwarded to the BT chip.

- TODO: Row/col key positions are hardcoded and not taken from the keymap.

* Reduce memory footprint.

Applying code review suggestions. Moved msgId to globals - preparing for
transmission without copying payload when no retries are necessary.

Added empty readme.md files - required by QMK lint.

Co-authored-by: Tomasz bla Fortuna <bla@thera.be>
2021-09-12 09:26:38 +02:00

158 lines
8.3 KiB
C

#include <stdint.h>
#include "annepro2.h"
#include "qmk_ap2_led.h"
#include "config.h"
enum anne_pro_layers {
_BASE_LAYER,
_FN1_LY,
_FN2_LY,
};
// Key symbols are based on QMK. Use them to remap your keyboard
/*
* Layer _BASE_LAYER
* ,-----------------------------------------------------------------------------------------.
* | esc | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | Bksp |
* |-----------------------------------------------------------------------------------------+
* | Tab | q | w | e | r | t | y | u | i | o | p | [ | ] | \ |
* |-----------------------------------------------------------------------------------------+
* | Ctrl/Bks| a | s | d | f | g | h | j | k | l | ; | ' | Enter |
* |-----------------------------------------------------------------------------------------+
* | Shift | z | x | c | v | b | n | m | , | . | / | Shift |
* |-----------------------------------------------------------------------------------------+
* | Ctrl | L1 | Alt | space | Alt | FN1 | FN2 | Ctrl |
* \-----------------------------------------------------------------------------------------/
* Layer TAP in _BASE_LAYER
* ,-----------------------------------------------------------------------------------------.
* | | | | | | | | | | | | | | |
* |-----------------------------------------------------------------------------------------+
* | | | | | | | | | | | | | | |
* |-----------------------------------------------------------------------------------------+
* | Bksp | | | | | | | | | | | | |
* |-----------------------------------------------------------------------------------------+
* | | | | | | | | | | | | UP |
* |-----------------------------------------------------------------------------------------+
* | | `~ | | | | LEFT | DOWN | RIGHT |
* \-----------------------------------------------------------------------------------------/
*/
const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_BASE_LAYER] = KEYMAP( /* Base */
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
MT(MOD_LCTL, KC_ESC), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, RSFT_T(KC_UP),
KC_LCTL, MT(MOD_LGUI, KC_GRV), KC_LALT, KC_SPC, KC_RALT, LT(_FN1_LY,KC_LEFT), LT(_FN2_LY,KC_DOWN), RCTL_T(KC_RGHT)
),
/*
* Layer _FN1_LY
* ,-----------------------------------------------------------------------------------------.
* | ` | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 | MEDIA PLAY|
* |-----------------------------------------------------------------------------------------+
* | Tab | q | UP | e | 7 | 8 | 9 | u | i | o | PS | HOME | END | \ |
* |-----------------------------------------------------------------------------------------+
* | |LEFT |DOWN |RIGHT| 4 | 5 | 6 | j | k | l | PGUP|PGDN | Enter |
* |-----------------------------------------------------------------------------------------+
* | LayerHold? |V-UP |V-DWN|MUTE | 1 | 2 | 3 | m | , |INSRT| DEL | Shift |
* |-----------------------------------------------------------------------------------------+
* | Ctrl | L1 | Alt | 0 | Alt | FN1 | FN2 | Ctrl |
* \-----------------------------------------------------------------------------------------/
*
*/
[_FN1_LY] = KEYMAP( /* Base */
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_MEDIA_PLAY_PAUSE,
KC_TRNS, KC_TRNS, KC_UP, KC_TRNS, KC_7, KC_8, KC_9, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_HOME, KC_END, KC_TRNS,
MO(_FN2_LY), KC_LEFT, KC_DOWN, KC_RGHT, KC_4, KC_5, KC_6, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_PGDN, KC_TRNS,
KC_TRNS, KC_VOLU, KC_VOLD, KC_MUTE, KC_1, KC_2, KC_3, KC_TRNS, KC_TRNS, KC_INS, KC_DEL, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_0, KC_TRNS, KC_TRNS, MO(_FN2_LY), KC_TRNS
),
/*
* Layer _FN2_LY
* ,-----------------------------------------------------------------------------------------.
* | ~ | BT1 | BT2 | BT3 | BT4 | F5 | F6 | F7 |LEDOF|LEDON| F10 | F11 | F12 | MEDIA PLAY|
* |-----------------------------------------------------------------------------------------+
* | Tab | q | UP | e | r | t | y | u | i | o | PS | HOME | END | \ |
* |-----------------------------------------------------------------------------------------+
* | Esc |LEFT |DOWN |RIGHT| f | g | h | j | k | l | PGUP|PGDN | Enter |
* |-----------------------------------------------------------------------------------------+
* | Shift | z | x | c | v | b | n | m | , |INSRT| DEL | Shift |
* |-----------------------------------------------------------------------------------------+
* | Ctrl | L1 | Alt | space | Alt | FN1 | FN2 | Ctrl |
* \-----------------------------------------------------------------------------------------/
*
*/
[_FN2_LY] = KEYMAP( /* Base */
KC_TRNS, KC_AP2_BT1, KC_AP2_BT2, KC_AP2_BT3, KC_AP2_BT4, KC_TRNS, KC_TRNS, KC_TRNS, KC_AP_LED_OFF, KC_AP_LED_ON, KC_AP_LED_NEXT_INTENSITY, KC_AP_LED_SPEED, KC_TRNS, KC_MEDIA_PLAY_PAUSE,
MO(_FN2_LY), KC_TRNS, KC_UP, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PSCR, KC_HOME, KC_END, KC_TRNS,
KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_PGUP, KC_PGDN, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_INS, KC_DEL, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, MO(_FN1_LY), MO(_FN2_LY), KC_TRNS
),
};
const uint16_t keymaps_size = sizeof(keymaps);
void matrix_init_user(void) {
}
void matrix_scan_user(void) {
}
// Code to run after initializing the keyboard
void keyboard_post_init_user(void) {
// Here are two common functions that you can use. For more LED functions, refer to the file "qmk_ap2_led.h"
// annepro2-shine disables LEDs by default. Uncomment this function to enable them at startup.
// annepro2LedEnable();
// Additionally, it also chooses the first LED profile by default. Refer to the "profiles" array in main.c in
// annepro2-shine to see the order. Replace "i" with the index of your preferred profile. (i.e the RED profile is index 0)
// annepro2LedSetProfile(i);
debug_enable=true;
}
layer_state_t layer_state_set_user(layer_state_t layer) {
switch(get_highest_layer(layer)) {
case _FN1_LY:
// Set the leds to green
annepro2LedSetForegroundColor(0x00, 0xFF, 0x00);
break;
case _FN2_LY:
// Set the leds to blue
annepro2LedSetForegroundColor(0x00, 0x00, 0xFF);
break;
default:
// Reset back to the current profile
annepro2LedResetForegroundColor();
break;
}
return layer;
}
// The function to handle the caps lock logic. It's executed after caps or layer
// changes state, after layer_state_set_user.
bool led_update_user(led_t leds) {
if (leds.caps_lock) {
const annepro2Led_t color = {
.p.red = 0xff,
.p.green = 0x00,
.p.blue = 0x00,
.p.alpha = 0xff
};
annepro2LedMaskSetKey(2, 0, color);
return true;
}
if(!layer_state_is(_FN1_LY) && !layer_state_is(_FN2_LY)) {
const annepro2Led_t color = {
.p.red = 0xff,
.p.green = 0x00,
.p.blue = 0x00,
.p.alpha = 0x00
};
annepro2LedMaskSetKey(2, 0, color);
}
return true;
}