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?

CoreMP135のLCDにPythonで描画する

Last updated at Posted at 2024-07-21

目的

CoreMP135のLCDにPythonで描画します。
CoreMP135のLCDのデバイスファイル/dev/fb1/ に、Python3を使ってYellow画像(320x240, RGB565形式))を書き込みます。

image.png

開発環境

Debian12をインストールしたCoreMP135を使いました。

CoreMP135
 Description:    Debian GNU/Linux 12 (bookworm)
 Linux CoreMP135 5.15.118 #1 SMP PREEMPT Thu Jun 27 19:59:30 JST 2024 armv7l GNU/Linux

ライブラリのインストール

 今回は、Pythonライブラリに、numpy, fcntl, mmapを使います。fcntlとmmapは標準ライブラリの一部なので、追加でインストールする必要はありません。numpyをインストールする。

sudo apt install python3-numpy

LCDへの描画

python3のプログラムで、LCDのフレームバッファのパスと情報(320x240、RGB565)を設定します。
そして、フレームバッファファイルを開き、メモリにマップします。
黄色の値をRGB565の値に計算して、フレームバッファ全体を塗りつぶします。

# python3 coremp135_lcd_yellow.py
coremp135_lcd_yellow.py
import numpy as np
import fcntl
import mmap

# フレームバッファのパス
FB_PATH = '/dev/fb1'

# フレームバッファの情報
WIDTH = 320
HEIGHT = 240
BPP = 2  # RGB565の場合、1ピクセルあたり2バイト

# 黄色のRGB565値を計算
# RGB888での黄色は (255, 255, 0)
# RGB565に変換: R(5bit)|G(6bit)|B(5bit)
YELLOW_RGB565 = ((31 << 11) | (63 << 5) | 0).to_bytes(2, byteorder='little')

# フレームバッファを開く
with open(FB_PATH, 'rb+') as fb:
    # メモリにマップ
    fb_memory = mmap.mmap(fb.fileno(), WIDTH * HEIGHT * BPP)

    # 黄色で塗りつぶす
    yellow_array = YELLOW_RGB565 * (WIDTH * HEIGHT)
    fb_memory.write(yellow_array)

    # 変更をフラッシュ
    fb_memory.flush()

print("Yellow color has been written to the framebuffer.")
0
0
1

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?