使用的linux内核
git clone https://github.com/Lichee-Pi/linux.git --depth=1 -b nano-4.14-exp
1、修改 include/dt-bindings/clock/suniv-ccu.h 文件
在
#define CLK_AVS 66
下面添加
#define CLK_CIR 67
2、修改 drivers/clk/sunxi-ng/ccu-suniv.h 文件
把
#define CLK_NUMBER (CLK_AVS + 1)
改成
#define CLK_NUMBER (CLK_CIR + 1)
3、修改 drivers/clk/sunxi-ng/ccu-suniv.c 文件
添加如下定义
static const char * const cir_parents[] = { "losc", "osc24M" };
static SUNXI_CCU_MP_WITH_MUX_GATE(cir_clk, "ir", cir_parents, 0x0b8,
0, 4, /* M */
16, 2, /* P */
24, 2, /* mux */
BIT(31), /* gate */
0);
在 suniv_ccu_clks[] 追加一项 &cir_clk.common,
static struct ccu_common *suniv_ccu_clks[] = {
......
&avs_clk.common,
&cir_clk.common, // 添加这一行
};
在 suniv_hw_clks 追加一项 &cir_clk.common,
static struct clk_hw_onecell_data suniv_hw_clks = {
.hws = {
......
[CLK_AVS] = &avs_clk.common.hw,
[CLK_CIR] = &cir_clk.common.hw, // 添加这一行
},
.num = CLK_NUMBER,
};
4、修改 suniv.dtsi 文件
添加
cir_pins_a: cir@0 {
pins = "PE11";
function = "ir";
allwinner,muxsel = <4>;
allwinner,drive = <1>;
allwinner,pull = <0>;
};
cir: cir@1C22C00{
compatible = "allwinner,sun4i-a10-ir";
reg = <0x01C22C00 0x400>;
interrupts = <6>;
clocks = <&ccu CLK_BUS_IR>, <&ccu CLK_CIR>;
clock-names = "apb", "ir";
resets = <&ccu RST_BUS_IR>;
pinctrl-names = "default";
pinctrl-0 = <&cir_pins_a>;
status = "okay";
};
5、make ARCH=arm menuconfig打开linux内核配置如下选项:
Device Drivers --->
<*> Remote Controller support --->
[*] Remote controller decoders --->
<*> Enable IR raw decoder for the NEC protocol
<*> Enable IR raw decoder for the RC-5 protocol
<*> Enable IR raw decoder for the RC6 protocol
<*> Enable IR raw decoder for the JVC protocol
<*> Enable IR raw decoder for the Sony protocol
<*> Enable IR raw decoder for the Sanyo protocol
<*> Enable IR raw decoder for the Sharp protocol
<*> Enable IR raw decoder for the MCE keyboard/mouse protocol
<*> Enable IR raw decoder for the XMP protocol
[*] Remote Controller devices --->
<*> SUNXI IR remote control
6、重新编译内核,系统启动时若IR初始化正常,将打印如下IR相关的日志信息
[ 0.955993] IR NEC protocol handler initialized
[ 0.960649] IR RC5(x/sz) protocol handler initialized
[ 0.965699] IR RC6 protocol handler initialized
[ 0.970268] IR JVC protocol handler initialized
[ 0.974788] IR Sony protocol handler initialized
[ 0.979426] IR SANYO protocol handler initialized
[ 0.984121] IR Sharp protocol handler initialized
[ 0.988844] IR MCE Keyboard/mouse protocol handler initialized
[ 0.994660] IR XMP protocol handler initialized
[ 1.000837] Registered IR keymap rc-empty
[ 1.005153] rc rc0: sunxi-ir as /devices/platform/soc/1c22c00.cir/rc/rc0
[ 1.012409] input: sunxi-ir as /devices/platform/soc/1c22c00.cir/rc/rc0/input2
[ 1.021028] input: MCE IR Keyboard/Mouse (sunxi-ir) as /devices/virtual/input/input3
[ 1.029990] sunxi-ir 1c22c00.cir: initialized sunXi IR driver
7、查看红外接收支持的解码协议
# cat /sys/class/rc/rc0/protocols
rc-5 nec rc-6 jvc sony rc-5-sz sanyo sharp mce_kbd xmp
8、使用 NEC 协议
# echo nec > /sys/class/rc/rc0/protocols
# cat /sys/class/rc/rc0/protocols
rc-5 [nec] rc-6 jvc sony rc-5-sz sanyo sharp mce_kbd xmp
9、查看输入设备
# cat /proc/bus/input/devices
I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="1c24800.rtp"
P: Phys=sun4i_ts/input0
S: Sysfs=/devices/platform/soc/1c24800.rtp/input/input0
U: Uniq=
H: Handlers=event0
B: PROP=0
B: EV=b
B: KEY=400 0 0 0 0 0 0 0 0 0 0
B: ABS=3
I: Bus=0019 Vendor=0000 Product=0000 Version=0000
N: Name="rotary@0"
P: Phys=
S: Sysfs=/devices/platform/rotary@0/input/input1
U: Uniq=
H: Handlers=event1
B: PROP=0
B: EV=5
B: REL=1
I: Bus=0019 Vendor=0001 Product=0001 Version=0100
N: Name="sunxi-ir"
P: Phys=sunxi-ir/input0
S: Sysfs=/devices/platform/soc/1c22c00.cir/rc/rc0/input2
U: Uniq=
H: Handlers=kbd event2
B: PROP=0
B: EV=100013
B: KEY=1000000 0 0 0 0
B: MSC=10
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="MCE IR Keyboard/Mouse (sunxi-ir)"
P: Phys=/input0
S: Sysfs=/devices/virtual/input/input3
U: Uniq=
H: Handlers=kbd event3
B: PROP=0
B: EV=100017
B: KEY=30000 0 7 ff87207a c14057ff febeffdf ffefffff ffffffff fffffffe
B: REL=3
B: MSC=10
10、测试红外接收
从上面输入设备可以看到,ir使用event2,通过使用evtest测试,按下遥控器时,evtest输出如下按键信息,输出的value值与逻辑分析仪采集的数据一致,说明按键码接收正常。
# evtest /dev/input/event2
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "sunxi-ir"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 152 (KEY_SCREENLOCK)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Key repeat handling:
Repeat type 20 (EV_REP)
Repeat code 0 (REP_DELAY)
Value 500
Repeat code 1 (REP_PERIOD)
Value 125
Testing ... (interrupt to exit)
Event: time 68.119608, type 4 (EV_MSC), code 4 (MSC_SCAN), value 114
Event: time 68.119608, -------------- SYN_REPORT ------------
Event: time 68.171084, type 4 (EV_MSC), code 4 (MSC_SCAN), value 114
Event: time 68.171084, -------------- SYN_REPORT ------------
离线
666功能越来越全了
离线
感谢楼主分享,只前试过GPIO来解码,发射红外信号 ,改天试试硬件方式
离线
今天测试了一下,我用的5.4内核,不过匹配的是compatible = "allwinner,sun6i-a31-ir";
[ 1.156710] IR NEC protocol handler initialized
[ 1.161258] IR RC5(x/sz) protocol handler initialized
[ 1.167467] Registered IR keymap rc-empty
[ 1.172009] rc rc0: sunxi-ir as /devices/platform/soc/1c22c00.cir/rc/rc0
[ 1.179245] input: sunxi-ir as /devices/platform/soc/1c22c00.cir/rc/rc0/input1
[ 1.187776] sunxi-ir 1c22c00.cir: initialized sunXi IR driver
# ./evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: 1c23400.lradc
/dev/input/event1: sunxi-ir
Select the device event number [0-1]: 1
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: "sunxi-ir"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 152 (KEY_SCREENLOCK)
Event type 2 (EV_REL)
Event code 0 (REL_X)
Event code 1 (REL_Y)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Key repeat handling:
Repeat type 20 (EV_REP)
Repeat code 0 (REP_DELAY)
Value 500
Repeat code 1 (REP_PERIOD)
Value 125
Properties:
Property type 5 (INPUT_PROP_POINTING_STICK)
Testing ... (interrupt to exit)
Event: time 113.474487, type 4 (EV_MSC), code 4 (MSC_SCAN), value 9f43
Event: time 113.474487, -------------- SYN_REPORT ------------
Event: time 113.528867, type 4 (EV_MSC), code 4 (MSC_SCAN), value 9f43
Event: time 113.528867, -------------- SYN_REPORT ------------
Event: time 123.140115, type 4 (EV_MSC), code 4 (MSC_SCAN), value 9f0a
Event: time 123.140115, -------------- SYN_REPORT ------------
Event: time 123.194514, type 4 (EV_MSC), code 4 (MSC_SCAN), value 9f0a
Event: time 123.194514, -------------- SYN_REPORT ------------
Event: time 125.754998, type 4 (EV_MSC), code 4 (MSC_SCAN), value 9f06
Event: time 125.754998, -------------- SYN_REPORT ------------
Event: time 145.473697, type 4 (EV_MSC), code 4 (MSC_SCAN), value bf0d
Event: time 145.473697, -------------- SYN_REPORT ------------
Event: time 145.527068, type 4 (EV_MSC), code 4 (MSC_SCAN), value bf0d
Event: time 145.527068, -------------- SYN_REPORT ------------
Event: time 134.284454, type 4 (EV_MSC), code 4 (MSC_SCAN), value bf43
Event: time 134.284454, -------------- SYN_REPORT ------------
离线