diff options
Diffstat (limited to 'quantum')
39 files changed, 1886 insertions, 1000 deletions
diff --git a/quantum/backlight/backlight.c b/quantum/backlight/backlight.c index 708022f68f..e57b31d103 100644 --- a/quantum/backlight/backlight.c +++ b/quantum/backlight/backlight.c @@ -21,6 +21,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. backlight_config_t backlight_config; +// TODO: migrate to backlight_config_t +static uint8_t breathing_period = BREATHING_PERIOD; + /** \brief Backlight initialization * * FIXME: needs doc @@ -191,3 +194,21 @@ void backlight_disable_breathing(void) { */ bool is_backlight_breathing(void) { return backlight_config.breathing; } #endif + +// following are marked as weak purely for backwards compatibility +__attribute__((weak)) void breathing_period_set(uint8_t value) { breathing_period = value ? value : 1; } + +__attribute__((weak)) uint8_t get_breathing_period(void) { return breathing_period; } + +__attribute__((weak)) void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } + +__attribute__((weak)) void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } + +__attribute__((weak)) void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } + +// defaults for backlight api +__attribute__((weak)) void backlight_init_ports(void) {} + +__attribute__((weak)) void backlight_set(uint8_t level) {} + +__attribute__((weak)) void backlight_task(void) {} diff --git a/quantum/backlight/backlight.h b/quantum/backlight/backlight.h index 1e581055db..9f0a5e81d7 100644 --- a/quantum/backlight/backlight.h +++ b/quantum/backlight/backlight.h @@ -41,22 +41,39 @@ typedef union { } backlight_config_t; void backlight_init(void); -void backlight_increase(void); -void backlight_decrease(void); void backlight_toggle(void); void backlight_enable(void); void backlight_disable(void); bool is_backlight_enabled(void); void backlight_step(void); -void backlight_set(uint8_t level); +void backlight_increase(void); +void backlight_decrease(void); void backlight_level(uint8_t level); uint8_t get_backlight_level(void); +// implementation specific +void backlight_init_ports(void); +void backlight_set(uint8_t level); +void backlight_task(void); + #ifdef BACKLIGHT_BREATHING + void backlight_toggle_breathing(void); void backlight_enable_breathing(void); void backlight_disable_breathing(void); bool is_backlight_breathing(void); + +void breathing_period_set(uint8_t value); +uint8_t get_breathing_period(void); +void breathing_period_default(void); +void breathing_period_inc(void); +void breathing_period_dec(void); + +// implementation specific void breathing_enable(void); void breathing_disable(void); +void breathing_toggle(void); +bool is_breathing(void); +void breathing_pulse(void); +void breathing_task(void); #endif diff --git a/quantum/backlight/backlight_arm.c b/quantum/backlight/backlight_arm.c index 3f94ccef8e..f7065906f8 100644 --- a/quantum/backlight/backlight_arm.c +++ b/quantum/backlight/backlight_arm.c @@ -10,10 +10,6 @@ # error "Backlight support for STMF072 is not available. Please disable." # endif -# if defined(STM32F1XX) || defined(STM32F1xx) -# define USE_GPIOV1 -# endif - // GPIOV2 && GPIOV3 # ifndef BACKLIGHT_PAL_MODE # define BACKLIGHT_PAL_MODE 2 @@ -110,7 +106,6 @@ void backlight_task(void) {} # define BREATHING_HALT_ON 2 # define BREATHING_STEPS 128 -static uint8_t breathing_period = BREATHING_PERIOD; static uint8_t breathing_halt = BREATHING_NO_HALT; static uint16_t breathing_counter = 0; @@ -118,7 +113,7 @@ bool is_breathing(void) { return BACKLIGHT_PWM_DRIVER.config == &pwmCFG_breathin static inline void breathing_min(void) { breathing_counter = 0; } -static inline void breathing_max(void) { breathing_counter = breathing_period * 256 / 2; } +static inline void breathing_max(void) { breathing_counter = get_breathing_period() * 256 / 2; } void breathing_interrupt_enable(void) { pwmStop(&BACKLIGHT_PWM_DRIVER); @@ -170,17 +165,6 @@ void breathing_toggle(void) { breathing_enable(); } -void breathing_period_set(uint8_t value) { - if (!value) value = 1; - breathing_period = value; -} - -void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } - -void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } - -void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } - /* To generate breathing curve in python: * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] */ @@ -191,7 +175,8 @@ static inline uint16_t scale_backlight(uint16_t v) { return v / BACKLIGHT_LEVELS static void breathing_callback(PWMDriver *pwmp) { (void)pwmp; - uint16_t interval = (uint16_t)breathing_period * 256 / BREATHING_STEPS; + uint8_t breathing_period = get_breathing_period(); + uint16_t interval = (uint16_t)breathing_period * 256 / BREATHING_STEPS; // resetting after one period to prevent ugly reset at overflow. breathing_counter = (breathing_counter + 1) % (breathing_period * 256); uint8_t index = breathing_counter / interval % BREATHING_STEPS; @@ -207,12 +192,4 @@ static void breathing_callback(PWMDriver *pwmp) { chSysUnlockFromISR(); } -#else - -__attribute__((weak)) void backlight_init_ports(void) {} - -__attribute__((weak)) void backlight_set(uint8_t level) {} - -__attribute__((weak)) void backlight_task(void) {} - #endif diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index edda6ea0b6..7cf1e0fb30 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c @@ -206,7 +206,7 @@ static const pin_t backlight_pin = BACKLIGHT_PIN; # endif # ifdef NO_HARDWARE_PWM -__attribute__((weak)) void backlight_init_ports(void) { +void backlight_init_ports(void) { // Setup backlight pin as output and output to on state. FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) @@ -217,8 +217,6 @@ __attribute__((weak)) void backlight_init_ports(void) { # endif } -__attribute__((weak)) void backlight_set(uint8_t level) {} - uint8_t backlight_tick = 0; # ifndef BACKLIGHT_CUSTOM_DRIVER @@ -303,7 +301,7 @@ static uint16_t cie_lightness(uint16_t v) { static inline void set_pwm(uint16_t val) { OCRxx = val; } # ifndef BACKLIGHT_CUSTOM_DRIVER -__attribute__((weak)) void backlight_set(uint8_t level) { +void backlight_set(uint8_t level) { if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; if (level == 0) { @@ -342,7 +340,6 @@ void backlight_task(void) {} # define BREATHING_HALT_ON 2 # define BREATHING_STEPS 128 -static uint8_t breathing_period = BREATHING_PERIOD; static uint8_t breathing_halt = BREATHING_NO_HALT; static uint16_t breathing_counter = 0; @@ -377,9 +374,9 @@ bool is_breathing(void) { return !!(TIMSKx & _BV(TOIEx)); } do { \ breathing_counter = 0; \ } while (0) -# define breathing_max() \ - do { \ - breathing_counter = breathing_period * 244 / 2; \ +# define breathing_max() \ + do { \ + breathing_counter = get_breathing_period() * 244 / 2; \ } while (0) void breathing_enable(void) { @@ -417,17 +414,6 @@ void breathing_toggle(void) { breathing_enable(); } -void breathing_period_set(uint8_t value) { - if (!value) value = 1; - breathing_period = value; -} - -void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); } - -void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); } - -void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); } - /* To generate breathing curve in python: * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] */ @@ -445,6 +431,7 @@ void breathing_task(void) ISR(TIMERx_OVF_vect) # endif { + uint8_t breathing_period = get_breathing_period(); uint16_t interval = (uint16_t)breathing_period * 244 / BREATHING_STEPS; // resetting after one period to prevent ugly reset at overflow. breathing_counter = (breathing_counter + 1) % (breathing_period * 244); @@ -459,7 +446,7 @@ ISR(TIMERx_OVF_vect) # endif // BACKLIGHT_BREATHING -__attribute__((weak)) void backlight_init_ports(void) { +void backlight_init_ports(void) { // Setup backlight pin as output and output to on state. FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) @@ -500,10 +487,4 @@ __attribute__((weak)) void backlight_init_ports(void) { # endif // hardware backlight -#else // no backlight - -__attribute__((weak)) void backlight_init_ports(void) {} - -__attribute__((weak)) void backlight_set(uint8_t level) {} - -#endif // backlight
\ No newline at end of file +#endif // backlight diff --git a/quantum/backlight/backlight_soft.c b/quantum/backlight/backlight_soft.c index a6aba7782c..096b41d910 100644 --- a/quantum/backlight/backlight_soft.c +++ b/quantum/backlight/backlight_soft.c @@ -10,7 +10,7 @@ #endif #ifndef BACKLIGHT_ON_STATE -# define BACKLIGHT_ON_STATE 0 +# define BACKLIGHT_ON_STATE 1 #endif #ifdef BACKLIGHT_PINS @@ -20,6 +20,7 @@ { BACKLIGHT_PIN } #endif +static uint16_t s_duty_pattern = 0; static const pin_t backlight_pins[] = BACKLIGHT_PIN_INIT; #define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t)) @@ -46,14 +47,38 @@ void backlight_off(pin_t backlight_pin) { } void backlight_init_ports(void) { - // Setup backlight pin as output and output to on state. - FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) + // Setup backlight pin as output and output to off state. + FOR_EACH_LED(setPinOutput(backlight_pin); backlight_off(backlight_pin);) } +// clang-format off + +/** \brief PWM duty patterns + * + * We scale the current backlight level to an index within this array. This allows + * backlight_task to focus on just switching LEDs on/off, and we can predict the duty pattern + */ +static uint16_t backlight_duty_table[] = { + 0b0000000000000000, + 0b1000000000000000, + 0b1000000010000000, + 0b1000001000010000, + 0b1000100010001000, + 0b1001001001001000, + 0b1010101010101010, + 0b1110111011101110, + 0b1111111111111111, +}; +#define backlight_duty_table_size (sizeof(backlight_duty_table) / sizeof(backlight_duty_table[0])) + +// clang-format on + +static uint8_t scale_backlight(uint8_t v) { return v * (backlight_duty_table_size - 1) / BACKLIGHT_LEVELS; } + void backlight_task(void) { static uint8_t backlight_tick = 0; - if ((0xFFFF >> (get_backlight_level() * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) { + if (s_duty_pattern & ((uint16_t)1 << backlight_tick)) { FOR_EACH_LED(backlight_on(backlight_pin);) } else { FOR_EACH_LED(backlight_off(backlight_pin);) @@ -61,6 +86,4 @@ void backlight_task(void) { backlight_tick = (backlight_tick + 1) % 16; } -void backlight_set(uint8_t level) { - // noop as backlight_task uses get_backlight_level() -} +void backlight_set(uint8_t level) { s_duty_pattern = backlight_duty_table[scale_backlight(level)]; } diff --git a/quantum/color.c b/quantum/color.c index 1f398e2403..8bd52444fa 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -85,3 +85,17 @@ RGB hsv_to_rgb(HSV hsv) { return rgb; } + +#ifdef RGBW +#ifndef MIN +# define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif +void convert_rgb_to_rgbw(LED_TYPE *led) { + // Determine lowest value in all three colors, put that into + // the white channel and then shift all colors by that amount + led->w = MIN(led->r, MIN(led->g, led->b)); + led->r -= led->w; + led->g -= led->w; + led->b -= led->w; +} +#endif diff --git a/quantum/color.h b/quantum/color.h index 6781646628..58d4f0407f 100644 --- a/quantum/color.h +++ b/quantum/color.h @@ -64,5 +64,7 @@ typedef struct PACKED { #endif RGB hsv_to_rgb(HSV hsv); - +#ifdef RGBW +void convert_rgb_to_rgbw(LED_TYPE *led); +#endif #endif // COLOR_H diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index ca056f630e..11d28592d6 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -20,28 +20,37 @@ #include "progmem.h" // to read default from flash #include "quantum.h" // for send_string() #include "dynamic_keymap.h" - -#ifdef DYNAMIC_KEYMAP_ENABLE - -# ifndef DYNAMIC_KEYMAP_EEPROM_ADDR -# error DYNAMIC_KEYMAP_EEPROM_ADDR not defined -# endif - -# ifndef DYNAMIC_KEYMAP_LAYER_COUNT -# error DYNAMIC_KEYMAP_LAYER_COUNT not defined -# endif - -# ifndef DYNAMIC_KEYMAP_MACRO_COUNT -# error DYNAMIC_KEYMAP_MACRO_COUNT not defined -# endif - -# ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR -# error DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR not defined -# endif - -# ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE -# error DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE not defined -# endif +#include "via.h" // for default VIA_EEPROM_ADDR_END + +#ifndef DYNAMIC_KEYMAP_LAYER_COUNT +# define DYNAMIC_KEYMAP_LAYER_COUNT 4 +#endif + +#ifndef DYNAMIC_KEYMAP_MACRO_COUNT +# define DYNAMIC_KEYMAP_MACRO_COUNT 16 +#endif + +// If DYNAMIC_KEYMAP_EEPROM_ADDR not explicitly defined in config.h, +// default it start after VIA_EEPROM_CUSTOM_ADDR+VIA_EEPROM_CUSTOM_SIZE +#ifndef DYNAMIC_KEYMAP_EEPROM_ADDR +# ifdef VIA_EEPROM_CUSTOM_CONFIG_ADDR +# define DYNAMIC_KEYMAP_EEPROM_ADDR (VIA_EEPROM_CUSTOM_CONFIG_ADDR+VIA_EEPROM_CUSTOM_CONFIG_SIZE) +# else +# error DYNAMIC_KEYMAP_EEPROM_ADDR not defined +# endif +#endif + +// Dynamic macro starts after dynamic keymaps +#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR +# define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR+(DYNAMIC_KEYMAP_LAYER_COUNT*MATRIX_ROWS*MATRIX_COLS*2)) +#endif + +// Dynamic macro uses up all remaining memory +// Assumes 1K EEPROM on ATMega32U4 +// Override for anything different +#ifndef DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE +# define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (1024-DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR) +#endif uint8_t dynamic_keymap_get_layer_count(void) { return DYNAMIC_KEYMAP_LAYER_COUNT; } @@ -208,5 +217,3 @@ void dynamic_keymap_macro_send(uint8_t id) { send_string(data); } } - -#endif // DYNAMIC_KEYMAP_ENABLE diff --git a/quantum/encoder.c b/quantum/encoder.c index 4aeb3d0cde..c41b89f495 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -37,8 +37,8 @@ static pin_t encoders_pad_b[] = ENCODERS_PAD_B; static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; -static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; -static int8_t encoder_pulses[NUMBER_OF_ENCODERS] = {0}; +static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; +static int8_t encoder_pulses[NUMBER_OF_ENCODERS] = {0}; #ifdef SPLIT_KEYBOARD // right half encoders come over as second set of encoders @@ -79,27 +79,27 @@ void encoder_init(void) { } static void encoder_update(int8_t index, uint8_t state) { - encoder_pulses[index] += encoder_LUT[state & 0xF]; - if (encoder_pulses[index] >= ENCODER_RESOLUTION) { + uint8_t i = index; +#ifdef SPLIT_KEYBOARD + index += thisHand; +#endif + encoder_pulses[i] += encoder_LUT[state & 0xF]; + if (encoder_pulses[i] >= ENCODER_RESOLUTION) { encoder_value[index]++; encoder_update_kb(index, true); } - if (encoder_pulses[index] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise encoder_value[index]--; encoder_update_kb(index, false); } - encoder_pulses[index] %= ENCODER_RESOLUTION; + encoder_pulses[i] %= ENCODER_RESOLUTION; } void encoder_read(void) { - for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { + for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { encoder_state[i] <<= 2; encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); -#if SPLIT_KEYBOARD - encoder_update(i + thisHand, encoder_state[i]); -#else encoder_update(i, encoder_state[i]); -#endif } } @@ -107,9 +107,9 @@ void encoder_read(void) { void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); } void encoder_update_raw(uint8_t* slave_state) { - for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { + for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { uint8_t index = i + thatHand; - int8_t delta = slave_state[i] - encoder_value[index]; + int8_t delta = slave_state[i] - encoder_value[index]; while (delta > 0) { delta--; encoder_value[index]++; diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 4fa45ac37b..c82c446399 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -48,13 +48,10 @@ action_t action_for_key(uint8_t layer, keypos_t key) { // keycode remapping keycode = keycode_config(keycode); - action_t action; + action_t action = {}; uint8_t action_layer, when, mod; switch (keycode) { - case KC_FN0 ... KC_FN31: - action.code = keymap_function_id_to_action(FN_INDEX(keycode)); - break; case KC_A ... KC_EXSEL: case KC_LCTRL ... KC_RGUI: action.code = ACTION_KEY(keycode); @@ -65,9 +62,11 @@ action_t action_for_key(uint8_t layer, keypos_t key) { case KC_AUDIO_MUTE ... KC_BRIGHTNESS_DOWN: action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode)); break; +#ifdef MOUSEKEY_ENABLE case KC_MS_UP ... KC_MS_ACCEL2: action.code = ACTION_MOUSEKEY(keycode); break; +#endif case KC_TRNS: action.code = ACTION_TRANSPARENT; break; @@ -76,17 +75,24 @@ action_t action_for_key(uint8_t layer, keypos_t key) { // Split it up action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key break; +#ifndef NO_ACTION_FUNCTION + case KC_FN0 ... KC_FN31: + action.code = keymap_function_id_to_action(FN_INDEX(keycode)); + break; case QK_FUNCTION ... QK_FUNCTION_MAX:; // Is a shortcut for function action_layer, pull last 12bits // This means we have 4,096 FN macros at our disposal action.code = keymap_function_id_to_action((int)keycode & 0xFFF); break; +#endif +#ifndef NO_ACTION_MACRO case QK_MACRO ... QK_MACRO_MAX: if (keycode & 0x800) // tap macros have upper bit set action.code = ACTION_MACRO_TAP(keycode & 0xFF); else action.code = ACTION_MACRO(keycode & 0xFF); break; +#endif case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF); break; diff --git a/quantum/matrix.c b/quantum/matrix.c index 907492a0f6..1675f2477b 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -17,34 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdint.h> #include <stdbool.h> #include "wait.h" -#include "print.h" -#include "debug.h" #include "util.h" #include "matrix.h" #include "debounce.h" #include "quantum.h" -#if (MATRIX_COLS <= 8) -# define print_matrix_header() print("\nr/c 01234567\n") -# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop(matrix[i]) -# define ROW_SHIFTER ((uint8_t)1) -#elif (MATRIX_COLS <= 16) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop16(matrix[i]) -# define ROW_SHIFTER ((uint16_t)1) -#elif (MATRIX_COLS <= 32) -# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") -# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) -# define matrix_bitpop(i) bitpop32(matrix[i]) -# define ROW_SHIFTER ((uint32_t)1) -#endif - -#ifdef MATRIX_MASKED -extern const matrix_row_t matrix_mask[]; -#endif - #ifdef DIRECT_PINS static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS; #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) @@ -53,61 +30,10 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; #endif /* matrix state(1:on, 0:off) */ -static matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values -static matrix_row_t matrix[MATRIX_ROWS]; // debounced values - -__attribute__((weak)) void matrix_init_quantum(void) { matrix_init_kb(); } - -__attribute__((weak)) void matrix_scan_quantum(void) { matrix_scan_kb(); } - -__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } +extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values +extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values -__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); } - -__attribute__((weak)) void matrix_init_user(void) {} - -__attribute__((weak)) void matrix_scan_user(void) {} - -inline uint8_t matrix_rows(void) { return MATRIX_ROWS; } - -inline uint8_t matrix_cols(void) { return MATRIX_COLS; } - -// Deprecated. -bool matrix_is_modified(void) { - if (debounce_active()) return false; - return true; -} - -inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1 << col)); } - -inline matrix_row_t matrix_get_row(uint8_t row) { - // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a - // switch blocker installed and the switch is always pressed. -#ifdef MATRIX_MASKED - return matrix[row] & matrix_mask[row]; -#else - return matrix[row]; -#endif -} - -void matrix_print(void) { - print_matrix_header(); - - for (uint8_t row = 0; row < MATRIX_ROWS; row++) { - phex(row); - print(": "); - print_matrix_row(row); - print("\n"); - } -} - -uint8_t matrix_key_count(void) { - uint8_t count = 0; - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - count += matrix_bitpop(i); - } - return count; -} +// matrix code #ifdef DIRECT_PINS @@ -129,7 +55,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { pin_t pin = direct_pins[current_row][col_index]; if (pin != NO_PIN) { - current_matrix[current_row] |= readPin(pin) ? 0 : (ROW_SHIFTER << col_index); + current_matrix[current_row] |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); } } @@ -175,7 +101,7 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) uint8_t pin_state = readPin(col_pins[col_index]); // Populate the matrix row with the state of the col pin - current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); + current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); } // Unselect row @@ -221,10 +147,10 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) // Check row pin state if (readPin(row_pins[row_index]) == 0) { // Pin LO, set col bit - current_matrix[row_index] |= (ROW_SHIFTER << current_col); + current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); } else { // Pin HI, clear col bit - current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); + current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); } // Determine if the matrix changed state diff --git a/quantum/matrix_common.c b/quantum/matrix_common.c new file mode 100644 index 0000000000..c326e59ca3 --- /dev/null +++ b/quantum/matrix_common.c @@ -0,0 +1,107 @@ +#include "matrix.h" +#include "debounce.h" +#include "print.h" +#include "debug.h" + +/* matrix state(1:on, 0:off) */ +matrix_row_t raw_matrix[MATRIX_ROWS]; +matrix_row_t matrix[MATRIX_ROWS]; + +#ifdef MATRIX_MASKED +extern const matrix_row_t matrix_mask[]; +#endif + +// user-defined overridable functions |