diff options
Diffstat (limited to 'quantum')
65 files changed, 2001 insertions, 878 deletions
diff --git a/quantum/action.c b/quantum/action.c index 6b2e9104e0..4f01acb96e 100644 --- a/quantum/action.c +++ b/quantum/action.c @@ -403,9 +403,9 @@ void process_action(keyrecord_t *record, action_t action) { # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 } else if (tap_count == ONESHOT_TAP_TOGGLE) { dprint("MODS_TAP: Toggling oneshot"); + register_mods(mods); clear_oneshot_mods(); set_oneshot_locked_mods(mods | get_oneshot_locked_mods()); - register_mods(mods); # endif } else { register_mods(mods | get_oneshot_mods()); @@ -418,16 +418,16 @@ void process_action(keyrecord_t *record, action_t action) { // Retain Oneshot mods # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1 if (mods & get_mods()) { + unregister_mods(mods); clear_oneshot_mods(); set_oneshot_locked_mods(~mods & get_oneshot_locked_mods()); - unregister_mods(mods); } } else if (tap_count == ONESHOT_TAP_TOGGLE) { // Toggle Oneshot Layer # endif } else { - clear_oneshot_mods(); unregister_mods(mods); + clear_oneshot_mods(); } } } @@ -918,6 +918,10 @@ __attribute__((weak)) void register_code(uint8_t code) { mousekey_on(code); mousekey_send(); } +#elif defined(POINTING_DEVICE_ENABLE) + else if IS_MOUSEKEY (code) { + pointing_device_keycode_handler(code, true); + } #endif } @@ -978,6 +982,10 @@ __attribute__((weak)) void unregister_code(uint8_t code) { mousekey_off(code); mousekey_send(); } +#elif defined(POINTING_DEVICE_ENABLE) + else if IS_MOUSEKEY (code) { + pointing_device_keycode_handler(code, false); + } #endif } 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/joystick.c b/quantum/joystick.c index 86b2c64036..d285dcdb5e 100644 --- a/quantum/joystick.c +++ b/quantum/joystick.c @@ -1,5 +1,24 @@ +/* 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 "joystick.h" +#include "analog.h" +#include "wait.h" + // clang-format off joystick_t joystick_status = { .buttons = {0}, @@ -15,12 +34,13 @@ joystick_t joystick_status = { // array defining the reading of analog values for each axis __attribute__((weak)) joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {}; -// to be implemented in the hid protocol library -void send_joystick_packet(joystick_t *joystick); +__attribute__((weak)) void joystick_task(void) { + joystick_read_axes(); +} void joystick_flush(void) { if ((joystick_status.status & JS_UPDATED) > 0) { - send_joystick_packet(&joystick_status); + host_joystick_send(&joystick_status); joystick_status.status &= ~JS_UPDATED; } } @@ -36,3 +56,75 @@ void unregister_joystick_button(uint8_t button) { joystick_status.status |= JS_UPDATED; joystick_flush(); } + +int16_t joystick_read_axis(uint8_t axis) { + // disable pull-up resistor + writePinLow(joystick_axes[axis].input_pin); + + // if pin was a pull-up input, we need to uncharge it by turning it low + // before making it a low input + setPinOutput(joystick_axes[axis].input_pin); + + wait_us(10); + + if (joystick_axes[axis].output_pin != JS_VIRTUAL_AXIS) { + setPinOutput(joystick_axes[axis].output_pin); + writePinHigh(joystick_axes[axis].output_pin); + } + + if (joystick_axes[axis].ground_pin != JS_VIRTUAL_AXIS) { + setPinOutput(joystick_axes[axis].ground_pin); + writePinLow(joystick_axes[axis].ground_pin); + } + + wait_us(10); + + setPinInput(joystick_axes[axis].input_pin); + + wait_us(10); + +#if defined(ANALOG_JOYSTICK_ENABLE) && (defined(__AVR__) || defined(PROTOCOL_CHIBIOS)) + int16_t axis_val = analogReadPin(joystick_axes[axis].input_pin); +#else + // default to resting position + int16_t axis_val = joystick_axes[axis].mid_digit; +#endif + + // test the converted value against the lower range + int32_t ref = joystick_axes[axis].mid_digit; + int32_t range = joystick_axes[axis].min_digit; + int32_t ranged_val = ((axis_val - ref) * -JOYSTICK_RESOLUTION) / (range - ref); + + if (ranged_val > 0) { + // the value is in the higher range + range = joystick_axes[axis].max_digit; + ranged_val = ((axis_val - ref) * JOYSTICK_RESOLUTION) / (range - ref); + } + + // clamp the result in the valid range + ranged_val = ranged_val < -JOYSTICK_RESOLUTION ? -JOYSTICK_RESOLUTION : ranged_val; + ranged_val = ranged_val > JOYSTICK_RESOLUTION ? JOYSTICK_RESOLUTION : ranged_val; + + return ranged_val; +} + +void joystick_read_axes() { +#if JOYSTICK_AXES_COUNT > 0 + for (int i = 0; i < JOYSTICK_AXES_COUNT; ++i) { + if (joystick_axes[i].input_pin == JS_VIRTUAL_AXIS) { + continue; + } + + joystick_set_axis(i, joystick_read_axis(i)); + } + + joystick_flush(); +#endif +} + +void joystick_set_axis(uint8_t axis, int16_t value) { + if (value != joystick_status.axes[axis]) { + joystick_status.axes[axis] = value; + joystick_status.status |= JS_UPDATED; + } +} diff --git a/quantum/joystick.h b/quantum/joystick.h index 5d81b14ef2..ee966fdb1a 100644 --- a/quantum/joystick.h +++ b/quantum/joystick.h @@ -1,3 +1,19 @@ +/* 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> @@ -54,7 +70,10 @@ typedef struct { extern joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT]; -enum joystick_status { JS_INITIALIZED = 1, JS_UPDATED = 2 }; +enum joystick_status { + JS_INITIALIZED = 1, + JS_UPDATED, +}; typedef struct { uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1]; @@ -65,7 +84,14 @@ typedef struct { extern joystick_t joystick_status; +void joystick_task(void); void joystick_flush(void); void register_joystick_button(uint8_t button); void unregister_joystick_button(uint8_t button); + +int16_t joystick_read_axis(uint8_t axis); +void joystick_read_axes(void); +void joystick_set_axis(uint8_t axis, int16_t value); + +void host_joystick_send(joystick_t *joystick); 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 }; |