regs 0.1.0

Low-level utilities for defining and accessing memory-mapped registers
Documentation
#![no_std]

use core::ops::{BitAnd, BitOr, Not};

pub trait Width: Not<Output = Self> + BitAnd<Output = Self> + BitOr<Output = Self> + Sized {}
impl<T> Width for T where
    T: Not<Output = Self> + BitAnd<Output = Self> + BitOr<Output = Self> + Sized
{
}

#[inline(always)]
pub unsafe fn write<T: Width>(addr: usize, value: T) {
    core::ptr::write_volatile(addr as *mut T, value);
}

#[inline(always)]
pub unsafe fn read<T: Width>(addr: usize) -> T {
    core::ptr::read_volatile(addr as *const T)
}

#[inline(always)]
pub unsafe fn modify<T: Width>(addr: usize, clear: T, set: T) {
    write::<T>(addr, (read::<T>(addr) & !clear) | set);
}