Skip to content

Commit 738e899

Browse files
committed
优化
1 parent 0feee7c commit 738e899

File tree

7 files changed

+218
-251
lines changed

7 files changed

+218
-251
lines changed

application/main/src/keyboard/keyboard_matrix.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ static uint8_t debouncing = DEBOUNCE_RELOAD;
4949
static matrix_row_t matrix[MATRIX_ROWS];
5050
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
5151

52-
static matrix_row_t read_cols(void);
53-
static void select_row(uint8_t row);
54-
static void unselect_rows(uint8_t row);
55-
5652
#ifdef ROW_IN
5753
#define READ_COL(pin) (!nrf_gpio_pin_read(pin))
5854
#else
@@ -63,7 +59,7 @@ static void unselect_rows(uint8_t row);
6359
* @brief 初始化键盘阵列
6460
*
6561
*/
66-
void matrix_init(void)
62+
__attribute__((weak)) void matrix_init(void)
6763
{
6864
for (uint_fast8_t i = MATRIX_COLS; i--;) {
6965
#ifdef ROW_IN
@@ -74,7 +70,7 @@ void matrix_init(void)
7470
}
7571
}
7672
/** read all rows */
77-
static matrix_row_t read_cols(void)
73+
__attribute__((weak)) matrix_row_t read_cols(void)
7874
{
7975
matrix_row_t result = 0;
8076

@@ -86,7 +82,7 @@ static matrix_row_t read_cols(void)
8682
return result;
8783
}
8884

89-
static void select_row(uint8_t row)
85+
__attribute__((weak)) void select_row(uint8_t row)
9086
{
9187
if ((uint32_t)row_pin_array[row] > 31 )
9288
return;
@@ -108,7 +104,7 @@ nrf_gpio_cfg(
108104
#endif
109105
}
110106

111-
static void unselect_rows(uint8_t row)
107+
__attribute__((weak)) void unselect_rows(uint8_t row)
112108
{
113109
if ((uint32_t)row_pin_array[row] > 31 )
114110
return;
@@ -133,7 +129,7 @@ static inline void delay_us(void)
133129
}
134130
}
135131

136-
uint8_t matrix_scan(void)
132+
__attribute__((weak)) uint8_t matrix_scan(void)
137133
{
138134
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
139135
select_row(i);
@@ -165,7 +161,7 @@ uint8_t matrix_scan(void)
165161
return 1;
166162
}
167163

168-
bool matrix_is_modified(void)
164+
__attribute__((weak)) bool matrix_is_modified(void)
169165
{
170166
if (debouncing)
171167
return false;
@@ -245,7 +241,7 @@ uint8_t matrix_key_count(void)
245241
* @brief 禁用所有阵列针脚
246242
*
247243
*/
248-
void matrix_deinit(void)
244+
__attribute__((weak)) void matrix_deinit(void)
249245
{
250246
for (uint8_t i = 0; i < MATRIX_COLS; i++) {
251247
nrf_gpio_cfg_default(column_pin_array[i]);
@@ -259,7 +255,7 @@ void matrix_deinit(void)
259255
* @brief 阵列准备睡眠
260256
*
261257
*/
262-
void matrix_wakeup_prepare(void)
258+
__attribute__((weak)) void matrix_wakeup_prepare(void)
263259
{
264260
// 这里监听所有按键作为唤醒按键,所以真正的唤醒判断应该在main的初始化过程中
265261
#ifdef ROW_IN

application/main/src/keyboard/keyboard_matrix.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#pragma once
22
#include <stdint.h>
3+
#include "matrix.h"
34

5+
void matrix_init(void);
6+
matrix_row_t read_cols(void);
7+
void select_row(uint8_t row);
8+
void unselect_rows(uint8_t row);
9+
uint8_t matrix_scan(void);
10+
bool matrix_is_modified(void);
411
void matrix_deinit(void);
512
void matrix_wakeup_prepare(void);
613

application/main/src/keyboard/keyboard_matrix_analog.c

Lines changed: 0 additions & 235 deletions
This file was deleted.

keyboard/magnet/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ INC_FOLDERS += .
1414
# 配置文件文件名
1515
CONFIG_H = config.h
1616
CONFIG_H_DIR = .
17-
SRC_FILES += keymap_plain.c
17+
SRC_FILES += matrix_analog.c keymap_plain.c
1818

1919
include ./rules.mk
2020

keyboard/magnet/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ static const uint8_t enable_pin_array[MUX_COUNT] = { 6 }; //mux enable, digital
2121
static const uint8_t channel_pin_array[MUX_CHANNELS] = { 7, 8 }; // mux channel, digital output
2222
#define MATRIX_ROWS 4 // Used mux channels, max = 2 ^ MUX_CHANNELS
2323
#define MATRIX_COLS 2 // Total mux sig pins, MUX_COUNT * MUX_OUTPUT
24-
static const uint8_t row_pin_array[MATRIX_ROWS] = { -1, -1, -1, -1 }; // Fake, will not use
24+
static const uint8_t row_pin_array[MATRIX_ROWS] = { 0 }; // fake
2525
static const uint8_t column_pin_array[MATRIX_COLS] = { 4, 5 }; // mux output, analog input
2626
#define DEBOUNCE 5
2727
#define MATRIX_SCAN_DELAY_CYCLE 36
28+
#define WAKE_UP_PIN 12
2829

2930
/* Magnet Switch Value Range */
3031
#define MAGNET_THRESHOLD_TOP 486 // stay still

keyboard/magnet/keymap_plain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
66
KC_1, KC_2,
77
KC_Q, KC_W,
88
KC_A, KC_S,
9-
KC_Z, KC_FN0,
9+
KC_Z, KC_FN0
1010
),
1111
KEYMAP(
1212
KC_5, KC_6,
1313
KC_T, KC_Y,
1414
KC_G, KC_H,
15-
KC_B, KC_TRNS,
15+
KC_B, KC_TRNS
1616
),
1717
};
1818

0 commit comments

Comments
 (0)