changeset 12:283955273884

Add trigger PIO file
author Daniel O'Connor <darius@dons.net.au>
date Mon, 24 Feb 2025 17:27:20 +1030
parents e9d12b36cfcc
children 032acb7fbc04
files trigger.pio
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trigger.pio	Mon Feb 24 17:27:20 2025 +1030
@@ -0,0 +1,34 @@
+;
+; Copyright (c) 2025 Daniel O'Connor
+;
+
+.program trigger
+.define TRIGGER_IRQ 0
+
+.wrap_target
+; Wait for trigger to be low
+    wait 0 pin 0
+; Wait for rising edge
+    wait 1 pin 0
+; Signal other state machine
+    irq nowait TRIGGER_IRQ
+.wrap
+
+% c-sdk {
+static inline void trigger_program_init(PIO pio, uint sm, uint offset, uint pin, uint clkdiv) {
+    pio_sm_config c = trigger_program_get_default_config(offset);
+
+    // Configure SM input pin mapping to point to trigger pin
+    sm_config_set_in_pins(&c, pin);
+    // Set to input
+    pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, false);
+    // Connect this GPIO to this PIO block
+    pio_gpio_init(pio, pin);
+
+    sm_config_set_clkdiv(&c, clkdiv);
+
+    // Load our configuration, and start the program from the beginning
+    pio_sm_init(pio, sm, offset, &c);
+    pio_sm_set_enabled(pio, sm, true);
+}
+%}