/*
* Driver Test/Example Program
*
* Compile with:
* gcc -s -Wall -Wstrict-prototypes tftfb0test.c -o tftfb0test
*
export PATH=$PATH:/usr/src/arm-linux-3.3/toolchain_gnueabi-4.4.0_ARMv5TE/usr/bin
arm-linux-gcc -s -Wall -Wstrict-prototypes tftfb0test.c -o tftfb0test
* Copyright (C) 1996, Paul Gortmaker.
*
* Released under the GNU General Public License, version 2,
* included herein by reference.
*
*/
#include <stdio.h>
//#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <linux/errno.h>
#include <linux/types.h>
/*
* This expects the new RTC class driver framework, working with
* clocks that will often not be clones of what the PC-AT had.
* Use the command line to specify another RTC if you need one.
*/
//static const char default_SPI[] = "/dev/spidev";
/* 9th_spi_test on
* 9th_spi_test off
*/
#if 0
int main(int argc, char **argv)
{
int fd;
int val = 1;
fd = open("/dev/fb0", O_RDWR);
if (fd < 0)
{
printf("can't open!\n");
}
if (argc != 2)
{
printf("Usage :\n");
printf("%s <on|off>\n", argv[0]);
return 0;
}
if (1)//(strcmp(argv[1], "on") == 0)
{
val = 1;
}
else
{
val = 0;
}
write(fd, &val, 4);
return 0;
}
#else // test
/*功能:在LCD屏幕上显示红色汉字“赵”。
(1)打开/dev/fbn 设备文件;
(2)用 ioctl()操作取得当前显示屏幕的参数,如屏幕分辨率、每个像素点的比特数和偏移;
根据屏幕参数可计算屏幕缓冲区的大小;
(3)将屏幕缓冲区映射到用户空间;
(4)映射后就可以直接读/写屏幕缓冲区,进行绘图和图片显示了。*/
int main(int argc, char **argv)
{
int fbfd=0;
struct fb_var_screeninfo vinfo;
unsigned long screensize=0;
char *fbp=0;
char hz[16][2]={
0x08, 0x00, 0x08, 0x00, 0x08, 0x04, 0x7E, 0x84, 0x08, 0x48, 0x08, 0x28, 0xFF, 0x10, 0x08, 0x10,
0x28, 0x28, 0x2F, 0x28, 0x28, 0x44, 0x28, 0x84, 0x58, 0x00, 0x48, 0x00, 0x87, 0xFE, 0x00, 0x00, }; //16*16字模库中提取的“赵”字对应的字符数组
// int x=0,y=0;
/* 第一步 open the device fb0*/
fbfd=open("/dev/fb0",O_RDWR); //打开帧缓冲设备
if(!fbfd){
printf("error,can't open dev/fb0!\n");
exit(1);
}
if (argc != 2)
{
printf("Usage show :\n");
printf("%s <on|off>\n", argv[0]);
return 0;
}
/* 第二步 获取这个LCD的一些可变的参数*/
if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo)){ //获取屏幕可变参数
printf("error to get VSCREENINFO\n");
exit(1);
}
//打印屏幕可变参数
printf("vinfo %dx%d,%dbpp\n",vinfo.xres,vinfo.yres,vinfo.bits_per_pixel);
screensize=vinfo.xres*vinfo.yres* vinfo.bits_per_pixel/2; //缓冲区字节大小
fbp=(char *)mmap(0,screensize,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0);//映射
if((int)fbp==-1){
printf("error to MAP_SHARED\n");
exit(4);
}
memset(fbp,0,screensize); //清屏 全部设置为黑色
int i,j,k;
for(j=0;j<16;j++){
for(i=0;i<2;i++){
for(k=0;k<8;k++){
if(hz[j][i]&(0x80>>k))
*((unsigned short *)(fbp + j*vinfo.xres*2 + i*16 + k*2))=0xf100;
}
}
}
munmap(fbp,screensize);
close(fbfd);
return 0;
}
#endif
* Driver Test/Example Program
*
* Compile with:
* gcc -s -Wall -Wstrict-prototypes tftfb0test.c -o tftfb0test
*
export PATH=$PATH:/usr/src/arm-linux-3.3/toolchain_gnueabi-4.4.0_ARMv5TE/usr/bin
arm-linux-gcc -s -Wall -Wstrict-prototypes tftfb0test.c -o tftfb0test
* Copyright (C) 1996, Paul Gortmaker.
*
* Released under the GNU General Public License, version 2,
* included herein by reference.
*
*/
#include <stdio.h>
//#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <linux/errno.h>
#include <linux/types.h>
/*
* This expects the new RTC class driver framework, working with
* clocks that will often not be clones of what the PC-AT had.
* Use the command line to specify another RTC if you need one.
*/
//static const char default_SPI[] = "/dev/spidev";
/* 9th_spi_test on
* 9th_spi_test off
*/
#if 0
int main(int argc, char **argv)
{
int fd;
int val = 1;
fd = open("/dev/fb0", O_RDWR);
if (fd < 0)
{
printf("can't open!\n");
}
if (argc != 2)
{
printf("Usage :\n");
printf("%s <on|off>\n", argv[0]);
return 0;
}
if (1)//(strcmp(argv[1], "on") == 0)
{
val = 1;
}
else
{
val = 0;
}
write(fd, &val, 4);
return 0;
}
#else // test
/*功能:在LCD屏幕上显示红色汉字“赵”。
(1)打开/dev/fbn 设备文件;
(2)用 ioctl()操作取得当前显示屏幕的参数,如屏幕分辨率、每个像素点的比特数和偏移;
根据屏幕参数可计算屏幕缓冲区的大小;
(3)将屏幕缓冲区映射到用户空间;
(4)映射后就可以直接读/写屏幕缓冲区,进行绘图和图片显示了。*/
int main(int argc, char **argv)
{
int fbfd=0;
struct fb_var_screeninfo vinfo;
unsigned long screensize=0;
char *fbp=0;
char hz[16][2]={
0x08, 0x00, 0x08, 0x00, 0x08, 0x04, 0x7E, 0x84, 0x08, 0x48, 0x08, 0x28, 0xFF, 0x10, 0x08, 0x10,
0x28, 0x28, 0x2F, 0x28, 0x28, 0x44, 0x28, 0x84, 0x58, 0x00, 0x48, 0x00, 0x87, 0xFE, 0x00, 0x00, }; //16*16字模库中提取的“赵”字对应的字符数组
// int x=0,y=0;
/* 第一步 open the device fb0*/
fbfd=open("/dev/fb0",O_RDWR); //打开帧缓冲设备
if(!fbfd){
printf("error,can't open dev/fb0!\n");
exit(1);
}
if (argc != 2)
{
printf("Usage show :\n");
printf("%s <on|off>\n", argv[0]);
return 0;
}
/* 第二步 获取这个LCD的一些可变的参数*/
if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo)){ //获取屏幕可变参数
printf("error to get VSCREENINFO\n");
exit(1);
}
//打印屏幕可变参数
printf("vinfo %dx%d,%dbpp\n",vinfo.xres,vinfo.yres,vinfo.bits_per_pixel);
screensize=vinfo.xres*vinfo.yres* vinfo.bits_per_pixel/2; //缓冲区字节大小
fbp=(char *)mmap(0,screensize,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0);//映射
if((int)fbp==-1){
printf("error to MAP_SHARED\n");
exit(4);
}
memset(fbp,0,screensize); //清屏 全部设置为黑色
int i,j,k;
for(j=0;j<16;j++){
for(i=0;i<2;i++){
for(k=0;k<8;k++){
if(hz[j][i]&(0x80>>k))
*((unsigned short *)(fbp + j*vinfo.xres*2 + i*16 + k*2))=0xf100;
}
}
}
munmap(fbp,screensize);
close(fbfd);
return 0;
}
#endif