5 个版本
0.1.4 | 2021年12月28日 |
---|---|
0.1.3 | 2021年8月30日 |
0.1.2 | 2021年4月26日 |
0.1.1 | 2020年9月18日 |
0.1.0 | 2020年9月17日 |
#1136 in 嵌入式开发
586 每月下载量
在 6 crates 中使用
17KB
153 行
RusPiRo MMIO Register
该包提供了宏来方便地定义内存映射I/O (MMIO) 寄存器。
用法
要使用此包,只需将其依赖项添加到您的 Cargo.toml
文件中
[dependencies]
ruspiro-mmio-register = "0.1.4"
使用提供的 define_mmio_register!
宏,MMIO寄存器的定义非常直接
use ruspiro_mmio_register::*;
define_mmio_register!(
/// FOO Register with read/write access, 32 bit wide and mapped at memory
/// address 0x3F20_0000
FOO<ReadWrite<u32>@(0x3F20_0000)> {
/// This register provides a field BAR at offset 0 covering 1 Bit
BAR OFFSET(0),
/// There is another field BAZ at offset 1 covering 3 Bits
BAZ OFFSET(1) BITS(3),
/// The third field BAL also has specific predefined values
BAL OFFSET(4) BITS(2) [
/// Field Value 1
VAL1 = 0b01,
/// Field Value 2
VAL2 = 0b10
]
}
);
一旦定义了寄存器,就可以根据其类型(ReadOnly,WriteOnly,ReadWrite)来读取或写入数据。
fn main() {
// write a specific value to a field of the register
FOO::Register.write_value( FOO::BAL::VAL1 );
// combine two field values with logical OR
FOO::Register.write_value( FOO::BAL::VAL1 | FOO::BAL::VAL2 );
// if there is no field defined for the MMIO register or raw value storage
// is preffered the raw value could be written
FOO::Register.write_value(FOO::BAZ::with_value(0b101));
FOO::Register.write(FOO::BAZ, 0b101);
FOO::Register.set(0x1F);
// reading from the MMIO register works in a simmilar way
let baz_val = FOO::Register.read(FOO::BAL); // return 0b01 or 0b10 eg.
let baz_field = FOO::Register.read_value(FOO::BAL); // returns a FieldValue
let raw_val = FOO::Register.get();
}
许可证
根据您的选择,许可在Apache License,版本2.0(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)或MIT(LICENSE-MIT 或 https://open-source.org.cn/licenses/MIT)下。
依赖项
~14KB