|
本帖最后由 wtmelen 于 2022-9-6 09:34 编辑
已经解决
请教大神,运行mmap出错,查不出原因。
报错:
toybrick@debian10:~/03mycode/dispaly$ sudo ./display
screen_size:8294400
mmap error: Invalid argument
- static int width; //LCD X 分辨率
- static int height; //LCD Y 分辨率
- static unsigned short *screen_base = NULL; //映射后的显存基地址
- int main(int argc, char *argv[])
- {
- struct fb_fix_screeninfo fb_fix;
- struct fb_var_screeninfo fb_var;
- unsigned int screen_size;
- int fd;
- /* 打开 framebuffer 设备 */
- if (0 > (fd = open("/dev/fb0", O_RDWR))) {
- perror("open error");
- exit(EXIT_FAILURE);
- }
- /* 获取参数信息 */
- ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
- ioctl(fd, FBIOGET_FSCREENINFO, &fb_fix);
- screen_size = fb_fix.line_length * fb_var.yres;
- printf("screen_size:%d\r\n",screen_size);
- width = fb_var.xres;
- height = fb_var.yres;
- /* 将显示缓冲区映射到进程地址空间 */
- screen_base = mmap(NULL, screen_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
- if (MAP_FAILED == (void *)screen_base) {
- perror("mmap error");
- close(fd);
- exit(EXIT_FAILURE);
- }
- memset(screen_base, 0xFF, screen_size);
- munmap(screen_base, screen_size); //取消映射
- close(fd); //关闭文件
- exit(EXIT_SUCCESS); //退出进
- }
|
|