Skip to content

Commit

Permalink
add a test loop to check the IRQ pin configuration
Browse files Browse the repository at this point in the history
this all seems to work as expected now, next up: hooking the
interrupt handler for the IOX.

Probably should put the actual IRQ router in the HAL so that multiple
services can configure it, but have the handler actually invoke
a function in our address space.
  • Loading branch information
bunnie committed Dec 27, 2024
1 parent 1978016 commit 2090288
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions services/usb-cramium/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::sync::Arc;

use api::{HIDReport, LogLevel, Opcode, U2fCode, U2fMsgIpc, UsbListenerRegistration};
use cram_hal_service::api::KeyMap;
use cramium_hal::axp2101::VbusIrq;
use cramium_hal::usb::driver::{CorigineUsb, CorigineWrapper};
use hw::CramiumUsb;
use hw::UsbIrqReq;
Expand Down Expand Up @@ -239,6 +240,32 @@ pub(crate) fn main_hw() -> ! {
}
});

std::thread::spawn({
move || {
log::info!("Connecting to I2C");
let mut i2c = cram_hal_service::I2c::new();
let mut pmic = cramium_hal::axp2101::Axp2101::new(&mut i2c).expect("couldn't open PMIC");
let iox = cram_hal_service::IoxHal::new();
log::info!("AXP2101 config: {:?}", pmic);
let tt = ticktimer::Ticktimer::new().unwrap();
pmic.setup_vbus_irq(&mut i2c, cramium_hal::axp2101::VbusIrq::InsertAndRemove)
.expect("couldn't setup IRQ");
// PB13 is the IRQ input
loop {
tt.sleep_ms(500).ok();
let status = pmic.get_vbus_irq_status(&mut i2c).unwrap();
log::info!(
"Status: {:?}, {:?}",
status,
iox.get_gpio_pin_value(cramium_hal::iox::IoxPort::PB, 13)
);
if status != VbusIrq::None {
pmic.clear_vbus_irq_pending(&mut i2c).expect("couldn't clear pending VBUS IRQ");
}
}
}
});

log::info!("Entering main loop");

let mut msg_opt = None;
Expand Down

0 comments on commit 2090288

Please sign in to comment.