From af6f1b5d7000d128cdf0147a1002cda9da96927b Mon Sep 17 00:00:00 2001 From: Fauzan Lubis Date: Sat, 9 Dec 2023 22:38:39 +0700 Subject: [PATCH 1/2] fix pin & key mapping tested out with current design --- keyboards/cheapino/info.json | 104 +++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 41 deletions(-) diff --git a/keyboards/cheapino/info.json b/keyboards/cheapino/info.json index 8804435fa9..ed251a4c12 100644 --- a/keyboards/cheapino/info.json +++ b/keyboards/cheapino/info.json @@ -12,12 +12,24 @@ "mousekey": true, "nkro": false }, - "community_layouts": [ - "split_3x5_3" - ], + "community_layouts": ["split_3x5_3"], "matrix_pins": { - "cols": ["GP0", "GP0", "GP1", "GP1", "GP2", "GP2", "GP14", "GP14", "GP15", "GP15", "GP26", "GP26"], - "rows": ["GP3", "GP4", "GP5", "GP6", "GP27", "GP28", "GP29", "GP8"] + "cols": [ + "GP6", + "GP6", + "GP5", + "GP5", + "GP4", + "GP4", + + "GP14", + "GP14", + "GP15", + "GP15", + "GP26", + "GP26" + ], + "rows": ["GP3", "GP1", "GP2", "GP0", "GP27", "GP28", "GP29", "GP8"] }, "processor": "RP2040", "url": "", @@ -29,42 +41,52 @@ "layouts": { "LAYOUT_split_3x5_3": { "layout": [ - { "matrix": [0, 4], "x": 0, "y": 0.25 }, - { "matrix": [0, 3], "x": 1, "y": 0.125 }, - { "matrix": [0, 2], "x": 2, "y": 0 }, - { "matrix": [0, 1], "x": 3, "y": 0.125 }, - { "matrix": [0, 0], "x": 4, "y": 0.25 }, - { "matrix": [2, 6], "x": 7, "y": 0.25 }, - { "matrix": [2, 7], "x": 8, "y": 0.125 }, - { "matrix": [2, 8], "x": 9, "y": 0 }, - { "matrix": [2, 9], "x": 10, "y": 0.125 }, - { "matrix": [2, 10], "x": 11, "y": 0.25 }, - { "matrix": [1, 4], "x": 0, "y": 1.25 }, - { "matrix": [1, 3], "x": 1, "y": 1.125 }, - { "matrix": [1, 2], "x": 2, "y": 1 }, - { "matrix": [1, 1], "x": 3, "y": 1.125 }, - { "matrix": [1, 0], "x": 4, "y": 1.25 }, - { "matrix": [1, 6], "x": 7, "y": 1.25 }, - { "matrix": [1, 7], "x": 8, "y": 1.125 }, - { "matrix": [1, 8], "x": 9, "y": 1 }, - { "matrix": [1, 9], "x": 10, "y": 1.125 }, - { "matrix": [1, 10], "x": 11, "y": 1.25 }, - { "matrix": [2, 4], "x": 0, "y": 2.25 }, - { "matrix": [2, 3], "x": 1, "y": 2.125 }, - { "matrix": [2, 2], "x": 2, "y": 2 }, - { "matrix": [2, 1], "x": 3, "y": 2.125 }, - { "matrix": [2, 0], "x": 4, "y": 2.25 }, - { "matrix": [0, 6], "x": 7, "y": 2.25 }, - { "matrix": [0, 7], "x": 8, "y": 2.125 }, - { "matrix": [0, 8], "x": 9, "y": 2 }, - { "matrix": [0, 9], "x": 10, "y": 2.125 }, - { "matrix": [0, 10], "x": 11, "y": 2.25 }, - { "matrix": [2, 5], "x": 2.5, "y": 3.25 }, - { "matrix": [1, 5], "x": 3.5, "y": 3.5 }, - { "matrix": [0, 5], "x": 4.5, "y": 3.75 }, - { "matrix": [2, 11], "x": 6.5, "y": 3.75 }, - { "matrix": [1, 11], "x": 7.5, "y": 3.5 }, - { "matrix": [0, 11], "x": 8.5, "y": 3.25 } + { "matrix": [4, 11], "x": 0, "y": 0.25 }, + { "matrix": [4, 8], "x": 1, "y": 0.125 }, + { "matrix": [4, 9], "x": 2, "y": 0 }, + { "matrix": [4, 6], "x": 3, "y": 0.125 }, + { "matrix": [4, 7], "x": 4, "y": 0.25 }, + + { "matrix": [0, 1], "x": 7, "y": 0.25 }, + { "matrix": [0, 0], "x": 8, "y": 0.125 }, + { "matrix": [0, 3], "x": 9, "y": 0 }, + { "matrix": [0, 2], "x": 10, "y": 0.125 }, + { "matrix": [0, 5], "x": 11, "y": 0.25 }, + + + { "matrix": [5, 11], "x": 0, "y": 1.25 }, + { "matrix": [5, 8], "x": 1, "y": 1.125 }, + { "matrix": [5, 9], "x": 2, "y": 1 }, + { "matrix": [5, 6], "x": 3, "y": 1.125 }, + { "matrix": [5, 7], "x": 4, "y": 1.25 }, + + { "matrix": [1, 1], "x": 7, "y": 1.25 }, + { "matrix": [1, 0], "x": 8, "y": 1.125 }, + { "matrix": [1, 3], "x": 9, "y": 1 }, + { "matrix": [1, 2], "x": 10, "y": 1.125 }, + { "matrix": [1, 5], "x": 11, "y": 1.25 }, + + + { "matrix": [6, 11], "x": 0, "y": 2.25 }, + { "matrix": [6, 8], "x": 1, "y": 2.125 }, + { "matrix": [6, 9], "x": 2, "y": 2 }, + { "matrix": [6, 6], "x": 3, "y": 2.125 }, + { "matrix": [6, 7], "x": 4, "y": 2.25 }, + + { "matrix": [2, 1], "x": 7, "y": 2.25 }, + { "matrix": [2, 0], "x": 8, "y": 2.125 }, + { "matrix": [2, 3], "x": 9, "y": 2 }, + { "matrix": [2, 2], "x": 10, "y": 2.125 }, + { "matrix": [2, 5], "x": 11, "y": 2.25 }, + + + { "matrix": [6, 10], "x": 2.5, "y": 3.25 }, + { "matrix": [5, 10], "x": 3.5, "y": 3.5 }, + { "matrix": [4, 10], "x": 4.5, "y": 3.75 }, + + { "matrix": [0, 4], "x": 6.5, "y": 3.75 }, + { "matrix": [1, 4], "x": 7.5, "y": 3.5 }, + { "matrix": [2, 4], "x": 8.5, "y": 3.25 } ] } } From d5b6ce4aa8d82d3010c9054c31a345f6f74dc95d Mon Sep 17 00:00:00 2001 From: Fauzan Lubis Date: Sat, 9 Dec 2023 22:39:25 +0700 Subject: [PATCH 2/2] fix encoder not recognized encoder code now only checks for certain bits --- keyboards/cheapino/encoder.c | 33 +++++++++++++++++++-------------- keyboards/cheapino/matrix.c | 2 ++ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/keyboards/cheapino/encoder.c b/keyboards/cheapino/encoder.c index bcaa86010e..4ca688443d 100644 --- a/keyboards/cheapino/encoder.c +++ b/keyboards/cheapino/encoder.c @@ -3,7 +3,12 @@ #define COL_SHIFTER ((uint16_t)1) -static bool colABpressed = false; +#define ENC_ROW 3 +#define ENC_A_COL 3 +#define ENC_B_COL 5 +#define ENC_BUTTON_COL 1 + +static bool colABpressed = false; static bool encoderPressed = false; void clicked(void) { @@ -22,16 +27,18 @@ void turned(bool clockwise) { } } +// Dead code for now, not sure if there's edge cases that needed it void blank_column(matrix_row_t current_matrix[], uint8_t col) { uint16_t column_index_bitmask = COL_SHIFTER << col; - for (uint8_t row_index = 0; row_index < MATRIX_ROWS-1; row_index++) { + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { current_matrix[row_index] &= ~column_index_bitmask; } } +// Dead code for now, not sure if there's edge cases that needed it bool is_entire_column_held(matrix_row_t current_matrix[], uint8_t col) { uint16_t column_index_bitmask = COL_SHIFTER << col; - for (uint8_t row_index = 0; row_index < MATRIX_ROWS-1; row_index++) { + for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { if (!(current_matrix[row_index] & column_index_bitmask)) return false; } return true; @@ -41,14 +48,15 @@ bool is_entire_column_held(matrix_row_t current_matrix[], uint8_t col) { // triggers entire columns... fix it in software here, assumption is that // you never press an entire column, sounds safe? void fix_encoder_action(matrix_row_t current_matrix[]) { + matrix_row_t encoder_row = current_matrix[ENC_ROW]; // 7th column means encoder was pressed - if (is_entire_column_held(current_matrix, 7)) { + if (encoder_row & (COL_SHIFTER << ENC_BUTTON_COL)) { encoderPressed = true; - blank_column(current_matrix, 7); - current_matrix[3] |= COL_SHIFTER; + // blank_column(current_matrix, 7); + current_matrix[3] |= COL_SHIFTER << 1; } else { - current_matrix[3] &= ~COL_SHIFTER; + current_matrix[3] &= ~COL_SHIFTER << 1; // Only trigger click on release if (encoderPressed) { encoderPressed = false; @@ -56,25 +64,22 @@ void fix_encoder_action(matrix_row_t current_matrix[]) { } } - // Now check rotary action: - bool colA = is_entire_column_held(current_matrix, 9); - bool colB = is_entire_column_held(current_matrix, 11); + // Check if the pin is pressed, as from observation when encoder is spun + // it doesn't result in all of the columns to turn on anymore + bool colA = encoder_row & (COL_SHIFTER << ENC_A_COL); + bool colB = encoder_row & (COL_SHIFTER << ENC_B_COL); if (colA && colB) { colABpressed = true; - blank_column(current_matrix, 9); - blank_column(current_matrix, 11); } else if (colA) { if (colABpressed) { colABpressed = false; turned(true); } - blank_column(current_matrix, 9); } else if (colB) { if (colABpressed) { colABpressed = false; turned(false); } - blank_column(current_matrix, 11); } } diff --git a/keyboards/cheapino/matrix.c b/keyboards/cheapino/matrix.c index 159d138d32..21f9150088 100644 --- a/keyboards/cheapino/matrix.c +++ b/keyboards/cheapino/matrix.c @@ -140,6 +140,8 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { read_rows_on_col(current_matrix, current_col); } + fix_encoder_action(current_matrix); + return has_matrix_changed(current_matrix); }