diff options
| author | dexter93 <d3xter93@gmail.com> | 2022-12-08 18:09:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-09 03:09:01 +1100 |
| commit | f2a8a13dbad220cfb0dfbd72a90492a15a2e58bb (patch) | |
| tree | 92c2389bba9eb8faa00b13e68b57f8196e87fc84 | |
| parent | 6668a0adb0b482a4b9adfab6693fc1b98a7eb16c (diff) | |
Core: Support inverted scan logic for optical switches (#19053)
| -rw-r--r-- | data/mappings/info_config.hjson | 1 | ||||
| -rw-r--r-- | data/schemas/keyboard.jsonschema | 1 | ||||
| -rw-r--r-- | docs/porting_your_keyboard_to_qmk.md | 12 | ||||
| -rw-r--r-- | quantum/matrix.c | 10 |
4 files changed, 20 insertions, 4 deletions
diff --git a/data/mappings/info_config.hjson b/data/mappings/info_config.hjson index 8f7b34d41a..414439d6e7 100644 --- a/data/mappings/info_config.hjson +++ b/data/mappings/info_config.hjson | |||
| @@ -55,6 +55,7 @@ | |||
| 55 | "LED_MATRIX_VAL_STEP": {"info_key": "led_matrix.val_steps", "value_type": "int"}, | 55 | "LED_MATRIX_VAL_STEP": {"info_key": "led_matrix.val_steps", "value_type": "int"}, |
| 56 | "LED_MATRIX_SPD_STEP": {"info_key": "led_matrix.speed_steps", "value_type": "int"}, | 56 | "LED_MATRIX_SPD_STEP": {"info_key": "led_matrix.speed_steps", "value_type": "int"}, |
| 57 | "MATRIX_HAS_GHOST": {"info_key": "matrix_pins.ghost", "value_type": "bool"}, | 57 | "MATRIX_HAS_GHOST": {"info_key": "matrix_pins.ghost", "value_type": "bool"}, |
| 58 | "MATRIX_INPUT_PRESSED_STATE": {"info_key": "matrix_pins.input_pressed_state", "value_type": "int"}, | ||
| 58 | "MATRIX_IO_DELAY": {"info_key": "matrix_pins.io_delay", "value_type": "int"}, | 59 | "MATRIX_IO_DELAY": {"info_key": "matrix_pins.io_delay", "value_type": "int"}, |
| 59 | "MOUSEKEY_DELAY": {"info_key": "mousekey.delay", "value_type": "int"}, | 60 | "MOUSEKEY_DELAY": {"info_key": "mousekey.delay", "value_type": "int"}, |
| 60 | "MOUSEKEY_INTERVAL": {"info_key": "mousekey.interval", "value_type": "int"}, | 61 | "MOUSEKEY_INTERVAL": {"info_key": "mousekey.interval", "value_type": "int"}, |
diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 5c0c23c2b1..7844bfd579 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema | |||
| @@ -304,6 +304,7 @@ | |||
| 304 | "custom": {"type": "boolean"}, | 304 | "custom": {"type": "boolean"}, |
| 305 | "custom_lite": {"type": "boolean"}, | 305 | "custom_lite": {"type": "boolean"}, |
| 306 | "ghost": {"type": "boolean"}, | 306 | "ghost": {"type": "boolean"}, |
| 307 | "input_pressed_state": {"$ref": "qmk.definitions.v1#/unsigned_int"}, | ||
| 307 | "io_delay": {"$ref": "qmk.definitions.v1#/unsigned_int"}, | 308 | "io_delay": {"$ref": "qmk.definitions.v1#/unsigned_int"}, |
| 308 | "direct": { | 309 | "direct": { |
| 309 | "type": "array", | 310 | "type": "array", |
diff --git a/docs/porting_your_keyboard_to_qmk.md b/docs/porting_your_keyboard_to_qmk.md index 484d079ea6..05054e25c7 100644 --- a/docs/porting_your_keyboard_to_qmk.md +++ b/docs/porting_your_keyboard_to_qmk.md | |||
| @@ -94,6 +94,18 @@ The next section of the `info` file deals with your keyboard's matrix. The first | |||
| 94 | 94 | ||
| 95 | The size of the `matrix_pins.cols` and `matrix_pins.rows` arrays infer the size of the matrix (previously `MATRIX_ROWS` and `MATRIX_COLS`). | 95 | The size of the `matrix_pins.cols` and `matrix_pins.rows` arrays infer the size of the matrix (previously `MATRIX_ROWS` and `MATRIX_COLS`). |
| 96 | 96 | ||
| 97 | ## Configuration Options | ||
| 98 | |||
| 99 | To invert the keypress logic, configure `input_pressed_state`: | ||
| 100 | |||
| 101 | ```json | ||
| 102 | "matrix_pins": { | ||
| 103 | "input_pressed_state": 1, | ||
| 104 | }, | ||
| 105 | ``` | ||
| 106 | |||
| 107 | This configures state of the GPIO pins when the key is pressed - `1` for high, `0` for low. Default value is `0`. | ||
| 108 | |||
| 97 | Finally, you can specify the direction your diodes point. This can be `COL2ROW` or `ROW2COL`. | 109 | Finally, you can specify the direction your diodes point. This can be `COL2ROW` or `ROW2COL`. |
| 98 | 110 | ||
| 99 | ```json | 111 | ```json |
diff --git a/quantum/matrix.c b/quantum/matrix.c index db683104ed..0de65c6cdd 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
| @@ -46,6 +46,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 46 | # define SPLIT_MUTABLE_COL const | 46 | # define SPLIT_MUTABLE_COL const |
| 47 | #endif | 47 | #endif |
| 48 | 48 | ||
| 49 | #ifndef MATRIX_INPUT_PRESSED_STATE | ||
| 50 | # define MATRIX_INPUT_PRESSED_STATE 0 | ||
| 51 | #endif | ||
| 52 | |||
| 49 | #ifdef DIRECT_PINS | 53 | #ifdef DIRECT_PINS |
| 50 | static SPLIT_MUTABLE pin_t direct_pins[ROWS_PER_HAND][MATRIX_COLS] = DIRECT_PINS; | 54 | static SPLIT_MUTABLE pin_t direct_pins[ROWS_PER_HAND][MATRIX_COLS] = DIRECT_PINS; |
| 51 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) | 55 | #elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW) |
| @@ -93,7 +97,7 @@ static inline void setPinInputHigh_atomic(pin_t pin) { | |||
| 93 | 97 | ||
| 94 | static inline uint8_t readMatrixPin(pin_t pin) { | 98 | static inline uint8_t readMatrixPin(pin_t pin) { |
| 95 | if (pin != NO_PIN) { | 99 | if (pin != NO_PIN) { |
| 96 | return readPin(pin); | 100 | return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; |
| 97 | } else { | 101 | } else { |
| 98 | return 1; | 102 | return 1; |
| 99 | } | 103 | } |
| @@ -121,9 +125,7 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
| 121 | matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; | 125 | matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; |
| 122 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { | 126 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { |
| 123 | pin_t pin = direct_pins[current_row][col_index]; | 127 | pin_t pin = direct_pins[current_row][col_index]; |
| 124 | if (pin != NO_PIN) { | 128 | current_row_value |= readMatrixPin(pin) ? 0 : row_shifter; |
| 125 | current_row_value |= readPin(pin) ? 0 : row_shifter; | ||
| 126 | } | ||
| 127 | } | 129 | } |
| 128 | 130 | ||
| 129 | // Update the matrix | 131 | // Update the matrix |
