diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/backlight/backlight_driver_common.c | 2 | ||||
-rw-r--r-- | quantum/backlight/backlight_software.c | 2 | ||||
-rw-r--r-- | quantum/dip_switch.c | 4 | ||||
-rw-r--r-- | quantum/encoder.c | 8 | ||||
-rw-r--r-- | quantum/encoder.h | 8 | ||||
-rw-r--r-- | quantum/pointing_device/pointing_device.c | 8 | ||||
-rw-r--r-- | quantum/pointing_device/pointing_device_drivers.c | 22 | ||||
-rw-r--r-- | quantum/pointing_device_internal.h | 14 | ||||
-rw-r--r-- | quantum/process_keycode/process_leader.c | 2 | ||||
-rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 19 | ||||
-rw-r--r-- | quantum/process_keycode/process_unicode_common.h | 3 | ||||
-rw-r--r-- | quantum/quantum.c | 4 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix_drivers.c | 2 | ||||
-rw-r--r-- | quantum/secure.c | 3 | ||||
-rw-r--r-- | quantum/util.h | 52 |
15 files changed, 100 insertions, 53 deletions
diff --git a/quantum/backlight/backlight_driver_common.c b/quantum/backlight/backlight_driver_common.c index e4c2e90b5f..1eb8969084 100644 --- a/quantum/backlight/backlight_driver_common.c +++ b/quantum/backlight/backlight_driver_common.c @@ -9,7 +9,7 @@ #if defined(BACKLIGHT_PINS) static const pin_t backlight_pins[] = BACKLIGHT_PINS; # ifndef BACKLIGHT_LED_COUNT -# define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t)) +# define BACKLIGHT_LED_COUNT ARRAY_SIZE(backlight_pins) # endif # define FOR_EACH_LED(x) \ diff --git a/quantum/backlight/backlight_software.c b/quantum/backlight/backlight_software.c index 3d412cab52..27ccbd2c9f 100644 --- a/quantum/backlight/backlight_software.c +++ b/quantum/backlight/backlight_software.c @@ -26,7 +26,7 @@ static const uint16_t backlight_duty_table[] = { 0b1110111011101110, 0b1111111111111111, }; -#define backlight_duty_table_size (sizeof(backlight_duty_table) / sizeof(backlight_duty_table[0])) +#define backlight_duty_table_size ARRAY_SIZE(backlight_duty_table) // clang-format on diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c index eee29aaf91..e180cfccdf 100644 --- a/quantum/dip_switch.c +++ b/quantum/dip_switch.c @@ -33,7 +33,7 @@ #endif #ifdef DIP_SWITCH_PINS -# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t)) +# define NUMBER_OF_DIP_SWITCHES (ARRAY_SIZE(dip_switch_pad)) static pin_t dip_switch_pad[] = DIP_SWITCH_PINS; #endif @@ -43,7 +43,7 @@ typedef struct matrix_index_t { uint8_t col; } matrix_index_t; -# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(matrix_index_t)) +# define NUMBER_OF_DIP_SWITCHES (ARRAY_SIZE(dip_switch_pad)) static matrix_index_t dip_switch_pad[] = DIP_SWITCH_MATRIX_GRID; extern bool peek_matrix(uint8_t row_index, uint8_t col_index, bool read_raw); static uint16_t scan_count; diff --git a/quantum/encoder.c b/quantum/encoder.c index 5f8a7ce080..1393e34868 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -24,7 +24,8 @@ #include <string.h> #ifndef ENCODER_MAP_KEY_DELAY -# define ENCODER_MAP_KEY_DELAY 2 +# include "action.h" +# define ENCODER_MAP_KEY_DELAY TAP_CODE_DELAY #endif #if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION) @@ -143,9 +144,14 @@ void encoder_init(void) { static void encoder_exec_mapping(uint8_t index, bool clockwise) { // The delays below cater for Windows and its wonderful requirements. action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true)); +# if ENCODER_MAP_KEY_DELAY > 0 wait_ms(ENCODER_MAP_KEY_DELAY); +# endif // ENCODER_MAP_KEY_DELAY > 0 + action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false)); +# if ENCODER_MAP_KEY_DELAY > 0 wait_ms(ENCODER_MAP_KEY_DELAY); +# endif // ENCODER_MAP_KEY_DELAY > 0 } #endif // ENCODER_MAP_ENABLE diff --git a/quantum/encoder.h b/quantum/encoder.h index 82f95b4931..4eb67fa25d 100644 --- a/quantum/encoder.h +++ b/quantum/encoder.h @@ -32,17 +32,17 @@ void encoder_state_raw(uint8_t* slave_state); void encoder_update_raw(uint8_t* slave_state); # if defined(ENCODERS_PAD_A_RIGHT) -# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t)) -# define NUM_ENCODERS_RIGHT (sizeof(((pin_t[])ENCODERS_PAD_A_RIGHT)) / sizeof(pin_t)) +# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A)) +# define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A_RIGHT)) # else -# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t)) +# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A)) # define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT # endif # define NUM_ENCODERS (NUM_ENCODERS_LEFT + NUM_ENCODERS_RIGHT) #else // SPLIT_KEYBOARD -# define NUM_ENCODERS (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t)) +# define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A)) # define NUM_ENCODERS_LEFT NUM_ENCODERS # define NUM_ENCODERS_RIGHT 0 diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c index 505a7a6ffd..ae3f122e89 100644 --- a/quantum/pointing_device/pointing_device.c +++ b/quantum/pointing_device/pointing_device.c @@ -166,11 +166,9 @@ __attribute__((weak)) void pointing_device_send(void) { host_mouse_send(&local_mouse_report); } // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device - local_mouse_report.x = 0; - local_mouse_report.y = 0; - local_mouse_report.v = 0; - local_mouse_report.h = 0; - + uint8_t buttons = local_mouse_report.buttons; + memset(&local_mouse_report, 0, sizeof(local_mouse_report)); + local_mouse_report.buttons = buttons; memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report)); } diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c index b96f8ff4b3..096ad5d028 100644 --- a/quantum/pointing_device/pointing_device_drivers.c +++ b/quantum/pointing_device/pointing_device_drivers.c @@ -17,6 +17,7 @@ */ #include "pointing_device.h" +#include "pointing_device_internal.h" #include "debug.h" #include "wait.h" #include "timer.h" @@ -32,10 +33,7 @@ report_mouse_t adns5050_get_report(report_mouse_t mouse_report) { report_adns5050_t data = adns5050_read_burst(); if (data.dx != 0 || data.dy != 0) { -# ifdef CONSOLE_ENABLE - if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); -# endif - + pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); mouse_report.x = (mouse_xy_report_t)data.dx; mouse_report.y = (mouse_xy_report_t)data.dy; } @@ -76,9 +74,7 @@ const pointing_device_driver_t pointing_device_driver = { report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report) { report_analog_joystick_t data = analog_joystick_read(); -# ifdef CONSOLE_ENABLE - if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y); -# endif + pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y); mouse_report.x = data.x; mouse_report.y = data.y; @@ -140,11 +136,9 @@ report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) { return mouse_report; } -# if CONSOLE_ENABLE - if (debug_mouse && touchData.touchDown) { - dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue); + if (touchData.touchDown) { + pd_dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue); } -# endif // Scale coordinates to arbitrary X, Y resolution cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale()); @@ -227,9 +221,7 @@ const pointing_device_driver_t pointing_device_driver = { report_mouse_t paw3204_get_report(report_mouse_t mouse_report) { report_paw3204_t data = paw3204_read(); if (data.isMotion) { -# ifdef CONSOLE_ENABLE - dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y); -# endif + pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y); mouse_report.x = data.x; mouse_report.y = data.y; @@ -329,7 +321,7 @@ report_mouse_t pmw33xx_get_report(report_mouse_t mouse_report) { if (!in_motion) { in_motion = true; - dprintf("PWM3360 (0): starting motion\n"); + pd_dprintf("PWM3360 (0): starting motion\n"); } mouse_report.x = CONSTRAIN_HID_XY(report.delta_x); diff --git a/quantum/pointing_device_internal.h b/quantum/pointing_device_internal.h new file mode 100644 index 0000000000..ef649407ca --- /dev/null +++ b/quantum/pointing_device_internal.h @@ -0,0 +1,14 @@ +// Copyright 2022 Stefan Kerkmann +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#ifdef POINTING_DEVICE_DEBUG +# include "debug.h" +# include "print.h" +# define pd_dprintf(...) dprintf(__VA_ARGS__) +#else +# define pd_dprintf(...) \ + do { \ + } while (0) +#endif diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c index ae00b3227a..3593f75f0d 100644 --- a/quantum/process_keycode/process_leader.c +++ b/quantum/process_keycode/process_leader.c @@ -58,7 +58,7 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) { keycode = keycode & 0xFF; } # endif // LEADER_KEY_STRICT_KEY_PROCESSING - if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) { + if (leader_sequence_size < ARRAY_SIZE(leader_sequence)) { leader_sequence[leader_sequence_size] = keycode; leader_sequence_size++; } else { diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 8de31c055c..94809cf029 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -25,10 +25,24 @@ bool unicode_saved_num_lock; #if UNICODE_SELECTED_MODES != -1 static uint8_t selected[] = {UNICODE_SELECTED_MODES}; -static int8_t selected_count = sizeof selected / sizeof *selected; +static int8_t selected_count = ARRAY_SIZE(selected); static int8_t selected_index; #endif +/** \brief Uunicode input mode set at user level + * + * Run user code on unicode input mode change + */ +__attribute__((weak)) void unicode_input_mode_set_user(uint8_t input_mode) {} + +/** \brief unicode input mode set at keyboard level + * + * Run keyboard code on unicode input mode change + */ +__attribute__((weak)) void unicode_input_mode_set_kb(uint8_t input_mode) { + unicode_input_mode_set_user(input_mode); +} + void unicode_input_mode_init(void) { unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); #if UNICODE_SELECTED_MODES != -1 @@ -50,6 +64,7 @@ void unicode_input_mode_init(void) { unicode_config.input_mode = selected[selected_index = 0]; # endif #endif + unicode_input_mode_set_kb(unicode_config.input_mode); dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode); } @@ -60,6 +75,7 @@ uint8_t get_unicode_input_mode(void) { void set_unicode_input_mode(uint8_t mode) { unicode_config.input_mode = mode; persist_unicode_input_mode(); + unicode_input_mode_set_kb(mode); dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); } @@ -73,6 +89,7 @@ void cycle_unicode_input_mode(int8_t offset) { # if UNICODE_CYCLE_PERSIST persist_unicode_input_mode(); # endif + unicode_input_mode_set_kb(unicode_config.input_mode); dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode); #endif } diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 15e798dbb3..bdc7a1dedd 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -87,6 +87,9 @@ void unicode_input_start(void); void unicode_input_finish(void); void unicode_input_cancel(void); +void unicode_input_mode_set_user(uint8_t input_mode); +void unicode_input_mode_set_kb(uint8_t input_mode); + void register_hex(uint16_t hex); void register_hex32(uint32_t hex); void register_unicode(uint32_t code_point); diff --git a/quantum/quantum.c b/quantum/quantum.c index 9a0016b150..acafd8025c 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -361,8 +361,10 @@ bool process_record_quantum(keyrecord_t *record) { #endif return false; case QK_CLEAR_EEPROM: +#ifdef NO_RESET eeconfig_init(); -#ifndef NO_RESET +#else + eeconfig_disable(); soft_reset_keyboard(); #endif return false; diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index 27fa7369bf..99151e5a92 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -369,7 +369,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) { } static void setled_all(uint8_t r, uint8_t g, uint8_t b) { - for (int i = 0; i < sizeof(rgb_matrix_ws2812_array) / sizeof(rgb_matrix_ws2812_array[0]); i++) { + for (int i = 0; i < ARRAY_SIZE(rgb_matrix_ws2812_array); i++) { setled(i, r, g, b); } } diff --git a/quantum/secure.c b/quantum/secure.c index f07f6af2cb..f2a567f31d 100644 --- a/quantum/secure.c +++ b/quantum/secure.c @@ -3,6 +3,7 @@ #include "secure.h" #include "timer.h" +#include "util.h" #ifndef SECURE_UNLOCK_TIMEOUT # define SECURE_UNLOCK_TIMEOUT 5000 @@ -59,7 +60,7 @@ void secure_activity_event(void) { void secure_keypress_event(uint8_t row, uint8_t col) { static const uint8_t sequence[][2] = SECURE_UNLOCK_SEQUENCE; - static const uint8_t sequence_len = sizeof(sequence) / sizeof(sequence[0]); + static const uint8_t sequence_len = ARRAY_SIZE(sequence); static uint8_t offset = 0; if ((sequence[offset][0] == row) && (sequence[offset][1] == col)) { diff --git a/quantum/util.h b/quantum/util.h index ab96ce4bde..9c034cc404 100644 --- a/quantum/util.h +++ b/quantum/util.h @@ -1,26 +1,11 @@ -/* -Copyright 2011 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/>. -*/ +// Copyright 2022 Stefan Kerkmann (KarlK90) +// Copyright 2011 Jun Wako <wakojun@gmail.com> +// SPDX-License-Identifier: GPL-2.0-or-later + #pragma once #include "bitwise.h" -// convert to L string -#define LSTR(s) XLSTR(s) -#define XLSTR(s) L## #s // convert to string #define STR(s) XSTR(s) #define XSTR(s) #s @@ -32,3 +17,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #if !defined(MAX) # define MAX(x, y) (((x) > (y)) ? (x) : (y)) #endif + +#if !defined(CEILING) +/** + * @brief Computes the rounded up result of a division of two integers at + * compile time. + */ +# define CEILING(dividend, divisor) (((dividend) + (divisor)-1) / (divisor)) +#endif + +#if !defined(IS_ARRAY) +/** + * @brief Returns true if the value is an array, false if it's a pointer. + * + * This macro is ill-formed for scalars, which is OK for its intended use in + * ARRAY_SIZE. + */ +# define IS_ARRAY(value) (!__builtin_types_compatible_p(typeof((value)), typeof(&(value)[0]))) +#endif + +#if !defined(ARRAY_SIZE) +/** + * @brief Computes the number of elements of the given array at compile time. + * + * This Macro can only be used for statically allocated arrays that have not + * been decayed into a pointer. This is detected at compile time, though the + * error message for scalar values is poor. + */ +# define ARRAY_SIZE(array) (__builtin_choose_expr(IS_ARRAY((array)), sizeof((array)) / sizeof((array)[0]), (void)0)) +#endif |