0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SHARP Brain に Linux を入れて遊ぶ(2) - フレームバッファ

Last updated at Posted at 2022-09-24

目次

概要

その1 で Linux が動いたので、画面周りを見ていこう。

画面周り

/dev/fb0

/dev/fb0 が存在するので、これを取得してみる。

user@brain:~$ cat /dev/fb0 > fb0.dat
user@brain:~$ ls -ls
total 756
752 -rw-r--r-- 1 user user 768000 Aug  7 19:44 fb0.dat
  4 drwxrwxr-x 2 user user   4096 Aug  7 19:03 lxterminal
user@brain:~$

768,000 バイトなので 800x480x16bpp ですね、はい。
頭にテキトーな 16bpp BMP ヘッダを付けて確認。

fb.bmp
+00: 42 4D 42 B8 0B 00 00 00 00 00 42 00 00 00 28 00
+10: 00 00 20 03 00 00 20 FE FF FF 01 00 10 00 03 00
+20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+30: 00 00 00 00 00 00 00 F8 00 00 E0 07 00 00 1F 00
+40: 00 00

フレームバッファの内容
fb.png

フレームバッファの情報を取得

ちょちょいとコードを書いて確認する。

fb.c
#include <linux/fb.h>
#include <stdio.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>

int main()
{
  const int fd = open("/dev/fb0", O_RDWR);
  if (fd != -1)
  {
    struct fb_var_screeninfo si;
    ioctl(fd, FBIOGET_VSCREENINFO, &si);
    printf("%d x %d x %dbpp\n", si.xres_virtual, si.yres_virtual, si.bits_per_pixel);
    close(fd);
  }
  return 0;
}

結果

user@brain:~/work$ gcc fb.c
user@brain:~/work$ ./a.out
800 x 480 x 16bpp
user@brain:~/work$

フレームバッファに書き込む

マップトファイルで画面をクリアしてみる。

fb2.c
#include <memory.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <linux/fb.h>
#include <linux/omapfb.h>

int main()
{
  const int fd = open("/dev/fb0", O_RDWR);
  if (fd != -1)
  {
    uint16_t* p = (uint16_t*)mmap(NULL, 800 * 480 * 2, PROT_WRITE, MAP_SHARED, fd, 0);
    if (p)
    {
      memset(p, 0, 800 * 480 * 2);
    }
    close(fd);
  }
  return 0;
}

動作OK。これで色々遊べそうだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?