summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/action.c19
-rw-r--r--quantum/action_util.c25
-rw-r--r--quantum/action_util.h13
-rw-r--r--quantum/audio/audio.c45
-rw-r--r--quantum/debounce/asym_eager_defer_pk.c2
-rw-r--r--quantum/debounce/sym_eager_pk.c1
-rw-r--r--quantum/debounce/sym_eager_pr.c1
-rw-r--r--quantum/dynamic_keymap.c15
-rw-r--r--quantum/keymap.h20
-rw-r--r--quantum/led.c6
-rw-r--r--quantum/led.h7
-rw-r--r--quantum/led_matrix/led_matrix.c5
-rw-r--r--quantum/led_matrix/led_matrix.h3
-rw-r--r--quantum/mousekey.c68
-rw-r--r--quantum/painter/lvgl/qp_lvgl.c2
-rw-r--r--quantum/painter/qp.c29
-rw-r--r--quantum/painter/qp_comms.c8
-rw-r--r--quantum/painter/qp_draw_circle.c2
-rw-r--r--quantum/painter/qp_draw_core.c6
-rw-r--r--quantum/painter/qp_draw_ellipse.c2
-rw-r--r--quantum/painter/qp_draw_image.c6
-rw-r--r--quantum/painter/qp_draw_text.c8
-rw-r--r--quantum/process_keycode/process_auto_shift.c10
-rw-r--r--quantum/process_keycode/process_auto_shift.h8
-rw-r--r--quantum/process_keycode/process_autocorrect.c74
-rw-r--r--quantum/process_keycode/process_autocorrect.h4
-rw-r--r--quantum/process_keycode/process_dynamic_macro.c117
-rw-r--r--quantum/process_keycode/process_dynamic_macro.h1
-rw-r--r--quantum/process_keycode/process_key_override.c9
-rw-r--r--quantum/quantum.c8
-rw-r--r--quantum/quantum_keycodes.h4
-rw-r--r--quantum/quantum_keycodes_legacy.h3
-rw-r--r--quantum/rgb_matrix/animations/pixel_fractal_anim.h6
-rw-r--r--quantum/rgb_matrix/animations/pixel_rain_anim.h10
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c5
-rw-r--r--quantum/rgb_matrix/rgb_matrix.h3
-rw-r--r--quantum/rgb_matrix/rgb_matrix_drivers.c15
-rw-r--r--quantum/split_common/transactions.c2
-rw-r--r--quantum/via.c99
-rw-r--r--quantum/via.h14
40 files changed, 487 insertions, 198 deletions
diff --git a/quantum/action.c b/quantum/action.c
index a45e70c557..6368f7398c 100644
--- a/quantum/action.c
+++ b/quantum/action.c
@@ -528,6 +528,13 @@ void process_action(keyrecord_t *record, action_t action) {
unregister_code(action.key.code);
} else {
ac_dprintf("MODS_TAP: No tap: add_mods\n");
+# if defined(RETRO_TAPPING) && defined(DUMMY_MOD_NEUTRALIZER_KEYCODE)
+ // Send a dummy keycode to neutralize flashing modifiers
+ // if the key was held and then released with no interruptions.
+ if (retro_tapping_counter == 2) {
+ neutralize_flashing_modifiers(get_mods());
+ }
+# endif
unregister_mods(mods);
}
}
@@ -882,7 +889,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is on
- if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return;
+ if (host_keyboard_led_state().caps_lock) return;
# endif
add_key(KC_CAPS_LOCK);
send_keyboard_report();
@@ -892,7 +899,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
- if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return;
+ if (host_keyboard_led_state().num_lock) return;
# endif
add_key(KC_NUM_LOCK);
send_keyboard_report();
@@ -902,7 +909,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
- if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return;
+ if (host_keyboard_led_state().scroll_lock) return;
# endif
add_key(KC_SCROLL_LOCK);
send_keyboard_report();
@@ -952,7 +959,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
} else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is off
- if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return;
+ if (!host_keyboard_led_state().caps_lock) return;
# endif
add_key(KC_CAPS_LOCK);
send_keyboard_report();
@@ -961,7 +968,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
} else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
- if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return;
+ if (!host_keyboard_led_state().num_lock) return;
# endif
add_key(KC_NUM_LOCK);
send_keyboard_report();
@@ -970,7 +977,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
} else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
- if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return;
+ if (!host_keyboard_led_state().scroll_lock) return;
# endif
add_key(KC_SCROLL_LOCK);
send_keyboard_report();
diff --git a/quantum/action_util.c b/quantum/action_util.c
index 361f410d2d..909dea0595 100644
--- a/quantum/action_util.c
+++ b/quantum/action_util.c
@@ -500,3 +500,28 @@ __attribute__((weak)) void oneshot_layer_changed_kb(uint8_t layer) {
uint8_t has_anymod(void) {
return bitpop(real_mods);
}
+
+#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE
+/** \brief Send a dummy keycode in between the register and unregister event of a modifier key, to neutralize the "flashing modifiers" phenomenon.
+ *
+ * \param active_mods 8-bit packed bit-array describing the currently active modifiers (in the format GASCGASC).
+ *
+ * Certain QMK features like key overrides or retro tap must unregister a previously
+ * registered modifier before sending another keycode but this can trigger undesired
+ * keyboard shortcuts if the clean tap of a single modifier key is bound to an action
+ * on the host OS, as is for example the case for the left GUI key on Windows, which
+ * opens the Start Menu when tapped.
+ */
+void neutralize_flashing_modifiers(uint8_t active_mods) {
+ // In most scenarios, the flashing modifiers phenomenon is a problem
+ // only for a subset of modifier masks.
+ const static uint8_t mods_to_neutralize[] = MODS_TO_NEUTRALIZE;
+ const static uint8_t n_mods = ARRAY_SIZE(mods_to_neutralize);
+ for (uint8_t i = 0; i < n_mods; ++i) {
+ if (active_mods == mods_to_neutralize[i]) {
+ tap_code(DUMMY_MOD_NEUTRALIZER_KEYCODE);
+ break;
+ }
+ }
+}
+#endif
diff --git a/quantum/action_util.h b/quantum/action_util.h
index 02f6e9e6df..831caf3c0a 100644
--- a/quantum/action_util.h
+++ b/quantum/action_util.h
@@ -102,6 +102,19 @@ void use_oneshot_swaphands(void);
void clear_oneshot_swaphands(void);
#endif
+#ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE
+// KC_A is used as the lowerbound instead of QK_BASIC because the range QK_BASIC...KC_A includes
+// internal keycodes like KC_NO and KC_TRANSPARENT which are unsuitable for use with `tap_code(kc)`.
+# if !(KC_A <= DUMMY_MOD_NEUTRALIZER_KEYCODE && DUMMY_MOD_NEUTRALIZER_KEYCODE <= QK_BASIC_MAX)
+# error "DUMMY_MOD_NEUTRALIZER_KEYCODE must be a basic, unmodified, HID keycode!"
+# endif
+void neutralize_flashing_modifiers(uint8_t active_mods);
+#endif
+#ifndef MODS_TO_NEUTRALIZE
+# define MODS_TO_NEUTRALIZE \
+ { MOD_BIT(KC_LEFT_ALT), MOD_BIT(KC_LEFT_GUI) }
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index 2570ad9cd1..0300483a93 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -547,20 +547,39 @@ void audio_decrease_tempo(uint8_t tempo_change) {
note_tempo -= tempo_change;
}
-// TODO in the int-math version are some bugs; songs sometimes abruptly end - maybe an issue with the timer/system-tick wrapping around?
+/**
+ * Converts from units of 1/64ths of a beat to milliseconds.
+ *
+ * Round-off error is at most 1 millisecond.
+ *
+ * Conversion will never overflow for duration_bpm <= 699, provided that
+ * note_tempo is at least 10. This is quite a long duration, over ten beats.
+ *
+ * Beware that for duration_bpm > 699, the result may overflow uint16_t range
+ * when duration_bpm is large compared to note_tempo:
+ *
+ * duration_bpm * 60 * 1000 / (64 * note_tempo) > UINT16_MAX
+ *
+ * duration_bpm > (2 * 65535 / 1875) * note_tempo
+ * = 69.904 * note_tempo.
+ */
uint16_t audio_duration_to_ms(uint16_t duration_bpm) {
-#if defined(__AVR__)
- // doing int-math saves us some bytes in the overall firmware size, but the intermediate result is less accurate before being cast to/returned as uint
- return ((uint32_t)duration_bpm * 60 * 1000) / (64 * note_tempo);
- // NOTE: beware of uint16_t overflows when note_tempo is low and/or the duration is long
-#else
- return ((float)duration_bpm * 60) / (64 * note_tempo) * 1000;
-#endif
+ return ((uint32_t)duration_bpm * 1875) / ((uint_fast16_t)note_tempo * 2);
}
+
+/**
+ * Converts from units of milliseconds to 1/64ths of a beat.
+ *
+ * Round-off error is at most 1/64th of a beat.
+ *
+ * This conversion never overflows: since duration_ms <= UINT16_MAX = 65535
+ * and note_tempo <= 255, the result is always in uint16_t range:
+ *
+ * duration_ms * 64 * note_tempo / 60 / 1000
+ * <= 65535 * 2 * 255 / 1875
+ * = 17825.52
+ * <= UINT16_MAX.
+ */
uint16_t audio_ms_to_duration(uint16_t duration_ms) {
-#if defined(__AVR__)
- return ((uint32_t)duration_ms * 64 * note_tempo) / 60 / 1000;
-#else
- return ((float)duration_ms * 64 * note_tempo) / 60 / 1000;
-#endif
+ return ((uint32_t)duration_ms * 2 * note_tempo) / 1875;
}
diff --git a/quantum/debounce/asym_eager_defer_pk.c b/quantum/debounce/asym_eager_defer_pk.c
index 4745c6f465..0f7640a80c 100644
--- a/quantum/debounce/asym_eager_defer_pk.c
+++ b/quantum/debounce/asym_eager_defer_pk.c
@@ -144,6 +144,8 @@ static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[],
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) {
debounce_counter_t *debounce_pointer = debounce_counters;
+ matrix_need_update = false;
+
for (uint8_t row = 0; row < num_rows; row++) {
matrix_row_t delta = raw[row] ^ cooked[row];
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
diff --git a/quantum/debounce/sym_eager_pk.c b/quantum/debounce/sym_eager_pk.c
index f736d1645c..15360441de 100644
--- a/quantum/debounce/sym_eager_pk.c
+++ b/quantum/debounce/sym_eager_pk.c
@@ -125,6 +125,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) {
// upload from raw_matrix to final matrix;
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) {
+ matrix_need_update = false;
debounce_counter_t *debounce_pointer = debounce_counters;
for (uint8_t row = 0; row < num_rows; row++) {
matrix_row_t delta = raw[row] ^ cooked[row];
diff --git a/quantum/debounce/sym_eager_pr.c b/quantum/debounce/sym_eager_pr.c
index aad5ca351b..84f897d674 100644
--- a/quantum/debounce/sym_eager_pr.c
+++ b/quantum/debounce/sym_eager_pr.c
@@ -119,6 +119,7 @@ static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time) {
// upload from raw_matrix to final matrix;
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows) {
+ matrix_need_update = false;
debounce_counter_t *debounce_pointer = debounce_counters;
for (uint8_t row = 0; row < num_rows; row++) {
matrix_row_t existing_row = cooked[row];
diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c
index 90a0f20838..2030c82a1b 100644
--- a/quantum/dynamic_keymap.c
+++ b/quantum/dynamic_keymap.c
@@ -152,22 +152,13 @@ void dynamic_keymap_reset(void) {
for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
for (int row = 0; row < MATRIX_ROWS; row++) {
for (int column = 0; column < MATRIX_COLS; column++) {
- if (layer < keymap_layer_count()) {
- dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column));
- } else {
- dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT);
- }
+ dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column));
}
}
#ifdef ENCODER_MAP_ENABLE
for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
- if (layer < encodermap_layer_count()) {
- dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true));
- dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false));
- } else {
- dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT);
- dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT);
- }
+ dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true));
+ dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false));
}
#endif // ENCODER_MAP_ENABLE
}
diff --git a/quantum/keymap.h b/quantum/keymap.h
deleted file mode 100644
index a067e1aa36..0000000000
--- a/quantum/keymap.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
-Copyright 2012-2016 Jun Wako <wakojun@gmail.com>
-
-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
-
-#pragma message("'keymap.h' should no longer be included!")
diff --git a/quantum/led.c b/quantum/led.c
index 42144566fd..8d86374a6f 100644
--- a/quantum/led.c
+++ b/quantum/led.c
@@ -153,14 +153,14 @@ __attribute__((weak)) void led_set(uint8_t usb_led) {
/** \brief Trigger behaviour on transition to suspend
*/
void led_suspend(void) {
- uint8_t leds_off = 0;
+ led_t leds_off = {0};
#ifdef BACKLIGHT_CAPS_LOCK
if (is_backlight_enabled()) {
// Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
- leds_off |= (1 << USB_LED_CAPS_LOCK);
+ leds_off.caps_lock = true;
}
#endif
- led_set(leds_off);
+ led_set(leds_off.raw);
}
/** \brief Trigger behaviour on transition from suspend
diff --git a/quantum/led.h b/quantum/led.h
index b9ad7ed9ae..b9fad670ae 100644
--- a/quantum/led.h
+++ b/quantum/led.h
@@ -22,13 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* FIXME: Add doxygen comments here. */
-/* keyboard LEDs */
-#define USB_LED_NUM_LOCK 0
-#define USB_LED_CAPS_LOCK 1
-#define USB_LED_SCROLL_LOCK 2
-#define USB_LED_COMPOSE 3
-#define USB_LED_KANA 4
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index 828d61641a..4b692d1904 100644
--- a/quantum/led_matrix/led_matrix.c
+++ b/quantum/led_matrix/led_matrix.c
@@ -366,7 +366,10 @@ void led_matrix_task(void) {
case RENDERING:
led_task_render(effect);
if (effect) {
- led_matrix_indicators();
+ // Only run the basic indicators in the last render iteration (default there are 5 iterations)
+ if (led_effect_params.iter == LED_MATRIX_LED_PROCESS_MAX_ITERATIONS) {
+ led_matrix_indicators();
+ }
led_matrix_indicators_advanced(&led_effect_params);
}
break;
diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h
index c7d360f366..9091f6890b 100644
--- a/quantum/led_matrix/led_matrix.h
+++ b/quantum/led_matrix/led_matrix.h
@@ -42,8 +42,9 @@
#endif
#ifndef LED_MATRIX_LED_PROCESS_LIMIT
-# define LED_MATRIX_LED_PROCESS_LIMIT (LED_MATRIX_LED_COUNT + 4) / 5
+# define LED_MATRIX_LED_PROCESS_LIMIT ((LED_MATRIX_LED_COUNT + 4) / 5)
#endif
+#define LED_MATRIX_LED_PROCESS_MAX_ITERATIONS ((LED_MATRIX_LED_COUNT + LED_MATRIX_LED_PROCESS_LIMIT - 1) / LED_MATRIX_LED_PROCESS_LIMIT)
#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT
# if defined(LED_MATRIX_SPLIT)
diff --git a/quantum/mousekey.c b/quantum/mousekey.c
index df8aa613be..c982a2f40b 100644
--- a/quantum/mousekey.c
+++ b/quantum/mousekey.c
@@ -25,11 +25,16 @@
#include "mousekey.h"
static inline int8_t times_inv_sqrt2(int8_t x) {
- // 181/256 is pretty close to 1/sqrt(2)
- // 0.70703125 0.707106781
- // 1 too small for x=99 and x=198
- // This ends up being a mult and discard lower 8 bits
- return (x * 181) >> 8;
+ // 181/256 (0.70703125) is used as an approximation for 1/sqrt(2)
+ // because it is close to the exact value which is 0.707106781
+ const int16_t n = x * 181;
+ const uint16_t d = 256;
+
+ // To ensure that the integer result is rounded accurately after
+ // division, check the sign of the numerator:
+ // If negative, subtract half of the denominator before dividing
+ // Otherwise, add half of the denominator before dividing
+ return n < 0 ? (n - d / 2) / d : (n + d / 2) / d;
}
static report_mouse_t mouse_report = {0};
@@ -74,7 +79,7 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
/* milliseconds between repeated motion events (0-255) */
# ifdef MK_KINETIC_SPEED
-float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
+uint16_t mk_wheel_interval = 1000U / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
# else
uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
# endif
@@ -175,7 +180,7 @@ static uint8_t wheel_unit(void) {
/*
* Kinetic movement acceleration algorithm
*
- * current speed = I + A * T/50 + A * 0.5 * T^2 | maximum B
+ * current speed = I + A * T/50 + A * (T/50)^2 * 1/2 | maximum B
*
* T: time since the mouse movement started
* E: mouse events per second (set through MOUSEKEY_INTERVAL, UHK sends 250, the
@@ -190,39 +195,48 @@ const uint16_t mk_decelerated_speed = MOUSEKEY_DECELERATED_SPEED;
const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED;
static uint8_t move_unit(void) {
- float speed = mk_initial_speed;
+ uint16_t speed = mk_initial_speed;
- if (mousekey_accel & ((1 << 0) | (1 << 2))) {
- speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed;
+ if (mousekey_accel & (1 << 0)) {
+ speed = mk_decelerated_speed;
+ } else if (mousekey_accel & (1 << 2)) {
+ speed = mk_accelerated_speed;
} else if (mousekey_repeat && mouse_timer) {
- const float time_elapsed = timer_elapsed(mouse_timer) / 50;
- speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed;
-
- speed = speed > mk_base_speed ? mk_base_speed : speed;
+ const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
+ speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + (MOUSEKEY_MOVE_DELTA * time_elapsed * time_elapsed) / 2;
+ if (speed > mk_base_speed) {
+ speed = mk_base_speed;
+ }
}
-
/* convert speed to USB mouse speed 1 to 127 */
- speed = (uint8_t)(speed / (1000.0f / mk_interval));
- speed = speed < 1 ? 1 : speed;
+ speed = (uint8_t)(speed / (1000U / mk_interval));
- return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
+ if (speed > MOUSEKEY_MOVE_MAX) {
+ speed = MOUSEKEY_MOVE_MAX;
+ } else if (speed < 1) {
+ speed = 1;
+ }
+ return speed;
}
static uint8_t wheel_unit(void) {
- float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
+ uint16_t speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
- if (mousekey_accel & ((1 << 0) | (1 << 2))) {
- speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
+ if (mousekey_accel & (1 << 0)) {
+ speed = MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
+ } else if (mousekey_accel & (1 << 2)) {
+ speed = MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS;
} else if (mousekey_wheel_repeat && mouse_timer) {
if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
- const float time_elapsed = timer_elapsed(mouse_timer) / 50;
- speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
+ const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
+ speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + (1 * time_elapsed * time_elapsed) / 2;
+ }
+ if (speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
+ speed = MOUSEKEY_WHEEL_BASE_MOVEMENTS;
}
- speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
}
- mk_wheel_interval = 1000.0f / speed;
-
- return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1;
+ mk_wheel_interval = 1000U / speed;
+ return 1;
}
# endif /* #ifndef MK_KINETIC_SPEED */
diff --git a/quantum/painter/lvgl/qp_lvgl.c b/quantum/painter/lvgl/qp_lvgl.c
index 6cc0061d73..280aeaf91f 100644
--- a/quantum/painter/lvgl/qp_lvgl.c
+++ b/quantum/painter/lvgl/qp_lvgl.c
@@ -61,7 +61,7 @@ bool qp_lvgl_attach(painter_device_t device) {
qp_lvgl_detach();
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_lvgl_attach: fail (validation_ok == false)\n");
qp_lvgl_detach();
return false;
diff --git a/quantum/painter/qp.c b/quantum/painter/qp.c
index aea9381b60..f27bb7892a 100644
--- a/quantum/painter/qp.c
+++ b/quantum/painter/qp.c
@@ -30,6 +30,11 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) {
qp_dprintf("qp_init: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
+ if (!driver) {
+ qp_dprintf("qp_init: fail (pointer to NULL)\n");
+ return false;
+ }
+
driver->validate_ok = false;
if (!validate_driver_integrity(driver)) {
qp_dprintf("Failed to validate driver integrity in qp_init\n");
@@ -65,7 +70,7 @@ bool qp_init(painter_device_t device, painter_rotation_t rotation) {
bool qp_power(painter_device_t device, bool power_on) {
qp_dprintf("qp_power: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_power: fail (validation_ok == false)\n");
return false;
}
@@ -87,7 +92,7 @@ bool qp_power(painter_device_t device, bool power_on) {
bool qp_clear(painter_device_t device) {
qp_dprintf("qp_clear: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_clear: fail (validation_ok == false)\n");
return false;
}
@@ -109,7 +114,7 @@ bool qp_clear(painter_device_t device) {
bool qp_flush(painter_device_t device) {
qp_dprintf("qp_flush: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_flush: fail (validation_ok == false)\n");
return false;
}
@@ -129,9 +134,14 @@ bool qp_flush(painter_device_t device) {
// Quantum Painter External API: qp_get_geometry
void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height, painter_rotation_t *rotation, uint16_t *offset_x, uint16_t *offset_y) {
- qp_dprintf("qp_geometry: entry\n");
+ qp_dprintf("qp_get_geometry: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
+ if (!driver) {
+ qp_dprintf("qp_get_geometry: fail (pointer to NULL)\n");
+ return;
+ }
+
switch (driver->rotation) {
default:
case QP_ROTATION_0:
@@ -166,7 +176,7 @@ void qp_get_geometry(painter_device_t device, uint16_t *width, uint16_t *height,
*offset_y = driver->offset_y;
}
- qp_dprintf("qp_geometry: ok\n");
+ qp_dprintf("qp_get_geometry: ok\n");
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -176,6 +186,11 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_
qp_dprintf("qp_set_viewport_offsets: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
+ if (!driver) {
+ qp_dprintf("qp_set_viewport_offsets: fail (pointer to NULL)\n");
+ return;
+ }
+
driver->offset_x = offset_x;
driver->offset_y = offset_y;
@@ -188,7 +203,7 @@ void qp_set_viewport_offsets(painter_device_t device, uint16_t offset_x, uint16_
bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom) {
qp_dprintf("qp_viewport: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_viewport: fail (validation_ok == false)\n");
return false;
}
@@ -211,7 +226,7 @@ bool qp_viewport(painter_device_t device, uint16_t left, uint16_t top, uint16_t
bool qp_pixdata(painter_device_t device, const void *pixel_data, uint32_t native_pixel_count) {
qp_dprintf("qp_pixdata: entry\n");
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_pixdata: fail (validation_ok == false)\n");
return false;
}
diff --git a/quantum/painter/qp_comms.c b/quantum/painter/qp_comms.c
index bcc6de8f2e..63667783e1 100644
--- a/quantum/painter/qp_comms.c
+++ b/quantum/painter/qp_comms.c
@@ -8,7 +8,7 @@
bool qp_comms_init(painter_device_t device) {
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_comms_init: fail (validation_ok == false)\n");
return false;
}
@@ -18,7 +18,7 @@ bool qp_comms_init(painter_device_t device) {
bool qp_comms_start(painter_device_t device) {
painter_driver_t *driver = (painter_driver_t *)device;
- if (!driver->validate_ok) {
+ if (!driver || !driver->validate_ok) {
qp_dprintf("qp_comms_start: fail (validation_ok == false)\n");
return false;
}
@@ -28,7 +28,7 @@ bool qp_comms_start(painter_device_t device) {
void qp_comms_stop(painter_device_t device) {