Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b01915c
initial version of i2c
lxuxx Jun 13, 2025
50449cb
Update clock selection for ast1060. Add buffer mode for i2c slave. Tr…
lxuxx Jun 21, 2025
880e9e2
Add i2c test code.
lxuxx Jun 23, 2025
4d0e747
Update to use static dispatch for i2c.
lxuxx Jun 23, 2025
b14e943
Format i2c.rs
lxuxx Jun 23, 2025
c29eb5e
Add drop for i2c controller.
lxuxx Jun 24, 2025
8804926
Resolve build issue due to multiple different versions of crate embed…
lxuxx Jun 25, 2025
60536c4
Enable i2c target functions in the code.
lxuxx Jun 25, 2025
9ddf19e
Add i2c config builder.
lxuxx Jun 26, 2025
9c9c02a
Move i2c to its own folder
lxuxx Jun 27, 2025
3948ce0
Unify error types.
lxuxx Jun 27, 2025
a533a76
Add i2c.rs for hal.
lxuxx Jun 27, 2025
407f3e5
Implement hardware interface for ast1060.
lxuxx Jun 28, 2025
3780625
Update init function.
lxuxx Jun 28, 2025
fe37519
More implementation of hardware interface.
lxuxx Jun 30, 2025
ed4d8da
Add logging interface for i2c.
lxuxx Jul 1, 2025
56bb0e9
Apply format.
lxuxx Jul 1, 2025
8c7d7b3
Separate state and config.
lxuxx Jul 2, 2025
7ef5672
Clean up and apply cargo clippy changes
lxuxx Jul 2, 2025
c43e88b
Enable all tests in main.rs
lxuxx Jul 2, 2025
a011cdc
rebase to main a826acd8fe04935e74c523716ee5ef6c0f5e50fc
lxuxx Jul 9, 2025
bb64e05
Fix format issues.
lxuxx Jul 9, 2025
422d9c3
Fix clippy errors.
lxuxx Jul 10, 2025
681cec4
Rebase to main fbf95ecf300c719c93bb420b20920bcbf20228b3
lxuxx Jul 14, 2025
4715091
Wire i2c slave isr instead of polling.
lxuxx Jul 22, 2025
6110895
Update i2c slave for swmbx
lxuxx Jul 30, 2025
73be8d2
Merge branch 'main' into i2c_feature
lxuxx Aug 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ edition = "2021"
[features]
default = []
std = []
i2c_target = []
test-rsa = []
test-ecdsa = []
test-hmac = []
Expand All @@ -33,6 +34,7 @@ embedded-io = "0.6.1"
fugit = "0.3.7"
proposed-traits = { git = "https://github.com/rusty1968/proposed_traits.git", package = "proposed-traits", rev = "85641310df5a5276c67f81621b104322cff0286c" }
hex-literal = "0.4"
heapless = "0.8.0"
nb = "1.1.0"
paste = "1.0"

Expand Down
48 changes: 42 additions & 6 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Licensed under the Apache-2.0 license

use crate::uart::UartController;
use core::ops::{Index, IndexMut};
use embedded_io::Write;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
trait I2cHardware {
type Config: Clone + core::fmt::Debug;
type Error;
fn reset(&mut self);
fn configure(&mut self, config: &Self::Config) -> Result<(), Self::Error>;
fn enable_interrupts(&mut self, mask: u32);
fn clear_interrupts(&mut self, mask: u32);
fn start_transfer(&mut self, state: &TransferState) -> Result<(), Self::Error>;
fn handle_interrupt(&mut self) -> InterruptStatus<Self::Error>;
fn is_bus_busy(&self) -> bool;
fn recover_bus(&mut self) -> Result<(), Self::Error>;
}

pub struct DummyDelay;

impl embedded_hal::delay::DelayNs for DummyDelay {
Expand Down Expand Up @@ -38,27 +42,25 @@ impl<const N: usize> DmaBuffer<N> {
}

#[must_use]
pub fn len(&self) -> usize {
pub const fn len(&self) -> usize {
N
}

#[must_use]
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
N == 0
}

#[must_use]
pub fn as_slice(&self) -> &[u8] {
&self.buf
pub fn as_slice(&self, start: usize, end: usize) -> &[u8] {
&self.buf[start..end]
}

pub fn as_mut_slice(&mut self, start: usize, end: usize) -> &mut [u8] {
&mut self.buf[start..end]
}
}

use core::ops::{Index, IndexMut};

impl<const N: usize> Index<usize> for DmaBuffer<N> {
type Output = u8;
fn index(&self, idx: usize) -> &Self::Output {
Expand All @@ -71,3 +73,37 @@ impl<const N: usize> IndexMut<usize> for DmaBuffer<N> {
&mut self.buf[idx]
}
}

pub trait Logger {
fn debug(&mut self, msg: &str);
fn error(&mut self, msg: &str);
}

// No-op implementation for production builds
pub struct NoOpLogger;
impl Logger for NoOpLogger {
fn debug(&mut self, _msg: &str) {}
fn error(&mut self, _msg: &str) {}
}

// UART logger adapter (separate concern)
pub struct UartLogger<'a> {
uart: &'a mut UartController<'a>,
}

impl<'a> UartLogger<'a> {
pub fn new(uart: &'a mut UartController<'a>) -> Self {
UartLogger { uart }
}
}

impl<'a> Logger for UartLogger<'a> {
fn debug(&mut self, msg: &str) {
writeln!(self.uart, "{msg}").ok();
write!(self.uart, "\r").ok();
}
fn error(&mut self, msg: &str) {
writeln!(self.uart, "ERROR: {msg}").ok();
write!(self.uart, "\r").ok();
}
}
Loading