6 releases

Uses old Rust 2015

0.2.2 Oct 20, 2023
0.2.1 Aug 14, 2021
0.2.0 Mar 8, 2017
0.1.2 Oct 15, 2016
0.1.1 Sep 28, 2016

#66 in Hardware support

Download history 25712/week @ 2023-12-13 20792/week @ 2023-12-20 18311/week @ 2023-12-27 25988/week @ 2024-01-03 25033/week @ 2024-01-10 24999/week @ 2024-01-17 23408/week @ 2024-01-24 24927/week @ 2024-01-31 23163/week @ 2024-02-07 23075/week @ 2024-02-14 25766/week @ 2024-02-21 24875/week @ 2024-02-28 27545/week @ 2024-03-06 25446/week @ 2024-03-13 26220/week @ 2024-03-20 21596/week @ 2024-03-27

105,727 downloads per month
Used in 1,223 crates (22 directly)

MIT/Apache

10KB
56 lines

crates.io crates.io

volatile-register

Volatile access to memory mapped hardware registers

Documentation

License

Licensed under either of

at your option.

Contribution

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


lib.rs:

Volatile access to memory mapped hardware registers

Usage

use volatile_register::RW;

// Create a struct that represents the memory mapped register block
/// Nested Vector Interrupt Controller
#[repr(C)]
pub struct Nvic {
    /// Interrupt Set-Enable
    pub iser: [RW<u32>; 8],
    reserved0: [u32; 24],
    /// Interrupt Clear-Enable
    pub icer: [RW<u32>; 8],
    reserved1: [u32; 24],
    // .. more registers ..
}

// Access the registers by casting the base address of the register block
// to the previously declared `struct`
let nvic = 0xE000_E100 as *const Nvic;
// Unsafe because the compiler can't verify the address is correct
unsafe { (*nvic).iser[0].write(1) }

Dependencies

~7KB