From 20902880095ac8eae6e71e29546c6e20e99553b4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 27 Dec 2024 20:02:08 +0800 Subject: [PATCH] add a test loop to check the IRQ pin configuration 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. --- services/usb-cramium/src/main.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/services/usb-cramium/src/main.rs b/services/usb-cramium/src/main.rs index 34080038a..a7c90b3a9 100644 --- a/services/usb-cramium/src/main.rs +++ b/services/usb-cramium/src/main.rs @@ -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; @@ -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;