Replace debounce malloc+loop with calloc

* Replace malloc() with calloc()
* Eliminate zero-initialization loops
* Minor code spacing edit
This commit is contained in:
フィルターペーパー 2025-07-23 13:11:22 +08:00
parent a954b568ea
commit 6e43a23312
5 changed files with 5 additions and 27 deletions

View File

@ -64,13 +64,7 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui
// we use num_rows rather than MATRIX_ROWS to support split keyboards
void debounce_init(uint8_t num_rows) {
debounce_counters = malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t));
int i = 0;
for (uint8_t r = 0; r < num_rows; r++) {
for (uint8_t c = 0; c < MATRIX_COLS; c++) {
debounce_counters[i++].time = DEBOUNCE_ELAPSED;
}
}
debounce_counters = calloc(num_rows * MATRIX_COLS, sizeof(debounce_counter_t));
}
void debounce_free(void) {

View File

@ -56,13 +56,7 @@ static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], u
// we use num_rows rather than MATRIX_ROWS to support split keyboards
void debounce_init(uint8_t num_rows) {
debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t));
int i = 0;
for (uint8_t r = 0; r < num_rows; r++) {
for (uint8_t c = 0; c < MATRIX_COLS; c++) {
debounce_counters[i++] = DEBOUNCE_ELAPSED;
}
}
debounce_counters = calloc(num_rows * MATRIX_COLS, sizeof(debounce_counter_t));
}
void debounce_free(void) {

View File

@ -34,7 +34,6 @@ static matrix_row_t* last_raw;
void debounce_init(uint8_t num_rows) {
countdowns = (uint8_t*)calloc(num_rows, sizeof(uint8_t));
last_raw = (matrix_row_t*)calloc(num_rows, sizeof(matrix_row_t));
last_time = timer_read();
}

View File

@ -57,13 +57,7 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui
// we use num_rows rather than MATRIX_ROWS to support split keyboards
void debounce_init(uint8_t num_rows) {
debounce_counters = (debounce_counter_t *)malloc(num_rows * MATRIX_COLS * sizeof(debounce_counter_t));
int i = 0;
for (uint8_t r = 0; r < num_rows; r++) {
for (uint8_t c = 0; c < MATRIX_COLS; c++) {
debounce_counters[i++] = DEBOUNCE_ELAPSED;
}
}
debounce_counters = calloc(num_rows * MATRIX_COLS, sizeof(debounce_counter_t));
}
void debounce_free(void) {

View File

@ -56,10 +56,7 @@ static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], ui
// we use num_rows rather than MATRIX_ROWS to support split keyboards
void debounce_init(uint8_t num_rows) {
debounce_counters = (debounce_counter_t *)malloc(num_rows * sizeof(debounce_counter_t));
for (uint8_t r = 0; r < num_rows; r++) {
debounce_counters[r] = DEBOUNCE_ELAPSED;
}
debounce_counters = calloc(num_rows, sizeof(debounce_counter_t));
}
void debounce_free(void) {