diff --git a/README.md b/README.md index bb78fd5..f5a2994 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,51 @@ # RaspberryPiMouse -![CI](https://github.com/rt-net/RaspberryPiMouse/workflows/CI/badge.svg?branch=master) +[![CI](https://github.com/rt-net/RaspberryPiMouse/actions/workflows/driver-cross-build.yml/badge.svg)](https://github.com/rt-net/RaspberryPiMouse/actions/workflows/driver-cross-build.yml) This repository has the source code and kernel objects for the Raspberry Pi Mouse. ## Installation -Run the installation script ([`./utils/build_install.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/build_install.bash)). +Run the following scripts. -インストール用のシェルスクリプト([`./utils/build_install.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/build_install.bash))を実行します。 +- setting script ([`./utils/set_configs.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/set_configs.bash)) +- installation script ([`./utils/build_install.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/build_install.bash)) -### for Raspberry Pi OS - -`/boot/firmware/config.txt`を編集し、ファイル末尾に以下の設定を追加します。 - -```sh -arm_64bit=0 # "64-bit"版では不要です -dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000 # カーネル5.16未満の場合は不要です -dtparam=i2c_baudrate=62500 -``` +以下のスクリプトを実行します +- setting script([`./utils/set_configs.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/set_configs.bash)) +- installation script([`./utils/build_install.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/build_install.bash)) -Raspberry Piを再起動します。 +### for `Raspberry Pi OS`・`Ubuntu` -以下のコマンドでインストールを実行します。 +以下のコマンドで本リポジトリをダウンロードし、Raspberry Pi本体の設定を行います。 -```sh +```bash $ git clone https://github.com/rt-net/RaspberryPiMouse.git $ cd RaspberryPiMouse/utils -$ sudo apt install raspberrypi-kernel-headers build-essential -$ ./build_install.bash +$ ./set_configs.bash ``` -### for Ubuntu +Raspberry Piを再起動し、以下のコマンドを実行してビルドに必要なファイルをインストールします。**`Ubuntu`と`Raspberry Pi OS`でコマンドが違います。** -`/boot/firmware/config.txt`を編集し、ファイル末尾に以下の設定を追加します。 +```bash +# Ubuntu Serverの場合 +$ sudo apt install linux-headers-$(uname -r) build-essential -```sh -dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000 # "Ubuntu Server 22.04"では不要です -dtparam=i2c_baudrate=62500 +# Raspberry Pi OSの場合 +$ sudo apt install raspberrypi-kernel-headers build-essential ``` -Raspberry Piを再起動します。 +以下のコマンドでビルドを実行します。 -以下のコマンドでインストールを実行します。 - -```sh -$ git clone https://github.com/rt-net/RaspberryPiMouse.git +```bash $ cd RaspberryPiMouse/utils -$ sudo apt install linux-headers-$(uname -r) build-essential $ ./build_install.bash ``` ### Manual installation -```sh +```bash $ git clone https://github.com/rt-net/RaspberryPiMouse.git $ cd RaspberryPiMouse/src/drivers $ make @@ -63,23 +54,31 @@ $ sudo insmod rtmouse.ko ## Notes for the installation (ドライバの導入の際の注意) +特定の機能の有効化や、プログラムのビルドのために設定が必要な項目があります。以下の設定をご確認ください。 + +※[`./utils/set_configs.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/set_configs.bash)を実行すると、[自動で適切な設定に書き換わります]((https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/set_configs.bash))。 + + ### for Raspberry Pi OS +Raspberry Pi OSでは、SPIとI2Cがデフォルトで無効となっているため、有効化する必要があります。 + +#### for SPI and I2C + Enable SPI and I2C functions via `raspi-config` command. -以下の設定を確認ください。 `raspi-config` コマンドで設定します。 * SPI機能を「入」にする。 * I2C機能を「入」にする。 - ### for Raspberry Pi 4 -Edit [`rtmouse.c`](https://github.com/rt-net/RaspberryPiMouse/blob/dd0343449951a99b067e24aef3c03ae5ed9ab936/src/drivers/rtmouse.c#L54) to change the defined value `RASPBERRYPI` from '2' to '4'. +Edit [`rtmouse.c`](https://github.com/rt-net/RaspberryPiMouse/blob/dd0343449951a99b067e24aef3c03ae5ed9ab936/src/drivers/rtmouse.c#L54) to change the defined value `RASPBERRYPI` from`2`to`4`. Raspberry Pi 4ではCPUのレジスタがそれまでのRaspberry Piとは異なります([issues#21](https://github.com/rt-net/RaspberryPiMouse/issues/21))。 Raspberry Pi 4で本ドライバを使用する際には`rtmouse.c`の以下の行(2020年4月13日現在の最新版のv2.1.0では[54行目](https://github.com/rt-net/RaspberryPiMouse/blob/dd0343449951a99b067e24aef3c03ae5ed9ab936/src/drivers/rtmouse.c#L54))を`RASPBERRYPI 4`に書き換えてビルドする必要があります。 + ※[`./utils/build_install.bash`](./utils/build_install.bash)を実行すると、Raspberry Piのモデルに合わせて[`rtmouse.c`](./src/drivers/rtmouse.c)が[自動で書き換わります](https://github.com/rt-net/RaspberryPiMouse/blob/a9af4fa2b2a8e34c0f93a6ce5cf88ebd50ff39c2/utils/build_install.raspi4ubuntu.bash#L13-L14)。 ```c @@ -91,6 +90,24 @@ Raspberry Pi 4で本ドライバを使用する際には`rtmouse.c`の以下の #define RASPBERRYPI 2 ``` +### for 32-bit OS + +Set 32bit-setting to `/boot/firmware/config.txt`. + +32-bit版のOSではビルドするために、`/boot/firmware/config.txt`に以下の1行を追加する必要があります。 + +```bash +arm_64bit=0 +``` + +### デバイスツリーオーバーレイについて + +kernel `5.16`以降では`/boot/firmware/config.txt`に以下の設定を記述し、dtoverlayを設定する必要があります。※[`./utils/set_configs.bash`](https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/set_configs.bash)を実行すると、設定は[自動で書き換わります]((https://github.com/rt-net/RaspberryPiMouse/blob/master/utils/set_configs.bash#L35-#L49))。 + +```bash +dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000 +``` + ### パルスカウンタについて パルスカウンタは値の読み取りにI2Cを使用しています。仕様上は400kHzまでbaudrateを上げることができます(※1)。 @@ -102,9 +119,11 @@ it may be necessary to set the I2C baudrate lower than the default value. Add a following new line in `/boot/firmware/config.txt` to change the i2c_baudrate to 62.5 kHz. `/boot/firmware/config.txt`に以下の1行を追加することでI2Cのbaudrateを62.5kHzに固定することができます。 -``` + +```bash dtparam=i2c_baudrate=62500 ``` + ※1 Raspberry Pi 4 Model B(Ubuntu Server `18.04` / `20.04` / `22.04` / `24.04`)を搭載して400kHzで通信できることを確認しています。 ※2 現在設定されているI2Cのbaudrateは以下のコマンドを実行することで確認できます。 ``` diff --git a/utils/set_configs.bash b/utils/set_configs.bash new file mode 100755 index 0000000..47a8d29 --- /dev/null +++ b/utils/set_configs.bash @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +set -eu + +# settings comment +SETTING_COMMENT='# Raspberry Pi Mouse V3 settings' + +# OS architecture (32-bit or 64-bit) +ARCHITECTURE=$(getconf LONG_BIT) + +# dtoverlay setting +DTOVERLAY='dtoverlay=anyspi:spi0-0,dev="microchip,mcp3204",speed=1000000' + +# i2c_baudrate-setting +DTPARAM='dtparam=i2c_baudrate=62500' + +# config-file PATH +CONFIG_FILE='/boot/firmware/config.txt' + +# compare kernel versions as integers for accurate version comparison (excluding minor versions). +GET_KERNEL_VERSION_INT() { + # 0-padding is used to avoid minor versions being compared by their first digit. + echo "$1" | awk -F. '{ printf "%d%02d", $1, $2 }' +} + +# kernel version +KERNEL_VERSION=$(uname -r | cut -d'-' -f1) +KERNEL_VERSION_INT=$(GET_KERNEL_VERSION_INT "$KERNEL_VERSION") + +# add "Raspberry Pi Mouse v3" settings +if ! grep -qxF "$SETTING_COMMENT" "$CONFIG_FILE"; then + echo "$SETTING_COMMENT" | sudo tee -a "$CONFIG_FILE" > /dev/null +fi + +# check if the OS is running in 32-bit mode +if [[ "$ARCHITECTURE" == "32" ]]; then + if ! grep -qxF "arm_64bit=0" "$CONFIG_FILE"; then + echo "arm_64bit=0" | sudo tee -a "$CONFIG_FILE" + echo "Add \"arm_64bit=0\" > $CONFIG_FILE" + fi +elif [[ "$ARCHITECTURE" == "64" ]]; then + # remove arm_64bit=0 if present in a 64-bit environment + if grep -qxF "arm_64bit=0" "$CONFIG_FILE"; then + sudo sed -i '/arm_64bit=0/d' "$CONFIG_FILE" + echo "Removed \"arm_64bit=0\" from $CONFIG_FILE" + fi +fi + +# add dtparam-setting for "/boot/firmware/config.txt" +if ! grep -qxF "$DTPARAM" "$CONFIG_FILE"; then + echo "$DTPARAM" | sudo tee -a "$CONFIG_FILE" > /dev/null + echo "Add \"$DTPARAM\" > $CONFIG_FILE" +fi + +# use device-tree-overlay when the kernel is 5.16 or higher +if (( KERNEL_VERSION_INT >= $(GET_KERNEL_VERSION_INT 5.16) )); then + # add dtoverlay-setting for "/boot/firmware/config.txt" + if ! grep -qxF "$DTOVERLAY" "$CONFIG_FILE"; then + echo "$DTOVERLAY" | sudo tee -a "$CONFIG_FILE" > /dev/null + echo "Add \"$DTOVERLAY\" > $CONFIG_FILE" + fi +else + # remove dtoverlay-setting if kernel is less than 5.16 + if grep -qxF "$DTOVERLAY" "$CONFIG_FILE"; then + sudo sed -i "/$DTOVERLAY/d" "$CONFIG_FILE" + echo "Removed \"$DTOVERLAY\" from $CONFIG_FILE" + fi +fi + +# replace "dtparam=i2c_arm=off" with "dtparam=i2c_arm=on" +if grep -qxF 'dtparam=i2c_arm=off' "$CONFIG_FILE"; then + sudo sed -i 's/dtparam=i2c_arm=off/dtparam=i2c_arm=on/' "$CONFIG_FILE" + echo "Changed \"dtparam=i2c_arm=off\" to \"dtparam=i2c_arm=on\" in $CONFIG_FILE" +fi + +# replace "dtparam=spi=off" with "dtparam=spi=on" +if grep -qxF 'dtparam=spi=off' "$CONFIG_FILE"; then + sudo sed -i 's/dtparam=spi=off/dtparam=spi=on/' "$CONFIG_FILE" + echo "Changed \"dtparam=spi=off\" to \"dtparam=spi=on\" in $CONFIG_FILE" +fi + +# uncomment "dtparam=i2c_arm=on" if it is commented +if grep -qxF '#dtparam=i2c_arm=on' "$CONFIG_FILE"; then + sudo sed -i 's/#dtparam=i2c_arm=on/dtparam=i2c_arm=on/' "$CONFIG_FILE" + echo "Uncommented \"dtparam=i2c_arm=on\" in $CONFIG_FILE" +fi + +# uncomment "dtparam=spi=on" if it is commented +if grep -qxF '#dtparam=spi=on' "$CONFIG_FILE"; then + sudo sed -i 's/#dtparam=spi=on/dtparam=spi=on/' "$CONFIG_FILE" + echo "Uncommented \"dtparam=spi=on\" in $CONFIG_FILE" +fi pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy