summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio/audio_arm.c2
-rw-r--r--quantum/backlight/backlight.c20
-rw-r--r--quantum/backlight/backlight.h2
-rw-r--r--quantum/color.c6
-rw-r--r--quantum/config_common.h3
-rw-r--r--quantum/dynamic_keymap.c20
-rw-r--r--quantum/encoder.c8
-rw-r--r--quantum/matrix.c10
-rw-r--r--quantum/process_keycode/process_grave_esc.c71
-rw-r--r--quantum/process_keycode/process_grave_esc.h20
-rw-r--r--quantum/process_keycode/process_rgb.c10
-rw-r--r--quantum/process_keycode/process_steno.c4
-rw-r--r--quantum/process_keycode/process_steno.h4
-rw-r--r--quantum/quantum.c65
-rw-r--r--quantum/quantum.h11
-rw-r--r--quantum/quantum_keycodes.h6
-rw-r--r--quantum/rgb_matrix.c29
-rw-r--r--quantum/rgblight.c32
-rw-r--r--quantum/rgblight.h6
-rw-r--r--quantum/split_common/matrix.c10
-rw-r--r--quantum/split_common/serial.c508
-rw-r--r--quantum/split_common/serial.h62
-rw-r--r--quantum/split_common/split_util.c12
-rw-r--r--quantum/via.c431
-rw-r--r--quantum/via.h113
25 files changed, 577 insertions, 888 deletions
diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c
index 87d625301f..e4483c3028 100644
--- a/quantum/audio/audio_arm.c
+++ b/quantum/audio/audio_arm.c
@@ -258,7 +258,7 @@ void audio_init() {
}
// Check EEPROM
-#if defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
+#ifdef EEPROM_ENABLE
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c
index e57b31d103..4aa74667d9 100644
--- a/quantum/backlight/backlight.c
+++ b/quantum/backlight/backlight.c
@@ -130,18 +130,30 @@ void backlight_step(void) {
backlight_set(backlight_config.level);
}
-/** \brief Backlight set level
+/** \brief Backlight set level without EEPROM update
*
- * FIXME: needs doc
*/
-void backlight_level(uint8_t level) {
+void backlight_level_noeeprom(uint8_t level) {
if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS;
backlight_config.level = level;
backlight_config.enable = !!backlight_config.level;
- eeconfig_update_backlight(backlight_config.raw);
backlight_set(backlight_config.level);
}
+/** \brief Backlight set level
+ *
+ * FIXME: needs doc
+ */
+void backlight_level(uint8_t level) {
+ backlight_level_noeeprom(level);
+ eeconfig_update_backlight(backlight_config.raw);
+}
+
+/** \brief Update current backlight state to EEPROM
+ *
+ */
+void eeconfig_update_backlight_current(void) { eeconfig_update_backlight(backlight_config.raw); }
+
/** \brief Get backlight level
*
* FIXME: needs doc
diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h
index 9f0a5e81d7..08acf942ff 100644
--- a/quantum/backlight/backlight.h
+++ b/quantum/backlight/backlight.h
@@ -48,8 +48,10 @@ bool is_backlight_enabled(void);
void backlight_step(void);
void backlight_increase(void);
void backlight_decrease(void);
+void backlight_level_noeeprom(uint8_t level);
void backlight_level(uint8_t level);
uint8_t get_backlight_level(void);
+void eeconfig_update_backlight_current(void);
// implementation specific
void backlight_init_ports(void);
diff --git a/quantum/color.c b/quantum/color.c
index 8bd52444fa..c050300627 100644
--- a/quantum/color.c
+++ b/quantum/color.c
@@ -87,9 +87,9 @@ RGB hsv_to_rgb(HSV hsv) {
}
#ifdef RGBW
-#ifndef MIN
-# define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
+# ifndef MIN
+# define MIN(a, b) ((a) < (b) ? (a) : (b))
+# endif
void convert_rgb_to_rgbw(LED_TYPE *led) {
// Determine lowest value in all three colors, put that into
// the white channel and then shift all colors by that amount
diff --git a/quantum/config_common.h b/quantum/config_common.h
index c1c1d4bd42..f981f3f8cb 100644
--- a/quantum/config_common.h
+++ b/quantum/config_common.h
@@ -19,7 +19,6 @@
/* diode directions */
#define COL2ROW 0
#define ROW2COL 1
-#define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
// useful for direct pin mapping
#define NO_PIN (~0)
@@ -133,7 +132,7 @@
# endif
# ifndef __ASSEMBLER__
-# define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
+# define _PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + ((p) >> PORT_SHIFTER) + (offset))
// Port X Input Pins Address
# define PINx_ADDRESS(p) _PIN_ADDRESS(p, 0)
// Port X Data Direction Register, 0:input 1:output
diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c
index 11d28592d6..0d8ea56b74 100644
--- a/quantum/dynamic_keymap.c
+++ b/quantum/dynamic_keymap.c
@@ -20,36 +20,36 @@
#include "progmem.h" // to read default from flash
#include "quantum.h" // for send_string()
#include "dynamic_keymap.h"
-#include "via.h" // for default VIA_EEPROM_ADDR_END
+#include "via.h" // for default VIA_EEPROM_ADDR_END
#ifndef DYNAMIC_KEYMAP_LAYER_COUNT
-# define DYNAMIC_KEYMAP_LAYER_COUNT 4
+# define DYNAMIC_KEYMAP_LAYER_COUNT 4
#endif
#ifndef DYNAMIC_KEYMAP_MACRO_COUNT
-# define DYNAMIC_KEYMAP_MACRO_COUNT 16
+# define DYNAMIC_KEYMAP_MACRO_COUNT 16
#endif
// If DYNAMIC_KEYMAP_EEPROM_ADDR not explicitly defined in config.h,
// default it start after VIA_EEPROM_CUSTOM_ADDR+VIA_EEPROM_CUSTOM_SIZE
#ifndef DYNAMIC_KEYMAP_EEPROM_ADDR
-# ifdef VIA_EEPROM_CUSTOM_CONFIG_ADDR
-# define DYNAMIC_KEYMAP_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR+VIA_EEPROM_CUSTOM_CONFIG_SIZE)
-# else
-# error DYNAMIC_KEYMAP_EEPROM_ADDR not defined
-# endif
+# ifdef VIA_EEPROM_CUSTOM_CONFIG_ADDR
+# define DYNAMIC_KEYMAP_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR + VIA_EEPROM_CUSTOM_CONFIG_SIZE)
+# else
+# error DYNAMIC_KEYMAP_EEPROM_ADDR not defined
+# endif
#endif
// Dynamic macro starts after dynamic keymaps
#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR
-# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR+(DYNAMIC_KEYMAP_LAYER_COUNT*MATRIX_ROWS*MATRIX_COLS*2))
+# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2))
#endif
// Dynamic macro uses up all remaining memory
// Assumes 1K EEPROM on ATMega32U4
// Override for anything different
#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE
-# define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (1024-DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR)
+# define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (1024 - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR)
#endif
uint8_t dynamic_keymap_get_layer_count(void) { return DYNAMIC_KEYMAP_LAYER_COUNT; }
diff --git a/quantum/encoder.c b/quantum/encoder.c
index c41b89f495..8e11562eb7 100644
--- a/quantum/encoder.c
+++ b/quantum/encoder.c
@@ -37,8 +37,8 @@ static pin_t encoders_pad_b[] = ENCODERS_PAD_B;
static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
-static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
-static int8_t encoder_pulses[NUMBER_OF_ENCODERS] = {0};
+static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
+static int8_t encoder_pulses[NUMBER_OF_ENCODERS] = {0};
#ifdef SPLIT_KEYBOARD
// right half encoders come over as second set of encoders
@@ -88,7 +88,7 @@ static void encoder_update(int8_t index, uint8_t state) {
encoder_value[index]++;
encoder_update_kb(index, true);
}
- if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
+ if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
encoder_value[index]--;
encoder_update_kb(index, false);
}
@@ -109,7 +109,7 @@ void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_valu
void encoder_update_raw(uint8_t* slave_state) {
for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) {
uint8_t index = i + thatHand;
- int8_t delta = slave_state[i] - encoder_value[index];
+ int8_t delta = slave_state[i] - encoder_value[index];
while (delta > 0) {
delta--;
encoder_value[index]++;
diff --git a/quantum/matrix.c b/quantum/matrix.c
index 1675f2477b..6bd604bb79 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -62,7 +62,8 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
return (last_row_value != current_matrix[current_row]);
}
-#elif (DIODE_DIRECTION == COL2ROW)
+#elif defined(DIODE_DIRECTION)
+# if (DIODE_DIRECTION == COL2ROW)
static void select_row(uint8_t row) {
setPinOutput(row_pins[row]);
@@ -110,7 +111,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
return (last_row_value != current_matrix[current_row]);
}
-#elif (DIODE_DIRECTION == ROW2COL)
+# elif (DIODE_DIRECTION == ROW2COL)
static void select_col(uint8_t col) {
setPinOutput(col_pins[col]);
@@ -165,6 +166,11 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
return matrix_changed;
}
+# else
+# error DIODE_DIRECTION must be one of COL2ROW or ROW2COL!
+# endif
+#else
+# error DIODE_DIRECTION is not defined!
#endif
void matrix_init(void) {
diff --git a/quantum/process_keycode/process_grave_esc.c b/quantum/process_keycode/process_grave_esc.c
new file mode 100644
index 0000000000..41c50f5cb8
--- /dev/null
+++ b/quantum/process_keycode/process_grave_esc.c
@@ -0,0 +1,71 @@
+/* Copyright 2020
+ *
+ * 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 "process_grave_esc.h"
+
+/* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
+ * Used to ensure that the correct keycode is released if the key is released.
+ */
+static bool grave_esc_was_shifted = false;
+
+bool process_grave_esc(uint16_t keycode, keyrecord_t *record) {
+ if (keycode == GRAVE_ESC) {
+ const uint8_t mods = get_mods();
+ uint8_t shifted = mods & MOD_MASK_SG;
+
+#ifdef GRAVE_ESC_ALT_OVERRIDE
+ // if ALT is pressed, ESC is always sent
+ // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
+ if (mods & MOD_MASK_ALT) {
+ shifted = 0;
+ }
+#endif
+
+#ifdef GRAVE_ESC_CTRL_OVERRIDE
+ // if CTRL is pressed, ESC is always sent
+ // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
+ if (mods & MOD_MASK_CTRL) {
+ shifted = 0;
+ }
+#endif
+
+#ifdef GRAVE_ESC_GUI_OVERRIDE
+ // if GUI is pressed, ESC is always sent
+ if (mods & MOD_MASK_GUI) {
+ shifted = 0;
+ }
+#endif
+
+#ifdef GRAVE_ESC_SHIFT_OVERRIDE
+ // if SHIFT is pressed, ESC is always sent
+ if (mods & MOD_MASK_SHIFT) {
+ shifted = 0;
+ }
+#endif
+
+ if (record->event.pressed) {
+ grave_esc_was_shifted = shifted;
+ add_key(shifted ? KC_GRAVE : KC_ESCAPE);
+ } else {
+ del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
+ }
+
+ send_keyboard_report();
+ return false;
+ }
+
+ // Not a grave keycode so continue processing
+ return true;
+}
diff --git a/quantum/process_keycode/process_grave_esc.h b/quantum/process_keycode/process_grave_esc.h
new file mode 100644
index 0000000000..bbf4483763
--- /dev/null
+++ b/quantum/process_keycode/process_grave_esc.h
@@ -0,0 +1,20 @@
+/* Copyright 2020
+ *
+ * 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"
+
+bool process_grave_esc(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c
index c76166342f..627e5986fb 100644
--- a/quantum/process_keycode/process_rgb.c
+++ b/quantum/process_keycode/process_rgb.c
@@ -20,8 +20,8 @@ typedef void (*rgb_func_pointer)(void);
/**
* Wrapper for inc/dec rgb keycode
- *
- * noinline to optimise for firmware size not speed (not in hot path)
+ *
+ * noinline to optimise for firmware size not speed (not in hot path)
*/
static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) {
if (is_shifted) {
@@ -35,10 +35,10 @@ static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted,
* Wrapper for animation mode
* - if not in animation family -> jump to that animation
* - otherwise -> wrap round animation speed
- *
- * noinline to optimise for firmware size not speed (not in hot path)
+ *
+ * noinline to optimise for firmware size not speed (not in hot path)
*/
-static void __attribute__((noinline,unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) {
+static void __attribute__((noinline, unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) {
if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) {
rgblight_step();
} else {
diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c
index e0b33ec861..57e279f211 100644
--- a/quantum/process_keycode/process_steno.c
+++ b/quantum/process_keycode/process_steno.c
@@ -73,7 +73,9 @@ static void steno_clear_state(void) {
static void send_steno_state(uint8_t size, bool send_empty) {
for (uint8_t i = 0; i < size; ++i) {
if (chord[i] || send_empty) {
+#ifdef VIRTSER_ENABLE
virtser_send(chord[i]);
+#endif
}
}
}
@@ -105,7 +107,9 @@ static void send_steno_chord(void) {
switch (mode) {
case STENO_MODE_BOLT:
send_steno_state(BOLT_STATE_SIZE, false);
+#ifdef VIRTSER_ENABLE
virtser_send(0); // terminating byte
+#endif
break;
case STENO_MODE_GEMINI:
chord[0] |= 0x80; // Indicate start of packet
diff --git a/quantum/process_keycode/process_steno.h b/quantum/process_keycode/process_steno.h
index 3675423728..ed049eb13f 100644
--- a/quantum/process_keycode/process_steno.h
+++ b/quantum/process_keycode/process_steno.h
@@ -18,10 +18,6 @@
#include "quantum.h"
-#if defined(STENO_ENABLE) && !defined(VIRTSER_ENABLE)
-# error "must have virtser enabled to use steno"
-#endif
-
typedef enum { STENO_MODE_BOLT, STENO_MODE_GEMINI } steno_mode_t;
bool process_steno(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index bf159644ab..52062bb174 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -256,6 +256,9 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef MAGIC_KEYCODE_ENABLE
process_magic(keycode, record) &&
#endif
+#ifdef GRAVE_ESC_ENABLE
+ process_grave_esc(keycode, record) &&
+#endif
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
process_rgb(keycode, record) &&
#endif
@@ -316,58 +319,6 @@ bool process_record_quantum(keyrecord_t *record) {
}
}
- // keycodes that depend on both pressed and non-pressed state
- switch (keycode) {
- case GRAVE_ESC: {
- /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
- * Used to ensure that the correct keycode is released if the key is released.
- */
- static bool grave_esc_was_shifted = false;
-
- uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT) | MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)));
-
-#ifdef GRAVE_ESC_ALT_OVERRIDE
- // if ALT is pressed, ESC is always sent
- // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
- if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) {
- shifted = 0;
- }
-#endif
-
-#ifdef GRAVE_ESC_CTRL_OVERRIDE
- // if CTRL is pressed, ESC is always sent
- // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
- if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) {
- shifted = 0;
- }
-#endif
-
-#ifdef GRAVE_ESC_GUI_OVERRIDE
- // if GUI is pressed, ESC is always sent
- if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) {
- shifted = 0;
- }
-#endif
-
-#ifdef GRAVE_ESC_SHIFT_OVERRIDE
- // if SHIFT is pressed, ESC is always sent
- if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) {
- shifted = 0;
- }
-#endif
-
- if (record->event.pressed) {
- grave_esc_was_shifted = shifted;
- add_key(shifted ? KC_GRAVE : KC_ESCAPE);
- } else {
- del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
- }
-
- send_keyboard_report();
- return false;
- }
- }
-
return process_action_kb(record);
}
@@ -379,6 +330,7 @@ __attribute__((weak)) const bool ascii_to_altgr_lut[128] PROGMEM = {0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+// clang-format off
__attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {// NUL SOH STX ETX EOT ENQ ACK BEL
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
// BS TAB LF VT FF CR SO SI
@@ -412,6 +364,7 @@ __attribute__((weak)) const uint8_t ascii_to_keycode_lut[128] PROGMEM = {// NUL
KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
// x y z { | } ~ DEL
KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL};
+// clang-format on
void send_string(const char *str) { send_string_with_delay(str, 0); }
@@ -477,7 +430,7 @@ void send_string_with_delay_P(const char *str, uint8_t interval) {
void send_char(char ascii_code) {
#if defined(AUDIO_ENABLE) && defined(SENDSTRING_BELL)
- if (ascii_code == '\a') { // BEL
+ if (ascii_code == '\a') { // BEL
PLAY_SONG(bell_song);
return;
}
@@ -634,12 +587,8 @@ void matrix_scan_quantum() {
matrix_scan_combo();
#endif
-#if defined(BACKLIGHT_ENABLE)
-# if defined(LED_MATRIX_ENABLE)
+#ifdef LED_MATRIX_ENABLE
led_matrix_task();
-# elif defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)
- backlight_task();
-# endif
#endif
#ifdef RGB_MATRIX_ENABLE
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 09550fec30..fbd5e90792 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -138,6 +138,10 @@ extern layer_state_t layer_state;
# include "process_magic.h"
#endif
+#ifdef GRAVE_ESC_ENABLE
+# include "process_grave_esc.h"
+#endif
+
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
# include "process_rgb.h"
#endif
@@ -163,18 +167,18 @@ extern layer_state_t layer_state;
#endif
#ifdef DYNAMIC_KEYMAP_ENABLE
-# include "dynamic_keymap.h"
+# include "dynamic_keymap.h"
#endif
#ifdef VIA_ENABLE
-# include "via.h"
+# include "via.h"
#endif
// Function substitutions to ease GPIO manipulation
#if defined(__AVR__)
typedef uint8_t pin_t;
-# define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF))
+# define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
# define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
@@ -184,6 +188,7 @@ typedef uint8_t pin_t;
# define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
+
#elif defined(PROTOCOL_CHIBIOS)
typedef ioline_t pin_t;
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index c8d0e354b0..54428fe1f2 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -677,7 +677,7 @@ enum quantum_keycodes {
#define AG_TOGG MAGIC_TOGGLE_ALT_GUI
#define GUI_OFF MAGIC_NO_GUI
-#define GUI_ON MAGIC_UNNO_GUI
+#define GUI_ON MAGIC_UNNO_GUI
#define GE_SWAP MAGIC_SWAP_GRAVE_ESC
#define GE_NORM MAGIC_UNSWAP_GRAVE_ESC
@@ -685,8 +685,8 @@ enum quantum_keycodes {
#define BS_SWAP MAGIC_SWAP_BACKSLASH_BACKSPACE
#define BS_NORM MAGIC_UNSWAP_BACKSLASH_BACKSPACE
-#define NK_ON MAGIC_HOST_NKRO
-#define NK_OFF MAGIC_UNHOST_NKRO
+#define NK_ON MAGIC_HOST_NKRO
+#define NK_OFF MAGIC_UNHOST_NKRO
#define NK_TOGG MAGIC_TOGGLE_NKRO
#define EH_LEFT MAGIC_EE_HANDS_LEFT
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 9bbeff8332..1a9cf82e5f 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -95,6 +95,23 @@ const point_t k_rgb_matrix_center = RGB_MATRIX_CENTER;
# endif
#endif
+#if !defined(RGB_MATRIX_STARTUP_HUE)
+# define RGB_MATRIX_STARTUP_HUE 0
+#endif
+
+#if !defined(RGB_MATRIX_STARTUP_SAT)
+# define RGB_MATRIX_STARTUP_SAT UINT8_MAX
+#endif
+
+#if !defined(RGB_MATRIX_STARTUP_VAL)
+# define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS
+#endif
+
+#if !defined(RGB_MATRIX_STARTUP_SPD)
+# define RGB_MATRIX_STARTUP_SPD UINT8_MAX / 2
+#endif
+
+
bool g_suspend_state = false;
rgb_config_t rgb_matrix_config;
@@ -119,8 +136,8 @@ void eeconfig_update_rgb_matrix_default(void) {
dprintf("eeconfig_update_rgb_matrix_default\n");
rgb_matrix_config.enable = 1;
rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE;
- rgb_matrix_config.hsv = (HSV){0, UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS};
- rgb_matrix_config.speed = UINT8_MAX / 2;
+ rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL};
+ rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD;
eeconfig_update_rgb_matrix();
}
@@ -417,11 +434,11 @@ void rgb_matrix_init(void) {
eeconfig_debug_rgb_matrix(); // display current eeprom values
}
-void rgb_matrix_set_suspend_state(bool state) {
- if (RGB_DISABLE_WHEN_USB_SUSPENDED && state) {
- rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending
+void rgb_matrix_set_suspend_state(bool state) {
+ if (RGB_DISABLE_WHEN_USB_SUSPENDED && state) {
+ rgb_matrix_set_color_all(0, 0, 0); // turn off all LEDs when suspending
}
- g_suspend_state = state;
+ g_suspend_state = state;
}
void rgb_matrix_toggle(void) {
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 141dc2e7bc..67d601af7f 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -19,9 +19,11 @@
# include <avr/eeprom.h>
# include <avr/interrupt.h>
#endif
+#ifdef EEPROM_ENABLE
+# include "eeprom.h"
+#endif
#ifdef STM32_EEPROM_ENABLE
# include "hal.h"
-# include "eeprom.h"
# include "eeprom_stm32.h"
#endif
#include "wait.h"
@@ -146,7 +148,7 @@ void rgblight_check_config(void) {
}
uint32_t eeconfig_read_rgblight(void) {
-#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
+#ifdef EEPROM_ENABLE
return eeprom_read_dword(EECONFIG_RGBLIGHT);
#else
return 0;
@@ -154,12 +156,14 @@ uint32_t eeconfig_read_rgblight(void) {
}
void eeconfig_update_rgblight(uint32_t val) {
-#if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
+#ifdef EEPROM_ENABLE
rgblight_check_config();
eeprom_update_dword(EECONFIG_RGBLIGHT, val);
#endif
}
+void eeconfig_update_rgblight_current(void) { eeconfig_update_rgblight(rgblight_config.raw); }
+
void eeconfig_update_rgblight_default(void) {
rgblight_config.enable = 1;
rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT;
@@ -501,6 +505,22 @@ void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_ee
void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); }
+uint8_t rgblight_get_speed(void) { return rgblight_config.speed; }
+
+void rgblight_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
+ rgblight_config.speed = speed;
+ if (write_to_eeprom) {
+ eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this
+ dprintf("rgblight set speed [EEPROM]: %u\n", rgblight_config.speed);
+ } else {
+ dprintf("rgblight set speed [NOEEPROM]: %u\n", rgblight_config.speed);
+ }
+}
+
+void rgblight_set_speed(uint8_t speed) { rgblight_set_speed_eeprom_helper(speed, true); }
+
+void rgblight_set_speed_noeeprom(uint8_t speed) { rgblight_set_speed_eeprom_helper(speed, false); }
+
uint8_t rgblight_get_hue(void) { return rgblight_config.hue; }
uint8_t rgblight_get_sat(void) { return rgblight_config.sat; }
@@ -622,12 +642,12 @@ void rgblight_set(void) {
start_led = led + clipping_start_pos;
# endif
-#ifdef RGBW
+# ifdef RGBW
for (uint8_t i = 0; i < num_leds; i++) {
convert_rgb_to_rgbw(&start_led[i]);
}
-#endif
- ws2812_setleds(start_led, num_leds);
+# endif
+ ws2812_setleds(start_led, num_leds);
}
#endif
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index e3aa098e4d..c0fc0f3c63 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -233,6 +233,11 @@ void rgblight_decrease_speed(void);
void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val);
void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val);
+/* effect speed */
+uint8_t rgblight_get_speed(void);
+void rgblight_set_speed(uint8_t speed);
+void rgblight_set_speed_noeeprom(uint8_t speed);
+
/* query */
uint8_t rgblight_get_mode(void);
uint8_t rgblight_get_hue(void);
@@ -245,6 +250,7 @@ uint32_t rgblight_read_dword(void);
void rgblight_update_dword(uint32_t dword);
uint32_t eeconfig_read_rgblight(void);
void eeconfig_update_rgblight(uint32_t val);
+void eeconfig_update_rgblight_current(void);
void eeconfig_update_rgblight_default(void);
void eeconfig_debug_rgblight(void);
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index ed1ff5acf3..454ea59c3b 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -79,7 +79,8 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
return (last_row_value != current_matrix[current_row]);
}
-#elif (DIODE_DIRECTION == COL2ROW)
+#elif defined(DIODE_DIRECTION)
+# if (DIODE_DIRECTION == COL2ROW)
static void select_row(uint8_t row) {
setPinOutput(row_pins[row]);
@@ -124,7 +125,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
return (last_row_value != current_matrix[current_row]);
}
-#elif (DIODE_DIRECTION == ROW2COL)
+# elif (DIODE_DIRECTION == ROW2COL)
static void select_col(uint8_t col) {
setPinOutput(col_pins[col]);
@@ -179,6 +180,11 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
return matrix_changed;
}
+# else
+# error DIODE_DIRECTION must be one of COL2ROW or ROW2COL!
+# endif
+#else
+# error DIODE_DIRECTION is not defined!
#endif
void matrix_init(void) {
diff --git a/quantum/split_common/serial.c b/quantum/split_common/serial.c
deleted file mode 100644
index c27cbfdd0a..0000000000
--- a/quantum/split_common/serial.c
+++ /dev/null
@@ -1,508 +0,0 @@
-/*
- * WARNING: be careful changing this code, it is very timing dependent
- *
- * 2018-10-28 checked
- * avr-gcc 4.9.2
- * avr-gcc 5.4.0
- * avr-gcc 7.3.0
- */
-
-#ifndef F_CPU
-# define F_CPU 16000000
-#endif
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <stddef.h>
-#include <stdbool.h>
-#include "serial.h"
-
-#ifdef SOFT_SERIAL_PIN
-
-# ifdef __AVR_ATmega32U4__
-// if using ATmega32U4 I2C, can not use PD0 and PD1 in soft serial.
-# ifdef USE_AVR_I2C
-# if SOFT_SERIAL_PIN == D0 || SOFT_SERIAL_PIN == D1
-# error Using ATmega32U4 I2C, so can not use PD0, PD1
-# endif
-# endif
-
-# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
-# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
-
-# if SOFT_SERIAL_PIN >= D0 && SOFT_SERIAL_PIN <= D3
-# if SOFT_SERIAL_PIN == D0
-# define EIMSK_BIT _BV(INT0)
-# define EICRx_BIT (~(_BV(ISC00) | _BV(ISC01)))
-# define SERIAL_PIN_INTERRUPT INT0_vect
-# elif SOFT_SERIAL_PIN == D1
-# define EIMSK_BIT _BV(INT1)
-# define EICRx_BIT (~(_BV(ISC10) | _BV(ISC11)))
-# define SERIAL_PIN_INTERRUPT INT1_vect
-# elif SOFT_SERIAL_PIN == D2
-# define EIMSK_BIT _BV(INT2)
-# define EICRx_BIT (~(_BV(ISC20) | _BV(ISC21)))
-# define SERIAL_PIN_INTERRUPT INT2_vect
-# elif SOFT_SERIAL_PIN == D3
-# define EIMSK_BIT _BV(INT3)
-# define EICRx_BIT (~(_BV(ISC30) | _BV(ISC31)))
-# define SERIAL_PIN_INTERRUPT INT3_vect
-# endif
-# elif SOFT_SERIAL_PIN == E6
-# define EIMSK_BIT _BV(INT6)
-# define EICRx_BIT (~(_BV(ISC60) | _BV(ISC61)))
-# define SERIAL_PIN_INTERRUPT INT6_vect
-# else
-# error invalid SOFT_SERIAL_PIN value
-# endif
-
-# else
-# error serial.c now support ATmega32U4 only
-# endif
-
-# define ALWAYS_INLINE __attribute__((always_inline))
-# define NO_INLINE __attribute__((noinline))
-# define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
-
-// parity check
-# define ODD_PARITY 1
-# define EVEN_PARITY 0
-# define PARITY EVEN_PARITY
-
-# ifdef SERIAL_DELAY
-// custom setup in config.h
-// #define TID_SEND_ADJUST 2
-// #define SERIAL_DELAY 6 // micro sec
-// #define READ_WRITE_START_ADJUST 30 // cycles
-// #define READ_WRITE_WIDTH_ADJUST 8 // cycles
-# else
-// ============ Standard setups ============
-
-# ifndef SELECT_SOFT_SERIAL_SPEED
-# define SELECT_SOFT_SERIAL_SPEED 1
-// 0: about 189kbps (Experimental only)
-// 1: about 137kbps (default)
-// 2: about 75kbps
-// 3: about 39kbps
-// 4: about 26kbps
-// 5: about 20kbps
-# endif
-
-# if __GNUC__ < 6
-# define TID_SEND_ADJUST 14
-# else
-# define TID_SEND_ADJUST 2
-# endif
-
-# if SELECT_SOFT_SERIAL_SPEED == 0
-// Very High speed
-# define SERIAL_DELAY 4 // micro sec
-# if __GNUC__ < 6
-# define READ_WRITE_START_ADJUST 33 // cycles
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_START_ADJUST 34 // cycles
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 1
-// High speed
-# define SERIAL_DELAY 6 // micro sec
-# if __GNUC__ < 6
-# define READ_WRITE_START_ADJUST 30 // cycles
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_START_ADJUST 33 // cycles
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 2
-// Middle speed
-# define SERIAL_DELAY 12 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 3
-// Low speed
-# define SERIAL_DELAY 24 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 4
-// Very Low speed
-# define SERIAL_DELAY 36 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# elif SELECT_SOFT_SERIAL_SPEED == 5
-// Ultra Low speed
-# define SERIAL_DELAY 48 // micro sec
-# define READ_WRITE_START_ADJUST 30 // cycles
-# if __GNUC__ < 6
-# define READ_WRITE_WIDTH_ADJUST 3 // cycles
-# else
-# define READ_WRITE_WIDTH_ADJUST 7 // cycles
-# endif
-# else
-# error invalid SELECT_SOFT_SERIAL_SPEED value
-# endif /* SELECT_SOFT_SERIAL_SPEED */
-# endif /* SERIAL_DELAY */
-
-# define SERIAL_DELAY_HALF1 (SERIAL_DELAY / 2)
-# define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY / 2)
-
-# define SLAVE_INT_WIDTH_US 1
-# ifndef SERIAL_USE_MULTI_TRANSACTION
-# define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
-# else
-# define SLAVE_INT_ACK_WIDTH_UNIT 2
-# define SLAVE_INT_ACK_WIDTH 4
-# endif
-
-static SSTD_t *Transaction_table = NULL;
-static uint8_t Transaction_table_size = 0;
-
-inline static void serial_delay(void) ALWAYS_INLINE;
-inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
-
-inline static void serial_delay_half1(void) ALWAYS_INLINE;
-inline static void serial_delay_half1(void) { _delay_us(SERIAL_DELAY_HALF1); }
-
-inline static void serial_delay_half2(void) ALWAYS_INLINE;
-inline static void serial_delay_half2(void) { _delay_us(SERIAL_DELAY_HALF2); }
-
-inline static void serial_output(void) ALWAYS_INLINE;
-inline static void serial_output(void) { setPinOutput(SOFT_SERIAL_PIN); }
-
-// make the serial pin an input with pull-up resistor
-inline static void serial_input_with_pullup(void) ALWAYS_INLINE;
-inline static void serial_input_with_pullup(void) { setPinInputHigh(SOFT_SERIAL_PIN); }
-
-inline static uint8_t serial_read_pin(void) ALWAYS_INLINE;
-inline static uint8_t serial_read_pin(void) { return !!readPin(SOFT_SERIAL_PIN); }
-
-inline static void serial_low(void) ALWAYS_INLINE;
-inline static void serial_low(void) { writePinLow(SOFT_SERIAL_PIN); }
-
-inline static void serial_high(void) ALWAYS_INLINE;
-inline static void serial_high(void) { writePinHigh(SOFT_SERIAL_PIN); }
-
-void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
- serial_output();
- serial_high();
-}
-
-void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size) {
- Transaction_table = sstd_table;
- Transaction_table_size = (uint8_t)sstd_table_size;
- serial_input_with_pullup();
-
- // Enable INT0-INT3,INT6
- EIMSK |= EIMSK_BIT;
-# if SOFT_SERIAL_PIN == E6
- // Trigger on falling edge of INT6
- EICRB &= EICRx_BIT;
-# else
- // Trigger on falling edge of INT0-INT3
- EICRA &= EICRx_BIT;
-# endif
-}
-
-// Used by the sender to synchronize timing with the reciver.
-static void sync_recv(void) NO_INLINE;
-static void sync_recv(void) {
- for (uint8_t i = 0; i < SERIAL_DELAY * 5 && serial_read_pin(); i++) {
- }
- // This shouldn't hang if the target disconnects because the
- // serial line will float to high if the target does disconnect.
- while (!serial_read_pin())
- ;
-}
-
-// Used by the reciver to send a synchronization signal to the sender.
-static void sync_send(void) NO_INLINE;
-static void sync_send(void) {
- serial_low();
- serial_delay();
- serial_high();
-}
-
-// Reads a byte from the serial line
-static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE;
-static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
- uint8_t byte, i, p, pb;
-
- _delay_sub_us(READ_WRITE_START_ADJUST);
- for (i = 0, byte = 0, p = PARITY; i < bit; i++) {
- serial_delay_half1(); // read the middle of pulses
- if (serial_read_pin()) {
- byte = (byte << 1) | 1;
- p ^= 1;
- } else {
- byte = (byte << 1) | 0;
- p ^= 0;
- }
- _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
- serial_delay_half2();
- }
- /* recive parity bit */
- serial_delay_half1(); // read the middle of pulses
- pb = serial_read_pin();
- _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
- serial_delay_half2();
-
- *pterrcount += (p != pb) ? 1 : 0;
-
- return byte;
-}
-
-// Sends a byte with MSB ordering
-void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
-void serial_write_chunk(uint8_t data, uint8_t bit) {
- uint8_t b, p;
- for (p = PARITY, b = 1 << (bit - 1); b; b >>= 1) {
- if (data & b) {
- serial_high();
- p ^= 1;
- } else {
- serial_low();
- p ^= 0;
- }
- serial_delay();
- }
- /* send parity bit */
- if (p & 1) {
- serial_high();
- } else {
- serial_low();
- }
- serial_delay();
-
- serial_low(); // sync_send() / senc_recv() need raise edge
-}
-
-static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
-static void serial_send_packet(uint8_t *buffer, uint8_t size) {
- for (uint8_t i = 0; i < size; ++i) {
- uint8_t data;
- data = buffer[i];
- sync_send();
- serial_write_chunk(data, 8);
- }
-}
-
-static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
-static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
- uint8_t pecount = 0;
- for (uint8_t i = 0; i < size; ++i) {
- uint8_t data;
- sync_recv();
- data = serial_read_chunk(&pecount, 8);
- buffer[i] = data;
- }
- return pecount == 0;
-}
-
-inline static void change_sender2reciver(void) {
- sync_send(); // 0
- serial_delay_half1(); // 1
- serial_low(); // 2
- serial_input_with_pullup(); // 2
- serial_delay_half1(); // 3
-}
-
-inline static void change_reciver2sender(void) {
- sync_recv(); // 0
- serial_delay(); // 1
- serial_low(); // 3
- serial_output(); // 3
- serial_delay_half1(); // 4
-}
-
-static inline uint8_t nibble_bits_count(uint8_t bits) {
- bits = (bits & 0x5) + (bits >> 1 & 0x5);
- bits = (bits & 0x3) + (bits >> 2 & 0x3);
- return bits;
-}
-
-// interrupt handle to be used by the target device
-ISR(SERIAL_PIN_INTERRUPT) {
-# ifndef SERIAL_USE_MULTI_TRANSACTION
- serial_low();
- serial_output();
- SSTD_t *trans = Transaction_table;
-# else
- // recive transaction table index
- uint8_t tid, bits;
- uint8_t pecount = 0;
- sync_recv();
- bits = serial_read_chunk(&pecount, 7);
- tid = bits >> 3;
- bits = (bits & 7) != nibble_bits_count(tid);
- if (bits || pecount > 0 || tid > Transaction_table_size) {
- return;
- }
- serial_delay_half1();
-
- serial_high(); // response step1 low->high
- serial_output();
- _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT * SLAVE_INT_ACK_WIDTH);
- SSTD_t *trans = &Transaction_table[tid];
- serial_low(); // response step2 ack high->low
-# endif
-
- // target send phase
- if (trans->target2initiator_buffer_size > 0) serial_send_packet((uint8_t *)trans->target2initiator_buffer, trans->target2initiator_buffer_size);
- // target switch to input
- change_sender2reciver();
-
- // target recive phase
- if (trans->initiator2target_buffer_size > 0) {
- if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer, trans->initiator2target_buffer_size)) {
- *trans->status = TRANSACTION_ACCEPTED;
- } else {
- *trans->status = TRANSACTION_DATA_ERROR;
- }
- } else {
- *trans->status = TRANSACTION_ACCEPTED;
- }
-
- sync_recv(); // weit initiator output to high
-}
-
-/////////
-// start transaction by initiator
-//
-// int soft_serial_transaction(int sstd_index)
-//
-// Returns:
-// TRANSACTION_END
-// TRANSACTION_NO_RESPONSE
-// TRANSACTION_DATA_ERROR
-// this code is very time dependent, so we need to disable interrupts
-# ifndef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_transaction(void) {
- SSTD_t *trans = Transaction_table;
-# else
-int soft_serial_transaction(int sstd_index) {
- if (sstd_index > Transaction_table_size) return TRANSACTION_TYPE_ERROR;
- SSTD_t *trans = &Transaction_table[sstd_index];
-# endif
- cli();
-
- // signal to the target that we want to start a transaction
- serial_output();
- serial_low();
- _delay_us(SLAVE_INT_WIDTH_US);
-
-# ifndef SERIAL_USE_MULTI_TRANSACTION
- // wait for the target response
- serial_input_with_pullup();
- _delay_us(SLAVE_INT_RESPONSE_TIME);
-
- // check if the target is present
- if (serial_read_pin()) {
- // target failed to pull the line low, assume not present
- serial_output();
- serial_high();
- *trans->status = TRANSACTION_NO_RESPONSE;
- sei();
- return TRANSACTION_NO_RESPONSE;
- }
-
-# else
- // send transaction table index
- int tid = (sstd_index << 3) | (7 & nibble_bits_count(sstd_index));
- sync_send();
- _delay_sub_us(TID_SEND_ADJUST);
- serial_write_chunk(tid, 7);
- serial_delay_half1();
-
- // wait for the target response (step1 low->high)
- serial_input_with_pullup();
- while (!serial_read_pin()) {
- _delay_sub_us(2);
- }
-
- // check if the target is present (step2 high->low)
- for (int i = 0; serial_read_pin(); i++) {
- if (i > SLAVE_INT_ACK_WIDTH + 1) {
- // slave failed to pull the line low, assume not present
- serial_output();
- serial_high();
- *trans->status = TRANSACTION_NO_RESPONSE;
- sei();
- return TRANSACTION_NO_RESPONSE;
- }
- _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
- }
-# endif
-
- // initiator recive phase
- // if the target is present syncronize with it
- if (trans->target2initiator_buffer_size > 0) {
- if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer, trans->target2initiator_buffer_size)) {
- serial_output();
- serial_high();
- *trans->status = TRANSACTION_DATA_ERROR;
- sei();
- return TRANSACTION_DATA_ERROR;
- }
- }
-
- // initiator switch to output
- change_reciver2sender();
-
- // initiator send phase
- if (trans->initiator2target_buffer_size > 0) {
- serial_send_packet((uint8_t *)trans->initiator2target_buffer, trans->initiator2target_buffer_size);
- }
-
- // always, release the line when not in use
- sync_send();
-
- *trans->status = TRANSACTION_END;
- sei();
- return TRANSACTION_END;
-}
-
-# ifdef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_get_and_clean_status(int sstd_index) {
- SSTD_t *trans = &Transaction_table[sstd_index];
- cli();
- int retval = *trans->status;
- *trans->status = 0;
- ;
- sei();
- return retval;
-}
-# endif
-
-#endif
-
-// Helix serial.c history
-// 2018-1-29 fork from let's split and add PD2, modify sync_recv() (#2308, bceffdefc)
-// 2018-6-28 bug fix master to slave comm and speed up (#3255, 1038bbef4)
-// (adjusted with avr-gcc 4.9.2)
-// 2018-7-13 remove USE_SERIAL_PD2 macro (#3374, f30d6dd78)
-// (adjusted with avr-gcc 4.9.2)
-// 2018-8-11 add support multi-type transaction (#3608, feb5e4aae)
-// (adjusted with avr-gcc 4.9.2)
-// 2018-10-21 fix serial and RGB animation conflict (#4191, 4665e4fff)
-// (adjusted with avr-gcc 7.3.0)
-// 2018-10-28 re-adjust compiler depend value of delay (#4269, 8517f8a66)
-// (adjusted with avr-gcc 5.4.0, 7.3.0)
-// 2018-12-17 copy to TOP/quantum/split_common/ and remove backward compatibility code (#4669)
diff --git a/quantum/split_common/serial.h b/quantum/split_common/serial.h
deleted file mode 100644
index 53e66cf905..0000000000
--- a/quantum/split_common/serial.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#pragma once
-
-#include <stdbool.h>
-
-// /////////////////////////////////////////////////////////////////
-// Need Soft Serial defines in config.h
-// /////////////////////////////////////////////////////////////////
-// ex.
-// #define SOFT_SERIAL_PIN ?? // ?? = D0,D1,D2,D3,E6
-// OPTIONAL: #define SELECT_SOFT_SERIAL_SPEED ? // ? = 1,2,3,4,5
-// // 1: about 137kbps (default)
-// // 2: about 75kbps
-// // 3: about 39kbps
-// // 4: about 26kbps
-// // 5: about 20kbps
-//
-// //// USE simple API (using signle-type transaction function)
-// /* nothing */
-// //// USE flexible API (using multi-type transaction function)
-// #define SERIAL_USE_MULTI_TRANSACTION
-//
-// /////////////////////////////////////////////////////////////////
-
-// Soft Serial Transaction Descriptor
-typedef struct _SSTD_t {
- uint8_t *status;
- uint8_t initiator2target_buffer_size;
- uint8_t *initiator2target_buffer;
- uint8_t target2initiator_buffer_size;
- uint8_t *target2initiator_buffer;
-} SSTD_t;
-#define TID_LIMIT(table) (sizeof(table) / sizeof(SSTD_t))
-
-// initiator is transaction start side
-void soft_serial_initiator_init(SSTD_t *sstd_table, int sstd_table_size);
-// target is interrupt accept side
-void soft_serial_target_init(SSTD_t *sstd_table, int sstd_table_size);
-
-// initiator resullt
-#define TRANSACTION_END 0
-#define TRANSACTION_NO_RESPONSE 0x1
-#define TRANSACTION_DATA_ERROR 0x2
-#define TRANSACTION_TYPE_ERROR 0x4
-#ifndef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_transaction(void);
-#else
-int soft_serial_transaction(int sstd_index);
-#endif
-
-// target status
-// *SSTD_t.status has
-// initiator:
-// TRANSACTION_END
-// or TRANSACTION_NO_RESPONSE
-// or TRANSACTION_DATA_ERROR
-// target:
-// TRANSACTION_DATA_ERROR
-// or TRANSACTION_ACCEPTED
-#define TRANSACTION_ACCEPTED 0x8
-#ifdef SERIAL_USE_MULTI_TRANSACTION
-int soft_serial_get_and_clean_status(int sstd_index);
-#endif
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 076f186649..103bc97142 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -15,14 +15,18 @@
#endif
#ifndef SPLIT_USB_TIMEOUT
-# define SPLIT_USB_TIMEOUT 2500
+# define SPLIT_USB_TIMEOUT 2000
+#endif
+
+#ifndef SPLIT_USB_TIMEOUT_POLL
+# define SPLIT_USB_TIMEOUT_POLL 10
#endif
volatile bool isLeftHand = true;
bool waitForUsb(void) {
- for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / 100); i++) {
- // This will return true of a USB connection has been established
+ for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) {
+ // This will return true if a USB connection has been established
#if defined(__AVR__)
if (UDADDR & _BV(ADDEN)) {
#else
@@ -30,7 +34,7 @@ bool waitForUsb(void) {
#endif
return true;
}
- wait_ms(100);
+ wait_ms(SPLIT_USB_TIMEOUT_POLL);
}
// Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow
diff --git a/quantum/via.c b/quantum/via.c
index 64b05324a1..f85af8d9e1 100644
--- a/quantum/via.c
+++ b/quantum/via.c
@@ -22,47 +22,70 @@
# error "DYNAMIC_KEYMAP_ENABLE is not enabled"
#endif
+// If VIA_CUSTOM_LIGHTING_ENABLE is not defined, then VIA_QMK_BACKLIGHT_ENABLE is set
+// if BACKLIGHT_ENABLE is set, so handling of QMK Backlight values happens here by default.
+// if VIA_CUSTOM_LIGHTING_ENABLE is defined, then VIA_QMK_BACKLIGHT_ENABLE must be explicitly
+// set in keyboard-level config.h, so handling of QMK Backlight values happens here
+#if defined(BACKLIGHT_ENABLE) && !defined(VIA_CUSTOM_LIGHTING_ENABLE)
+# define VIA_QMK_BACKLIGHT_ENABLE
+#endif
+
+// If VIA_CUSTOM_LIGHTING_ENABLE is not defined, then VIA_QMK_RGBLIGHT_ENABLE is set
+// if RGBLIGHT_ENABLE is set, so handling of QMK RGBLIGHT values happens here by default.
+// If VIA_CUSTOM_LIGHTING_ENABLE is defined, then VIA_QMK_RGBLIGHT_ENABLE must be explicitly
+// set in keyboard-level config.h, so handling of QMK RGBLIGHT values happens here
+#if defined(RGBLIGHT_ENABLE) && !defined(VIA_CUSTOM_LIGHTING_ENABLE)
+# define VIA_QMK_RGBLIGHT_ENABLE
+#endif
+
#include "quantum.h"
#include "via.h"
+
#include "raw_hid.h"
#include "dynamic_keymap.h"
#include "tmk_core/common/eeprom.h"
-#include "version.h" // for QMK_BUILDDATE used in EEPROM magic
+#include "version.h" // for QMK_BUILDDATE used in EEPROM magic
+
+// Forward declare some helpers.
+#if defined(VIA_QMK_BACKLIGHT_ENABLE)
+void via_qmk_backlight_set_value(uint8_t *data);
+void via_qmk_backlight_get_value(uint8_t *data);
+#endif
+
+#if defined(VIA_QMK_RGBLIGHT_ENABLE)
+void via_qmk_rgblight_set_value(uint8_t *data);
+void via_qmk_rgblight_get_value(uint8_t *data);
+#endif
// Can be called in an overriding via_init_kb() to test if keyboard level code usage of
// EEPROM is invalid and use/save defaults.
-bool via_eeprom_is_valid(void)
-{
- char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
- uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
- uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
- uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
-
- return (eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0 ) == magic0 &&
- eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1 ) == magic1 &&
- eeprom_read_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2 ) == magic2 );
+bool via_eeprom_is_valid(void) {
+ char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
+ uint8_t magic0 = ((p[2] & 0x0F) << 4) | (p[3] & 0x0F);
+ uint8_t magic1 = ((p[5] & 0x0F) << 4) | (p[6] & 0x0F);
+ uint8_t magic2 = ((p[8] & 0x0F) << 4) | (p[9] & 0x0F);
+
+ return (eeprom_read_byte((void *)VIA_EEPROM_MAGIC_ADDR + 0) == magic0 && eeprom_read_byte((void *)VIA_EEPROM_MAGIC_ADDR + 1) == magic1 && eeprom_read_byte((void *)VIA_EEPROM_MAGIC_ADDR + 2) == magic2);
}
// Sets VIA/keyboard level usage of EEPROM to valid/invalid
// Keyboard level code (eg. via_init_kb()) should not call this
-void via_eeprom_set_valid(bool valid)
-{
- char *p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
- uint8_t magic0 = ( ( p[2] & 0x0F ) << 4 ) | ( p[3] & 0x0F );
- uint8_t magic1 = ( ( p[5] & 0x0F ) << 4 ) | ( p[6] & 0x0F );
- uint8_t magic2 = ( ( p[8] & 0x0F ) << 4 ) | ( p[9] & 0x0F );
-
- eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+0, valid ? magic0 : 0xFF);
- eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+1, valid ? magic1 : 0xFF);
- eeprom_update_byte( (void*)VIA_EEPROM_MAGIC_ADDR+2, valid ? magic2 : 0xFF);
+void via_eeprom_set_valid(bool valid) {
+ char * p = QMK_BUILDDATE; // e.g. "2019-11-05-11:29:54"
+ uint8_t magic0 = ((p[2] & 0x0F) << 4) | (p[3] & 0x0F);
+ uint8_t magic1 = ((p[5] & 0x0F) << 4) | (p[6] & 0x0F);
+ uint8_t magic2 = ((p[8] & 0x0F) << 4) | (p[9] & 0x0F);
+
+ eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 0, valid ? magic0 : 0xFF);
+ eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 1, valid ? magic1 : 0xFF);
+ eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 2, valid ? magic2 : 0xFF);
}
// Flag QMK and VIA/keyboard level EEPROM as invalid.
// Used in bootmagic_lite() and VIA command handler.
// Keyboard level code should not need to call this.
-void via_eeprom_reset(void)
-{
+void via_eeprom_reset(void) {
// Set the VIA specific EEPROM state as invalid.
via_eeprom_set_valid(false);
// Set the TMK/QMK EEPROM state as invalid.
@@ -72,8 +95,7 @@ void via_eeprom_reset(void)
// Override bootmagic_lite() so it can flag EEPROM as invalid
// as well as jump to bootloader, thus performing a "factory reset"
// of dynamic keymaps and optionally backlight/other settings.
-void bootmagic_lite(void)
-{
+void bootmagic_lite(void) {
// The lite version of TMK's bootmagic based on Wilba.
// 100% less potential for accidentally making the
// keyboard do stupid things.
@@ -106,12 +128,10 @@ void bootmagic_lite(void)
// for backlight, rotary encoders, etc.
// The override should not set via_eeprom_set_valid(true) as
// the caller also needs to check the valid state.
-__attribute__((weak)) void via_init_kb(void) {
-}
+__attribute__((weak)) void via_init_kb(void) {}
// Called by QMK core to initialize dynamic keymaps etc.
-void via_init(void)
-{
+void via_init(void) {
// Let keyboard level test EEPROM valid state,
// but not set it valid, it is done here.
via_init_kb();
@@ -119,7 +139,7 @@ void via_init(void)
// If the EEPROM has the magic, the data is good.
// OK to load from EEPROM.
if (via_eeprom_is_valid()) {
- } else {
+ } else {
// This resets the layout options
via_set_layout_options(0);
// This resets the keymaps in EEPROM to what is in flash.
@@ -133,12 +153,11 @@ void via_init(void)
// This is generalized so the layout options EEPROM usage can be
// variable, between 1 and 4 bytes.
-uint32_t via_get_layout_options(void)
-{
+uint32_t via_get_layout_options(void) {
uint32_t value = 0;
// Start at the most significant byte
- void * source = (void *)(VIA_EEPROM_LAYOUT_OPTIONS_ADDR);
- for ( uint8_t i = 0; i < VIA_EEPROM_LAYOUT_OPTIONS_SIZE; i++ ) {
+ void *source = (void *)(VIA_EEPROM_LAYOUT_OPTIONS_ADDR);
+ for (uint8_t i = 0; i < VIA_EEPROM_LAYOUT_OPTIONS_SIZE; i++) {
value = value << 8;
value |= eeprom_read_byte(source);
source++;
@@ -146,24 +165,21 @@ uint32_t via_get_layout_options(void)
return value;
}
-void via_set_layout_options(uint32_t value)
-{
+void via_set_layout_options(uint32_t value) {
// Start at the least significant byte
- void * target = (void *)(VIA_EEPROM_LAYOUT_OPTIONS_ADDR+VIA_EEPROM_LAYOUT_OPTIONS_SIZE-1);
- for ( uint8_t i = 0; i < VIA_EEPROM_LAYOUT_OPTIONS_SIZE; i++ ) {
- eeprom_update_byte(target, value & 0xFF );
+ void *target = (void *)(VIA_EEPROM_LAYOUT_OPTIONS_ADDR + VIA_EEPROM_LAYOUT_OPTIONS_SIZE - 1);
+ for (uint8_t i = 0; i < VIA_EEPROM_LAYOUT_OPTIONS_SIZE; i++) {
+ eeprom_update_byte(target, value & 0xFF);
value = value >> 8;
target--;
}
}
// Called by QMK core to process VIA-specific keycodes.
-bool process_record_via(uint16_t keycode, keyrecord_t *record)
-{
+bool process_record_via(uint16_t keycode, keyrecord_t *record) {
// Handle macros
if (record->event.pressed) {
- if ( keycode >= MACRO00 && keycode <= MACRO15 )
- {
+ if (keycode >= MACRO00 && keycode <= MACRO15) {
uint8_t id = keycode - MACRO00;
dynamic_keymap_macro_send(id);
return false;
@@ -173,7 +189,7 @@ bool process_record_via(uint16_t keycode, keyrecord_t *record)
// TODO: ideally this would be generalized and refactored into
// QMK core as advanced keycodes, until then, the simple case
// can be available here to keyboards using VIA
- switch(keycode) {
+ switch (keycode) {
case FN_MO13:
if (record->event.pressed) {
layer_on(1);
@@ -203,7 +219,7 @@ bool process_record_via(uint16_t keycode, keyrecord_t *record)
// DO NOT call raw_hid_send() in the overide function.
__attribute__((weak)) void raw_hid_receive_kb(uint8_t *data, uint8_t length) {
uint8_t *command_id = &(data[0]);
- *command_id = id_unhandled;
+ *command_id = id_unhandled;
}
// VIA handles received HID messages first, and will route to
@@ -211,182 +227,193 @@ __attribute__((weak)) void raw_hid_receive_kb(uint8_t *data, uint8_t length) {
// This gives the keyboard code level the ability to handle the command
// specifically.
//
-// raw_hid_send() is called at the end, with the same buffer, which was
+// raw_hid_send() is called at the end, with the same buffer, which was
// possibly modified with returned values.
-void raw_hid_receive( uint8_t *data, uint8_t length )
-{
- uint8_t *command_id = &(data[0]);
+void raw_hid_receive(uint8_t *data, uint8_t length) {
+ uint8_t *command_id = &(data[0]);
uint8_t *command_data = &(data[1]);
- switch ( *command_id )
- {
- case id_get_protocol_version:
- {
+ switch (*command_id) {
+ case id_get_protocol_version: {
command_data[0] = VIA_PROTOCOL_VERSION >> 8;
command_data[1] = VIA_PROTOCOL_VERSION & 0xFF;
break;
}
- case id_get_keyboard_value:
- {
- switch ( command_data[0] )
- {
- case id_uptime:
- {
- uint32_t value = timer_read32();
- command_data[1] = (value >> 24 ) & 0xFF;
- command_data[2] = (value >> 16 ) & 0xFF;
- command_data[3] = (value >> 8 ) & 0xFF;
+ case id_get_keyboard_value: {
+ switch (command_data[0]) {
+ case id_uptime: {
+ uint32_t value = timer_read32();
+ command_data[1] = (value >> 24) & 0xFF;
+ command_data[2] = (value >> 16) & 0xFF;
+ command_data[3] = (value >> 8) & 0xFF;
command_data[4] = value & 0xFF;
break;
}
- case id_layout_options:
- {
- uint32_t value = via_get_layout_options();
- command_data[1] = (value >> 24 ) & 0xFF;
- command_data[2] = (value >> 16 ) & 0xFF;
- command_data[3] = (value >> 8 ) & 0xFF;
+ case id_layout_options: {
+ uint32_t value = via_get_layout_options();
+ command_data[1] = (value >> 24) & 0xFF;
+ command_data[2] = (value >> 16) & 0xFF;
+ command_data[3] = (value >> 8) & 0xFF;
command_data[4] = value & 0xFF;
break;
}
- case id_switch_matrix_state:
- {
-#if ( (MATRIX_COLS/8+1)*MATRIX_ROWS <= 28 )
+ case id_switch_matrix_state: {
+#if ((MATRIX_COLS / 8 + 1) * MATRIX_ROWS <= 28)
uint8_t i = 1;
- for ( uint8_t row=0; row<MATRIX_ROWS; row++ ) {
+ for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
matrix_row_t value = matrix_get_row(row);
-#if (MATRIX_COLS > 24)
- command_data[i++] = (value >> 24 ) & 0xFF;
-#endif
-#if (MATRIX_COLS > 16)
- command_data[i++] = (value >> 16 ) & 0xFF;
-#endif
-#if (MATRIX_COLS > 8)
- command_data[i++] = (value >> 8 ) & 0xFF;
-#endif
+# if (MATRIX_COLS > 24)
+ command_data[i++] = (value >> 24) & 0xFF;
+# endif
+# if (MATRIX_COLS > 16)
+ command_data[i++] = (value >> 16) & 0xFF;
+# endif
+# if (MATRIX_COLS > 8)
+ command_data[i++] = (value >> 8) & 0xFF;
+# endif
command_data[i++] = value & 0xFF;
}
#endif
break;
}
- default:
- {
- raw_hid_receive_kb(data,length);
+ default: {
+ raw_hid_receive_kb(data, length);
break;
}
}
break;
}
- case id_set_keyboard_value:
- {
- switch ( command_data[0] )
- {
- case id_layout_options:
- {
- uint32_t value = ( (uint32_t)command_data[1] << 24 ) |
- ( (uint32_t)command_data[2] << 16 ) |
- ( (uint32_t)command_data[3] << 8 ) |
- (uint32_t)command_data[4];
+ case id_set_keyboard_value: {
+ switch (command_data[0]) {
+ case id_layout_options: {
+ uint32_t value = ((uint32_t)command_data[1] << 24) | ((uint32_t)command_data[2] << 16) | ((uint32_t)command_data[3] << 8) | (uint32_t)command_data[4];
via_set_layout_options(value);
break;
}
- default:
- {
- raw_hid_receive_kb(data,length);
+ default: {
+ raw_hid_receive_kb(data, length);
break;
}
}
break;
}
- case id_dynamic_keymap_get_keycode:
- {
- uint16_t keycode = dynamic_keymap_get_keycode( command_data[0], command_data[1], command_data[2] );
- command_data[3] = keycode >> 8;
- command_data[4] = keycode & 0xFF;
+ case id_dynamic_keymap_get_keycode: {
+ uint16_t keycode = dynamic_keymap_get_keycode(command_data[0], command_data[1], command_data[2]);
+ command_data[3] = keycode >> 8;
+ command_data[4] = keycode & 0xFF;
break;
}
- case id_dynamic_keymap_set_keycode:
- {
- dynamic_keymap_set_keycode( command_data[0], command_data[1], command_data[2], ( command_data[3] << 8 ) | command_data[4] );
+ case id_dynamic_keymap_set_keycode: {
+ dynamic_keymap_set_keycode(command_data[0], command_data[1], command_data[2], (command_data[3] << 8) | command_data[4]);
break;
}
- case id_dynamic_keymap_reset:
- {
+ case id_dynamic_keymap_reset: {
dynamic_keymap_reset();
break;
}
- case id_backlight_config_set_value:
- case id_backlight_config_get_value:
- case id_backlight_config_save:
- {
+ case id_lighting_set_value: {
+#if defined(VIA_QMK_BACKLIGHT_ENABLE)
+ via_qmk_backlight_set_value(command_data);
+#endif
+#if defined(VIA_QMK_RGBLIGHT_ENABLE)
+ via_qmk_rgblight_set_value(command_data);
+#endif
+#if defined(VIA_CUSTOM_LIGHTING_ENABLE)
raw_hid_receive_kb(data, length);
+#endif
+#if !defined(VIA_QMK_BACKLIGHT_ENABLE) && !defined(VIA_QMK_RGBLIGHT_ENABLE) && !defined(VIA_CUSTOM_LIGHTING_ENABLE)
+ // Return the unhandled state
+ *command_id = id_unhandled;
+#endif
break;
}
- case id_dynamic_keymap_macro_get_count:
- {
+ case id_lighting_get_value: {
+#if defined(VIA_QMK_BACKLIGHT_ENABLE)
+ via_qmk_backlight_get_value(command_data);
+#endif
+#if defined(VIA_QMK_RGBLIGHT_ENABLE)
+ via_qmk_rgblight_get_value(command_data);
+#endif
+#if defined(VIA_CUSTOM_LIGHTING_ENABLE)
+ raw_hid_receive_kb(data, length);
+#endif
+#if !defined(VIA_QMK_BACKLIGHT_ENABLE) && !defined(VIA_QMK_RGBLIGHT_ENABLE) && !defined(VIA_CUSTOM_LIGHTING_ENABLE)
+ // Return the unhandled state
+ *command_id = id_unhandled;
+#endif
+ break;
+ }
+ case id_lighting_save: {
+#if defined(VIA_QMK_BACKLIGHT_ENABLE)
+ eeconfig_update_backlight_current();
+#endif
+#if defined(VIA_QMK_RGBLIGHT_ENABLE)
+ eeconfig_update_rgblight_current();
+#endif
+#if defined(VIA_CUSTOM_LIGHTING_ENABLE)
+ raw_hid_receive_kb(data, length);
+#endif
+#if !defined(VIA_QMK_BACKLIGHT_ENABLE) && !defined(VIA_QMK_RGBLIGHT_ENABLE) && !defined(VIA_CUSTOM_LIGHTING_ENABLE)
+ // Return the unhandled state
+ *command_id = id_unhandled;
+#endif
+ break;
+ }
+ case id_dynamic_keymap_macro_get_count: {
command_data[0] = dynamic_keymap_macro_get_count();
break;
}
- case id_dynamic_keymap_macro_get_buffer_size:
- {
- uint16_t size = dynamic_keymap_macro_get_buffer_size();
+ case id_dynamic_keymap_macro_get_buffer_size: {
+ uint16_t size = dynamic_keymap_macro_get_buffer_size();
command_data[0] = size >> 8;
command_data[1] = size & 0xFF;
break;
}
- case id_dynamic_keymap_macro_get_buffer:
- {
- uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
- uint16_t size = command_data[2]; // size <= 28
- dynamic_keymap_macro_get_buffer( offset, size, &command_data[3] );
+ case id_dynamic_keymap_macro_get_buffer: {
+ uint16_t offset = (command_data[0] << 8) | command_data[1];
+ uint16_t size = command_data[2]; // size <= 28
+ dynamic_keymap_macro_get_buffer(offset, size, &command_data[3]);
break;
}
- case id_dynamic_keymap_macro_set_buffer:
- {
- uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
- uint16_t size = command_data[2]; // size <= 28
- dynamic_keymap_macro_set_buffer( offset, size, &command_data[3] );
+ case id_dynamic_keymap_macro_set_buffer: {
+ uint16_t offset = (command_data[0] << 8) | command_data[1];
+ uint16_t size = command_data[2]; // size <= 28
+ dynamic_keymap_macro_set_buffer(offset, size, &command_data[3]);
break;
}
- case id_dynamic_keymap_macro_reset:
- {
+ case id_dynamic_keymap_macro_reset: {
dynamic_keymap_macro_reset();
break;
}
- case id_dynamic_keymap_get_layer_count:
- {
+ case id_dynamic_keymap_get_layer_count: {
command_data[0] = dynamic_keymap_get_layer_count();
break;
}
- case id_dynamic_keymap_get_buffer:
- {
- uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
- uint16_t size = command_data[2]; // size <= 28
- dynamic_keymap_get_buffer( offset, size, &command_data[3] );
+ case id_dynamic_keymap_get_buffer: {
+ uint16_t offset = (command_data[0] << 8) | command_data[1];
+ uint16_t size = command_data[2]; // size <= 28
+ dynamic_keymap_get_buffer(offset, size, &command_data[3]);
break;
}
- case id_dynamic_keymap_set_buffer:
- {
- uint16_t offset = ( command_data[0] << 8 ) | command_data[1];
- uint16_t size = command_data[2]; // size <= 28
- dynamic_keymap_set_buffer( offset, size, &command_data[3] );
+ case id_dynamic_keymap_set_buffer: {
+ uint16_t offset = (command_data[0] << 8) | command_data[1];
+ uint16_t size = command_data[2]; // size <= 28
+ dynamic_keymap_set_buffer(offset, size, &command_data[3]);
break;
}
- case id_eeprom_reset:
- {
+ case id_eeprom_reset: {
via_eeprom_reset();
break;
}
- case id_bootloader_jump:
- {
+ case id_bootloader_jump: {
// Need to send data back before the jump
// Informs host that the command is handled
- raw_hid_send( data, length );
+ raw_hid_send(data, length);
// Give host time to read it
wait_ms(100);
bootloader_jump();
break;
}
- default:
- {
+ default: {
// The command ID is not known
// Return the unhandled state
*command_id = id_unhandled;
@@ -396,5 +423,111 @@ void raw_hid_receive( uint8_t *data, uint8_t length )
// Return the same buffer, optionally with values changed
// (i.e. returning state to the host, or the unhandled state).
- raw_hid_send( data, length );
+ raw_hid_send(data, length);
}
+
+#if defined(VIA_QMK_BACKLIGHT_ENABLE)
+
+# if BACKLIGHT_LEVELS == 0
+# error BACKLIGHT_LEVELS == 0
+# endif
+
+void via_qmk_backlight_get_value(uint8_t *data) {
+ uint8_t *value_id = &(data[0]);
+ uint8_t *value_data = &(data[1]);
+ switch (*value_id) {
+ case id_qmk_backlight_brightness: {
+ // level / BACKLIGHT_LEVELS * 255
+ value_data[0] = ((uint16_t)get_backlight_level()) * 255 / BACKLIGHT_LEVELS;
+ break;
+ }
+ case id_qmk_backlight_effect: {
+# ifdef BACKLIGHT_BREATHING
+ value_data[0] = is_backlight_breathing() ? 1 : 0;
+# else
+ value_data[0] = 0;
+# endif
+ break;
+ }
+ }
+}
+
+void via_qmk_backlight_set_value(uint8_t *data) {
+ uint8_t *value_id = &(data[0]);
+ uint8_t *value_data = &(data[1]);
+ switch (*value_id) {
+ case id_qmk_backlight_brightness: {
+ // level / 255 * BACKLIGHT_LEVELS
+ backlight_level_noeeprom(((uint16_t)value_data[0]) * BACKLIGHT_LEVELS / 255);
+ break;
+ }
+ case id_qmk_backlight_effect: {
+# ifdef BACKLIGHT_BREATHING
+ if (value_data[0] == 0) {
+ backlight_disable_breathing();
+ } else {
+ backlight_enable_breathing();
+ }
+# endif
+ break;
+ }
+ }
+}
+
+#endif // #if defined(VIA_QMK_BACKLIGHT_ENABLE)
+
+#if defined(VIA_QMK_RGBLIGHT_ENABLE)
+
+void via_qmk_rgblight_get_value(uint8_t *data) {
+ uint8_t *value_id = &(data[0]);
+ uint8_t *value_data = &(data[1]);
+ switch (*value_id) {
+ case id_qmk_rgblight_brightness: {
+ value_data[0] = rgblight_get_val();
+ break;
+ }
+ case id_qmk_rgblight_effect: {
+ value_data[0] = rgblight_get_mode();
+ break;
+ }
+ case id_qmk_rgblight_effect_speed: {
+ value_data[0] = rgblight_get_speed();
+ break;
+ }
+ case id_qmk_rgblight_color: {
+ value_data[0] = rgblight_get_hue();
+ value_data[1] = rgblight_get_sat();
+ break;
+ }
+ }
+}
+
+void via_qmk_rgblight_set_value(uint8_t *data) {
+ uint8_t *value_id = &(data[0]);
+ uint8_t *value_data = &(data[1]);
+ switch (*value_id) {
+ case id_qmk_rgblight_brightness: {
+ rgblight_sethsv_noeeprom(rgblight_get_hue(), rgblight_get_sat(), value_data[0]);
+ break;
+ }
+ case id_qmk_rgblight_effect: {
+ rgblight_mode_noeeprom(value_data[0]);
+ if (value_data[0] == 0) {
+ rgblight_disable_noeeprom();
+ } else {
+ rgblight_enable_noeeprom();
+ }
+ break;
+ }
+ case id_qmk_rgblight_effect_speed: {
+ rgblight_set_speed_noeeprom(value_data[0]);
+ break;
+ }
+ case id_qmk_rgblight_color: {
+ rgblight_sethsv_noeeprom(value_data[0], value_data[1], rgblight_get_val());
+ break;
+ }
+ }
+}
+
+#endif // #if defined(VIA_QMK_RGBLIGHT_ENABLE)
diff --git a/quantum/via.h b/quantum/via.h
index f9a8017b24..012547e055 100644
--- a/quantum/via.h
+++ b/quantum/via.h
@@ -16,7 +16,7 @@
#pragma once
-#include <tmk_core/common/eeconfig.h> // for EECONFIG_SIZE
+#include <tmk_core/common/eeconfig.h> // for EECONFIG_SIZE
// Keyboard level code can change where VIA stores the magic.
// The magic is the build date YYMMDD encoded as BCD in 3 bytes,
@@ -25,60 +25,70 @@
// The only reason this is important is in case EEPROM usage changes
// and the EEPROM was not explicitly reset by bootmagic lite.
#ifndef VIA_EEPROM_MAGIC_ADDR
-# define VIA_EEPROM_MAGIC_ADDR (EECONFIG_SIZE)
+# define VIA_EEPROM_MAGIC_ADDR (EECONFIG_SIZE)
#endif
-#define VIA_EEPROM_LAYOUT_OPTIONS_ADDR (VIA_EEPROM_MAGIC_ADDR+3)
+#define VIA_EEPROM_LAYOUT_OPTIONS_ADDR (VIA_EEPROM_MAGIC_ADDR + 3)
// Changing the layout options size after release will invalidate EEPROM,
// but this is something that should be set correctly on initial implementation.
// 1 byte is enough for most uses (i.e. 8 binary states, or 6 binary + 1 ternary/quaternary )
#ifndef VIA_EEPROM_LAYOUT_OPTIONS_SIZE
-# define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 1
+# define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 1
#endif
// The end of the EEPROM memory used by VIA
// By default, dynamic keymaps will start at this if there is no
// custom config
-#define VIA_EEPROM_CUSTOM_CONFIG_ADDR (VIA_EEPROM_LAYOUT_OPTIONS_ADDR+VIA_EEPROM_LAYOUT_OPTIONS_SIZE)
+#define VIA_EEPROM_CUSTOM_CONFIG_ADDR (VIA_EEPROM_LAYOUT_OPTIONS_ADDR + VIA_EEPROM_LAYOUT_OPTIONS_SIZE)
#ifndef VIA_EEPROM_CUSTOM_CONFIG_SIZE
-# define VIA_EEPROM_CUSTOM_CONFIG_SIZE 0
+# define VIA_EEPROM_CUSTOM_CONFIG_SIZE 0
#endif
// This is changed only when the command IDs change,
-// so VIA Configurator can detect compatible firmware.
+// so VIA Configurator can detect compatible firmware.
#define VIA_PROTOCOL_VERSION 0x0009
-enum via_command_id
-{
- id_get_protocol_version = 0x01, // always 0x01
- id_get_keyboard_value,
- id_set_keyboard_value,
- id_dynamic_keymap_get_keycode,
- id_dynamic_keymap_set_keycode,
- id_dynamic_keymap_reset,
- id_backlight_config_set_value,
- id_backlight_config_get_value,
- id_backlight_config_save,
- id_eeprom_reset,
- id_bootloader_jump,
- id_dynamic_keymap_macro_get_count,
- id_dynamic_keymap_macro_get_buffer_size,
- id_dynamic_keymap_macro_get_buffer,
- id_dynamic_keymap_macro_set_buffer,
- id_dynamic_keymap_macro_reset,
- id_dynamic_keymap_get_layer_count,
- id_dynamic_keymap_get_buffer,
- id_dynamic_keymap_set_buffer,
- id_unhandled = 0xFF,
+enum via_command_id {
+ id_get_protocol_version = 0x01, // always 0x01
+ id_get_keyboard_value = 0x02,
+ id_set_keyboard_value = 0x03,
+ id_dynamic_keymap_get_keycode = 0x04,
+ id_dynamic_keymap_set_keycode = 0x05,
+ id_dynamic_keymap_reset = 0x06,
+ id_lighting_set_value = 0x07,
+ id_lighting_get_value = 0x08,
+ id_lighting_save = 0x09,
+ id_eeprom_reset = 0x0A,
+ id_bootloader_jump = 0x0B,
+ id_dynamic_keymap_macro_get_count = 0x0C,
+ id_dynamic_keymap_macro_get_buffer_size = 0x0D,
+ id_dynamic_keymap_macro_get_buffer = 0x0E,
+ id_dynamic_keymap_macro_set_buffer = 0x0F,
+ id_dynamic_keymap_macro_reset = 0x10,
+ id_dynamic_keymap_get_layer_count = 0x11,
+ id_dynamic_keymap_get_buffer = 0x12,
+ id_dynamic_keymap_set_buffer = 0x13,
+ id_unhandled = 0xFF,
};
-enum via_keyboard_value_id
-{
- id_uptime = 0x01,
- id_layout_options,
- id_switch_matrix_state
+enum via_keyboard_value_id {
+ id_uptime = 0x01, //
+ id_layout_options = 0x02,
+ id_switch_matrix_state = 0x03
+};
+
+enum via_lighting_value {
+ // QMK BACKLIGHT
+ id_qmk_backlight_brightness = 0x09,
+ id_qmk_backlight_effect = 0x0A,
+
+ // QMK RGBLIGHT
+ id_qmk_rgblight_brightness = 0x80,
+ id_qmk_rgblight_effect = 0x81,
+ id_qmk_rgblight_effect_speed = 0x82,
+ id_qmk_rgblight_color = 0x83,
};
// Can't use SAFE_RANGE here, it might change if someone adds
@@ -108,22 +118,22 @@ enum via_keycodes {
};
enum user_keycodes {
- USER00 = 0x5F80,
- USER01,
- USER02,
- USER03,
- USER04,
- USER05,
- USER06,
- USER07,
- USER08,
- USER09,
- USER10,
- USER11,
- USER12,
- USER13,
- USER14,
- USER15,
+ USER00 = 0x5F80,
+ USER01,
+ USER02,
+ USER03,
+ USER04,
+ USER05,
+ USER06,
+ USER07,
+ USER08,
+ USER09,
+ USER10,
+ USER11,
+ USER12,
+ USER13,
+ USER14,
+ USER15,
};
// Can be called in an overriding via_init_kb() to test if keyboard level code usage of
@@ -144,8 +154,7 @@ void via_init(void);
// Used by VIA to store and retrieve the layout options.
uint32_t via_get_layout_options(void);
-void via_set_layout_options(uint32_t value);
+void via_set_layout_options(uint32_t value);
// Called by QMK core to process VIA-specific keycodes.
bool process_record_via(uint16_t keycode, keyrecord_t *record);
-