add oem-baosec-lite support to usb driver

there is currently no method to detect USB power connect
in this board. Considering adding a simple circuit to enable
this. This design is not meant to be battery powered but
it is possible that an aftermarket modification would introduce
a battery, in which case, vbus detection does become A Thing.
This commit is contained in:
bunnie 2026-01-24 23:54:21 +08:00
parent bcf73733c3
commit 8b06b212bb
3 changed files with 11 additions and 8 deletions

View file

@ -58,6 +58,7 @@ board-baosec = [
"bao1x-hal", "bao1x-hal",
"bao1x-hal-service", "bao1x-hal-service",
] ]
oem-baosec-lite = ["bao1x-hal/oem-baosec-lite"]
board-dabao = ["utralib/bao1x", "utralib/std", "bao1x-hal", "bao1x-hal-service"] board-dabao = ["utralib/bao1x", "utralib/std", "bao1x-hal", "bao1x-hal-service"]
hosted-baosec = ["utralib/hosted", "utralib/std", "bao1x-emu"] hosted-baosec = ["utralib/hosted", "utralib/std", "bao1x-emu"]
# none of these other modes are actually supported, but are listed here # none of these other modes are actually supported, but are listed here

View file

@ -87,14 +87,16 @@ impl<'a> Bao1xUsb<'a> {
// to concurrently add that in - you have to kick out one of the interfaces above to add mass // to concurrently add that in - you have to kick out one of the interfaces above to add mass
// storage!) // storage!)
#[cfg(feature = "board-baosec")] #[cfg(feature = "oem-baosec-lite")]
let product = "Baosec-lite";
#[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
let product = "Baosec"; let product = "Baosec";
#[cfg(feature = "board-baosec")] #[cfg(feature = "board-baosec")]
let pid = 0x6198; // pending PR acceptance let pid = 0x6198;
#[cfg(feature = "board-dabao")] #[cfg(feature = "board-dabao")]
let product = "Dabao"; let product = "Dabao";
#[cfg(feature = "board-dabao")] #[cfg(feature = "board-dabao")]
let pid = 0x6197; // pending PR acceptance let pid = 0x6197;
let device = UsbDeviceBuilder::new(&usb_alloc, UsbVidPid(0x1d50, pid)) let device = UsbDeviceBuilder::new(&usb_alloc, UsbVidPid(0x1d50, pid))
.manufacturer("Baochip") .manufacturer("Baochip")
.product(product) .product(product)
@ -160,7 +162,7 @@ impl<'a> Bao1xUsb<'a> {
/// Process an unplug event - only valid on baosec, because dabao doesn't have a battery and unplugging /// Process an unplug event - only valid on baosec, because dabao doesn't have a battery and unplugging
/// it would power it down. /// it would power it down.
#[cfg(feature = "board-baosec")] #[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
pub fn unplug(&mut self) { pub fn unplug(&mut self) {
// disable all interrupts so we can safely go through initialization routines // disable all interrupts so we can safely go through initialization routines
self.irq_csr.wo(utra::irqarray1::EV_ENABLE, 0); self.irq_csr.wo(utra::irqarray1::EV_ENABLE, 0);

View file

@ -52,7 +52,7 @@ pub(crate) fn main_hw() -> ! {
use api::*; use api::*;
use bao1x_api::IoGpio; use bao1x_api::IoGpio;
use bao1x_api::keyboard::KeyMap; use bao1x_api::keyboard::KeyMap;
#[cfg(feature = "board-baosec")] #[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
use bao1x_hal::axp2101::VbusIrq; use bao1x_hal::axp2101::VbusIrq;
use bao1x_hal::usb::driver::{CorigineUsb, CorigineWrapper}; use bao1x_hal::usb::driver::{CorigineUsb, CorigineWrapper};
use hw::{Bao1xUsb, UsbIrqReq}; use hw::{Bao1xUsb, UsbIrqReq};
@ -260,9 +260,9 @@ pub(crate) fn main_hw() -> ! {
}); });
let iox = bao1x_api::IoxHal::new(); let iox = bao1x_api::IoxHal::new();
#[cfg(feature = "board-baosec")] #[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
let mut i2c = bao1x_hal::i2c::I2c::new(); let mut i2c = bao1x_hal::i2c::I2c::new();
#[cfg(feature = "board-baosec")] #[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
let pmic = { let pmic = {
log::info!("Registering PMIC handler to detect USB plug/unplug events"); log::info!("Registering PMIC handler to detect USB plug/unplug events");
bao1x_hal::board::setup_pmic_irq( bao1x_hal::board::setup_pmic_irq(
@ -292,7 +292,7 @@ pub(crate) fn main_hw() -> ! {
); );
} }
match opcode { match opcode {
#[cfg(feature = "board-baosec")] #[cfg(all(feature = "board-baosec", not(feature = "oem-baosec-lite")))]
Opcode::PmicIrq => match pmic.get_vbus_irq_status(&mut i2c).unwrap() { Opcode::PmicIrq => match pmic.get_vbus_irq_status(&mut i2c).unwrap() {
VbusIrq::Insert => { VbusIrq::Insert => {
log::error!("VBUS insert reported by PMIC, but we didn't ask for the event!"); log::error!("VBUS insert reported by PMIC, but we didn't ask for the event!");