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

no-std ruspiro-mmio-register

The crate provides macros to conviniently define memory mapped I/O (MMIO) registers

5 releases

0.1.4 Dec 28, 2021
0.1.3 Aug 30, 2021
0.1.2 Apr 26, 2021
0.1.1 Sep 18, 2020
0.1.0 Sep 17, 2020

#1739 in Embedded development

Download history 22/week @ 2024-07-19 89/week @ 2024-07-26 133/week @ 2024-08-02 169/week @ 2024-08-09 185/week @ 2024-08-16 267/week @ 2024-08-23 384/week @ 2024-08-30 345/week @ 2024-09-06 344/week @ 2024-09-13 321/week @ 2024-09-20 186/week @ 2024-09-27 45/week @ 2024-10-04 61/week @ 2024-10-11 97/week @ 2024-10-18 11/week @ 2024-10-25 36/week @ 2024-11-01

206 downloads per month
Used in 6 crates

MIT/Apache

17KB
153 lines

RusPiRo MMIO Register

The crate provides macros to conviniently define memory mapped I/O (MMIO) registers.

CI Latest Version Documentation License

Usage

To use this crate simply add the dependency to your Cargo.toml file:

[dependencies]
ruspiro-mmio-register = "0.1.4"

The definition of MMIO registers is straight forward using the provided define_mmio_register! macro like so:

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
        ]
    }
);

Once the register is defined it can be used to read data from or write data to, depending on its type (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();
}

License

Licensed under Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or MIT (LICENSE-MIT or http://opensource.org/licenses/MIT)) at your choice.

Dependencies

~14KB