GAMEPI20に純なLinux(RaspberryPi OS)を入れる

基本的な情報源

https://github.com/darrenliew96/gamepi20_drivers

MicroSDカードにRaspberryPi OS を焼く

RasPi ImagerでカードにOSを焼く
Updateする

sudo apt update
sudo apt full-upgrade
audo apt dist-update
$ uname -a
Linux raspberrypi 5.10.63+ #1459 Wed Oct 6 16:40:27 BST 2021 armv6l GNU/Linux

GAMEPI20ドライバ

gamepi20.dtsを作る

$ nano gamepi20.dts

/dts-v1/;
/plugin/;

/ {
        compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

        fragment@0 {
                target = <&spi0>;
                __overlay__ {
                        status = "okay";

                        spidev@0{
                                status = "disabled";
                        };

                        spidev@1{
                                status = "disabled";
                        };
                };
        };

        fragment@1 {
                target = <&gpio>;
                __overlay__ {
                        gamepi20_pins: gamepi20 {
                                brcm,pins = <25 27 >;
                                brcm,function = <1 1>; /* out */
                                brcm,pull = <0>; /* none */
                        };
                };
        };

        fragment@2 {
                target = <&spi0>;
                __overlay__ {
                        /* needed to avoid dtc warning */
                        #address-cells = <1>;
                        #size-cells = <0>;

                        gamepi20: gamepi20@0{
                               compatible = "sitronix,st7789v";
                               reg = <0>;
                               pinctrl-names = "default";
                               pinctrl-0 = <&gamepi20_pins>;
                               
                               spi-max-frequency = <96000000>;
                               
                               rotate = <90>;
                               width = <240>;
                               height = <320>;
                               fps = <60>;
                               buswidth = <8>;
                               spi-cpol;
                               spi-cpha;
                               custom = <1>;
                               bgr;
                               
                               reset-gpios = <&gpio 27 1>;
                               dc-gpios = <&gpio 25 0>;
                               led-gpios = <&gpio 24 1>;
                               /*cs-gpios = <&gpio 8 0>;*/
                               
                               debug = <0>;
                               
                               init = <0x1000011
                                       0x20000ff
                                       0x1000036 0xA0
                                       0x100003a 0x05
                                       0x1000021 
                                       0x100002a 0x00 0x01 0x00 0x3f
                                       0x100002b 0x00 0x00 0x00 0xef
                                       0x10000b2 0x0c 0x0c 0x00 0x33 0x33
                                       0x10000b7 0x35
                                       0x10000bb 0x1f
                                       0x10000c0 0x0c
                                       0x10000c2 0x01
                                       0x10000c3 0x12
                                       0x10000c4 0x20
                                       0x10000c6 0x0f
                                       0x10000d0 0xa4 0xa1
                                       0x10000e0 0xd0 0x08 0x11 0x08 0x0C 0x15 0x39 0x33 0x50 0x36 0x13 0x14 0x29 0x2d
                                       0x10000e1 0xd0 0x08 0x10 0x08 0x06 0x06 0x39 0x44 0x51 0x0b 0x16 0x14 0x2f 0x31
                                       0x1000029>;
                        };
                };
        };


        __overrides__ {
                speed =   <&gamepi20>,"spi-max-frequency:0";
                rotate =  <&gamepi20>,"rotate:0";
                width =   <&gamepi20>,"width:0";
                height =  <&gamepi20>,"height:0";
                fps =     <&gamepi20>,"fps:0";
                debug =   <&gamepi20>,"debug:0";
        };
};

元ネタの https://github.com/darrenliew96/gamepi20_drivers にあるファイルから一部修正してある。
具体的には、

修正前 led-gpios = <&gpio 24 0>;
修正後 led-gpios = <&gpio 24 1>;

gamepi20.dtsを登録する

$ sudo dtc -@ -I dts -O dtb -o /boot/overlays/gamepi20.dtbo gamepi20.dts

config.txtを編集

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on
#dtoverlay=i2c-dev=spi_bcm2835

# Automatically load overlays for detected cameras
camera_auto_detect=0
#無効にしておく

# Automatically load overlays for detected DSI displays
display_auto_detect=0
#無効にしておく
 
# Enable DRM VC4 V3D driver
#dtoverlay=vc4-kms-v3d
#max_framebuffers=2
#無効にしておく

# Disable compensation for displays with overscan
disable_overscan=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
#otg_mode=1
#無効にしておく

[all]
#dtoverlay=pi3-disable-bt
#dtoverlay=pi3-miniuart-bt
#enable_uart=1
#GAMEPI20のディスプレイドライバ指定
dtoverlay=gamepi20
#画面解像度を適当に小さくしておく(HDMIはVGAの60fps GAMEPI20は320x240)
hdmi_force_hotplug=1
hdmi_cvt=640 480 60 1 0 0 0
hdmi_group=2
hdmi_mode=1
hdmi_mode=87
audio_pwm_mode=2
dtoverlay=audremap,pins_18_19

fbcpを作る

sudo apt-get install cmake git
cd ~
git clone https://github.com/tasanakorn/rpi-fbcp
cd rpi-fbcp/
mkdir build
cd build/
cmake ..
make
sudo install fbcp /usr/local/bin/fbcp

フレームバッファー間のコピーを行うコマンド。
プライマリディスプレイのフレームバッファの内容をセカンダリディスプレイのフレームバッファにコピーする。
つまり、ミラーリング。

/etc/modulesに追記

sudo nano /etc/modulesに追記
i2c-dev
spi-bcm2835 
flexfb
fbtft_device

fbtft.conf fileを作る(2行)

sudo nano /etc/modprobe.d/fbtft.conf
options fbtft_device name=flexfb gpios=reset:27,dc:25,cs:8,led:24 speed=96000000 bgr=1 fps=60 custom=1 height=240 width=320
options flexfb setaddrwin=0 width=320 height=240 init=-1,0x11,-2,120,-1,0x36,0xA0,-1,0x3A,0x05,-1,0x21,-1,0x2A,0x00,0x01,0x00,0x3F,-1,0x2B,0x00,0x00,0x00,0xEF,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1F,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x12,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0xE0,0xD0,0x08,0x11,0x08,0x0C,0x15,0x39,0x33,0x50,0x36,0x13,0x14,0x29,0x2D,-1,0xE1,0xD0,0x08,0x10,0x08,0x06,0x06,0x39,0x44,0x51,0x0B,0x16,0x14,0x2F,0x31,-1,0x29,-3

/etc/rc.localを編集

fbcp &
exit 0

各キーのGPIO割り当て

キーBCM No.
 ↑12
  →13
←  21
 ↓20
SELECT16
START26
 Y17
  X22
23
 B4
5
  R6
 L             R
      ┌────┐
 ↑    │    │    Y
← →   │    │   X B
 ↓    │    │    A
      └────┘

   SELECT      START

GAMEPI20.png

pythonでボタンを読む

#!/usr/bin/python3

import RPi.GPIO as GPIO
import time
import sys

#ポート番号の定義
SW_U = 12
SW_D = 20
SW_L = 21
SW_R = 13
SW_A = 23
SW_B = 4
SW_X = 22
SW_Y = 17
SW_L2 = 5
SW_R2 = 6
SW_SEL = 16
SW_STA = 26

#GPIOの設定
GPIO.setmode(GPIO.BCM)

#GPIOを入力モードに設定してプルダウン抵抗を有効にする
GPIO.setup(SW_U, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_D, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_L, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_R, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_A, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_B, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_X, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_Y, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_L2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_R2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_SEL, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(SW_STA, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
        try:
                if(GPIO.input(SW_U) == 0):
                        print("UP")
                elif(GPIO.input(SW_D) == 0):
                        print("DOWN")
                elif(GPIO.input(SW_L) == 0):
                        print("LEFT")
                elif(GPIO.input(SW_R) == 0):
                        print("RIGHT")
                elif(GPIO.input(SW_A) == 0):
                        print("A")
                elif(GPIO.input(SW_B) == 0):
                        print("B")
                elif(GPIO.input(SW_X) == 0):
                        print("X")
                elif(GPIO.input(SW_Y) == 0):
                        print("Y")
                elif(GPIO.input(SW_L2) == 0):
                        print("L-BACK")
                elif(GPIO.input(SW_R2) == 0):
                        print("R-BACK")
                elif(GPIO.input(SW_SEL) == 0):
                        print("SELECT")
                elif(GPIO.input(SW_STA) == 0):
                        print("START")
                time.sleep(0.1)         #0.1秒間待つ
        except KeyboardInterrupt:       #Ctrl+Cキーが押された
                GPIO.cleanup()          #GPIOをクリーンアップ
                sys.exit()

添付ファイル: fileGAMEPI20.png 136件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-11-27 (月) 23:39:34