mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Split out to a timer controller to keep the GBA struct zero sized
This commit is contained in:
parent
f7a10677dd
commit
75bd475f08
|
@ -17,7 +17,8 @@ fn main() -> ! {
|
||||||
let mut input = ButtonController::new();
|
let mut input = ButtonController::new();
|
||||||
let vblank_provider = agb::interrupt::VBlank::get();
|
let vblank_provider = agb::interrupt::VBlank::get();
|
||||||
|
|
||||||
let mut mixer = gba.mixer.mixer(&mut gba.timers.timer0);
|
let mut timers = gba.timers.timers();
|
||||||
|
let mut mixer = gba.mixer.mixer(&mut timers.timer0);
|
||||||
mixer.enable();
|
mixer.enable();
|
||||||
|
|
||||||
let channel = SoundChannel::new(DEAD_CODE);
|
let channel = SoundChannel::new(DEAD_CODE);
|
||||||
|
|
|
@ -14,7 +14,7 @@ fn main() -> ! {
|
||||||
let mut gba = Gba::new();
|
let mut gba = Gba::new();
|
||||||
let vblank_provider = agb::interrupt::VBlank::get();
|
let vblank_provider = agb::interrupt::VBlank::get();
|
||||||
|
|
||||||
let mut timer_controller = gba.timers;
|
let mut timer_controller = gba.timers.timers();
|
||||||
let mut timer = timer_controller.timer1;
|
let mut timer = timer_controller.timer1;
|
||||||
timer.set_enabled(true);
|
timer.set_enabled(true);
|
||||||
|
|
||||||
|
|
|
@ -33,20 +33,21 @@ impl Divider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct Timer {
|
pub struct Timer {
|
||||||
timer_number: u16,
|
timer_number: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct TimerController {
|
pub struct Timers {
|
||||||
pub timer0: Timer,
|
pub timer0: Timer,
|
||||||
pub timer1: Timer,
|
pub timer1: Timer,
|
||||||
pub timer2: Timer,
|
pub timer2: Timer,
|
||||||
pub timer3: Timer,
|
pub timer3: Timer,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimerController {
|
impl Timers {
|
||||||
pub(crate) const unsafe fn new() -> Self {
|
pub(crate) unsafe fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
timer0: Timer::new(0),
|
timer0: Timer::new(0),
|
||||||
timer1: Timer::new(1),
|
timer1: Timer::new(1),
|
||||||
|
@ -57,8 +58,12 @@ impl TimerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Timer {
|
impl Timer {
|
||||||
const unsafe fn new(timer_number: u16) -> Self {
|
unsafe fn new(timer_number: u16) -> Self {
|
||||||
Self { timer_number }
|
let new_timer = Self { timer_number };
|
||||||
|
new_timer.data_register().set(0);
|
||||||
|
new_timer.control_register().set(0);
|
||||||
|
|
||||||
|
new_timer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_overflow_amount(&mut self, n: u16) {
|
pub fn set_overflow_amount(&mut self, n: u16) {
|
||||||
|
@ -97,3 +102,16 @@ impl Timer {
|
||||||
self.timer_number as usize
|
self.timer_number as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[non_exhaustive]
|
||||||
|
pub struct TimerController {}
|
||||||
|
|
||||||
|
impl TimerController {
|
||||||
|
pub(crate) const fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn timers(&mut self) -> Timers {
|
||||||
|
unsafe { Timers::new() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue