mirror of
https://github.com/esp-rs/esp-idf-hal.git
synced 2025-09-28 12:51:04 +00:00
Fix a crash when dropping SpiDriver
This commit is contained in:
parent
7d5e233ac9
commit
30d4874def
@ -623,7 +623,7 @@ pub struct SpiBusDriver<'d, T>
|
|||||||
where
|
where
|
||||||
T: BorrowMut<SpiDriver<'d>>,
|
T: BorrowMut<SpiDriver<'d>>,
|
||||||
{
|
{
|
||||||
_lock: BusLock,
|
lock: Option<BusLock>,
|
||||||
handle: spi_device_handle_t,
|
handle: spi_device_handle_t,
|
||||||
driver: T,
|
driver: T,
|
||||||
duplex: Duplex,
|
duplex: Duplex,
|
||||||
@ -646,7 +646,7 @@ where
|
|||||||
let lock = BusLock::new(handle)?;
|
let lock = BusLock::new(handle)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
_lock: lock,
|
lock: Some(lock),
|
||||||
handle,
|
handle,
|
||||||
driver,
|
driver,
|
||||||
duplex: config.duplex,
|
duplex: config.duplex,
|
||||||
@ -825,6 +825,10 @@ where
|
|||||||
T: BorrowMut<SpiDriver<'d>>,
|
T: BorrowMut<SpiDriver<'d>>,
|
||||||
{
|
{
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
// Need to drop the lock first, because it holds the device
|
||||||
|
// we are about to remove below
|
||||||
|
self.lock = None;
|
||||||
|
|
||||||
esp!(unsafe { spi_bus_remove_device(self.handle) }).unwrap();
|
esp!(unsafe { spi_bus_remove_device(self.handle) }).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user