From ff2daaff679ab79c856164d19b1bd15c7526991f Mon Sep 17 00:00:00 2001 From: Henrik Berg Date: Wed, 12 Jul 2023 16:41:35 +0200 Subject: [PATCH] RP: Watchdog scratch set/get with index: usize. --- embassy-rp/src/watchdog.rs | 116 +++++++++---------------------------- 1 file changed, 26 insertions(+), 90 deletions(-) diff --git a/embassy-rp/src/watchdog.rs b/embassy-rp/src/watchdog.rs index 7b36bb5a..f1e986ec 100644 --- a/embassy-rp/src/watchdog.rs +++ b/embassy-rp/src/watchdog.rs @@ -108,99 +108,35 @@ impl Watchdog { }) } - pub fn set_scratch0(&mut self, value: u32) { + /// Store data in scratch register + pub fn set_scratch(&mut self, index: usize, value: u32) { let watchdog = pac::WATCHDOG; - watchdog.scratch0().write(|w| { - *w = value; - }) + match index { + 0 => watchdog.scratch0().write(|w| *w = value), + 1 => watchdog.scratch1().write(|w| *w = value), + 2 => watchdog.scratch2().write(|w| *w = value), + 3 => watchdog.scratch3().write(|w| *w = value), + 4 => watchdog.scratch4().write(|w| *w = value), + 5 => watchdog.scratch5().write(|w| *w = value), + 6 => watchdog.scratch6().write(|w| *w = value), + 7 => watchdog.scratch7().write(|w| *w = value), + _ => panic!("Invalid watchdog scratch index"), + } } - pub fn get_scratch0(&mut self) -> u32 { + /// Read data from scratch register + pub fn get_scratch(&mut self, index: usize) -> u32 { let watchdog = pac::WATCHDOG; - watchdog.scratch0().read() - } - - pub fn set_scratch1(&mut self, value: u32) { - let watchdog = pac::WATCHDOG; - watchdog.scratch1().write(|w| { - *w = value; - }) - } - - pub fn get_scratch1(&mut self) -> u32 { - let watchdog = pac::WATCHDOG; - watchdog.scratch1().read() - } - - pub fn set_scratch2(&mut self, value: u32) { - let watchdog = pac::WATCHDOG; - watchdog.scratch2().write(|w| { - *w = value; - }) - } - - pub fn get_scratch2(&mut self) -> u32 { - let watchdog = pac::WATCHDOG; - watchdog.scratch2().read() - } - - pub fn set_scratch3(&mut self, value: u32) { - let watchdog = pac::WATCHDOG; - watchdog.scratch3().write(|w| { - *w = value; - }) - } - - pub fn get_scratch3(&mut self) -> u32 { - let watchdog = pac::WATCHDOG; - watchdog.scratch3().read() - } - - pub fn set_scratch4(&mut self, value: u32) { - let watchdog = pac::WATCHDOG; - watchdog.scratch4().write(|w| { - *w = value; - }) - } - - pub fn get_scratch4(&mut self) -> u32 { - let watchdog = pac::WATCHDOG; - watchdog.scratch4().read() - } - - pub fn set_scratch5(&mut self, value: u32) { - let watchdog = pac::WATCHDOG; - watchdog.scratch5().write(|w| { - *w = value; - }) - } - - pub fn get_scratch5(&mut self) -> u32 { - let watchdog = pac::WATCHDOG; - watchdog.scratch5().read() - } - - pub fn set_scratch6(&mut self, value: u32) { - let watchdog = pac::WATCHDOG; - watchdog.scratch6().write(|w| { - *w = value; - }) - } - - pub fn get_scratch6(&mut self) -> u32 { - let watchdog = pac::WATCHDOG; - watchdog.scratch6().read() - } - - pub fn set_scratch7(&mut self, value: u32) { - let watchdog = pac::WATCHDOG; - watchdog.scratch7().write(|w| { - *w = value; - }) - } - - pub fn get_scratch7(&mut self) -> u32 { - let watchdog = pac::WATCHDOG; - watchdog.scratch7().read() + match index { + 0 => watchdog.scratch0().read(), + 1 => watchdog.scratch1().read(), + 2 => watchdog.scratch2().read(), + 3 => watchdog.scratch3().read(), + 4 => watchdog.scratch4().read(), + 5 => watchdog.scratch5().read(), + 6 => watchdog.scratch6().read(), + 7 => watchdog.scratch7().read(), + _ => panic!("Invalid watchdog scratch index"), + } } }