strip out disconnect idiom in the HAL crate

This commit is contained in:
bunnie 2026-02-02 01:20:14 +08:00
parent 8bc480994c
commit d466abd456

View file

@ -1,5 +1,3 @@
use core::sync::atomic::{AtomicU32, Ordering};
use bao1x_api::*;
use xous_ipc::Buffer;
@ -9,7 +7,6 @@ pub struct I2c {
impl I2c {
pub fn new() -> Self {
REFCOUNT.fetch_add(1, Ordering::Relaxed);
let xns = xous_api_names::XousNames::new().unwrap();
let conn = xns
.request_connection(bao1x_api::SERVER_NAME_BAO1X_HAL)
@ -70,16 +67,3 @@ impl I2cApi for I2c {
}
}
}
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
impl Drop for I2c {
fn drop(&mut self) {
// de-allocate myself. It's unsafe because we are responsible to make sure nobody else is using the
// connection.
if REFCOUNT.fetch_sub(1, Ordering::Relaxed) == 1 {
unsafe {
xous::disconnect(self.conn).unwrap();
}
}
}
}