触觉智能分享|SSD20X红外接口调试参考

红外线(Infrared Radiation),简称IR,是一种无线通讯方式,可以进行无线数据的传输。SSD20X拥有1路IR,支持NEC编码。

01.硬件设计

PM_IR为主控IR信号输入端:

图片

02.确认帧头

NEC编码协议包含一个9ms+4.5ms的帧头,工作时根据帧头筛选需要接收的数据。使用示波器对PM_IR引脚进行测量(按下遥控器的任意按键),可以确认帧头,同时可以验证IR电路是否能正常接收IR信号:

图片

图片

从第一个下降沿开始计算,根据以上波形能够知道,前9ms一直为低电平(0x00),后4.5ms为高电平(0xFF),因此可以确认帧头为0x00+0xFF。

03.加载驱动

# cd kernel

# ARCH=arm make menuconfig

Device Drivers  --->

[*] SStar SoC platform drivers  --->

<*>   SStar IR driver

 同时需要修改驱动,配置正确的帧头:

# vi kernel/drivers/sstar/ir/include/IR_MSTAR_DTV.h

#define IR_HEADER_CODE0         0x00    // 9ms

#define IR_HEADER_CODE1         0xFF    // 4.5ms

04.按键匹配

驱动根据kernel/drivers/sstar/ir/include/IR_MSTAR_DTV.h中的mstar_tv[]的配置进行上报按键键值。

mstar_tv[]为一个二维数组,第一个值为currKey,第二个值为上报的键值code,即当驱动接收到IR数据为currKey时,就会上报键值code。

图片

使用ir.c进行测试,确认每个按键的currkey,以此绑定code:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include



int main(int argc, char **argv)

{

         struct input_event event;

         char name[64];

         int fd;

         int rc;

        

         if ( argc != 2){

                  printf("usage: ./ir_test 0\n");

                  return 0;

         }

        



         sprintf(name, "/dev/input/event%d", atoi(argv[1]));

        

         while(1)

         {

                  if ((fd = open(name, O_RDWR, 0)) >= 0)

                  {

                           printf("%s: open, fd = %d\n", name, fd);

                           while ((rc = read(fd, &event, sizeof(event))) > 0)

                           {

                                    if (event.type == EV_KEY)

                                    {

                                             switch (event.code)

                                             {

                                                      case KEY_0 :

                                                               printf("KEY_0 %s\n", (event.value)?"Pressed":"Released");

                                                               break;

                                                      case KEY_1 :

                                                               printf("KEY_1 %s\n", (event.value)?"Pressed":"Released");

                                                               break;

                                                      default:

                                                               break;

                                             }

                                    }

                           }

                           close(fd);

                  }else{

                           return -1;

                  }

         }



         return 0;

}

# arm-linux-gnueabihf-gcc ir.c -o ir_tes

 把ir_test拷贝到开发板上运行,并按下遥控器上的按键,观察程序打印的currKey:

#./ir_test 0

图片

可以看到,当我按下遥控器上的”1”按键时,显示currKey=0x45,因此修改mstar_tv[],将0x45和KEY_1绑定:

图片

同样地,继续按键遥控器上的其他按键,在mstar_tv[]中将它们进行绑定,这样,在ir.c  中,我们就能根据event.code来判断是哪个按键按下了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Industio_触觉智能

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值