mirror of
https://github.com/italicsjenga/gba.git
synced 2025-01-22 23:56:32 +11:00
Bitfield fixes (#146)
* Fix incorrect bit for `chained_counting` field in TimerControl. * Fixes incorrect bitfield manipulation math in mmio_types.
This commit is contained in:
parent
127f31ecf2
commit
093edc703f
2 changed files with 6 additions and 6 deletions
|
@ -15,13 +15,13 @@ macro_rules! bitfield_int {
|
||||||
($inner:ty; $low:literal ..= $high:literal : $nt:ident, $get:ident, $with:ident, $set:ident) => {
|
($inner:ty; $low:literal ..= $high:literal : $nt:ident, $get:ident, $with:ident, $set:ident) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn $get(self) -> $nt {
|
pub const fn $get(self) -> $nt {
|
||||||
const MASK: $inner = ((1 << $high) - 1) << $low;
|
const MASK: $inner = ((1 << ($high - $low + 1)) - 1) << $low;
|
||||||
((self.0 & MASK) >> $low) as $nt
|
((self.0 & MASK) >> $low) as $nt
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn $with(self, $get: $nt) -> Self {
|
pub const fn $with(self, $get: $nt) -> Self {
|
||||||
const MASK: $inner = ((1 << $high) - 1) << $low;
|
const MASK: $inner = ((1 << ($high - $low + 1)) - 1) << $low;
|
||||||
Self(self.0 ^ ((self.0 ^ ($get as $inner)) & MASK))
|
Self(self.0 ^ ((self.0 ^ (($get as $inner) << $low)) & MASK))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn $set(&mut self, $get: $nt) {
|
pub fn $set(&mut self, $get: $nt) {
|
||||||
|
@ -36,12 +36,12 @@ macro_rules! bitfield_newtype {
|
||||||
($inner:ty; $low:literal ..= $high:literal : $nt:ident, $get:ident, $with:ident, $set:ident) => {
|
($inner:ty; $low:literal ..= $high:literal : $nt:ident, $get:ident, $with:ident, $set:ident) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn $get(self) -> $nt {
|
pub const fn $get(self) -> $nt {
|
||||||
const MASK: $inner = ((1 << $high) - 1) << $low;
|
const MASK: $inner = ((1 << ($high - $low + 1)) - 1) << $low;
|
||||||
$nt(self.0 & MASK)
|
$nt(self.0 & MASK)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn $with(self, $get: $nt) -> Self {
|
pub const fn $with(self, $get: $nt) -> Self {
|
||||||
const MASK: $inner = ((1 << $high) - 1) << $low;
|
const MASK: $inner = ((1 << ($high - $low + 1)) - 1) << $low;
|
||||||
Self(self.0 ^ ((self.0 ^ $get.0) & MASK))
|
Self(self.0 ^ ((self.0 ^ $get.0) & MASK))
|
||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -6,7 +6,7 @@ pub struct TimerControl(u8);
|
||||||
impl TimerControl {
|
impl TimerControl {
|
||||||
const_new!();
|
const_new!();
|
||||||
bitfield_int!(u8; 0..=1: u8, prescaler_selection, with_prescaler_selection, set_prescaler_selection);
|
bitfield_int!(u8; 0..=1: u8, prescaler_selection, with_prescaler_selection, set_prescaler_selection);
|
||||||
bitfield_bool!(u8; 4, chained_counting, with_chained_counting, set_chained_counting);
|
bitfield_bool!(u8; 2, chained_counting, with_chained_counting, set_chained_counting);
|
||||||
bitfield_bool!(u8; 6, irq_on_overflow, with_irq_on_overflow, set_irq_on_overflow);
|
bitfield_bool!(u8; 6, irq_on_overflow, with_irq_on_overflow, set_irq_on_overflow);
|
||||||
bitfield_bool!(u8; 7, enabled, with_enabled, set_enabled);
|
bitfield_bool!(u8; 7, enabled, with_enabled, set_enabled);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue