Skip to content

Commit 660ea7a

Browse files
committed
Tidy nested lock calls
1 parent 303a0b9 commit 660ea7a

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

examples/spi-dma-rtic.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,39 +141,33 @@ mod app {
141141
}
142142

143143
#[task(binds=DMA1_STR1, shared = [transfer, cs], priority=2)]
144-
fn dma_complete(mut ctx: dma_complete::Context) {
144+
fn dma_complete(ctx: dma_complete::Context) {
145145
// If desired, the transfer can scheduled again here to continue transmitting.
146-
let mut cs = ctx.shared.cs;
147-
ctx.shared.transfer.lock(|transfer| {
148-
cs.lock(|cs| {
149-
transfer.clear_transfer_complete_interrupt();
150-
transfer.pause(|spi| {
151-
// At this point, the DMA transfer is done, but the data is still in the SPI output
152-
// FIFO. Wait for it to complete before disabling CS.
153-
while spi.inner().sr.read().txc().bit_is_clear() {}
154-
cs.set_high().unwrap();
155-
});
146+
(ctx.shared.transfer, ctx.shared.cs).lock(|transfer, cs| {
147+
transfer.clear_transfer_complete_interrupt();
148+
transfer.pause(|spi| {
149+
// At this point, the DMA transfer is done, but the data is still in the SPI output
150+
// FIFO. Wait for it to complete before disabling CS.
151+
while spi.inner().sr.read().txc().bit_is_clear() {}
152+
cs.set_high().unwrap();
156153
});
157154
});
158155
}
159156

160157
#[idle(shared = [transfer, cs])]
161-
fn idle(mut ctx: idle::Context) -> ! {
158+
fn idle(ctx: idle::Context) -> ! {
162159
// Start the DMA transfer over SPI.
163-
let mut cs = ctx.shared.cs;
164-
ctx.shared.transfer.lock(|transfer| {
165-
cs.lock(|cs| {
166-
transfer.start(|spi| {
167-
// Set CS low for the transfer.
168-
cs.set_low().unwrap();
169-
170-
// Enable TX DMA support, enable the SPI peripheral, and start the transaction.
171-
spi.enable_dma_tx();
172-
spi.inner_mut().cr1.modify(|_, w| w.spe().enabled());
173-
spi.inner_mut().cr1.modify(|_, w| w.cstart().started());
174-
175-
// The transaction immediately begins as the TX FIFO is now being filled by DMA.
176-
});
160+
(ctx.shared.transfer, ctx.shared.cs).lock(|transfer, cs| {
161+
transfer.start(|spi| {
162+
// Set CS low for the transfer.
163+
cs.set_low().unwrap();
164+
165+
// Enable TX DMA support, enable the SPI peripheral, and start the transaction.
166+
spi.enable_dma_tx();
167+
spi.inner_mut().cr1.modify(|_, w| w.spe().enabled());
168+
spi.inner_mut().cr1.modify(|_, w| w.cstart().started());
169+
170+
// The transaction immediately begins as the TX FIFO is now being filled by DMA.
177171
});
178172
});
179173

0 commit comments

Comments
 (0)