-
Notifications
You must be signed in to change notification settings - Fork 400
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
pabera
merged 59 commits into
MiczFlor:future3/develop
from
pabera:future3/hifiberry-doc
Jan 16, 2024
Merged
Changes from all 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 6639015
Allow for all hifiberry boards
pabera 9d709b7
Disabling HDMI Audio
pabera 9621133
Finalize HiFiBerry doc
pabera 8b31685
Refer to Pi Pinout for convenience
pabera e1dfb53
Enable ALSA config as an option as well
pabera 8174d34
Allow script to be run multiple times
pabera 6ce855c
Add OnOff SHIM as component
pabera 701f8e3
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera a62c036
Make script more robust based on PR comments
pabera 0427214
Update hifiberry soundcard options
pabera c6df305
Automate soundcard detection for asound.conf
pabera bfaad30
use /boot/config based on debian version
pabera 2cac674
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera 0da4d73
Reorganize a few things
pabera 2aa6f47
some bugfixes
pabera e18189b
Final fixes
pabera 9cebeaa
Optimize case
pabera 348413c
Update docs
pabera 99df470
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera 56cddb7
Uninstall option
pabera 2cf5516
fix: Remove option was not reachable
pabera 1679be2
fix: enable sudo
pabera 240a938
fix: make I/O fail silently
pabera f3e0bb8
feat: Introduce 1-line installation
pabera 0aa34ad
feat: outsource onboard_sound as its own option
pabera 251224a
refactor: remove alsa config
pabera 3abef5f
fix: update case function
pabera 61aa460
fix: adding some thens
pabera ee0c47c
fix: some iterations did not work
pabera 165e07e
fix: adding another sudo
pabera dc89268
refactor: get_key_by_item_number for associated arrays
pabera 7758da6
refactor: remove last bits of alsa
pabera cda18f9
fix: final touches
pabera 8e584b7
fix: add missing removal only option
pabera 3740abb
fix: outsource example_usage for 1-line install
pabera 35189e0
fix: condition for 1-line installation
pabera fd67e1e
fix: another fix for if conditions
pabera 00e03ed
refactor: move 1-line installation down
pabera 4ff95a1
gs
pabera 2434315
another fix
pabera 38797d2
fix: write array check differently
pabera cd31cf5
refactor: final touches
pabera 8e0707f
feat: enable silent mode for check_existing_hifiberry
pabera b66c430
fix: reintroduce sudo check
pabera 3e217cc
fix: documentation
pabera 4aa34bf
fix: final touches again
pabera d1e2f58
fix: remove is_sudo again
pabera a43bafd
fix: Remove last sudo occurrences
pabera 8e16955
fix: bullet proof
pabera 8c96690
Make bash files executable
pabera b9f1ed6
fix: Update documentation
pabera 66acd47
fix: 1-line path does not worj
pabera 709f576
Update documentation/builders/components/soundcards/hifiberry.md
pabera 09b6e48
Update documentation/builders/components/soundcards/hifiberry.md
pabera 83b5d99
Update documentation/builders/components/soundcards/hifiberry.md
pabera 94e9bcf
fix: Update regex for commented code
pabera daf396e
Merge branch 'future3/develop' into future3/hifiberry-doc
pabera 4cb9ffd
Adding OnOff Shim resource
pabera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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) | ||
|
||
## 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 | | ||
|
||
* More information can be found here: https://pinout.xyz/pinout/onoff_shim | ||
|
||
## Assembly options | ||
|
||
![](https://cdn.review-images.pimoroni.com/upload-b6276a310ccfbeae93a2d13ec19ab83b-1617096824.jpg?width=640) | ||
|
||
pabera marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
```bash | ||
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 | ||
|
||
```bash | ||
./setup_hifiberry.sh enable hifiberry-dac | ||
``` | ||
|
||
If you like to disable your HiFiberry Sound card and enable onboard sound, run the following command | ||
|
||
|
||
```bash | ||
./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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
./../options/onboard_sound.sh disable | ||
} | ||
|
||
disable_hifiberry() { | ||
echo "Removing existing HiFiBerry configuration..." | ||
sudo sed -i '/^dtoverlay=hifiberry-/d' "$boot_config_path" | ||
./../options/onboard_sound.sh enable | ||
} | ||
|
||
check_existing_hifiberry() { | ||
existing_config=$(grep '^dtoverlay=hifiberry-' "$boot_config_path") | ||
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/{s/,audio=off//g;}' "$boot_config_path" | ||
sudo sed -i '/^dtoverlay=vc4-kms-v3d/{s/,noaudio//g;}' "$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/{s/,audio=off//g;s/$/,audio=off/g;}' "$boot_config_path" | ||
sudo sed -i '/^dtoverlay=vc4-kms-v3d/{s/,noaudio//g;s/$/,noaudio/g;}' "$boot_config_path" | ||
fi | ||
s-martin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# TODO Test | ||
AlvinSchiller marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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