当前位置:首页 > 公众号精选 > 嵌入式客栈
[导读]红外遥控是我们经常见到的一种无线收发设备,比如电视遥控,空调遥控,现在电视遥控有些慢慢变成了蓝牙装置。昨天是在知识星球里面看到有人提问,今天来解析一份网友写的驱动程序。调试红外需要注意几个细节1、我们发射的遥控器用肉眼是看不到的,需要拿相机来观察。2、红外接收管和普通的二极管不同...

红外遥控是我们经常见到的一种无线收发设备,比如电视遥控,空调遥控,现在电视遥控有些慢慢变成了蓝牙装置。昨天是在知识星球里面看到有人提问,今天来解析一份网友写的驱动程序。


调试红外需要注意几个细节

1、我们发射的遥控器用肉眼是看不到的,需要拿相机来观察。

2、红外接收管和普通的二极管不同,如果用错物料也是不行的。



1.NEC协议无线传输数据原理


NEC协议的特征: 


1、8位地址和8位指令长度; 

2、地址和命令两次传输;(确保可靠性) 

3、PWM脉冲宽度调制,以发射红外载波的占空比代表“0”和“1”; 

4、载波频率为38KHz 

5、位时间为1.125ms和2.25ms 


NEC码位的定义:一个脉冲对应560us的连续载波,一个逻辑1传输需要2.25ms(560us脉冲 1680us低电平),一个逻辑0的 传输需要1.125ms(560us脉冲 560us低电平)。


而遥控接收头在收到脉冲时为低电平,在没有收到脉冲时为高电平,因此, 我们在接收头端收到的信号为:逻辑1应该是560us低 1680us高,逻辑0应该是560us低 560us高。


如下图:




硬件




2. Linux下的驱动接收程序


参考原文:


https://blog.csdn.net/wllw7176/article/details/110506677


两个驱动文件


gpio-ir-recv.c

/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */


#include 

  • #include 

  • #include 

  • #include 

  • #include 

  • #include 

  • #include 

  • #include 

  • #include 

  • #include 

  • #include 
    #include 

    #define GPIO_IR_DRIVER_NAME "gpio-rc-recv"
    #define GPIO_IR_DEVICE_NAME "gpio_ir_recv"

    struct gpio_rc_dev {
     struct rc_dev *rcdev;
     int gpio_nr;
     bool active_low;
    };

    #ifdef CONFIG_OF
    /*
     * Translate OpenFirmware node properties into platform_data
     */

    static int gpio_ir_recv_get_devtree_pdata(struct device *dev,
          struct gpio_ir_recv_platform_data *pdata)

    {
     struct device_node *np = dev->of_node;
     enum of_gpio_flags flags;
     int gpio;

     gpio = of_get_gpio_flags(np, 0
  • 本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
    关闭
    关闭