#memory-mapped #register #mmio #raspberry-pi #ruspiro

无std ruspiro-mmio-register

该包提供了宏来方便地定义内存映射I/O (MMIO) 寄存器

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 嵌入式开发

Download history · Rust 包仓库 37/week @ 2024-03-13 · Rust 包仓库 76/week @ 2024-03-20 · Rust 包仓库 61/week @ 2024-03-27 · Rust 包仓库 67/week @ 2024-04-03 · Rust 包仓库 100/week @ 2024-04-10 · Rust 包仓库 164/week @ 2024-04-17 · Rust 包仓库 39/week @ 2024-04-24 · Rust 包仓库 41/week @ 2024-05-01 · Rust 包仓库 35/week @ 2024-05-08 · Rust 包仓库 36/week @ 2024-05-15 · Rust 包仓库 29/week @ 2024-05-22 · Rust 包仓库 84/week @ 2024-05-29 · Rust 包仓库 170/week @ 2024-06-05 · Rust 包仓库 115/week @ 2024-06-12 · Rust 包仓库 188/week @ 2024-06-19 · Rust 包仓库 102/week @ 2024-06-26 · Rust 包仓库

586 每月下载量
6 crates 中使用

MIT/Apache

17KB
153

RusPiRo MMIO Register

该包提供了宏来方便地定义内存映射I/O (MMIO) 寄存器。

CI Latest Version Documentation License

用法

要使用此包,只需将其依赖项添加到您的 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-APACHEhttps://apache.ac.cn/licenses/LICENSE-2.0)或MIT(LICENSE-MIThttps://open-source.org.cn/licenses/MIT)下。

依赖项

~14KB