Skip to content

Commit

Permalink
Merge pull request qmk#3 from fauh45/cheapinov2
Browse files Browse the repository at this point in the history
Fix Cheapino v2 Code
  • Loading branch information
tompi authored Dec 10, 2023
2 parents f0892a0 + d5b6ce4 commit 0671e5f
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 55 deletions.
33 changes: 19 additions & 14 deletions keyboards/cheapino/encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -41,40 +48,38 @@ 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;
clicked();
}
}

// 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);
}
}
104 changes: 63 additions & 41 deletions keyboards/cheapino/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand All @@ -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 }
]
}
}
Expand Down
2 changes: 2 additions & 0 deletions keyboards/cheapino/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 0671e5f

Please sign in to comment.