Skip to content

Convert install_wm8960.sh to Python#398

Merged
makermelissa merged 3 commits into
adafruit:mainfrom
makermelissa-piclaw:convert-install-wm8960
Jun 16, 2026
Merged

Convert install_wm8960.sh to Python#398
makermelissa merged 3 commits into
adafruit:mainfrom
makermelissa-piclaw:convert-install-wm8960

Conversation

@makermelissa-piclaw

Copy link
Copy Markdown
Contributor

Converts install_wm8960.sh to install_wm8960.py, continuing the shell-to-Python migration for this repo.

This is a faithful 1:1 port using adafruit_shell (no behavior changes, install-only like the original). It:

  • Clones the Waveshare WM8960-Audio-HAT repo and installs kernel headers + dkms deps
  • DKMS-builds the soundcard module for every installed kernel >= 6.5, preserving the 0.0.0 marker directory that protects the sources from removal across kernel updates
  • Installs the .dtbo, sets the kernel modules and snd_bcm2835 blacklist
  • Enables the i2s / i2c_arm dtparams and the i2s-mmap + wm8960-soundcard overlays in config.txt
  • Installs the .conf/.state files to /etc/wm8960-soundcard, installs the binary and systemd service, and enables it
  • Cleans up the clone directory

Hardware tested

Verified on a Pi 5 (Debian Trixie) with a WM8960 codec. Full install ran cleanly — DKMS module built and installed for both installed kernels (6.12.75+rpt-rpi-2712 and -v8), and every config / module / blacklist / overlay / service piece was placed correctly. The test system was then reverted to a captured baseline (config.txt md5 confirmed identical afterward).

Faithful 1:1 port of install_wm8960.sh to install_wm8960.py using
adafruit_shell, matching the existing converted-script conventions in
this repo. Behavior is unchanged: clones the Waveshare WM8960-Audio-HAT
repo, installs kernel headers + dkms deps, DKMS-builds the soundcard
module for every installed kernel >= 6.5 (preserving the 0.0.0 marker
trick that protects sources across kernel updates), installs the dtbo,
sets the kernel modules and snd_bcm2835 blacklist, enables the i2s /
i2c_arm dtparams and overlays in config.txt, installs the config files
and systemd service, and cleans up the clone.

Hardware-tested on a Pi 5 (Debian Trixie) with a WM8960 codec: full
install verified (DKMS built+installed for both kernels, all config/
module/service pieces placed), then reverted to a captured baseline.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Python-based installer for the Waveshare WM8960 Audio HAT, continuing the repository’s migration from shell installers to adafruit_shell-driven Python scripts.

Changes:

  • Added install_wm8960.py, a Python port of the existing WM8960 installer flow (clone Waveshare repo, install deps, DKMS build/install, config + service setup).
  • Implemented DKMS rebuild/install across all installed kernels with version gating (>= 6.5) and a DKMS “marker” directory to preserve sources across kernel updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install_wm8960.py Outdated
Comment on lines +103 to +107
shell.pattern_replace(config, "^#dtparam=i2s=on", "dtparam=i2s=on")
shell.pattern_replace(config, "^#dtparam=i2c_arm=on", "dtparam=i2c_arm=on")
append_if_missing(config, "dtoverlay=i2s-mmap")
append_if_missing(config, "dtparam=i2s=on")
append_if_missing(config, "dtoverlay=wm8960-soundcard")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Switched to shell.reconfig(config, "^#?dtparam=i2c_arm=on", "dtparam=i2c_arm=on") (same for i2s), which uncomments the line if present and appends it if absent — so I2C/I2S are guaranteed enabled. Verified against four config.txt states (commented, absent, already-on, commented mid-file). Fixed in 05fd9f2.

Comment thread install_wm8960.py Outdated
shell.remove(CLONE_DIR)

print("------------------------------------------------------")
print("Please reboot your raspberry pi to apply all settings")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed — capitalized to "Raspberry Pi" in 05fd9f2.

@makermelissa

Copy link
Copy Markdown
Contributor

append_if_missing would be a great function to add to adafruit_python_shell

…ry Pi

Use shell.reconfig (uncomment-or-append) for dtparam=i2s=on and
dtparam=i2c_arm=on so I2C/I2S are guaranteed enabled even when the
line isn't already present (commented) in config.txt. Drops the now
redundant dtparam=i2s=on append. Also fixes the reboot message
capitalization.
@makermelissa-piclaw

Copy link
Copy Markdown
Contributor Author

Agreed — append_if_missing (grep-or-append, which is the grep -q "^line$" file || echo line >> file idiom every one of these installers repeats) is a natural fit for Adafruit_Python_Shell alongside reconfig. Want me to open a PR there adding Shell.append_if_missing(path, line)? Once it ships I can drop the local helper here and reuse it across the other conversions (spectro, rgb-matrix, etc.).

For now I've kept the local helper so this PR doesn't depend on an unreleased shell version.

@makermelissa-piclaw

Copy link
Copy Markdown
Contributor Author

Opened adafruit/Adafruit_Python_Shell#39 to add Shell.append_if_missing(). Once that's released I'll drop the local helper here (and in the other conversions) and use the shared one.

Drop the local append_if_missing helper now that it's available in the
shared library (adafruit/Adafruit_Python_Shell#39).
@makermelissa-piclaw

Copy link
Copy Markdown
Contributor Author

adafruit-python-shell 1.14.0 is out, so I've dropped the local helper and switched to shell.append_if_missing() (1ac12a2). Ready for another look.

@makermelissa makermelissa merged commit e4faba1 into adafruit:main Jun 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants