⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btnio.h

📁 矩阵button驱动
💻 H
字号:
#include <linux/ioctl.h>#include <unistd.h>#include "btn_ioctl_cmd.h"#ifndef u8 #define u8 unsigned char#endif//used in the function getKeyValue() and getKey();//this is the phone key layoutstatic u8 key[8][4]={                           {'*','1','4','7'},                           {'0','2','5','8'},                           {'#','3','6','9'},                           {'e','h',' ','k'},                           {' ',' ',' ',' '},                           {' ','a','j','b'},                           {' ',' ',' ','i'},                           {' ',' ',' ','l'},};static u8 getKeyValue(u8 x,u8 position_Y);static u8 getKey(u8 position[2]);static u8 btnRead(int fd);////the key[][] variable is global variable,which represent the phone key layoutstatic u8 getKeyValue(u8 x,u8 position_Y){         if(!(position_Y & ~0x40)) return key[x][3];    if(!(position_Y & ~0x20)) return key[x][2];    if(!(position_Y & ~0x10)) return key[x][1];    if(!(position_Y & ~0x08)) return key[x][0];        printf("the position_Y key is not existing\n");    return 0xff;}////the key[][] variable is global variable,which represent the phone key layoutstatic u8 getKey(u8 position[2]){    u8 keyValue=0;    if(!(position[0] & 0x80)) return 'n';//hang up    if(!(position[0] & ~0x80)) return keyValue=getKeyValue(7,position[1]);//call        if(!(position[0] & ~0x81)) return keyValue=getKeyValue(0,position[1]);    if(!(position[0] & ~0x82)) return keyValue=getKeyValue(1,position[1]);    if(!(position[0] & ~0x84)) return keyValue=getKeyValue(2,position[1]);    if(!(position[0] & ~0x88)) return keyValue=getKeyValue(3,position[1]);    if(!(position[0] & ~0xa0)) return keyValue=getKeyValue(5,position[1]);    if(!(position[0] & ~0xc0)) return keyValue=getKeyValue(6,position[1]);            printf("the position_X key is not existing\n");    return 0xff;}u8 btnRead(int fd){    u8 row=0,temp_row=0,temp_col=0;    u8 position[2]={0};    u8 ch=0;    int num=0;        int status=0;        static int hangUp_or_call=1;    while(1)    {        ioctl(fd,BTN_GET_POSITION,position);        row=position[0];                temp_col=position[1];//keep the col value        if( (row & 0x80) && (row & ~0x80))//check whether the row is what we need         {            temp_row=row;//keep the row value                        //eliminate dither            ioctl(fd,BTN_GET_POSITION,position);            row=position[0];                        if(temp_row==row)//eliminate dither            {                                ioctl(fd,BTN_GET_STATUS,&status);                while(status) ioctl(fd,BTN_GET_STATUS,&status);                /*                do                {//just ready for accepting next key value,so hold the process                    usleep(10000);                    //button_read(&row);                    ioctl(fd,BTN_GET_POSITION,position);                    row=position[0];                                        if(num++>30)                    {                        break;                    }                }                while(!(row & ~0x80) || temp_row==row);                printf(" matrix button read temp_row:%x\n",temp_row);                printf(" matrix button read row:%x\n",row);                */                                position[0]=temp_row;                position[1]=temp_col;                ch=getKey(position);//get the key value                if(ch)                {                    return ch;                    break;                }            }        }        else        {            if(!(row & ~0x80))            {               // printf("=======================%x\n",row);               if( !row  && hangUp_or_call == 1) {hangUp_or_call = 2;return 'n';}                else if( row  && hangUp_or_call == 2 ){hangUp_or_call = 1; return 'y';}            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -