can-hal-rs 0.3.2

Hardware-agnostic traits for CAN bus communication
Documentation

crates.io Documentation Minimum Supported Rust Version License CI

can-hal-rs defines the interface. Backend crates implement it. Application code is portable across CAN hardware.

no_std support

This crate is no_std-compatible (requires Rust 1.81+). The std feature is enabled by default. To use in embedded / no_std contexts:

[dependencies]
can-hal-rs = { version = "0.3", default-features = false }

Traits

Trait Purpose
Transmit / Receive Classic CAN (up to 8 bytes)
TransmitFd / ReceiveFd CAN FD (up to 64 bytes)
Driver / ChannelBuilder Open and configure channels
Filterable Hardware acceptance filtering
BusStatus Bus state and error counters

Async variants (AsyncTransmit, AsyncReceive, etc.) are available behind the async feature flag.

Usage

use can_hal::{CanId, CanFrame, Transmit, Receive};

fn echo<T: Transmit<Error = E> + Receive<Error = E>, E: can_hal::CanError>(
    channel: &mut T,
) -> Result<(), E> {
    let msg = channel.receive()?;
    channel.transmit(msg.frame())?;
    Ok(())
}

Backend crates

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.