From 140f1ae538c4ff5b24aac7181f0b4cac77f022c5 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 5 Oct 2025 17:17:31 +0800 Subject: [PATCH] add dabao support to usb-bao1x the minimal set of envisioned services for the dabao would include a USB handler. Seems like too useful a thing to not have it enabled. --- services/usb-bao1x/Cargo.toml | 1 + services/usb-bao1x/src/hw.rs | 4 +++- services/usb-bao1x/src/main.rs | 23 +++++++++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/services/usb-bao1x/Cargo.toml b/services/usb-bao1x/Cargo.toml index b850fd6f8..2b8bf921b 100644 --- a/services/usb-bao1x/Cargo.toml +++ b/services/usb-bao1x/Cargo.toml @@ -58,6 +58,7 @@ board-baosec = [ "bao1x-hal", "bao1x-hal-service", ] +board-dabao = ["utralib/bao1x", "utralib/std", "bao1x-hal", "bao1x-hal-service"] hosted-baosec = ["utralib/hosted", "utralib/std", "bao1x-emu"] # none of these other modes are actually supported, but are listed here # to allow direct re-use of API code diff --git a/services/usb-bao1x/src/hw.rs b/services/usb-bao1x/src/hw.rs index 182df9812..7ffd3dfd2 100644 --- a/services/usb-bao1x/src/hw.rs +++ b/services/usb-bao1x/src/hw.rs @@ -138,7 +138,9 @@ impl<'a> Bao1xUsb<'a> { self.irq_csr.wfo(utra::irqarray1::EV_SOFT_TRIGGER, SW_IRQ_MASK); } - /// Process an unplug event + /// Process an unplug event - only valid on baosec, because dabao doesn't have a battery and unplugging + /// it would power it down. + #[cfg(feature = "board-baosec")] pub fn unplug(&mut self) { // disable all interrupts so we can safely go through initialization routines self.irq_csr.wo(utra::irqarray1::EV_ENABLE, 0); diff --git a/services/usb-bao1x/src/main.rs b/services/usb-bao1x/src/main.rs index 9d7336f05..a6ce7522b 100644 --- a/services/usb-bao1x/src/main.rs +++ b/services/usb-bao1x/src/main.rs @@ -16,6 +16,7 @@ use std::sync::Arc; use api::*; use bao1x_api::keyboard::KeyMap; +#[cfg(feature = "board-baosec")] use bao1x_hal::axp2101::VbusIrq; use bao1x_hal::usb::driver::{CorigineUsb, CorigineWrapper}; use hw::Bao1xUsb; @@ -59,10 +60,6 @@ fn main() -> ! { } pub(crate) fn main_hw() -> ! { - // confirm that the app UART is initialized in our PID - this needs to happen in a userspace call - // before any IRQ calls try to use it. - crate::println!("APP UART in PID {}", xous::process::id()); - #[cfg(feature = "usbd-debug")] // bind the duart let duart_mapping = xous::syscall::map_memory( @@ -263,12 +260,21 @@ pub(crate) fn main_hw() -> ! { } }); - log::info!("Registering PMIC handler to detect USB plug/unplug events"); let iox = bao1x_api::IoxHal::new(); - bao1x_hal::board::setup_pmic_irq(&iox, api::SERVER_NAME_USB_DEVICE, Opcode::PmicIrq.to_usize().unwrap()); + #[cfg(feature = "board-baosec")] let mut i2c = bao1x_hal_service::I2c::new(); - let mut pmic = bao1x_hal::axp2101::Axp2101::new(&mut i2c).expect("couldn't open PMIC"); - pmic.setup_vbus_irq(&mut i2c, bao1x_hal::axp2101::VbusIrq::Remove).expect("couldn't setup IRQ"); + #[cfg(feature = "board-baosec")] + let pmic = { + log::info!("Registering PMIC handler to detect USB plug/unplug events"); + bao1x_hal::board::setup_pmic_irq( + &iox, + api::SERVER_NAME_USB_DEVICE, + Opcode::PmicIrq.to_usize().unwrap(), + ); + let mut pmic = bao1x_hal::axp2101::Axp2101::new(&mut i2c).expect("couldn't open PMIC"); + pmic.setup_vbus_irq(&mut i2c, bao1x_hal::axp2101::VbusIrq::Remove).expect("couldn't setup IRQ"); + pmic + }; let (se0_port, se0_pin) = bao1x_hal::board::setup_usb_pins(&iox); iox.set_gpio_pin_value(se0_port, se0_pin, bao1x_api::IoxValue::High); // release SE0 state, allowing for enumeration @@ -282,6 +288,7 @@ pub(crate) fn main_hw() -> ! { let opcode = num_traits::FromPrimitive::from_usize(msg.body.id()).unwrap_or(Opcode::InvalidCall); log::debug!("{:?}", opcode); match opcode { + #[cfg(feature = "board-baosec")] Opcode::PmicIrq => match pmic.get_vbus_irq_status(&mut i2c).unwrap() { VbusIrq::Insert => { log::error!("VBUS insert reported by PMIC, but we didn't ask for the event!");