Crates.io | mcp2003a |
lib.rs | mcp2003a |
version | 0.0.24 |
source | src |
created_at | 2024-06-23 17:16:32.386601 |
updated_at | 2024-12-07 22:10:29.725187 |
description | MCP2003A LIN transceiver driver with embedded-hal traits for no-std environments. |
homepage | |
repository | https://github.com/zpg6/mcp2003a |
max_upload_size | |
id | 1281318 |
size | 39,809 |
Embedded Rust Microchip MCP2003A/B LIN transceiver driver with embedded-hal
blocking and async traits for no-std
environments.
[!WARNING] This crate may not be suitable for production use. It was written as hands-on learning exercise of a well-documented specification. It may not cover all edge cases or vendor-specific implementations. Please use with caution.
This driver attempts to be a simple reflection of the well-documented instructions from the LIN specification: https://www.lin-cia.org/fileadmin/microsites/lin-cia.org/resources/documents/LIN_2.2A.pdf
Tested on:
Should also work with:
Full Documentation: https://docs.rs/mcp2003a/latest/mcp2003a/
Blocking:
embedded-hal = "1.0.0"
- Embedded HAL traits for GPIO, UART, and Delay drivers.embedded-hal-nb = "1.0.0"
- Additional non-blocking traits using nb
crate underneath.Async:
embedded-hal-async = "1.0.0"
- Async traits for async GPIO, and Delay drivers.embedded-io-async = "0.6.1"
- Async traits for async UART drivers.Add the crate to your Cargo.toml
:
cargo add mcp2003a
let mut mcp2003a = Mcp2003a::new(uart2_driver, break_pin_driver, delay);
let lin_bus_config = LinBusConfig {
speed: LinBusSpeed::Baud19200,
break_duration: LinBreakDuration::Minimum13Bits, // Test for your application
wakeup_duration: LinWakeupDuration::Minimum250Microseconds, // Test for your application
read_device_response_timeout: LinReadDeviceResponseTimeout::DelayMilliseconds(15), // Test for your application
inter_frame_space: LinInterFrameSpace::DelayMilliseconds(1), // Test for your application
};
mcp2003a.init(lin_bus_config);
mcp2003a.send_wakeup();
// Works for different LIN versions, you calculate id and checksum based on your application
mcp2003a.send_frame(0x01, &[0x02, 0x03], 0x05).unwrap();
let mut read_buffer = [0u8; 8]; // Initialize the buffer to the frame's known size
let checksum = mcp2003a.read_frame(0xC1, &mut read_buffer).unwrap();
If you have async UART, GPIO, and Delay drivers that implement the embedded-hal-async
traits, you can use the async methods (recommended). For example:
mcp2003a.send_frame_async(0x01, &[0x02, 0x03], 0x05).await.unwrap();
(More coming soon)
esp-idf-hal
(std).