#register #bit-field #set-bit #ruspiro #field-value #registerfields

no-std ruspiro-register

The crate provides the definitions to conviniently work with register field values that are typically presented by a set of bit fields

15 releases

0.5.5 Dec 28, 2021
0.5.4 Apr 20, 2021
0.5.0 Sep 18, 2020
0.4.2 Mar 31, 2020
0.0.2 Jul 29, 2019

#649 in Embedded development

Download history 134/week @ 2023-12-14 65/week @ 2023-12-21 11/week @ 2023-12-28 86/week @ 2024-01-04 265/week @ 2024-01-11 398/week @ 2024-01-18 145/week @ 2024-01-25 237/week @ 2024-02-01 242/week @ 2024-02-08 98/week @ 2024-02-15 79/week @ 2024-02-22 68/week @ 2024-02-29 88/week @ 2024-03-07 69/week @ 2024-03-14 111/week @ 2024-03-21 91/week @ 2024-03-28

373 downloads per month
Used in 13 crates (5 directly)

MIT/Apache

14KB
169 lines

RusPiRo Register

The crate provides the definitions to conviniently work with register field values that are typically presented by a set of bit fields.

CI Latest Version Documentation License

Usage

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

[dependencies]
ruspiro-register = "0.5.5"

A single register field is specified with its bit mask and the bit shift. The RegisterField structure can be instantiated for the types u8, u16, u32 and u64.

use ruspiro_register::*;

fn main() {
    let field = RegisterField::<u32>::new(0x3, 6);
}

To represent a specific value of a register field the RegisterFieldValue structure is used. It is available for the same scalar types as the RegisterField: u8, u16, u32 and u64.

use ruspiro_register::*;

fn main() {
    let field = RegisterField::<u8>::new(0x3, 2);
    // the value to the regsiter field will be shifted and masked internally
    // so it will be provided without any shifting
    let value = RegisterFieldValue::<u8>::new(field, 0b10);
    println!("{:?}", value);
}

The register field value printed will look like this then:

RegisterFieldValue { field: RegisterField {
    Bits: [3:2]
    Mask: 0b1100
}, value: 2, raw_value: 8 }

It is quite unlikely those definitions will be directly used as the represantation of a full register with all its fields. Typically macros will be used to reduce the complexity of the register definitions. Examples can be found in the ruspiro-mmio-register and the ruspiro-arch-aarch64 crates.

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.

No runtime deps