IR (Infrared Radiation), is a wireless communication method. Usually the remote control is used as the transmitter and the TV or set-top box is used as the receiver. In the receiving process, the IR wave signal is converted to electrical signal through optical filter and photodiode, and this signal is amplified, detector, shaped, demodulated and sent to the decoding and interface circuit to complete the corresponding remote control function.
In RK3568,PWM driver can support the demodulation of IR data, convert it into specified data and report it to the system layer by way of input_event.
For different remote controls, each usercode and keycode correspondence is different, and this correspondence can usually be obtained from the remote control manufacturer, and this correspondence needs to be configured in the device tree. The underlying driver will convert the parsed data to the specified key value based on this keycode table.
You can view all INPUT devices in the current system with the following command
cat /proc/bus/input/devices
The results are as follows
The first one is the IR device.
The IR slot needs to have an IR receiver plugged into it, the wiring is as follows
In addition, these input devices can be read by commands like cat or hexdump, but the contents cannot be parsed out, so we will only introduce the C API to operate them
All the event nodes under "/dev/input" need root privileges to operate, and programs compiled in C need root privileges to operate input devices. If you are using ssh or LX terminal, first execute the following command to get root privileges.
sudo su
By linking to the libperipheral_api.a static library, the following interfaces can be called in C to operate IR
/**
* @name: user_ir_open
* @description: open ir device
* @return greater than or equal to 0 - success, return value is file descriptor; less than 0 - failure
*/
int user_ir_open(void);
/**
* @name: user_ir_get
* @description: Read data from ir device
* @param fd: file descriptor, user_ir_open return value
* @param code: current keystroke value
* @param value: current event type, 1 - pressed; 0 - bounced
*
* @return equal to 0 - success; less than 0 - failure, no data or error
*/
int user_ir_get(int fd, int *code, int *value);
/**
* @name: user_ir_close
* @description: close ir device
* @param fd: file descriptor, user_ir_open return value
* @return always equal to 0, meaningless
*/
int user_ir_close(int fd);
The test demos are as follows
#include "peripheral_api.h"
void ir_api_test(void)
{
int ret = 0;
int fd = -1;
int code = 0, value = 0;
fd = user_ir_open();
if (fd < 0) {
printf("user_ir_open fail \n");
return;
}
for (;;) {
ret = user_ir_get(fd, &code, &value);
if (ret == 0) {
printf("key %d %s\n", code, (value) ? "pressed" : "released");
} else {
usleep(10 * 1000);
}
}
user_ir_close(fd);
return;
}
int main()
{
ir_api_test();
return 0;
}
Compile and run the following results, press the 1 2 3 4 5 6 buttons in sequence
Note that the key value and the value do not correspond to each other, but the relationship between the two can be found in the include/uapi/linux/input-event-codes.h header file in the kernel