Skip to content

Commit

Permalink
Merge pull request #612 from umi-eng/embedded-can-defmt
Browse files Browse the repository at this point in the history
Add defmt feature and traits for embedded-can
  • Loading branch information
Dirbaio authored Jul 4, 2024
2 parents 1c585d4 + 3c41607 commit 8a9b250
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions embedded-can/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ repository = "https://github.com/rust-embedded/embedded-hal"

[dependencies]
nb = "1"
defmt = { version = "0.3", optional = true }

[features]
defmt-03 = ["dep:defmt"]
4 changes: 4 additions & 0 deletions embedded-can/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ This project is developed and maintained by the [HAL team](https://github.com/ru

[API reference]: https://docs.rs/embedded-can

## Optional features

- **`defmt-03`**: Derive `defmt::Format` from `defmt` 0.3 for enums and structs.

## Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.60 and up. It *might*
Expand Down
3 changes: 3 additions & 0 deletions embedded-can/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// Standard 11-bit CAN Identifier (`0..=0x7FF`).
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub struct StandardId(u16);

impl StandardId {
Expand Down Expand Up @@ -44,6 +45,7 @@ impl StandardId {

/// Extended 29-bit CAN Identifier (`0..=1FFF_FFFF`).
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub struct ExtendedId(u32);

impl ExtendedId {
Expand Down Expand Up @@ -93,6 +95,7 @@ impl ExtendedId {

/// A CAN Identifier (standard or extended).
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
pub enum Id {
/// Standard 11-bit Identifier (`0..=0x7FF`).
Standard(StandardId),
Expand Down
1 change: 1 addition & 0 deletions embedded-can/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl Error for core::convert::Infallible {
/// free to define more specific or additional error types. However, by providing
/// a mapping to these common CAN errors, generic code can still react to them.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[non_exhaustive]
pub enum ErrorKind {
/// The peripheral receive buffer was overrun.
Expand Down

0 comments on commit 8a9b250

Please sign in to comment.