Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持在keymap中覆盖,使用自定义的扫描算法 #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions application/main/src/keyboard/keyboard_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ static uint8_t debouncing = DEBOUNCE_RELOAD;
static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];

static matrix_row_t read_cols(void);
static void select_row(uint8_t row);
static void unselect_rows(uint8_t row);

#ifdef ROW_IN
#define READ_COL(pin) (!nrf_gpio_pin_read(pin))
#else
Expand All @@ -63,7 +59,7 @@ static void unselect_rows(uint8_t row);
* @brief 初始化键盘阵列
*
*/
void matrix_init(void)
__attribute__((weak)) void matrix_init(void)
{
for (uint_fast8_t i = MATRIX_COLS; i--;) {
#ifdef ROW_IN
Expand All @@ -74,7 +70,7 @@ void matrix_init(void)
}
}
/** read all rows */
static matrix_row_t read_cols(void)
__attribute__((weak)) matrix_row_t read_cols(void)
{
matrix_row_t result = 0;

Expand All @@ -86,7 +82,7 @@ static matrix_row_t read_cols(void)
return result;
}

static void select_row(uint8_t row)
__attribute__((weak)) void select_row(uint8_t row)
{
if ((uint32_t)row_pin_array[row] > 31 )
return;
Expand All @@ -108,7 +104,7 @@ nrf_gpio_cfg(
#endif
}

static void unselect_rows(uint8_t row)
__attribute__((weak)) void unselect_rows(uint8_t row)
{
if ((uint32_t)row_pin_array[row] > 31 )
return;
Expand All @@ -133,7 +129,7 @@ static inline void delay_us(void)
}
}

uint8_t matrix_scan(void)
__attribute__((weak)) uint8_t matrix_scan(void)
{
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
select_row(i);
Expand Down Expand Up @@ -165,7 +161,7 @@ uint8_t matrix_scan(void)
return 1;
}

bool matrix_is_modified(void)
__attribute__((weak)) bool matrix_is_modified(void)
{
if (debouncing)
return false;
Expand Down Expand Up @@ -245,7 +241,7 @@ uint8_t matrix_key_count(void)
* @brief 禁用所有阵列针脚
*
*/
void matrix_deinit(void)
__attribute__((weak)) void matrix_deinit(void)
{
for (uint8_t i = 0; i < MATRIX_COLS; i++) {
nrf_gpio_cfg_default(column_pin_array[i]);
Expand All @@ -259,7 +255,7 @@ void matrix_deinit(void)
* @brief 阵列准备睡眠
*
*/
void matrix_wakeup_prepare(void)
__attribute__((weak)) void matrix_wakeup_prepare(void)
{
// 这里监听所有按键作为唤醒按键,所以真正的唤醒判断应该在main的初始化过程中
#ifdef ROW_IN
Expand Down
7 changes: 7 additions & 0 deletions application/main/src/keyboard/keyboard_matrix.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#pragma once
#include <stdint.h>
#include "matrix.h"

void matrix_init(void);
matrix_row_t read_cols(void);
void select_row(uint8_t row);
void unselect_rows(uint8_t row);
uint8_t matrix_scan(void);
bool matrix_is_modified(void);
void matrix_deinit(void);
void matrix_wakeup_prepare(void);

Expand Down
Loading