pub struct Reg<T: Copy, A: Access> { /* private fields */ }Expand description
Generic register structure. T refers to the data type of the register.
Alternatively, A corresponds to the access level (e.g., read-only, read-write…).
§Note
This structure assumes that it points to a valid peripheral register. If so, it is safe to read from or write to the register. However, keep in mind that read-modify-write operations may lead to wrong behavior.
Implementations§
Source§impl<T: Copy, A: Read> Reg<T, A>
impl<T: Copy, A: Read> Reg<T, A>
Sourcepub fn read(self) -> T
pub fn read(self) -> T
Performs a volatile read of the peripheral register with no side effects.
§Note
If you want to perform a read-modify-write operation, use Reg::modify instead.
Source§impl<T: Copy, A: Write> Reg<T, A>
impl<T: Copy, A: Write> Reg<T, A>
Sourcepub fn write(self, val: T)
pub fn write(self, val: T)
Performs a volatile write of the peripheral register.
§Note
If you want to perform a read-modify-write operation, use Reg::modify instead.
Source§impl<T: Copy, A: Read + Write> Reg<T, A>
impl<T: Copy, A: Read + Write> Reg<T, A>
Sourcepub fn modify<R>(self, f: impl FnOnce(&mut T) -> R) -> R
pub fn modify<R>(self, f: impl FnOnce(&mut T) -> R) -> R
It modifies the value of the register according to a given function f.
After writing the new value to the register, it returns the value returned by f.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Source§impl<A: Read + Write> Reg<u8, A>
impl<A: Read + Write> Reg<u8, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: u8)
pub fn write_bits(self, start: usize, end: usize, val: u8)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<u16, A>
impl<A: Read + Write> Reg<u16, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: u16)
pub fn write_bits(self, start: usize, end: usize, val: u16)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<u32, A>
impl<A: Read + Write> Reg<u32, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: u32)
pub fn write_bits(self, start: usize, end: usize, val: u32)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<u64, A>
impl<A: Read + Write> Reg<u64, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: u64)
pub fn write_bits(self, start: usize, end: usize, val: u64)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<u128, A>
impl<A: Read + Write> Reg<u128, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: u128)
pub fn write_bits(self, start: usize, end: usize, val: u128)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<usize, A>
impl<A: Read + Write> Reg<usize, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: usize)
pub fn write_bits(self, start: usize, end: usize, val: usize)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<i8, A>
impl<A: Read + Write> Reg<i8, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: i8)
pub fn write_bits(self, start: usize, end: usize, val: i8)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<i16, A>
impl<A: Read + Write> Reg<i16, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: i16)
pub fn write_bits(self, start: usize, end: usize, val: i16)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<i32, A>
impl<A: Read + Write> Reg<i32, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: i32)
pub fn write_bits(self, start: usize, end: usize, val: i32)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<i64, A>
impl<A: Read + Write> Reg<i64, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: i64)
pub fn write_bits(self, start: usize, end: usize, val: i64)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<i128, A>
impl<A: Read + Write> Reg<i128, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: i128)
pub fn write_bits(self, start: usize, end: usize, val: i128)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<isize, A>
impl<A: Read + Write> Reg<isize, A>
Sourcepub fn clear_bit(self, n: usize)
pub fn clear_bit(self, n: usize)
Clears the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn set_bit(self, n: usize)
pub fn set_bit(self, n: usize)
Sets the nth bit of the register.
§Note
It performs a non-atomic read-modify-write operation, which may lead to wrong behavior.
Sourcepub fn write_bits(self, start: usize, end: usize, val: isize)
pub fn write_bits(self, start: usize, end: usize, val: isize)
Writes a range of bits of the register specified by the start and end indexes, both included.
Source§impl<A: Read + Write> Reg<u8, A>
impl<A: Read + Write> Reg<u8, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU8
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU8
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<u16, A>
impl<A: Read + Write> Reg<u16, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU16
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU16
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<u32, A>
impl<A: Read + Write> Reg<u32, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU32
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU32
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<u64, A>
impl<A: Read + Write> Reg<u64, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU64
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicU64
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<usize, A>
impl<A: Read + Write> Reg<usize, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicUsize
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicUsize
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<i8, A>
impl<A: Read + Write> Reg<i8, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI8
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI8
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<i16, A>
impl<A: Read + Write> Reg<i16, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI16
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI16
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<i32, A>
impl<A: Read + Write> Reg<i32, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI32
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI32
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<i64, A>
impl<A: Read + Write> Reg<i64, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI64
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicI64
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Source§impl<A: Read + Write> Reg<isize, A>
impl<A: Read + Write> Reg<isize, A>
Sourcepub unsafe fn as_atomic<'a>(&self) -> &'a AtomicIsize
pub unsafe fn as_atomic<'a>(&self) -> &'a AtomicIsize
Creates a new atomic reference to the register.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations for the whole lifetime
'a.
Sourcepub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_clear_bit(&self, n: usize, order: Ordering)
Clears the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.
Sourcepub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
pub unsafe fn atomic_set_bit(&self, n: usize, order: Ordering)
Sets the nth bit of the register atomically.
§Safety
- Register must be properly aligned for atomic operations.
- The register must not be accessed through non-atomic operations until this function returns.