您尚未登录。

楼主 # 2022-06-06 22:12:46

爱上linux
会员
注册时间: 2022-06-06
已发帖子: 2
积分: 2

基于T113-S3 屏幕R-G-B切换闪屏问题

TFT 800x480 max 46.8MHz

关于dev/fb0的使用,有哪位大佬能帮忙看一下,如何解决这个闪花屏问题?
代码如下:

代码如下

#include "stdio.h"
#include "stdint.h"
#include "string.h"
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "fbio.h"
#include "linux/fb.h"
#include <unistd.h>
#include <sys/time.h>
#include "stdio.h"

#define FBDEV_PATH  "/dev/fb0"

int fbfd = 0;
struct fb_var_screeninfo vinfo;

uint8_t * fbdev_init() {
  uint8_t * fbp = 0;
  struct fb_fix_screeninfo finfo;
  uint32_t screensize = 0;

  fbfd = open(FBDEV_PATH, O_RDWR);
  
  if(fbfd == -1) {
    perror("Error: cannot open framebuffer device");
    return fbp;
  }

  printf("The framebuffer device was opened successfully.\n");

  struct fbtype fb;
  unsigned line_length;


  // Get fixed screen information
  if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
    perror("Error reading fixed information");
    return fbp;
  }

  // Get variable screen information
  if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
    perror("Error reading variable information");
    return fbp;
  }

  // Figure out the size of the screen in bytes
  screensize =  finfo.smem_len; //finfo.line_length * vinfo.yres;    

  // Map the device to memory
  fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);

  printf("%dx%d, %dbpp, size: %d; ptr: %08X\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel, screensize, fbp);
  
  if ((intptr_t)fbp == -1) {
    perror("Error: failed to map framebuffer device to memory");
    return fbp;
  }
  
  memset(fbp, 0x00, screensize);
 
  return fbp;
}

void fb_try_pan(uint32_t offset) {
  vinfo.xoffset = 0;
  vinfo.yoffset = offset;
  vinfo.activate = FB_ACTIVATE_VBL;

  int res = ioctl(fbfd, FBIOPAN_DISPLAY, &vinfo);

  if (res==-1) {
    printf("fb_try_pan res: %d\n", res);
    perror("fb_try_pan res:");
  }
}

int cur_fb=0;

void fill_fb(uint32_t * fb, uint32_t pattern) {
  struct timeval tv;
  uint32_t fb_num=1;

  if (cur_fb==1) {  // Draw on inactive buf
    fb_num=0;
  }

  gettimeofday(&tv,NULL);
  long st = 1000000 * tv.tv_sec + tv.tv_usec;

  printf("Draw on buf %d. Current buf: %d\n", fb_num, cur_fb);
  
  for (uint32_t i=0; i<1024*600; i++) {
    fb[i+fb_num*1024*600]=pattern;
  }

  if (cur_fb==1) {  // Draw on inactive buf
    printf("Activate buf 0\n");
    fb_try_pan(600);
    fb_try_pan(0);
    cur_fb=0;
  }
    else
  {
    printf("Activate buf 1\n");
    fb_try_pan(0);
    fb_try_pan(600);
    cur_fb=1;
  } 

  gettimeofday(&tv,NULL);
  long end = 1000000 * tv.tv_sec + tv.tv_usec;
  long t=end-st;

  printf("time: %d, fps: %d\n", t, 1000000/t);

  usleep(1000000);
}

int main(void) {
  uint32_t * fb;
  printf("Hello my T133 board\n");

  fb=(uint32_t *)fbdev_init();

  if (fb==NULL) {
    return 0;
  }

  fb_try_pan(0);
 
  while (1) {
    printf("RED!!!\n");
    fill_fb(fb, 0x01FF0000);
    printf("GREEN!!!\n");
    fill_fb(fb, 0x0100FF00);
    printf("BLUE!!!\n");
    fill_fb(fb, 0x010000FF);
    printf("BLACK!!!\n");
    fill_fb(fb, 0x01000000);
    printf("WHITE!!!\n");
    fill_fb(fb, 0x01FFFFFF);
  }
#endif
}

离线

楼主 #2 2022-06-06 22:52:48

爱上linux
会员
注册时间: 2022-06-06
已发帖子: 2
积分: 2

Re: 基于T113-S3 屏幕R-G-B切换闪屏问题

哇酷小二 说:

可能像素时钟频率太高了。

感谢回复,像素时钟设置为36Mhz是匹配LCD参数的,另外尝试了修改PCLK,也都没有解决此问题......
另外,换用 mango-pi MQ Dual T113 (标准Linux image),也有相同的问题,即使使用双缓冲…看起来屏幕更新非常慢。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn