Compare commits

...

2 Commits

Author SHA1 Message Date
Mark 417abd2697
Removed extra code 2022-07-21 14:10:07 -07:00
Mark c5003d5104
Added HID layer state and keymap.
Closes #3
2022-07-21 14:09:50 -07:00
17 changed files with 141 additions and 18 deletions

View File

@ -476,6 +476,14 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
return process_record_user(keycode, record); return process_record_user(keycode, record);
} }
uint32_t layer_state_set_kb(uint32_t state) {
//uint8_t layer = biton32(state);
hid_send_state(
.state = state
);
return layer_state_set_user(state);
};
// EEPROM is getting reset! // EEPROM is getting reset!
void eeconfig_init_kb(void) { void eeconfig_init_kb(void) {

View File

@ -126,15 +126,6 @@
// turn off effects when suspended // turn off effects when suspended
#define RGB_DISABLE_WHEN_USB_SUSPENDED true #define RGB_DISABLE_WHEN_USB_SUSPENDED true
// Misc
/* key combination for command */
#define IS_COMMAND() ( \
get_mods() == (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL)) || \
get_mods() == (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)) \
)
// Not sure what this does. // Not sure what this does.
// ZSA says: "fixes space cadet rollover issue" // ZSA says: "fixes space cadet rollover issue"
#define DISABLE_SPACE_CADET_ROLLOVER #define DISABLE_SPACE_CADET_ROLLOVER

View File

@ -2,6 +2,7 @@
#include "layers/layers.h" #include "layers/layers.h"
#include "spellcheck.h" #include "spellcheck.h"
#include "rawhid.h"
// Values that should not be saved to git. // Values that should not be saved to git.
// Create a `secrets.h` in the keymap directory. // Create a `secrets.h` in the keymap directory.
@ -37,6 +38,14 @@ void matrix_scan_user(void) {
} }
uint32_t layer_state_set_user(uint32_t state) {
set_layer_colors(state);
//uint8_t layer = biton32(state);
return state;
};
// Return FALSE to halt key processing, // Return FALSE to halt key processing,
// Return TRUE to allow QMK to handle keypress. // Return TRUE to allow QMK to handle keypress.

View File

@ -22,8 +22,16 @@ extern rgb_config_t rgb_matrix_config;
#define LC_RU_G LC_HSV(153, 255, 153) #define LC_RU_G LC_HSV(153, 255, 153)
#define LC_RU_K LC_HSV( 0, 255, 145) #define LC_RU_K LC_HSV( 0, 255, 145)
// Language keymap ids for layers.
// See layers/definitions/symbols.h.
enum layer_layout_ids {
LAYOUT_NULL, // This layer doesn't care what keymap the OS is using
LAYOUT_EN, // This layer is designed for the standard keymapping
LAYOUT_RU,
};
// Define custom keys // Define custom keys
// (Must be done BEFORE keymaps) // (Must be done before keymaps are loaded)
enum custom_keycodes { enum custom_keycodes {
M_SHUTDOWN = BETA_SAFE_RANGE, M_SHUTDOWN = BETA_SAFE_RANGE,
M_RESETWM, M_RESETWM,

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(ARROWS) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(ARROWS)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_NULL
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_TRANSPARENT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,\ KC_TRANSPARENT, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,\

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(DESKTOP) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(DESKTOP)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_EN
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_TRANSPARENT, LGUI(KC_1), LGUI(KC_2), LGUI(KC_3), LGUI(KC_4), LGUI(KC_5), TO(LAYER_MAIN),\ KC_TRANSPARENT, LGUI(KC_1), LGUI(KC_2), LGUI(KC_3), LGUI(KC_4), LGUI(KC_5), TO(LAYER_MAIN),\

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(FKEYS) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(FKEYS)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_NULL
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_NO, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_NO,\ KC_NO, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_NO,\

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(KEYBOARD) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(KEYBOARD)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_EN
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
RGB_TOG, RGB_HUD, RGB_HUI, KC_NO, KC_NO, KC_NO, KC_NO,\ RGB_TOG, RGB_HUD, RGB_HUI, KC_NO, KC_NO, KC_NO, KC_NO,\

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(MAIN) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(MAIN)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_EN
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_ESCAPE, KC_1, KC_2, KC_3, KC_4, KC_5, OSL(LAYER_DESKTOP),\ KC_ESCAPE, KC_1, KC_2, KC_3, KC_4, KC_5, OSL(LAYER_DESKTOP),\

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(NUMPAD) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(NUMPAD)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_EN
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_TRANSPARENT, KC_CIRC, KC_NO, KC_HASH, KC_DLR, KC_PERC, KC_NO,\ KC_TRANSPARENT, KC_CIRC, KC_NO, KC_HASH, KC_DLR, KC_PERC, KC_NO,\

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(RUSSIAN) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(RUSSIAN)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_RU
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_TRANSPARENT, RU_1, RU_2, RU_3, RU_4, RU_5, KC_TRANSPARENT,\ KC_TRANSPARENT, RU_1, RU_2, RU_3, RU_4, RU_5, KC_TRANSPARENT,\

View File

@ -13,6 +13,15 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(SYMBOLS) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(SYMBOLS)
// What OS keyboard layout this layer is designed for.
// See keymap.h for possible values.
//
// Every layer must have this section.
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_EN
BETA_LAYER_MAGIC_MACRO
#endif
// If BETA_LAYER_NAME is defined, the preprocessor is making // If BETA_LAYER_NAME is defined, the preprocessor is making
// enums for this layer. See keymap.h. // enums for this layer. See keymap.h.
@ -28,7 +37,7 @@
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_NO, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_NO,\ KC_NO, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_NO,\
KC_NO, KC_GRAVE, KC_LPRN, KC_RPRN, KC_QUES, KC_LCBR, KC_NO,\ KC_NO, KC_GRAVE, KC_LPRN, KC_RPRN, KC_QUES, KC_LCBR, KC_TRNS,\
KC_NO, KC_TILD, KC_QUOTE, KC_COMMA, KC_DOT, KC_DQUO,\ KC_NO, KC_TILD, KC_QUOTE, KC_COMMA, KC_DOT, KC_DQUO,\
KC_NO, KC_NO, KC_LBRACKET, KC_RBRACKET, KC_EXLM, KC_RCBR, KC_NO,\ KC_NO, KC_NO, KC_LBRACKET, KC_RBRACKET, KC_EXLM, KC_RCBR, KC_NO,\
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,\ KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,\

View File

@ -2,6 +2,11 @@
#define BETA_LAYER_MAGIC_MACRO BETA_LAYER(SYMBOLS_RU) #define BETA_LAYER_MAGIC_MACRO BETA_LAYER(SYMBOLS_RU)
#ifdef BETA_LAYER_LAYOUTS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_RU
BETA_LAYER_MAGIC_MACRO
#endif
#ifdef BETA_LAYER_KEYS #ifdef BETA_LAYER_KEYS
#define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\ #define BETA_LAYER_CONTEXT_DATA LAYOUT_ergodox(\
KC_NO, RU_EXLM, RU_DQUO, RU_NUM, RU_SCLN, RU_PERC, KC_NO,\ KC_NO, RU_EXLM, RU_DQUO, RU_NUM, RU_SCLN, RU_PERC, KC_NO,\

View File

@ -20,6 +20,14 @@ const uint8_t PROGMEM ledmaps[][DRIVER_LED_TOTAL][3] = {
#undef BETA_LAYER #undef BETA_LAYER
#undef BETA_LAYER_LEDS #undef BETA_LAYER_LEDS
// Create os layout array
#define BETA_LAYER_LAYOUTS
#define BETA_LAYER(name) [LAYER_##name] = BETA_LAYER_CONTEXT_DATA,
uint8_t layer_layouts[] = {
#include LAYER_INCLUDE_FILE
};
#undef BETA_LAYER
#undef BETA_LAYER_LAYOUTS
void set_layer_color(int layer) { void set_layer_color(int layer) {
@ -70,7 +78,7 @@ void rgb_matrix_indicators_user(void) {
uint32_t layer_state_set_user(uint32_t state) { uint32_t set_layer_colors(uint32_t state) {
uint8_t layer = biton32(state); uint8_t layer = biton32(state);

View File

@ -33,8 +33,9 @@ enum led_indices {
//const uint16_t PROGMEM keymaps[X_LAYER_MAX][MATRIX_ROWS][MATRIX_COLS]; //const uint16_t PROGMEM keymaps[X_LAYER_MAX][MATRIX_ROWS][MATRIX_COLS];
//const uint8_t PROGMEM ledmaps[X_LAYER_LEDS_MAX][DRIVER_LED_TOTAL][3]; //const uint8_t PROGMEM ledmaps[X_LAYER_LEDS_MAX][DRIVER_LED_TOTAL][3];
extern uint8_t layer_layouts[];
void set_layer_color(int layer); void set_layer_color(int layer);
void rgb_matrix_indicators_user(void); void rgb_matrix_indicators_user(void);
uint32_t layer_state_set_user(uint32_t state); uint32_t set_layer_colors(uint32_t state);

View File

@ -1,6 +1,7 @@
#include "rawhid.h" #include "rawhid.h"
#include "extra_mappings.h" #include "extra_mappings.h"
extern uint8_t layer_layouts[];
#include "spellcheck.h" #include "spellcheck.h"
// See rawhid.h for prococol documentation // See rawhid.h for prococol documentation
@ -36,14 +37,35 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
} }
uint8_t nth_byte(size_t n, uint32_t data) {
return (data >> (8 * n)) & 0xFF;
}
void hid_send_state() { // state: layer state.
// If this is 0, we'll use global layer_state instead.
void _hid_send_state(_hid_send_state_args args) {
uint32_t state = args.state ? args.state : layer_state;
uint8_t packet[RAW_EPSIZE] = { uint8_t packet[RAW_EPSIZE] = {
CMD_SEND_STATE CMD_SEND_STATE,
// Animation state, set later
0x00,
// Layer state
nth_byte(0, state),
nth_byte(1, state),
nth_byte(2, state),
nth_byte(3, state),
// Keymap for active layer
layer_layouts[biton32(state)]
}; };
// Set second byte
if (rgb_matrix_get_flags() != LED_FLAG_ALL) { if (rgb_matrix_get_flags() != LED_FLAG_ALL) {
// RGB matrix is disabled // RGB matrix is disabled
packet[1] = 0x00; packet[1] = 0x00;

View File

@ -4,12 +4,26 @@
void raw_hid_receive(uint8_t *data, uint8_t length); void raw_hid_receive(uint8_t *data, uint8_t length);
void hid_send_state(void);
void hid_send_word(void); void hid_send_word(void);
// hid_send_state with advanced arguments
typedef struct {
uint32_t state;
} _hid_send_state_args;
void _hid_send_state(_hid_send_state_args args);
#define hid_send_state(...) _hid_send_state( \
(_hid_send_state_args) { \
.state = 0, \
__VA_ARGS__ \
} \
)
void cmd_animation(uint8_t *data, uint8_t length); void cmd_animation(uint8_t *data, uint8_t length);
#ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS #ifdef RGB_MATRIX_FRAMEBUFFER_EFFECTS
extern uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS]; extern uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
#endif #endif
@ -35,15 +49,28 @@ extern uint8_t g_rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS];
// Send keyboard state to host. // Send keyboard state to host.
// //
// Packet structure: // Packet structure:
// Data: | cmd | anim state | // Data: | cmd | anim state | layer state | layer layout |
// # of Bytes: | 1 | 1 | // # of Bytes: | 1 | 1 | 4 | 1 |
// //
// anim state: // anim state:
// 0x00: RGBMatrix disabled // 0x00: RGBMatrix disabled
// 0x01: normal animation, no HID data. // 0x01: normal animation, no HID data.
// 0x02: FFT Animation // 0x02: FFT Animation
//
// layer state: layer state right now.
// This is a uint32_t, where each bit corresponds to a layer index.
// Lowest-order bit is base layer, highest bit is layer 31.
// Layer indices are defined by the LAYER_* enum in layer.h,
// host interface should have a matching enum.
// Make sure to update it when you change your layers!
//
// layer layout:
// The layout this layer was designed for.
// 0x00: en_us
// 0x01: russian
#define CMD_SEND_STATE 0x02 #define CMD_SEND_STATE 0x02
// Sent by keyboard to host when a complete word is typed. // Sent by keyboard to host when a complete word is typed.
// Host checks if this is a known word. // Host checks if this is a known word.
// If it is not, host responds with the same CMD (see below). // If it is not, host responds with the same CMD (see below).