reg-map 0.1.1

Derive volatile accesses to a register map and memory-mapped IO
Documentation
  • Coverage
  • 95.24%
    20 out of 21 items documented1 out of 8 items with examples
  • Size
  • Source code size: 69.33 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.41 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • rikyborg/reg-map
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rikyborg

reg-map

Crates.io Version docs.rs

Derive volatile accesses to a register map and memory-mapped IO.

Documentation

API documentation in available at docs.rs/reg-map.

Usage

Here's a quick-and-dirty example, see the API documentation for more use cases such as iteration and a more in-depth description of the functionality.

use reg_map::RegMap;

// define struct Registers with the register map
// and derive the pointer RegistersPtr using the RegMap macro
#[repr(C)]
#[derive(RegMap, Default)]
struct Registers {
    field1: u64,
    field2: u32,
    #[reg(RO)]
    read_only_field: i8,
    #[reg(WO)]
    write_only_field: u128,
    #[reg(RW)]
    read_write_is_default: i16,
}

// initialize the base struct
// and obtain a pointer to the registers
let mut regs = Registers::default();
let ptr = RegistersPtr::from_mut(&mut regs);

// when dealing with e.g. memory-mapped IO (MMIO),
// you'd probably just get a pointer to the data from a known base address
// let ptr = unsafe { RegistersPtr::from_ptr(0xAA55_000 as *mut _) };

// all write() operations are volatile
ptr.field1().write(10);
ptr.field2().write(32);
ptr.write_only_field().write(76);
ptr.read_write_is_default().write(98);

// all read() operations are volatile
assert_eq!(ptr.field1().read(), 10);
assert_eq!(ptr.field2().read(), 32);
assert_eq!(ptr.read_only_field().read(), 0);
assert_eq!(ptr.read_write_is_default().read(), 98);

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.