From caf803f727b57a9c70b07bd4201d77d059c652c4 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Thu, 3 Oct 2024 12:51:17 -0700 Subject: [PATCH] Remove 2 insns from tone PIO program Manually load the 2 needed registers using pio_execute to save a couple PIO instruction slots. --- cores/rp2040/Tone.cpp | 2 ++ cores/rp2040/tone2.pio | 4 ++-- cores/rp2040/tone2.pio.h | 16 +++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cores/rp2040/Tone.cpp b/cores/rp2040/Tone.cpp index a7888dbcd..114eca451 100644 --- a/cores/rp2040/Tone.cpp +++ b/cores/rp2040/Tone.cpp @@ -100,6 +100,8 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration) { } pio_sm_clear_fifos(newTone->pio, newTone->sm); // Remove any old updates that haven't yet taken effect pio_sm_put_blocking(newTone->pio, newTone->sm, RP2040::usToPIOCycles(us)); + pio_sm_exec(newTone->pio, newTone->sm, pio_encode_pull(false, false)); + pio_sm_exec(newTone->pio, newTone->sm, pio_encode_mov(pio_x, pio_osr)); pio_sm_set_enabled(newTone->pio, newTone->sm, true); _toneMap.insert({pin, newTone}); diff --git a/cores/rp2040/tone2.pio b/cores/rp2040/tone2.pio index 9f28518b5..0df248cab 100644 --- a/cores/rp2040/tone2.pio +++ b/cores/rp2040/tone2.pio @@ -23,8 +23,8 @@ .program tone2 .side_set 1 opt - pull ; TXFIFO -> OSR, or X -> OSR if no new period - mov x, osr ; OSR -> X +; pull ; TXFIFO -> OSR, or X -> OSR if no new period +; mov x, osr ; OSR -> X high: pull noblock ; Potentially grab new HALFCYCLECOUNT, OTW copy from backup in X diff --git a/cores/rp2040/tone2.pio.h b/cores/rp2040/tone2.pio.h index dcdc874d2..d0e7be392 100644 --- a/cores/rp2040/tone2.pio.h +++ b/cores/rp2040/tone2.pio.h @@ -13,27 +13,25 @@ // ----- // #define tone2_wrap_target 0 -#define tone2_wrap 8 +#define tone2_wrap 6 #define tone2_pio_version 0 static const uint16_t tone2_program_instructions[] = { // .wrap_target - 0x80a0, // 0: pull block + 0x8080, // 0: pull noblock 0xa027, // 1: mov x, osr - 0x8080, // 2: pull noblock - 0xa027, // 3: mov x, osr - 0xb847, // 4: mov y, osr side 1 + 0xb847, // 2: mov y, osr side 1 + 0x0083, // 3: jmp y--, 3 + 0xb047, // 4: mov y, osr side 0 0x0085, // 5: jmp y--, 5 - 0xb047, // 6: mov y, osr side 0 - 0x0087, // 7: jmp y--, 7 - 0x0002, // 8: jmp 2 + 0x0000, // 6: jmp 0 // .wrap }; #if !PICO_NO_HARDWARE static const struct pio_program tone2_program = { .instructions = tone2_program_instructions, - .length = 9, + .length = 7, .origin = -1, .pio_version = 0, #if PICO_PIO_VERSION > 0