aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/pio_programs
diff options
context:
space:
mode:
authorMichael Turner <[email protected]>2025-11-02 10:24:52 -0800
committerMichael Turner <[email protected]>2025-11-02 10:24:52 -0800
commitd838c2b84b133e2a38e30bb7ccc1cbd7253451dc (patch)
tree8b53b9870f81ee2ebce17bd33e62ef4081668c3d /embassy-rp/src/pio_programs
parent3ff0b2c5971e72a93bd37d7f8fecbc8e64421360 (diff)
Disable PIO SM before setting Y register
Diffstat (limited to 'embassy-rp/src/pio_programs')
-rw-r--r--embassy-rp/src/pio_programs/onewire.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/embassy-rp/src/pio_programs/onewire.rs b/embassy-rp/src/pio_programs/onewire.rs
index 09babc229..3adab3b79 100644
--- a/embassy-rp/src/pio_programs/onewire.rs
+++ b/embassy-rp/src/pio_programs/onewire.rs
@@ -163,7 +163,11 @@ impl<'d, PIO: Instance, const SM: usize> PioOneWire<'d, PIO, SM> {
163 163
164 /// Write bytes to the onewire bus 164 /// Write bytes to the onewire bus
165 pub async fn write_bytes(&mut self, data: &[u8]) { 165 pub async fn write_bytes(&mut self, data: &[u8]) {
166 unsafe { self.sm.set_y(u32::MAX as u32) }; 166 unsafe {
167 self.sm.set_enable(false);
168 self.sm.set_y(u32::MAX as u32);
169 self.sm.set_enable(true);
170 }
167 let (rx, tx) = self.sm.rx_tx(); 171 let (rx, tx) = self.sm.rx_tx();
168 for b in data { 172 for b in data {
169 tx.wait_push(*b as u32).await; 173 tx.wait_push(*b as u32).await;
@@ -175,7 +179,11 @@ impl<'d, PIO: Instance, const SM: usize> PioOneWire<'d, PIO, SM> {
175 179
176 /// Write bytes to the onewire bus, then apply a strong pullup 180 /// Write bytes to the onewire bus, then apply a strong pullup
177 pub async fn write_bytes_pullup(&mut self, data: &[u8], pullup_time: embassy_time::Duration) { 181 pub async fn write_bytes_pullup(&mut self, data: &[u8], pullup_time: embassy_time::Duration) {
178 unsafe { self.sm.set_y(data.len() as u32 * 8 - 1) }; 182 unsafe {
183 self.sm.set_enable(false);
184 self.sm.set_y(data.len() as u32 * 8 - 1);
185 self.sm.set_enable(true);
186 };
179 let (rx, tx) = self.sm.rx_tx(); 187 let (rx, tx) = self.sm.rx_tx();
180 for b in data { 188 for b in data {
181 tx.wait_push(*b as u32).await; 189 tx.wait_push(*b as u32).await;
@@ -195,7 +203,11 @@ impl<'d, PIO: Instance, const SM: usize> PioOneWire<'d, PIO, SM> {
195 203
196 /// Read bytes from the onewire bus 204 /// Read bytes from the onewire bus
197 pub async fn read_bytes(&mut self, data: &mut [u8]) { 205 pub async fn read_bytes(&mut self, data: &mut [u8]) {
198 unsafe { self.sm.set_y(u32::MAX as u32) }; 206 unsafe {
207 self.sm.set_enable(false);
208 self.sm.set_y(u32::MAX as u32);
209 self.sm.set_enable(true);
210 };
199 let (rx, tx) = self.sm.rx_tx(); 211 let (rx, tx) = self.sm.rx_tx();
200 for b in data { 212 for b in data {
201 // Write all 1's so that we can read what the device responds 213 // Write all 1's so that we can read what the device responds