按键矩阵
Read time: 2 minute(s)
Luban-Lite 可以实现按键矩阵功能。矩阵键盘是一种通过行列扫描技术来检测多个按键状态的输入设备,广泛应用于需要大量按键输入的场景,如计算器、遥控器、游戏控制器等。它能有效节省 I/O 资源,同时提供灵活的按键布局方式。
如需实现按键矩阵功能,可执行以下操作流程:
- 在 Luban-Lite 根目录下,执行 scons --menuconfig,进入 menuconfig 的功能配置界面。
- 根据原理图配置 keyadc 所用通道,例如选择 GPAI6:
Board options ---> [*] Using GPAI GPAI options ---> [ ] Using GPAI0 [ ] Using GPAI1 [ ] Using GPAI2 [ ] Using GPAI3 [ ] Using GPAI4 [ ] Using GPAI5 [*] Using GPAI6 [ ] Using GPAI7 GPAI6 Parameter ---> obtaning data mode (CPU interrupt mode) ---> period mode (period mode) (1) sample period time (us) (2x2f) ADC Acquisition Time
- 在 menuconfig
的功能配置界面,按如下选择:
Drivers options ---> Drivers examples ---> [*] Enable KEYADC driver test command
- 编译并运行 test_keyadc 命令。例如:
-
设置采样通道为 2
test_keyadc -c 2
- 设置按键 adc 值可允许波动范围为
50
test_keyadc -s 50
- 开始按键矩阵判断。
test_keyadc -g
-
-
在打开 test_keyadc 的编译后,板子上可直接运行
test_keyadc
命令。执行下列命令,可以查看test_keyadc
命令参数:test_keyadc -h
Compile time: Mar 16202409:58:21 Usage: test_keyadc [options] -c, --channel Select one channel in[0, 7], default is 2 -s, --scale Set the adc scale,default is 50 -g, --get Get the adc value -h, --help Example: test_keyadc -c 2 -g
执行上述操作后,可以获得按键矩阵的按键状态和采样通道号以及 adc 采样值:
[key2] ch2: 3369 # [按键] 采样通道号: adc 采样值 LONG Press # 当前正在进行长按操作
test_keyadc -c 2# 设置采样通道 test_keyadc -s 50# 设置按键 adc 值可允许波动范围 test_keyadc -g # 开始按键矩阵判断[key2] ch2: 3369# [按键] 采样通道号: adc 采样值[key2] ch2: 3369 LONG Press # 当前正在进行长按操作