使用F1C200S从零制作掌机之官方LCD驱动测试

一、硬件

LCD显示实验使用LicheePi Nano开发板。

屏幕使用官方的5寸电阻屏幕。

image-20240612143121877

image-20240612143151143

image-20240612135137555

二、u-boot配置LCD

sudo apt-get install git
git clone https://github.com/Lichee-Pi/u-boot.git
cd u-boot

# 查看分支
git branch -a
# 切换到 Nano 分支
git checkout nano-v2018.01

设置LCD,配置过程如下:

make menuconfig

通过配置 ARM architecture ‣ Enable graphical uboot console on HDMI, LCD or VGAY

接着根据你自己的显示屏大小,配置同级的 LCD panel timing details 为:

800*480 规格

x:800,y:480,depth:18,pclk_khz:33000,le:87,ri:40,up:31,lo:13,hs:1,vs:1,sync:3,vmode:0

480*272 规格

x:480,y:272,depth:18,pclk_khz:10000,le:42,ri:8,up:11,lo:4,hs:1,vs:1,sync:3,vmode:0

开启编译

make

替换原有u-boot

查看效果???我这里还没看。

三、Linux的lcd驱动

使用官方移植好的linux-nano-5.2-tf测试屏幕。

源码下载:https://github.com/Lichee-Pi/linux/tree/nano-5.2-tf

不做任何修改,直接编译。将zImage和suniv-f1c100s-licheepi-nano.dtb拷贝到SD卡。

重新上电开机屏亮,无内容显示。

2.1 测试屏幕

cat /dev/zero > /dev/fb0

cat /dev/urandom > /dev/fb0

2.2 如何将linux日志输出到屏幕

  1. 修改 bootargs=console=tty0 console=ttyS0,115200 panic=5 rootwait root=/dev/mmcblk0p2 earlyprintk rw

  2. Kernel 开启 Device Drivers > Graphics support > Console display driver support > Framebuffer Console Support

2.3 怎样显示小企鹅

内核配置 Device Drivers —> Graphics support —> [*]Boot logo —> 全选

2.4 lcd 怎么知道是RGB565 RGB888 RGB666

cat /sys/class/graphics/fb0/rgb

fbset -s

# fbset -s

mode "800x480-0"
        # D: 0.000 MHz, H: 0.000 kHz, V: 0.000 Hz
        geometry 800 480 800 480 32
        timings 0 0 0 0 0 0 0
        accel true
        rgba 8/16,8/8,8/0,0/0
endmode
fbset 的参数
fbset是一个用于设置和显示Linux系统上Linux帧缓冲设备的工具。它提供了很多参数供用户设置,下面将依次介绍这些参数的作用和使用方法。
1. 显示器相关参数:
- geometry:设置显示器的宽度和高度,格式为“<宽度> <高度>”,例如“1024 768”。
- timings:设置显示器的时序参数,格式为“<像素时钟> <前沿同步> <后缘同步> <上行> <下行> <左边距> <右边距> <上边距> <下边距>”,例如“50.0 160 24 29 3 32 96 2 10”。
- virtrefresh:设置虚拟屏幕刷新频率,单位为Hz,例如“60”。
- refresh:设置显示器刷新频率,单位为Hz,例如“75”。
2. 像素格式参数:
- depth:设置像素位数,例如“16”表示16位色彩。
- rgba:设置颜色分量的位移和位数,格式为“<红色位移>:<红色位数>,<绿色位移>:<绿色位数>,<蓝色位移>:<蓝色位数>,<透明度位移>:<透明度位数>”,例如“11:5,5:6,0:5,0:0”表示R5G6B5格式。
- cmap:设置颜色映射表的位数,例如“8”表示8位颜色索引。
3. 缓冲区参数:
- accel:设置是否启用硬件加速,值为“true”或“false”。
- ywrap:设置是否启用垂直滚动,值为“true”或“false”。
- ypan:设置垂直滚动的偏移量,单位为像素,例如“0”表示不偏移。
4. 其他参数:
- fbmem:设置帧缓冲设备的内存地址,格式为“<起始地址> <长度>”,例如“0xc0000000 16384”。
- swapbytes:设置是否交换像素字节序,值为“true”或“false”。
- slowfb:设置是否启用慢速帧缓冲设备,值为“true”或“false”。
以上就是fbset的一些常用参数和使用方法。通过设置这些参数,用户可以调整和优化Linux系统上的帧缓冲设备,以获得更好的显示效果和性能。

2.5 fb 与应用程序的交互

在应用层中,用户可以将fb设备看成是显存的一个映像,将其映射到进程空间后,就可以直接进行读写操作,写操作会直接反映在屏幕上。

在应用程序中,操作 /dev/fbn 的一般步骤如下:

  1. 打开 /dev/fbn 设备文件;
  2. ioctl() 操作取得当前显示屏幕的参数,如屏幕分辨率、每个像素点的比特数。根据屏幕参数可计算屏幕缓冲区的大小;
  3. mmap() 函数,将屏幕缓冲区映射到用户空间;
  4. 映射后就可以直接读/写屏幕缓冲区,进行绘图和图片显示;
  5. 使用完帧缓冲设备后需要将其释放;
  6. 关闭文件。

应用示例:

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ioctl.h>
 
/* 显示屏相关头文件 */
#include <linux/fb.h>
#include <sys/mman.h>
 
typedef struct lcd_color
{
    unsigned char bule;
    unsigned char green;
    unsigned char red;
    unsigned char alpha;
} lcd_color;
 
/**
 * 更新屏幕显示内存块信息,颜色格式为RGB8888
*/
void screen_refresh(unsigned char *fbp, lcd_color color_buff, long screen_size)
{
    for(int i=0; i < screen_size; i+=4)
    {
        *((lcd_color*)(fbp + i)) = color_buff;
    }
    usleep(1000*2000);
}
 
int main()
{
    int fp = 0;
    int rgb_type = 0;
    long screen_size = 0; 
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;          
    unsigned char *fbp = 0;
 
    fp = open("/dev/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);
 
    /* 获取RGB的颜色颜色格式,比如RGB8888、RGB656 */
    rgb_type = vinfo.bits_per_pixel / 8;
    /* 屏幕的像素点 */
    screen_size = vinfo.xres * vinfo.yres * rgb_type;
    /* 映射 framebuffer 的缓冲空间,得到一个指向这块空间的指针 */
    fbp =(unsigned char *) mmap (NULL, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fp, 0);
    if (fbp == NULL)
    {
       printf ("Error: failed to map framebuffer device to memory./n");
       exit (4);
    }
 
    /* 刷白屏 */
    memset(fbp, 0xff, screen_size);    
    usleep(1000*2000);
 
    /* 我的显示屏是RGBA的,所以县色格式为32为,注意自己的显示屏信息,对应修改 */
    /* 刷红色 */
    screen_refresh(fbp, (lcd_color){0, 0, 255, 255}, screen_size);
    usleep(1000*2000);
 
    /* 刷绿色 */
    screen_refresh(fbp, (lcd_color){0, 255, 0, 255}, screen_size);
    usleep(1000*2000);
 
    /* 刷蓝色 */
    screen_refresh(fbp, (lcd_color){255, 0, 0, 255}, screen_size);
    usleep(1000*2000);
 
    /* 解除映射 */
    munmap (fbp, screen_size); 
 
    close(fp);
    return 0;
}
# ./lcd_test
The mem is :1536000
The line_length is :3200
The xres is :800
The yres is :480
bits_per_pixel is :32

四、LCD时序

https://blog.csdn.net/richard_liujh/article/details/46352857

https://blog.csdn.net/weixin_55053963/article/details/129430133?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-129430133-blog-46352857.235%5Ev43%5Epc_blog_bottom_relevance_base4&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-2-129430133-blog-46352857.235%5Ev43%5Epc_blog_bottom_relevance_base4&utm_relevant_index=5

img

img

五、更多

正点原子4.3寸:https://blog.csdn.net/qq_41709234/article/details/128586204

正点原子7寸:https://blog.csdn.net/qq_27350133/article/details/124602894

st7789:https://blog.csdn.net/qq_33552551/article/details/133740350

GT1151:https://download.csdn.net/blog/column/12158774/128661071

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值