Difference between revisions of "Rock/ir"
(9 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{rock_header}} | ||
{{Languages|rock/ir}} | {{Languages|rock/ir}} | ||
__TOC__ | __TOC__ | ||
− | The Radxa Rock comes with IR sensor(between the uSD card and USB otg port). This page | + | The Radxa Rock comes with IR sensor(between the uSD card and USB otg port). This page describes how to use and configure the remote to work properly on RR. You can do this in two ways: |
* Modify the IR kernel driver - low level hacking, working on Linux and Android since they are based the same kernel | * Modify the IR kernel driver - low level hacking, working on Linux and Android since they are based the same kernel | ||
Line 16: | Line 17: | ||
1、Add an array as follow: | 1、Add an array as follow: | ||
+ | <syntaxhighlight lang="c" enclose="div"> | ||
static struct rkxx_remote_key_table remote_key_table_41C8[] = { | static struct rkxx_remote_key_table remote_key_table_41C8[] = { | ||
− | + | {0x38, KEY_VOLUMEUP}, | |
− | + | {0xb8, KEY_VOLUMEDOWN}, | |
− | + | {0x58, KEY_MENU}, | |
− | + | {0xd0, KEY_REPLY}, | |
− | + | {0x48, KEY_BACK}, | |
− | + | {0x98, KEY_BACK}, | |
− | + | {0x50, KEY_UP}, | |
− | + | {0x30, KEY_DOWN}, | |
− | + | {0xc8, KEY_LEFT}, | |
− | + | {0xc0, KEY_RIGHT}, | |
− | + | {0x40, KEY_REPLY}, | |
− | + | {0x80, KEY_SEARCH}, | |
}; | }; | ||
− | + | </syntaxhighlight> | |
− | The first column is the IR key value,the second column is the corresponding key | + | The first column is the IR key value,the second column is the corresponding key code. |
2、Add one item in | 2、Add one item in | ||
− | + | <syntaxhighlight lang="c"> | |
+ | static struct rkxx_remotectl_button remotectl_button[] | ||
+ | </syntaxhighlight> | ||
For example: | For example: | ||
+ | <syntaxhighlight lang="c"> | ||
{ | { | ||
− | .usercode = 0x41c8, | + | .usercode = 0x41c8, /* need to get the usercode in next step */ |
− | + | .nbuttons = 12, /* number of buttons */ | |
− | + | .key_table = &remote_key_table_41C8[0], /* key table */ | |
}, | }, | ||
+ | </syntaxhighlight> | ||
− | The first is usercode, every IR has a usercode; the second is the | + | The first is usercode, every IR has a usercode; the second is the number of buttons, the third is the address of the array we added in the 1st step. |
− | the third is the | + | |
− | How to get the usercode and IR key value | + | === How to get the usercode and IR key value === |
− | In the remotectl_do_something func | + | |
+ | In the '''remotectl_do_something''' func | ||
+ | <syntaxhighlight lang="c" highlight="9"> | ||
case RMC_USERCODE: | case RMC_USERCODE: | ||
{ | { | ||
Line 68: | Line 75: | ||
} | } | ||
− | + | </syntaxhighlight> | |
+ | |||
+ | Uncomment the printk code to get the usercode,then add remotectl_button array with the usercode and the buttons number | ||
+ | <syntaxhighlight lang="c" highlight="9"> | ||
case RMC_GETDATA: | case RMC_GETDATA: | ||
{ | { | ||
Line 89: | Line 99: | ||
} | } | ||
− | + | </syntaxhighlight> | |
+ | Uncomment the printk code ,you can get the IR key value | ||
Note: | Note: | ||
− | # | + | # The printk output is in hex(0x) format, the first two number is we needed ,the last two number is just used for checking, we can ignore it. |
− | + | # Don't leave much printing log in code, it will make in the ir not work. | |
− | # Don't leave much log in code, | + | |
== Android Key Remapping == | == Android Key Remapping == | ||
+ | /system/usr/keylayout/rkxx-remotectl.kl is a file mapping scancodes(linux) to keycodes(android). you can add the item to match your IR- remocon's key. | ||
+ | Here are some mistakes someone has met. | ||
+ | |||
+ | 1) Number KEY doesn't work.(Map's Items is wrote wrong) | ||
+ | |||
+ | //Wrong Code | ||
+ | key 1 KEY_1 | ||
+ | key 2 KEY_2 | ||
+ | key 3 KEY_3 | ||
+ | key 4 KEY_4 | ||
+ | key 5 KEY_5 | ||
+ | key 6 KEY_6 | ||
+ | key 7 KEY_7 | ||
+ | key 8 KEY_8 | ||
+ | key 9 KEY_9 | ||
+ | key 0 KEY_0 | ||
+ | |||
+ | //Right Code | ||
+ | key 1 ESCAPE | ||
+ | key 2 1 //NOTE is 1 not 2 | ||
+ | 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 |
Latest revision as of 04:18, 6 January 2015
The Radxa Rock comes with IR sensor(between the uSD card and USB otg port). This page describes how to use and configure the remote to work properly on RR. You can do this in two ways:
- Modify the IR kernel driver - low level hacking, working on Linux and Android since they are based the same kernel
- Modify the Android key mapping if you use android - user space hacking
Kernel Level
The IR driver only supports NEC Encode format. Below is the instructions of how to add you IR remote to send the right key code in Linux kernel.
There is just one file related "kernel/drivers/input/remotectl/rkxx_remotectl.c"
Do as follows
1、Add an array as follow:
{0x38, KEY_VOLUMEUP},
{0xb8, KEY_VOLUMEDOWN},
{0x58, KEY_MENU},
{0xd0, KEY_REPLY},
{0x48, KEY_BACK},
{0x98, KEY_BACK},
{0x50, KEY_UP},
{0x30, KEY_DOWN},
{0xc8, KEY_LEFT},
{0xc0, KEY_RIGHT},
{0x40, KEY_REPLY},
{0x80, KEY_SEARCH},
};
The first column is the IR key value,the second column is the corresponding key code.
2、Add one item in
static struct rkxx_remotectl_button remotectl_button[]
For example:
{ .usercode = 0x41c8, /* need to get the usercode in next step */ .nbuttons = 12, /* number of buttons */ .key_table = &remote_key_table_41C8[0], /* key table */ },
The first is usercode, every IR has a usercode; the second is the number of buttons, the third is the address of the array we added in the 1st step.
How to get the usercode and IR key value
In the remotectl_do_something func
case RMC_USERCODE: { ddata->scanData <<= 1; ddata->count ++; if ((TIME_BIT1_MIN < ddata->period) && (ddata->period < TIME_BIT1_MAX)){ ddata->scanData |= 0x01; } if (ddata->count == 0x10){//16 bit user code // printk("u=0x%x\n",((ddata->scanData)&0xFFFF)); if (remotectl_keybdNum_lookup(ddata)){ ddata->state = RMC_GETDATA; ddata->scanData = 0; ddata->count = 0; }else{ ddata->state = RMC_PRELOAD; } } }
Uncomment the printk code to get the usercode,then add remotectl_button array with the usercode and the buttons number
case RMC_GETDATA: { ddata->count ++; ddata->scanData <<= 1; if ((TIME_BIT1_MIN < ddata->period) && (ddata->period < TIME_BIT1_MAX)){ ddata->scanData |= 0x01; } if (ddata->count == 0x10){ // printk(KERN_ERR "d=%x\n",(ddata->scanData&0xFFFF)); if ((ddata->scanData&0x0ff) == ((~ddata->scanData >> 8)&0x0ff)){ if (remotectl_keycode_lookup(ddata)){ ddata->press = 1; ... } ... } ... } }
Uncomment the printk code ,you can get the IR key value
Note:
- The printk output is in hex(0x) format, the first two number is we needed ,the last two number is just used for checking, we can ignore it.
- Don't leave much printing log in code, it will make in the ir not work.
Android Key Remapping
/system/usr/keylayout/rkxx-remotectl.kl is a file mapping scancodes(linux) to keycodes(android). you can add the item to match your IR- remocon's key. Here are some mistakes someone has met.
1) Number KEY doesn't work.(Map's Items is wrote wrong)
//Wrong Code key 1 KEY_1 key 2 KEY_2 key 3 KEY_3 key 4 KEY_4 key 5 KEY_5 key 6 KEY_6 key 7 KEY_7 key 8 KEY_8 key 9 KEY_9 key 0 KEY_0
//Right Code key 1 ESCAPE key 2 1 //NOTE is 1 not 2 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