feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support: - Splash screen on boot (1.5s) with project name, version, board - Dashboard showing radio state, config, counters, RSSI/SNR - RSSI history sparkline (64-sample ring buffer, 2px-wide bars) - DisplayOn/DisplayOff host commands routed via dedicated channel - Pure render functions against generic DrawTarget (no hardware coupling) - Display on/off control bypasses radio task entirely Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
17624 files changed
+4564928
-38
No files matched your search
+1
@@ -0,0 +1 @@
|
||||
{"files":{".cargo_vcs_info.json":"168c62bb04943a60e16be84cb2cd0af990ce48322a7e7d58308f2e3c9e7fba27","CHANGELOG.md":"8e0636d51fe4992edcc44568551e4577f25aa8b70796f231e7e06414d1ceb068","Cargo.toml":"325f994c5dac7b04b5b958a3e34e88d9b63af311af3118cce507c34b5cbce352","Cargo.toml.orig":"e34519b52d716dec4c3043d552b82c867e1628925f24b12bc8f18c6811aac0c9","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"b32b47118594bca5e21a37d64d9924bff856bf4f688c482b417cc5e885d6e7bf","README.md":"f7aac3bad319a567fee675ae352fdf12ca60b35c995044b904d0bee055ac09ca","src/blocking.rs":"19bc74ed1bf295a5f8c3aec695234bb67167406623458682059c7b467aec32a3","src/id.rs":"e1a3b3e2d9930b5e1d2ef327c596bece1cf067c007d4815151d533c3cb9afdb3","src/lib.rs":"65eea1dc21f5c702e5980363da3c79ee92932235d7ec86c7f1b77c3f920d947d","src/nb.rs":"ac377f29b1d79c73f3649a0cc598cd2496023826ebfe207433f3aec44f963bbe"},"package":"e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438"}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"git": {
|
||||
"sha1": "a55595cc80f19626f5db58abb6da619459064bf7"
|
||||
},
|
||||
"path_in_vcs": "embedded-can"
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
...
|
||||
|
||||
## [v0.4.1] - 2022-09-28
|
||||
|
||||
### Removed
|
||||
- Unnecessary `embedded-hal` dependency.
|
||||
|
||||
## [v0.4.0] - 2022-09-28
|
||||
|
||||
Release of version of the traits extracted from embedded-hal.
|
||||
|
||||
[Unreleased]: https://github.com/rust-embedded/embedded-hal/compare/embedded-can-v0.4.1...HEAD
|
||||
[v0.4.1]: https://github.com/rust-embedded/embedded-hal/compare/embedded-can-v0.4.0...embedded-can-v0.4.1
|
||||
[v0.4.0]: https://github.com/rust-embedded/embedded-hal/tree/embedded-can-v0.4.0
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
name = "embedded-can"
|
||||
version = "0.4.1"
|
||||
description = "HAL traits for Controller Area Network (CAN) devices."
|
||||
documentation = "https://docs.rs/embedded-can"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"hal",
|
||||
"IO",
|
||||
]
|
||||
categories = [
|
||||
"embedded",
|
||||
"hardware-support",
|
||||
"no-std",
|
||||
]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/rust-embedded/embedded-hal"
|
||||
|
||||
[dependencies.nb]
|
||||
version = "1"
|
||||
Vendored
+201
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2021-2022 The Rust embedded HAL team and contributors.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Vendored
+37
@@ -0,0 +1,37 @@
|
||||
[](https://crates.io/crates/embedded-can)
|
||||
[](https://crates.io/crates/embedded-can)
|
||||
[](https://docs.rs/embedded-can)
|
||||

|
||||
|
||||
# `embedded-can`
|
||||
|
||||
An embedded Controller Area Network (CAN) abstraction layer. This crate defines generic traits to be implemented by CAN driver and MCU HAL crates.
|
||||
|
||||
This project is developed and maintained by the [HAL team](https://github.com/rust-embedded/wg#the-hal-team).
|
||||
|
||||
## [API reference]
|
||||
|
||||
[API reference]: https://docs.rs/embedded-can
|
||||
|
||||
## Minimum Supported Rust Version (MSRV)
|
||||
|
||||
This crate is guaranteed to compile on stable Rust 1.54 and up. It *might*
|
||||
compile with older versions but that may change in any new patch release.
|
||||
|
||||
See [here](../docs/msrv.md) for details on how the MSRV may be upgraded.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||
http://www.apache.org/licenses/LICENSE-2.0)
|
||||
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
|
||||
dual licensed as above, without any additional terms or conditions.
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
//! Blocking CAN API
|
||||
|
||||
/// A blocking CAN interface that is able to transmit and receive frames.
|
||||
pub trait Can {
|
||||
/// Associated frame type.
|
||||
type Frame: crate::Frame;
|
||||
|
||||
/// Associated error type.
|
||||
type Error: crate::Error;
|
||||
|
||||
/// Puts a frame in the transmit buffer. Blocks until space is available in
|
||||
/// the transmit buffer.
|
||||
fn transmit(&mut self, frame: &Self::Frame) -> Result<(), Self::Error>;
|
||||
|
||||
/// Blocks until a frame was received or an error occured.
|
||||
fn receive(&mut self) -> Result<Self::Frame, Self::Error>;
|
||||
}
|
||||
Vendored
+209
@@ -0,0 +1,209 @@
|
||||
//! CAN Identifiers.
|
||||
|
||||
/// Standard 11-bit CAN Identifier (`0..=0x7FF`).
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||
pub struct StandardId(u16);
|
||||
|
||||
impl StandardId {
|
||||
/// CAN ID `0`, the highest priority.
|
||||
pub const ZERO: Self = Self(0);
|
||||
|
||||
/// CAN ID `0x7FF`, the lowest priority.
|
||||
pub const MAX: Self = Self(0x7FF);
|
||||
|
||||
/// Tries to create a `StandardId` from a raw 16-bit integer.
|
||||
///
|
||||
/// This will return `None` if `raw` is out of range of an 11-bit integer (`> 0x7FF`).
|
||||
#[inline]
|
||||
pub const fn new(raw: u16) -> Option<Self> {
|
||||
if raw <= 0x7FF {
|
||||
Some(Self(raw))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new `StandardId` without checking if it is inside the valid range.
|
||||
///
|
||||
/// # Safety
|
||||
/// Using this method can create an invalid ID and is thus marked as unsafe.
|
||||
#[inline]
|
||||
pub const unsafe fn new_unchecked(raw: u16) -> Self {
|
||||
Self(raw)
|
||||
}
|
||||
|
||||
/// Returns this CAN Identifier as a raw 16-bit integer.
|
||||
#[inline]
|
||||
pub fn as_raw(&self) -> u16 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Extended 29-bit CAN Identifier (`0..=1FFF_FFFF`).
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||
pub struct ExtendedId(u32);
|
||||
|
||||
impl ExtendedId {
|
||||
/// CAN ID `0`, the highest priority.
|
||||
pub const ZERO: Self = Self(0);
|
||||
|
||||
/// CAN ID `0x1FFFFFFF`, the lowest priority.
|
||||
pub const MAX: Self = Self(0x1FFF_FFFF);
|
||||
|
||||
/// Tries to create a `ExtendedId` from a raw 32-bit integer.
|
||||
///
|
||||
/// This will return `None` if `raw` is out of range of an 29-bit integer (`> 0x1FFF_FFFF`).
|
||||
#[inline]
|
||||
pub const fn new(raw: u32) -> Option<Self> {
|
||||
if raw <= 0x1FFF_FFFF {
|
||||
Some(Self(raw))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new `ExtendedId` without checking if it is inside the valid range.
|
||||
///
|
||||
/// # Safety
|
||||
/// Using this method can create an invalid ID and is thus marked as unsafe.
|
||||
#[inline]
|
||||
pub const unsafe fn new_unchecked(raw: u32) -> Self {
|
||||
Self(raw)
|
||||
}
|
||||
|
||||
/// Returns this CAN Identifier as a raw 32-bit integer.
|
||||
#[inline]
|
||||
pub fn as_raw(&self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Returns the Base ID part of this extended identifier.
|
||||
pub fn standard_id(&self) -> StandardId {
|
||||
// ID-28 to ID-18
|
||||
StandardId((self.0 >> 18) as u16)
|
||||
}
|
||||
}
|
||||
|
||||
/// A CAN Identifier (standard or extended).
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum Id {
|
||||
/// Standard 11-bit Identifier (`0..=0x7FF`).
|
||||
Standard(StandardId),
|
||||
|
||||
/// Extended 29-bit Identifier (`0..=0x1FFF_FFFF`).
|
||||
Extended(ExtendedId),
|
||||
}
|
||||
|
||||
/// Implement `Ord` according to the CAN arbitration rules
|
||||
///
|
||||
/// When performing arbitration, frames are looked at bit for bit starting
|
||||
/// from the beginning. A bit with the value 0 is dominant and a bit with
|
||||
/// value of 1 is recessive.
|
||||
///
|
||||
/// When two devices are sending frames at the same time, as soon as the first
|
||||
/// bit is found which differs, the frame with the corresponding dominant
|
||||
/// 0 bit will win and get to send the rest of the frame.
|
||||
///
|
||||
/// This implementation of `Ord` for `Id` will take this into consideration
|
||||
/// and when comparing two different instances of `Id` the "smallest" will
|
||||
/// always be the ID which would form the most dominant frame, all other
|
||||
/// things being equal.
|
||||
impl Ord for Id {
|
||||
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
|
||||
let split_id = |id: &Id| {
|
||||
let (standard_id_part, ide_bit, extended_id_part) = match id {
|
||||
Id::Standard(StandardId(x)) => (*x, 0, 0),
|
||||
Id::Extended(x) => (
|
||||
x.standard_id().0,
|
||||
1,
|
||||
x.0 & ((1 << 18) - 1), // Bit ID-17 to ID-0
|
||||
),
|
||||
};
|
||||
(standard_id_part, ide_bit, extended_id_part)
|
||||
};
|
||||
|
||||
split_id(self).cmp(&split_id(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Id {
|
||||
fn partial_cmp(&self, other: &Id) -> Option<core::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StandardId> for Id {
|
||||
#[inline]
|
||||
fn from(id: StandardId) -> Self {
|
||||
Id::Standard(id)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExtendedId> for Id {
|
||||
#[inline]
|
||||
fn from(id: ExtendedId) -> Self {
|
||||
Id::Extended(id)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn standard_id_new() {
|
||||
assert_eq!(
|
||||
StandardId::new(StandardId::MAX.as_raw()),
|
||||
Some(StandardId::MAX)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_id_new_out_of_range() {
|
||||
assert_eq!(StandardId::new(StandardId::MAX.as_raw() + 1), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn standard_id_new_unchecked_out_of_range() {
|
||||
let id = StandardId::MAX.as_raw() + 1;
|
||||
assert_eq!(unsafe { StandardId::new_unchecked(id) }, StandardId(id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_id_new() {
|
||||
assert_eq!(
|
||||
ExtendedId::new(ExtendedId::MAX.as_raw()),
|
||||
Some(ExtendedId::MAX)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_id_new_out_of_range() {
|
||||
assert_eq!(ExtendedId::new(ExtendedId::MAX.as_raw() + 1), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn extended_id_new_unchecked_out_of_range() {
|
||||
let id = ExtendedId::MAX.as_raw() + 1;
|
||||
assert_eq!(unsafe { ExtendedId::new_unchecked(id) }, ExtendedId(id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_standard_id_from_extended_id() {
|
||||
assert_eq!(
|
||||
Some(ExtendedId::MAX.standard_id()),
|
||||
StandardId::new((ExtendedId::MAX.0 >> 18) as u16)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cmp_id() {
|
||||
assert!(StandardId::ZERO < StandardId::MAX);
|
||||
assert!(ExtendedId::ZERO < ExtendedId::MAX);
|
||||
|
||||
assert!(Id::Standard(StandardId::ZERO) < Id::Extended(ExtendedId::ZERO));
|
||||
assert!(Id::Extended(ExtendedId::ZERO) < Id::Extended(ExtendedId::MAX));
|
||||
assert!(Id::Extended(ExtendedId((1 << 11) - 1)) < Id::Standard(StandardId(1)));
|
||||
assert!(Id::Standard(StandardId(1)) < Id::Extended(ExtendedId::MAX));
|
||||
}
|
||||
}
|
||||
Vendored
+133
@@ -0,0 +1,133 @@
|
||||
//! Controller Area Network (CAN) traits
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![no_std]
|
||||
|
||||
pub mod blocking;
|
||||
pub mod nb;
|
||||
|
||||
mod id;
|
||||
|
||||
pub use id::*;
|
||||
|
||||
/// A CAN2.0 Frame
|
||||
pub trait Frame: Sized {
|
||||
/// Creates a new frame.
|
||||
///
|
||||
/// This will return `None` if the data slice is too long.
|
||||
fn new(id: impl Into<Id>, data: &[u8]) -> Option<Self>;
|
||||
|
||||
/// Creates a new remote frame (RTR bit set).
|
||||
///
|
||||
/// This will return `None` if the data length code (DLC) is not valid.
|
||||
fn new_remote(id: impl Into<Id>, dlc: usize) -> Option<Self>;
|
||||
|
||||
/// Returns true if this frame is a extended frame.
|
||||
fn is_extended(&self) -> bool;
|
||||
|
||||
/// Returns true if this frame is a standard frame.
|
||||
fn is_standard(&self) -> bool {
|
||||
!self.is_extended()
|
||||
}
|
||||
|
||||
/// Returns true if this frame is a remote frame.
|
||||
fn is_remote_frame(&self) -> bool;
|
||||
|
||||
/// Returns true if this frame is a data frame.
|
||||
fn is_data_frame(&self) -> bool {
|
||||
!self.is_remote_frame()
|
||||
}
|
||||
|
||||
/// Returns the frame identifier.
|
||||
fn id(&self) -> Id;
|
||||
|
||||
/// Returns the data length code (DLC) which is in the range 0..8.
|
||||
///
|
||||
/// For data frames the DLC value always matches the length of the data.
|
||||
/// Remote frames do not carry any data, yet the DLC can be greater than 0.
|
||||
fn dlc(&self) -> usize;
|
||||
|
||||
/// Returns the frame data (0..8 bytes in length).
|
||||
fn data(&self) -> &[u8];
|
||||
}
|
||||
|
||||
/// CAN error
|
||||
pub trait Error: core::fmt::Debug {
|
||||
/// Convert error to a generic CAN error kind
|
||||
///
|
||||
/// By using this method, CAN errors freely defined by HAL implementations
|
||||
/// can be converted to a set of generic serial errors upon which generic
|
||||
/// code can act.
|
||||
fn kind(&self) -> ErrorKind;
|
||||
}
|
||||
|
||||
impl Error for core::convert::Infallible {
|
||||
fn kind(&self) -> ErrorKind {
|
||||
match *self {}
|
||||
}
|
||||
}
|
||||
|
||||
/// CAN error kind
|
||||
///
|
||||
/// This represents a common set of CAN operation errors. HAL implementations are
|
||||
/// 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)]
|
||||
#[non_exhaustive]
|
||||
pub enum ErrorKind {
|
||||
/// The peripheral receive buffer was overrun.
|
||||
Overrun,
|
||||
|
||||
// MAC sublayer errors
|
||||
/// A bit error is detected at that bit time when the bit value that is
|
||||
/// monitored differs from the bit value sent.
|
||||
Bit,
|
||||
|
||||
/// A stuff error is detected at the bit time of the sixth consecutive
|
||||
/// equal bit level in a frame field that shall be coded by the method
|
||||
/// of bit stuffing.
|
||||
Stuff,
|
||||
|
||||
/// Calculated CRC sequence does not equal the received one.
|
||||
Crc,
|
||||
|
||||
/// A form error shall be detected when a fixed-form bit field contains
|
||||
/// one or more illegal bits.
|
||||
Form,
|
||||
|
||||
/// An ACK error shall be detected by a transmitter whenever it does not
|
||||
/// monitor a dominant bit during the ACK slot.
|
||||
Acknowledge,
|
||||
|
||||
/// A different error occurred. The original error may contain more information.
|
||||
Other,
|
||||
}
|
||||
|
||||
impl Error for ErrorKind {
|
||||
fn kind(&self) -> ErrorKind {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Display for ErrorKind {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
Self::Overrun => write!(f, "The peripheral receive buffer was overrun"),
|
||||
Self::Bit => write!(
|
||||
f,
|
||||
"Bit value that is monitored differs from the bit value sent"
|
||||
),
|
||||
Self::Stuff => write!(f, "Sixth consecutive equal bits detected"),
|
||||
Self::Crc => write!(f, "Calculated CRC sequence does not equal the received one"),
|
||||
Self::Form => write!(
|
||||
f,
|
||||
"A fixed-form bit field contains one or more illegal bits"
|
||||
),
|
||||
Self::Acknowledge => write!(f, "Transmitted frame was not acknowledged"),
|
||||
Self::Other => write!(
|
||||
f,
|
||||
"A different error occurred. The original error may contain more information"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
//! Non-blocking CAN API
|
||||
|
||||
/// A CAN interface that is able to transmit and receive frames.
|
||||
pub trait Can {
|
||||
/// Associated frame type.
|
||||
type Frame: crate::Frame;
|
||||
|
||||
/// Associated error type.
|
||||
type Error: crate::Error;
|
||||
|
||||
/// Puts a frame in the transmit buffer to be sent on the bus.
|
||||
///
|
||||
/// If the transmit buffer is full, this function will try to replace a pending
|
||||
/// lower priority frame and return the frame that was replaced.
|
||||
/// Returns `Err(WouldBlock)` if the transmit buffer is full and no frame can be
|
||||
/// replaced.
|
||||
///
|
||||
/// # Notes for implementers
|
||||
///
|
||||
/// * Frames of equal identifier shall be transmited in FIFO fashion when more
|
||||
/// than one transmit buffer is available.
|
||||
/// * When replacing pending frames make sure the frame is not in the process of
|
||||
/// being send to the bus.
|
||||
fn transmit(&mut self, frame: &Self::Frame) -> nb::Result<Option<Self::Frame>, Self::Error>;
|
||||
|
||||
/// Returns a received frame if available.
|
||||
fn receive(&mut self) -> nb::Result<Self::Frame, Self::Error>;
|
||||
}
|
||||
Reference in new issue
Block a user