post @drashna review

This commit is contained in:
silvinor 2025-05-04 20:43:42 +10:00
parent bbd29448de
commit ef8a97659a
6 changed files with 49 additions and 126 deletions

View File

@ -11,12 +11,14 @@
# define OLED_SPLASH_TIMEOUT 2500
# endif
// clang-format off
enum oled_modes {
OLED_SPLASH,
OLED_DEFAULT,
OLED_OFF,
__NUM_OLED_MODES
} oled_modes_t;
// clang-format on
bool candypad_render_logo_user(void);
bool candypad_render_logo_kb(void);

View File

@ -11,17 +11,17 @@
/* CandyPad Logo */
static void __candypad_render_logo_default(void) {
// Generated from https://joric.github.io/qle/
static const unsigned char PROGMEM raw_logo[] = {
static const char PROGMEM raw_logo[] = {
0, 0, 0, 0, 128, 192, 224, 96, 240, 240, 152, 24, 24, 24, 24, 24, 24, 24, 24, 56, 48, 96, 224, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 0, 0, 192, 248, 62, 7, 15, 28, 56, 112, 225, 195, 135, 14, 28, 56, 112, 224, 192, 128, 0, 0, 0, 0, 1, 7, 62, 252, 192, 0, 128, 192, 224, 112, 48, 48, 48, 112, 96, 0, 128, 192, 224, 96,
48, 48, 48, 112, 224, 240, 240, 0, 0, 240, 240, 96, 112, 48, 48, 48, 112, 224, 192, 128, 0, 0, 128, 192, 224, 112, 48, 48, 48, 112, 224, 255, 255, 0, 48, 112, 224, 128, 0, 0, 0, 0, 128, 224, 112, 48, 0, 240, 240, 224, 112, 48, 48, 48, 112, 224, 192, 128, 0, 0, 128, 192, 224, 96, 48, 48, 48, 112, 224, 240, 240, 0, 0, 128, 192, 224, 112, 48, 48, 48, 112, 224, 255, 255, 0, 0, 3, 31, 124, 224, 192, 0, 0, 0, 0, 1, 3, 7, 14, 28, 56, 112, 225, 195, 135, 14, 28, 56, 240, 224, 124, 63, 3, 0, 15, 31, 56, 112, 96, 96, 96, 112, 48, 0, 15, 31, 56, 112, 96, 96, 96, 112, 56, 127, 127, 0, 0, 127, 127, 0, 0, 0, 0, 0, 0, 1, 127, 127, 0, 0, 15, 31, 56, 112, 96, 96, 96, 112, 56, 127, 127, 0, 0, 0, 3, 15, 62, 240, 248, 62, 15,
3, 0, 0, 0, 255, 255, 56, 112, 96, 96, 96, 112, 56, 31, 15, 0, 0, 15, 31, 56, 112, 96, 96, 96, 112, 56, 127, 127, 0, 0, 15, 63, 56, 112, 96, 96, 96, 112, 56, 127, 127, 0, 0, 0, 0, 0, 1, 3, 7, 6, 14, 12, 24, 24, 24, 24, 24, 24, 24, 24, 25, 15, 15, 6, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 31, 7, 1, 0, 0, 0, 0, 0, 0, 31, 31, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
oled_write_raw_P((char *)raw_logo, sizeof(raw_logo));
oled_write_raw_P(raw_logo, sizeof(raw_logo));
}
// weak so that user keymaps can make their own
// Weak so that user keymaps can make their own
__attribute__((weak)) bool candypad_render_logo_user(void) {
return false; // return true if your user keymap renders its own
return false; // Return true if your user keymap renders its own
}
__attribute__((weak)) bool candypad_render_logo_kb(void) {
@ -40,8 +40,8 @@ oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
static char *get_enc_mode(uint8_t encoder) {
# ifdef ENCODER_MAP_ENABLE
static char s_u_d[4] = {24, 38, 25, 0}; // up and down
static char s_l_r[4] = {27, 38, 26, 0}; // left and right
static char s_u_d[4] = {24, 38, 25, 0}; // Up and down
static char s_l_r[4] = {27, 38, 26, 0}; // Left and right
uint8_t layer = get_highest_layer(layer_state);
uint16_t keycode = KC_TRNS;
@ -111,14 +111,14 @@ static void __draw_line_v(uint8_t x, uint8_t y, uint8_t len, bool on) {
}
}
// weak so that user keymaps can make their own
// Weak so that user keymaps can make their own
__attribute__((weak)) bool candypad_render_default_user(void) {
return false; // return true if your user keymap renders its own
return false; // Return true if your user keymap renders its own
}
__attribute__((weak)) bool candypad_render_default_kb(void) {
if (candypad_render_default_user()) {
return true; // was handled by user code
return true; // Was handled by user code
}
bool on;
@ -203,7 +203,7 @@ __attribute__((weak)) bool candypad_render_default_kb(void) {
__draw_line_v(MXDS_X - 2, MXDS_Y - 1, 8, true);
__draw_line_v(MXDS_X + 5, MXDS_Y - 1, 8, true);
return true; // was handled here
return true; // Was handled here
}
bool oled_task_kb(void) {
@ -211,7 +211,7 @@ bool oled_task_kb(void) {
return false;
}
// if (!oled_task_needs_to_repaint()) { return false; }
/* !!! oled_clear(); // is broken !!! */
/* !! : oled_clear(); // Is broken !!! */
if (oled_repaint_requested) {
oled_repaint_requested = false;
oled_clear();
@ -220,8 +220,8 @@ bool oled_task_kb(void) {
switch (oled_mode) {
case OLED_OFF:
// do nothing
// this PCB has no digital switch to power off the OLED :(
// Do nothing
// This PCB has no digital switch to power off the OLED :(
break;
case OLED_SPLASH:

View File

@ -23,7 +23,7 @@
#endif // OLED_ENABLE
/* ---- Direct pins, for use in (custom) `matrix.c` (please read that file) ----- */
// *NB*: DIRECT_PINS_CUSTOM must match the MATRIX_ROWS / MATRIX_COLS matrix structure
// !! : DIRECT_PINS_CUSTOM must match the MATRIX_ROWS / MATRIX_COLS matrix structure
// clang-format off
#define DIRECT_PINS_CUSTOM \
{ \

View File

@ -1,8 +0,0 @@
// Copyright 2023 binepad (@binepad)
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#define HAL_USE_I2C TRUE
#include_next <halconf.h>

View File

@ -6,104 +6,59 @@
* This file is mostly a copy of `matrix.c` from the QMK core, however
* it assumes the matrix is always COL2ROW and that the KB has BOTH
* matrix and direct pins.
*
* For direct pins define
* `DIRECT_PINS_CUSTOM`
* This stucture must match exactly the MATRIX_ROWS / MATRIX_COLS matrix.
* This stucture must exactly match the MATRIX_ROWS / MATRIX_COLS matrix.
*
* NB!!: The ROW that supports direct pins **must** have the row set
* to NO_PIN in the matrix array.
*/
* !! : The ROW that supports direct pins __must__ have the row set to NO_PIN in the matrix array.
*/
#include "matrix.h"
#include "debounce.h"
#include "atomic_util.h"
#include <string.h>
#include <string.h> // For memset, memcmp & memcpy
#include "wait.h"
#include "print.h"
#ifndef DEBOUNCE
# define DEBOUNCE 5
#endif
#ifndef MATRIX_INPUT_PRESSED_STATE
# define MATRIX_INPUT_PRESSED_STATE 0
#endif
#ifndef MATRIX_IO_DELAY
# define MATRIX_IO_DELAY 30
#endif
static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
static pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
// define DIRECT_PINS_CUSTOM in `config.h`
// ** NB: ** must match the MATRIX_ROWS / MATRIX_COLS matrix structure
// !! : Must match the MATRIX_ROWS / MATRIX_COLS matrix structure
static pin_t direct_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS_CUSTOM;
/* matrix state(1:on, 0:off) */
matrix_row_t raw_matrix[MATRIX_ROWS];
matrix_row_t matrix[MATRIX_ROWS];
__attribute__((weak)) void matrix_init_user(void) {}
__attribute__((weak)) void matrix_init_kb(void) {
matrix_init_user();
}
__attribute__((weak)) void matrix_scan_user(void) {}
__attribute__((weak)) void matrix_scan_kb(void) {
matrix_scan_user();
}
#define print_matrix_header() print("\nr/c 01234567\n")
#define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
__attribute__((weak)) void matrix_output_select_delay(void) {
waitInputPinDelay();
}
__attribute__((weak)) void matrix_output_unselect_delay(uint8_t line, bool key_pressed) {
wait_us(MATRIX_IO_DELAY);
}
static inline void setPinOutput_writeLow(pin_t pin) {
static inline void gpio_atomic_set_pin_output_low(pin_t pin) {
ATOMIC_BLOCK_FORCEON {
setPinOutput(pin);
writePinLow(pin);
gpio_set_pin_output(pin);
gpio_write_pin_low(pin);
}
}
static inline void setPinInputHigh_atomic(pin_t pin) {
static inline void gpio_atomic_set_pin_input_high(pin_t pin) {
ATOMIC_BLOCK_FORCEON {
setPinInputHigh(pin);
gpio_set_pin_input_high(pin);
}
}
static inline uint8_t readMatrixPin(pin_t pin) {
static inline uint8_t gpio_read_matrix_pin(pin_t pin) {
if (pin != NO_PIN) {
return (readPin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1;
return (gpio_read_pin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1;
} else {
return 1;
}
}
void matrix_print(void) {
print_matrix_header();
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
print_hex8(row);
print(": ");
print_matrix_row(row);
print("\n");
}
}
static bool select_row(uint8_t row) {
pin_t pin = row_pins[row];
if (pin != NO_PIN) {
setPinOutput_writeLow(pin);
gpio_atomic_set_pin_output_low(pin);
return true;
}
return false;
@ -112,7 +67,7 @@ static bool select_row(uint8_t row) {
static void unselect_row(uint8_t row) {
pin_t pin = row_pins[row];
if (pin != NO_PIN) {
setPinInputHigh_atomic(pin);
gpio_atomic_set_pin_input_high(pin);
}
}
@ -126,7 +81,7 @@ void matrix_init_pins__matrix(void) {
unselect_rows();
for (uint8_t x = 0; x < MATRIX_COLS; x++) {
if (col_pins[x] != NO_PIN) {
setPinInputHigh_atomic(col_pins[x]);
gpio_atomic_set_pin_input_high(col_pins[x]);
}
}
}
@ -136,42 +91,19 @@ void matrix_init_pins__direct(void) {
for (int col = 0; col < MATRIX_COLS; col++) {
pin_t pin = direct_pins[row][col];
if (pin != NO_PIN) {
setPinInputHigh(pin);
gpio_atomic_set_pin_input_high(pin);
}
}
}
}
inline uint8_t matrix_rows(void) {
return MATRIX_ROWS;
}
inline uint8_t matrix_cols(void) {
return MATRIX_COLS;
}
void matrix_init(void) {
void matrix_init_custom(void) {
// initialize key pins
matrix_init_pins__matrix();
matrix_init_pins__direct();
// initialize matrix state: all keys off
memset(raw_matrix, 0, sizeof(raw_matrix));
memset(matrix, 0, sizeof(matrix));
// Unless hardware debouncing - Init the configured debounce routine
debounce_init(MATRIX_ROWS);
// This *must* be called for correct keyboard behavior
matrix_init_kb();
}
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) {
return matrix[row];
}
void matrix_read_cols_on_row__matrix(matrix_row_t current_matrix[], uint8_t current_row) {
@ -186,7 +118,7 @@ void matrix_read_cols_on_row__matrix(matrix_row_t current_matrix[], uint8_t curr
// For each col...
matrix_row_t row_shifter = MATRIX_ROW_SHIFTER;
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) {
uint8_t pin_state = readMatrixPin(col_pins[col_index]);
uint8_t pin_state = gpio_read_matrix_pin(col_pins[col_index]);
// Populate the matrix row with the state of the col pin
current_row_value |= pin_state ? 0 : row_shifter;
@ -208,7 +140,7 @@ void matrix_read_cols_on_row__direct(matrix_row_t current_matrix[], uint8_t curr
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) {
pin_t pin = direct_pins[current_row][col_index];
if (NO_PIN != pin) {
current_row_value |= readMatrixPin(pin) ? 0 : row_shifter;
current_row_value |= gpio_read_matrix_pin(pin) ? 0 : row_shifter;
}
}
@ -216,24 +148,23 @@ void matrix_read_cols_on_row__direct(matrix_row_t current_matrix[], uint8_t curr
current_matrix[current_row] = current_row_value;
}
uint8_t matrix_scan(void) {
matrix_row_t curr_matrix[MATRIX_ROWS] = {0};
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
bool matrix_has_changed = false;
// Matrix keys: Set row, read cols
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
// if the row is a NO_PIN then assume it's on a direct pins matrix, else assume COL2ROW matrix
if (NO_PIN != row_pins[current_row]) {
matrix_read_cols_on_row__matrix(curr_matrix, current_row);
matrix_read_cols_on_row__matrix(current_matrix, current_row);
} else {
matrix_read_cols_on_row__direct(curr_matrix, current_row);
matrix_read_cols_on_row__direct(current_matrix, current_row);
}
}
bool changed = memcmp(raw_matrix, curr_matrix, sizeof(curr_matrix)) != 0;
if (changed) memcpy(raw_matrix, curr_matrix, sizeof(curr_matrix));
matrix_has_changed = memcmp(raw_matrix, current_matrix, MATRIX_ROWS) != 0;
if (matrix_has_changed) {
memcpy(raw_matrix, current_matrix, MATRIX_ROWS);
}
changed = debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
matrix_scan_kb();
return (uint8_t)changed;
return matrix_has_changed;
}

View File

@ -1,9 +1,7 @@
# Copyright 2023 binepad (@binepad)
# SPDX-License-Identifier: GPL-2.0-or-later
CUSTOM_MATRIX = yes
CUSTOM_MATRIX = lite
SRC += matrix.c \
candypad_oled.c
OPT_DEFS += -DHAL_USE_I2C=TRUE