Skip to content

Commit

Permalink
Workaround to support single port TPS66993 variant
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertZ2011 committed Jan 15, 2025
1 parent 89d2671 commit e2f56c4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/rt685s-evk/src/bin/ev1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ async fn main(spawner: Spawner) {
});

static CONTROLLER0: StaticCell<Controller<'static>> = StaticCell::new();
let controller0 = CONTROLLER0.init(Controller::new(I2cDevice::new(bus), ADDR0).unwrap());
let controller0 = CONTROLLER0.init(Controller::new(I2cDevice::new(bus), ADDR0, false).unwrap());
let (pd0, interrupt0) = controller0.make_parts();

static CONTROLLER1: StaticCell<Controller<'static>> = StaticCell::new();
let controller1 = CONTROLLER1.init(Controller::new(I2cDevice::new(bus), ADDR1).unwrap());
let controller1 = CONTROLLER1.init(Controller::new(I2cDevice::new(bus), ADDR1, true).unwrap());
let (pd1, interrupt1) = controller1.make_parts();

spawner.must_spawn(interrupt_task(int_in, interrupt0, interrupt1));
Expand Down
2 changes: 1 addition & 1 deletion examples/rt685s-evk/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn main(spawner: Spawner) {
let device = I2cDevice::new(bus);

static CONTROLLER: StaticCell<Controller<'static>> = StaticCell::new();
let controller = CONTROLLER.init(Controller::new(device, ADDR0).unwrap());
let controller = CONTROLLER.init(Controller::new(device, ADDR0, true).unwrap());
let (pd, interrupt) = controller.make_parts();

spawner.must_spawn(interrupt_task(int_in, interrupt));
Expand Down
14 changes: 12 additions & 2 deletions src/asynchronous/embassy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use core::sync::atomic::AtomicBool;

use defmt::{error, warn};
use defmt::{debug, error, warn};
use embassy_sync::blocking_mutex::raw::{NoopRawMutex, RawMutex};
use embassy_sync::mutex::{Mutex, MutexGuard};
use embassy_sync::signal::Signal;
Expand All @@ -30,14 +30,16 @@ pub struct Controller<M: RawMutex, B: I2c> {
inner: Mutex<M, internal::Tps6699x<B>>,
interrupt_waker: Signal<NoopRawMutex, (IntEventBus1, IntEventBus1)>,
interrupts_enabled: [AtomicBool; NUM_PORTS],
hack_disable_port_1: AtomicBool,
}

impl<M: RawMutex, B: I2c> Controller<M, B> {
pub fn new(bus: B, addr: [u8; NUM_PORTS]) -> Result<Self, Error<B::Error>> {
pub fn new(bus: B, addr: [u8; NUM_PORTS], hack_disable_port_1: bool) -> Result<Self, Error<B::Error>> {
Ok(Self {
inner: Mutex::new(internal::Tps6699x::new(bus, addr)),
interrupt_waker: Signal::new(),
interrupts_enabled: [AtomicBool::new(true), AtomicBool::new(true)],
hack_disable_port_1: AtomicBool::new(hack_disable_port_1),
})
}

Expand Down Expand Up @@ -321,11 +323,19 @@ impl<'a, M: RawMutex, B: I2c> Interrupt<'a, M, B> {
self.controller.interrupts_enabled[0].load(core::sync::atomic::Ordering::SeqCst),
self.controller.interrupts_enabled[1].load(core::sync::atomic::Ordering::SeqCst),
];
let hack_disable_port_1 = self
.controller
.hack_disable_port_1
.load(core::sync::atomic::Ordering::SeqCst);

let mut inner = self.lock_inner().await;
for port in 0..NUM_PORTS {
let port_id = PortId(port as u8);

if port_id == PORT1 && hack_disable_port_1 {
continue;
}

if !interrupts_enabled[port] {
continue;
}
Expand Down

0 comments on commit e2f56c4

Please sign in to comment.