Skip to content

Commit 9268cf3

Browse files
committed
add the option to select any trigger pin.
1 parent 39806d8 commit 9268cf3

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/current/rp2350/RP2350PIOCurrentSense.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#include "RP2350PIOCurrentSense.h"
22

3-
RP2350PIOCurrentSense::RP2350PIOCurrentSense(float gain, uint32_t max_adc_value, int pinSCK, int pinCSB, int pinD0) : CurrentSense() {
3+
RP2350PIOCurrentSense::RP2350PIOCurrentSense(float gain, uint32_t max_adc_value, int pinSCK, int pinCSB, int pinD0, int pinTRIG) : CurrentSense() {
44
this->pinSCK = pinSCK;
55
this->pinCSB = pinCSB;
66
this->pinD0 = pinD0;
77
this->pinD1 = pinD0+1;
88
this->pinD2 = pinD0+2;
9+
this->pinTRIG = pinTRIG;
910
this->gain_a = gain;
1011
this->gain_b = gain;
1112
this->gain_c = gain;
@@ -35,7 +36,16 @@
3536
int sm = pio_claim_unused_sm(pio0, false);
3637
if (sm < 0) { pio = pio1; sm = pio_claim_unused_sm(pio1, true); }
3738

38-
uint off = pio_add_program(pio, &bu79100g_parallel3_program);
39+
// --- patch program instructions with chosen trigger pin ---
40+
size_t prog_len = bu79100g_parallel3_program.length;
41+
uint16_t insns[prog_len];
42+
memcpy(insns, bu79100g_parallel3_program_instructions, sizeof(insns));
43+
insns[1] = (insns[1] & ~0x1Fu) | (this->pinTRIG & 0x1Fu);
44+
insns[2] = (insns[2] & ~0x1Fu) | (this->pinTRIG & 0x1Fu);
45+
struct pio_program prog = bu79100g_parallel3_program; // copy metadata
46+
prog.instructions = insns;
47+
48+
uint off = pio_add_program(pio, &prog);
3949
pio_sm_config c = bu79100g_parallel3_program_get_default_config(off);
4050

4151
// Map pins to the SM

src/current/rp2350/RP2350PIOCurrentSense.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class RP2350PIOCurrentSense: public CurrentSense {
88
public:
9-
RP2350PIOCurrentSense(float gain, uint32_t max_adc_value, int pinSCK, int pinCSB, int pinD0);
9+
RP2350PIOCurrentSense(float gain, uint32_t max_adc_value, int pinSCK, int pinCSB, int pinD0, int pinTRIG);
1010
~RP2350PIOCurrentSense();
1111

1212
int init() override;
@@ -19,6 +19,7 @@ class RP2350PIOCurrentSense: public CurrentSense {
1919
int pinD0;
2020
int pinD1;
2121
int pinD2;
22+
int pinTRIG;
2223
int gain_a;
2324
int gain_b;
2425
int gain_c;

src/current/rp2350/bu79100g_parallel3.pio

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
.wrap_target
1010
set pins, 1 side 1 ; CSB=1, SCK=1
1111
; -------- wait external falling edge on absolute GPIO ----------
12-
wait 1 gpio 11 ; TODO, we will need to have this pin setable from the C code. direcetly edit the program?
13-
wait 0 gpio 11
12+
wait 1 gpio 11 ;THIS INSTRUCTION WILL BE PATCHED AT RUNTIME TO CHANGE GPIO. DO NOT MOVE IT WITHOUT CHANGING PIO INIT.
13+
wait 0 gpio 11 ;THIS INSTRUCTION WILL BE PATCHED AT RUNTIME TO CHANGE GPIO. DO NOT MOVE IT WITHOUT CHANGING PIO INIT.
1414
set pins, 0 side 1 ; CS=0, SCK=1
1515
set x, 15 side 1 ; prepare loop cpt
1616
; -------- 16 dummy clocks (no sampling) -----------------------

0 commit comments

Comments
 (0)