The android platform uses GPIO analog IR to control the vehicle DTV

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.