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 made primarily for embedded-devices, which is a collection of drivers for a variety of different embedded sensors and devices.
Usage
Add this to your Cargo.toml:
[]
# You will need these to define your own bitfield-capable enums
= { = "0.1.14", = false, = ["derive"] }
= { = "1.16.3", = ["derive", "min_const_generics"] }
= "0.9.7"
Registers are defined simply by annotating a bondrewd struct with #[register(address = 0x42, mode = "rw")].
Take for example this register definition for the device id of a MCP9808:
use register;
For more specific usage 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.