Skip to content

Commit

Permalink
implement Drop for I2sParallelTransfer
Browse files Browse the repository at this point in the history
  • Loading branch information
liebman committed Oct 21, 2024
1 parent 7529640 commit a6b48cf
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions esp-hal/src/i2s_parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ where
let view = unsafe { ManuallyDrop::take(&mut self.buf_view) };
(i2s, BUF::from_view(view))
}

fn stop_peripherals(&mut self) {
I::tx_stop();
self.i2s.tx_channel.stop_transfer();
}
}

impl<'d, I, BUF> I2sParallelTransfer<'d, I, BUF, crate::Async>
Expand Down Expand Up @@ -469,6 +474,25 @@ where
}
}

impl<'d, I, BUF, DM> Drop for I2sParallelTransfer<'d, I, BUF, DM>
where
I: Instance,
BUF: DmaTxBuffer,
DM: Mode,
{
fn drop(&mut self) {
self.stop_peripherals();

// SAFETY: This is Drop, we know that self.i2s and self.buf_view
// won't be touched again.
let view = unsafe {
ManuallyDrop::drop(&mut self.i2s);
ManuallyDrop::take(&mut self.buf_view)
};
let _ = BUF::from_view(view);
}
}

mod private {
use fugit::HertzU32;

Expand Down

0 comments on commit a6b48cf

Please sign in to comment.