You've already forked torvalds-GuitarPedal
mirror of
https://github.com/torvalds/GuitarPedal.git
synced 2026-08-19 13:34:01 +00:00
'Software' was the directory everything that was not KiCad ended up in, which stopped describing anything a while ago - Validation and the web app are software too. Worse, it put the shared parts inside the firmware, where they read as the firmware's own. They are not. Effects/ has three consumers built from it: the firmware, Validation's bench, and the web app's controls, all generated from the same POT: comments by gen_effects.py. Audio/ has two - the bench compiles the same biquads, the same envelope followers and the same single_sample(), which is the whole reason a measurement on a workstation says anything about the pedal. Neither belongs under Firmware/, so neither is under it any more: Effects/ one file per effect Audio/ the DSP they are built from, and the audio loop Firmware/ the rest of what runs on the pedal, and the submodules WebMIDI/ the web app scripts/ what the build runs Validation/ unchanged Hardware/, Documentation/, Images/ CMakeLists.txt and the wrapper Makefile move to the top with them, because the build now consumes four of those directories and generates into a fifth. board.local and build/ come along; MIDI_CC_MAP.md is generated into Documentation/ rather than into the old Software/ root. scripts/ goes with the build rather than staying under the firmware, because six of the ten had nothing to do with the firmware: gen_effects.py reads Effects/ and writes to three different places, pow2/log2/quarter_sine generate Audio/'s tables, check-readme.py compares Effects/ against the README, and server.py serves the web app. Four of them are invoked from Validation, which was reaching into Firmware/ for tooling - the same burying this commit is undoing. The four that really are about the firmware are ELF checks the top-level build drives anyway, and a second scripts directory would only be a second place to look. C includes say "Audio/foo.h" and the generated map says "Effects/bar.h", with the repository root on the include path for both the firmware and the bench. Spelling the directory out rather than relying on a bare name is what keeps Audio/cycles.h shimmable: a quoted include searches the including file's own directory first. The submodules are renamed as well as moved. git mv updates their paths but leaves the section names, and 'Software/pico-sdk' surviving in .gitmodules would be the word this commit removes, still load-bearing. That meant the nested modules under pico-sdk too - six .git files pointing into .git/modules/Software - which is why 'git submodule update --init --recursive' is worth running once after pulling this. Verified rather than assumed: a clean configure and build, make check (failing only on the missing-eeprom case it already failed on), check-effects, all four analysis pages reproducing every series and drawing every chart, and a flash to the board that still measures a routed reverb where it did before. One latent bug fell out of it. bench/coeff declared only quarter_sine.h of the three generated math tables, and Audio/util.h includes pow2.h and log2.h as well - so building that target with an empty gen/ could never have worked. 'make bench' builds bench/bench first, which generates all three, so it stayed hidden until this rebuilt everything from nothing. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
56 lines
2.0 KiB
Python
Executable File
56 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# The WS2812B waveform, as a table.
|
|
#
|
|
# Each of the eight bits in a colour byte becomes four output bits at
|
|
# four times the bit rate: '1000' for a zero and '1110' for a one. At
|
|
# the 1.25us WS2812B bit period each output bit is 312.5ns, so:
|
|
#
|
|
# zero 312ns high, 938ns low
|
|
# one 938ns high, 312ns low
|
|
#
|
|
# FOUR, not three, and this is the whole point of the file. Three bits
|
|
# gives a 417ns high for a zero, which is correct for the original
|
|
# WS2812B - it asks for 400ns +-150 - and wrong for the WS2812B-2020,
|
|
# which asks for **220-380ns** and reads anything longer as a one. Feed
|
|
# a 2020 the three-bit encoding and every bit of every byte comes back
|
|
# as a one: all three LEDs sit at 0xffffff and nothing you encode makes
|
|
# the slightest difference, because none of it is being read. That is
|
|
# not a subtle failure but it is a confusing one, because the symptom
|
|
# looks like a brightness bug rather than a timing one.
|
|
#
|
|
# The knob test board this came from uses WS2812B-4020, which has the
|
|
# older timing and works either way. Same family, same protocol, and a
|
|
# different answer to "how long is a zero".
|
|
#
|
|
# Four bits also happens to be tidier: eight of them is exactly 32 bits,
|
|
# so one colour byte is one whole word with nothing thrown away, and the
|
|
# PIO side autopulls at 32 rather than at 24.
|
|
#
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def encode(byte):
|
|
word = 0
|
|
for i in range(8):
|
|
bit = (byte >> (7 - i)) & 1
|
|
# '1110' or '1000', most significant bit of the byte first
|
|
word |= (0b1110 if bit else 0b1000) << (28 - 4 * i)
|
|
return word
|
|
|
|
def generate_table(output_path):
|
|
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
with open(output_path, 'w') as f:
|
|
f.write("// Generated by scripts/ws2812_table.py - do not edit\n")
|
|
f.write("const uint32_t ws2812_encode[256] = {")
|
|
|
|
for i in range(256):
|
|
prefix = "\n\t" if i % 4 == 0 else " "
|
|
f.write(f"{prefix}0x{encode(i):08x},")
|
|
|
|
f.write("\n};\n")
|
|
|
|
if __name__ == "__main__":
|
|
generate_table(sys.argv[1])
|