Merge pull request #3 from fauh45/cheapinov2

Fix Cheapino v2 Code
This commit is contained in:
Thomas Haukland 2023-12-10 12:21:29 +01:00 committed by GitHub
commit 0671e5f95c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 55 deletions

View File

@ -3,6 +3,11 @@
#define COL_SHIFTER ((uint16_t)1) #define COL_SHIFTER ((uint16_t)1)
#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 colABpressed = false;
static bool encoderPressed = false; static bool encoderPressed = false;
@ -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) { void blank_column(matrix_row_t current_matrix[], uint8_t col) {
uint16_t column_index_bitmask = COL_SHIFTER << 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; 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) { bool is_entire_column_held(matrix_row_t current_matrix[], uint8_t col) {
uint16_t column_index_bitmask = COL_SHIFTER << 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; if (!(current_matrix[row_index] & column_index_bitmask)) return false;
} }
return true; 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 // triggers entire columns... fix it in software here, assumption is that
// you never press an entire column, sounds safe? // you never press an entire column, sounds safe?
void fix_encoder_action(matrix_row_t current_matrix[]) { void fix_encoder_action(matrix_row_t current_matrix[]) {
matrix_row_t encoder_row = current_matrix[ENC_ROW];
// 7th column means encoder was pressed // 7th column means encoder was pressed
if (is_entire_column_held(current_matrix, 7)) { if (encoder_row & (COL_SHIFTER << ENC_BUTTON_COL)) {
encoderPressed = true; encoderPressed = true;
blank_column(current_matrix, 7); // blank_column(current_matrix, 7);
current_matrix[3] |= COL_SHIFTER; current_matrix[3] |= COL_SHIFTER << 1;
} else { } else {
current_matrix[3] &= ~COL_SHIFTER; current_matrix[3] &= ~COL_SHIFTER << 1;
// Only trigger click on release // Only trigger click on release
if (encoderPressed) { if (encoderPressed) {
encoderPressed = false; encoderPressed = false;
@ -56,25 +64,22 @@ void fix_encoder_action(matrix_row_t current_matrix[]) {
} }
} }
// Now check rotary action: // Check if the pin is pressed, as from observation when encoder is spun
bool colA = is_entire_column_held(current_matrix, 9); // it doesn't result in all of the columns to turn on anymore
bool colB = is_entire_column_held(current_matrix, 11); bool colA = encoder_row & (COL_SHIFTER << ENC_A_COL);
bool colB = encoder_row & (COL_SHIFTER << ENC_B_COL);
if (colA && colB) { if (colA && colB) {
colABpressed = true; colABpressed = true;
blank_column(current_matrix, 9);
blank_column(current_matrix, 11);
} else if (colA) { } else if (colA) {
if (colABpressed) { if (colABpressed) {
colABpressed = false; colABpressed = false;
turned(true); turned(true);
} }
blank_column(current_matrix, 9);
} else if (colB) { } else if (colB) {
if (colABpressed) { if (colABpressed) {
colABpressed = false; colABpressed = false;
turned(false); turned(false);
} }
blank_column(current_matrix, 11);
} }
} }

View File

@ -12,12 +12,24 @@
"mousekey": true, "mousekey": true,
"nkro": false "nkro": false
}, },
"community_layouts": [ "community_layouts": ["split_3x5_3"],
"split_3x5_3"
],
"matrix_pins": { "matrix_pins": {
"cols": ["GP0", "GP0", "GP1", "GP1", "GP2", "GP2", "GP14", "GP14", "GP15", "GP15", "GP26", "GP26"], "cols": [
"rows": ["GP3", "GP4", "GP5", "GP6", "GP27", "GP28", "GP29", "GP8"] "GP6",
"GP6",
"GP5",
"GP5",
"GP4",
"GP4",
"GP14",
"GP14",
"GP15",
"GP15",
"GP26",
"GP26"
],
"rows": ["GP3", "GP1", "GP2", "GP0", "GP27", "GP28", "GP29", "GP8"]
}, },
"processor": "RP2040", "processor": "RP2040",
"url": "", "url": "",
@ -29,42 +41,52 @@
"layouts": { "layouts": {
"LAYOUT_split_3x5_3": { "LAYOUT_split_3x5_3": {
"layout": [ "layout": [
{ "matrix": [0, 4], "x": 0, "y": 0.25 }, { "matrix": [4, 11], "x": 0, "y": 0.25 },
{ "matrix": [0, 3], "x": 1, "y": 0.125 }, { "matrix": [4, 8], "x": 1, "y": 0.125 },
{ "matrix": [0, 2], "x": 2, "y": 0 }, { "matrix": [4, 9], "x": 2, "y": 0 },
{ "matrix": [0, 1], "x": 3, "y": 0.125 }, { "matrix": [4, 6], "x": 3, "y": 0.125 },
{ "matrix": [0, 0], "x": 4, "y": 0.25 }, { "matrix": [4, 7], "x": 4, "y": 0.25 },
{ "matrix": [2, 6], "x": 7, "y": 0.25 },
{ "matrix": [2, 7], "x": 8, "y": 0.125 }, { "matrix": [0, 1], "x": 7, "y": 0.25 },
{ "matrix": [2, 8], "x": 9, "y": 0 }, { "matrix": [0, 0], "x": 8, "y": 0.125 },
{ "matrix": [2, 9], "x": 10, "y": 0.125 }, { "matrix": [0, 3], "x": 9, "y": 0 },
{ "matrix": [2, 10], "x": 11, "y": 0.25 }, { "matrix": [0, 2], "x": 10, "y": 0.125 },
{ "matrix": [1, 4], "x": 0, "y": 1.25 }, { "matrix": [0, 5], "x": 11, "y": 0.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": [5, 11], "x": 0, "y": 1.25 },
{ "matrix": [1, 0], "x": 4, "y": 1.25 }, { "matrix": [5, 8], "x": 1, "y": 1.125 },
{ "matrix": [1, 6], "x": 7, "y": 1.25 }, { "matrix": [5, 9], "x": 2, "y": 1 },
{ "matrix": [1, 7], "x": 8, "y": 1.125 }, { "matrix": [5, 6], "x": 3, "y": 1.125 },
{ "matrix": [1, 8], "x": 9, "y": 1 }, { "matrix": [5, 7], "x": 4, "y": 1.25 },
{ "matrix": [1, 9], "x": 10, "y": 1.125 },
{ "matrix": [1, 10], "x": 11, "y": 1.25 }, { "matrix": [1, 1], "x": 7, "y": 1.25 },
{ "matrix": [2, 4], "x": 0, "y": 2.25 }, { "matrix": [1, 0], "x": 8, "y": 1.125 },
{ "matrix": [2, 3], "x": 1, "y": 2.125 }, { "matrix": [1, 3], "x": 9, "y": 1 },
{ "matrix": [2, 2], "x": 2, "y": 2 }, { "matrix": [1, 2], "x": 10, "y": 1.125 },
{ "matrix": [2, 1], "x": 3, "y": 2.125 }, { "matrix": [1, 5], "x": 11, "y": 1.25 },
{ "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": [6, 11], "x": 0, "y": 2.25 },
{ "matrix": [0, 8], "x": 9, "y": 2 }, { "matrix": [6, 8], "x": 1, "y": 2.125 },
{ "matrix": [0, 9], "x": 10, "y": 2.125 }, { "matrix": [6, 9], "x": 2, "y": 2 },
{ "matrix": [0, 10], "x": 11, "y": 2.25 }, { "matrix": [6, 6], "x": 3, "y": 2.125 },
{ "matrix": [2, 5], "x": 2.5, "y": 3.25 }, { "matrix": [6, 7], "x": 4, "y": 2.25 },
{ "matrix": [1, 5], "x": 3.5, "y": 3.5 },
{ "matrix": [0, 5], "x": 4.5, "y": 3.75 }, { "matrix": [2, 1], "x": 7, "y": 2.25 },
{ "matrix": [2, 11], "x": 6.5, "y": 3.75 }, { "matrix": [2, 0], "x": 8, "y": 2.125 },
{ "matrix": [1, 11], "x": 7.5, "y": 3.5 }, { "matrix": [2, 3], "x": 9, "y": 2 },
{ "matrix": [0, 11], "x": 8.5, "y": 3.25 } { "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 }
] ]
} }
} }

View File

@ -140,6 +140,8 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
read_rows_on_col(current_matrix, current_col); read_rows_on_col(current_matrix, current_col);
} }
fix_encoder_action(current_matrix);
return has_matrix_changed(current_matrix); return has_matrix_changed(current_matrix);
} }