红外控制LVGL界面切换
1. 测试红外功能
1.1 配置设备树
查看原理图:
可以看到红外对应的引脚号是PG16
。
进入目录:
cd /home/ubuntu/tina-d1-h/device/config/chips/d1-h/configs/nezha/linux-5.4
修改board.dts
:
vim board.dts
修改引脚:
以下节点是红外接收
的设备树节点,没有使能的话,需要使能:
1.2 配置内核配置文件
执行ckernel
,进入内核目录。
打开内核配置界面:
m kernel_menuconfig
红外有很多种协议,NEC红外协议是最常用的一种,默认选上:
添加红外接收驱动:
保存,回到SDK根目录,编译make
、打包pack
和烧录。
1.3 验证红外功能
开发板上,执行cat proc/bus/input/devices
:
root@TinaLinux:/# cat proc/bus/input/devices
I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="sunxi-keyboard"
P: Phys=sunxikbd/input0
S: Sysfs=/devices/virtual/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=3
B: KEY=100000000 0 0 100000000800 4000000000000 10000000
I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="sunxi-ir"
P: Phys=sunxi-ir/input0
S: Sysfs=/devices/platform/soc@3000000/7040000.s_cir/rc/rc0/s_cir_rx
U: Uniq=
H: Handlers=kbd event1
B: PROP=20
B: EV=100017
B: KEY=2
B: REL=3
B: MSC=10
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="audiocodec sunxi Audio Jack"
P: Phys=ALSA
S: Sysfs=/devices/platform/soc@3000000/2030340.sound/sound/card0/input2
U: Uniq=
H: Handlers=kbd event2
B: PROP=0
B: EV=23
B: KEY=40 0 0 0 0 0 400000000 0 c000000000000 0
B: SW=14
I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="fts_ts"
P: Phys=
S: Sysfs=/devices/platform/soc@3000000/sunxi-i2c2/i2c-2/2-0038/input/input3
U: Uniq=
H: Handlers=event3
B: PROP=2
B: EV=b
B: KEY=400 0 0 0 0 0
B: ABS=661800000000000
可以看到/dev/input/event1
就是红外接收的设备节点了。
执行:
hexdump /dev/input/event1
查看是否接收正常:
root@TinaLinux:/# hexdump /dev/input/event1
0000000 0d07 0000 0000 0000 4ab4 000c 0000 0000
0000010 0004 0004 0007 0000 0d07 0000 0000 0000
0000020 4ab4 000c 0000 0000 0000 0000 0000 0000
0000030 0d08 0000 0000 0000 4a1b 000e 0000 0000
0000040 0004 0004 0009 0000 0d08 0000 0000 0000
0000050 4a1b 000e 0000 0000 0000 0000 0000 0000
0000060 0d0a 0000 0000 0000 5968 0009 0000 0000
0000070 0004 0004 0007 0000 0d0a 0000 0000 0000
0000080 5968 0009 0000 0000 0000 0000 0000 0000
0000090 0d0b 0000 0000 0000 cf50 0004 0000 0000
00000a0 0004 0004 0009 0000 0d0b 0000 0000 0000
00000b0 cf50 0004 0000 0000 0000 0000 0000 0000
收到数据就是接收正常的现象。下面可以编写测试程序了。
1.4 编写红外接收测试程序
以下编写的测试文件:
ubuntu@ubuntu1804:~/C_Source/C_IRTest$ tree -L 2
.
├── bin
│ └── main
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ └── Makefile
├── build.sh
├── CMakeLists.txt
├── inc
│ └── ir_test.h
├── main.c
├── src
│ └── ir_test.c
└── toolchain.cmake
5 directories, 10 files