RK3228H开发之新红外遥控器的适配

一、引言

在android中适配一个红外遥控器,除了驱动部分的适配,还需要转换编码,而编码的转换涉及到硬件原始编码、linux编码以及上层java的编码,这里简单说一下。

小广告

中间打个小广告,是本人的一个小小副业。

大家有需要各种品牌的鞋(耐克、阿迪、斐乐、vans、匡威等),都可以加下面这个微信号,性价比巨高,质量绝对可靠,自己穿的也都是这买的,到手不喜欢,不影响二次销售可直接退货,希望大家能多多支持(暂时不想买的也欢迎添加,首双优惠!),全国包邮!

vx:cp_shop12138

二、适配新的红外遥控器

1、底层编码转换

只要涉及到dts文件

......
        ir_key4 {
                rockchip,usercode = <0x5347>;
                rockchip,key_table =
                        <0xe8   KEY_ENTER>,
                        <0xfb   KEY_BACK>,
                        <0xec   KEY_UP>,
                        <0xeb   KEY_DOWN>,
                        <0xea   KEY_LEFT>,
                        <0xe9   KEY_RIGHT>,
                        <0xe7   KEY_VOLUMEUP>,
                        <0xe6   KEY_VOLUMEDOWN>,
                //        <0xad   KEY_SEARCH>,
                        <0xe5   KEY_POWER>,
                        <0xa4   KEY_MUTE>,
                        <0xad   KEY_MENU>,
                        <0xfc   KEY_HOME>,
               //         <0xf9   0x191>,
               //         <0xf5   0x192>,
               //         <0xb3   388>,
                        <0x57   185>,
                        <0x56   186>,
                        <0xf7   KEY_1>,
                        <0xf6   KEY_2>,
                        <0xf5   KEY_3>,
                        <0xf4   KEY_4>,
                        <0xf3   KEY_5>,
                        <0xf2   KEY_6>,
                        <0xf1   KEY_7>,
                        <0xf0   KEY_8>,
                        <0xef   KEY_9>,
                        <0xf8   KEY_0>,
                        <0x1F   KEY_LAYOUT>,
//                      <0x20   KEY_PTZ>,
//                      <0x1e   KEY_DEMO>,
                        <0xfa   KEY_CALL>,
                        <0xf9   KEY_ENDCALL>,
//                      <0xfa   KEY_CALL>,
//                      <0xf9   KEY_ENDCALL>,
                        <0xbc   KEY_BACKSPACE>;
        };
        ......

而用来填写这个关系表的数值,可以在android中打印出来
在android中输入如下命令

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

echo 0 > sys/module/rockchip_pwm_remotectl/parameters/code_print  //关闭

在按下遥控器上的按键,会有如下打印

shell@c03:/ # [ 1604.358668] I[1:      swapper/1:    0] USERCODE=0x5347
[ 1604.384983] I[1:      swapper/1:    0] RMC_GETDATA=ea
[ 1604.978988] I[1:      swapper/1:    0] USERCODE=0x5347
[ 1605.005263] I[1:      swapper/1:    0] RMC_GETDATA=e9
[ 1605.404248] I[1:      swapper/1:    0] USERCODE=0x5347
[ 1605.430567] I[1:      swapper/1:    0] RMC_GETDATA=ec
[ 1605.808230] I[1:      swapper/1:    0] USERCODE=0x5347
[ 1605.834547] I[1:      swapper/1:    0] RMC_GETDATA=eb
[ 1606.197356] I[1:      swapper/1:    0] USERCODE=0x5347
[ 1606.223649] I[1:      swapper/1:    0] RMC_GETDATA=ea
[ 1606.608632] I[1:      swapper/1:    0] USERCODE=0x5347
[ 1606.634924] I[1:      swapper/1:    0] RMC_GETDATA=e9

分别匹配该遥控器的系统码及按键的原始编码

2、linux编码设置
include/dt-bindings/input/input.h
......
#define KEY_RESERVED            0
#define KEY_ESC                 1
#define KEY_1                   2
#define KEY_2                   3
#define KEY_3                   4
#define KEY_4                   5
#define KEY_5                   6
#define KEY_6                   7
#define KEY_7                   8
#define KEY_8                   9
#define KEY_9                   10
#define KEY_0                   11
#define KEY_MINUS               12
#define KEY_EQUAL               13
#define KEY_BACKSPACE           14
#define KEY_TAB                 15
#define KEY_Q                   16
#define KEY_W                   17
#define KEY_E                   18
#define KEY_R                   19
#define KEY_T                   20
#define KEY_Y                   21
#define KEY_U                   22
#define KEY_I                   23
#define KEY_O                   24
#define KEY_P                   25
......
3、android层的修改

主要是修改kl文件,加入键值对应关系,这里要注意键值的命名以及,要与linux中的功能码对应上

device/rockchip/rksdk/20050030_pwm.kl

.......
key 28    ENTER
key 116   POWER             WAKE
key 158   BACK
key 139   MENU
key 217   SEARCH
key 232   DPAD_CENTER
key 108   DPAD_DOWN
key 103   DPAD_UP
key 102   HOME
key 105   DPAD_LEFT
key 106   DPAD_RIGHT
key 115   VOLUME_UP
key 114   VOLUME_DOWN
key 143   NOTIFICATION      WAKE
key 113   VOLUME_MUTE
key 388   F3
key 400   TV_MEDIA_MULT_BACKWARD
key 401   TV_MEDIA_MULT_FORWARD
key 402   TV_MEDIA_PLAY_PAUSE
key 64    TV_MEDIA_PLAY
key 65    TV_MEDIA_PAUSE
key 66    TV_MEDIA_STOP
key 67    TV_MEDIA_REWIND
key 68    TV_MEDIA_FAST_FORWARD
key 87    TV_MEDIA_PREVIOUS
key 88    TV_MEDIA_NEXT
key 141   SETTINGS

java

最后就是java文件的修改

frameworks/base/core/java/android/view/KeyEvent.java

.......
/** Key code constant: '1' key. */
    public static final int KEYCODE_1               = 8;
    /** Key code constant: '2' key. */
    public static final int KEYCODE_2               = 9;
    /** Key code constant: '3' key. */
    public static final int KEYCODE_3               = 10;
    /** Key code constant: '4' key. */
    public static final int KEYCODE_4               = 11;
    /** Key code constant: '5' key. */
    public static final int KEYCODE_5               = 12;
    /** Key code constant: '6' key. */
    public static final int KEYCODE_6               = 13;
    /** Key code constant: '7' key. */
    public static final int KEYCODE_7               = 14;
    /** Key code constant: '8' key. */
    public static final int KEYCODE_8               = 15;
    /** Key code constant: '9' key. */
    public static final int KEYCODE_9               = 16;
    /** Key code constant: '*' key. */
    public static final int KEYCODE_STAR            = 17;
    /** Key code constant: '#' key. */
    public static final int KEYCODE_POUND           = 18;
......

其中的键值名称除去KEYCODE_后要与kl文件中的相同

上层键值表的查看

我们可以在以下文件中查看上层定义的键值关系表

development/ndk/platforms/android-9/include/android/keycodes.h

.........
enum {
    AKEYCODE_UNKNOWN         = 0,
    AKEYCODE_SOFT_LEFT       = 1,
    AKEYCODE_SOFT_RIGHT      = 2,
    AKEYCODE_HOME            = 3,
    AKEYCODE_BACK            = 4,
    AKEYCODE_CALL            = 5,
    AKEYCODE_ENDCALL         = 6,
    AKEYCODE_0               = 7,
    AKEYCODE_1               = 8,
    AKEYCODE_2               = 9,
    AKEYCODE_3               = 10,
    AKEYCODE_4               = 11,
    AKEYCODE_5               = 12,
    AKEYCODE_6               = 13,
    AKEYCODE_7               = 14,
    AKEYCODE_8               = 15,
    AKEYCODE_9               = 16,
    AKEYCODE_STAR            = 17,
    AKEYCODE_POUND           = 18,
    AKEYCODE_DPAD_UP         = 19,
    AKEYCODE_DPAD_DOWN       = 20,
    AKEYCODE_DPAD_LEFT       = 21,
    AKEYCODE_DPAD_RIGHT      = 22,
    AKEYCODE_DPAD_CENTER     = 23,
    AKEYCODE_VOLUME_UP       = 24,
    AKEYCODE_VOLUME_DOWN     = 25,
    AKEYCODE_POWER           = 26,
    AKEYCODE_CAMERA          = 27,
.......

其他

以下网址为android键值关系表 可以查阅下
Android KeyCode列表

你可能感兴趣的:(linux,android)