RP: Watchdog scratch set/get with index: usize.

This commit is contained in:
Henrik Berg 2023-07-12 16:41:35 +02:00
parent 6d402fe393
commit ff2daaff67

View file

@ -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"),
}
}
}