aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/timer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nrf/src/timer.rs')
-rw-r--r--embassy-nrf/src/timer.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index 3dbfdac42..3c35baee5 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -111,7 +111,7 @@ impl<'d, T: Instance> Timer<'d, T> {
111 Self::new_inner(timer, true) 111 Self::new_inner(timer, true)
112 } 112 }
113 113
114 fn new_inner(timer: impl Peripheral<P = T> + 'd, is_counter: bool) -> Self { 114 fn new_inner(timer: impl Peripheral<P = T> + 'd, _is_counter: bool) -> Self {
115 into_ref!(timer); 115 into_ref!(timer);
116 116
117 let regs = T::regs(); 117 let regs = T::regs();
@@ -122,12 +122,16 @@ impl<'d, T: Instance> Timer<'d, T> {
122 // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification. 122 // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification.
123 this.stop(); 123 this.stop();
124 124
125 if is_counter { 125 #[cfg(not(feature = "nrf51"))]
126 if _is_counter {
126 regs.mode.write(|w| w.mode().low_power_counter()); 127 regs.mode.write(|w| w.mode().low_power_counter());
127 } else { 128 } else {
128 regs.mode.write(|w| w.mode().timer()); 129 regs.mode.write(|w| w.mode().timer());
129 } 130 }
130 131
132 #[cfg(feature = "nrf51")]
133 regs.mode.write(|w| w.mode().timer());
134
131 // Make the counter's max value as high as possible. 135 // Make the counter's max value as high as possible.
132 // TODO: is there a reason someone would want to set this lower? 136 // TODO: is there a reason someone would want to set this lower?
133 regs.bitmode.write(|w| w.bitmode()._32bit()); 137 regs.bitmode.write(|w| w.bitmode()._32bit());
@@ -238,7 +242,11 @@ pub struct Cc<'d, T: Instance> {
238impl<'d, T: Instance> Cc<'d, T> { 242impl<'d, T: Instance> Cc<'d, T> {
239 /// Get the current value stored in the register. 243 /// Get the current value stored in the register.
240 pub fn read(&self) -> u32 { 244 pub fn read(&self) -> u32 {
241 T::regs().cc[self.n].read().cc().bits() 245 #[cfg(not(feature = "nrf51"))]
246 return T::regs().cc[self.n].read().cc().bits();
247
248 #[cfg(feature = "nrf51")]
249 return T::regs().cc[self.n].read().bits();
242 } 250 }
243 251
244 /// Set the value stored in the register. 252 /// Set the value stored in the register.
@@ -246,7 +254,11 @@ impl<'d, T: Instance> Cc<'d, T> {
246 /// `event_compare` will fire when the timer's counter reaches this value. 254 /// `event_compare` will fire when the timer's counter reaches this value.
247 pub fn write(&self, value: u32) { 255 pub fn write(&self, value: u32) {
248 // SAFETY: there are no invalid values for the CC register. 256 // SAFETY: there are no invalid values for the CC register.
249 T::regs().cc[self.n].write(|w| unsafe { w.cc().bits(value) }) 257 #[cfg(not(feature = "nrf51"))]
258 T::regs().cc[self.n].write(|w| unsafe { w.cc().bits(value) });
259
260 #[cfg(feature = "nrf51")]
261 T::regs().cc[self.n].write(|w| unsafe { w.bits(value) });
250 } 262 }
251 263
252 /// Capture the current value of the timer's counter in this register, and return it. 264 /// Capture the current value of the timer's counter in this register, and return it.