diff --git a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs index 311c69a69..87a8b5a02 100644 --- a/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs +++ b/bao1x-boot/boot1/src/platform/bao1x/bao1x.rs @@ -189,7 +189,7 @@ pub fn early_init(mut board_type: bao1x_api::BoardTypeCoding) -> (bao1x_api::Boa ) }; let mut i2c = unsafe { - bao1x_hal::udma::I2c::new_with_ifram( + bao1x_hal::udma::I2cDriver::new_with_ifram( i2c_channel, 400_000, 100_000_000, diff --git a/libs/bao1x-hal/Cargo.toml b/libs/bao1x-hal/Cargo.toml index 17b02ae17..3f42d3aa3 100644 --- a/libs/bao1x-hal/Cargo.toml +++ b/libs/bao1x-hal/Cargo.toml @@ -46,6 +46,7 @@ rand_chacha = { version = "0.3.1", default-features = false } # [target.'cfg(target_os = "xous")'.dependencies] xous = { version = "0.9.67", features = ["v2p"] } +xous-ipc = { version = "0.10.7", optional = true } bitflags = "1.2.1" # TODO: migrate from bitflags to this crate @@ -117,6 +118,7 @@ std = [ "usb-device", "xous-api-ticktimer", "bao1x-api/std", + "xous-ipc", ] derive-rkyv = ["rkyv"] diff --git a/libs/bao1x-hal/src/board/baosec.rs b/libs/bao1x-hal/src/board/baosec.rs index 324f8e968..785b658f9 100644 --- a/libs/bao1x-hal/src/board/baosec.rs +++ b/libs/bao1x-hal/src/board/baosec.rs @@ -176,6 +176,7 @@ pub fn setup_memory_pins(iox: &dyn IoSetup) -> SpimChannel { SPI_MEM_CHANNEL } +const I2C_CHANNEL: I2cChannel = I2cChannel::Channel0; /// This also sets up I2C-adjacent interrupt inputs as well pub fn setup_i2c_pins(iox: &dyn IoSetup) -> I2cChannel { // I2C_SCL_B[0] @@ -211,9 +212,12 @@ pub fn setup_i2c_pins(iox: &dyn IoSetup) -> I2cChannel { None, None, ); - I2cChannel::Channel0 + I2C_CHANNEL } +/// A function just to get the channel. +pub fn get_i2c_channel() -> I2cChannel { I2C_CHANNEL } + /// returns the power-down port and pin number pub fn setup_camera_pins(iox: &T) -> (IoxPort, u8) { iox.setup_pin( diff --git a/libs/bao1x-hal/src/i2c.rs b/libs/bao1x-hal/src/i2c.rs index 029dd0e59..6a82354ec 100644 --- a/libs/bao1x-hal/src/i2c.rs +++ b/libs/bao1x-hal/src/i2c.rs @@ -10,9 +10,9 @@ pub struct I2c { impl I2c { pub fn new() -> Self { REFCOUNT.fetch_add(1, Ordering::Relaxed); - let xns = xous_names::XousNames::new().unwrap(); + let xns = xous_api_names::XousNames::new().unwrap(); let conn = xns - .request_connection(crate::SERVER_NAME_BAO1X_HAL) + .request_connection(bao1x_api::SERVER_NAME_BAO1X_HAL) .expect("Couldn't connect to bao1x HAL server"); I2c { conn } } diff --git a/libs/bao1x-hal/src/lib.rs b/libs/bao1x-hal/src/lib.rs index 07e961ada..be53682ad 100644 --- a/libs/bao1x-hal/src/lib.rs +++ b/libs/bao1x-hal/src/lib.rs @@ -38,6 +38,8 @@ pub mod clocks; pub mod coreuser; #[cfg(all(not(feature = "hosted-baosec"), not(feature = "kernel")))] pub mod hardening; +#[cfg(feature = "std")] +pub mod i2c; #[cfg(all(not(feature = "hosted-baosec"), feature = "std"))] pub mod kpc_aoint; #[cfg(not(feature = "hosted-baosec"))] diff --git a/libs/bao1x-hal/src/udma/i2c.rs b/libs/bao1x-hal/src/udma/i2c.rs index 6e9008a0d..fc1f5ed09 100644 --- a/libs/bao1x-hal/src/udma/i2c.rs +++ b/libs/bao1x-hal/src/udma/i2c.rs @@ -68,7 +68,7 @@ const MAX_I2C_TXLEN: usize = 512; const MAX_I2C_RXLEN: usize = 512; const MAX_I2C_CMDLEN: usize = 512; -pub struct I2c<'a> { +pub struct I2cDriver<'a> { csr: CSR, #[allow(dead_code)] // used in bao1x udma_global: &'a dyn UdmaGlobalConfig, @@ -87,13 +87,13 @@ pub struct I2c<'a> { pending: I2cPending, } -impl Udma for I2c<'_> { +impl Udma for I2cDriver<'_> { fn csr_mut(&mut self) -> &mut CSR { &mut self.csr } fn csr(&self) -> &CSR { &self.csr } } -impl<'a> I2c<'a> { +impl<'a> I2cDriver<'a> { /// Safety: called only after global clock for I2C channel is enabled. /// It is also unsafe to `Drop` because you have to cleanup the clock manually. #[cfg(feature = "std")] @@ -105,7 +105,7 @@ impl<'a> I2c<'a> { ) -> Option { // one page is the minimum size we can request if let Some(ifram) = IframRange::request(4096, None) { - Some(I2c::new_with_ifram(channel, i2c_freq, perclk_freq, ifram, udma_global)) + Some(I2cDriver::new_with_ifram(channel, i2c_freq, perclk_freq, ifram, udma_global)) } else { None } @@ -159,7 +159,7 @@ impl<'a> I2c<'a> { // one page is the minimum size we can request let ifram_base = ifram.virt_range.as_ptr() as usize; let ifram_base_phys = ifram.phys_range.as_ptr() as usize; - let mut i2c = I2c { + let mut i2c = I2cDriver { csr, udma_global, channel, @@ -495,7 +495,7 @@ impl<'a> I2c<'a> { } } -impl I2cApi for I2c<'_> { +impl I2cApi for I2cDriver<'_> { fn i2c_read( &mut self, dev: u8, diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index 21394ae00..ed18d450d 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -4,7 +4,7 @@ use bao1x_api::I2cResult; #[cfg(feature = "hosted-baosec")] use bao1x_emu::i2c::I2c; #[cfg(not(feature = "hosted-baosec"))] -use bao1x_hal_service::I2c; +use bao1x_hal::i2c::I2c; use crate::{CommonEnv, ShellCmdApi}; diff --git a/services/usb-bao1x/src/main.rs b/services/usb-bao1x/src/main.rs index 6c91fe5f1..d2bf35c72 100644 --- a/services/usb-bao1x/src/main.rs +++ b/services/usb-bao1x/src/main.rs @@ -258,7 +258,7 @@ pub(crate) fn main_hw() -> ! { let iox = bao1x_api::IoxHal::new(); #[cfg(feature = "board-baosec")] - let mut i2c = bao1x_hal_service::I2c::new(); + let mut i2c = bao1x_hal::i2c::I2c::new(); #[cfg(feature = "board-baosec")] let pmic = { log::info!("Registering PMIC handler to detect USB plug/unplug events");