福彩3D走势图

技术天地

在英创Linux主板上用GPIO实现矩阵键盘作者:黄志超    发布时间:2019-7-29    被阅览数:次

  YINGCHUANGGONGSIDELinuxZHUBANDUIYUJUZHENJIANPANDEZHICHIYOUDUOZHONGFANGANKEYISHIXIAN,WOMENZAIYIQIANTUICHUGUOSHIYONGi2cKUOZHANDEFANGAN,JUTIQINGKUANGKEYICANKAOETA202MOKUAIDEZILIAO:,ZHEIZHONGFANGANDEHAOCHUSHIZHIXUYAOSHIYONGI2CZONGXIANDELIANGTIAOXINHAOXIANSCLHESDA,KEYIJIEYUEZHUBANSHANGDEGPIOZIYUAN。ESMARCXILIEZHUBANDOUYONGYOU32WEIGPIOZIYUAN,WEILEGENGHAOLIYONGYINGJIANZIYUAN,YINGCHUANGGONGSITUICHULEGPIOJIEJUZHENJIANPANDEFANGAN,ZAIIOZIYUANMANZUXUQIUDEQINGKUANGXIA,KEYISHIYONGZHEITAOFANGAN,YOUDIANSHIKEYIJIEYUEYINGJIANKUOZHANDECHENGBEN,BINGQIERUANJIANSHANGSHIYONGLinuxBIAOZHUNDEinputSHEBEIJIEKOUJIUKEYICAOZUO,BUXUYAOEWAIZUORENHEGONGZUO。


  GPIOZHICHIJUZHENJIANPANSHITONGGUOIOZHONGDUANLAISHIXIANDE,DANGJIANCEDAOYOUANJIANANXIA,JIUHUICHUFAZHONGDUAN,SAOMIAOJIANPANLAIPANDUANJUTIDEANJIANDONGZUO。ZHICHIDEJUZHENJIANPANZUIDAFANWEIWEI4×5,WOMENYIYINGCHUANGGONGSIDEJUZHENJIANPANMOKUAIWEILI:


英创Linux主板支持矩阵键盘.png


  SHIYONGDEGUANJIAOWEIGPIO16~GPIO24,YUESMARCPINGGUDIBANLIANJIECESHI,LIANJIEFANGSHIRUXIA:


英创Linux主板支持矩阵键盘.png


  JUTIDEXINHAOPAILIERUXIA(CN18):


信号及说明PIN#信号及说明
GPIO16 -> 用作 ROW012GPIO17 -> 用作 COL0
GPIO18 -> 用作 ROW134GPIO19 -> 用作 COL1
GPIO20 -> 用作 ROW256GPIO21 -> 用作 COL2
GPIO22 -> 用作 ROW378GPIO23 -> 用作 COL3
GPIO24 -> 用作 ROW4910GPIO25
GPIO261112GPIO27
GPIO281314GPIO29
GPIO301516GPIO31
+5V1718+5V
GND1920GND


福彩3D走势图  YINGCHUANGGONGSIYIJINGJIANGQUDONGWENJIANZHIZUOCHENGNEIHEQUDONGMOKUAIDEXINGSHIFANGRUWENJIANXITONGZHONGLE,QUDONGMINGCHENGWEImatrix_keypad.ko,YONGHUYAOSHIYONGGAIGONGNENG,ZHIXUYAOJIAZAIQUDONGMOKUAIJIKE。QUDONGMOKUAIFANGZAI/lib/modules/<kernel-version>/XIAMIAN,LIRUSHIYONGESM335xZHUBAN,YINWEIESM335xDENEIHEBANBENWEI4.1.6,SHURUMINGLINGWEI:insmode /lib/modules/4.1.6/matrix_keypad.ko,ZHUYIRUGUOSHIYONGDEZHUBANWEIESM7000,ESM6802,ESM6800HHUOZHEESM6800VXILIEDEBANKA,KEYISHIYONGMINGLING:modprobe matrix_keypad,BUXUYAODAIRULUJING。


  WEILEBIMIANZHANYONGBUBIYAODEYINGJIANZIYUAN,GENJUSHIJIDEXUQIU,ZAIJIAZAIQUDONGMOKUAIDESHIHOUKEYIDAIRUCANSHUZHIDINGHENGLIEDESHUZHI,CANSHUcol(1-4)DAIBIAOLIESHU,row(1-5)DAIBIAOHENGPAISHU,RUGUOBUDAIRUCANSHU,MORENWEIZHICHIcol=4,row=5DEJUZHENJIANPAN。YIESM335xWEILI,JIAZAIZHICHI3×3DAXIAOJUZHENJIANPANDEMINGLINGWEIinsmod /lib/modules/4.1.6/matrix_keypad.ko col=3 row=3,RUXIARUSUOSHI:


英创Linux主板支持矩阵键盘.png

加载驱动


  福彩3D走势图当代入col和row的值小于最大值的时候,驱动占用的管脚资源是从COL0和ROW0开始的,例如上面设置的3×3大小,占用的管脚为COL0-COL2,ROW0-ROW2,对应的按键如下图所示:


英创Linux主板支持矩阵键盘.png

3×3对应按键


  驱动加载成功后,会在/dev/input目录下生成对应的event设备节点,系统根据当前的event设备数,会自动为生成设备节点增加序号。以ESM335x为例,生成的设备节点为/dev/input/even1,如下图:


英创Linux主板支持矩阵键盘.png

设备节点


  福彩3D走势图图中event0为ESM335x主板自带的触摸屏设备节点,所以加载驱动后矩阵键盘的设备节点就会自动命名为event2,通过这个设备节点,就可以通过程序读取按键的键值了。其中每一个按键都有一个对应的键值,英创公司使用的是标准的WINDOWS按键消息值,为方便客户评估,矩阵键盘的虚拟键码与英创矩阵键盘扩展模块(ETA201)完全对应,具体的虚拟键码如下所示:


 COL0COL1COL2COL3
ROW0VK_ESCAPE/0x1BVK_0/0x60VK_PERIOD/0xBEVK_BACK/0x08
ROW1VK_ADD/0x6BVK_1/0x61VK_2/0x62VK_BACK/0x08
ROW2VK_SUBTRACT/0x6DVK_4/0x64VK_5/0x65VK_BACK/0x08
ROW3VK_MULTIPLY/0x6AVK_7/0x67VK_8/0x68VK_9/0x69
ROW4VK_DIVIDE/0x6FVK_SPACE/0x20VK_DECIMAL/0x6EVK_RETURN/0x0D


  YUXUNIJIANMADUIYINGDE16JINZHIZHIKEZAIMSDNSHANGZHAODAO:。


  RUANJIANSHANGSHIFENJIANDAN,ZAICHENGXUZHONGXIANTONGGUOopenHANSHUDAKAIJUZHENJIANPANDUIYINGDESHEBEIJIEDIAN,RANHOUTONGGUOreadHANSHUJIUKEYIDUQUCHUXINXI,JUTIDAIMARUXIA:



struct input_event input;

int fd, rd;

//打开设备节点

if ((fd = open ("/dev/input/event1", O_RDONLY)) == -1)

{

       printf ("open failed!\n");

       return -1;

}

 

rd = read(fd, (void*)&input, sizeof(input));

if(rd <= 0)

       printf ("rd: %d\n", rd);



  ZAISHANGMIANDEDAIMAZHONGKEYIKANDAO,DUQUCHULAIDESHIYIGEinput_eventJIEGOUTI,ZHEISHILinuxXITONGBIAOZHUNDOUWENJIANDINGYIDEJIEGOUTI,TONGGUOZHEIGEJIEGOUTIKEYIHUOQUDAOWOMENSUOXUYAODESUOYOUXINXI,XIAMIANJIULAIJIESHAOYIXIAZHEIGEJIEGOUTI:



/*

 * The event structure itself

*/

structinput_event {

       struct timeval time;

       __u16type;

       __u16code;

       __s32value;

};



  QIZHONGtimeDEZHIWEIANJIANSHIJIAN。typeWEISHIJIANLEIXING,YINWEIQUDONGZHICHIDESHIJUZHENJIANPAN,SUOYIZHEILIDEZHIZONGSHIWEIEV_KEY(0x01)。codeWEIJIANZHI,JUTIDEJIANZHIQINGCANKAOSHANGMIANDEBIAOGE。valueWEIANJIANSHIJIANDEZHI,ZAISHIJIANLEIXINGWEIEV_KEYSHI,DANGANJIANANXIASHIZHIWEI1,SONGKAISHIZHIWEI0。


  DUQUANJIANCAOZUODEWANZHENGDAIMARUXIA:



int main (int argc, char *argv[])

{

       struct input_event input;

       int fd, rd;

 

       //打开设备节点

       if ((fd = open ("/dev/input/event1", O_RDONLY)) == -1)

       {

              printf ("open failed!\n");

              return -1;

       }

 

       printf("Press any key.\n");

 

       while(1)

       {

              memset((void*)&input, 0, sizeof(input));

              //读取input设备信息

              rd = read(fd, (void*)&input, sizeof(input));

              if(rd <= 0)

                     printf ("rd: %d\n", rd);

 

              //判断按键动作

              if(input.type == 1)

              {

                     switch(input.value)

                     {

                     case 0:

                            printf("Key release\n");

                            break;

                     case 1:

                            printf("Key press\n");

                            break;

                     case 2:

                            printf("Key hold\n");

                            break;

                     default:

                            printf("Undifined value\n");

                     }

                     //打印键值

                     printf("Code: 0x%x\n", input.code);

              }

       }

       return 0;

}


Go Top