-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/rt685s-evk: Create plug_status binary
- Loading branch information
1 parent
b49e823
commit cbd01fe
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,6 @@ static_cell = "2.1.0" | |
|
||
[[bin]] | ||
name = "fw_update" | ||
|
||
[[bin]] | ||
name = "plug_status" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#![no_std] | ||
#![no_main] | ||
use core::default::Default; | ||
|
||
use defmt::info; | ||
use embassy_embedded_hal::shared_bus::asynch::i2c::I2cDevice; | ||
use embassy_executor::Spawner; | ||
use embassy_imxrt::gpio::{Input, Inverter, Pull}; | ||
use embassy_imxrt::i2c::master::{I2cMaster, Speed}; | ||
use embassy_imxrt::i2c::Async; | ||
use embassy_imxrt::{self, bind_interrupts, peripherals}; | ||
use embassy_sync::blocking_mutex::raw::NoopRawMutex; | ||
use embassy_sync::mutex::Mutex; | ||
use embassy_sync::once_lock::OnceLock; | ||
use embedded_usb_pd::PortId; | ||
use mimxrt600_fcb::FlexSPIFlashConfigurationBlock; | ||
use static_cell::StaticCell; | ||
use tps6699x::asynchronous::embassy as pd_controller; | ||
use tps6699x::registers::field_sets::IntEventBus1; | ||
use tps6699x::ADDR0; | ||
use {defmt_rtt as _, panic_probe as _}; | ||
|
||
bind_interrupts!(struct Irqs { | ||
FLEXCOMM2 => embassy_imxrt::i2c::InterruptHandler<peripherals::FLEXCOMM2>; | ||
}); | ||
|
||
type Bus<'a> = I2cDevice<'a, NoopRawMutex, I2cMaster<'a, Async>>; | ||
type Controller<'a> = pd_controller::controller::Controller<NoopRawMutex, Bus<'a>>; | ||
|
||
type Interrupt<'a> = pd_controller::Interrupt<'a, NoopRawMutex, Bus<'a>>; | ||
|
||
#[embassy_executor::task] | ||
async fn interrupt_task(mut int_in: Input<'static>, mut interrupt: Interrupt<'static>) { | ||
pd_controller::task::interrupt_task(&mut int_in, [&mut interrupt]).await; | ||
} | ||
|
||
#[embassy_executor::main] | ||
async fn main(spawner: Spawner) { | ||
let p = embassy_imxrt::init(Default::default()); | ||
|
||
let int_in = Input::new(p.PIO1_0, Pull::Up, Inverter::Disabled); | ||
static BUS: OnceLock<Mutex<NoopRawMutex, I2cMaster<'static, Async>>> = OnceLock::new(); | ||
let bus = BUS.get_or_init(|| { | ||
Mutex::new(I2cMaster::new_async(p.FLEXCOMM2, p.PIO0_18, p.PIO0_17, Irqs, Speed::Standard, p.DMA0_CH5).unwrap()) | ||
}); | ||
|
||
let device = I2cDevice::new(bus); | ||
|
||
static CONTROLLER: StaticCell<Controller<'static>> = StaticCell::new(); | ||
let controller = CONTROLLER.init(Controller::new_tps66994(device, ADDR0).unwrap()); | ||
let (mut pd, interrupt) = controller.make_parts(); | ||
|
||
info!("Spawing PD interrupt task"); | ||
spawner.must_spawn(interrupt_task(int_in, interrupt)); | ||
|
||
loop { | ||
let flags = pd.wait_interrupt(false, |_, flags| flags.plug_event()).await; | ||
|
||
for (i, flag) in flags.iter().enumerate().take(pd.num_ports()) { | ||
if *flag == IntEventBus1::new_zero() { | ||
continue; | ||
} | ||
|
||
let port = PortId(i as u8); | ||
info!("P{}: plug event", i); | ||
let result = pd.get_port_status(port).await; | ||
if let Err(e) = result { | ||
info!("P{}: error getting port status: {:?}", i, e); | ||
continue; | ||
} | ||
|
||
let status = result.unwrap(); | ||
if status.plug_present() { | ||
info!("P{}: plug present", i); | ||
if status.plug_orientation() { | ||
info!("P{}: flipped ", i); | ||
} else { | ||
info!("P{}: not flipped", i); | ||
} | ||
|
||
info!("P{}: connection state {:?}", i, status.connection_state()); | ||
} else { | ||
info!("P{}: plug removed", i); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[link_section = ".otfad"] | ||
#[used] | ||
static OTFAD: [u8; 256] = [0; 256]; | ||
|
||
#[link_section = ".fcb"] | ||
#[used] | ||
static FCB: FlexSPIFlashConfigurationBlock = FlexSPIFlashConfigurationBlock::build(); | ||
|
||
#[link_section = ".biv"] | ||
#[used] | ||
static BOOT_IMAGE_VERSION: u32 = 0x01000000; | ||
|
||
#[link_section = ".keystore"] | ||
#[used] | ||
static KEYSTORE: [u8; 2048] = [0; 2048]; |