Register Bits 🦀

A crate to perform register-bit manipulation which is verified at compile time
This crate provides many inlined procedures for performing bit manipulations including taking a selection of bits, concatinating bits and forming new bitstring. All these manipulations are checked at compile time to ensure reliability at runtime at the cost of compilation duration.
There are 4 different register types.
- A 8 bit register which can be enabled with the
8bit
feature - A 16 bit register which can be enabled with the
16bit
feature - A 32 bit register which can be enabled with the
32bit
feature (included by default) - A 64 bit register which can be enabled with the
64bit
feature
All the register variants can be included using the all-regs
feature.
Usage
To utilize most of the functionality a set of traits need to used. To utilize all the useful traites it is recommended to use the prelude.
Basic Usage
use *;
// Forms a Reg32Bits<32>
let value = new;
// Take substrings from value
let low_12bits: = value.take_low; // 0x678
let high_12bits: = value.take_high; // 0x123
// Type of Reg32Bits<24> is automatically inferred
let concatination = high_12bits.concat; // 0x123_678
assert_eq!;
Casting
use *;
// Forms a Reg32Bits<32>
let value = new;
let low_12bits: = value.take_low; // 0x678
// We can fetch the inner value
let uint_value = u32 from;
assert_eq!;
// Most of the operations you can do from within the struct however
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// You can also add bits
let bigger: = low_12bits.zero_extend; // 0x0678
let sign_extended: = low_12bits.sign_extend; // 0x0678
let padded: = low_12bits.zero_pad; // 0x6780
Individual bit manipulations
use *;
// Forms a Reg32Bits<32>
let value = new;
let low_byte: = value.take_low; // 0b1011_1000
// We can get the value of individual bits
let bits = low_byte.bits;
// This is perfect for pattern matching
assert_eq!;
// We can also get a bit from a runtime variable
assert_eq!;
No-Std
The no-std
ensures that the environment does not utilize the standard library.
Development
The reg8.rs
, reg16.rs
, reg32.rs
and reg64.rs
are automatically generated from the reg_reference.rs
file. This is done with the generate_impl_rs.py
script.