Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ on:
paths: [ src ]

env:
RUSTC_WRAPPER: "sccache"
RUSTFLAGS: "-Dwarnings"
SCCACHE_GHA_ENABLED: "true"

jobs:
build:
Expand All @@ -36,9 +34,6 @@ jobs:
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.5

- name: Check formatting
run: cargo fmt --all --check

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ rust-version = "1.71.1"
version = "0.2.1"

[dependencies]
defmt = { version = "0.3", optional = true }
defmt = { version = "1.0", optional = true }
embedded-hal = { version = "1.0", optional = true }
embedded-hal-async = { version = "1.0", optional = true }
log = { version = "0.4", optional = true }
maybe-async-cfg2 = "0.3"

[features]
async = ["dep:embedded-hal-async"]
core-error = [] # bump MSRV to 1.81.0
core-error = [] # bump MSRV to 1.81.0
default = ["sync"]
defmt-03 = ["dep:defmt"]
defmt = ["dep:defmt"]
not-recommended-rfs = []
sync = ["dep:embedded-hal"]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Distributed under the AGPLv3 License. See [LICENSE.txt](./LICENSE.txt) for more

## Features

- `defmt-03` add support for defmt Formatting of public enums and structs.
- `defmt` add support for defmt Formatting of public enums and structs.
- `sync` (default) use `embedded_hal::i2c::I2c` trait to provide a sync driver.
- `async` use `embedded_hal_async::i2c::I2c` trait to provide an async driver. Both `sync` and `async` can be enable at the same time, but enabling none is pointless.
- `not-recommended-rfs` allow driver to use not recommended Rfs value for microamps convertions
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub type Result<T, E> = core::result::Result<T, Error<E>>;

/// Driver errors.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error<E> {
/// I2C bus error.
I2c(E),
Expand Down
62 changes: 31 additions & 31 deletions src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#![macro_use]
#![allow(unused_macros)]

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

macro_rules! assert {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::assert!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::assert!($($x)*);
}
};
Expand All @@ -18,9 +18,9 @@ macro_rules! assert {
macro_rules! assert_eq {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::assert_eq!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::assert_eq!($($x)*);
}
};
Expand All @@ -29,9 +29,9 @@ macro_rules! assert_eq {
macro_rules! assert_ne {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::assert_ne!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::assert_ne!($($x)*);
}
};
Expand All @@ -40,9 +40,9 @@ macro_rules! assert_ne {
macro_rules! debug_assert {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::debug_assert!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::debug_assert!($($x)*);
}
};
Expand All @@ -51,9 +51,9 @@ macro_rules! debug_assert {
macro_rules! debug_assert_eq {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::debug_assert_eq!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::debug_assert_eq!($($x)*);
}
};
Expand All @@ -62,9 +62,9 @@ macro_rules! debug_assert_eq {
macro_rules! debug_assert_ne {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::debug_assert_ne!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::debug_assert_ne!($($x)*);
}
};
Expand All @@ -73,9 +73,9 @@ macro_rules! debug_assert_ne {
macro_rules! todo {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::todo!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::todo!($($x)*);
}
};
Expand All @@ -84,9 +84,9 @@ macro_rules! todo {
macro_rules! unreachable {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::unreachable!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::unreachable!($($x)*);
}
};
Expand All @@ -95,9 +95,9 @@ macro_rules! unreachable {
macro_rules! panic {
($($x:tt)*) => {
{
#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
::core::panic!($($x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::panic!($($x)*);
}
};
Expand All @@ -108,9 +108,9 @@ macro_rules! trace {
{
#[cfg(feature = "log")]
::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
}
};
Expand All @@ -121,9 +121,9 @@ macro_rules! debug {
{
#[cfg(feature = "log")]
::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
}
};
Expand All @@ -134,9 +134,9 @@ macro_rules! info {
{
#[cfg(feature = "log")]
::log::info!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
}
};
Expand All @@ -147,9 +147,9 @@ macro_rules! warn {
{
#[cfg(feature = "log")]
::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
}
};
Expand All @@ -160,22 +160,22 @@ macro_rules! error {
{
#[cfg(feature = "log")]
::log::error!($s $(, $x)*);
#[cfg(feature = "defmt-03")]
#[cfg(feature = "defmt")]
::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt-03")))]
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
}
};
}

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

#[cfg(not(feature = "defmt-03"))]
#[cfg(not(feature = "defmt"))]
macro_rules! unwrap {
($arg:expr) => {
match $crate::fmt::Try::into_result($arg) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const IOUT_UA_MAX: f32 = 200.0;

/// An output controllable by the DS4432. This device has two.
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum Output {
Zero = 0xF8,
Expand All @@ -58,7 +58,7 @@ impl From<Output> for u8 {

/// The status of an output.
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Status {
/// The output is completely disabled
Disable,
Expand Down