register-rs
Unified interface for type-safe MMIO and CPU register access in Rust.
Outline
Usage
This crate uses the tock-register-interface, please refer to their
Readme for the whole
API. Make sure to check the register_structs!
explanation, especially the fact that you must
explicitly annotate gaps.
Defining MMIO registers
use ;
register_bitfields!
register_structs!
The Deref pattern for drivers
The MMIO
part of this crate can and will often be used for implementing device drivers. In this
case, you might find the Deref pattern
useful for referencing your registers. It alleviates you
from manually dereferencing each time a register access is due, and also encapsulates the unsafe
keyword.
Here is an example (extending the code snippet from above):
register_bitfields!
register_structs!
Defining CPU registers
For CPU registers, you only need to implement the respective read/write trait. All other methods are provided by default.
use ;
register_bitfields!
;
static CNTP_CTL_EL0: Reg = Reg ;
Testing
In order to use this crate in custom_test_frameworks
environments, please set the
no_std_unit_tests
feature flag in your dependency section.
Otherwise, you might encounter errors like the following:
error[E0463]: can't find crate for `test`
--> src/bsp/driver/bcm/bcm2xxx_gpio.rs:52:1
|
52 | / register_structs! {
53 | | #[allow(non_snake_case)]
54 | | RegisterBlock {
55 | | (0x00 => GPFSEL0: ReadWrite<u32>),
... |
66 | | }
67 | | }
| |_^ can't find crate
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (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.