Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New component] HiFiBerry Sound Card & OnOff SHIM #2169

Merged
merged 59 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
6475eeb
Add components folder to installation and docs. First component is hi…
pabera Dec 19, 2023
6639015
Allow for all hifiberry boards
pabera Dec 19, 2023
9d709b7
Disabling HDMI Audio
pabera Dec 20, 2023
9621133
Finalize HiFiBerry doc
pabera Dec 20, 2023
8b31685
Refer to Pi Pinout for convenience
pabera Dec 20, 2023
e1dfb53
Enable ALSA config as an option as well
pabera Dec 20, 2023
8174d34
Allow script to be run multiple times
pabera Dec 20, 2023
6ce855c
Add OnOff SHIM as component
pabera Dec 21, 2023
701f8e3
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Dec 21, 2023
a62c036
Make script more robust based on PR comments
pabera Dec 25, 2023
0427214
Update hifiberry soundcard options
pabera Jan 1, 2024
c6df305
Automate soundcard detection for asound.conf
pabera Jan 1, 2024
bfaad30
use /boot/config based on debian version
pabera Jan 1, 2024
2cac674
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Jan 2, 2024
0da4d73
Reorganize a few things
pabera Jan 2, 2024
2aa6f47
some bugfixes
pabera Jan 2, 2024
e18189b
Final fixes
pabera Jan 2, 2024
9cebeaa
Optimize case
pabera Jan 2, 2024
348413c
Update docs
pabera Jan 2, 2024
99df470
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Jan 4, 2024
56cddb7
Uninstall option
pabera Jan 11, 2024
2cf5516
fix: Remove option was not reachable
pabera Jan 11, 2024
1679be2
fix: enable sudo
pabera Jan 11, 2024
240a938
fix: make I/O fail silently
pabera Jan 11, 2024
f3e0bb8
feat: Introduce 1-line installation
pabera Jan 12, 2024
0aa34ad
feat: outsource onboard_sound as its own option
pabera Jan 12, 2024
251224a
refactor: remove alsa config
pabera Jan 12, 2024
3abef5f
fix: update case function
pabera Jan 12, 2024
61aa460
fix: adding some thens
pabera Jan 12, 2024
ee0c47c
fix: some iterations did not work
pabera Jan 12, 2024
165e07e
fix: adding another sudo
pabera Jan 12, 2024
dc89268
refactor: get_key_by_item_number for associated arrays
pabera Jan 12, 2024
7758da6
refactor: remove last bits of alsa
pabera Jan 12, 2024
cda18f9
fix: final touches
pabera Jan 12, 2024
8e584b7
fix: add missing removal only option
pabera Jan 12, 2024
3740abb
fix: outsource example_usage for 1-line install
pabera Jan 12, 2024
35189e0
fix: condition for 1-line installation
pabera Jan 12, 2024
fd67e1e
fix: another fix for if conditions
pabera Jan 12, 2024
00e03ed
refactor: move 1-line installation down
pabera Jan 12, 2024
4ff95a1
gs
pabera Jan 12, 2024
2434315
another fix
pabera Jan 12, 2024
38797d2
fix: write array check differently
pabera Jan 12, 2024
cd31cf5
refactor: final touches
pabera Jan 12, 2024
8e0707f
feat: enable silent mode for check_existing_hifiberry
pabera Jan 12, 2024
b66c430
fix: reintroduce sudo check
pabera Jan 12, 2024
3e217cc
fix: documentation
pabera Jan 12, 2024
4aa34bf
fix: final touches again
pabera Jan 13, 2024
d1e2f58
fix: remove is_sudo again
pabera Jan 13, 2024
a43bafd
fix: Remove last sudo occurrences
pabera Jan 13, 2024
8e16955
fix: bullet proof
pabera Jan 14, 2024
8c96690
Make bash files executable
pabera Jan 14, 2024
b9f1ed6
fix: Update documentation
pabera Jan 14, 2024
66acd47
fix: 1-line path does not worj
pabera Jan 14, 2024
709f576
Update documentation/builders/components/soundcards/hifiberry.md
pabera Jan 15, 2024
09b6e48
Update documentation/builders/components/soundcards/hifiberry.md
pabera Jan 15, 2024
83b5d99
Update documentation/builders/components/soundcards/hifiberry.md
pabera Jan 15, 2024
94e9bcf
fix: Update regex for commented code
pabera Jan 16, 2024
daf396e
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera Jan 16, 2024
4cb9ffd
Adding OnOff Shim resource
pabera Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions documentation/builders/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
* [Card Database](./card-database.md)
* [Troubleshooting](./troubleshooting.md)

## Components
* [Power](./components/power/)
* [OnOff SHIM for safe power on/off](./components/power/onoff-shim.md)
* [Soundcards](./components/soundcards/)
* [HiFiBerry Boards](./components/soundcards/hifiberry.md)

## Advanced

* [Bluetooth (and audio buttons)](./bluetooth-audio-buttons.md)
Expand Down
34 changes: 34 additions & 0 deletions documentation/builders/components/power/onoff-shim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# OnOff SHIM by Pimorino

The OnOff SHIM from Pimorino allows you to savely start and shutdown your Raspberry Pi through a button. While you can switch of your Phoniebox via an RFID Card (through an RPC command), it is difficult to switch it on again without cutting the physical power supply.

## Installation

To install the software, open a terminal and type the following command to run the one-line-installer. A reboot will be required once the installation is finished.

> [!NOTE]
> The installation will ask you a few questions. You can safely answer with the default response.

```
curl https://get.pimoroni.com/onoffshim | bash
```

* [Source](https://shop.pimoroni.com/products/onoff-shim?variant=41102600138)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also add how to customize the shutdown command, so the Phoniebox shutdown is used (that's why I was working on pbc.c and run_rpc_tool.py).

I could add something tonight.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably, add it directly to this PR

## How to manually wire OnOff SHIM

The OnOff SHIM comes with a 12-PIN header which needs soldering. If you want to spare some GPIO pins for other purposes, you can individually wire the OnOff SHIM with the Raspberry Pi. Below you can find a table of Pins to be connected.
pabera marked this conversation as resolved.
Show resolved Hide resolved

| Board pin name | Board pin | Physical RPi pin | RPi pin name |
|----------------|-----------|------------------|--------------|
| 3.3V | 1 | 1, 17 | 3V3 power |
| 5V | 2 | 2 | 5V power |
| 5V | 4 | 4 | 5V power |
| GND | 6 | 6, 9, 20, 25 | Ground |
| GPLCLK0 | 7 | 7 | GPIO4 |
| GPIO17 | 11 | 11 | GPIO17 |

## Assembly options

![](https://cdn.review-images.pimoroni.com/upload-b6276a310ccfbeae93a2d13ec19ab83b-1617096824.jpg?width=640)

pabera marked this conversation as resolved.
Show resolved Hide resolved
49 changes: 49 additions & 0 deletions documentation/builders/components/soundcards/hifiberry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# HiFiBerry

The installation script works for the most common set of HiFiBerry boards but also other "DAC" related sound cards like `I2S PCM5102A DAC`.

## Automatic setup

Run the following command to install any HiFiBerry board. Make sure you reboot your device afterwards.

```
pabera marked this conversation as resolved.
Show resolved Hide resolved
cd ~/RPi-Jukebox-RFID/installation/components
./setup_hifiberry.sh
```

If you know you HifiBerry Board identifier, you can run the script as a 1-liner as well

```
pabera marked this conversation as resolved.
Show resolved Hide resolved
./setup_hifiberry.sh enable hifiberry-dac
```

If you like to disable your HiFiberry Sound card and enable onboard sound, run the following command


```
pabera marked this conversation as resolved.
Show resolved Hide resolved
./setup_hifiberry.sh disable
```

## Additional information

If you like to understand what's happening under the hood, feel free to check the [install script](../../../../installation/components/setup_hifiberry.sh).

The setup is based on [HiFiBerry's instructions](https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/).

## How to manually wire your HiFiBerry board

Most HiFiBerry boards come with 40-pin header that you can directly attach to your Pi. This idles many GPIO pins that may be required for other inputs to be attached (like GPIO buttons or RFID). You can also connect your HiFiBerry board separately. The following table show cases the pins required.

* [Raspberry Pi Pinout](https://github.com/raspberrypi/documentation/blob/develop/documentation/asciidoc/computers/os/using-gpio.adoc)

| Board pin name | Board pin | Physical RPi pin | RPi pin name |
|----------------|-----------|------------------|--------------|
| 3.3V | 1 | 1, 17 | 3V3 power |
| 5V | 2 | 2, 4 | 5V power |
| GND | 6 | 6, 9, 20, 25 | Ground |
| PCM_CLK | 12 | 12 | GPIO18 |
| PCM_FS | 36 | 36 | GPIO19 |
| PCM_DIN | 38 | 38 | GPIO20 |
| PCM_DOUT | 40 | 40 | GPIO21 |

You can find more information about manually wiring [here](https://forum-raspberrypi.de/forum/thread/44967-kein-ton-ueber-hifiberry-miniamp-am-rpi-4/?postID=401305#post401305).
2 changes: 1 addition & 1 deletion documentation/developers/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ need to adapt some of those commands to your needs.
## Prerequisites

1. Install required software: Docker, Compose and pulseaudio
* Check installations guide for [Mac](#mac), [Windows](#windows) or [Linux](#linux)
* Check installation guide for [Mac](#mac), [Windows](#windows) or [Linux](#linux)

2. Pull the Jukebox repository:

Expand Down
119 changes: 119 additions & 0 deletions installation/components/setup_hifiberry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env bash

# This script follows the official HiFiBerry documentation
# https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/

source ../includes/02_helpers.sh

script_name=$(basename "$0")
boot_config_path=$(get_boot_config_path)

declare -A hifiberry_map=(
["hifiberry-dac"]="DAC (HiFiBerry MiniAmp, I2S PCM5102A DAC)"
["hifiberry-dacplus"]="HiFiBerry DAC+ Standard/Pro/Amp2"
["hifiberry-dacplushd"]="HiFiBerry DAC2 HD"
["hifiberry-dacplusadc"]="HiFiBerry DAC+ ADC"
["hifiberry-dacplusadcpro"]="HiFiBerry DAC+ ADC Pro"
["hifiberry-digi"]="HiFiBerry Digi+"
["hifiberry-digi-pro"]="HiFiBerry Digi+ Pro"
["hifiberry-amp"]="HiFiBerry Amp+ (not Amp2)"
["hifiberry-amp3"]="HiFiBerry Amp3"
)

example_usage() {
for key in "${!hifiberry_map[@]}"; do
description="${hifiberry_map[$key]}"
echo "$key) $description"
done
echo "Example usage: ./${script_name} enable hifiberry-dac"
}

enable_hifiberry() {
echo "Enabling HiFiBerry board..."
grep -qxF "dtoverlay=$1" "$boot_config_path" || echo "dtoverlay=$1" | sudo tee -a "$boot_config_path" > /dev/null
pabera marked this conversation as resolved.
Show resolved Hide resolved
./../options/onboard_sound.sh disable
}

disable_hifiberry() {
echo "Removing existing HiFiBerry configuration..."
sudo sed -i '/dtoverlay=hifiberry-/d' "$boot_config_path"
pabera marked this conversation as resolved.
Show resolved Hide resolved
./../options/onboard_sound.sh enable
}

check_existing_hifiberry() {
existing_config=$(grep 'dtoverlay=hifiberry-' "$boot_config_path")
pabera marked this conversation as resolved.
Show resolved Hide resolved
if [ ! -z "$existing_config" ]; then
if [ "$1" = "silent" ]; then
disable_hifiberry
return 0
fi

echo "Existing HiFiBerry configuration detected: $existing_config"
read -p "Do you want to proceed with a new configuration? This will remove the existing one. (Y/n): " choice
case $choice in
[nN][oO]|[nN])
echo "Exiting without making changes.";
exit;;
*)
disable_hifiberry;
return 0;;
esac
fi
}

# 1-line installation
if [ $# -ge 1 ]; then
if [[ "$1" != "enable" && "$1" != "disable" ]] || [[ "$1" == "enable" && -z "$2" ]]; then
echo "Error: Invalid arguments provided.
Usage: ./${script_name} <status> <hifiberry-board>
where <status> can be 'enable' or 'disable'.

The following board options exist:"
example_usage
exit 1
fi

if [ "$1" == "enable" ]; then
if [[ -v hifiberry_map["$2"] ]]; then
check_existing_hifiberry "silent"
enable_hifiberry "$2"
exit 1
fi

echo "'$2' is not a valid option. You can choose from:"
example_usage
exit 1
fi

disable_hifiberry
exit 1
fi

# Guided installation
board_count=${#hifiberry_map[@]}
counter=1

echo "Select your HiFiBerry board:"
for key in "${!hifiberry_map[@]}"; do
description="${hifiberry_map[$key]}"
echo "$counter) $description"
((counter++))
done
echo "0) Remove existing HiFiBerry configuration"

read -p "Enter your choice (0-$board_count): " choice
case $choice in
[0])
disable_hifiberry;
;;
[1-$board_count])
selected_board=$(get_key_by_item_number hifiberry_map "$choice")
check_existing_hifiberry
enable_hifiberry "$selected_board";
;;
*)
echo "Invalid selection. Exiting.";
exit 1;;
esac

echo "Configuration complete. Please restart your device."
70 changes: 58 additions & 12 deletions installation/includes/02_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

### Helpers

# Get key by item number of associated array
get_key_by_item_number() {
local -n array="$1"
local item_number="$2"
local count=0

for key in "${!array[@]}"; do
((count++))
if [ "$count" -eq "$item_number" ]; then
echo "$key"
return
fi
done
}

# $1->start, $2->end
calc_runtime_and_print() {
runtime=$(($2-$1))
Expand Down Expand Up @@ -35,18 +50,49 @@ run_with_log_frame() {
}

get_architecture() {
local arch=""
if [ "$(uname -m)" = "armv7l" ]; then
arch="armv7"
elif [ "$(uname -m)" = "armv6l" ]; then
arch="armv6"
elif [ "$(uname -m)" = "aarch64" ]; then
arch="arm64"
else
arch="$(uname -m)"
fi

echo $arch
local arch=""
if [ "$(uname -m)" = "armv7l" ]; then
arch="armv7"
elif [ "$(uname -m)" = "armv6l" ]; then
arch="armv6"
elif [ "$(uname -m)" = "aarch64" ]; then
arch="arm64"
else
arch="$(uname -m)"
fi

echo $arch
}

is_raspian() {
if [[ $( . /etc/os-release; printf '%s\n' "$ID"; ) == *"raspbian"* ]]; then
echo true
else
echo false
fi
}

get_debian_version_number() {
source /etc/os-release
echo "$VERSION_ID"
}

get_boot_config_path() {
if [ "$(is_raspian)" = true ]; then
local debian_version_number=$(get_debian_version_number)

# Bullseye and lower
if [ "$debian_version_number" -le 11 ]; then
echo "/boot/config.txt"
# Bookworm and higher
elif [ "$debian_version_number" -ge 12 ]; then
echo "/boot/firmware/config.txt"
else
echo "unknown"
fi
else
echo "unknown"
fi
}

validate_url() {
Expand Down
27 changes: 27 additions & 0 deletions installation/options/onboard_sound.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
source ../includes/02_helpers.sh
script_name=$(basename "$0")
boot_config_path=$(get_boot_config_path)

if [ -z "$1" ] || { [ "$1" != "enable" ] && [ "$1" != "disable" ]; }; then
echo "Error: Invalid or no argument provided.
Usage: ./${script_name} <arg>
where <arg> can be 'enable' or 'disable'"
exit 1
fi

arg="$1"

if [ "$arg" = "enable" ]; then
echo "Enabling Onboard Sound..."
sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(off\|false\|no\|0\)\(.*\)/\1audio=on\4/g" "$boot_config_path"
sudo sed -i '/dtoverlay=vc4-fkms-v3d,audio=off/c\dtoverlay=vc4-fkms-v3d' "$boot_config_path"
sudo sed -i '/dtoverlay=vc4-kms-v3d,noaudio/c\dtoverlay=vc4-kms-v3d' "$boot_config_path"
elif [ "$arg" = "disable" ]; then
echo "Disabling Onboard Sound..."
sudo sed -i "s/^\(dtparam=\([^,]*,\)*\)audio=\(on\|true\|yes\|1\)\(.*\)/\1audio=off\4/g" "$boot_config_path"
pabera marked this conversation as resolved.
Show resolved Hide resolved
sudo sed -i '/dtoverlay=vc4-fkms-v3d/c\dtoverlay=vc4-fkms-v3d,audio=off' "$boot_config_path"
sudo sed -i '/dtoverlay=vc4-kms-v3d/c\dtoverlay=vc4-kms-v3d,noaudio' "$boot_config_path"
fi
s-martin marked this conversation as resolved.
Show resolved Hide resolved
pabera marked this conversation as resolved.
Show resolved Hide resolved

# TODO Test
AlvinSchiller marked this conversation as resolved.
Show resolved Hide resolved