0
mirror of https://github.com/torvalds/GuitarPedal.git synced 2026-08-18 21:26:54 +00:00
Files
Linus Torvalds 0c1b9c3db3 Split Software/ into the four things it actually was
'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>
2026-08-11 13:48:26 -07:00

132 lines
3.6 KiB
C

#if MIDI_HW
#define UART_TX_BUF_SIZE 512
static uint8_t uart_tx_buf[UART_TX_BUF_SIZE];
static volatile unsigned uart_tx_head;
static volatile unsigned uart_tx_tail;
#define UART_RX_BUF_SIZE 256
static uint8_t uart_rx_buf[UART_RX_BUF_SIZE];
static volatile unsigned uart_rx_head;
static volatile unsigned uart_rx_tail;
#endif
void uart_midi_write(const uint8_t packet[4])
{
#if MIDI_HW
int len = midi_cin_length(packet[0] & 0x0F);
for (int i = 0; i < len; i++) {
unsigned head = uart_tx_head;
unsigned next_head = (head + 1) % UART_TX_BUF_SIZE;
if (next_head != uart_tx_tail) {
uart_tx_buf[head] = packet[1 + i];
uart_tx_head = next_head;
}
}
#endif
}
bool uart_midi_read(uint8_t packet[4])
{
#if MIDI_HW
static int expected_bytes = 0;
static uint8_t parser_packet[4];
static int parser_idx = 0;
while (uart_rx_head != uart_rx_tail) {
uint8_t b = uart_rx_buf[uart_rx_tail];
uart_rx_tail = (uart_rx_tail + 1) % UART_RX_BUF_SIZE;
if (b >= 0xF8) {
// Real-time message
continue;
} else if (b >= 0x80) {
parser_packet[1] = b;
parser_idx = 2;
if ((b & 0xF0) == 0xC0 || (b & 0xF0) == 0xD0) {
expected_bytes = 1;
} else if (b < 0xF0) {
expected_bytes = 2;
} else {
expected_bytes = 0;
}
} else if (expected_bytes > 0 && parser_idx > 0) {
parser_packet[parser_idx++] = b;
if (parser_idx - 2 == expected_bytes) {
// CIN 0 is reserved: a host is entitled to
// ignore it, and ours was emitting nothing
// else on this path.
packet[0] = midi_status_cin(parser_packet[1]);
packet[1] = parser_packet[1];
packet[2] = parser_packet[2];
packet[3] = parser_packet[3];
parser_idx = 2;
return true;
}
}
}
#endif
return false;
}
void uart_midi_poll(void)
{
#if MIDI_HW
while (uart_is_readable(MIDI_UART)) {
unsigned head = uart_rx_head;
unsigned next_head = (head + 1) % UART_RX_BUF_SIZE;
if (next_head != uart_rx_tail) {
uart_rx_buf[head] = uart_getc(MIDI_UART);
uart_rx_head = next_head;
} else {
break;
}
}
while (uart_tx_head != uart_tx_tail && uart_is_writable(MIDI_UART)) {
uart_putc_raw(MIDI_UART, uart_tx_buf[uart_tx_tail]);
uart_tx_tail = (uart_tx_tail + 1) % UART_TX_BUF_SIZE;
}
uint8_t packet[4];
while (uart_midi_read(packet)) {
if (!handle_midi_packet(packet)) {
usb_midi_write(packet); // MIDI Thru: Echo to USB if not for us
uart_midi_write(packet); // MIDI Thru: Echo to UART if not for us
}
}
#endif
}
static void uart_midi_init(void)
{
#if MIDI_HW
// The funcsel is a property of the pins and comes from
// board.h. UART_FUNCSEL_NUM() can't work it out, and the
// answer is not the same on both boards: UART1 TX/RX is
// function 2 on GPIO 20/21 and function 11 on 26/27,
// because 26/27 have CTS/RTS at 2 and the TX/RX pair is
// one of the RP2350's extended functions.
//
// Don't even ask how long it took to debug this the first
// time: I had read the datasheet when setting this all up,
// but I hadn't connected the dots on UART_FUNCSEL_NUM() not
// doing the right thing. Then it was hardcoded to 11 here,
// which cost a second evening on the board that wants 2 -
// the pins silently ended up muxed to a function that does
// not exist on them, which is as quiet as a failure gets.
gpio_set_function(MIDI_OUT, MIDI_FUNCSEL);
gpio_set_function(MIDI_IN, MIDI_FUNCSEL);
// MIDI idle is +5V, but that is "no current": LED is off,
// and the TLP2310 drives the MIDI_IN pin low.
//
// Standard UART idle is high, but that is easily dealt
// with by just inverting the GPIO pin
gpio_set_inover(MIDI_IN, GPIO_OVERRIDE_INVERT);
// Let it rip!
uart_init(MIDI_UART, 31250);
#endif
}