mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-22 09:23:16 +00:00
Merge branch 'main' into vault2
This commit is contained in:
commit
b9bac3d5cf
19 changed files with 412 additions and 52 deletions
17
Cargo.lock
generated
17
Cargo.lock
generated
|
|
@ -1308,26 +1308,25 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curve25519-dalek"
|
name = "curve25519-dalek"
|
||||||
version = "4.1.2"
|
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 = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cpufeatures",
|
"cpufeatures",
|
||||||
"curve25519-dalek-derive",
|
"curve25519-dalek-derive",
|
||||||
"digest 0.10.7",
|
"digest 0.10.7",
|
||||||
"engine25519-as",
|
|
||||||
"fiat-crypto 0.2.7",
|
"fiat-crypto 0.2.7",
|
||||||
"log",
|
"platforms",
|
||||||
"rustc_version 0.4.0",
|
"rustc_version 0.4.0",
|
||||||
"subtle",
|
"subtle",
|
||||||
"utralib 0.1.25",
|
|
||||||
"xous 0.9.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "curve25519-dalek-derive"
|
name = "curve25519-dalek-derive"
|
||||||
version = "0.1.1"
|
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 = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -4075,6 +4074,12 @@ version = "0.3.29"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb"
|
checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "platforms"
|
||||||
|
version = "3.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b02ffed1bc8c2234bb6f8e760e34613776c5102a041f25330b869a78153a68c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "plotters"
|
name = "plotters"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ pub enum HalOpcode {
|
||||||
ConfigureUdmaClock = 7,
|
ConfigureUdmaClock = 7,
|
||||||
// blocking scalar
|
// blocking scalar
|
||||||
ConfigureUdmaEvent = 8,
|
ConfigureUdmaEvent = 8,
|
||||||
|
// blocking scalar
|
||||||
|
UdmaIrqStatusBits = 16,
|
||||||
|
|
||||||
/// I2C operations
|
/// I2C operations
|
||||||
I2c = 9,
|
I2c = 9,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
pub trait I2cApi {
|
pub trait I2cApi {
|
||||||
fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result<usize, xous::Error>;
|
fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result<I2cResult, xous::Error>;
|
||||||
|
|
||||||
/// initiate an i2c read. The read buffer is passed during the await.
|
/// initiate an i2c read. The read buffer is passed during the await.
|
||||||
fn i2c_read(
|
fn i2c_read(
|
||||||
|
|
@ -8,7 +8,7 @@ pub trait I2cApi {
|
||||||
adr: u8,
|
adr: u8,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
repeated_start: bool,
|
repeated_start: bool,
|
||||||
) -> Result<usize, xous::Error>;
|
) -> Result<I2cResult, xous::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
|
#[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))]
|
#[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
pub enum I2cResult {
|
pub enum I2cResult {
|
||||||
/// For the outbound message holder
|
/// For the outbound message holder
|
||||||
Pending,
|
Pending,
|
||||||
|
|
@ -28,6 +28,8 @@ pub enum I2cResult {
|
||||||
Ack(usize),
|
Ack(usize),
|
||||||
/// An error occurred.
|
/// An error occurred.
|
||||||
Nack,
|
Nack,
|
||||||
|
/// An unhandled error has occurred.
|
||||||
|
InternalError,
|
||||||
}
|
}
|
||||||
#[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
|
#[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,12 @@ pub enum EventChannel {
|
||||||
Channel3 = 24,
|
Channel3 = 24,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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
|
/// Use a trait that will allow us to share code between both `std` and `no-std` implementations
|
||||||
pub trait UdmaGlobalConfig {
|
pub trait UdmaGlobalConfig {
|
||||||
fn clock(&self, peripheral: PeriphId, enable: bool);
|
fn clock(&self, peripheral: PeriphId, enable: bool);
|
||||||
|
|
@ -243,4 +249,5 @@ pub trait UdmaGlobalConfig {
|
||||||
to_channel: EventChannel,
|
to_channel: EventChannel,
|
||||||
);
|
);
|
||||||
fn reset(&self, peripheral: PeriphId);
|
fn reset(&self, peripheral: PeriphId);
|
||||||
|
fn irq_status_bits(&self, bank: IrqBank) -> u32;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(
|
pub fn set_ldo(
|
||||||
&mut self,
|
&mut self,
|
||||||
i2c: &mut dyn I2cApi,
|
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 {
|
fn encode_dcdc_ena(&self) -> u8 {
|
||||||
let mut code = 0;
|
let mut code = 0;
|
||||||
for (i, &ena) in self.dcdc_ena.iter().enumerate() {
|
for (i, &ena) in self.dcdc_ena.iter().enumerate() {
|
||||||
|
|
|
||||||
|
|
@ -263,6 +263,50 @@ impl<'a> I2c<'a> {
|
||||||
xous::yield_slice();
|
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() {
|
let ret = match self.pending.take() {
|
||||||
I2cPending::Read(len) => {
|
I2cPending::Read(len) => {
|
||||||
if let Some(buf) = rx_buf {
|
if let Some(buf) = rx_buf {
|
||||||
|
|
@ -458,13 +502,25 @@ impl I2cApi for I2c<'_> {
|
||||||
adr: u8,
|
adr: u8,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
repeated_start: bool,
|
repeated_start: bool,
|
||||||
) -> Result<usize, xous::Error> {
|
) -> Result<I2cResult, xous::Error> {
|
||||||
self.i2c_read_async(dev, adr, buf.len(), repeated_start)?;
|
match self.i2c_read_async(dev, adr, buf.len(), repeated_start) {
|
||||||
self.i2c_await(Some(buf), true)
|
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<usize, xous::Error> {
|
fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result<I2cResult, xous::Error> {
|
||||||
self.i2c_write_async(dev, adr, data)?;
|
match self.i2c_write_async(dev, adr, data) {
|
||||||
self.i2c_await(None, true)
|
Err(_) => return Err(xous::Error::InternalError),
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
match self.i2c_await(None, true) {
|
||||||
|
Ok(b) => Ok(I2cResult::Ack(b)),
|
||||||
|
_ => Ok(I2cResult::Nack),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,53 @@ impl Into<usize> for GlobalReg {
|
||||||
|
|
||||||
pub struct GlobalConfig {
|
pub struct GlobalConfig {
|
||||||
csr: SharedCsr<u32>,
|
csr: SharedCsr<u32>,
|
||||||
|
i2c_irq: SharedCsr<u32>,
|
||||||
|
i2c_err_irq: SharedCsr<u32>,
|
||||||
}
|
}
|
||||||
impl GlobalConfig {
|
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;
|
||||||
|
|
||||||
|
#[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) {
|
pub fn clock_on(&self, peripheral: PeriphId) {
|
||||||
// Safety: only safe when used in the context of UDMA registers.
|
// Safety: only safe when used in the context of UDMA registers.
|
||||||
|
|
@ -138,6 +182,21 @@ impl UdmaGlobalConfig for GlobalConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(&self, peripheral: PeriphId) { self.reset(peripheral); }
|
fn reset(&self, peripheral: PeriphId) { self.reset(peripheral); }
|
||||||
|
|
||||||
|
fn irq_status_bits(&self, bank: IrqBank) -> u32 {
|
||||||
|
match bank {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// --------------------------------- DMA channel ------------------------------------
|
// --------------------------------- DMA channel ------------------------------------
|
||||||
pub(crate) const CFG_EN: u32 = 0b01_0000; // start a transfer
|
pub(crate) const CFG_EN: u32 = 0b01_0000; // start a transfer
|
||||||
|
|
|
||||||
|
|
@ -235,7 +235,7 @@ pub fn early_init() -> u32 {
|
||||||
|
|
||||||
// Set up the UDMA_UART block to the correct baud rate and enable status
|
// Set up the UDMA_UART block to the correct baud rate and enable status
|
||||||
#[allow(unused_mut)] // some configs require mut
|
#[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.clock_on(PeriphId::Uart1);
|
||||||
udma_global.map_event(
|
udma_global.map_event(
|
||||||
PeriphId::Uart1,
|
PeriphId::Uart1,
|
||||||
|
|
@ -409,7 +409,7 @@ pub fn early_init() -> u32 {
|
||||||
// show the boot logo
|
// show the boot logo
|
||||||
use ux_api::minigfx::FrameBuffer;
|
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(
|
let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(
|
||||||
cramium_hal::sh1107::MainThreadToken::new(),
|
cramium_hal::sh1107::MainThreadToken::new(),
|
||||||
perclk,
|
perclk,
|
||||||
|
|
@ -456,7 +456,7 @@ pub fn early_init() -> u32 {
|
||||||
use crate::platform::cramium::qr;
|
use crate::platform::cramium::qr;
|
||||||
|
|
||||||
let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
|
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
|
// setup camera pins
|
||||||
let (cam_pdwn_bnk, cam_pdwn_pin) = cramium_hal::board::setup_camera_pins(&iox);
|
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
|
// setup the I/O pins
|
||||||
let mut iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32);
|
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);
|
let channel = cramium_hal::board::setup_memory_pins(&iox);
|
||||||
udma_global.clock_off(PeriphId::from(channel));
|
udma_global.clock_off(PeriphId::from(channel));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ pub struct SwapHal {
|
||||||
impl SwapHal {
|
impl SwapHal {
|
||||||
pub fn new(cfg: &BootConfig, perclk_freq: u32) -> Option<SwapHal> {
|
pub fn new(cfg: &BootConfig, perclk_freq: u32) -> Option<SwapHal> {
|
||||||
if let Some(swap) = cfg.swap {
|
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
|
// setup the I/O pins
|
||||||
let iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32);
|
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);
|
iox.set_gpio_dir(IoxPort::PD, 3, IoxDir::Output);
|
||||||
|
|
||||||
// Set up the UDMA_UART block to the correct baud rate and enable status
|
// Set up the UDMA_UART block to the correct baud rate and enable status
|
||||||
let udma_global =
|
let udma_global = cramium_hal::udma::GlobalConfig::new();
|
||||||
cramium_hal::udma::GlobalConfig::new(utralib::utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32);
|
|
||||||
udma_global.clock_on(PeriphId::Uart0);
|
udma_global.clock_on(PeriphId::Uart0);
|
||||||
udma_global.map_event(
|
udma_global.map_event(
|
||||||
PeriphId::Uart0,
|
PeriphId::Uart0,
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ pub fn process_update(perclk: u32) {
|
||||||
|
|
||||||
crate::println!("waiting for button press");
|
crate::println!("waiting for button press");
|
||||||
let mut iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32);
|
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 iox_kbd = iox.clone();
|
||||||
let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(
|
let mut sh1107 = cramium_hal::sh1107::Oled128x128::new(
|
||||||
|
|
@ -394,9 +394,7 @@ pub fn process_update(perclk: u32) {
|
||||||
);
|
);
|
||||||
progress_bar(&mut sh1107, 0);
|
progress_bar(&mut sh1107, 0);
|
||||||
|
|
||||||
let udma_global = GlobalConfig::new(
|
let udma_global = GlobalConfig::new();
|
||||||
utralib::generated::HW_UDMA_CTRL_BASE as *mut u32,
|
|
||||||
);
|
|
||||||
|
|
||||||
// setup the I/O pins
|
// setup the I/O pins
|
||||||
let iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32);
|
let iox = Iox::new(utralib::generated::HW_IOX_BASE as *mut u32);
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,9 @@ hosted-baosec = [
|
||||||
"cramium-hal/hosted-baosec",
|
"cramium-hal/hosted-baosec",
|
||||||
]
|
]
|
||||||
usb = []
|
usb = []
|
||||||
pddbtest = []
|
battery-readout = []
|
||||||
|
with-pddb = []
|
||||||
|
pddbtest = ["with-pddb"]
|
||||||
test-rekey = []
|
test-rekey = []
|
||||||
autobasis = ["rand_chacha", "rand"]
|
autobasis = ["rand_chacha", "rand"]
|
||||||
modal-testing = ["ux-api", "modals/modal-testing"]
|
modal-testing = ["ux-api", "modals/modal-testing"]
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,14 @@ use trng_cmd::*;
|
||||||
mod usb;
|
mod usb;
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "usb")]
|
||||||
use usb::*;
|
use usb::*;
|
||||||
|
#[cfg(feature = "with-pddb")]
|
||||||
mod pddb;
|
mod pddb;
|
||||||
|
#[cfg(feature = "with-pddb")]
|
||||||
use pddb::*;
|
use pddb::*;
|
||||||
|
mod i2cdetect;
|
||||||
|
use i2cdetect::*;
|
||||||
|
mod cute;
|
||||||
|
use cute::*;
|
||||||
|
|
||||||
pub struct CmdEnv {
|
pub struct CmdEnv {
|
||||||
common_env: CommonEnv,
|
common_env: CommonEnv,
|
||||||
|
|
@ -97,6 +103,7 @@ pub struct CmdEnv {
|
||||||
trng_cmd: TrngCmd,
|
trng_cmd: TrngCmd,
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "usb")]
|
||||||
usb: Usb,
|
usb: Usb,
|
||||||
|
#[cfg(feature = "with-pddb")]
|
||||||
pddb_cmd: PddbCmd,
|
pddb_cmd: PddbCmd,
|
||||||
}
|
}
|
||||||
impl CmdEnv {
|
impl CmdEnv {
|
||||||
|
|
@ -120,6 +127,7 @@ impl CmdEnv {
|
||||||
},
|
},
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "usb")]
|
||||||
usb: Usb::new(),
|
usb: Usb::new(),
|
||||||
|
#[cfg(feature = "with-pddb")]
|
||||||
pddb_cmd: PddbCmd::new(),
|
pddb_cmd: PddbCmd::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,14 +142,20 @@ 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 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 ver_cmd = Ver {};
|
||||||
let mut console_cmd = Test {};
|
let mut console_cmd = Test {};
|
||||||
|
let mut i2cdetect_cmd = I2cDetect {};
|
||||||
|
let mut cute_cmd = Cute {};
|
||||||
|
|
||||||
let commands: &mut [&mut dyn ShellCmdApi] = &mut [
|
let commands: &mut [&mut dyn ShellCmdApi] = &mut [
|
||||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||||
&mut echo_cmd,
|
&mut echo_cmd,
|
||||||
&mut ver_cmd,
|
&mut ver_cmd,
|
||||||
&mut self.trng_cmd,
|
&mut self.trng_cmd,
|
||||||
|
&mut i2cdetect_cmd,
|
||||||
|
&mut cute_cmd,
|
||||||
&mut console_cmd,
|
&mut console_cmd,
|
||||||
#[cfg(feature = "usb")]
|
#[cfg(feature = "usb")]
|
||||||
&mut self.usb,
|
&mut self.usb,
|
||||||
|
#[cfg(feature = "with-pddb")]
|
||||||
&mut self.pddb_cmd,
|
&mut self.pddb_cmd,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
90
services/bao-console/src/cmds/cute.rs
Normal file
90
services/bao-console/src/cmds/cute.rs
Normal file
|
|
@ -0,0 +1,90 @@
|
||||||
|
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<Option<String>, 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
103
services/bao-console/src/cmds/i2cdetect.rs
Normal file
103
services/bao-console/src/cmds/i2cdetect.rs
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
use String;
|
||||||
|
use cram_hal_service::I2c;
|
||||||
|
use cramium_api::I2cApi;
|
||||||
|
use cramium_api::I2cResult;
|
||||||
|
|
||||||
|
use crate::{CommonEnv, ShellCmdApi};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
fn process(&mut self, args: String, _env: &mut CommonEnv) -> Result<Option<String>, xous::Error> {
|
||||||
|
use core::fmt::Write;
|
||||||
|
let mut ret = String::new();
|
||||||
|
let helpstring = "Usage:
|
||||||
|
i2cdetect probe <hex> - probes a single I2C address (e.g. 34)
|
||||||
|
i2cdetect scan - reads all addresses on the bus (use with caution!)";
|
||||||
|
|
||||||
|
let mut tokens = args.split_whitespace();
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
write!(
|
||||||
|
ret,
|
||||||
|
"Invalid hex address '{}'. Example: i2cdetect probe 3C\n",
|
||||||
|
addr_str
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
write!(ret, "Usage: i2cdetect probe <hexaddr>\n").unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"scan" => {
|
||||||
|
let mut i2c = I2c::new();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => {
|
||||||
|
write!(ret, "{}\n", helpstring).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
write!(ret, "{}\n", helpstring).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(ret))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -108,7 +108,7 @@ fn main() {
|
||||||
modals::tests::spawn_test();
|
modals::tests::spawn_test();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
#[cfg(feature = "battery-readout")]
|
||||||
{
|
{
|
||||||
use cramium_api::I2cApi;
|
use cramium_api::I2cApi;
|
||||||
let mut i2c = cram_hal_service::I2c::new();
|
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 {
|
loop {
|
||||||
tt.sleep_ms(2_000).ok();
|
tt.sleep_ms(2_000).ok();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ impl I2cApi for I2c {
|
||||||
adr: u8,
|
adr: u8,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
repeated_start: bool,
|
repeated_start: bool,
|
||||||
) -> Result<usize, xous::Error> {
|
) -> Result<I2cResult, xous::Error> {
|
||||||
let r = I2cTransaction {
|
let r = I2cTransaction {
|
||||||
i2c_type: if repeated_start {
|
i2c_type: if repeated_start {
|
||||||
I2cTransactionType::ReadRepeatedStart
|
I2cTransactionType::ReadRepeatedStart
|
||||||
|
|
@ -46,16 +46,14 @@ impl I2cApi for I2c {
|
||||||
result: I2cResult::Pending,
|
result: I2cResult::Pending,
|
||||||
};
|
};
|
||||||
let result = self.i2c_transactions(I2cTransactions::from(vec![r]))?;
|
let result = self.i2c_transactions(I2cTransactions::from(vec![r]))?;
|
||||||
match result.transactions[0].result {
|
if result.transactions[0].result == I2cResult::InternalError {
|
||||||
I2cResult::Ack(b) => {
|
Err(xous::Error::InternalError)
|
||||||
buf.copy_from_slice(&result.transactions[0].data);
|
} else {
|
||||||
Ok(b)
|
Ok(result.transactions[0].result)
|
||||||
}
|
|
||||||
_ => Err(xous::Error::InternalError),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result<usize, xous::Error> {
|
fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result<I2cResult, xous::Error> {
|
||||||
let w = I2cTransaction {
|
let w = I2cTransaction {
|
||||||
i2c_type: I2cTransactionType::Write,
|
i2c_type: I2cTransactionType::Write,
|
||||||
device: dev,
|
device: dev,
|
||||||
|
|
@ -64,9 +62,10 @@ impl I2cApi for I2c {
|
||||||
result: I2cResult::Pending,
|
result: I2cResult::Pending,
|
||||||
};
|
};
|
||||||
let result = self.i2c_transactions(I2cTransactions::from(vec![w]))?;
|
let result = self.i2c_transactions(I2cTransactions::from(vec![w]))?;
|
||||||
match result.transactions[0].result {
|
if result.transactions[0].result == I2cResult::InternalError {
|
||||||
I2cResult::Ack(b) => Ok(b),
|
Err(xous::Error::InternalError)
|
||||||
_ => Err(xous::Error::InternalError),
|
} else {
|
||||||
|
Ok(result.transactions[0].result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,20 @@ impl UdmaGlobalConfig for UdmaGlobal {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reset(&self, peripheral: PeriphId) { self.reset(peripheral); }
|
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"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use bitfield::*;
|
||||||
use cramium_api::*;
|
use cramium_api::*;
|
||||||
use cramium_hal::{iox::Iox, udma::GlobalConfig};
|
use cramium_hal::{iox::Iox, udma::GlobalConfig};
|
||||||
use num_traits::*;
|
use num_traits::*;
|
||||||
|
use udma::UdmaGlobalConfig;
|
||||||
use utralib::CSR;
|
use utralib::CSR;
|
||||||
#[cfg(feature = "quantum-timer")]
|
#[cfg(feature = "quantum-timer")]
|
||||||
use utralib::utra;
|
use utralib::utra;
|
||||||
|
|
@ -185,14 +186,7 @@ fn main() {
|
||||||
.expect("couldn't claim the IOX hardware page");
|
.expect("couldn't claim the IOX hardware page");
|
||||||
let iox = Iox::new(iox_page.as_ptr() as *mut u32);
|
let iox = Iox::new(iox_page.as_ptr() as *mut u32);
|
||||||
|
|
||||||
let udma_global_csr = xous::syscall::map_memory(
|
let udma_global = GlobalConfig::new();
|
||||||
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);
|
|
||||||
|
|
||||||
// Note: the I2C handler can be put into a separate thread if we need the main
|
// 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
|
// HAL server to not block while a large I2C transaction is being handled. For
|
||||||
|
|
@ -533,6 +527,13 @@ fn main() {
|
||||||
udma_global.map_event_with_offset(periph, event_offset, to_channel);
|
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 => {
|
HalOpcode::PeriphReset => {
|
||||||
if let Some(scalar) = msg.body.scalar_message() {
|
if let Some(scalar) = msg.body.scalar_message() {
|
||||||
let periph: PeriphId = num_traits::FromPrimitive::from_usize(scalar.arg1).unwrap();
|
let periph: PeriphId = num_traits::FromPrimitive::from_usize(scalar.arg1).unwrap();
|
||||||
|
|
@ -548,7 +549,7 @@ fn main() {
|
||||||
match transaction.i2c_type {
|
match transaction.i2c_type {
|
||||||
I2cTransactionType::Write => {
|
I2cTransactionType::Write => {
|
||||||
match i2c.i2c_write(transaction.device, transaction.address, &transaction.data) {
|
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,
|
_ => transaction.result = I2cResult::Nack,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -559,7 +560,7 @@ fn main() {
|
||||||
&mut transaction.data,
|
&mut transaction.data,
|
||||||
transaction.i2c_type == I2cTransactionType::ReadRepeatedStart,
|
transaction.i2c_type == I2cTransactionType::ReadRepeatedStart,
|
||||||
) {
|
) {
|
||||||
Ok(b) => transaction.result = I2cResult::Ack(b),
|
Ok(result) => transaction.result = result,
|
||||||
_ => transaction.result = I2cResult::Nack,
|
_ => transaction.result = I2cResult::Nack,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -614,7 +614,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
// - [planned] vault application
|
// - [planned] vault application
|
||||||
let bao_rram_pkgs =
|
let bao_rram_pkgs =
|
||||||
["xous-ticktimer", "xous-log", "xous-names", "keystore" /* "usb-cramium" */].to_vec(); /* "usb-cramium" */
|
["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() {
|
if !builder.is_swap_set() {
|
||||||
builder.set_swap(0, 8 * 1024 * 1024);
|
builder.set_swap(0, 8 * 1024 * 1024);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue