Digital TV-DTV is no longer a new thing for us. On-board electronics, DTV mostly exists independently in the form of modules and is configurable. In the on-board market, the customer's needs are diverse. If DTV is used as the on-board navigation main PCB, it is still not flexible. If DTV is not used, it must be different PCB boards, this is not a good solution for after-sales maintenance and development.
DTV is at home, and we usually operate through the remote control. Of course, some android TV boxes can be controlled by mobile phones now. There is an apk of the taijie remote control, through the same wifi hotspot TV box, it is convenient to use a mobile phone. But in the car, how do I operate DTV? In a car, the space is usually relatively narrow, and it is inconvenient to use the remote control. Therefore, we need to implement the control to the navigation control. In the remote control protocol, the NEC protocol is the most widely used. Next we will take the NEC protocol as an example to learn how to use GPIO to simulate IR key messages.
A key information of NEC consists of the Data header, Customer Code, Customer Code, key value, key value, and stop bit. Duplicate codes are not described here. The data header is a combination of 9 ms + ms, followed by four bytes of value, that is, the combination of 0 and 1 of 32bit. The gpio port of the IR port is usually high by default, and the decoder driver mostly uses the descent edge to trigger the interruption. Here we mainly want to compile a string of IR pulses. The code for combining this string of pulses is as follows:
gpio_write_one_pin_value(simulate_ir_gpio_hdle, 0, "simulate_ir_gpio"); Delay10us(900);// 9ms gpio_write_one_pin_value(simulate_ir_gpio_hdle, 1, "simulate_ir_gpio"); Delay10us(450);// 4.5ms //IR Customer Code: 0x807f , NEC IR protocol SendByteData(0x80); // DVB HEADER_CODE0 SendByteData(0x7F); // DVB HEADER_CODE1 SendByteData(IRData); SendByteData(~IRData); gpio_write_one_pin_value(simulate_ir_gpio_hdle, 0, "simulate_ir_gpio"); Delay10us(56); gpio_write_one_pin_value(simulate_ir_gpio_hdle, 1, "simulate_ir_gpio");
There is a problem here: it takes more than 50 ms to compile this pulse, and the standard complete message is about 108 ms-110 ms. This requires that we cannot be scheduled by the task in the middle of sending 4 bytes of data and the stop code, because the width of the code will be greatly different when the task is scheduled, the remote control value is regarded as an incorrect value after receiving end parsing. So how can we guarantee it? In linux, there is a spinlock, that is, the spin lock. Once this lock is obtained, it can ensure that the processes executed are not scheduled to be preemptible. Therefore, the above Code adds a lock and cancels the lock operation. In actual operations, the success rate of sending the IR key value is in nearly operations. The lock-related code is as follows:
#include <linux/spinlock.h>spinlock_tlock; spin_lock_init(&lock); spin_lock(&lock); ////////////////for your process////////////////// spin_unlock(&lock);
In the upper layer of android, ioctl can be used for control. The upper layer can be encapsulated in the service for upper-layer applications.