Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2021 17:53
Show Gist options
  • Save vitorio/25282c8e0f11e75875349d7cc6217bc5 to your computer and use it in GitHub Desktop.
Save vitorio/25282c8e0f11e75875349d7cc6217bc5 to your computer and use it in GitHub Desktop.
Sawtooth Power Mac G4 Raspberry Pi 4 case configuration files v1

Okay, here's where we've landed for v1:

  • Power button
    • Wired to GPIO3, the default for gpio-shutdown
    • When pressed, does a safe shutdown
  • Green power LED
    • Wired to GPIO23
    • Lights up green when the RPi powers on
  • Reset button
    • Wired to RUN using a test point pin
    • Hard resets the Pi
    • Also boots the Pi if a safe shutdown was performed but power is still present
  • Programmer's button
    • Wired to GPIO22
    • Available for programmatic use
  • Yellow sleep LED
    • Wired to GPIO24
    • Available for programmatic use
  • Front speaker
    • Connected to amp left channel, amp connected to TRRS jack
    • "frontspeaker" composite mono ALSA device available
    • "Front Speaker Output" mono PulseAudio device available, selectable for "AV Jack" in LXDE PulseAudio volume control widget
    • Plays Power Mac G4 startup sound on boot (after Linux initializes the sound device, which is actually pretty late in the boot process)
  • DVD drive
    • Connected to USB 3.0 port
    • Reports as Bus 02.Port 2: Dev 3, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
  • Zip disk slot
    • Replaced with SSD bay
    • Connected to USB 3.0 port
    • Reports as Bus 02.Port 1: Dev 2, If 0, Class=Mass Storage, Driver=uas, 5000M
  • PSU
    • Connected to ATX PSU switch to control power
    • Powering the RPi4 from a molex connector 5V line to USB-C
      • Power appears stable while running sysbench
    • Powering the amp from a molex connector 5V line to bare wires

Here's the software configuration:

  • /opt/4.wav
  • /etc/asound.conf
  • /etc/systemd/system/bootsound.service
  • /home/pi/ (for testing the programmer's button and yellow LED)
  • /boot/config.txt
  • /usr/share/pulseaudio/alsa-mixer/profile-sets/sawtoothg4-frontspeaker.conf
  • /etc/udev/rules.d/91-pulseaudio-rpi.rules (this is a copy of /lib/udev/rules.d/91-pulseaudio-rpi.rules to override it)


  • Plug the old I/O ports
  • Bring out the two USB 2.0 jacks
  • Bring out the two HDMI jacks
  • Bring out the ethernet jack
  • Bring out the ATX PSU switch, although this will go away in a v2


pi@rpi4sawtooth:~ $ cat /etc/asound.conf
pcm.card1 {
  type hw
  card 1

ctl.card1 {
  type hw
  card 1

pcm.frontspeaker {
  slave.pcm card1
  slave.channels 2
#  type plug
  type route
  ttable {
    # Copy both input channels to output channel 0 (Left).
    0.0 0.5
    1.0 0.5
    # Send nothing to output channel 1 (Right).
    0.1 0
    1.1 0

ctl.frontspeaker {
  type hw
  card 1

#pcm.!default monocard
pi@rpi4sawtooth:~ $ cat /etc/systemd/system/bootsound.service
Description=Boot Sound

ExecStart=/usr/bin/aplay /opt/4.wav -D frontspeaker -q

pi@rpi4sawtooth:~ $ cat /home/pi/sawtoothg4/
#!/usr/bin/env python3
import gpiozero
import signal

# Run as root to output to the HDMI display, otherwise will output locally
hdmi = None
    hdmi = open("/dev/console", "w")

def hello_programmers():
    print("Programmer's button", file=hdmi)

programmers = gpiozero.Button(22)
yellow = gpiozero.LED(24)

programmers.when_pressed = hello_programmers

pi@rpi4sawtooth:~ $ tail /boot/config.txt

# Enable DRM VC4 V3D driver on top of the dispmanx display stack

pi@rpi4sawtooth:~ $ cat /usr/share/pulseaudio/alsa-mixer/profile-sets/sawtoothg4-frontspeaker.conf
auto-profiles = yes

[Mapping front-speaker]
description = Front Speaker
device-strings = hw:%f
fallback = yes
priority = 1
direction = output
channel-map = mono,mono
paths-output = analog-output
pi@rpi4sawtooth:~ $ cat /etc/udev/rules.d/91-pulseaudio-rpi.rules
SUBSYSTEM!="sound*", GOTO="end"
ACTION!="change", GOTO="end"
KERNEL!="card*", GOTO="end"
ENV{SOUND_FORM_FACTOR}!="internal", GOTO="end"

DRIVERS=="bcm2835_audio", ATTR{id}=="b1", ENV{PULSE_PROFILE_SET}="rpi-hdmi.conf", GOTO="end"
DRIVERS=="bcm2835_audio", ATTR{id}=="b2", ENV{PULSE_PROFILE_SET}="rpi-hdmi.conf", GOTO="end"
DRIVERS=="bcm2835_audio", ATTR{id}=="Headphones", ENV{PULSE_PROFILE_SET}="sawtoothg4-frontspeaker.conf", GOTO="end"

pi@rpi4sawtooth:~ $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment