Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defmt feature and traits for embedded-can #612

Merged
merged 1 commit into from
Jul 4, 2024
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
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