效果如下图:
DTS修改如下:
&i2c1 {
status = "okay";
ssd1306fb: ssd1306fb@3c {
compatible = "solomon,ssd1306fb-i2c";
reg = <0x3c>;
solomon,width = <128>;
solomon,height = <64>;
solomon,page-offset = <0>;
solomon,com-invdir;
};
};
kernel config 修改如下:
diff --git a/arch/arm64/configs/rockchip_defconfig b/arch/arm64/configs/rockchip_defconfig
index b0f9a34..28ecac3 100644
--- a/arch/arm64/configs/rockchip_defconfig
+++ b/arch/arm64/configs/rockchip_defconfig
@@ -625,6 +625,7 @@ CONFIG_MALI_BIFROST_DEVFREQ=y
CONFIG_MALI_PLATFORM_NAME="rk"
CONFIG_MALI_BIFROST_EXPERT=y
CONFIG_MALI_BIFROST_DEBUG=y
+CONFIG_FB_SSD1307=y
CONFIG_BACKLIGHT_LCD_SUPPORT=y
# CONFIG_LCD_CLASS_DEVICE is not set
CONFIG_BACKLIGHT_CLASS_DEVICE=y
测试代码如下:
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
/*seconds: the seconds; mseconds: the micro seconds*/
void setTimer(int seconds, int mseconds)
{
struct timeval temp;
temp.tv_sec = seconds;
temp.tv_usec = mseconds;
printf("timer1\n");
select(0, NULL, NULL, NULL, &temp);
printf("timer2\n");
return ;
}
int main ()
{
char lichee[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x80,0x1F,0x00,0x00,0x80,0x0F,0x00,0x0F,0x00,0x00,0x38,0x00,0x70,0x00,0x00,
0x00,0xC0,0xFF,0x00,0x70,0xC0,0x3F,0x00,0x0F,0x00,0x00,0xFF,0x01,0xFF,0x01,0x00,
0x00,0xC0,0xE1,0x01,0x7E,0xE0,0x38,0x80,0x1F,0x00,0x80,0xC7,0x03,0xC7,0x03,0x00,
0x00,0xC0,0xC1,0x83,0x0F,0x70,0x70,0x80,0x1F,0x00,0xC0,0x01,0x07,0x81,0x07,0x00,
0x00,0xC0,0x81,0x83,0x03,0x70,0x70,0x80,0x1D,0x00,0xC0,0x01,0x0F,0x00,0x07,0x00,
0x00,0xC0,0x81,0xC3,0x01,0x70,0x70,0x80,0x19,0x00,0xE0,0x00,0x0E,0x00,0x07,0x00,
0x00,0xC0,0x81,0xC3,0x00,0x70,0x70,0xC0,0x39,0x00,0xE0,0x00,0x0E,0x00,0x07,0x00,
0x00,0xC0,0x81,0xE3,0x00,0xE0,0x38,0xC0,0x39,0x00,0x70,0x00,0x1C,0x00,0x07,0x00,
0x00,0xC0,0xC1,0x61,0x3E,0xE0,0x1D,0xC0,0x39,0x00,0x70,0x00,0x1C,0x00,0x07,0x00,
0x00,0xC0,0xE1,0x71,0x7F,0x80,0x1F,0xE0,0x70,0x00,0x70,0x00,0x1C,0x80,0x03,0x00,
0x00,0xC0,0xFF,0xF0,0xF1,0xC0,0x1F,0xE0,0x70,0x00,0x70,0x00,0x1C,0x80,0x03,0x00,
0x00,0xC0,0x7F,0xF0,0xE0,0xE1,0x3C,0xE0,0x70,0x00,0x70,0x00,0x1C,0xC0,0x01,0x00,
0x00,0xC0,0xE1,0x70,0xC0,0x71,0x70,0xE0,0x70,0xF0,0x77,0x00,0x1C,0xE0,0x01,0x00,
0x00,0xC0,0xC1,0x71,0xC0,0x39,0xF0,0xF0,0xFF,0xF0,0x77,0x00,0x1C,0xE0,0x00,0x00,
0x00,0xC0,0xC1,0x71,0xC0,0x39,0xE0,0xF0,0xFF,0x00,0xE0,0x00,0x0E,0x70,0x00,0x00,
0x00,0xC0,0xC1,0x71,0xC0,0x39,0xE0,0x70,0xE0,0x00,0xE0,0x00,0x0E,0x38,0x00,0x00,
0x00,0xC0,0x81,0xE1,0xC0,0x39,0xE0,0x38,0xE0,0x01,0xE0,0x01,0x0E,0x3C,0x00,0x00,
0x00,0xC0,0x81,0xE3,0xE0,0x78,0x70,0x38,0xC0,0x01,0xC0,0x01,0x07,0x1E,0x00,0x00,
0x00,0xC0,0x81,0xC3,0xF1,0xF0,0x78,0x38,0xC0,0x01,0x80,0xC7,0x03,0x0F,0x00,0x00,
0x00,0xC0,0x81,0x83,0x3F,0xE0,0x3F,0x3C,0xC0,0x03,0x00,0xFF,0x81,0xFF,0x07,0x00,
0x00,0xC0,0x81,0x07,0x0C,0x80,0x0F,0x1C,0x80,0x03,0x00,0xF8,0x87,0xFF,0x07,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x1F,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,
0x60,0xE6,0x99,0xCD,0x0C,0xCF,0x83,0x37,0x73,0x7C,0x87,0x0F,0x3C,0x0F,0xDF,0x01,
0x60,0xE6,0x99,0xCD,0x0C,0x67,0xC6,0xB0,0xD9,0xCC,0xCC,0x0E,0x86,0x19,0x33,0x03,
0x40,0x2A,0xA9,0x48,0x05,0x33,0x6C,0xB0,0x88,0xCD,0x6C,0x0C,0xC3,0x30,0x33,0x03,
0x40,0x2A,0xA9,0x48,0x05,0x33,0x6C,0xF0,0x8C,0xCD,0x6C,0x0C,0xC3,0x30,0x33,0x03,
0x40,0x29,0xA5,0x28,0x05,0x33,0x6C,0xB0,0xFC,0xCD,0x6C,0x0C,0xC3,0x30,0x33,0x03,
0x40,0x29,0xA5,0x28,0x05,0x33,0x6C,0xB0,0x0D,0xCC,0x6C,0x0C,0xC3,0x30,0x33,0x03,
0x80,0x19,0x66,0x30,0x63,0x63,0xC6,0x30,0x1B,0xCC,0xCC,0xCC,0x86,0x19,0x33,0x03,
0x80,0x19,0x66,0x30,0x63,0xC3,0x83,0x37,0xF3,0xCC,0x8C,0xCF,0x3C,0x0F,0x33,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
int fp=0;
long screensize=0;
char *fbp = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
fp = open ("/dev/graphics/fb0",O_RDWR);
if (fp < 0){
printf("Error : Can not open framebuffer device/n");
exit(1);
}
if (ioctl(fp,FBIOGET_FSCREENINFO,&finfo)){
printf("Error reading fixed information/n");
exit(2);
}
if (ioctl(fp,FBIOGET_VSCREENINFO,&vinfo)){
printf("Error reading variable information/n");
exit(3);
}
printf("The mem is :%d\n",finfo.smem_len);
printf("The line_length is :%d\n",finfo.line_length);
printf("The xres is :%d\n",vinfo.xres);
printf("The yres is :%d\n",vinfo.yres);
printf("bits_per_pixel is :%d\n",vinfo.bits_per_pixel);
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
printf("screensize: %ld\n",screensize);
fbp =(char *) mmap (0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fp,0);
if ((int) fbp == -1)
{
printf ("Error: failed to map framebuffer device to memory./n");
exit (4);
}
int i=0;
memset(fbp, 0x00, 1024);
setTimer(3,0);
// while(1){
for(i=0;i<1024;i++){
fbp[i]=lichee[i];
}
//setTimer(3,0);
// memset(fbp, 0x00, 1024);
// setTimer(3,0);
// }
munmap (fbp, screensize);
close (fp);
}