[RK3288][android11] Adapt to infrared remote control

Life is full of electromagnetic waves of various wavelengths. The so-called visible (color) light is the electromagnetic spectrum visible to the human eye. Its wavelength is 380~770nm. In order to avoid the light emitted by the remote control from causing discomfort to the human eye and reduce the interference of general artificial light sources, Therefore, the infrared (Infrared) wavelength invisible to the human eye is selected. At present, almost all remote control emitters in the industry use a wavelength of 940nm.
insert image description here
The application of infrared remote control is also a kind of wireless signal transmission. Like most wireless transmission technologies, in order to avoid the interference of electromagnetic waves of the same wavelength in the environment, a carrier frequency (carrier frequency) as shown in the figure below will be added to the transmission signal. , the carrier range in remote control applications is 30~60kHz, and 38kHz is the most common carrier frequency.
insert image description here
Currently, infrared remote control protocols include RC5, SIRCS, Sy, RECS80, Denon, NEC, Motorola, Japanese, SAMSWNG and Daewoo, etc. Rockchip平台只支持 NEC 编码, most domestic electrical appliances use this encoding protocol.


RK platform PWM has three working modes, reference mode, one-shot mode and continuous mode. The infrared remote control uses reference mode. In this mode, the PWM can capture the width of the input high and low levels and generate an interrupt. After receiving the interrupt, the CPU goes to The corresponding register is read.

1. Refer to the schematic diagram to add the configuration of the kernel IR

insert image description here

1.1 Add the following configuration to the device tree in use:

&pwm3 {
    
    
    status = "okay";

    compatible = "rockchip,remotectl-pwm";
    remote_pwm_id = <3>;
    handle_cpu_id = <1>;
    remote_support_psci = <0>;
    pinctrl-names = "default";
    pinctrl-0 = <&pwm3_pins>;

    ir_key1 {
    
    
        rockchip,usercode = <0x4040>;
        rockchip,key_table =
            <0xf2    KEY_REPLY>,
            <0xba    KEY_BACK>,
            <0xf4    KEY_UP>,
            <0xf1    KEY_DOWN>,
            <0xef    KEY_LEFT>,
            <0xee    KEY_RIGHT>,
            <0xbd    KEY_HOME>,
            <0xea    KEY_VOLUMEUP>,
            <0xe3    KEY_VOLUMEDOWN>,
            <0xe2    KEY_SEARCH>,
            <0xb2    KEY_POWER>,
            <0xbc    KEY_MUTE>,
            <0xec    KEY_MENU>,
            <0xbf    0x190>,
            <0xe0    0x191>,
            <0xe1    0x192>,
            <0xe9    183>,
            <0xe6    248>,
            <0xe8    185>,
            <0xe7    186>,
            <0xf0    388>,
            <0xbe    0x175>;
    };
......
};

1.2 Check the input device and find the pwm infrared device just added. The driver is loaded normally, and the next step is to add the remote control according to the key value.

\> adb shell
rk3568_r:/ # getevent
add device 1: /dev/input/event3
  name:     "Logitech USB Optical Mouse"
add device 2: /dev/input/event2
  name:     "WDR USB Camera: WDR USB Camera"
add device 3: /dev/input/event0
  name:     "fdd70030.pwm"
add device 4: /dev/input/event1
  name:     "rk805 pwrkey"
add device 5: /dev/input/event4
  name:     "adc-keys"
add device 6: /dev/input/event5
  name:     "rk-headset"

2. Add the infrared button to report the key value (defined separately by the rk platform)

The rk platform can directly view the infrared receiver, and the command to open the key value is as follows:

echo 1 > /sys/module/rockchip_pwm_remotectl/parameters/code_print

There are too many kernel logs, you can use the adb command (or serial port printing) to filter and get the key value directly, USERCODEadd the rockchip and usercode corresponding to the remote control dts, and RMC_GETDATAthe corresponding key value can be converted to the rk-input key value through rockchip, key_table.

adb root;adb shell
# cat /dev/kmsg | grep USERCODE -A 2
6,1136,469064745,-;USERCODE=0x4040
6,1137,469091760,-;RMC_GETDATA=b2
6,1138,482889791,-;USERCODE=0x4040
6,1139,482916765,-;RMC_GETDATA=b4

Letter and symbol keys are standard key values ​​of linux, which can kernel/include/dt-bindings/input/linux-event-codes.hbe viewed in the file.


3. Add key-value transformation

The Linux standard key value is not the same as the Android standard key value, and it is necessary to convert the file to match the corresponding relationship. The intermediate conversion configuration file will use PWM to match the configuration file corresponding to the name of the PWM label according to the infrared remote control. This debugging uses the number pwm3 corresponding to PWM3: pwm@fdd70030 {, the name of the key-value conversion configuration file fdd70030_pwm.kl, and the device description file is fdd70030_pwm.idc.

If you don't understand the Android key value, you can view frameworks/base/core/java/android/view/KeyEvent.javathe file;
you can manually copy it for temporary debugging /vendor/usr/keylayout, and restart it to take effect.

fdd70030_pwm.idc

device.internal = 1 #是否为内部设备
audio.mic = 0 #是否带mic

dd70030_pwm.kl

key 116   POWER
key 102   HOME
key 139   MENU
key 113   VOLUME_MUTE

key 115   VOLUME_UP
key 114   VOLUME_DOWN
key 158   BACK

key 232   DPAD_CENTER
key 103   DPAD_UP
key 108   DPAD_DOWN
key 105   DPAD_LEFT
key 106   DPAD_RIGHT
key 240   PROFILE_SWITCH

key 15    TAB
key 104   PAGE_UP
key 109   PAGE_DOWN

key 2     1
key 3     2
key 4     3
key 5     4
key 6     5
key 7     6
key 8     7
key 9     8
key 10    9
key 11    0
key 52    PERIOD
key 111   DEL

key 119   MEDIA_PAUSE
key 207   MEDIA_PLAY

key 418   F3
key 419   F4

4. Automatically compile and build

Need to copy fdd70030_pwm.kl and fdd70030_pwm.idc to device/rockchip/commonthe directory. And add copy rules in device.mk, it will be automatically copied to the specified directory when compiling.

PRODUCT_COPY_FILES += \
    device/rockchip/common/fdd70030_pwm.kl:system/usr/keylayout/fdd70030_pwm.kl \

The power button has no effect during debugging.
Theoretically, after the usercode and keycode are added, the system needs to 重新启动use the power button once. (At this time, after rebooting, look at the keycode value printed by the serial port, and directly replace the previous powerkey_keycode value with the u-boot stage code), which can achieve the effect that the power key can be used for the first time when the power key is burned.
insert image description here

Note:
a) "OK" key is KEY_REPLY.
b) /vendor/usr/keylayout is the same as /system/usr/keylayout.
c) Infrared registration failed, you can check PWM GPIO multiplexing (iomux).

Guess you like

Origin blog.csdn.net/weixin_45639314/article/details/131127607