diff options
Diffstat (limited to 'quantum')
60 files changed, 1787 insertions, 692 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/eeconfig.c b/quantum/eeconfig.c index 0ff9996ca4..27a0f6d48f 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -46,7 +46,8 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); default_layer_state = 0; eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0); - eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x4); + // Enable oneshot and autocorrect by default: 0b0001 0100 + eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x14); eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default @@ -57,16 +58,6 @@ void eeconfig_init_quantum(void) { eeprom_update_dword(EECONFIG_RGB_MATRIX, 0); eeprom_update_word(EECONFIG_RGB_MATRIX_EXTENDED, 0); - // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS - // within the emulated eeprom via dfu-util or another tool -#if defined INIT_EE_HANDS_LEFT -# pragma message "Faking EE_HANDS for left hand" - eeprom_update_byte(EECONFIG_HANDEDNESS, 1); -#elif defined INIT_EE_HANDS_RIGHT -# pragma message "Faking EE_HANDS for right hand" - eeprom_update_byte(EECONFIG_HANDEDNESS, 0); -#endif - #if defined(HAPTIC_ENABLE) haptic_reset(); #else 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/keyboard.c b/quantum/keyboard.c index 1c62a43d9d..3b5e9b0200 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -107,6 +107,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #endif #ifdef BLUETOOTH_ENABLE # include "outputselect.h" +# ifdef BLUETOOTH_BLUEFRUIT_LE +# include "bluefruit_le.h" +# elif BLUETOOTH_RN42 +# include "rn42.h" +# endif #endif #ifdef CAPS_WORD_ENABLE # include "caps_word.h" @@ -346,9 +351,6 @@ void quantum_init(void) { #ifdef HAPTIC_ENABLE haptic_init(); #endif -#if defined(BLUETOOTH_ENABLE) && defined(OUTPUT_AUTO_ENABLE) - set_output(OUTPUT_AUTO); -#endif } /** \brief keyboard_init @@ -410,6 +412,9 @@ void keyboard_init(void) { // init after split init pointing_device_init(); #endif +#if defined(BLUETOOTH_RN42) + rn42_init(); +#endif #if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE) debug_enable = true; @@ -670,5 +675,9 @@ void keyboard_task(void) { programmable_button_send(); #endif +#ifdef BLUETOOTH_BLUEFRUIT_LE + bluefruit_le_task(); +#endif + led_task(); } diff --git a/quantum/keycode.h b/quantum/keycode.h index 3c80a386d1..b492e4292a 100644 --- a/quantum/keycode.h +++ b/quantum/keycode.h @@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) #define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE) -#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID) +#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_ASST) #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) @@ -205,6 +205,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define KC_MRWD KC_MEDIA_REWIND #define KC_BRIU KC_BRIGHTNESS_UP #define KC_BRID KC_BRIGHTNESS_DOWN +#define KC_CPNL KC_CONTROL_PANEL +#define KC_ASST KC_ASSISTANT /* System Specific */ #define KC_BRMU KC_PAUSE @@ -502,7 +504,9 @@ enum internal_special_keycodes { KC_MEDIA_FAST_FORWARD, KC_MEDIA_REWIND, KC_BRIGHTNESS_UP, - KC_BRIGHTNESS_DOWN + KC_BRIGHTNESS_DOWN, + KC_CONTROL_PANEL, + KC_ASSISTANT // 0xC0 }; enum mouse_keys { @@ -510,11 +514,11 @@ enum mouse_keys { #ifdef VIA_ENABLE KC_MS_UP = 0xF0, #else - KC_MS_UP = 0xED, + KC_MS_UP = 0xCD, #endif KC_MS_DOWN, KC_MS_LEFT, - KC_MS_RIGHT, // 0xF0 + KC_MS_RIGHT, KC_MS_BTN1, KC_MS_BTN2, KC_MS_BTN3, @@ -539,7 +543,7 @@ enum mouse_keys { /* Acceleration */ KC_MS_ACCEL0, KC_MS_ACCEL1, - KC_MS_ACCEL2 // 0xFF + KC_MS_ACCEL2 // 0xDF, or 0xFF if via enabled }; #include "keycode_legacy.h" diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index 81a8e61471..eef048d95c 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h @@ -39,6 +39,7 @@ typedef union { bool swap_rctl_rgui : 1; bool oneshot_enable : 1; bool swap_escape_capslock : 1; + bool autocorrect_enable : 1; }; } keymap_config_t; diff --git a/quantum/keymap.h b/quantum/keymap.h index edff484129..67e35c4e2f 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h @@ -19,38 +19,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdint.h> #include <stdbool.h> +#include "platform_deps.h" #include "action.h" -#if defined(__AVR__) -# include <avr/pgmspace.h> -#elif defined PROTOCOL_CHIBIOS -// We need to ensure that chibios is include before redefining reset -# include <ch.h> -#endif #include "keycode.h" #include "report.h" #include "host.h" -// #include "print.h" #include "debug.h" #include "keycode_config.h" #include "gpio.h" // for pin_t -// ChibiOS uses RESET in its FlagStatus enumeration -// Therefore define it as QK_BOOTLOADER here, to avoid name collision -#if defined(PROTOCOL_CHIBIOS) -# define RESET QK_BOOTLOADER -#endif -// Gross hack, remove me and change RESET keycode to QK_BOOT -#if defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__) -# undef RESET -#endif - #include "quantum_keycodes.h" -// Gross hack, remove me and change RESET keycode to QK_BOOT -#if defined(MCU_RP) -# undef RESET -#endif - // translates key to keycode uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 8d7a8bda9a..1d5ef9b403 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -61,7 +61,7 @@ action_t action_for_keycode(uint16_t keycode) { case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE: action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode)); break; - case KC_AUDIO_MUTE ... KC_BRIGHTNESS_DOWN: + case KC_AUDIO_MUTE ... KC_ASSISTANT: action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode)); break; #endif diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c index 14dd0dd48a..5bff154480 100644 --- a/quantum/led_matrix/led_matrix.c +++ b/quantum/led_matrix/led_matrix.c @@ -170,7 +170,7 @@ void led_matrix_set_value(int index, uint8_t value) { void led_matrix_set_value_all(uint8_t value) { #if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT) - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) + for (uint8_t i = 0; i < LED_MATRIX_LED_COUNT; i++) led_matrix_set_value(i, value); #else # ifdef USE_CIE1931_CURVE @@ -399,13 +399,13 @@ void led_matrix_indicators_advanced(effect_params_t *params) { * and not sure which would be better. Otherwise, this should be called from * led_task_render, right before the iter++ line. */ -#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL +#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; + if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT; #else uint8_t min = 0; - uint8_t max = DRIVER_LED_TOTAL; + uint8_t max = LED_MATRIX_LED_COUNT; #endif led_matrix_indicators_advanced_kb(min, max); led_matrix_indicators_advanced_user(min, max); diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h index 446f293c78..db4f223d5b 100644 --- a/quantum/led_matrix/led_matrix.h +++ b/quantum/led_matrix/led_matrix.h @@ -42,15 +42,15 @@ #endif #ifndef LED_MATRIX_LED_PROCESS_LIMIT -# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 +# define LED_MATRIX_LED_PROCESS_LIMIT (LED_MATRIX_LED_COUNT + 4) / 5 #endif -#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL +#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) # define LED_MATRIX_USE_LIMITS(min, max) \ uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \ uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \ - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; \ + if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT; \ uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0]; @@ -58,20 +58,20 @@ # define LED_MATRIX_USE_LIMITS(min, max) \ uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \ uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \ - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; + if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT; # endif #else # if defined(LED_MATRIX_SPLIT) # define LED_MATRIX_USE_LIMITS(min, max) \ uint8_t min = 0; \ - uint8_t max = DRIVER_LED_TOTAL; \ + uint8_t max = LED_MATRIX_LED_COUNT; \ const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0]; # else # define LED_MATRIX_USE_LIMITS(min, max) \ uint8_t min = 0; \ - uint8_t max = DRIVER_LED_TOTAL; + uint8_t max = LED_MATRIX_LED_COUNT; # endif #endif @@ -181,9 +181,9 @@ static inline bool led_matrix_check_finished_leds(uint8_t led_idx) { uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; return led_idx < k_led_matrix_split[0]; } else - return led_idx < DRIVER_LED_TOTAL; + return led_idx < LED_MATRIX_LED_COUNT; #else - return led_idx < DRIVER_LED_TOTAL; + return led_idx < LED_MATRIX_LED_COUNT; #endif } diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c index f01b395c15..2c09ba82b1 100644 --- a/quantum/led_matrix/led_matrix_drivers.c +++ b/quantum/led_matrix/led_matrix_drivers.c @@ -96,7 +96,7 @@ static void init(void) { # endif # endif - for (int index = 0; index < DRIVER_LED_TOTAL; index++) { + for (int index = 0; index < LED_MATRIX_LED_COUNT; index++) { # if defined(IS31FL3731) IS31FL3731_set_led_control_register(index, true); # elif defined(IS31FL3733) diff --git a/quantum/led_matrix/led_matrix_types.h b/quantum/led_matrix/led_matrix_types.h index 3dc533100f..6d79a3592d 100644 --- a/quantum/led_matrix/led_matrix_types.h +++ b/quantum/led_matrix/led_matrix_types.h @@ -76,8 +76,8 @@ typedef struct PACKED { typedef struct PACKED { uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; - led_point_t point[DRIVER_LED_TOTAL]; - uint8_t flags[DRIVER_LED_TOTAL]; + led_point_t point[LED_MATRIX_LED_COUNT]; + uint8_t flags[LED_MATRIX_LED_COUNT]; } led_config_t; typedef union { diff --git a/quantum/painter/qp.h b/quantum/painter/qp.h index fb6904de22..69bc435961 100644 --- a/quantum/painter/qp.h +++ b/quantum/painter/qp.h @@ -432,6 +432,10 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Quantum Painter Drivers +#ifdef QUANTUM_PAINTER_RGB565_SURFACE_ENABLE +# include "qp_rgb565_surface.h" +#endif // QUANTUM_PAINTER_RGB565_SURFACE_ENABLE + #ifdef QUANTUM_PAINTER_ILI9163_ENABLE # include "qp_ili9163.h" #endif // QUANTUM_PAINTER_ILI9163_ENABLE diff --git a/quantum/painter/qp_draw_image.c b/quantum/painter/qp_draw_image.c index 5822758dce..e9b975f23a 100644 --- a/quantum/painter/qp_draw_image.c +++ b/quantum/painter/qp_draw_image.c @@ -25,10 +25,10 @@ typedef struct qgf_image_handle_t { static qgf_image_handle_t image_descriptors[QUANTUM_PAINTER_NUM_IMAGES] = {0}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Quantum Painter External API: qp_load_image_mem +// Helper: load image from stream -painter_image_handle_t qp_load_image_mem(const void *buffer) { - qp_dprintf("qp_load_image_mem: entry\n"); +static painter_image_handle_t qp_load_image_internal(bool (*stream_factory)(qgf_image_handle_t *image, void *arg), void *arg) { + qp_dprintf("qp_load_image: entry\n"); qgf_image_handle_t *image = NULL; // Find a free slot @@ -41,20 +41,18 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) { // Drop out if not found if (!image) { - qp_dprintf("qp_load_image_mem: fail (no free slot)\n"); + qp_dprintf("qp_load_image: fail (no free slot)\n"); return NULL; } - // Assume we can read the graphics descriptor - image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t)); - - // Update the length of the stream to match, and rewind to the start - image->mem_stream.length = qgf_get_total_size(&image->stream); - image->mem_stream.position = 0; + if (!stream_factory(image, arg)) { + qp_dprintf("qp_load_image: fail (could not create stream)\n"); + return NULL; + } // Now that we know the length, validate the input data if (!qgf_validate_stream(&image->stream)) { - qp_dprintf("qp_load_image_mem: fail (failed validation)\n"); + qp_dprintf("qp_load_image: fail (failed validation)\n"); return NULL; } @@ -63,11 +61,31 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) { // Validation success, we can return the handle image->validate_ok = true; - qp_dprintf("qp_load_image_mem: ok\n"); + qp_dprintf("qp_load_image: ok\n"); return (painter_image_handle_t)image; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Quantum Painter External API: qp_load_image_mem + +static inline bool image_mem_stream_factory(qgf_image_handle_t *image, void *arg) { + void *buffer = arg; + + // Assume we can read the graphics descriptor + image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t)); + + // Update the length of the stream to match, and rewind to the start + image->mem_stream.length = qgf_get_total_size(&image->stream); + image->mem_stream.position = 0; + + return true; +} + +painter_image_handle_t qp_load_image_mem(const void *buffer) { + return qp_load_image_internal(image_mem_stream_factory, (void *)buffer); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Quantum Painter External API: qp_close_image bool qp_close_image(painter_image_handle_t image) { @@ -79,6 +97,7 @@ bool qp_close_image(painter_image_handle_t image) { // Free up this image for use elsewhere. qgf_image->validate_ok = false; + qp_stream_close(&qgf_image->stream); return true; } diff --git a/quantum/painter/qp_draw_text.c b/quantum/painter/qp_draw_text.c index f99e082cad..0f5473abd0 100644 --- a/quantum/painter/qp_draw_text.c +++ b/quantum/painter/qp_draw_text.c @@ -36,10 +36,10 @@ typedef struct qff_font_handle_t { static qff_font_handle_t font_descriptors[QUANTUM_PAINTER_NUM_FONTS] = {0}; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Quantum Painter External API: qp_load_font_mem +// Helper: load font from stream -painter_font_handle_t qp_load_font_mem(const void *buffer) { - qp_dprintf("qp_load_font_mem: entry\n"); +static painter_font_handle_t qp_load_font_internal(bool (*stream_factory)(qff_font_handle_t *font, void *arg), void *arg) { + qp_dprintf("qp_load_font: entry\n"); qff_font_handle_t *font = NULL; // Find a free slot @@ -52,20 +52,18 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) { // Drop out if not found if (!font) { - qp_dprintf("qp_load_font_mem: fail (no free slot)\n"); + qp_dprintf("qp_load_font: fail (no free slot)\n"); return NULL; } - // Assume we can read the graphics descriptor - font->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qff_font_descriptor_v1_t)); - - // Update the length of the stream to match, and rewind to the start - font->mem_stream.length = qff_get_total_size(&font->stream); - font->mem_stream.position = 0; + if (!stream_factory(font, arg)) { + qp_dprintf("qp_load_font: fail (could not create stream)\n"); + return NULL; + } // Now that we know the length, validate the input data if (!qff_validate_stream(&font->stream)) { - qp_dprintf("qp_load_font_mem: fail (failed validation)\n"); + qp_dprintf("qp_load_font: fail (failed validation)\n"); return NULL; } @@ -76,12 +74,12 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) { void *ram_buffer = malloc(font->mem_stream.length); if (ram_buffer == NULL) { - qp_dprintf("qp_load_font_mem: could not allocate enough RAM for font, falling back to original\n"); + qp_dprintf("qp_load_font: could not allocate enough RAM for font, falling back to original\n"); } else { do { // Copy the data into RAM if (qp_stream_read(ram_buffer, 1, font->mem_stream.length, &font->mem_stream) != font->mem_stream.length) { - qp_dprintf("qp_load_font_mem: could not copy from flash to RAM, falling back to original\n"); + qp_dprintf("qp_load_font: could not copy from flash to RAM, falling back to original\n"); break; } @@ -102,18 +100,38 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) { qff_read_font_descriptor(&font->stream, &font->base.line_height, &font->has_ascii_table, &font->num_unicode_glyphs, &font->bpp, &font->has_palette, &font->compression_scheme, NULL); if (!qp_internal_bpp_capable(font->bpp)) { - qp_dprintf("qp_load_font_mem: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp); + qp_dprintf("qp_load_font: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp); qp_close_font((painter_font_handle_t)font); return NULL; } // Validation success, we can return the handle font->validate_ok = true; - qp_dprintf("qp_load_font_mem: ok\n"); + qp_dprintf("qp_load_font: ok\n"); return (painter_font_handle_t)font; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Quantum Painter External API: qp_load_font_mem + +static inline bool font_mem_stream_factory(qff_font_handle_t *font, void *arg) { + void *buffer = arg; + + // Assume we can read the graphics descriptor + font->mem_stream = qp_make_memory_stream(buffer, sizeof(qff_font_descriptor_v1_t)); + + // Update the length of the stream to match, and rewind to the start + font->mem_stream.length = qff_get_total_size(&font->stream); + font->mem_stream.position = 0; + + return true; +} + +painter_font_handle_t qp_load_font_mem(const void *buffer) { + return qp_load_font_internal(font_mem_stream_factory, (void *)buffer); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Quantum Painter External API: qp_close_font bool qp_close_font(painter_font_handle_t font) { @@ -133,6 +151,7 @@ bool qp_close_font(painter_font_handle_t font) { #endif // QUANTUM_PAINTER_LOAD_FONTS_TO_RAM // Free up this font for use elsewhere. + qp_stream_close(&qff_font->stream); qff_font->validate_ok = false; return true; } diff --git a/quantum/painter/qp_stream.c b/quantum/painter/qp_stream.c index f00ae5ed38..1198cf793d 100644 --- a/quantum/painter/qp_stream.c +++ b/quantum/painter/qp_stream.c @@ -38,7 +38,7 @@ uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint3 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Memory streams -int16_t mem_get(qp_stream_t *stream) { +static inline int16_t mem_get(qp_stream_t *stream) { qp_memory_stream_t *s = (qp_memory_stream_t *)stream; if (s->position >= s->length) { s->is_eof = true; @@ -47,7 +47,7 @@ int16_t mem_get(qp_stream_t *stream) { return s->buffer[s->position++]; } -bool mem_put(qp_stream_t *stream, uint8_t c) { +static inline bool mem_put(qp_stream_t *stream, uint8_t c) { qp_memory_stream_t *s = (qp_memory_stream_t *)stream; if (s->position >= s->length) { s->is_eof = true; @@ -57,7 +57,7 @@ bool mem_put(qp_stream_t *stream, uint8_t c) { return true; } -int mem_seek(qp_stream_t *stream, int32_t offset, int origin) { +static inline int mem_seek(qp_stream_t *stream, int32_t offset, int origin) { qp_memory_stream_t *s = (qp_memory_stream_t *)stream; // Handle as per fseek @@ -95,26 +95,23 @@ int mem_seek(qp_stream_t *stream, int32_t offset, int origin) { return 0; } -int32_t mem_tell(qp_stream_t *stream) { +static inline int32_t mem_tell(qp_stream_t *stream) { qp_memory_stream_t *s = (qp_memory_stream_t *)stream; return s->position; } -bool mem_is_eof(qp_stream_t *stream) { +static inline bool mem_is_eof(qp_stream_t *stream) { qp_memory_stream_t *s = (qp_memory_stream_t *)stream; return s->is_eof; } +static inline void mem_close(qp_stream_t *stream) { + // No-op. +} + qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) { qp_memory_stream_t stream = { - .base = - { - .get = mem_get, - .put = mem_put, - .seek = mem_seek, - .tell = mem_tell, - .is_eof = mem_is_eof, - }, + .base = {.get = mem_get, .put = mem_put, .seek = mem_seek, .tell = mem_tell, .is_eof = mem_is_eof, .close = mem_close}, .buffer = (uint8_t *)buffer, .length = length, .position = 0, @@ -127,43 +124,41 @@ qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) { #ifdef QP_STREAM_HAS_FILE_IO -int16_t file_get(qp_stream_t *stream) { +static inline int16_t file_get(qp_stream_t *stream) { qp_file_stream_t *s = (qp_file_stream_t *)stream; int c = fgetc(s->file); if (c < 0 || feof(s->file)) return STREAM_EOF; return (uint16_t)c; } -bool file_put(qp_stream_t *stream, uint8_t c) { +static inline bool file_put(qp_stream_t *stream, uint8_t c) { qp_file_stream_t *s = (qp_file_stream_t *)stream; return fputc(c, s->file) == c; } -int file_seek(qp_stream_t *stream, int32_t offset, int origin) { +static inline int file_seek(qp_stream_t *stream, int32_t offset, int origin) { qp_file_stream_t *s = (qp_file_stream_t *)stream; return fseek(s->file, offset, origin); } -int32_t file_tell(qp_stream_t *stream) { +static inline int32_t file_tell(qp_stream_t *stream) { qp_file_stream_t *s = (qp_file_stream_t *)stream; return (int32_t)ftell(s->file); } -bool file_is_eof(qp_stream_t *stream) { +static inline bool file_is_eof(qp_stream_t *stream) { qp_file_stream_t *s = (qp_file_stream_t *)stream; return (bool)feof(s->file); } +static inline void file_close(qp_stream_t *stream) { + qp_file_stream_t *s = (qp_file_stream_t *)stream; + fclose(s->file); +} + qp_file_stream_t qp_make_file_stream(FILE *f) { qp_file_stream_t stream = { - .base = - { - .get = file_get, - .put = file_put, - .seek = file_seek, - .tell = file_tell, - .is_eof = file_is_eof, - }, + .base = {.get = file_get, .put = file_put, .seek = file_seek, .tell = file_tell, .is_eof = file_is_eof, .close = file_close}, .file = f, }; return stream; diff --git a/quantum/painter/qp_stream.h b/quantum/painter/qp_stream.h index 878b9bf530..c0e745adc1 100644 --- a/quantum/painter/qp_stream.h +++ b/quantum/painter/qp_stream.h @@ -41,6 +41,8 @@ typedef struct qp_stream_t qp_stream_t; uint32_t qp_stream_read_impl(void *output_buf, uint32_t member_size, uint32_t num_members, qp_stream_t *stream); uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint32_t num_members, qp_stream_t *stream); +#define qp_stream_close(stream_ptr) (((qp_stream_t *)(stream_ptr))->close((qp_stream_t *)(stream_ptr))) + #define STREAM_EOF ((int16_t)(-1)) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -52,6 +54,7 @@ struct qp_stream_t { int (*seek)(qp_stream_t *stream, int32_t offset, int origin); int32_t (*tell)(qp_stream_t *stream); bool (*is_eof)(qp_stream_t *stream); + void (*close)(qp_stream_t *stream); }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -77,6 +80,6 @@ typedef struct qp_file_stream_t { FILE * file; } qp_file_stream_t; -qp_file_stream_t qo_make_file_stream(FILE *f); +qp_file_stream_t qp_make_file_stream(FILE *f); #endif // QP_STREAM_HAS_FILE_IO diff --git a/quantum/painter/rules.mk b/quantum/painter/rules.mk index 91787dfe0e..5ac374a96e 100644 --- a/quantum/painter/rules.mk +++ b/quantum/painter/rules.mk @@ -3,14 +3,23 @@ QUANTUM_PAINTER_DRIVERS ?= QUANTUM_PAINTER_ANIMATIONS_ENABLE ?= yes # The list of permissible drivers that can be listed in QUANTUM_PAINTER_DRIVERS -VALID_QUANTUM_PAINTER_DRIVERS := ili9163_spi ili9341_spi ili9488_spi st7789_spi st7735_spi gc9a01_spi ssd1351_spi +VALID_QUANTUM_PAINTER_DRIVERS := \ + rgb565_surface \ + ili9163_spi \ + ili9341_spi \ + ili9488_spi \ + st7735_spi \ + st7789_spi \ + gc9a01_spi \ + ssd1351_spi #------------------------------------------------------------------------------- OPT_DEFS += -DQUANTUM_PAINTER_ENABLE -COMMON_VPATH += $(QUANTUM_DIR)/painter +COMMON_VPATH += $(QUANTUM_DIR)/painter \ + $(QUANTUM_DIR)/unicode SRC += \ - $(QUANTUM_DIR)/utf8.c \ + $(QUANTUM_DIR)/unicode/utf8.c \ $(QUANTUM_DIR)/color.c \ $(QUANTUM_DIR)/painter/qp.c \ $(QUANTUM_DIR)/painter/qp_stream.c \ @@ -39,6 +48,13 @@ define handle_quantum_painter_driver ifeq ($$(filter $$(strip $$(CURRENT_PAINTER_DRIVER)),$$(VALID_QUANTUM_PAINTER_DRIVERS)),) $$(error "$$(CURRENT_PAINTER_DRIVER)" is not a valid Quantum Painter driver) + else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),rgb565_surface) + OPT_DEFS += -DQUANTUM_PAINTER_RGB565_SURFACE_ENABLE + COMMON_VPATH += \ + $(DRIVER_PATH)/painter/generic + SRC += \ + $(DRIVER_PATH)/painter/generic/qp_rgb565_surface.c \ + else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),ili9163_spi) QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes @@ -72,27 +88,27 @@ define handle_quantum_painter_driver $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ $(DRIVER_PATH)/painter/ili9xxx/qp_ili9488.c \ - else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7789_spi) + else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7735_spi) QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes - OPT_DEFS += -DQUANTUM_PAINTER_ST7789_ENABLE -DQUANTUM_PAINTER_ST7789_SPI_ENABLE + OPT_DEFS += -DQUANTUM_PAINTER_ST7735_ENABLE -DQUANTUM_PAINTER_ST7735_SPI_ENABLE COMMON_VPATH += \ $(DRIVER_PATH)/painter/tft_panel \ $(DRIVER_PATH)/painter/st77xx SRC += \ $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ - $(DRIVER_PATH)/painter/st77xx/qp_st7789.c + $(DRIVER_PATH)/painter/st77xx/qp_st7735.c - else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7735_spi) + else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7789_spi) QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes - OPT_DEFS += -DQUANTUM_PAINTER_ST7735_ENABLE -DQUANTUM_PAINTER_ST7735_SPI_ENABLE + OPT_DEFS += -DQUANTUM_PAINTER_ST7789_ENABLE -DQUANTUM_PAINTER_ST7789_SPI_ENABLE COMMON_VPATH += \ $(DRIVER_PATH)/painter/tft_panel \ $(DRIVER_PATH)/painter/st77xx SRC += \ $(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \ - $(DRIVER_PATH)/painter/st77xx/qp_st7735.c + $(DRIVER_PATH)/painter/st77xx/qp_st7789.c else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),gc9a01_spi) QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c index 505a7a6ffd..6981f850d0 100644 --- a/quantum/pointing_device/pointing_device.c +++ b/quantum/pointing_device/pointing_device.c @@ -144,7 +144,11 @@ __attribute__((weak)) void pointing_device_init(void) { { pointing_device_driver.init(); #ifdef POINTING_DEVICE_MOTION_PIN +# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW setPinInputHigh(POINTING_DEVICE_MOTION_PIN); +# else + setPinInput(POINTING_DEVICE_MOTION_PIN); +# endif #endif } @@ -166,11 +170,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)); } @@ -238,7 +240,11 @@ __attribute__((weak)) void pointing_device_task(void) { # if defined(SPLIT_POINTING_ENABLE) # error POINTING_DEVICE_MOTION_PIN not supported when sharing the pointing device report between sides. # endif +# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW if (!readPin(POINTING_DEVICE_MOTION_PIN)) +# else + if (readPin(POINTING_DEVICE_MOTION_PIN)) +# endif #endif #if defined(SPLIT_POINTING_ENABLE) @@ -270,6 +276,10 @@ __attribute__((weak)) void pointing_device_task(void) { local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report); local_mouse_report = pointing_device_task_kb(local_mouse_report); #endif + // automatic mouse layer function +#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE + pointing_device_task_auto_mouse(local_mouse_report); +#endif // combine with mouse report to ensure that the combined is sent correctly #ifdef MOUSEKEY_ENABLE report_mouse_t mousekey_report = mousekey_get_report(); diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h index 77db5471ea..27a3f95e32 100644 --- a/quantum/pointing_device/pointing_device.h +++ b/quantum/pointing_device/pointing_device.h @@ -21,20 +21,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "host.h" #include "report.h" +#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE +# include "pointing_device_auto_mouse.h" +#endif + #if defined(POINTING_DEVICE_DRIVER_adns5050) # include "drivers/sensors/adns5050.h" +# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW #elif defined(POINTING_DEVICE_DRIVER_adns9800) # include "spi_master.h" # include "drivers/sensors/adns9800.h" +# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW #elif defined(POINTING_DEVICE_DRIVER_analog_joystick) # include "analog.h" # include "drivers/sensors/analog_joystick.h" +# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi) # include "drivers/sensors/cirque_pinnacle.h" # include "drivers/sensors/cirque_pinnacle_gestures.h" # include "pointing_device_gestures.h" #elif defined(POINTING_DEVICE_DRIVER_paw3204) # include "drivers/sensors/paw3204.h" +# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) # include "i2c_master.h" # include "drivers/sensors/pimoroni_trackball.h" @@ -48,9 +56,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. # ifdef PIMORONI_TRACKBALL_ROTATE # define POINTING_DEVICE_ROTATION_90 # endif +# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW #elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389) # include "spi_master.h" # include "drivers/sensors/pmw33xx_common.h" +# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW #else void pointing_device_driver_init(void); report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report); diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c new file mode 100644 index 0000000000..edffd44787 --- /dev/null +++ b/quantum/pointing_device/pointing_device_auto_mouse.c @@ -0,0 +1,384 @@ +/* Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> + * Copyright 2022 Alabastard + * + * 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/>. + */ + +#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE + +# include "pointing_device_auto_mouse.h" + +/* local data structure for tracking auto mouse */ +static auto_mouse_context_t auto_mouse_context = {.config.layer = (uint8_t)AUTO_MOUSE_DEFAULT_LAYER}; + +/* local functions */ +static bool is_mouse_record(uint16_t keycode, keyrecord_t* record); +static void auto_mouse_reset(void); + +/* check for target layer deactivation overrides */ +static inline bool layer_hold_check(void) { + return get_auto_mouse_toggle() || +# ifndef NO_ACTION_ONESHOT + get_oneshot_layer() == (AUTO_MOUSE_TARGET_LAYER) || +# endif + false; +} + +/* check all layer activation criteria */ +static inline bool is_auto_mouse_active(void) { + return auto_mouse_context.status.is_activated || auto_mouse_context.status.mouse_key_tracker || layer_hold_check(); +} + +/** + * @brief Get auto mouse enable state + * + * Return is_enabled value + * + * @return bool true: auto mouse enabled false: auto mouse disabled + */ +bool get_auto_mouse_enable(void) { + return auto_mouse_context.config.is_enabled; +} + +/** + * @brief get current target layer index + * + * NOTE: (AUTO_MOUSE_TARGET_LAYER) is an alias for this function + * + * @return uint8_t target layer index + */ +uint8_t get_auto_mouse_layer(void) { + return auto_mouse_context.config.layer; +} + +/** + * @brief get layer_toggled value + * + * @return bool of current layer_toggled state + */ +bool get_auto_mouse_toggle(void) { + return auto_mouse_context.status.is_toggled; +} + +/** + * @brief Reset auto mouse context + * + * Clear timers and status + * + * NOTE: this will set is_toggled to false so careful when using it + */ +static void auto_mouse_reset(void) { + memset(&auto_mouse_context.status, 0, sizeof(auto_mouse_context.status)); + memset(&auto_mouse_context.timer, 0, sizeof(auto_mouse_context.timer)); +} + +/** + * @brief Set auto mouse enable state + * + * Set local auto mouse enabled state + * + * @param[in] state bool + */ +void set_auto_mouse_enable(bool enable) { + // skip if unchanged + if (auto_mouse_context.config.is_enabled == enable) return; + auto_mouse_context.config.is_enabled = enable; + auto_mouse_reset(); +} + +/** + * @brief Change target layer for auto mouse + * + * Sets input as the new target layer if different from current and resets auto mouse + * + * NOTE: remove_auto_mouse_layer(state, false) or auto_mouse_layer_off should be called + * before this function to avoid issues with layers getting stuck + * + * @param[in] layer uint8_t + */ +void set_auto_mouse_layer(uint8_t layer) { + // skip if unchanged + if (auto_mouse_context.config.layer == layer) return; + auto_mouse_context.config.layer = layer; + auto_mouse_reset(); +} + +/** + * @brief toggle mouse layer setting + * + * Change state of local layer_toggled bool meant to track when the mouse layer is toggled on by other means + * + * NOTE: While is_toggled is true it will prevent deactiving target layer (but not activation) + */ +void auto_mouse_toggle(void) { + auto_mouse_context.status.is_toggled ^= 1; + auto_mouse_context.timer.delay = 0; +} + +/** + * @brief Remove current auto mouse target layer from layer state + * + * Will remove auto mouse target layer from given layer state if appropriate. + * + * NOTE: Removal can be forced, ignoring appropriate critera + * + * @params state[in] layer_state_t original layer state + * @params force[in] bool force removal + * + * @return layer_state_t modified layer state + */ +layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force) { + if (force || ((AUTO_MOUSE_ENABLED) && !layer_hold_check())) { + state &= ~((layer_state_t)1 << (AUTO_MOUSE_TARGET_LAYER)); + } + return state; +} + +/** + * @brief Disable target layer + * + * Will disable target layer if appropriate. + * NOTE: NOT TO BE USED in layer_state_set stack!!! + */ +void auto_mouse_layer_off(void) { + if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && (AUTO_MOUSE_ENABLED) && !layer_hold_check()) { + layer_off((AUTO_MOUSE_TARGET_LAYER)); + } +} + +/** + * @brief Weak function to handel testing if pointing_device is active + * + * Will trigger target layer activation(if delay timer has expired) and prevent deactivation when true. + * May be replaced by bool in report_mouse_t in future + * + * NOTE: defined weakly to allow for changing and adding conditions for specific hardware/customization + * + * @param[in] mouse_report report_mouse_t + * @return bool of pointing_device activation + */ +__attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) { + return mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons; +} + +/** + * @brief Update the auto mouse based on mouse_report + * + * Handel activation/deactivation of target layer based on auto_mouse_activation and state timers and local key/layer tracking data + * + * @param[in] mouse_report report_mouse_t + */ +void pointing_device_task_auto_mouse(report_mouse_t mouse_report) { + // skip if disabled, delay timer running, or debounce + if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= AUTO_MOUSE_DEBOUNCE || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) { + return; + } + // update activation and reset debounce + auto_mouse_context.status.is_activated = auto_mouse_activation(mouse_report); + if (is_auto_mouse_active()) { + auto_mouse_context.timer.active = timer_read(); + auto_mouse_context.timer.delay = 0; + if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) { + layer_on((AUTO_MOUSE_TARGET_LAYER)); + } + } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > AUTO_MOUSE_TIME) { + layer_off((AUTO_MOUSE_TARGET_LAYER)); + auto_mouse_context.timer.active = 0; + } +} + +/** + * @brief Handle mouskey event + * + * Increments/decrements mouse_key_tracker and restart active timer + * + * @param[in] pressed bool + */ +void auto_mouse_keyevent(bool pressed) { + if (pressed) { + auto_mouse_context.status.mouse_key_tracker++; + } else { + auto_mouse_context.status.mouse_key_tracker--; + } + auto_mouse_context.timer.delay = 0; +} + +/** + * @brief Handle auto mouse non mousekey reset + * + * Start/restart delay timer and reset auto mouse on keydown as well as turn the + * target layer off if on and reset toggle status + * + * NOTE: NOT TO BE USED in layer_state_set stack!!! + * + * @param[in] pressed bool + */ +void auto_mouse_reset_trigger(bool pressed) { + if (pressed) { + if (layer_state_is((AUTO_MOUSE_TARGET_LAYER))) { + layer_off((AUTO_MOUSE_TARGET_LAYER)); + }; + auto_mouse_reset(); + } + auto_mouse_context.timer.delay = timer_read(); +} + +/** + * @brief handle key events processing for auto mouse + * + * Will process keys differently depending on if key is defined as mousekey or not. + * Some keys have built in behaviour(not overwritable): + * mouse buttons : auto_mouse_keyevent() + * non-mouse keys : auto_mouse_reset_trigger() + * mod keys : skip auto mouse key processing + * mod tap : skip on hold (mod keys) + * QK mods e.g. LCTL(kc): default to non-mouse key, add at kb/user level as needed + * non target layer keys: skip auto mouse key processing (same as mod keys) + * MO(target layer) : auto_mouse_keyevent() + * target layer toggles : auto_mouse_toggle() (on both key up and keydown) + * target layer tap : default processing on tap mouse key on hold + * all other keycodes : default to non-mouse key, add at kb/user level as needed + * + * Will deactivate target layer once a non mouse key is pressed if nothing is holding the layer active + * such as held mousekey, toggled current target layer, or auto_mouse_activation is true + * + * @params keycode[in] uint16_t + * @params record[in] keyrecord_t pointer + */ +bool process_auto_mouse(uint16_t keycode, keyrecord_t* record) { + // skip if not enabled or mouse_layer not set + if (!(AUTO_MOUSE_ENABLED)) return true; + + switch (keycode) { + // Skip Mod keys to avoid layer reset + case KC_LEFT_CTRL ... KC_RIGHT_GUI: + case QK_MODS ... QK_MODS_MAX: + break; + // TO((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------- + case QK_TO ... QK_TO_MAX: // same proccessing as next + // TG((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------- + case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX: + if ((keycode & 0xff) == (AUTO_MOUSE_TARGET_LAYER)) { + if (!(record->event.pressed)) auto_mouse_toggle(); + } + break; + // MO((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------- + case QK_MOMENTARY ... QK_MOMENTARY_MAX: + if ((keycode & 0xff) == (AUTO_MOUSE_TARGET_LAYER)) { + auto_mouse_keyevent(record->event.pressed); + } + // DF --------------------------------------------------------------------------------------------------------- + case QK_DEF_LAYER ... QK_DEF_LAYER_MAX: +# ifndef NO_ACTION_ONESHOT + // OSL((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------ + case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX: + case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX: +# endif + break; + // LM((AUTO_MOUSE_TARGET_LAYER), mod)-------------------------------------------------------------------------- + case QK_LAYER_MOD ... QK_LAYER_MOD_MAX: + if (((keycode >> 8) & 0x0f) == (AUTO_MOUSE_TARGET_LAYER)) { + auto_mouse_keyevent(record->event.pressed); + } + break; + // TT((AUTO_MOUSE_TARGET_LAYER))--------------------------------------------------------------------------- +# ifndef NO_ACTION_TAPPING + case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX: + if ((keycode & 0xff) == (AUTO_MOUSE_TARGET_LAYER)) { + auto_mouse_keyevent(record->event.pressed); +# if TAPPING_TOGGLE != 0 + if (record->tap.count == TAPPING_TOGGLE) { + if (record->event.pressed) { + auto_mouse_context.status.mouse_key_tracker--; + } else { + auto_mouse_toggle(); + auto_mouse_context.status.mouse_key_tracker++; + } + } +# endif + } + break; + // LT((AUTO_MOUSE_TARGET_LAYER), kc)--------------------------------------------------------------------------- + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: + if (!record->tap.count) { + if (((keycode >> 8) & 0x0f) == (AUTO_MOUSE_TARGET_LAYER)) { + auto_mouse_keyevent(record->event.pressed); + } + break; + } + // MT(kc) only skip on hold + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + if (!record->tap.count) break; +# endif + // QK_MODS goes to default + default: + // skip on no event + if (IS_NOEVENT(record->event)) break; + // check if keyrecord is mousekey + if (is_mouse_record(keycode, record)) { + auto_mouse_keyevent(record->event.pressed); + } else if (!is_auto_mouse_active()) { + // all non-mousekey presses restart delay timer and reset status + auto_mouse_reset_trigger(record->event.pressed); + } + } + if (auto_mouse_context.status.mouse_key_tracker < 0) { + auto_mouse_context.status.mouse_key_tracker = 0; + dprintf("key tracker error (<0) \n"); + } + return true; +} + +/** + * @brief Local function to handle checking if a keycode is a mouse button + * + * Starts code stack for checking keyrecord if defined as mousekey + * + * @params keycode[in] uint16_t + * @params record[in] keyrecord_t pointer + * @return bool true: keyrecord is mousekey false: keyrecord is not mousekey + */ +static bool is_mouse_record(uint16_t keycode, keyrecord_t* record) { + // allow for keyboard to hook in and override if need be + if (is_mouse_record_kb(keycode, record) || IS_MOUSEKEY(keycode)) return true; + return false; +} + +/** + * @brief Weakly defined keyboard level callback for adding keyrecords as mouse keys + * + * Meant for redefinition at keyboard level and should return is_mouse_record_user by default at end of function + * + * @params keycode[in] uint16_t + * @params record[in] keyrecord_t pointer + * @return bool true: keyrecord is defined as mouse key false: keyrecord is not defined as mouse key + */ +__attribute__((weak)) bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record) { + return is_mouse_record_user(keycode, record); +} + +/** + * @brief Weakly defined keymap/user level callback for adding keyrecords as mouse keys + * + * Meant for redefinition at keymap/user level and should return false by default at end of function + * + * @params keycode[in] uint16_t + * @params record[in] keyrecord_t pointer + * @return bool true: keyrecord is defined as mouse key false: keyrecord is not defined as mouse key + */ +__attribute__((weak)) bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record) { + return false; +} + +#endif // POINTING_DEVICE_AUTO_MOUSE_ENABLE diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h new file mode 100644 index 0000000000..0f26af79e6 --- /dev/null +++ b/quantum/pointing_device/pointing_device_auto_mouse.h @@ -0,0 +1,87 @@ +/* Copyright 2022 Alabastard + * + * 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 <string.h> + +#include "quantum.h" +#include "pointing_device.h" +#include "print.h" + +/* check settings and set defaults */ +#ifndef POINTING_DEVICE_AUTO_MOUSE_ENABLE +# error "POINTING_DEVICE_AUTO_MOUSE_ENABLE not defined! check config settings" +#endif + +#ifndef AUTO_MOUSE_DEFAULT_LAYER +# define AUTO_MOUSE_DEFAULT_LAYER 1 +#endif +#ifndef AUTO_MOUSE_TIME +# define AUTO_MOUSE_TIME 650 +#endif +#ifndef AUTO_MOUSE_DELAY +# define AUTO_MOUSE_DELAY GET_TAPPING_TERM(KC_MS_BTN1, &(keyrecord_t){}) +#endif +#ifndef AUTO_MOUSE_DEBOUNCE +# define AUTO_MOUSE_DEBOUNCE 25 +#endif + +/* data structure */ +typedef struct { + struct { + bool is_enabled; + uint8_t layer; + } config; + struct { + uint16_t active; + uint16_t delay; + } timer; + struct { + bool is_activated; + bool is_toggled; + int8_t mouse_key_tracker; + } status; +} auto_mouse_context_t; + +/* ----------Set up and control------------------------------------------------------------------------------ */ +void set_auto_mouse_enable(bool enable); // enable/disable auto mouse feature +bool get_auto_mouse_enable(void); // get auto_mouse_enable +void set_auto_mouse_layer(uint8_t layer); // set target layer by index +uint8_t get_auto_mouse_layer(void); // get target layer index +void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!) +layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force); // remove auto mouse target layer from state if appropriate (can be forced) + +/* ----------For custom pointing device activation----------------------------------------------------------- */ +bool auto_mouse_activation(report_mouse_t mouse_report); // handles pointing device trigger conditions for target layer activation (overwritable) + +/* ----------Handling keyevents------------------------------------------------------------------------------ */ +void auto_mouse_keyevent(bool pressed); // trigger auto mouse keyevent: mouse_keytracker increment/decrement on press/release +void auto_mouse_reset_trigger(bool pressed); // trigger non mouse keyevent: reset and start delay timer (DO NOT USE in layer_state_set stack!!) +void auto_mouse_toggle(void); // toggle mouse layer flag disables mouse layer deactivation while on (meant for tap toggle or toggle of target) +bool get_auto_mouse_toggle(void); // get toggle mouse layer flag value + +/* ----------Callbacks for adding keycodes to mouse record checking------------------------------------------ */ +bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record); +bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record); + +/* ----------Core functions (only used in custom pointing devices or key processing)------------------------- */ +void pointing_device_task_auto_mouse(report_mouse_t mouse_report); // add to pointing_device_task_* +bool process_auto_mouse(uint16_t keycode, keyrecord_t* record); // add to process_record_* + +/* ----------Macros/Aliases---------------------------------------------------------------------------------- */ +#define AUTO_MOUSE_TARGET_LAYER get_auto_mouse_layer() +#define AUTO_MOUSE_ENABLED get_auto_mouse_enable() diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c index b96f8ff4b3..172c9f36d7 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; @@ -117,12 +113,24 @@ void cirque_pinnacle_configure_cursor_glide(float trigger_px) { # endif # if CIRQUE_PINNACLE_POSITION_MODE + +# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE +static bool is_touch_down; + +bool auto_mouse_activation(report_mouse_t mouse_report) { + return is_touch_down || mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons; +} +# endif + report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) { pinnacle_data_t touchData = cirque_pinnacle_read_data(); mouse_xy_report_t report_x = 0, report_y = 0; static uint16_t x = 0, y = 0; +# if defined(CIRQUE_PINNACLE_TAP_ENABLE) + mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1); +# endif # ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE - cursor_glide_t glide_report = {0}; + cursor_glide_t glide_report = {0}; if (cursor_glide_enable) { glide_report = cursor_glide_check(&glide); @@ -140,10 +148,12 @@ 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); } + +# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE + is_touch_down = touchData.touchDown; # endif // Scale coordinates to arbitrary X, Y resolution @@ -227,9 +237,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 +337,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/autocorrect_data_default.h b/quantum/process_keycode/autocorrect_data_default.h new file mode 100644 index 0000000000..bfc29666df --- /dev/null +++ b/quantum/process_keycode/autocorrect_data_default.h @@ -0,0 +1,85 @@ +// Generated code. + +// Autocorrection dictionary (70 entries): +// :guage -> gauge +// :the:the: -> the +// :thier -> their +// :ture -> true +// accomodate -> accommodate +// acommodate -> accommodate +// aparent -> apparent +// aparrent -> apparent +// apparant -> apparent +// apparrent -> apparent +// aquire -> acquire +// becuase -> because +// cauhgt -> caught +// cheif -> chief +// choosen -> chosen +// cieling -> ceiling +// collegue -> colleague +// concensus -> consensus +// contians -> contains +// cosnt -> const +// dervied -> derived +// fales -> false +// fasle -> false +// fitler -> filter +// flase -> false +// foward -> forward +// frequecy -> frequency +// gaurantee -> guarantee +// guaratee -> guarantee +// heigth -> height +// heirarchy -> hierarchy +// inclued -> include +// interator -> iterator +// intput -> input +// invliad -> invalid +// lenght -> length +// liasion -> liaison +// libary -> library +// listner -> listener +// looses: -> loses +// looup -> lookup +// manefist -> manifest +// namesapce -> namespace +// namespcae -> namespace +// occassion -> occasion +// occured -> occurred +// ouptut -> output +// ouput -> output +// overide -> override +// postion -> position +// priviledge -> privilege +// psuedo -> pseudo +// recieve -> receive +// refered -> referred +// relevent -> relevant +// repitition -> repetition +// retrun -> return +// retun -> return +// reuslt -> result +// reutrn -> return +// saftey -> safety +// seperate -> separate +// singed -> signed +// stirng -> string +// strign -> string +// swithc -> switch +// swtich -> switch +// thresold -> threshold +// udpate -> update +// widht -> width + +#define AUTOCORRECT_MIN_LENGTH 5 // ":ture" +#define AUTOCORRECT_MAX_LENGTH 10 // "accomodate" + +#define DICTIONARY_SIZE 1104 + +static const uint8_t autocorrect_data[DICTIONARY_SIZE] PROGMEM = {108, 43, 0, 6, 71, 0, 7, 81, 0, 8, 199, 0, 9, 240, 1, 10, 250, 1, 11, 26, 2, 17, 53, 2, 18, 190, 2, 19, 202, 2, 21, 212, 2, 22, 20, 3, 23, 67, 3, 28, 16, 4, 0, 72, 50, 0, 22, 60, 0, 0, 11, 23, 44, 8, 11, 23, 44, 0, 132, 0, 8, 22, 18, 18, 15, 0, 132, 115, 101, 115, 0, 11, 23, 12, 26, 22, 0, 129, 99, 104, 0, 68, 94, 0, 8, 106, 0, 15, 174, 0, 21, 187, 0, 0, 12, 15, 25, 17, 12, 0, 131, 97, 108, 105, 100, 0, 74, 119, 0, 12, 129, 0, 21, 140, 0, 24, 165, 0, 0, 17, 12, 22, 0, 131, 103, 110, 101, 100, 0, 25, 21, 8, 7, 0, 131, 105, 118, 101, 100, 0, 72, 147, 0, 24, 156, 0, 0, 9, 8, 21, 0, 129, 114, 101, 100, 0, 6, 6, 18, 0, 129, 114, 101, 100, 0, 15, 6, 17, 12, 0, 129, 100, 101, 0, 18, 22, 8, 21, 11, 23, 0, 130, 104, 111, + 108, 100, 0, 4, 26, 18, 9, 0, 131, 114, 119, 97, 114, 100, 0, 68, 233, 0, 6, 246, 0, 7, 4, 1, 8, 16, 1, 10, 52, 1, 15, 81, 1, 21, 90, 1, 22, 117, 1, 23, 144, 1, 24, 215, 1, 25, 228, 1, 0, 6, 19, 22, 8, 16, 4, 17, 0, 130, 97, 99, 101, 0, 19, 4, 22, 8, 16, 4, 17, 0, 131, 112, 97, 99, 101, 0, 12, 21, 8, 25, 18, 0, 130, 114, 105, 100, 101, 0, 23, 0, 68, 25, 1, 17, 36, 1, 0, 21, 4, 24, 10, 0, 130, 110, 116, 101, 101, 0, 4, 21, 24, 4, 10, 0, 135, 117, 97, 114, 97, 110, 116, 101, 101, 0, 68, 59, 1, 7, 69, 1, 0, 24, 10, 44, 0, 131, 97, 117, 103, 101, 0, 8, 15, 12, 25, 12, 21, 19, 0, 130, 103, 101, 0, 22, 4, 9, 0, 130, 108, 115, 101, 0, 76, 97, 1, 24, 109, 1, 0, 24, 20, 4, 0, 132, 99, 113, 117, 105, 114, 101, 0, 23, 44, 0, + 130, 114, 117, 101, 0, 4, 0, 79, 126, 1, 24, 134, 1, 0, 9, 0, 131, 97, 108, 115, 101, 0, 6, 8, 5, 0, 131, 97, 117, 115, 101, 0, 4, 0, 71, 156, 1, 19, 193, 1, 21, 203, 1, 0, 18, 16, 0, 80, 166, 1, 18, 181, 1, 0, 18, 6, 4, 0, 135, 99, 111, 109, 109, 111, 100, 97, 116, 101, 0, 6, 6, 4, 0, 132, 109, 111, 100, 97, 116, 101, 0, 7, 24, 0, 132, 112, 100, 97, 116, 101, 0, 8, 19, 8, 22, 0, 132, 97, 114, 97, 116, 101, 0, 10, 8, 15, 15, 18, 6, 0, 130, 97, 103, 117, 101, 0, 8, 12, 6, 8, 21, 0, 131, 101, 105, 118, 101, 0, 12, 8, 11, 6, 0, 130, 105, 101, 102, 0, 17, 0, 76, 3, 2, 21, 16, 2, 0, 15, 8, 12, 6, 0, 133, 101, 105, 108, 105, 110, 103, 0, 12, 23, 22, 0, 131, 114, 105, 110, 103, 0, 70, 33, 2, 23, 44, 2, 0, 12, 23, 26, 22, 0, 131, 105, + 116, 99, 104, 0, 10, 12, 8, 11, 0, 129, 104, 116, 0, 72, 69, 2, 10, 80, 2, 18, 89, 2, 21, 156, 2, 24, 167, 2, 0, 22, 18, 18, 11, 6, 0, 131, 115, 101, 110, 0, 12, 21, 23, 22, 0, 129, 110, 103, 0, 12, 0, 86, 98, 2, 23, 124, 2, 0, 68, 105, 2, 22, 114, 2, 0, 12, 15, 0, 131, 105, 115, 111, 110, 0, 4, 6, 6, 18, 0, 131, 105, 111, 110, 0, 76, 131, 2, 22, 146, 2, 0, 23, 12, 19, 8, 21, 0, 134, 101, 116, 105, 116, 105, 111, 110, 0, 18, 19, 0, 131, 105, 116, 105, 111, 110, 0, 23, 24, 8, 21, 0, 131, 116, 117, 114, 110, 0, 85, 174, 2, 23, 183, 2, 0, 23, 8, 21, 0, 130, 117, 114, 110, 0, 8, 21, 0, 128, 114, 110, 0, 7, 8, 24, 22, 19, 0, 131, 101, 117, 100, 111, 0, 24, 18, 18, 15, 0, 129, 107, 117, 112, 0, 72, 219, 2, 18, 3, 3, 0, 76, 229, 2, 15, 238, + 2, 17, 248, 2, 0, 11, 23, 44, 0, 130, 101, 105, 114, 0, 23, 12, 9, 0, 131, 108, 116, 101, 114, 0, 23, 22, 12, 15, 0, 130, 101, 110, 101, 114, 0, 23, 4, 21, 8, 23, 17, 12, 0, 135, 116, 101, 114, 97, 116, 111, 114, 0, 72, 30, 3, 17, 38, 3, 24, 51, 3, 0, 15, 4, 9, 0, 129, 115, 101, 0, 4, 12, 23, 17, 18, 6, 0, 131, 97, 105, 110, 115, 0, 22, 17, 8, 6, 17, 18, 6, 0, 133, 115, 101, 110, 115, 117, 115, 0, 74, 86, 3, 11, 96, 3, 15, 118, 3, 17, 129, 3, 22, 218, 3, 24, 232, 3, 0, 11, 24, 4, 6, 0, 130, 103, 104, 116, 0, 71, 103, 3, 10, 110, 3, 0, 12, 26, 0, 129, 116, 104, 0, 17, 8, 15, 0, 129, 116, 104, 0, 22, 24, 8, 21, 0, 131, 115, 117, 108, 116, 0, 68, 139, 3, 8, 150, 3, 22, 210, 3, 0, 21, 4, 19, 19, 4, 0, 130, 101, 110, 116, 0, 85, 157, + 3, 25, 200, 3, 0, 68, 164, 3, 21, 175, 3, 0, 19, 4, 0, 132, 112, 97, 114, 101, 110, 116, 0, 4, 19, 0, 68, 185, 3, 19, 193, 3, 0, 133, 112, 97, 114, 101, 110, 116, 0, 4, 0, 131, 101, 110, 116, 0, 8, 15, 8, 21, 0, 130, 97, 110, 116, 0, 18, 6, 0, 130, 110, 115, 116, 0, 12, 9, 8, 17, 4, 16, 0, 132, 105, 102, 101, 115, 116, 0, 83, 239, 3, 23, 6, 4, 0, 87, 246, 3, 24, 254, 3, 0, 17, 12, 0, 131, 112, 117, 116, 0, 18, 0, 130, 116, 112, 117, 116, 0, 19, 24, 18, 0, 131, 116, 112, 117, 116, 0, 70, 29, 4, 8, 41, 4, 11, 51, 4, 21, 69, 4, 0, 8, 24, 20, 8, 21, 9, 0, 129, 110, 99, 121, 0, 23, 9, 4, 22, 0, 130, 101, 116, 121, 0, 6, 21, 4, 21, 12, 8, 11, 0, 135, 105, 101, 114, 97, 114, 99, 104, 121, 0, 4, 5, 12, 15, 0, 130, 114, 97, 114, 121, 0}; diff --git a/quantum/process_keycode/process_autocorrect.c b/quantum/process_keycode/process_autocorrect.c new file mode 100644 index 0000000000..abae5e7811 --- /dev/null +++ b/quantum/process_keycode/process_autocorrect.c @@ -0,0 +1,287 @@ +// Copyright 2021 Google LLC +// Copyright 2021 @filterpaper +// SPDX-License-Identifier: Apache-2.0 +// Original source: https://getreuer.info/posts/keyboards/autocorrection + +#include "process_autocorrect.h" +#include <string.h> +#include "keycode_config.h" + +#if __has_include("autocorrect_data.h") +# include "autocorrect_data.h" +#else +# pragma message "Autocorrect is using the default library." +# include "autocorrect_data_default.h" +#endif + +static uint8_t typo_buffer[AUTOCORRECT_MAX_LENGTH] = {KC_SPC}; +static uint8_t typo_buffer_size = 1; + +/** + * @brief function for querying the enabled state of autocorrect + * + * @return true if enabled + * @return false if disabled + */ +bool autocorrect_is_enabled(void) { + return keymap_config.autocorrect_enable; +} + +/** + * @brief Enables autocorrect and saves state to eeprom + * + */ +void autocorrect_enable(void) { + keymap_config.autocorrect_enable = true; + eeconfig_update_keymap(keymap_config.raw); +} + +/** + * @brief Disables autocorrect and saves state to eeprom + * + */ +void autocorrect_disable(void) { + keymap_config.autocorrect_enable = false; + typo_buffer_size = 0; + eeconfig_update_keymap(keymap_config.raw); +} + +/** + * @brief Toggles autocorrect's status and save state to eeprom + * + */ +void autocorrect_toggle(void) { + keymap_config.autocorrect_enable = !keymap_config.autocorrect_enable; + typo_buffer_size = 0; + eeconfig_update_keymap(keymap_config.raw); +} + +/** + * @brief handler for determining if autocorrect should process keypress + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @param typo_buffer_size passed along to allow resetting of autocorrect buffer + * @param mods allow processing of mod status + * @return true Allow autocorection + * @return false Stop processing and escape from autocorrect. + */ +__attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) { + // See quantum_keycodes.h for reference on these matched ranges. + switch (*keycode) { + // Exclude these keycodes from processing. + case KC_LSFT: + case KC_RSFT: + case KC_CAPS: + case QK_TO ... QK_ONE_SHOT_LAYER_MAX: + case QK_LAYER_TAP_TOGGLE ... QK_LAYER_MOD_MAX: + case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX: + return false; + + // Mask for base keycode from shifted keys. + case QK_LSFT ... QK_LSFT + 255: + case QK_RSFT ... QK_RSFT + 255: + if (*keycode >= QK_LSFT && *keycode <= (QK_LSFT + 255)) { + *mods |= MOD_LSFT; + } else { + *mods |= MOD_RSFT; + } + *keycode &= 0xFF; // Get the basic keycode. + return true; +#ifndef NO_ACTION_TAPPING + // Exclude tap-hold keys when they are held down + // and mask for base keycode when they are tapped. + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: +# ifdef NO_ACTION_LAYER + // Exclude Layer Tap, if layers are disabled + // but action tapping is still enabled. + return false; +# endif + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + // Exclude hold keycode + if (!record->tap.count) { + return false; + } + *keycode &= 0xFF; + break; +#else + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: + // Exclude if disabled + return false; +#endif + // Exclude swap hands keys when they are held down + // and mask for base keycode when they are tapped. + case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX: +#ifdef SWAP_HANDS_ENABLE + if (*keycode >= 0x56F0 || !record->tap.count) { + return false; + } + *keycode &= 0xFF; + break; +#else + // Exclude if disabled + return false; +#endif + } + + // Disable autocorrect while a mod other than shift is active. + if ((*mods & ~MOD_MASK_SHIFT) != 0) { + *typo_buffer_size = 0; + return false; + } + + return true; +} + +/** + * @brief handling for when autocorrection has been triggered + * + * @param backspaces number of characters to remove + * @param str pointer to PROGMEM string to replace mistyped seletion with + * @return true apply correction + * @return false user handled replacement + */ +__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str) { + return true; +} + +/** + * @brief Process handler for autocorrect feature + * + * @param keycode Keycode registered by matrix press, per keymap + * @param record keyrecord_t structure + * @return true Continue processing keycodes, and send to host + * @return false Stop processing keycodes, and don't send to host + */ +bool process_autocorrect(uint16_t keycode, keyrecord_t *record) { + uint8_t mods = get_mods(); +#ifndef NO_ACTION_ONESHOT + mods |= get_oneshot_mods(); +#endif + + if ((keycode >= AUTOCORRECT_ON && keycode <= AUTOCORRECT_TOGGLE) && record->event.pressed) { + if (keycode == AUTOCORRECT_ON) { + autocorrect_enable(); + } else if (keycode == AUTOCORRECT_OFF) { + autocorrect_disable(); + } else if (keycode == AUTOCORRECT_TOGGLE) { + autocorrect_toggle(); + } else { + return true; + } + + return false; + } + + if (!keymap_config.autocorrect_enable) { + typo_buffer_size = 0; + return true; + } + + if (!record->event.pressed) { + return true; + } + + // autocorrect keycode verification and extraction + if (!process_autocorrect_user(&keycode, record, &typo_buffer_size, &mods)) { + return true; + } + + // keycode buffer check + switch (keycode) { + case KC_A ... KC_Z: + // process normally + break; + case KC_1 ... KC_0: + case KC_TAB ... KC_SEMICOLON: + case KC_GRAVE ... KC_SLASH: + // Set a word boundary if space, period, digit, etc. is pressed. + keycode = KC_SPC; + break; + case KC_ENTER: + // Behave more conservatively for the enter key. Reset, so that enter + // can't be used on a word ending. + typo_buffer_size = 0; + keycode = KC_SPC; + break; + case KC_BSPC: + // Remove last character from the buffer. + if (typo_buffer_size > 0) { + --typo_buffer_size; + } + return true; + case KC_QUOTE: + // Treat " (shifted ') as a word boundary. + if ((mods & MOD_MASK_SHIFT) != 0) { + keycode = KC_SPC; + } + break; + default: + // Clear state if some other non-alpha key is pressed. + typo_buffer_size = 0; + return true; + } + + // Rotate oldest character if buffer is full. + if (typo_buffer_size >= AUTOCORRECT_MAX_LENGTH) { + memmove(typo_buffer, typo_buffer + 1, AUTOCORRECT_MAX_LENGTH - 1); + typo_buffer_size = AUTOCORRECT_MAX_LENGTH - 1; + } + + // Append `keycode` to buffer. + typo_buffer[typo_buffer_size++] = keycode; + // Return if buffer is smaller than the shortest word. + if (typo_buffer_size < AUTOCORRECT_MIN_LENGTH) { + return true; + } + + // Check for typo in buffer using a trie stored in `autocorrect_data`. + uint16_t state = 0; + uint8_t code = pgm_read_byte(autocorrect_data + state); + for (int8_t i = typo_buffer_size - 1; i >= 0; --i) { + uint8_t const key_i = typo_buffer[i]; + + if (code & 64) { // Check for match in node with multiple children. + code &= 63; + for (; code != key_i; code = pgm_read_byte(autocorrect_data + (state += 3))) { + if (!code) return true; + } + // Follow link to child node. + state = (pgm_read_byte(autocorrect_data + state + 1) | pgm_read_byte(autocorrect_data + state + 2) << 8); + // Check for match in node with single child. + } else if (code != key_i) { + return true; + } else if (!(code = pgm_read_byte(autocorrect_data + (++state)))) { + ++state; + } + + // Stop if `state` becomes an invalid index. This should not normally + // happen, it is a safeguard in case of a bug, data corruption, etc. + if (state >= DICTIONARY_SIZE) { + return true; + } + + code = pgm_read_byte(autocorrect_data + state); + + if (code & 128) { // A typo was found! Apply autocorrect. + const uint8_t backspaces = (code & 63) + !record->event.pressed; + if (apply_autocorrect(backspaces, (char const *)(autocorrect_data + state + 1))) { + for (uint8_t i = 0; i < backspaces; ++i) { + tap_code(KC_BSPC); + } + send_string_P((char const *)(autocorrect_data + state + 1)); + } + + if (keycode == KC_SPC) { + typo_buffer[0] = KC_SPC; + typo_buffer_size = 1; + return true; + } else { + typo_buffer_size = 0; + return false; + } + } + } + return true; +} diff --git a/quantum/process_keycode/process_autocorrect.h b/quantum/process_keycode/process_autocorrect.h new file mode 100644 index 0000000000..c7596107e5 --- /dev/null +++ b/quantum/process_keycode/process_autocorrect.h @@ -0,0 +1,17 @@ +// Copyright 2021 Google LLC +// Copyright 2021 @filterpaper +// SPDX-License-Identifier: Apache-2.0 +// Original source: https://getreuer.info/posts/keyboards/autocorrection + +#pragma once + +#include "quantum.h" + +bool process_autocorrect(uint16_t keycode, keyrecord_t *record); +bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods); +bool apply_autocorrect(uint8_t backspaces, const char *str); + +bool autocorrect_is_enabled(void); +void autocorrect_enable(void); +void autocorrect_disable(void); +void autocorrect_toggle(void); 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_ucis.c b/quantum/process_keycode/process_ucis.c index 6a8d8f0ff6..646471bc4d 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -15,6 +15,9 @@ */ #include "process_ucis.h" +#include "unicode.h" +#include "keycode.h" +#include "wait.h" qk_ucis_state_t qk_ucis_state; @@ -26,9 +29,7 @@ void qk_ucis_start(void) { } __attribute__((weak)) void qk_ucis_start_user(void) { - unicode_input_start(); - register_hex(0x2328); // ⌨ - unicode_input_finish(); + register_unicode(0x2328); // ⌨ } __attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {} @@ -51,10 +52,7 @@ static bool is_uni_seq(char *seq) { __attribute__((weak)) void qk_ucis_symbol_fallback(void) { for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { - uint8_t keycode = qk_ucis_state.codes[i]; - register_code(keycode); - unregister_code(keycode); - wait_ms(UNICODE_TYPE_DELAY); + tap_code(qk_ucis_state.codes[i]); } } @@ -63,7 +61,6 @@ __attribute__((weak)) void qk_ucis_cancel(void) {} void register_ucis(const uint32_t *code_points) { for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) { register_unicode(code_points[i]); - wait_ms(UNICODE_TYPE_DELAY); } } @@ -94,9 +91,7 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) { case KC_ENTER: case KC_ESCAPE: for (uint8_t i = 0; i < qk_ucis_state.count; i++) { - register_code(KC_BACKSPACE); - unregister_code(KC_BACKSPACE); - wait_ms(UNICODE_TYPE_DELAY); + tap_code(KC_BACKSPACE); } if (keycode == KC_ESCAPE) { diff --git a/quantum/process_keycode/process_ucis.h b/quantum/process_keycode/process_ucis.h index a667430bda..3de0707762 100644 --- a/quantum/process_keycode/process_ucis.h +++ b/quantum/process_keycode/process_ucis.h @@ -16,8 +16,10 @@ #pragma once -#include "quantum.h" -#include "process_unicode_common.h" +#include <stdbool.h> +#include <stdint.h> + +#include "action.h" #ifndef UCIS_MAX_SYMBOL_LENGTH # define UCIS_MAX_SYMBOL_LENGTH 32 diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 18a1d8bc1f..99cc2f5f26 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -15,14 +15,14 @@ */ #include "process_unicode.h" -#include "action_util.h" -#include "eeprom.h" +#include "unicode.h" +#include "quantum_keycodes.h" bool process_unicode(uint16_t keycode, keyrecord_t *record) { - if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) { - unicode_input_start(); - register_hex(keycode & 0x7FFF); - unicode_input_finish(); + if (record->event.pressed) { + if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX) { + register_unicode(keycode & 0x7FFF); + } } return true; } diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index 22765ad560..341bc8d861 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h @@ -16,6 +16,9 @@ #pragma once -#include "process_unicode_common.h" +#include <stdbool.h> +#include <stdint.h> + +#include "action.h" bool process_unicode(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 8de31c055c..bd5fc560f3 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -15,289 +15,17 @@ */ #include "process_unicode_common.h" -#include "eeprom.h" -#include "utf8.h" +#include "unicode.h" +#include "action_util.h" +#include "keycode.h" -unicode_config_t unicode_config; -uint8_t unicode_saved_mods; -bool unicode_saved_caps_lock; -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_index; -#endif - -void unicode_input_mode_init(void) { - unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); -#if UNICODE_SELECTED_MODES != -1 -# if UNICODE_CYCLE_PERSIST - // Find input_mode in selected modes - int8_t i; - for (i = 0; i < selected_count; i++) { - if (selected[i] == unicode_config.input_mode) { - selected_index = i; - break; - } - } - if (i == selected_count) { - // Not found: input_mode isn't selected, change to one that is - unicode_config.input_mode = selected[selected_index = 0]; - } -# else - // Always change to the first selected input mode - unicode_config.input_mode = selected[selected_index = 0]; -# endif -#endif - dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode); -} - -uint8_t get_unicode_input_mode(void) { - return unicode_config.input_mode; -} - -void set_unicode_input_mode(uint8_t mode) { - unicode_config.input_mode = mode; - persist_unicode_input_mode(); - dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); -} - -void cycle_unicode_input_mode(int8_t offset) { -#if UNICODE_SELECTED_MODES != -1 - selected_index = (selected_index + offset) % selected_count; - if (selected_index < 0) { - selected_index += selected_count; - } - unicode_config.input_mode = selected[selected_index]; -# if UNICODE_CYCLE_PERSIST - persist_unicode_input_mode(); -# endif - dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode); -#endif -} - -void persist_unicode_input_mode(void) { - eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); -} - -__attribute__((weak)) void unicode_input_start(void) { - unicode_saved_caps_lock = host_keyboard_led_state().caps_lock; - unicode_saved_num_lock = host_keyboard_led_state().num_lock; - - // Note the order matters here! - // Need to do this before we mess around with the mods, or else - // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work - // correctly in the shifted case. - if (unicode_config.input_mode == UC_LNX && unicode_saved_caps_lock) { - tap_code(KC_CAPS_LOCK); - } - - unicode_saved_mods = get_mods(); // Save current mods - clear_mods(); // Unregister mods to start from a clean state - clear_weak_mods(); - - switch (unicode_config.input_mode) { - case UC_MAC: - register_code(UNICODE_KEY_MAC); - break; - case UC_LNX: - tap_code16(UNICODE_KEY_LNX); - break; - case UC_WIN: - // For increased reliability, use numpad keys for inputting digits - if (!unicode_saved_num_lock) { - tap_code(KC_NUM_LOCK); - } - register_code(KC_LEFT_ALT); - wait_ms(UNICODE_TYPE_DELAY); - tap_code(KC_KP_PLUS); - break; - case UC_WINC: - tap_code(UNICODE_KEY_WINC); - tap_code(KC_U); - break; - case UC_EMACS: - // The usual way to type unicode in emacs is C-x-8 <RET> then the unicode number in hex - tap_code16(LCTL(KC_X)); - tap_code16(KC_8); - tap_code16(KC_ENTER); - break; - } - - wait_ms(UNICODE_TYPE_DELAY); -} - -__attribute__((weak)) void unicode_input_finish(void) { - switch (unicode_config.input_mode) { - case UC_MAC: - unregister_code(UNICODE_KEY_MAC); - break; - case UC_LNX: - tap_code(KC_SPACE); - if (unicode_saved_caps_lock) { - tap_code(KC_CAPS_LOCK); - } - break; - case UC_WIN: - unregister_code(KC_LEFT_ALT); - if (!unicode_saved_num_lock) { - tap_code(KC_NUM_LOCK); - } - break; - case UC_WINC: - tap_code(KC_ENTER); - break; - case UC_EMACS: - tap_code16(KC_ENTER); - break; - } - - set_mods(unicode_saved_mods); // Reregister previously set mods -} - -__attribute__((weak)) void unicode_input_cancel(void) { - switch (unicode_config.input_mode) { - case UC_MAC: - unregister_code(UNICODE_KEY_MAC); - break; - case UC_LNX: - tap_code(KC_ESCAPE); - if (unicode_saved_caps_lock) { - tap_code(KC_CAPS_LOCK); - } - break; - case UC_WINC: - tap_code(KC_ESCAPE); - break; - case UC_WIN: - unregister_code(KC_LEFT_ALT); - if (!unicode_saved_num_lock) { - tap_code(KC_NUM_LOCK); - } - break; - case UC_EMACS: - tap_code16(LCTL(KC_G)); // C-g cancels - break; - } - - set_mods(unicode_saved_mods); // Reregister previously set mods -} - -// clang-format off - -static void send_nibble_wrapper(uint8_t digit) { - if (unicode_config.input_mode == UC_WIN) { - uint8_t kc = digit < 10 - ? KC_KP_1 + (10 + digit - 1) % 10 - : KC_A + (digit - 10); - tap_code(kc); - return; - } - send_nibble(digit); -} - -// clang-format on - -void register_hex(uint16_t hex) { - for (int i = 3; i >= 0; i--) { - uint8_t digit = ((hex >> (i * 4)) & 0xF); - send_nibble_wrapper(digit); - } -} - -void register_hex32(uint32_t hex) { - bool onzerostart = true; - for (int i = 7; i >= 0; i--) { - if (i <= 3) { - onzerostart = false; - } - uint8_t digit = ((hex >> (i * 4)) & 0xF); - if (digit == 0) { - if (!onzerostart) { - send_nibble_wrapper(digit); - } - } else { - send_nibble_wrapper(digit); - onzerostart = false; - } - } -} - -void register_unicode(uint32_t code_point) { - if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) { - // Code point out of range, do nothing - return; - } - - unicode_input_start(); - if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) { - // Convert code point to UTF-16 surrogate pair on macOS - code_point -= 0x10000; - uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10; - register_hex32(hi + 0xD800); - register_hex32(lo + 0xDC00); - } else { - register_hex32(code_point); - } - unicode_input_finish(); -} - -void send_unicode_string(const char *str) { - if (!str) { - return; - } - - while (*str) { - int32_t code_point = 0; - str = decode_utf8(str, &code_point); - - if (code_point >= 0) { - register_unicode(code_point); - } - } -} - -// clang-format off - -static void audio_helper(void) { -#ifdef AUDIO_ENABLE - switch (get_unicode_input_mode()) { -# ifdef UNICODE_SONG_MAC - static float song_mac[][2] = UNICODE_SONG_MAC; - case UC_MAC: - PLAY_SONG(song_mac); - break; -# endif -# ifdef UNICODE_SONG_LNX - static float song_lnx[][2] = UNICODE_SONG_LNX; - case UC_LNX: - PLAY_SONG(song_lnx); - break; -# endif -# ifdef UNICODE_SONG_WIN - static float song_win[][2] = UNICODE_SONG_WIN; - case UC_WIN: - PLAY_SONG(song_win); - break; -# endif -# ifdef UNICODE_SONG_BSD - static float song_bsd[][2] = UNICODE_SONG_BSD; - case UC_BSD: - PLAY_SONG(song_bsd); - break; -# endif -# ifdef UNICODE_SONG_WINC - static float song_winc[][2] = UNICODE_SONG_WINC; - case UC_WINC: - PLAY_SONG(song_winc); - break; -# endif - } +#if defined(UNICODE_ENABLE) +# include "process_unicode.h" +#elif defined(UNICODEMAP_ENABLE) +# include "process_unicodemap.h" +#elif defined(UCIS_ENABLE) +# include "process_ucis.h" #endif -} - -// clang-format on bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { @@ -305,35 +33,27 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case UNICODE_MODE_FORWARD: cycle_unicode_input_mode(shifted ? -1 : +1); - audio_helper(); break; case UNICODE_MODE_REVERSE: cycle_unicode_input_mode(shifted ? +1 : -1); - audio_helper(); break; case UNICODE_MODE_MAC: set_unicode_input_mode(UC_MAC); - audio_helper(); break; case UNICODE_MODE_LNX: set_unicode_input_mode(UC_LNX); - audio_helper(); break; case UNICODE_MODE_WIN: set_unicode_input_mode(UC_WIN); - audio_helper(); break; case UNICODE_MODE_BSD: set_unicode_input_mode(UC_BSD); - audio_helper(); break; case UNICODE_MODE_WINC: set_unicode_input_mode(UC_WINC); - audio_helper(); break; case UNICODE_MODE_EMACS: set_unicode_input_mode(UC_EMACS); - audio_helper(); break; } } diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 15e798dbb3..fd09a41818 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -16,187 +16,9 @@ #pragma once -#include "quantum.h" +#include <stdbool.h> +#include <stdint.h> -#if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1 -# error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" -#endif - -// Keycodes used for starting Unicode input on different platforms -#ifndef UNICODE_KEY_MAC -# define UNICODE_KEY_MAC KC_LEFT_ALT -#endif -#ifndef UNICODE_KEY_LNX -# define UNICODE_KEY_LNX LCTL(LSFT(KC_U)) -#endif -#ifndef UNICODE_KEY_WINC -# define UNICODE_KEY_WINC KC_RIGHT_ALT -#endif - -// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle) -// Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX -#ifndef UNICODE_SELECTED_MODES -# define UNICODE_SELECTED_MODES -1 -#endif - -// Whether input mode changes in cycle should be written to EEPROM -#ifndef UNICODE_CYCLE_PERSIST -# define UNICODE_CYCLE_PERSIST true -#endif - -// Delay between starting Unicode input and sending a sequence, in ms -#ifndef UNICODE_TYPE_DELAY -# define UNICODE_TYPE_DELAY 10 -#endif - -// Deprecated aliases -#if !defined(UNICODE_KEY_MAC) && defined(UNICODE_KEY_OSX) -# define UNICODE_KEY_MAC UNICODE_KEY_OSX -#endif -#if !defined(UNICODE_SONG_MAC) && defined(UNICODE_SONG_OSX) -# define UNICODE_SONG_MAC UNICODE_SONG_OSX -#endif -#define UC_OSX UC_MAC - -enum unicode_input_modes { - UC_MAC, // macOS using Unicode Hex Input - UC_LNX, // Linux using IBus - UC_WIN, // Windows using EnableHexNumpad - UC_BSD, // BSD (not implemented) - UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose) - UC_EMACS, // Emacs is an operating system in search of a good text editor - UC__COUNT // Number of available input modes (always leave at the end) -}; - -typedef union { - uint32_t raw; - struct { - uint8_t input_mode : 8; - }; -} unicode_config_t; - -extern unicode_config_t unicode_config; - -void unicode_input_mode_init(void); -uint8_t get_unicode_input_mode(void); -void set_unicode_input_mode(uint8_t mode); -void cycle_unicode_input_mode(int8_t offset); -void persist_unicode_input_mode(void); - -void unicode_input_start(void); -void unicode_input_finish(void); -void unicode_input_cancel(void); - -void register_hex(uint16_t hex); -void register_hex32(uint32_t hex); -void register_unicode(uint32_t code_point); - -void send_unicode_string(const char *str); +#include "action.h" bool process_unicode_common(uint16_t keycode, keyrecord_t *record); - -#define UC_BSPC UC(0x0008) -#define UC_SPC UC(0x0020) - -#define UC_EXLM UC(0x0021) -#define UC_DQUT UC(0x0022) -#define UC_HASH UC(0x0023) -#define UC_DLR UC(0x0024) -#define UC_PERC UC(0x0025) -#define UC_AMPR UC(0x0026) -#define UC_QUOT UC(0x0027) -#define UC_LPRN UC(0x0028) -#define UC_RPRN UC(0x0029) -#define UC_ASTR UC(0x002A) -#define UC_PLUS UC(0x002B) -#define UC_COMM UC(0x002C) -#define UC_DASH UC(0x002D) -#define UC_DOT UC(0x002E) -#define UC_SLSH UC(0x002F) - -#define UC_0 UC(0x0030) -#define UC_1 UC(0x0031) -#define UC_2 UC(0x0032) -#define UC_3 UC(0x0033) -#define UC_4 UC(0x0034) -#define UC_5 UC(0x0035) -#define UC_6 UC(0x0036) -#define UC_7 UC(0x0037) -#define UC_8 UC(0x0038) -#define UC_9 UC(0x0039) - -#define UC_COLN UC(0x003A) -#define UC_SCLN UC(0x003B) -#define UC_LT UC(0x003C) -#define UC_EQL UC(0x003D) -#define UC_GT UC(0x003E) -#define UC_QUES UC(0x003F) -#define UC_AT UC(0x0040) - -#define UC_A UC(0x0041) -#define UC_B UC(0x0042) -#define UC_C UC(0x0043) -#define UC_D UC(0x0044) -#define UC_E UC(0x0045) -#define UC_F UC(0x0046) -#define UC_G UC(0x0047) -#define UC_H UC(0x0048) -#define UC_I UC(0x0049) -#define UC_J UC(0x004A) -#define UC_K UC(0x004B) -#define UC_L UC(0x004C) -#define UC_M UC(0x004D) -#define UC_N UC(0x004E) -#define UC_O UC(0x004F) -#define UC_P UC(0x0050) -#define UC_Q UC(0x0051) -#define UC_R UC(0x0052) -#define UC_S UC(0x0053) -#define UC_T UC(0x0054) -#define UC_U UC(0x0055) -#define UC_V UC(0x0056) -#define UC_W UC(0x0057) -#define UC_X UC(0x0058) -#define UC_Y UC(0x0059) -#define UC_Z UC(0x005A) - -#define UC_LBRC UC(0x005B) -#define UC_BSLS UC(0x005C) -#define UC_RBRC UC(0x005D) -#define UC_CIRM UC(0x005E) -#define UC_UNDR UC(0x005F) - -#define UC_GRV UC(0x0060) - -#define UC_a UC(0x0061) -#define UC_b UC(0x0062) -#define UC_c UC(0x0063) -#define UC_d UC(0x0064) -#define UC_e UC(0x0065) -#define UC_f UC(0x0066) -#define UC_g UC(0x0067) -#define UC_h UC(0x0068) -#define UC_i UC(0x0069) -#define UC_j UC(0x006A) -#define UC_k UC(0x006B) -#define UC_l UC(0x006C) -#define UC_m UC(0x006D) -#define UC_n UC(0x006E) -#define UC_o UC(0x006F) -#define UC_p UC(0x0070) -#define UC_q UC(0x0071) -#define UC_r UC(0x0072) -#define UC_s UC(0x0073) -#define UC_t UC(0x0074) -#define UC_u UC(0x0075) -#define UC_v UC(0x0076) -#define UC_w UC(0x0077) -#define UC_x UC(0x0078) -#define UC_y UC(0x0079) -#define UC_z UC(0x007A) - -#define UC_LCBR UC(0x007B) -#define UC_PIPE UC(0x007C) -#define UC_RCBR UC(0x007D) -#define UC_TILD UC(0x007E) -#define UC_DEL UC(0x007F) diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 459397014d..979d773b05 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -15,6 +15,11 @@ */ #include "process_unicodemap.h" +#include "unicode.h" +#include "quantum_keycodes.h" +#include "keycode.h" +#include "action_util.h" +#include "host.h" __attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) { if (keycode >= QK_UNICODEMAP_PAIR) { diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index c429859bbb..73f5449864 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h @@ -16,7 +16,11 @@ #pragma once -#include "process_unicode_common.h" +#include <stdbool.h> +#include <stdint.h> + +#include "action.h" +#include "progmem.h" extern const uint32_t PROGMEM unicode_map[]; diff --git a/quantum/quantum.c b/quantum/quantum.c index 9a0016b150..ff36e14775 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -272,6 +272,9 @@ bool process_record_quantum(keyrecord_t *record) { #if defined(VIA_ENABLE) process_record_via(keycode, record) && #endif +#if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE) + process_auto_mouse(keycode, record) && +#endif process_record_kb(keycode, record) && #if defined(SECURE_ENABLE) process_secure(keycode, record) && @@ -336,6 +339,9 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef PROGRAMMABLE_BUTTON_ENABLE process_programmable_button(keycode, record) && #endif +#ifdef AUTOCORRECT_ENABLE + process_autocorrect(keycode, record) && +#endif true)) { return false; } @@ -361,8 +367,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/quantum.h b/quantum/quantum.h index 8d74f2be38..9c1b9952b8 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -109,6 +109,7 @@ extern layer_state_t layer_state; #endif #ifdef UNICODE_COMMON_ENABLE +# include "unicode.h" # include "process_unicode_common.h" #endif @@ -235,6 +236,10 @@ extern layer_state_t layer_state; # include "process_caps_word.h" #endif +#ifdef AUTOCORRECT_ENABLE +# include "process_autocorrect.h" +#endif + // For tri-layer void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index c8f03fa1ce..abf3f1a384 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -611,6 +611,10 @@ enum quantum_keycodes { UNICODE_MODE_EMACS, + AUTOCORRECT_ON, + AUTOCORRECT_OFF, + AUTOCORRECT_TOGGLE, + // Start of custom keycode range for keyboards and keymaps - always leave at the end SAFE_RANGE }; @@ -799,6 +803,10 @@ enum quantum_keycodes { #define EH_LEFT MAGIC_EE_HANDS_LEFT #define EH_RGHT MAGIC_EE_HANDS_RIGHT +#define CRT_ON AUTOCORRECT_ON +#define CRT_OFF AUTOCORRECT_OFF +#define CRT_TOG AUTOCORRECT_TOGGLE + // GOTO layer - 256 layer max #define TO(layer) (QK_TO | ((layer)&0xFF)) diff --git a/quantum/quantum_keycodes_legacy.h b/quantum/quantum_keycodes_legacy.h index 51380d9c50..1de81b4c0f 100644 --- a/quantum/quantum_keycodes_legacy.h +++ b/quantum/quantum_keycodes_legacy.h @@ -4,7 +4,6 @@ // Deprecated Quantum keycodes -#define RESET QK_BOOTLOADER #define DEBUG QK_DEBUG_TOGGLE #define GRAVE_ESC QK_GRAVE_ESCAPE #define EEPROM_RESET QK_CLEAR_EEPROM @@ -13,4 +12,5 @@ #define EEP_RST QK_CLEAR_EEPROM #define TERM_ON _Static_assert(false, "The Terminal feature has been removed from QMK. Please remove use of TERM_ON/TERM_OFF from your keymap.") -#define TERM_OFF _Static_assert(false, "The Terminal feature has been removed from QMK.. Please remove use of TERM_ON/TERM_OFF from your keymap.")
\ No newline at end of file +#define TERM_OFF _Static_assert(false, "The Terminal feature has been removed from QMK.. Please remove use of TERM_ON/TERM_OFF from your keymap.") +// #define RESET _Static_assert(false, "The RESET keycode has been removed from QMK.. Please remove use from your keymap.") diff --git a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h index 31dffcbc5a..69bf265d14 100644 --- a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h +++ b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h @@ -13,7 +13,7 @@ bool JELLYBEAN_RAINDROPS(effect_params_t* params) { if (!params->init) { // Change one LED every tick, make sure speed is not 0 if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) { - jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL, params); + jellybean_raindrops_set_color(rand() % RGB_MATRIX_LED_COUNT, params); } return false; } diff --git a/quantum/rgb_matrix/animations/pixel_flow_anim.h b/quantum/rgb_matrix/animations/pixel_flow_anim.h index 714f5d174e..8628c3c2ec 100644 --- a/quantum/rgb_matrix/animations/pixel_flow_anim.h +++ b/quantum/rgb_matrix/animations/pixel_flow_anim.h @@ -7,7 +7,7 @@ RGB_MATRIX_EFFECT(PIXEL_FLOW) static bool PIXEL_FLOW(effect_params_t* params) { // LED state array - static RGB led[DRIVER_LED_TOTAL]; + static RGB led[RGB_MATRIX_LED_COUNT]; static uint32_t wait_timer = 0; if (wait_timer > g_rgb_timer) { @@ -21,7 +21,7 @@ static bool PIXEL_FLOW(effect_params_t* params) { if (params->init) { // Clear LEDs and fill the state array rgb_matrix_set_color_all(0, 0, 0); - for (uint8_t j = 0; j < DRIVER_LED_TOTAL; ++j) { + for (uint8_t j = 0; j < RGB_MATRIX_LED_COUNT; ++j) { led[j] = (random8() & 2) ? (RGB){0, 0, 0} : hsv_to_rgb((HSV){random8(), qadd8(random8() >> 1, 127), rgb_matrix_config.hsv.v}); } } diff --git a/quantum/rgb_matrix/animations/pixel_rain_anim.h b/quantum/rgb_matrix/animations/pixel_rain_anim.h index ce2528a26d..fded60340f 100644 --- a/quantum/rgb_matrix/animations/pixel_rain_anim.h +++ b/quantum/rgb_matrix/animations/pixel_rain_anim.h @@ -41,7 +41,7 @@ static bool PIXEL_RAIN(effect_params_t* params) { RGB_MATRIX_USE_LIMITS(led_min, led_max); if (g_rgb_timer > wait_timer) { - rain_pixel(mod8(random8(), DRIVER_LED_TOTAL), params, random8() & 2); + rain_pixel(mod8(random8(), RGB_MATRIX_LED_COUNT), params, random8() & 2); } return rgb_matrix_check_finished_leds(led_max); } diff --git a/quantum/rgb_matrix/animations/raindrops_anim.h b/quantum/rgb_matrix/animations/raindrops_anim.h index a508e51183..6b92d649ad 100644 --- a/quantum/rgb_matrix/animations/raindrops_anim.h +++ b/quantum/rgb_matrix/animations/raindrops_anim.h @@ -24,7 +24,7 @@ bool RAINDROPS(effect_params_t* params) { if (!params->init) { // Change one LED every tick, make sure speed is not 0 if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) { - raindrops_set_color(random8() % DRIVER_LED_TOTAL, params); + raindrops_set_color(random8() % RGB_MATRIX_LED_COUNT, params); } } else { for (int i = led_min; i < led_max; i++) { diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c index 2730686839..ae61e75535 100644 --- a/quantum/rgb_matrix/rgb_matrix.c +++ b/quantum/rgb_matrix/rgb_matrix.c @@ -202,7 +202,7 @@ void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) - for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) + for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) rgb_matrix_set_color(i, red, green, blue); #else rgb_matrix_driver.set_color_all(red, green, blue); @@ -461,13 +461,13 @@ void rgb_matrix_indicators_advanced(effect_params_t *params) { * and not sure which would be better. Otherwise, this should be called from * rgb_task_render, right before the iter++ line. */ -#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL +#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1); uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; + if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; #else uint8_t min = 0; - uint8_t max = DRIVER_LED_TOTAL; + uint8_t max = RGB_MATRIX_LED_COUNT; #endif rgb_matrix_indicators_advanced_kb(min, max); rgb_matrix_indicators_advanced_user(min, max); diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h index fc9fc3e020..0b35e98f45 100644 --- a/quantum/rgb_matrix/rgb_matrix.h +++ b/quantum/rgb_matrix/rgb_matrix.h @@ -47,15 +47,15 @@ #endif #ifndef RGB_MATRIX_LED_PROCESS_LIMIT -# define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 +# define RGB_MATRIX_LED_PROCESS_LIMIT (RGB_MATRIX_LED_COUNT + 4) / 5 #endif -#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL +#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT # if defined(RGB_MATRIX_SPLIT) # define RGB_MATRIX_USE_LIMITS(min, max) \ uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; \ + if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; \ uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; @@ -63,20 +63,20 @@ # define RGB_MATRIX_USE_LIMITS(min, max) \ uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \ uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \ - if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; + if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; # endif #else # if defined(RGB_MATRIX_SPLIT) # define RGB_MATRIX_USE_LIMITS(min, max) \ uint8_t min = 0; \ - uint8_t max = DRIVER_LED_TOTAL; \ + uint8_t max = RGB_MATRIX_LED_COUNT; \ const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \ if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \ if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0]; # else # define RGB_MATRIX_USE_LIMITS(min, max) \ uint8_t min = 0; \ - uint8_t max = DRIVER_LED_TOTAL; + uint8_t max = RGB_MATRIX_LED_COUNT; # endif #endif @@ -246,9 +246,9 @@ static inline bool rgb_matrix_check_finished_leds(uint8_t led_idx) { uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; return led_idx < k_rgb_matrix_split[0]; } else - return led_idx < DRIVER_LED_TOTAL; + return led_idx < RGB_MATRIX_LED_COUNT; #else - return led_idx < DRIVER_LED_TOTAL; + return led_idx < RGB_MATRIX_LED_COUNT; #endif } diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index 27fa7369bf..e75b2c6c9d 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -106,7 +106,7 @@ static void init(void) { # endif # endif - for (int index = 0; index < DRIVER_LED_TOTAL; index++) { + for (int index = 0; index < RGB_MATRIX_LED_COUNT; index++) { bool enabled = true; // This only caches it for later @@ -336,13 +336,13 @@ const rgb_matrix_driver_t rgb_matrix_driver = { # endif // LED color buffer -LED_TYPE rgb_matrix_ws2812_array[DRIVER_LED_TOTAL]; +LED_TYPE rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT]; static void init(void) {} static void flush(void) { // Assumes use of RGB_DI_PIN - ws2812_setleds(rgb_matrix_ws2812_array, DRIVER_LED_TOTAL); + ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT); } // Set an led in the buffer to a color @@ -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/rgb_matrix/rgb_matrix_types.h b/quantum/rgb_matrix/rgb_matrix_types.h index d0ac4e4466..eea603c41c 100644 --- a/quantum/rgb_matrix/rgb_matrix_types.h +++ b/quantum/rgb_matrix/rgb_matrix_types.h @@ -78,8 +78,8 @@ typedef struct PACKED { typedef struct PACKED { uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS]; - led_point_t point[DRIVER_LED_TOTAL]; - uint8_t flags[DRIVER_LED_TOTAL]; + led_point_t point[RGB_MATRIX_LED_COUNT]; + uint8_t flags[RGB_MATRIX_LED_COUNT]; } led_config_t; typedef union { diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index e5d3a98bea..73b352cea8 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c @@ -16,7 +16,6 @@ #include <math.h> #include <string.h> #include <stdlib.h> -#include "wait.h" #include "progmem.h" #include "sync_timer.h" #include "rgblight.h" @@ -410,7 +409,6 @@ void rgblight_disable(void) { dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); rgblight_timer_disable(); RGBLIGHT_SPLIT_SET_CHANGE_MODE; - wait_ms(50); rgblight_set(); } @@ -419,7 +417,6 @@ void rgblight_disable_noeeprom(void) { dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); rgblight_timer_disable(); RGBLIGHT_SPLIT_SET_CHANGE_MODE; - wait_ms(50); rgblight_set(); } @@ -704,7 +701,6 @@ void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8 #endif } rgblight_set(); - wait_ms(1); } void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { 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/split_common/split_util.c b/quantum/split_common/split_util.c index 4892b7f8d8..0b3338ed6f 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c @@ -139,6 +139,20 @@ void split_pre_init(void) { if (!eeconfig_is_enabled()) { eeconfig_init(); } + // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS within the emulated eeprom via dfu-util or another tool +# if defined(INIT_EE_HANDS_LEFT) || defined(INIT_EE_HANDS_RIGHT) +# if defined(INIT_EE_HANDS_LEFT) +# pragma message "Faking EE_HANDS for left hand" + const bool should_be_left = true; +# else +# pragma message "Faking EE_HANDS for right hand" + const bool should_be_left = false; +# endif + bool is_left = eeconfig_read_handedness(); + if (is_left != should_be_left) { + eeconfig_update_handedness(should_be_left); + } +# endif // defined(INIT_EE_HANDS_LEFT) || defined(INIT_EE_HANDS_RIGHT) #endif isLeftHand = is_keyboard_left(); diff --git a/quantum/unicode/unicode.c b/quantum/unicode/unicode.c new file mode 100644 index 0000000000..3f934c9277 --- /dev/null +++ b/quantum/unicode/unicode.c @@ -0,0 +1,383 @@ +/* Copyright 2022 + * + * 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 "unicode.h" + +#include "eeprom.h" +#include "eeconfig.h" +#include "action.h" +#include "action_util.h" +#include "host.h" +#include "keycode.h" +#include "wait.h" +#include "audio.h" +#include "send_string.h" +#include "utf8.h" + +#if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1 +# error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" +#endif + +// Keycodes used for starting Unicode input on different platforms +#ifndef UNICODE_KEY_MAC +# define UNICODE_KEY_MAC KC_LEFT_ALT +#endif +#ifndef UNICODE_KEY_LNX +# define UNICODE_KEY_LNX LCTL(LSFT(KC_U)) +#endif +#ifndef UNICODE_KEY_WINC +# define UNICODE_KEY_WINC KC_RIGHT_ALT +#endif + +// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle) +// Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX +#ifndef UNICODE_SELECTED_MODES +# define UNICODE_SELECTED_MODES -1 +#endif + +// Whether input mode changes in cycle should be written to EEPROM +#ifndef UNICODE_CYCLE_PERSIST +# define UNICODE_CYCLE_PERSIST true +#endif + +// Delay between starting Unicode input and sending a sequence, in ms +#ifndef UNICODE_TYPE_DELAY +# define UNICODE_TYPE_DELAY 10 +#endif + +unicode_config_t unicode_config; +uint8_t unicode_saved_mods; +led_t unicode_saved_led_state; + +#if UNICODE_SELECTED_MODES != -1 +static uint8_t selected[] = {UNICODE_SELECTED_MODES}; +static int8_t selected_count = ARRAY_SIZE(selected); +static int8_t selected_index; +#endif + +/** \brief unicode 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); +} + +#ifdef AUDIO_ENABLE +# ifdef UNICODE_SONG_MAC +static float song_mac[][2] = UNICODE_SONG_MAC; +# endif +# ifdef UNICODE_SONG_LNX +static float song_lnx[][2] = UNICODE_SONG_LNX; +# endif +# ifdef UNICODE_SONG_WIN +static float song_win[][2] = UNICODE_SONG_WIN; +# endif +# ifdef UNICODE_SONG_BSD +static float song_bsd[][2] = UNICODE_SONG_BSD; +# endif +# ifdef UNICODE_SONG_WINC +static float song_winc[][2] = UNICODE_SONG_WINC; +# endif +# ifdef UNICODE_SONG_EMACS +static float song_emacs[][2] = UNICODE_SONG_EMACS; +# endif + +static void unicode_play_song(uint8_t mode) { + switch (mode) { +# ifdef UNICODE_SONG_MAC + case UC_MAC: + PLAY_SONG(song_mac); + break; +# endif +# ifdef UNICODE_SONG_LNX + case UC_LNX: + PLAY_SONG(song_lnx); + break; +# endif +# ifdef UNICODE_SONG_WIN + case UC_WIN: + PLAY_SONG(song_win); + break; +# endif +# ifdef UNICODE_SONG_BSD + case UC_BSD: + PLAY_SONG(song_bsd); + break; +# endif +# ifdef UNICODE_SONG_WINC + case UC_WINC: + PLAY_SONG(song_winc); + break; +# endif +# ifdef UNICODE_SONG_EMACS + case UC_EMACS: + PLAY_SONG(song_emacs); + break; +# endif + } +} +#endif + +void unicode_input_mode_init(void) { + unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); +#if UNICODE_SELECTED_MODES != -1 +# if UNICODE_CYCLE_PERSIST + // Find input_mode in selected modes + int8_t i; + for (i = 0; i < selected_count; i++) { + if (selected[i] == unicode_config.input_mode) { + selected_index = i; + break; + } + } + if (i == selected_count) { + // Not found: input_mode isn't selected, change to one that is + unicode_config.input_mode = selected[selected_index = 0]; + } +# else + // Always change to the first selected input mode + 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); +} + +uint8_t get_unicode_input_mode(void) { + return unicode_config.input_mode; +} + +void set_unicode_input_mode(uint8_t mode) { + unicode_config.input_mode = mode; + persist_unicode_input_mode(); +#ifdef AUDIO_ENABLE + unicode_play_song(mode); +#endif + unicode_input_mode_set_kb(mode); + dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); +} + +void cycle_unicode_input_mode(int8_t offset) { +#if UNICODE_SELECTED_MODES != -1 + selected_index = (selected_index + offset) % selected_count; + if (selected_index < 0) { + selected_index += selected_count; + } + unicode_config.input_mode = selected[selected_index]; +# if UNICODE_CYCLE_PERSIST + persist_unicode_input_mode(); +# endif +# ifdef AUDIO_ENABLE + unicode_play_song(unicode_config.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 +} + +void persist_unicode_input_mode(void) { + eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); +} + +__attribute__((weak)) void unicode_input_start(void) { + unicode_saved_led_state = host_keyboard_led_state(); + + // Note the order matters here! + // Need to do this before we mess around with the mods, or else + // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work + // correctly in the shifted case. + if (unicode_config.input_mode == UC_LNX && unicode_saved_led_state.caps_lock) { + tap_code(KC_CAPS_LOCK); + } + + unicode_saved_mods = get_mods(); // Save current mods + clear_mods(); // Unregister mods to start from a clean state + clear_weak_mods(); + + switch (unicode_config.input_mode) { + case UC_MAC: + register_code(UNICODE_KEY_MAC); + break; + case UC_LNX: + tap_code16(UNICODE_KEY_LNX); + break; + case UC_WIN: + // For increased reliability, use numpad keys for inputting digits + if (!unicode_saved_led_state.num_lock) { + tap_code(KC_NUM_LOCK); + } + register_code(KC_LEFT_ALT); + wait_ms(UNICODE_TYPE_DELAY); + tap_code(KC_KP_PLUS); + break; + case UC_WINC: + tap_code(UNICODE_KEY_WINC); + tap_code(KC_U); + break; + case UC_EMACS: + // The usual way to type unicode in emacs is C-x-8 <RET> then the unicode number in hex + tap_code16(LCTL(KC_X)); + tap_code16(KC_8); + tap_code16(KC_ENTER); + break; + } + + wait_ms(UNICODE_TYPE_DELAY); +} + +__attribute__((weak)) void unicode_input_finish(void) { + switch (unicode_config.input_mode) { + case UC_MAC: + unregister_code(UNICODE_KEY_MAC); + break; + case UC_LNX: + tap_code(KC_SPACE); + if (unicode_saved_led_state.caps_lock) { + tap_code(KC_CAPS_LOCK); + } + break; + case UC_WIN: + unregister_code(KC_LEFT_ALT); + if (!unicode_saved_led_state.num_lock) { + tap_code(KC_NUM_LOCK); + } + break; + case UC_WINC: + tap_code(KC_ENTER); + break; + case UC_EMACS: + tap_code16(KC_ENTER); + break; + } + + set_mods(unicode_saved_mods); // Reregister previously set mods +} + +__attribute__((weak)) void unicode_input_cancel(void) { + switch (unicode_config.input_mode) { + case UC_MAC: + unregister_code(UNICODE_KEY_MAC); + break; + case UC_LNX: + tap_code(KC_ESCAPE); + if (unicode_saved_led_state.caps_lock) { + tap_code(KC_CAPS_LOCK); + } + break; + case UC_WINC: + tap_code(KC_ESCAPE); + break; + case UC_WIN: + unregister_code(KC_LEFT_ALT); + if (!unicode_saved_led_state.num_lock) { + tap_code(KC_NUM_LOCK); + } + break; + case UC_EMACS: + tap_code16(LCTL(KC_G)); // C-g cancels + break; + } + + set_mods(unicode_saved_mods); // Reregister previously set mods +} + +// clang-format off + +static void send_nibble_wrapper(uint8_t digit) { + if (unicode_config.input_mode == UC_WIN) { + uint8_t kc = digit < 10 + ? KC_KP_1 + (10 + digit - 1) % 10 + : KC_A + (digit - 10); + tap_code(kc); + return; + } + send_nibble(digit); +} + +// clang-format on + +void register_hex(uint16_t hex) { + for (int i = 3; i >= 0; i--) { + uint8_t digit = ((hex >> (i * 4)) & 0xF); + send_nibble_wrapper(digit); + } +} + +void register_hex32(uint32_t hex) { + bool first_digit = true; + bool needs_leading_zero = (unicode_config.input_mode == UC_WINC); + for (int i = 7; i >= 0; i--) { + // Work out the digit we're going to transmit + uint8_t digit = ((hex >> (i * 4)) & 0xF); + + // If we're still searching for the first digit, and found one + // that needs a leading zero sent out, send the zero. + if (first_digit && needs_leading_zero && digit > 9) { + send_nibble_wrapper(0); + } + + // Always send digits (including zero) if we're down to the last + // two bytes of nibbles. + bool must_send = i < 4; + + // If we've found a digit worth transmitting, do so. + if (digit != 0 || !first_digit || must_send) { + send_nibble_wrapper(digit); + first_digit = false; + } + } +} + +void register_unicode(uint32_t code_point) { + if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) { + // Code point out of range, do nothing + return; + } + + unicode_input_start(); + if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) { + // Convert code point to UTF-16 surrogate pair on macOS + code_point -= 0x10000; + uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10; + register_hex32(hi + 0xD800); + register_hex32(lo + 0xDC00); + } else { + register_hex32(code_point); + } + unicode_input_finish(); +} + +void send_unicode_string(const char *str) { + if (!str) { + return; + } + + while (*str) { + int32_t code_point = 0; + str = decode_utf8(str, &code_point); + + if (code_point >= 0) { + register_unicode(code_point); + } + } +} diff --git a/quantum/unicode/unicode.h b/quantum/unicode/unicode.h new file mode 100644 index 0000000000..b3e43799ff --- /dev/null +++ b/quantum/unicode/unicode.h @@ -0,0 +1,165 @@ +/* Copyright 2022 + * + * 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 <stdint.h> + +#include "quantum.h" + +typedef union { + uint32_t raw; + struct { + uint8_t input_mode : 8; + }; +} unicode_config_t; + +extern unicode_config_t unicode_config; + +enum unicode_input_modes { + UC_MAC, // macOS using Unicode Hex Input + UC_LNX, // Linux using IBus + UC_WIN, // Windows using EnableHexNumpad + UC_BSD, // BSD (not implemented) + UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose) + UC_EMACS, // Emacs is an operating system in search of a good text editor + UC__COUNT // Number of available input modes (always leave at the end) +}; + +void unicode_input_mode_init(void); +uint8_t get_unicode_input_mode(void); +void set_unicode_input_mode(uint8_t mode); +void cycle_unicode_input_mode(int8_t offset); +void persist_unicode_input_mode(void); + +void unicode_input_mode_set_user(uint8_t input_mode); +void unicode_input_mode_set_kb(uint8_t input_mode); + +void unicode_input_start(void); +void unicode_input_finish(void); +void unicode_input_cancel(void); + +void register_hex(uint16_t hex); +void register_hex32(uint32_t hex); +void register_unicode(uint32_t code_point); + +void send_unicode_string(const char *str); + +// clang-format off + +#define UC_BSPC UC(0x0008) // (backspace) + +#define UC_SPC UC(0x0020) // (space) +#define UC_EXLM UC(0x0021) // ! +#define UC_DQUT UC(0x0022) // " +#define UC_HASH UC(0x0023) // # +#define UC_DLR UC(0x0024) // $ +#define UC_PERC UC(0x0025) // % +#define UC_AMPR UC(0x0026) // & +#define UC_QUOT UC(0x0027) // ' +#define UC_LPRN UC(0x0028) // ( +#define UC_RPRN UC(0x0029) // ) +#define UC_ASTR UC(0x002A) // * +#define UC_PLUS UC(0x002B) // + +#define UC_COMM UC(0x002C) // , +#define UC_DASH UC(0x002D) // - +#define UC_DOT UC(0x002E) // . +#define UC_SLSH UC(0x002F) // / + +#define UC_0 UC(0x0030) // 0 +#define UC_1 UC(0x0031) // 1 +#define UC_2 UC(0x0032) // 2 +#define UC_3 UC(0x0033) // 3 +#define UC_4 UC(0x0034) // 4 +#define UC_5 UC(0x0035) // 5 +#define UC_6 UC(0x0036) // 6 +#define UC_7 UC(0x0037) // 7 +#define UC_8 UC(0x0038) // 8 +#define UC_9 UC(0x0039) // 9 +#define UC_COLN UC(0x003A) // : +#define UC_SCLN UC(0x003B) // ; +#define UC_LT UC(0x003C) // < +#define UC_EQL UC(0x003D) // = +#define UC_GT UC(0x003E) // > +#define UC_QUES UC(0x003F) // ? + +#define UC_AT UC(0x0040) // @ +#define UC_A UC(0x0041) // A +#define UC_B UC(0x0042) // B +#define UC_C UC(0x0043) // C +#define UC_D UC(0x0044) // D +#define UC_E UC(0x0045) // E +#define UC_F UC(0x0046) // F +#define UC_G UC(0x0047) // G +#define UC_H UC(0x0048) // H +#define UC_I UC(0x0049) // I +#define UC_J UC(0x004A) // J +#define UC_K UC(0x004B) // K +#define UC_L UC(0x004C) // L +#define UC_M UC(0x004D) // M +#define UC_N UC(0x004E) // N +#define UC_O UC(0x004F) // O + +#define UC_P UC(0x0050) // P +#define UC_Q UC(0x0051) // Q +#define UC_R UC(0x0052) // R +#define UC_S UC(0x0053) // S +#define UC_T UC(0x0054) // T +#define UC_U UC(0x0055) // U +#define UC_V UC(0x0056) // V +#define UC_W UC(0x0057) // W +#define UC_X UC(0x0058) // X +#define UC_Y UC(0x0059) // Y +#define UC_Z UC(0x005A) // Z +#define UC_LBRC UC(0x005B) // [ +#define UC_BSLS UC(0x005C) // (backslash) +#define UC_RBRC UC(0x005D) // ] +#define UC_CIRM UC(0x005E) // ^ +#define UC_UNDR UC(0x005F) // _ + +#define UC_GRV UC(0x0060) // ` +#define UC_a UC(0x0061) // a +#define UC_b UC(0x0062) // b +#define UC_c UC(0x0063) // c +#define UC_d UC(0x0064) // d +#define UC_e UC(0x0065) // e +#define UC_f UC(0x0066) // f +#define UC_g UC(0x0067) // g +#define UC_h UC(0x0068) // h +#define UC_i UC(0x0069) // i +#define UC_j UC(0x006A) // j +#define UC_k UC(0x006B) // k +#define UC_l UC(0x006C) // l +#define UC_m UC(0x006D) // m +#define UC_n UC(0x006E) // n +#define UC_o UC(0x006F) // o + +#define UC_p UC(0x0070) // p +#define UC_q UC(0x0071) // q +#define UC_r UC(0x0072) // r +#define UC_s UC(0x0073) // s +#define UC_t UC(0x0074) // t +#define UC_u UC(0x0075) // u +#define UC_v UC(0x0076) // v +#define UC_w UC(0x0077) // w +#define UC_x UC(0x0078) // x +#define UC_y UC(0x0079) // y +#define UC_z UC(0x007A) // z +#define UC_LCBR UC(0x007B) // { +#define UC_PIPE UC(0x007C) // | +#define UC_RCBR UC(0x007D) // } +#define UC_TILD UC(0x007E) // ~ +#define UC_DEL UC(0x007F) // (delete) diff --git a/quantum/utf8.c b/quantum/unicode/utf8.c index 4b2cd4d8d4..4b2cd4d8d4 100644 --- a/quantum/utf8.c +++ b/quantum/unicode/utf8.c diff --git a/quantum/utf8.h b/quantum/unicode/utf8.h index fb10910944..521dd1918c 100644 --- a/quantum/utf8.h +++ b/quantum/unicode/utf8.h @@ -18,4 +18,4 @@ #include <stdint.h> -const char *decode_utf8(const char *str, int32_t *code_point);
\ No newline at end of file +const char *decode_utf8(const char *str, int32_t *code_point); 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 diff --git a/quantum/via_ensure_keycode.h b/quantum/via_ensure_keycode.h index 75f816b560..010e1d92d4 100644 --- a/quantum/via_ensure_keycode.h +++ b/quantum/via_ensure_keycode.h @@ -195,6 +195,8 @@ _Static_assert(KC_MFFD == 0x00BB, ""); _Static_assert(KC_MRWD == 0x00BC, ""); _Static_assert(KC_BRIU == 0x00BD, ""); _Static_assert(KC_BRID == 0x00BE, ""); +_Static_assert(KC_CPNL == 0x00BF, ""); +_Static_assert(KC_ASST == 0x00C0, ""); _Static_assert(KC_LEFT_CTRL == 0x00E0, ""); _Static_assert(KC_LEFT_SHIFT == 0x00E1, ""); |