一、开发板LCD的使用
打开LCD:open(“/dev/fb0”,O_WRONLY);
写LCD(向LCD填充颜色值):write();
方法一:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main(void)
{
//打开lcd屏
int lcd_fd = open("/dev/fb0", O_WRONLY);
//判断
if (lcd_fd == -1)
{
printf("open LCD failed!\n");
return -1;
}
//写缓冲区
int lcd_buf[800*480] = {0};
//给缓冲区赋值
int i;
for(i=0; i<800*480; i++)
{
lcd_buf[i] = 0x00ffffff;//白色
}
write(lcd_fd, lcd_buf, 800*480*4);
return 0;
}
方法二:
#include <stdio.h>
#include <errno.h>
#include "file.h"
int main(int argc,char **argv)
{
int red = 0x00ff0000;
int lcd_fd = open_file("/dev/fb0",O_WRONLY,0);
int *lcd_mem = mmap(NULL,800*480*4,PORT_READ|PORT_WRITE,MAP_SHARED,lcd_fd,0);
for(int i = 0;i<800*480;i++)
*(lcd_mem+i) = red;
return 0;
}
二、触摸屏的使用
打开触摸屏:open(“/dev/input/event0”,O_RDWR);
读触摸屏:read();
注意:每读一次只能得到一个结构体。
触摸屏结构体:
struct input_event {
struct timeval time;
__u16 type; --->事件类型(发生了按键事件)
__u16 code; --->事件编码(按了哪个键)
__s32 value; --->事件的值(按下还是松开)
};
获取的数据:
type : 3 , code : 0 , value : 784 //X轴坐标
type : 3 , code : 0x1 , value : 19 //Y轴坐标
type : 1 , code : 0x14a , value : 1 //按键事件---》按下
type : 1 , code : 0x14a , value : 0 //按键事件---》松开
数据具体分析:参照input-event-codes.h
type : 3 , code : 0 , value : 784
type --->发生的绝对坐标事件 #define EV_ABS 0x03 //绝对坐标
code--->X轴 #define ABS_X 0x00
value--->X轴坐标的值
根据事件的不同,值代表的意义不同
#include <stdio.h>
#include <errno.h>
#include <linux/input.h>
#include "file.h"
/* struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
}; */
int main(int argc,char **argv)
{
int x,y;
int cnt=0;
struct input_event ts;
int ts_fd = open_file("/dev/input/event0",O_RDONLY,0);
while(1)
{
while(1)
{
read(ts_fd,&ts,sizeof(ts));
if(ts.type == EV_ABS && ts.code == ABS_X)
{
x = ts.value;
cnt++;
}
if(ts.type == EV_ABS && ts.code == ABS_Y)
{
y = ts.value;
cnt++;
}
if(cnt == 2)
break;
}
cnt = 0;
printf("(%d , %d)\n",x,y);
}
return 0;
}