提示:作为Espressif(乐鑫科技)大中华区合作伙伴及sigmastar(厦门星宸)VAD合作伙伴,我们不仅用心整理了你在开发过程中可能会遇到的问题以及快速上手的简明教程供开发小伙伴参考。同时也用心整理了乐鑫及星宸科技的新产品、新方案的主要特点及应用!希望你能第一时间了解并快速用上好的方案和产品!
简称IR,是一种无线通讯方式,可以进行无线数据的传输。SSD20X拥有1路IR,支持NEC编码。
PM_IR为主控IR信号输入端:
NEC编码协议包含一个9ms+4.5ms的帧头,工作时根据帧头筛选需要接收的数据。使用示波器对PM_IR引脚进行测量(按下遥控器的任意按键),可以确认帧头,同时可以验证IR电路是否能正常接收IR信号:
# 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
驱动根据kernel/drivers/sstar/ir/include/IR_MSTAR_DTV.h中的mstar_tv[]的配置进行上报按键键值。
mstar_tv[]为一个二维数组,第一个值为currKey,第二个值为上报的键值code,即当驱动接收到IR数据为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
联系客服