From cfe9b3c8458006c16eb4cc87e6644c2bd7201e10 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 01:52:25 +0800 Subject: [PATCH 01/27] modify base API for GlobalConfig to auto-infer the API address the switch based on target is now absorbed into the new() function. This paves the way for us to add more CSR ranges into the global configuration object, i.e. IRQ csrs for I2C. --- libs/cramium-hal/src/udma/mod.rs | 29 +++++++++++++++++++++++++- loader/src/platform/cramium/cramium.rs | 8 +++---- loader/src/platform/cramium/swap.rs | 5 ++--- loader/src/platform/cramium/update.rs | 6 ++---- services/cram-hal-service/src/main.rs | 9 +------- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/libs/cramium-hal/src/udma/mod.rs b/libs/cramium-hal/src/udma/mod.rs index 7185e7c6c..3bd8b60ad 100644 --- a/libs/cramium-hal/src/udma/mod.rs +++ b/libs/cramium-hal/src/udma/mod.rs @@ -37,9 +37,36 @@ impl Into for GlobalReg { pub struct GlobalConfig { csr: SharedCsr, + i2c_irq: SharedCsr, } impl GlobalConfig { - pub fn new(base_addr: *mut u32) -> Self { GlobalConfig { csr: SharedCsr::new(base_addr) } } + pub fn new() -> Self { + #[cfg(target_os = "xous")] + let base_addr = xous::syscall::map_memory( + xous::MemoryAddress::new(utralib::generated::HW_UDMA_CTRL_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map UDMA global control") + .as_mut_ptr() as *mut u32; + #[cfg(not(target_os = "xous"))] + let base_addr = utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32; + + #[cfg(target_os = "xous")] + let i2c_irq_addr = xous::syscall::map_memory( + xous::MemoryAddress::new(utralib::generated::HW_IRQARRAY7_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map I2C IRQ range") + .as_mut_ptr() as *mut u32; + #[cfg(not(target_os = "xous"))] + let i2c_irq_addr = utralib::generated::HW_IRQARRAY7_BASE as *mut u32; + + GlobalConfig { csr: SharedCsr::new(base_addr), i2c_irq: SharedCsr::new(i2c_irq_addr) } + } pub fn clock_on(&self, peripheral: PeriphId) { // Safety: only safe when used in the context of UDMA registers. diff --git a/loader/src/platform/cramium/cramium.rs b/loader/src/platform/cramium/cramium.rs index 14537261d..09231c229 100644 --- a/loader/src/platform/cramium/cramium.rs +++ b/loader/src/platform/cramium/cramium.rs @@ -235,7 +235,7 @@ pub fn early_init() -> u32 { // Set up the UDMA_UART block to the correct baud rate and enable status #[allow(unused_mut)] // some configs require mut - let mut udma_global = GlobalConfig::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32); + let mut udma_global = GlobalConfig::new(); udma_global.clock_on(PeriphId::Uart1); udma_global.map_event( PeriphId::Uart1, @@ -409,7 +409,7 @@ pub fn early_init() -> u32 { // show the boot logo use ux_api::minigfx::FrameBuffer; - let mut udma_global = GlobalConfig::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32); + let mut udma_global = GlobalConfig::new(); let mut sh1107 = cramium_hal::sh1107::Oled128x128::new( cramium_hal::sh1107::MainThreadToken::new(), perclk, @@ -456,7 +456,7 @@ pub fn early_init() -> u32 { use crate::platform::cramium::qr; let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32); - let udma_global = GlobalConfig::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32); + let udma_global = GlobalConfig::new(); // setup camera pins let (cam_pdwn_bnk, cam_pdwn_pin) = cramium_hal::board::setup_camera_pins(&iox); @@ -962,7 +962,7 @@ pub fn early_init() -> u32 { // setup the I/O pins let mut iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32); - let mut udma_global = GlobalConfig::new(utralib::generated::HW_UDMA_CTRL_BASE as *mut u32); + let mut udma_global = GlobalConfig::new(); let channel = cramium_hal::board::setup_memory_pins(&iox); udma_global.clock_off(PeriphId::from(channel)); diff --git a/loader/src/platform/cramium/swap.rs b/loader/src/platform/cramium/swap.rs index 1b39a4f89..56af26be6 100644 --- a/loader/src/platform/cramium/swap.rs +++ b/loader/src/platform/cramium/swap.rs @@ -41,7 +41,7 @@ pub struct SwapHal { impl SwapHal { pub fn new(cfg: &BootConfig, perclk_freq: u32) -> Option { if let Some(swap) = cfg.swap { - let udma_global = GlobalConfig::new(utralib::generated::HW_UDMA_CTRL_BASE as *mut u32); + let udma_global = GlobalConfig::new(); // setup the I/O pins let iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32); @@ -413,8 +413,7 @@ pub fn userspace_maps(cfg: &mut BootConfig) { iox.set_gpio_dir(IoxPort::PD, 3, IoxDir::Output); // Set up the UDMA_UART block to the correct baud rate and enable status - let udma_global = - cramium_hal::udma::GlobalConfig::new(utralib::utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32); + let udma_global = cramium_hal::udma::GlobalConfig::new(); udma_global.clock_on(PeriphId::Uart0); udma_global.map_event( PeriphId::Uart0, diff --git a/loader/src/platform/cramium/update.rs b/loader/src/platform/cramium/update.rs index afb4691f8..614d38f55 100644 --- a/loader/src/platform/cramium/update.rs +++ b/loader/src/platform/cramium/update.rs @@ -110,7 +110,7 @@ pub fn process_update(perclk: u32) { crate::println!("waiting for button press"); let mut iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32); - let mut udma_global = udma::GlobalConfig::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32); + let mut udma_global = udma::GlobalConfig::new(); let iox_kbd = iox.clone(); let mut sh1107 = cramium_hal::sh1107::Oled128x128::new( @@ -394,9 +394,7 @@ pub fn process_update(perclk: u32) { ); progress_bar(&mut sh1107, 0); - let udma_global = GlobalConfig::new( - utralib::generated::HW_UDMA_CTRL_BASE as *mut u32, - ); + let udma_global = GlobalConfig::new(); // setup the I/O pins let iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32); diff --git a/services/cram-hal-service/src/main.rs b/services/cram-hal-service/src/main.rs index 759749148..41bce7648 100644 --- a/services/cram-hal-service/src/main.rs +++ b/services/cram-hal-service/src/main.rs @@ -185,14 +185,7 @@ fn main() { .expect("couldn't claim the IOX hardware page"); let iox = Iox::new(iox_page.as_ptr() as *mut u32); - let udma_global_csr = xous::syscall::map_memory( - xous::MemoryAddress::new(utralib::generated::HW_UDMA_CTRL_BASE), - None, - 4096, - xous::MemoryFlags::R | xous::MemoryFlags::W, - ) - .expect("couldn't map UDMA global control"); - let udma_global = GlobalConfig::new(udma_global_csr.as_mut_ptr() as *mut u32); + let udma_global = GlobalConfig::new(); // Note: the I2C handler can be put into a separate thread if we need the main // HAL server to not block while a large I2C transaction is being handled. For From c24bb3a4505fd552e41d2e61f464dc1c742d5c2b Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 02:42:25 +0800 Subject: [PATCH 02/27] add irq_status_bits() trait and enum for selecting Irq bank multiple IRQs related to the UDMA will eventually get mapped into the global IRQ handler for UDMA. Create an enum type that will help us differentiate this and add a trait that returns the raw bits for a given IRQ type. Probably a fancier wrapper should be made to interptet the IRQ bits but unfortunately there isn't a uniform pattern to the IRQ mappings, it's pretty much whatever fit into the IRQ space based on the underlying function. At the moment not even sure if this is the right register to be chasing, so we'll use this for probing that aspect and then get fancy later, maybe. --- libs/cramium-api/src/udma.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/cramium-api/src/udma.rs b/libs/cramium-api/src/udma.rs index cd23c7a53..b11550aad 100644 --- a/libs/cramium-api/src/udma.rs +++ b/libs/cramium-api/src/udma.rs @@ -233,6 +233,11 @@ pub enum EventChannel { Channel3 = 24, } +#[derive(Debug, Copy, Clone, num_derive::FromPrimitive)] +pub enum IrqBank { + I2c, +} + /// Use a trait that will allow us to share code between both `std` and `no-std` implementations pub trait UdmaGlobalConfig { fn clock(&self, peripheral: PeriphId, enable: bool); @@ -243,4 +248,5 @@ pub trait UdmaGlobalConfig { to_channel: EventChannel, ); fn reset(&self, peripheral: PeriphId); + fn irq_status_bits(&self, bank: IrqBank) -> u32; } From c48c97ebdda92eeaafe036048cf952aca8aeb32b Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 02:45:59 +0800 Subject: [PATCH 03/27] add the hal-side implementation this call works either on bare iron or in a xous context --- libs/cramium-hal/src/udma/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/cramium-hal/src/udma/mod.rs b/libs/cramium-hal/src/udma/mod.rs index 3bd8b60ad..8cb6ca337 100644 --- a/libs/cramium-hal/src/udma/mod.rs +++ b/libs/cramium-hal/src/udma/mod.rs @@ -165,6 +165,12 @@ impl UdmaGlobalConfig for GlobalConfig { } fn reset(&self, peripheral: PeriphId) { self.reset(peripheral); } + + fn irq_status_bits(&self, bank: IrqBank) -> u32 { + match bank { + IrqBank::I2c => self.i2c_irq.r(utralib::utra::irqarray7::EV_STATUS), + } + } } // --------------------------------- DMA channel ------------------------------------ pub(crate) const CFG_EN: u32 = 0b01_0000; // start a transfer From 2c99b32e5afb301d1ef42a849ef26d377f20ecd7 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 02:46:42 +0800 Subject: [PATCH 04/27] add an API opcode for messaging the cramium_hal_service in the Xous context, because the IRQ banks are owned by a global object, not every server can simply refer to the IRQ bits by just dereferencing a pointer. Instead, it needs to send a message to the cram_hal_service with an API number which then catches this and does the dereference on behalf of the caller. --- libs/cramium-api/src/api.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/cramium-api/src/api.rs b/libs/cramium-api/src/api.rs index 3eed7e1a8..7d2a073a0 100644 --- a/libs/cramium-api/src/api.rs +++ b/libs/cramium-api/src/api.rs @@ -36,6 +36,8 @@ pub enum HalOpcode { ConfigureUdmaClock = 7, // blocking scalar ConfigureUdmaEvent = 8, + // blocking scalar + UdmaIrqStatusBits = 16, /// I2C operations I2c = 9, From f3e7eec6cfb3dc930cdaa89505927ad88ba430cd Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 02:48:10 +0800 Subject: [PATCH 05/27] add 'lib' side code for sending the API call to cramium_hal_service this is the code that exists on the caller's side. It creates a message with the correct opcode and decodes the result. --- services/cram-hal-service/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/services/cram-hal-service/src/lib.rs b/services/cram-hal-service/src/lib.rs index 37082e724..2cda32d56 100644 --- a/services/cram-hal-service/src/lib.rs +++ b/services/cram-hal-service/src/lib.rs @@ -86,4 +86,20 @@ impl UdmaGlobalConfig for UdmaGlobal { } fn reset(&self, peripheral: PeriphId) { self.reset(peripheral); } + + fn irq_status_bits(&self, bank: IrqBank) -> u32 { + match xous::send_message( + self.conn, + xous::Message::new_blocking_scalar( + HalOpcode::UdmaIrqStatusBits.to_usize().unwrap(), + bank as u32 as usize, + 0, + 0, + 0, + ), + ) { + Ok(xous::Result::Scalar5(_, value, _, _, _)) => value as u32, + _ => panic!("Unhandled response on irq_status_bits"), + } + } } From 76a45ff47dee470a6dc0b199899b131f59e20a1b Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 02:48:58 +0800 Subject: [PATCH 06/27] add code to the server this is the actual handler inside the Xous service which, when receiving the opcode, dereferences its exclusive pointer to the IRQ bank and then returns the result to the caller. --- services/cram-hal-service/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/cram-hal-service/src/main.rs b/services/cram-hal-service/src/main.rs index 41bce7648..bce8a2e0c 100644 --- a/services/cram-hal-service/src/main.rs +++ b/services/cram-hal-service/src/main.rs @@ -5,6 +5,7 @@ use bitfield::*; use cramium_api::*; use cramium_hal::{iox::Iox, udma::GlobalConfig}; use num_traits::*; +use udma::UdmaGlobalConfig; use utralib::CSR; #[cfg(feature = "quantum-timer")] use utralib::utra; @@ -526,6 +527,13 @@ fn main() { udma_global.map_event_with_offset(periph, event_offset, to_channel); } } + HalOpcode::UdmaIrqStatusBits => { + if let Some(scalar) = msg.body.scalar_message_mut() { + let bank = num_traits::FromPrimitive::from_usize(scalar.arg1) + .expect("Bad argument to UdmaIrqStatusBits"); + scalar.arg1 = udma_global.irq_status_bits(bank) as usize; + } + } HalOpcode::PeriphReset => { if let Some(scalar) = msg.body.scalar_message() { let periph: PeriphId = num_traits::FromPrimitive::from_usize(scalar.arg1).unwrap(); From 73a171477277d1dc197c6de09e49b75a8948c148 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:46:14 +0800 Subject: [PATCH 07/27] Modify I2C API to accommodate Nack responses specifically --- libs/cramium-api/src/i2c.rs | 8 +++++--- libs/cramium-api/src/udma.rs | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/cramium-api/src/i2c.rs b/libs/cramium-api/src/i2c.rs index dc6498e4c..ed8e9f6f7 100644 --- a/libs/cramium-api/src/i2c.rs +++ b/libs/cramium-api/src/i2c.rs @@ -1,5 +1,5 @@ pub trait I2cApi { - fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result; + fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result; /// initiate an i2c read. The read buffer is passed during the await. fn i2c_read( @@ -8,7 +8,7 @@ pub trait I2cApi { adr: u8, buf: &mut [u8], repeated_start: bool, - ) -> Result; + ) -> Result; } #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] @@ -20,7 +20,7 @@ pub enum I2cTransactionType { } #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum I2cResult { /// For the outbound message holder Pending, @@ -28,6 +28,8 @@ pub enum I2cResult { Ack(usize), /// An error occurred. Nack, + /// An unhandled error has occurred. + InternalError, } #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] #[cfg(feature = "std")] diff --git a/libs/cramium-api/src/udma.rs b/libs/cramium-api/src/udma.rs index b11550aad..1e08f8180 100644 --- a/libs/cramium-api/src/udma.rs +++ b/libs/cramium-api/src/udma.rs @@ -236,6 +236,7 @@ pub enum EventChannel { #[derive(Debug, Copy, Clone, num_derive::FromPrimitive)] pub enum IrqBank { I2c, + I2cErr, } /// Use a trait that will allow us to share code between both `std` and `no-std` implementations From 34ae2011b22f3e5a7e941133c8a6414714d79923 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:47:16 +0800 Subject: [PATCH 08/27] sidequest - add some accessors to axp2101 object --- libs/cramium-hal/src/axp2101.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/cramium-hal/src/axp2101.rs b/libs/cramium-hal/src/axp2101.rs index 163331ad3..bc5e4ee29 100644 --- a/libs/cramium-hal/src/axp2101.rs +++ b/libs/cramium-hal/src/axp2101.rs @@ -213,6 +213,8 @@ impl Axp2101 { } } + pub fn get_dcdc(&mut self, which: WhichDcDc) -> (f32, bool) { self.dcdc_v_dvm[which as usize] } + pub fn set_ldo( &mut self, i2c: &mut dyn I2cApi, @@ -237,6 +239,10 @@ impl Axp2101 { } } + pub fn get_ldo(&mut self, which: WhichLdo) -> (f32, bool) { + (self.ldo_v[which as usize], self.ldo_ena[which as usize]) + } + fn encode_dcdc_ena(&self) -> u8 { let mut code = 0; for (i, &ena) in self.dcdc_ena.iter().enumerate() { From 09644f435a39b78af1e5ddd6a3fa0bdce670c3ee Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:54:10 +0800 Subject: [PATCH 09/27] add CSR bank for I2C error signals --- libs/cramium-hal/src/udma/mod.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/libs/cramium-hal/src/udma/mod.rs b/libs/cramium-hal/src/udma/mod.rs index 8cb6ca337..33fedc735 100644 --- a/libs/cramium-hal/src/udma/mod.rs +++ b/libs/cramium-hal/src/udma/mod.rs @@ -38,6 +38,7 @@ impl Into for GlobalReg { pub struct GlobalConfig { csr: SharedCsr, i2c_irq: SharedCsr, + i2c_err_irq: SharedCsr, } impl GlobalConfig { pub fn new() -> Self { @@ -65,7 +66,23 @@ impl GlobalConfig { #[cfg(not(target_os = "xous"))] let i2c_irq_addr = utralib::generated::HW_IRQARRAY7_BASE as *mut u32; - GlobalConfig { csr: SharedCsr::new(base_addr), i2c_irq: SharedCsr::new(i2c_irq_addr) } + #[cfg(target_os = "xous")] + let i2c_err_irq_addr = xous::syscall::map_memory( + xous::MemoryAddress::new(utralib::generated::HW_IRQARRAY12_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map I2C IRQ range") + .as_mut_ptr() as *mut u32; + #[cfg(not(target_os = "xous"))] + let i2c_err_irq_addr = utralib::generated::HW_IRQARRAY12_BASE as *mut u32; + + GlobalConfig { + csr: SharedCsr::new(base_addr), + i2c_irq: SharedCsr::new(i2c_irq_addr), + i2c_err_irq: SharedCsr::new(i2c_err_irq_addr), + } } pub fn clock_on(&self, peripheral: PeriphId) { @@ -168,7 +185,16 @@ impl UdmaGlobalConfig for GlobalConfig { fn irq_status_bits(&self, bank: IrqBank) -> u32 { match bank { - IrqBank::I2c => self.i2c_irq.r(utralib::utra::irqarray7::EV_STATUS), + IrqBank::I2c => { + let pending = self.i2c_irq.r(utralib::utra::irqarray7::EV_PENDING); + self.i2c_irq.wo(utralib::utra::irqarray7::EV_PENDING, pending); + pending + } + IrqBank::I2cErr => { + let pending = self.i2c_err_irq.r(utralib::utra::irqarray12::EV_PENDING); + self.i2c_err_irq.wo(utralib::utra::irqarray12::EV_PENDING, pending); + pending + } } } } From 1abf0430054f0eaf29fa440c529f3881f379092f Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:54:52 +0800 Subject: [PATCH 10/27] check NACK status in i2c_await routine; update bare metal API NACK bit is now checked after running the transaction, and if it is set an appropriate error code is returned. The trait implementation for i2c baremetal calls is also updated in this commit --- libs/cramium-hal/src/udma/i2c.rs | 68 +++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/libs/cramium-hal/src/udma/i2c.rs b/libs/cramium-hal/src/udma/i2c.rs index 264c3f3a5..1c03aab4b 100644 --- a/libs/cramium-hal/src/udma/i2c.rs +++ b/libs/cramium-hal/src/udma/i2c.rs @@ -263,6 +263,50 @@ impl<'a> I2c<'a> { xous::yield_slice(); } } + let nack_bits = self.udma_global.irq_status_bits(IrqBank::I2cErr); + match self.channel { + I2cChannel::Channel0 => { + if (nack_bits + & (utralib::utra::irqarray12::EV_STATUS_I2C0_NACK.mask() + << utralib::utra::irqarray12::EV_STATUS_I2C0_NACK.offset()) + as u32) + != 0 + { + return Err(xous::Error::Timeout); + } + } + I2cChannel::Channel1 => { + if (nack_bits + & (utralib::utra::irqarray12::EV_STATUS_I2C1_NACK.mask() + << utralib::utra::irqarray12::EV_STATUS_I2C1_NACK.offset()) + as u32) + != 0 + { + return Err(xous::Error::Timeout); + } + } + I2cChannel::Channel2 => { + if (nack_bits + & (utralib::utra::irqarray12::EV_STATUS_I2C2_NACK.mask() + << utralib::utra::irqarray12::EV_STATUS_I2C2_NACK.offset()) + as u32) + != 0 + { + return Err(xous::Error::Timeout); + } + } + I2cChannel::Channel3 => { + if (nack_bits + & (utralib::utra::irqarray12::EV_STATUS_I2C3_NACK.mask() + << utralib::utra::irqarray12::EV_STATUS_I2C3_NACK.offset()) + as u32) + != 0 + { + return Err(xous::Error::Timeout); + } + } + } + let ret = match self.pending.take() { I2cPending::Read(len) => { if let Some(buf) = rx_buf { @@ -458,13 +502,25 @@ impl I2cApi for I2c<'_> { adr: u8, buf: &mut [u8], repeated_start: bool, - ) -> Result { - self.i2c_read_async(dev, adr, buf.len(), repeated_start)?; - self.i2c_await(Some(buf), true) + ) -> Result { + match self.i2c_read_async(dev, adr, buf.len(), repeated_start) { + Err(_) => return Err(xous::Error::InternalError), + _ => (), + }; + match self.i2c_await(Some(buf), true) { + Ok(b) => Ok(I2cResult::Ack(b)), + _ => Ok(I2cResult::Nack), + } } - fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result { - self.i2c_write_async(dev, adr, data)?; - self.i2c_await(None, true) + fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result { + match self.i2c_write_async(dev, adr, data) { + Err(_) => return Err(xous::Error::InternalError), + _ => (), + }; + match self.i2c_await(None, true) { + Ok(b) => Ok(I2cResult::Ack(b)), + _ => Ok(I2cResult::Nack), + } } } From 63c1d975b44dca0cf41eccafd25c808b5315fe90 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:56:29 +0800 Subject: [PATCH 11/27] modify result interpretation to allow i2c nacks --- services/cram-hal-service/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/cram-hal-service/src/main.rs b/services/cram-hal-service/src/main.rs index bce8a2e0c..1959fb8ba 100644 --- a/services/cram-hal-service/src/main.rs +++ b/services/cram-hal-service/src/main.rs @@ -549,7 +549,7 @@ fn main() { match transaction.i2c_type { I2cTransactionType::Write => { match i2c.i2c_write(transaction.device, transaction.address, &transaction.data) { - Ok(b) => transaction.result = I2cResult::Ack(b), + Ok(result) => transaction.result = result, _ => transaction.result = I2cResult::Nack, } } @@ -560,7 +560,7 @@ fn main() { &mut transaction.data, transaction.i2c_type == I2cTransactionType::ReadRepeatedStart, ) { - Ok(b) => transaction.result = I2cResult::Ack(b), + Ok(result) => transaction.result = result, _ => transaction.result = I2cResult::Nack, } } From d17f9881b2269ff5270a055245613abd39847c38 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:56:51 +0800 Subject: [PATCH 12/27] modify user mode i2c lib calls to return nacks Note that a NACK is returned as an Ok(I2cResult::Nack) - this is because the Err() path is still reserved for "OS failure" errors. A Nack isn't a terminal failure, it is a recoverable fault, and so it's handled in the Ok() path. --- services/cram-hal-service/src/i2c_lib.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/services/cram-hal-service/src/i2c_lib.rs b/services/cram-hal-service/src/i2c_lib.rs index af511538e..609b6f981 100644 --- a/services/cram-hal-service/src/i2c_lib.rs +++ b/services/cram-hal-service/src/i2c_lib.rs @@ -33,7 +33,7 @@ impl I2cApi for I2c { adr: u8, buf: &mut [u8], repeated_start: bool, - ) -> Result { + ) -> Result { let r = I2cTransaction { i2c_type: if repeated_start { I2cTransactionType::ReadRepeatedStart @@ -46,16 +46,14 @@ impl I2cApi for I2c { result: I2cResult::Pending, }; let result = self.i2c_transactions(I2cTransactions::from(vec![r]))?; - match result.transactions[0].result { - I2cResult::Ack(b) => { - buf.copy_from_slice(&result.transactions[0].data); - Ok(b) - } - _ => Err(xous::Error::InternalError), + if result.transactions[0].result == I2cResult::InternalError { + Err(xous::Error::InternalError) + } else { + Ok(result.transactions[0].result) } } - fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result { + fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result { let w = I2cTransaction { i2c_type: I2cTransactionType::Write, device: dev, @@ -64,9 +62,10 @@ impl I2cApi for I2c { result: I2cResult::Pending, }; let result = self.i2c_transactions(I2cTransactions::from(vec![w]))?; - match result.transactions[0].result { - I2cResult::Ack(b) => Ok(b), - _ => Err(xous::Error::InternalError), + if result.transactions[0].result == I2cResult::InternalError { + Err(xous::Error::InternalError) + } else { + Ok(result.transactions[0].result) } } } From ea3b032fbe2c7c048a15c48f32de4135f45ddc8d Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 9 Jun 2025 16:37:47 +0800 Subject: [PATCH 13/27] add build flags to bao-console two flags are added: with-pddb - puts the PDDB commands into the console battery-readout - turns on the periodic battery readout --- services/bao-console/Cargo.toml | 4 +++- services/bao-console/src/cmds.rs | 5 +++++ services/bao-console/src/main.rs | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/services/bao-console/Cargo.toml b/services/bao-console/Cargo.toml index 9dc3130c2..ba2b1900a 100644 --- a/services/bao-console/Cargo.toml +++ b/services/bao-console/Cargo.toml @@ -50,7 +50,9 @@ hosted-baosec = [ "cramium-hal/hosted-baosec", ] usb = [] -pddbtest = [] +battery-readout = [] +with-pddb = [] +pddbtest = ["with-pddb"] test-rekey = [] autobasis = ["rand_chacha", "rand"] modal-testing = ["ux-api", "modals/modal-testing"] diff --git a/services/bao-console/src/cmds.rs b/services/bao-console/src/cmds.rs index 62cfc821c..df1e995c2 100644 --- a/services/bao-console/src/cmds.rs +++ b/services/bao-console/src/cmds.rs @@ -87,7 +87,9 @@ use trng_cmd::*; mod usb; #[cfg(feature = "usb")] use usb::*; +#[cfg(feature = "with-pddb")] mod pddb; +#[cfg(feature = "with-pddb")] use pddb::*; pub struct CmdEnv { @@ -97,6 +99,7 @@ pub struct CmdEnv { trng_cmd: TrngCmd, #[cfg(feature = "usb")] usb: Usb, + #[cfg(feature = "with-pddb")] pddb_cmd: PddbCmd, } impl CmdEnv { @@ -120,6 +123,7 @@ impl CmdEnv { }, #[cfg(feature = "usb")] usb: Usb::new(), + #[cfg(feature = "with-pddb")] pddb_cmd: PddbCmd::new(), } } @@ -142,6 +146,7 @@ impl CmdEnv { &mut console_cmd, #[cfg(feature = "usb")] &mut self.usb, + #[cfg(feature = "with-pddb")] &mut self.pddb_cmd, ]; diff --git a/services/bao-console/src/main.rs b/services/bao-console/src/main.rs index 1ffc9d201..cfc282e35 100644 --- a/services/bao-console/src/main.rs +++ b/services/bao-console/src/main.rs @@ -108,7 +108,7 @@ fn main() { modals::tests::spawn_test(); } - #[cfg(not(feature = "hosted-baosec"))] + #[cfg(feature = "battery-readout")] { use cramium_api::I2cApi; let mut i2c = cram_hal_service::I2c::new(); @@ -126,7 +126,7 @@ fn main() { } } } - #[cfg(feature = "hosted-baosec")] + #[cfg(any(feature = "hosted-baosec", not(feature = "battery-readout")))] loop { tt.sleep_ms(2_000).ok(); } From 526d8353fde54fcfc42f4ad2a106a4153421813a Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 2 Jun 2025 11:26:35 +0800 Subject: [PATCH 14/27] hello world exercise --- Cargo.lock | 17 +++-- services/bao-console/src/cmds.rs | 5 ++ services/bao-console/src/cmds/cute.rs | 92 +++++++++++++++++++++++++++ services/bao-console/src/cmds/pddb.rs | 1 + services/bao-console/src/main.rs | 14 ++-- xtask/src/main.rs | 3 +- 6 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 services/bao-console/src/cmds/cute.rs diff --git a/Cargo.lock b/Cargo.lock index 12cb31635..081eb6a2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1308,26 +1308,25 @@ dependencies = [ [[package]] name = "curve25519-dalek" version = "4.1.2" -source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#bef542a781348054c32a9beaf6bd1195814cace2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", - "engine25519-as", "fiat-crypto 0.2.7", - "log", + "platforms", "rustc_version 0.4.0", "subtle", - "utralib 0.1.25", - "xous 0.9.66 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize", ] [[package]] name = "curve25519-dalek-derive" version = "0.1.1" -source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#bef542a781348054c32a9beaf6bd1195814cace2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", @@ -4075,6 +4074,12 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +[[package]] +name = "platforms" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d43467300237085a4f9e864b937cf0bc012cef7740be12be1a48b10d2c8a3701" + [[package]] name = "plotters" version = "0.3.5" diff --git a/services/bao-console/src/cmds.rs b/services/bao-console/src/cmds.rs index df1e995c2..76ff189e0 100644 --- a/services/bao-console/src/cmds.rs +++ b/services/bao-console/src/cmds.rs @@ -91,6 +91,8 @@ use usb::*; mod pddb; #[cfg(feature = "with-pddb")] use pddb::*; +mod cute; +use cute::*; pub struct CmdEnv { common_env: CommonEnv, @@ -138,11 +140,14 @@ impl CmdEnv { let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions) let mut ver_cmd = Ver {}; let mut console_cmd = Test {}; + let mut cute_cmd = Cute{}; + let commands: &mut [&mut dyn ShellCmdApi] = &mut [ ///// 4. add your command to this array, so that it can be looked up and dispatched &mut echo_cmd, &mut ver_cmd, &mut self.trng_cmd, + &mut cute_cmd, &mut console_cmd, #[cfg(feature = "usb")] &mut self.usb, diff --git a/services/bao-console/src/cmds/cute.rs b/services/bao-console/src/cmds/cute.rs new file mode 100644 index 000000000..277a96022 --- /dev/null +++ b/services/bao-console/src/cmds/cute.rs @@ -0,0 +1,92 @@ +use String; + +use crate::{CommonEnv, ShellCmdApi}; + +#[derive(Debug)] +pub struct Cute {} + +impl<'a> ShellCmdApi<'a> for Cute { + cmd_api!(cute); + + fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result, xous::Error> { + use core::fmt::Write; + let mut ret = String::new(); + let helpstring = "Usage: + cute cat - prints cat ascii art + cute bread - prints bread ascii art + cute breadcat - prints breadcat ascii art"; + + let mut tokens = args.split_whitespace(); + + if let Some(sub_cmd) = tokens.next() { + match sub_cmd { + "cat" => { + let cat_art = r#" +⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⠀⠀⢀⣾⣿⣿⣿⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠐⠀⡀ +⠀⠀⠀⠀⢰⡿⠉⠀⡜⣿⣿⣿⡿⠿⢿⣿⣿⡃⠀⠀⠂⠄⠀ +⠀⠀⠒⠒⠸⣿⣄⡘⣃⣿⣿⡟⢰⠃⠀⢹⣿⡇⠀⠀⠀⠀⠀ +⠀⠀⠚⠉⠀⠊⠻⣿⣿⣿⣿⣿⣮⣤⣤⣿⡟⠁⠘⠠⠁⠀⠀ +⠀⠀⠀⠀⠀⠠⠀⠀⠈⠙⠛⠛⠛⠛⠛⠁⠀⠒⠤⠀⠀⠀⠀ +⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀ +⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +"#; + write!(ret, "{}", cat_art).unwrap(); + } + "bread" => { + let bread_art = r#" +⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣵⣾⣿⡿⠟⠛⠉⣉⣉⣉⣉⠉⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣿⡟⢁⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣿⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀ +⠀⢿⣿⣿⣿⣿⣿⣿⡄⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠈⠻⣿⣿⣿⣿⣿⣷⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠈⠻⣿⣿⣿⣿⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠙⢿⣿⠇⢰⣿⣿⣿⣿⡿⠛⢉⣩⣉⡉⠛⠻⠇⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠙⠀⠸⠿⠿⠟⢉⣠⣾⣿⣿⣿⣿⣷⣶⣦⣤⣄⣀⣀⡀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⣉⠉⠛⠛⠻⠿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀ +"#; + write!(ret, "{}", bread_art).unwrap(); + } + "breadcat" => { + let breadcat_art = r#" +⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢨⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⡟⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠙⣿⣷⣬⣿⣿⣿⣿⣿⣿⣿⡼⣿⣿⡟⣱⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣿⣧⣠⣿⣿⣿⣿⣿⣿⣿⣀⣾⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣅⣽⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠛⠙⠋⠋⠋⠋⠋⠋⠋⠋⠛⠙⠙⠁⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⢿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⣴⣶⣉⢿⣿⣿⣿⡟⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣆⡻⣿⣷⠜⣿⣏⣾⣿⣿⡿⠁⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⣿⣿⣽⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +"#; + write!(ret, "{}", breadcat_art).unwrap(); + } + _ => { + write!(ret, "{}\n", helpstring).unwrap(); + } + } + } else { + write!(ret, "{}\n", helpstring).unwrap(); + } + + Ok(Some(ret)) +} + + +} \ No newline at end of file diff --git a/services/bao-console/src/cmds/pddb.rs b/services/bao-console/src/cmds/pddb.rs index 0945ee357..6c06637be 100644 --- a/services/bao-console/src/cmds/pddb.rs +++ b/services/bao-console/src/cmds/pddb.rs @@ -15,6 +15,7 @@ pub struct PddbCmd { } impl PddbCmd { pub fn new() -> Self { + log::info!("here"); let pddb = pddb::Pddb::new(); log::info!("PDDB mount result: {:?}", pddb.try_mount()); PddbCmd { pddb } diff --git a/services/bao-console/src/main.rs b/services/bao-console/src/main.rs index cfc282e35..40b635705 100644 --- a/services/bao-console/src/main.rs +++ b/services/bao-console/src/main.rs @@ -117,13 +117,13 @@ fn main() { let mut buf = [0u8, 0u8]; loop { tt.sleep_ms(2_000).ok(); - for (name, offset) in measurements { - i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap(); - let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32; - log::info!("{}: {:0.3}V", name, v as f32 / 1000.0); - i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap(); - log::info!("SOC: {}%", buf[0]); - } + // for (name, offset) in measurements { + // i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap(); + // let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32; + // log::info!("{}: {:0.3}V", name, v as f32 / 1000.0); + // i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap(); + // log::info!("SOC: {}%", buf[0]); + // } } } #[cfg(any(feature = "hosted-baosec", not(feature = "battery-readout")))] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index afd85b59c..79b617517 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -612,13 +612,14 @@ fn main() -> Result<(), Box> { // - [planned] vault application let bao_rram_pkgs = ["xous-ticktimer", "xous-log", "xous-names", "keystore" /* "usb-cramium" */].to_vec(); /* "usb-cramium" */ - let bao_swap_pkgs = ["cram-hal-service", "bao-console", "modals", "pddb", "bao-video"].to_vec(); /* "bao-video" */ + let bao_swap_pkgs = ["cram-hal-service", "bao-console", /*"modals", "pddb", "bao-video"*/].to_vec(); /* "bao-video" */ if !builder.is_swap_set() { builder.set_swap(0, 8 * 1024 * 1024); } builder.add_loader_feature("swap"); builder.add_kernel_feature("swap"); builder.add_feature("swap"); + // builder.add_feature("autotest"); builder.add_loader_feature("debug-print"); // the following feature needs to be uncommented if we also enable From 0d0267f0ea3c3de43d3e50ae304971dc2d8bc316 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 6 Jun 2025 16:45:00 +0800 Subject: [PATCH 15/27] scaffolding the i2cdetect command --- Cargo.lock | 17 ++++++----------- services/bao-console/src/cmds.rs | 8 ++++---- .../src/cmds/{cute.rs => i2cdetect.rs} | 12 ++++++------ 3 files changed, 16 insertions(+), 21 deletions(-) rename services/bao-console/src/cmds/{cute.rs => i2cdetect.rs} (95%) diff --git a/Cargo.lock b/Cargo.lock index 081eb6a2e..12cb31635 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1308,25 +1308,26 @@ dependencies = [ [[package]] name = "curve25519-dalek" version = "4.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#bef542a781348054c32a9beaf6bd1195814cace2" dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", + "engine25519-as", "fiat-crypto 0.2.7", - "platforms", + "log", "rustc_version 0.4.0", "subtle", + "utralib 0.1.25", + "xous 0.9.66 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize", ] [[package]] name = "curve25519-dalek-derive" version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#bef542a781348054c32a9beaf6bd1195814cace2" dependencies = [ "proc-macro2", "quote", @@ -4074,12 +4075,6 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" -[[package]] -name = "platforms" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d43467300237085a4f9e864b937cf0bc012cef7740be12be1a48b10d2c8a3701" - [[package]] name = "plotters" version = "0.3.5" diff --git a/services/bao-console/src/cmds.rs b/services/bao-console/src/cmds.rs index 76ff189e0..e93af6b59 100644 --- a/services/bao-console/src/cmds.rs +++ b/services/bao-console/src/cmds.rs @@ -91,8 +91,8 @@ use usb::*; mod pddb; #[cfg(feature = "with-pddb")] use pddb::*; -mod cute; -use cute::*; +mod i2cdetect; +use i2cdetect:*; pub struct CmdEnv { common_env: CommonEnv, @@ -140,14 +140,14 @@ impl CmdEnv { let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions) let mut ver_cmd = Ver {}; let mut console_cmd = Test {}; - let mut cute_cmd = Cute{}; + let mut i2cdetect_cmd = I2cdetect{}; let commands: &mut [&mut dyn ShellCmdApi] = &mut [ ///// 4. add your command to this array, so that it can be looked up and dispatched &mut echo_cmd, &mut ver_cmd, &mut self.trng_cmd, - &mut cute_cmd, + &mut i2cdetect_cmd, &mut console_cmd, #[cfg(feature = "usb")] &mut self.usb, diff --git a/services/bao-console/src/cmds/cute.rs b/services/bao-console/src/cmds/i2cdetect.rs similarity index 95% rename from services/bao-console/src/cmds/cute.rs rename to services/bao-console/src/cmds/i2cdetect.rs index 277a96022..d8a861024 100644 --- a/services/bao-console/src/cmds/cute.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -3,18 +3,18 @@ use String; use crate::{CommonEnv, ShellCmdApi}; #[derive(Debug)] -pub struct Cute {} +pub struct I2cDetect {} -impl<'a> ShellCmdApi<'a> for Cute { - cmd_api!(cute); +impl<'a> ShellCmdApi<'a> for I2cDetect { + cmd_api!(cui; fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result, xous::Error> { use core::fmt::Write; let mut ret = String::new(); let helpstring = "Usage: - cute cat - prints cat ascii art - cute bread - prints bread ascii art - cute breadcat - prints breadcat ascii art"; + i2cdetect cat - prints cat ascii art + i2cdetect bread - prints bread ascii art + i2cdetect breadcat - prints breadcat ascii art"; let mut tokens = args.split_whitespace(); From b0b29f7d78c5b435c6e015dedc263c36a3338248 Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Fri, 6 Jun 2025 17:39:59 +0800 Subject: [PATCH 16/27] reestablishing devenv --- Cargo.lock | 17 +++++++++++------ services/bao-console/src/cmds.rs | 4 ++-- services/bao-console/src/cmds/i2cdetect.rs | 8 ++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12cb31635..32211957c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1308,26 +1308,25 @@ dependencies = [ [[package]] name = "curve25519-dalek" version = "4.1.2" -source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#bef542a781348054c32a9beaf6bd1195814cace2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ "cfg-if", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", - "engine25519-as", "fiat-crypto 0.2.7", - "log", + "platforms", "rustc_version 0.4.0", "subtle", - "utralib 0.1.25", - "xous 0.9.66 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize", ] [[package]] name = "curve25519-dalek-derive" version = "0.1.1" -source = "git+https://github.com/betrusted-io/curve25519-dalek.git?branch=main#bef542a781348054c32a9beaf6bd1195814cace2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", @@ -4075,6 +4074,12 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +[[package]] +name = "platforms" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b02ffed1bc8c2234bb6f8e760e34613776c5102a041f25330b869a78153a68c" + [[package]] name = "plotters" version = "0.3.5" diff --git a/services/bao-console/src/cmds.rs b/services/bao-console/src/cmds.rs index e93af6b59..f425055ce 100644 --- a/services/bao-console/src/cmds.rs +++ b/services/bao-console/src/cmds.rs @@ -92,7 +92,7 @@ mod pddb; #[cfg(feature = "with-pddb")] use pddb::*; mod i2cdetect; -use i2cdetect:*; +use i2cdetect::*; pub struct CmdEnv { common_env: CommonEnv, @@ -140,7 +140,7 @@ impl CmdEnv { let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions) let mut ver_cmd = Ver {}; let mut console_cmd = Test {}; - let mut i2cdetect_cmd = I2cdetect{}; + let mut i2cdetect_cmd = I2cDetect{}; let commands: &mut [&mut dyn ShellCmdApi] = &mut [ ///// 4. add your command to this array, so that it can be looked up and dispatched diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index d8a861024..2a2c5ff97 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -6,15 +6,15 @@ use crate::{CommonEnv, ShellCmdApi}; pub struct I2cDetect {} impl<'a> ShellCmdApi<'a> for I2cDetect { - cmd_api!(cui; + cmd_api!(i2cdetect); fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result, xous::Error> { use core::fmt::Write; let mut ret = String::new(); let helpstring = "Usage: - i2cdetect cat - prints cat ascii art - i2cdetect bread - prints bread ascii art - i2cdetect breadcat - prints breadcat ascii art"; + i2cdetect cat - prints cat ascii art + i2cdetect bread - prints bread ascii art + i2cdetect breadcat - prints breadcat ascii art"; let mut tokens = args.split_whitespace(); From b35f9cad33cd878f71e538b2ef81d3526290799b Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Sat, 7 Jun 2025 11:17:00 +0800 Subject: [PATCH 17/27] working read --- services/bao-console/src/cmds/i2cdetect.rs | 160 ++++++++++++++------- 1 file changed, 112 insertions(+), 48 deletions(-) diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index 2a2c5ff97..cd67de50e 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -1,4 +1,8 @@ use String; +use cramium_api::I2cApi; +use cram_hal_service::I2c; +use std::thread::sleep; +use std::time::Duration; use crate::{CommonEnv, ShellCmdApi}; @@ -14,69 +18,129 @@ impl<'a> ShellCmdApi<'a> for I2cDetect { let helpstring = "Usage: i2cdetect cat - prints cat ascii art i2cdetect bread - prints bread ascii art - i2cdetect breadcat - prints breadcat ascii art"; + i2cdetect breadcat - prints breadcat ascii art + i2cdetect probe - probes a single I2C address (e.g. 34) + i2cdetect bmptemp - reads raw temperature from BMP180"; let mut tokens = args.split_whitespace(); if let Some(sub_cmd) = tokens.next() { match sub_cmd { "cat" => { - let cat_art = r#" -⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⠀⠀⢀⣾⣿⣿⣿⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠐⠀⡀ -⠀⠀⠀⠀⢰⡿⠉⠀⡜⣿⣿⣿⡿⠿⢿⣿⣿⡃⠀⠀⠂⠄⠀ -⠀⠀⠒⠒⠸⣿⣄⡘⣃⣿⣿⡟⢰⠃⠀⢹⣿⡇⠀⠀⠀⠀⠀ -⠀⠀⠚⠉⠀⠊⠻⣿⣿⣿⣿⣿⣮⣤⣤⣿⡟⠁⠘⠠⠁⠀⠀ -⠀⠀⠀⠀⠀⠠⠀⠀⠈⠙⠛⠛⠛⠛⠛⠁⠀⠒⠤⠀⠀⠀⠀ -⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀ -⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -"#; + let cat_art = r#"f + ⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⠀⠀⢀⣾⣿⣿⣿⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠐⠀⡀ + ⠀⠀⠀⠀⢰⡿⠉⠀⡜⣿⣿⣿⡿⠿⢿⣿⣿⡃⠀⠀⠂⠄⠀ + ⠀⠀⠒⠒⠸⣿⣄⡘⣃⣿⣿⡟⢰⠃⠀⢹⣿⡇⠀⠀⠀⠀⠀ + ⠀⠀⠚⠉⠀⠊⠻⣿⣿⣿⣿⣿⣮⣤⣤⣿⡟⠁⠘⠠⠁⠀⠀ + ⠀⠀⠀⠀⠀⠠⠀⠀⠈⠙⠛⠛⠛⠛⠛⠁⠀⠒⠤⠀⠀⠀⠀ + ⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀ + ⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + "#; write!(ret, "{}", cat_art).unwrap(); } "bread" => { let bread_art = r#" -⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⢸⣿⣿⣿⣿⣿⣵⣾⣿⡿⠟⠛⠉⣉⣉⣉⣉⠉⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⢸⣿⣿⣿⣿⣿⣿⡟⢁⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⢸⣿⣿⣿⣿⣿⣿⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀ -⠀⢿⣿⣿⣿⣿⣿⣿⡄⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠈⠻⣿⣿⣿⣿⣿⣷⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠈⠻⣿⣿⣿⣿⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠙⢿⣿⠇⢰⣿⣿⣿⣿⡿⠛⢉⣩⣉⡉⠛⠻⠇⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠙⠀⠸⠿⠿⠟⢉⣠⣾⣿⣿⣿⣿⣷⣶⣦⣤⣄⣀⣀⡀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⣉⠉⠛⠛⠻⠿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀ -"#; + ⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⢸⣿⣿⣿⣿⣿⣵⣾⣿⡿⠟⠛⠉⣉⣉⣉⣉⠉⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⢸⣿⣿⣿⣿⣿⣿⡟⢁⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⢸⣿⣿⣿⣿⣿⣿⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀ + ⠀⢿⣿⣿⣿⣿⣿⣿⡄⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠈⠻⣿⣿⣿⣿⣿⣷⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠈⠻⣿⣿⣿⣿⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠙⢿⣿⠇⢰⣿⣿⣿⣿⡿⠛⢉⣩⣉⡉⠛⠻⠇⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠙⠀⠸⠿⠿⠟⢉⣠⣾⣿⣿⣿⣿⣷⣶⣦⣤⣄⣀⣀⡀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⣉⠉⠛⠛⠻⠿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀ + "#; write!(ret, "{}", bread_art).unwrap(); } "breadcat" => { let breadcat_art = r#" -⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢨⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⡟⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠙⣿⣷⣬⣿⣿⣿⣿⣿⣿⣿⡼⣿⣿⡟⣱⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⣿⣧⣠⣿⣿⣿⣿⣿⣿⣿⣀⣾⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣅⣽⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠛⠙⠋⠋⠋⠋⠋⠋⠋⠋⠛⠙⠙⠁⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⢿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⣴⣶⣉⢿⣿⣿⣿⡟⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣆⡻⣿⣷⠜⣿⣏⣾⣿⣿⡿⠁⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⣿⣿⣽⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀ -⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -"#; + ⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢨⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⡟⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠙⣿⣷⣬⣿⣿⣿⣿⣿⣿⣿⡼⣿⣿⡟⣱⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣿⣧⣠⣿⣿⣿⣿⣿⣿⣿⣀⣾⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣅⣽⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠛⠙⠋⠋⠋⠋⠋⠋⠋⠋⠛⠙⠙⠁⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⢿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⣴⣶⣉⢿⣿⣿⣿⡟⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣆⡻⣿⣷⠜⣿⣏⣾⣿⣿⡿⠁⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⣿⣿⣽⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀ + ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ + "#; write!(ret, "{}", breadcat_art).unwrap(); } + + "probe" => { + if let Some(addr_str) = tokens.next() { + match u8::from_str_radix(addr_str, 16) { + Ok(addr) => { + let mut i2c = I2c::new(); + let mut buf = [0u8; 1]; + match i2c.i2c_read(addr, 0x00, &mut buf, false) { + Ok(_) => { + write!(ret, "Device found at address {:02X} (via read)\n", addr).unwrap(); + } + Err(xous::Error::InternalError) => { + write!(ret, "No device found at address {:02X}\n", addr).unwrap(); + } + Err(e) => { + write!(ret, "Error probing address {:02X}: {:?}\n", addr, e).unwrap(); + } + } + } + Err(_) => { + write!(ret, "Invalid hex address '{}'. Example: i2cdetect probe 3C\n", addr_str).unwrap(); + } + } + } else { + write!(ret, "Usage: i2cdetect probe \n").unwrap(); + } + } + + "bmptemp" => { + const BMP180_ADDR: u8 = 0x77; + const REG_CTRL: u8 = 0xF4; + const REG_DATA_START: u8 = 0xF6; + const CMD_READ_TEMP: u8 = 0x2E; + + let mut i2c = I2c::new(); + + match i2c.i2c_write(BMP180_ADDR, REG_CTRL, &[CMD_READ_TEMP]) { + Ok(_) => { + sleep(Duration::from_millis(5)); + + + let mut temp_buffer = [0u8; 2]; + match i2c.i2c_read(BMP180_ADDR, REG_DATA_START, &mut temp_buffer, true) { + Ok(_) => { + let uncalibrated_temp = i16::from_be_bytes(temp_buffer); + write!(ret, "BMP180 raw temp: {}\n", uncalibrated_temp).unwrap(); + } + Err(e) => { + write!(ret, "Failed to read temp data: {:?}\n", e).unwrap(); + } + } + } + Err(e) => { + write!(ret, "Failed to write command to BMP180 (is it connected @ 0x77?): {:?}\n", e).unwrap(); + } + } + } + _ => { write!(ret, "{}\n", helpstring).unwrap(); } @@ -86,7 +150,7 @@ impl<'a> ShellCmdApi<'a> for I2cDetect { } Ok(Some(ret)) -} + } } \ No newline at end of file From 916c93e2769526c324e4a4f357c322afb0aa68c3 Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Sat, 7 Jun 2025 11:55:14 +0800 Subject: [PATCH 18/27] now with SI units --- services/bao-console/src/cmds/i2cdetect.rs | 68 ++++++++++++++++------ 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index cd67de50e..d949582a4 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -7,7 +7,14 @@ use std::time::Duration; use crate::{CommonEnv, ShellCmdApi}; #[derive(Debug)] + pub struct I2cDetect {} +struct Bmp180Calibration { + ac1: i16, ac2: i16, ac3: i16, + ac4: u16, ac5: u16, ac6: u16, + b1: i16, b2: i16, + mb: i16, mc: i16, md: i16, +} impl<'a> ShellCmdApi<'a> for I2cDetect { cmd_api!(i2cdetect); @@ -113,32 +120,55 @@ impl<'a> ShellCmdApi<'a> for I2cDetect { "bmptemp" => { const BMP180_ADDR: u8 = 0x77; + const REG_CALIB_START: u8 = 0xAA; const REG_CTRL: u8 = 0xF4; const REG_DATA_START: u8 = 0xF6; const CMD_READ_TEMP: u8 = 0x2E; let mut i2c = I2c::new(); - match i2c.i2c_write(BMP180_ADDR, REG_CTRL, &[CMD_READ_TEMP]) { - Ok(_) => { - sleep(Duration::from_millis(5)); - - - let mut temp_buffer = [0u8; 2]; - match i2c.i2c_read(BMP180_ADDR, REG_DATA_START, &mut temp_buffer, true) { - Ok(_) => { - let uncalibrated_temp = i16::from_be_bytes(temp_buffer); - write!(ret, "BMP180 raw temp: {}\n", uncalibrated_temp).unwrap(); - } - Err(e) => { - write!(ret, "Failed to read temp data: {:?}\n", e).unwrap(); - } - } - } - Err(e) => { - write!(ret, "Failed to write command to BMP180 (is it connected @ 0x77?): {:?}\n", e).unwrap(); - } + let mut cal_buf = [0u8; 22]; + if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_CALIB_START, &mut cal_buf, true) { + write!(ret, "Failed to read calibration data: {:?}\n", e).unwrap(); + return Ok(Some(ret)); } + + // note: calibration data is Big Endian, hence the from_be_bytes + let cal = Bmp180Calibration { + ac1: i16::from_be_bytes([cal_buf[0], cal_buf[1]]), + ac2: i16::from_be_bytes([cal_buf[2], cal_buf[3]]), + ac3: i16::from_be_bytes([cal_buf[4], cal_buf[5]]), + ac4: u16::from_be_bytes([cal_buf[6], cal_buf[7]]), + ac5: u16::from_be_bytes([cal_buf[8], cal_buf[9]]), + ac6: u16::from_be_bytes([cal_buf[10], cal_buf[11]]), + b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]), + b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]), + mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]), + mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]), + md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]), + }; + + + if let Err(e) = i2c.i2c_write(BMP180_ADDR, REG_CTRL, &[CMD_READ_TEMP]) { + write!(ret, "Failed to start temp measurement: {:?}\n", e).unwrap(); + return Ok(Some(ret)); + } + + sleep(Duration::from_millis(5)); + + let mut temp_buffer = [0u8; 2]; + if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_DATA_START, &mut temp_buffer, true) { + write!(ret, "Failed to read temp data: {:?}\n", e).unwrap(); + return Ok(Some(ret)); + } + let ut = i16::from_be_bytes(temp_buffer) as i32; + + let x1 = (ut - cal.ac6 as i32) * cal.ac5 as i32 >> 15; + let x2 = (cal.mc as i32 * 2048) / (x1 + cal.md as i32); + let b5 = x1 + x2; + let temp = ((b5 + 8) >> 4) as f32 / 10.0; + + write!(ret, "BMP180 Temperature: {:.1}°C\n", temp).unwrap(); } _ => { From 1b8554b8f2c11a40808390c33ee201437a898cf9 Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 9 Jun 2025 16:10:42 +0800 Subject: [PATCH 19/27] removing the BMP180 code --- services/bao-console/src/cmds/i2cdetect.rs | 195 ++++++--------------- services/bao-console/src/main.rs | 10 +- 2 files changed, 59 insertions(+), 146 deletions(-) diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index d949582a4..32e3cf139 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -1,21 +1,31 @@ use String; use cramium_api::I2cApi; +use cramium_api::I2cResult; use cram_hal_service::I2c; -use std::thread::sleep; -use std::time::Duration; use crate::{CommonEnv, ShellCmdApi}; #[derive(Debug)] -pub struct I2cDetect {} -struct Bmp180Calibration { - ac1: i16, ac2: i16, ac3: i16, - ac4: u16, ac5: u16, ac6: u16, - b1: i16, b2: i16, - mb: i16, mc: i16, md: i16, +enum ProbeStatus { + Ack, + Nack, } +fn probe_address(i2c: &mut I2c, addr: u8) -> ProbeStatus { + let mut buf = [0u8; 1]; + match i2c.i2c_read(addr, 0x00, &mut buf, false) { + Ok(I2cResult::Ack(_)) => ProbeStatus::Ack, + Ok(I2cResult::Nack) => ProbeStatus::Nack, + Ok(I2cResult::Pending) => panic!("Unexpected I2cResult::Pending: this operation should be blocking."), + Ok(I2cResult::InternalError) => panic!("Unexpected Ok(I2cResult::InternalError)."), + Err(e) => panic!("I2C bus error while probing address 0x{:02X}: {:?}", addr, e), + } +} + + +pub struct I2cDetect {} + impl<'a> ShellCmdApi<'a> for I2cDetect { cmd_api!(i2cdetect); @@ -23,154 +33,57 @@ impl<'a> ShellCmdApi<'a> for I2cDetect { use core::fmt::Write; let mut ret = String::new(); let helpstring = "Usage: - i2cdetect cat - prints cat ascii art - i2cdetect bread - prints bread ascii art - i2cdetect breadcat - prints breadcat ascii art - i2cdetect probe - probes a single I2C address (e.g. 34) - i2cdetect bmptemp - reads raw temperature from BMP180"; + i2cdetect probe - probes a single I2C address (e.g. 34) + i2cdetect scan - reads + i2cdetect bmp180_temp - reads raw temperature from BMP180"; let mut tokens = args.split_whitespace(); if let Some(sub_cmd) = tokens.next() { match sub_cmd { - "cat" => { - let cat_art = r#"f - ⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⠀⠀⢀⣾⣿⣿⣿⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠐⠀⡀ - ⠀⠀⠀⠀⢰⡿⠉⠀⡜⣿⣿⣿⡿⠿⢿⣿⣿⡃⠀⠀⠂⠄⠀ - ⠀⠀⠒⠒⠸⣿⣄⡘⣃⣿⣿⡟⢰⠃⠀⢹⣿⡇⠀⠀⠀⠀⠀ - ⠀⠀⠚⠉⠀⠊⠻⣿⣿⣿⣿⣿⣮⣤⣤⣿⡟⠁⠘⠠⠁⠀⠀ - ⠀⠀⠀⠀⠀⠠⠀⠀⠈⠙⠛⠛⠛⠛⠛⠁⠀⠒⠤⠀⠀⠀⠀ - ⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀ - ⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - "#; - write!(ret, "{}", cat_art).unwrap(); - } - "bread" => { - let bread_art = r#" - ⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⢸⣿⣿⣿⣿⣿⣵⣾⣿⡿⠟⠛⠉⣉⣉⣉⣉⠉⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⢸⣿⣿⣿⣿⣿⣿⡟⢁⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⢸⣿⣿⣿⣿⣿⣿⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀ - ⠀⢿⣿⣿⣿⣿⣿⣿⡄⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠈⠻⣿⣿⣿⣿⣿⣷⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠈⠻⣿⣿⣿⣿⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠙⢿⣿⠇⢰⣿⣿⣿⣿⡿⠛⢉⣩⣉⡉⠛⠻⠇⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠙⠀⠸⠿⠿⠟⢉⣠⣾⣿⣿⣿⣿⣷⣶⣦⣤⣄⣀⣀⡀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⣉⠉⠛⠛⠻⠿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀ - "#; - write!(ret, "{}", bread_art).unwrap(); - } - "breadcat" => { - let breadcat_art = r#" - ⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢨⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⡟⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠙⣿⣷⣬⣿⣿⣿⣿⣿⣿⣿⡼⣿⣿⡟⣱⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⣿⣧⣠⣿⣿⣿⣿⣿⣿⣿⣀⣾⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣅⣽⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠛⠙⠋⠋⠋⠋⠋⠋⠋⠋⠛⠙⠙⠁⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⢿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⣴⣶⣉⢿⣿⣿⣿⡟⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣆⡻⣿⣷⠜⣿⣏⣾⣿⣿⡿⠁⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⣿⣿⣽⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀ - ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ - "#; - write!(ret, "{}", breadcat_art).unwrap(); - } - "probe" => { - if let Some(addr_str) = tokens.next() { - match u8::from_str_radix(addr_str, 16) { - Ok(addr) => { - let mut i2c = I2c::new(); - let mut buf = [0u8; 1]; - match i2c.i2c_read(addr, 0x00, &mut buf, false) { - Ok(_) => { - write!(ret, "Device found at address {:02X} (via read)\n", addr).unwrap(); - } - Err(xous::Error::InternalError) => { - write!(ret, "No device found at address {:02X}\n", addr).unwrap(); - } - Err(e) => { - write!(ret, "Error probing address {:02X}: {:?}\n", addr, e).unwrap(); - } + if let Some(addr_str) = tokens.next() { + match u8::from_str_radix(addr_str, 16) { + Ok(addr) => { + let mut i2c = I2c::new(); + let status = probe_address(&mut i2c, addr); + match status { + ProbeStatus::Ack => write!(ret, "Device found at address {:02X}\n", addr).unwrap(), + ProbeStatus::Nack => write!(ret, "Device at address {:02X} responded with NACK\n", addr).unwrap(), + }; + } + Err(_) => { + write!(ret, "Invalid hex address '{}'. Example: i2cdetect probe 3C\n", addr_str).unwrap(); } } - Err(_) => { - write!(ret, "Invalid hex address '{}'. Example: i2cdetect probe 3C\n", addr_str).unwrap(); - } + } else { + write!(ret, "Usage: i2cdetect probe \n").unwrap(); } - } else { - write!(ret, "Usage: i2cdetect probe \n").unwrap(); } - } - - "bmptemp" => { - const BMP180_ADDR: u8 = 0x77; - const REG_CALIB_START: u8 = 0xAA; - const REG_CTRL: u8 = 0xF4; - const REG_DATA_START: u8 = 0xF6; - const CMD_READ_TEMP: u8 = 0x2E; + "scan" => { let mut i2c = I2c::new(); - - let mut cal_buf = [0u8; 22]; - if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_CALIB_START, &mut cal_buf, true) { - write!(ret, "Failed to read calibration data: {:?}\n", e).unwrap(); - return Ok(Some(ret)); + writeln!(&mut ret, " 0 1 2 3 4 5 6 7 8 9 a b c d e f").unwrap(); + for row in 0..8 { + write!(&mut ret, "{:02x}: ", row * 16).unwrap(); + for col in 0..16 { + let addr = (row * 16 + col) as u8; + if addr < 0x03 || addr > 0x77 { + write!(&mut ret, " ").unwrap(); + } else { + let status = probe_address(&mut i2c, addr); + match status { + ProbeStatus::Ack => write!(&mut ret, "{:02x} ", addr).unwrap(), + ProbeStatus::Nack => write!(&mut ret, "-- ").unwrap(), + }; + } + } + writeln!(&mut ret).unwrap(); } - - // note: calibration data is Big Endian, hence the from_be_bytes - let cal = Bmp180Calibration { - ac1: i16::from_be_bytes([cal_buf[0], cal_buf[1]]), - ac2: i16::from_be_bytes([cal_buf[2], cal_buf[3]]), - ac3: i16::from_be_bytes([cal_buf[4], cal_buf[5]]), - ac4: u16::from_be_bytes([cal_buf[6], cal_buf[7]]), - ac5: u16::from_be_bytes([cal_buf[8], cal_buf[9]]), - ac6: u16::from_be_bytes([cal_buf[10], cal_buf[11]]), - b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]), - b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]), - mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]), - mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]), - md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]), - }; - - - if let Err(e) = i2c.i2c_write(BMP180_ADDR, REG_CTRL, &[CMD_READ_TEMP]) { - write!(ret, "Failed to start temp measurement: {:?}\n", e).unwrap(); - return Ok(Some(ret)); - } - - sleep(Duration::from_millis(5)); - - let mut temp_buffer = [0u8; 2]; - if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_DATA_START, &mut temp_buffer, true) { - write!(ret, "Failed to read temp data: {:?}\n", e).unwrap(); - return Ok(Some(ret)); - } - let ut = i16::from_be_bytes(temp_buffer) as i32; - - let x1 = (ut - cal.ac6 as i32) * cal.ac5 as i32 >> 15; - let x2 = (cal.mc as i32 * 2048) / (x1 + cal.md as i32); - let b5 = x1 + x2; - let temp = ((b5 + 8) >> 4) as f32 / 10.0; - - write!(ret, "BMP180 Temperature: {:.1}°C\n", temp).unwrap(); } + + _ => { write!(ret, "{}\n", helpstring).unwrap(); } diff --git a/services/bao-console/src/main.rs b/services/bao-console/src/main.rs index 40b635705..4f40e6079 100644 --- a/services/bao-console/src/main.rs +++ b/services/bao-console/src/main.rs @@ -110,11 +110,11 @@ fn main() { #[cfg(feature = "battery-readout")] { - use cramium_api::I2cApi; - let mut i2c = cram_hal_service::I2c::new(); - use cramium_hal::axp2101::*; - let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)]; - let mut buf = [0u8, 0u8]; + // use cramium_api::I2cApi; + // let mut i2c = cram_hal_service::I2c::new(); + // use cramium_hal::axp2101::*; + // let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)]; + // let mut buf = [0u8, 0u8]; loop { tt.sleep_ms(2_000).ok(); // for (name, offset) in measurements { From e5cdeaf2ca74a85db02077cc367824ea3095d9f0 Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 9 Jun 2025 16:18:56 +0800 Subject: [PATCH 20/27] adding some cute command line arguments --- services/bao-console/src/cmds.rs | 4 ++ services/bao-console/src/cmds/cute.rs | 92 +++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 services/bao-console/src/cmds/cute.rs diff --git a/services/bao-console/src/cmds.rs b/services/bao-console/src/cmds.rs index f425055ce..c73fa4c98 100644 --- a/services/bao-console/src/cmds.rs +++ b/services/bao-console/src/cmds.rs @@ -93,6 +93,8 @@ mod pddb; use pddb::*; mod i2cdetect; use i2cdetect::*; +mod cute; +use cute::*; pub struct CmdEnv { common_env: CommonEnv, @@ -141,6 +143,7 @@ impl CmdEnv { let mut ver_cmd = Ver {}; let mut console_cmd = Test {}; let mut i2cdetect_cmd = I2cDetect{}; + let mut cute_cmd = Cute{}; let commands: &mut [&mut dyn ShellCmdApi] = &mut [ ///// 4. add your command to this array, so that it can be looked up and dispatched @@ -148,6 +151,7 @@ impl CmdEnv { &mut ver_cmd, &mut self.trng_cmd, &mut i2cdetect_cmd, + &mut cute_cmd, &mut console_cmd, #[cfg(feature = "usb")] &mut self.usb, diff --git a/services/bao-console/src/cmds/cute.rs b/services/bao-console/src/cmds/cute.rs new file mode 100644 index 000000000..277a96022 --- /dev/null +++ b/services/bao-console/src/cmds/cute.rs @@ -0,0 +1,92 @@ +use String; + +use crate::{CommonEnv, ShellCmdApi}; + +#[derive(Debug)] +pub struct Cute {} + +impl<'a> ShellCmdApi<'a> for Cute { + cmd_api!(cute); + + fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result, xous::Error> { + use core::fmt::Write; + let mut ret = String::new(); + let helpstring = "Usage: + cute cat - prints cat ascii art + cute bread - prints bread ascii art + cute breadcat - prints breadcat ascii art"; + + let mut tokens = args.split_whitespace(); + + if let Some(sub_cmd) = tokens.next() { + match sub_cmd { + "cat" => { + let cat_art = r#" +⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⠀⠀⢀⣾⣿⣿⣿⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠀⠀⠐⠀⡀ +⠀⠀⠀⠀⢰⡿⠉⠀⡜⣿⣿⣿⡿⠿⢿⣿⣿⡃⠀⠀⠂⠄⠀ +⠀⠀⠒⠒⠸⣿⣄⡘⣃⣿⣿⡟⢰⠃⠀⢹⣿⡇⠀⠀⠀⠀⠀ +⠀⠀⠚⠉⠀⠊⠻⣿⣿⣿⣿⣿⣮⣤⣤⣿⡟⠁⠘⠠⠁⠀⠀ +⠀⠀⠀⠀⠀⠠⠀⠀⠈⠙⠛⠛⠛⠛⠛⠁⠀⠒⠤⠀⠀⠀⠀ +⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀ +⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +"#; + write!(ret, "{}", cat_art).unwrap(); + } + "bread" => { + let bread_art = r#" +⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣵⣾⣿⡿⠟⠛⠉⣉⣉⣉⣉⠉⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣿⡟⢁⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⢸⣿⣿⣿⣿⣿⣿⠀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀ +⠀⢿⣿⣿⣿⣿⣿⣿⡄⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠈⠻⣿⣿⣿⣿⣿⣷⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠈⠻⣿⣿⣿⣿⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠙⢿⣿⠇⢰⣿⣿⣿⣿⡿⠛⢉⣩⣉⡉⠛⠻⠇⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠙⠀⠸⠿⠿⠟⢉⣠⣾⣿⣿⣿⣿⣷⣶⣦⣤⣄⣀⣀⡀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡷⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣉⣉⠉⠛⠛⠻⠿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀ +"#; + write!(ret, "{}", bread_art).unwrap(); + } + "breadcat" => { + let breadcat_art = r#" +⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⢺⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢨⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⣿⣿⣿⡟⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠙⣿⣷⣬⣿⣿⣿⣿⣿⣿⣿⡼⣿⣿⡟⣱⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣿⣧⣠⣿⣿⣿⣿⣿⣿⣿⣀⣾⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣅⣽⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠛⠙⠋⠋⠋⠋⠋⠋⠋⠋⠛⠙⠙⠁⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⠛⢿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢈⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⣴⣶⣉⢿⣿⣿⣿⡟⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣆⡻⣿⣷⠜⣿⣏⣾⣿⣿⡿⠁⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣇⣿⣿⣽⣿⣿⣿⠿⠋⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀ +⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ +"#; + write!(ret, "{}", breadcat_art).unwrap(); + } + _ => { + write!(ret, "{}\n", helpstring).unwrap(); + } + } + } else { + write!(ret, "{}\n", helpstring).unwrap(); + } + + Ok(Some(ret)) +} + + +} \ No newline at end of file From c291b6a11f0f56540b37367b0948f6a913e1c420 Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 9 Jun 2025 16:27:34 +0800 Subject: [PATCH 21/27] now passing the linter --- services/bao-console/src/cmds.rs | 4 +- services/bao-console/src/cmds/cute.rs | 52 ++++++++++----------- services/bao-console/src/cmds/i2cdetect.rs | 53 ++++++++++++---------- xtask/src/main.rs | 3 +- 4 files changed, 58 insertions(+), 54 deletions(-) diff --git a/services/bao-console/src/cmds.rs b/services/bao-console/src/cmds.rs index c73fa4c98..741f9e8d7 100644 --- a/services/bao-console/src/cmds.rs +++ b/services/bao-console/src/cmds.rs @@ -142,8 +142,8 @@ impl CmdEnv { let mut echo_cmd = Echo {}; // this command has no persistent storage, so we can "create" it every time we call dispatch (but it's a zero-cost absraction so this doesn't actually create any instructions) let mut ver_cmd = Ver {}; let mut console_cmd = Test {}; - let mut i2cdetect_cmd = I2cDetect{}; - let mut cute_cmd = Cute{}; + let mut i2cdetect_cmd = I2cDetect {}; + let mut cute_cmd = Cute {}; let commands: &mut [&mut dyn ShellCmdApi] = &mut [ ///// 4. add your command to this array, so that it can be looked up and dispatched diff --git a/services/bao-console/src/cmds/cute.rs b/services/bao-console/src/cmds/cute.rs index 277a96022..9577cc1de 100644 --- a/services/bao-console/src/cmds/cute.rs +++ b/services/bao-console/src/cmds/cute.rs @@ -9,19 +9,19 @@ impl<'a> ShellCmdApi<'a> for Cute { cmd_api!(cute); fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result, xous::Error> { - use core::fmt::Write; - let mut ret = String::new(); - let helpstring = "Usage: + use core::fmt::Write; + let mut ret = String::new(); + let helpstring = "Usage: cute cat - prints cat ascii art cute bread - prints bread ascii art cute breadcat - prints breadcat ascii art"; - let mut tokens = args.split_whitespace(); + let mut tokens = args.split_whitespace(); - if let Some(sub_cmd) = tokens.next() { - match sub_cmd { - "cat" => { - let cat_art = r#" + if let Some(sub_cmd) = tokens.next() { + match sub_cmd { + "cat" => { + let cat_art = r#" ⠀⠀⠀⠀⢀⠠⠤⠀⢀⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠐⠀⠐⠀⠀⢀⣾⣿⡇⠀⠀⠀⠀⠀⢀⣼⡇⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⠀⠀⠀⠀⣴⣿⣿⠇⠀⠀⠀⠀ @@ -34,10 +34,10 @@ impl<'a> ShellCmdApi<'a> for Cute { ⠨⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠀⠀⠀⠀⠀⠀ ⠁⠃⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ "#; - write!(ret, "{}", cat_art).unwrap(); - } - "bread" => { - let bread_art = r#" + write!(ret, "{}", cat_art).unwrap(); + } + "bread" => { + let bread_art = r#" ⠀⠀⠀⠀⣀⣠⣤⣤⣤⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⣴⣿⣿⠿⠛⣉⣁⣠⣤⣤⣤⣬⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⢸⣿⣿⣿⣿⣿⣿⡿⠛⣉⣁⣠⣤⣤⣤⣬⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ @@ -54,10 +54,10 @@ impl<'a> ShellCmdApi<'a> for Cute { ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠛⠛⠛⠻⠶⣶⣤⣈⣉⣉⣉⣁⣤⣴⠾⠛⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠙⠛⠉⠉⠉⠀⠀⠀⠀ "#; - write!(ret, "{}", bread_art).unwrap(); - } - "breadcat" => { - let breadcat_art = r#" + write!(ret, "{}", bread_art).unwrap(); + } + "breadcat" => { + let breadcat_art = r#" ⠀⠀⠀⠰⣦⣤⣤⣀⠀⠀⡀⠀⠀⠀⠀⣀⣀⠀⠠⢤⣶⣶⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢿⣿⢋⣵⣾⣿⣿⡿⣥⣮⢻⣿⣿⣿⣿⣶⣌⢿⣿⢰⣶⣶⣶⣶⣶⣶⣶⣶⣶⣶⣦⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠘⢡⣿⣿⣿⣿⣿⣷⡹⠟⣵⣿⣿⣿⣿⣿⣿⣦⢃⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀ @@ -75,18 +75,16 @@ impl<'a> ShellCmdApi<'a> for Cute { ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⣿⣿⠿⠟⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ "#; - write!(ret, "{}", breadcat_art).unwrap(); - } - _ => { - write!(ret, "{}\n", helpstring).unwrap(); + write!(ret, "{}", breadcat_art).unwrap(); + } + _ => { + write!(ret, "{}\n", helpstring).unwrap(); + } } + } else { + write!(ret, "{}\n", helpstring).unwrap(); } - } else { - write!(ret, "{}\n", helpstring).unwrap(); + + Ok(Some(ret)) } - - Ok(Some(ret)) } - - -} \ No newline at end of file diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index 32e3cf139..4fd3e8cef 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -1,7 +1,7 @@ use String; +use cram_hal_service::I2c; use cramium_api::I2cApi; use cramium_api::I2cResult; -use cram_hal_service::I2c; use crate::{CommonEnv, ShellCmdApi}; @@ -23,37 +23,46 @@ fn probe_address(i2c: &mut I2c, addr: u8) -> ProbeStatus { } } - pub struct I2cDetect {} impl<'a> ShellCmdApi<'a> for I2cDetect { cmd_api!(i2cdetect); fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result, xous::Error> { - use core::fmt::Write; - let mut ret = String::new(); - let helpstring = "Usage: + use core::fmt::Write; + let mut ret = String::new(); + let helpstring = "Usage: i2cdetect probe - probes a single I2C address (e.g. 34) i2cdetect scan - reads i2cdetect bmp180_temp - reads raw temperature from BMP180"; - let mut tokens = args.split_whitespace(); + let mut tokens = args.split_whitespace(); - if let Some(sub_cmd) = tokens.next() { - match sub_cmd { - "probe" => { + if let Some(sub_cmd) = tokens.next() { + match sub_cmd { + "probe" => { if let Some(addr_str) = tokens.next() { match u8::from_str_radix(addr_str, 16) { Ok(addr) => { let mut i2c = I2c::new(); let status = probe_address(&mut i2c, addr); match status { - ProbeStatus::Ack => write!(ret, "Device found at address {:02X}\n", addr).unwrap(), - ProbeStatus::Nack => write!(ret, "Device at address {:02X} responded with NACK\n", addr).unwrap(), + ProbeStatus::Ack => { + write!(ret, "Device found at address {:02X}\n", addr).unwrap() + } + ProbeStatus::Nack => { + write!(ret, "Device at address {:02X} responded with NACK\n", addr) + .unwrap() + } }; } Err(_) => { - write!(ret, "Invalid hex address '{}'. Example: i2cdetect probe 3C\n", addr_str).unwrap(); + write!( + ret, + "Invalid hex address '{}'. Example: i2cdetect probe 3C\n", + addr_str + ) + .unwrap(); } } } else { @@ -82,18 +91,14 @@ impl<'a> ShellCmdApi<'a> for I2cDetect { } } - - - _ => { - write!(ret, "{}\n", helpstring).unwrap(); + _ => { + write!(ret, "{}\n", helpstring).unwrap(); + } } + } else { + write!(ret, "{}\n", helpstring).unwrap(); } - } else { - write!(ret, "{}\n", helpstring).unwrap(); + + Ok(Some(ret)) } - - Ok(Some(ret)) - } - - -} \ No newline at end of file +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 79b617517..3e84266df 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -612,7 +612,8 @@ fn main() -> Result<(), Box> { // - [planned] vault application let bao_rram_pkgs = ["xous-ticktimer", "xous-log", "xous-names", "keystore" /* "usb-cramium" */].to_vec(); /* "usb-cramium" */ - let bao_swap_pkgs = ["cram-hal-service", "bao-console", /*"modals", "pddb", "bao-video"*/].to_vec(); /* "bao-video" */ + let bao_swap_pkgs = + ["cram-hal-service", "bao-console" /* "modals", "pddb", "bao-video" */].to_vec(); /* "bao-video" */ if !builder.is_swap_set() { builder.set_swap(0, 8 * 1024 * 1024); } From d1b5a41e820783e94f8a8e019317d20ce712432e Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 9 Jun 2025 16:32:42 +0800 Subject: [PATCH 22/27] fixing help text --- services/bao-console/src/cmds/i2cdetect.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index 4fd3e8cef..c491e33e0 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -33,8 +33,7 @@ impl<'a> ShellCmdApi<'a> for I2cDetect { let mut ret = String::new(); let helpstring = "Usage: i2cdetect probe - probes a single I2C address (e.g. 34) - i2cdetect scan - reads - i2cdetect bmp180_temp - reads raw temperature from BMP180"; + i2cdetect scan - reads all addresses on the bus (use with caution!)" let mut tokens = args.split_whitespace(); From 90d88820dd590e07c71af5e04a5c4e8e0a8e8cfa Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 9 Jun 2025 17:04:32 +0800 Subject: [PATCH 23/27] dropped a ; --- libs/cramium-hal/src/bmp180.rs | 64 ++++++++++++++++++++++ services/bao-console/src/cmds/i2cdetect.rs | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 libs/cramium-hal/src/bmp180.rs diff --git a/libs/cramium-hal/src/bmp180.rs b/libs/cramium-hal/src/bmp180.rs new file mode 100644 index 000000000..dd4cd7870 --- /dev/null +++ b/libs/cramium-hal/src/bmp180.rs @@ -0,0 +1,64 @@ +use cramium_api::I2cApi; +use cramium_api::I2cResult; +use cram_hal_service::I2c; +use std::thread::sleep; +use std::time::Duration; + +struct Bmp180Calibration { + ac1: i16, ac2: i16, ac3: i16, + ac4: u16, ac5: u16, ac6: u16, + b1: i16, b2: i16, + mb: i16, mc: i16, md: i16, +} + "bmp180_temp" => { + const BMP180_ADDR: u8 = 0x77; + const REG_CALIB_START: u8 = 0xAA; + const REG_CTRL: u8 = 0xF4; + const REG_DATA_START: u8 = 0xF6; + const CMD_READ_TEMP: u8 = 0x2E; + + let mut i2c = I2c::new(); + + let mut cal_buf = [0u8; 22]; + if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_CALIB_START, &mut cal_buf, true) { + write!(ret, "Failed to read calibration data: {:?}\n", e).unwrap(); + return Ok(Some(ret)); + } + + // note: calibration data is Big Endian, hence the from_be_bytes + let cal = Bmp180Calibration { + ac1: i16::from_be_bytes([cal_buf[0], cal_buf[1]]), + ac2: i16::from_be_bytes([cal_buf[2], cal_buf[3]]), + ac3: i16::from_be_bytes([cal_buf[4], cal_buf[5]]), + ac4: u16::from_be_bytes([cal_buf[6], cal_buf[7]]), + ac5: u16::from_be_bytes([cal_buf[8], cal_buf[9]]), + ac6: u16::from_be_bytes([cal_buf[10], cal_buf[11]]), + b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]), + b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]), + mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]), + mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]), + md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]), + }; + + + if let Err(e) = i2c.i2c_write(BMP180_ADDR, REG_CTRL, &[CMD_READ_TEMP]) { + write!(ret, "Failed to start temp measurement: {:?}\n", e).unwrap(); + return Ok(Some(ret)); + } + + sleep(Duration::from_millis(5)); + + let mut temp_buffer = [0u8; 2]; + if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_DATA_START, &mut temp_buffer, true) { + write!(ret, "Failed to read temp data: {:?}\n", e).unwrap(); + return Ok(Some(ret)); + } + let ut = i16::from_be_bytes(temp_buffer) as i32; + + let x1 = (ut - cal.ac6 as i32) * cal.ac5 as i32 >> 15; + let x2 = (cal.mc as i32 * 2048) / (x1 + cal.md as i32); + let b5 = x1 + x2; + let temp = ((b5 + 8) >> 4) as f32 / 10.0; + + write!(ret, "BMP180 Temperature: {:.1}°C\n", temp).unwrap(); + } \ No newline at end of file diff --git a/services/bao-console/src/cmds/i2cdetect.rs b/services/bao-console/src/cmds/i2cdetect.rs index c491e33e0..a3aa598e1 100644 --- a/services/bao-console/src/cmds/i2cdetect.rs +++ b/services/bao-console/src/cmds/i2cdetect.rs @@ -33,7 +33,7 @@ impl<'a> ShellCmdApi<'a> for I2cDetect { let mut ret = String::new(); let helpstring = "Usage: i2cdetect probe - probes a single I2C address (e.g. 34) - i2cdetect scan - reads all addresses on the bus (use with caution!)" + i2cdetect scan - reads all addresses on the bus (use with caution!)"; let mut tokens = args.split_whitespace(); From e7ac82161f0e735160c1d0eeff83db7425a9a06c Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 9 Jun 2025 17:22:55 +0800 Subject: [PATCH 24/27] removing bmp180 which should be its own PR --- libs/cramium-hal/src/bmp180.rs | 64 ---------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 libs/cramium-hal/src/bmp180.rs diff --git a/libs/cramium-hal/src/bmp180.rs b/libs/cramium-hal/src/bmp180.rs deleted file mode 100644 index dd4cd7870..000000000 --- a/libs/cramium-hal/src/bmp180.rs +++ /dev/null @@ -1,64 +0,0 @@ -use cramium_api::I2cApi; -use cramium_api::I2cResult; -use cram_hal_service::I2c; -use std::thread::sleep; -use std::time::Duration; - -struct Bmp180Calibration { - ac1: i16, ac2: i16, ac3: i16, - ac4: u16, ac5: u16, ac6: u16, - b1: i16, b2: i16, - mb: i16, mc: i16, md: i16, -} - "bmp180_temp" => { - const BMP180_ADDR: u8 = 0x77; - const REG_CALIB_START: u8 = 0xAA; - const REG_CTRL: u8 = 0xF4; - const REG_DATA_START: u8 = 0xF6; - const CMD_READ_TEMP: u8 = 0x2E; - - let mut i2c = I2c::new(); - - let mut cal_buf = [0u8; 22]; - if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_CALIB_START, &mut cal_buf, true) { - write!(ret, "Failed to read calibration data: {:?}\n", e).unwrap(); - return Ok(Some(ret)); - } - - // note: calibration data is Big Endian, hence the from_be_bytes - let cal = Bmp180Calibration { - ac1: i16::from_be_bytes([cal_buf[0], cal_buf[1]]), - ac2: i16::from_be_bytes([cal_buf[2], cal_buf[3]]), - ac3: i16::from_be_bytes([cal_buf[4], cal_buf[5]]), - ac4: u16::from_be_bytes([cal_buf[6], cal_buf[7]]), - ac5: u16::from_be_bytes([cal_buf[8], cal_buf[9]]), - ac6: u16::from_be_bytes([cal_buf[10], cal_buf[11]]), - b1: i16::from_be_bytes([cal_buf[12], cal_buf[13]]), - b2: i16::from_be_bytes([cal_buf[14], cal_buf[15]]), - mb: i16::from_be_bytes([cal_buf[16], cal_buf[17]]), - mc: i16::from_be_bytes([cal_buf[18], cal_buf[19]]), - md: i16::from_be_bytes([cal_buf[20], cal_buf[21]]), - }; - - - if let Err(e) = i2c.i2c_write(BMP180_ADDR, REG_CTRL, &[CMD_READ_TEMP]) { - write!(ret, "Failed to start temp measurement: {:?}\n", e).unwrap(); - return Ok(Some(ret)); - } - - sleep(Duration::from_millis(5)); - - let mut temp_buffer = [0u8; 2]; - if let Err(e) = i2c.i2c_read(BMP180_ADDR, REG_DATA_START, &mut temp_buffer, true) { - write!(ret, "Failed to read temp data: {:?}\n", e).unwrap(); - return Ok(Some(ret)); - } - let ut = i16::from_be_bytes(temp_buffer) as i32; - - let x1 = (ut - cal.ac6 as i32) * cal.ac5 as i32 >> 15; - let x2 = (cal.mc as i32 * 2048) / (x1 + cal.md as i32); - let b5 = x1 + x2; - let temp = ((b5 + 8) >> 4) as f32 / 10.0; - - write!(ret, "BMP180 Temperature: {:.1}°C\n", temp).unwrap(); - } \ No newline at end of file From a25f20d0459acbae7f47fd16e2431a995a60cdaf Mon Sep 17 00:00:00 2001 From: Sam Chin Date: Mon, 9 Jun 2025 17:47:00 +0800 Subject: [PATCH 25/27] making console flags happy --- services/bao-console/src/main.rs | 24 ++++++++++++------------ xtask/src/main.rs | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/services/bao-console/src/main.rs b/services/bao-console/src/main.rs index 4f40e6079..cfc282e35 100644 --- a/services/bao-console/src/main.rs +++ b/services/bao-console/src/main.rs @@ -110,20 +110,20 @@ fn main() { #[cfg(feature = "battery-readout")] { - // use cramium_api::I2cApi; - // let mut i2c = cram_hal_service::I2c::new(); - // use cramium_hal::axp2101::*; - // let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)]; - // let mut buf = [0u8, 0u8]; + use cramium_api::I2cApi; + let mut i2c = cram_hal_service::I2c::new(); + use cramium_hal::axp2101::*; + let measurements = [("VBAT", REG_VBAT_H), ("VBUS", REG_VBUS_H), ("VSYS", REG_VSYS_H)]; + let mut buf = [0u8, 0u8]; loop { tt.sleep_ms(2_000).ok(); - // for (name, offset) in measurements { - // i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap(); - // let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32; - // log::info!("{}: {:0.3}V", name, v as f32 / 1000.0); - // i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap(); - // log::info!("SOC: {}%", buf[0]); - // } + for (name, offset) in measurements { + i2c.i2c_read(AXP2101_DEV, offset, &mut buf, false).unwrap(); + let v: u32 = (((buf[0] as u32) & 0x3F) << 8) | buf[1] as u32; + log::info!("{}: {:0.3}V", name, v as f32 / 1000.0); + i2c.i2c_read(AXP2101_DEV, REG_SOC, &mut buf[0..1], false).unwrap(); + log::info!("SOC: {}%", buf[0]); + } } } #[cfg(any(feature = "hosted-baosec", not(feature = "battery-readout")))] diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3e84266df..790edf3b2 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -620,7 +620,6 @@ fn main() -> Result<(), Box> { builder.add_loader_feature("swap"); builder.add_kernel_feature("swap"); builder.add_feature("swap"); - // builder.add_feature("autotest"); builder.add_loader_feature("debug-print"); // the following feature needs to be uncommented if we also enable From 59db16aa99157fc2d55b6b652a4244d254679c07 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 9 Jun 2025 18:49:28 +0800 Subject: [PATCH 26/27] remove debug message --- services/bao-console/src/cmds/pddb.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/services/bao-console/src/cmds/pddb.rs b/services/bao-console/src/cmds/pddb.rs index 6c06637be..0945ee357 100644 --- a/services/bao-console/src/cmds/pddb.rs +++ b/services/bao-console/src/cmds/pddb.rs @@ -15,7 +15,6 @@ pub struct PddbCmd { } impl PddbCmd { pub fn new() -> Self { - log::info!("here"); let pddb = pddb::Pddb::new(); log::info!("PDDB mount result: {:?}", pddb.try_mount()); PddbCmd { pddb } From 7d23064d08aa9a4710572d52dde9c94350ee7c1b Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 9 Jun 2025 18:50:46 +0800 Subject: [PATCH 27/27] Leave in bao-video I think we can leave in the bao-video package without breaking the size of the swap.img file... --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 790edf3b2..d80e1e8ec 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -613,7 +613,7 @@ fn main() -> Result<(), Box> { let bao_rram_pkgs = ["xous-ticktimer", "xous-log", "xous-names", "keystore" /* "usb-cramium" */].to_vec(); /* "usb-cramium" */ let bao_swap_pkgs = - ["cram-hal-service", "bao-console" /* "modals", "pddb", "bao-video" */].to_vec(); /* "bao-video" */ + ["cram-hal-service", "bao-console", /* "modals", "pddb", */ "bao-video"].to_vec(); /* "bao-video" */ if !builder.is_swap_set() { builder.set_swap(0, 8 * 1024 * 1024); }