Embedded Registers
WARNING: This crate is currently in experimental state, so anything may change at any time.
This crate provides a procedural macro for effortless definitions of registers in embedded device drivers. This is automatically generates functions to read/write the register over I2C and SPI, although it isn't limited to those buses. The resulting struct may trivially be extended to work with any other similar communication bus.
- Allows defintion of read-only, write-only and read-write registers
- Generates I2C and SPI read/write functions
- Registers are defined as bitfields via bondrewd.
- Only the accessed bitfield members are decoded, conserving memory and saving on CPU time.
- Supports both async and blocking operation modes
This crate was designed for the embedded-devices crate, which aims to provide modern async-capable and coherent definitions for many embedded devices.
Usage
Add this to your Cargo.toml
:
[]
# You will need this to define your own bitfield-capable enums
= { = "0.1.14", = false, = ["derive"] }
= "0.9.6"
For a simple register definition example, take a look at this DeviceId
register
from the MCP9808 temperature sensor:
use register;
You may then read the register simply by calling DeviceId::read_i2c
or DeviceId::read_i2c_blocking
(or similarly write to it if you specified write
in the definition above):
let reg = read_i2c.await?;
info!;
// Prints: DeviceId ([4, 0]) => DeviceIdBitfield { device_id: 4, revision: 0 }
For more information and more complex examples, please refer to the embededded-registers docs and the bondrewd docs.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.