Skip to content

Commit

Permalink
Merge pull request #3 from DanielWarloch/feature/bm1370
Browse files Browse the repository at this point in the history
[WIP] Add BM1370 support
  • Loading branch information
Georges760 authored Jan 2, 2025
2 parents 0736018 + 3b69cf9 commit b72a205
Show file tree
Hide file tree
Showing 23 changed files with 2,709 additions and 801 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Test
run: cargo test --features core-error --verbose
run: cargo test --verbose
- name: Format
run: cargo fmt --check
- name: Clippy
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"
members = [
"bm1366",
"bm1370",
"bm1397",
"bm13xx-asic",
"bm13xx-chain",
Expand All @@ -17,3 +18,4 @@ embedded-io-async = "0.6"
fugit = "0.3"
heapless = "0.8"
log = "0.4"
rustversion = "1.0"
4 changes: 0 additions & 4 deletions bm1366/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ heapless = { workspace = true }
log = { workspace = true, optional = true }

[features]
core-error = [ # bump MSRV to 1.81.0
"bm13xx-asic/core-error",
"bm13xx-protocol/core-error",
]
defmt-03 = [
"dep:defmt",
"bm13xx-asic/defmt-03",
Expand Down
1,131 changes: 667 additions & 464 deletions bm1366/src/lib.rs

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions bm1370/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
categories = ["embedded", "no-std"]
edition = "2021"
name = "bm1370"
rust-version = "1.75.0"
version = "0.1.0"

[dependencies]
"bm13xx-asic" = { path = "../bm13xx-asic" }
"bm13xx-protocol" = { path = "../bm13xx-protocol" }

defmt = { workspace = true, optional = true }
fugit = { workspace = true }
heapless = { workspace = true }
log = { workspace = true, optional = true }

[features]
defmt-03 = [
"dep:defmt",
"bm13xx-asic/defmt-03",
"bm13xx-protocol/defmt-03",
"fugit/defmt",
"heapless/defmt-03",
]
226 changes: 226 additions & 0 deletions bm1370/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
#![macro_use]
#![allow(unused_macros)]

#[cfg(all(feature = "defmt-03", feature = "log"))]
compile_error!("You may not enable both `defmt` and `log` features.");

macro_rules! assert {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::assert!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::assert!($($x)*);
}
};
}

macro_rules! assert_eq {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::assert_eq!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::assert_eq!($($x)*);
}
};
}

macro_rules! assert_ne {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::assert_ne!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::assert_ne!($($x)*);
}
};
}

macro_rules! debug_assert {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::debug_assert!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::debug_assert!($($x)*);
}
};
}

macro_rules! debug_assert_eq {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::debug_assert_eq!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::debug_assert_eq!($($x)*);
}
};
}

macro_rules! debug_assert_ne {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::debug_assert_ne!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::debug_assert_ne!($($x)*);
}
};
}

macro_rules! todo {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::todo!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::todo!($($x)*);
}
};
}

macro_rules! unreachable {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::unreachable!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::unreachable!($($x)*);
}
};
}

macro_rules! panic {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
::core::panic!($($x)*);
#[cfg(feature = "defmt-03")]
::defmt::panic!($($x)*);
}
};
}

macro_rules! trace {
($s:literal $(, $x:expr)* $(,)?) => {
{
#[cfg(feature = "log")]
::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
let _ = ($( & $x ),*);
}
};
}

macro_rules! debug {
($s:literal $(, $x:expr)* $(,)?) => {
{
#[cfg(feature = "log")]
::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
let _ = ($( & $x ),*);
}
};
}

macro_rules! info {
($s:literal $(, $x:expr)* $(,)?) => {
{
#[cfg(feature = "log")]
::log::info!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
let _ = ($( & $x ),*);
}
};
}

macro_rules! warn {
($s:literal $(, $x:expr)* $(,)?) => {
{
#[cfg(feature = "log")]
::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
let _ = ($( & $x ),*);
}
};
}

macro_rules! error {
($s:literal $(, $x:expr)* $(,)?) => {
{
#[cfg(feature = "log")]
::log::error!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
let _ = ($( & $x ),*);
}
};
}

#[cfg(feature = "defmt-03")]
macro_rules! unwrap {
($($x:tt)*) => {
::defmt::unwrap!($($x)*)
};
}

#[cfg(not(feature = "defmt-03"))]
macro_rules! unwrap {
($arg:expr) => {
match $crate::fmt::Try::into_result($arg) {
::core::result::Result::Ok(t) => t,
::core::result::Result::Err(e) => {
::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
}
}
};
($arg:expr, $($msg:expr),+ $(,)? ) => {
match $crate::fmt::Try::into_result($arg) {
::core::result::Result::Ok(t) => t,
::core::result::Result::Err(e) => {
::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
}
}
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct NoneError;

#[allow(dead_code)]
pub trait Try {
type Ok;
type Error;
fn into_result(self) -> Result<Self::Ok, Self::Error>;
}

impl<T> Try for Option<T> {
type Ok = T;
type Error = NoneError;

#[inline]
fn into_result(self) -> Result<T, NoneError> {
self.ok_or(NoneError)
}
}

impl<T, E> Try for Result<T, E> {
type Ok = T;
type Error = E;

#[inline]
fn into_result(self) -> Self {
self
}
}
Loading

0 comments on commit b72a205

Please sign in to comment.