aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authorsodo <[email protected]>2024-01-02 01:37:00 +0900
committersodo <[email protected]>2024-01-02 13:34:22 +0900
commit6ee153a3e2eec284c0d9d87f31801265c0604f74 (patch)
tree8b801cbd15f9ad5052d5942c731e75736dc9d7eb /embassy-nrf/src
parentb7cd7952c890f585ff876c622482534e5d58d4a4 (diff)
parent0be9b0599aaf2e425d76ec7852ff4b3535defddf (diff)
Merge remote-tracking branch 'origin'
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs1
-rw-r--r--embassy-nrf/src/gpio.rs124
-rw-r--r--embassy-nrf/src/gpiote.rs10
-rw-r--r--embassy-nrf/src/lib.rs9
-rwxr-xr-xembassy-nrf/src/qspi.rs3
5 files changed, 101 insertions, 46 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index 4ac622d34..2c620798d 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -342,6 +342,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> {
342 s.tx_count.store(0, Ordering::Relaxed); 342 s.tx_count.store(0, Ordering::Relaxed);
343 s.rx_started_count.store(0, Ordering::Relaxed); 343 s.rx_started_count.store(0, Ordering::Relaxed);
344 s.rx_ended_count.store(0, Ordering::Relaxed); 344 s.rx_ended_count.store(0, Ordering::Relaxed);
345 s.rx_started.store(false, Ordering::Relaxed);
345 let len = tx_buffer.len(); 346 let len = tx_buffer.len();
346 unsafe { s.tx_buf.init(tx_buffer.as_mut_ptr(), len) }; 347 unsafe { s.tx_buf.init(tx_buffer.as_mut_ptr(), len) };
347 let len = rx_buffer.len(); 348 let len = rx_buffer.len();
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index cf6225282..27c18383f 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -50,21 +50,21 @@ impl<'d, T: Pin> Input<'d, T> {
50 Self { pin } 50 Self { pin }
51 } 51 }
52 52
53 /// Test if current pin level is high. 53 /// Get whether the pin input level is high.
54 #[inline] 54 #[inline]
55 pub fn is_high(&self) -> bool { 55 pub fn is_high(&mut self) -> bool {
56 self.pin.is_high() 56 self.pin.is_high()
57 } 57 }
58 58
59 /// Test if current pin level is low. 59 /// Get whether the pin input level is low.
60 #[inline] 60 #[inline]
61 pub fn is_low(&self) -> bool { 61 pub fn is_low(&mut self) -> bool {
62 self.pin.is_low() 62 self.pin.is_low()
63 } 63 }
64 64
65 /// Returns current pin level 65 /// Get the pin input level.
66 #[inline] 66 #[inline]
67 pub fn get_level(&self) -> Level { 67 pub fn get_level(&mut self) -> Level {
68 self.pin.get_level() 68 self.pin.get_level()
69 } 69 }
70} 70}
@@ -152,27 +152,33 @@ impl<'d, T: Pin> Output<'d, T> {
152 self.pin.set_low() 152 self.pin.set_low()
153 } 153 }
154 154
155 /// Toggle the output level.
156 #[inline]
157 pub fn toggle(&mut self) {
158 self.pin.toggle()
159 }
160
155 /// Set the output level. 161 /// Set the output level.
156 #[inline] 162 #[inline]
157 pub fn set_level(&mut self, level: Level) { 163 pub fn set_level(&mut self, level: Level) {
158 self.pin.set_level(level) 164 self.pin.set_level(level)
159 } 165 }
160 166
161 /// Is the output pin set as high? 167 /// Get whether the output level is set to high.
162 #[inline] 168 #[inline]
163 pub fn is_set_high(&self) -> bool { 169 pub fn is_set_high(&mut self) -> bool {
164 self.pin.is_set_high() 170 self.pin.is_set_high()
165 } 171 }
166 172
167 /// Is the output pin set as low? 173 /// Get whether the output level is set to low.
168 #[inline] 174 #[inline]
169 pub fn is_set_low(&self) -> bool { 175 pub fn is_set_low(&mut self) -> bool {
170 self.pin.is_set_low() 176 self.pin.is_set_low()
171 } 177 }
172 178
173 /// What level output is set to 179 /// Get the current output level.
174 #[inline] 180 #[inline]
175 pub fn get_output_level(&self) -> Level { 181 pub fn get_output_level(&mut self) -> Level {
176 self.pin.get_output_level() 182 self.pin.get_output_level()
177 } 183 }
178} 184}
@@ -275,21 +281,26 @@ impl<'d, T: Pin> Flex<'d, T> {
275 self.pin.conf().reset(); 281 self.pin.conf().reset();
276 } 282 }
277 283
278 /// Test if current pin level is high. 284 /// Get whether the pin input level is high.
279 #[inline] 285 #[inline]
280 pub fn is_high(&self) -> bool { 286 pub fn is_high(&mut self) -> bool {
281 !self.is_low() 287 !self.is_low()
282 } 288 }
283 289
284 /// Test if current pin level is low. 290 /// Get whether the pin input level is low.
291 #[inline]
292 pub fn is_low(&mut self) -> bool {
293 self.ref_is_low()
294 }
295
285 #[inline] 296 #[inline]
286 pub fn is_low(&self) -> bool { 297 pub(crate) fn ref_is_low(&self) -> bool {
287 self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 298 self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0
288 } 299 }
289 300
290 /// Returns current pin level 301 /// Get the pin input level.
291 #[inline] 302 #[inline]
292 pub fn get_level(&self) -> Level { 303 pub fn get_level(&mut self) -> Level {
293 self.is_high().into() 304 self.is_high().into()
294 } 305 }
295 306
@@ -305,6 +316,16 @@ impl<'d, T: Pin> Flex<'d, T> {
305 self.pin.set_low() 316 self.pin.set_low()
306 } 317 }
307 318
319 /// Toggle the output level.
320 #[inline]
321 pub fn toggle(&mut self) {
322 if self.is_set_low() {
323 self.set_high()
324 } else {
325 self.set_low()
326 }
327 }
328
308 /// Set the output level. 329 /// Set the output level.
309 #[inline] 330 #[inline]
310 pub fn set_level(&mut self, level: Level) { 331 pub fn set_level(&mut self, level: Level) {
@@ -314,21 +335,26 @@ impl<'d, T: Pin> Flex<'d, T> {
314 } 335 }
315 } 336 }
316 337
317 /// Is the output pin set as high? 338 /// Get whether the output level is set to high.
318 #[inline] 339 #[inline]
319 pub fn is_set_high(&self) -> bool { 340 pub fn is_set_high(&mut self) -> bool {
320 !self.is_set_low() 341 !self.is_set_low()
321 } 342 }
322 343
323 /// Is the output pin set as low? 344 /// Get whether the output level is set to low.
324 #[inline] 345 #[inline]
325 pub fn is_set_low(&self) -> bool { 346 pub fn is_set_low(&mut self) -> bool {
347 self.ref_is_set_low()
348 }
349
350 #[inline]
351 pub(crate) fn ref_is_set_low(&self) -> bool {
326 self.pin.block().out.read().bits() & (1 << self.pin.pin()) == 0 352 self.pin.block().out.read().bits() & (1 << self.pin.pin()) == 0
327 } 353 }
328 354
329 /// What level output is set to 355 /// Get the current output level.
330 #[inline] 356 #[inline]
331 pub fn get_output_level(&self) -> Level { 357 pub fn get_output_level(&mut self) -> Level {
332 self.is_set_high().into() 358 self.is_set_high().into()
333 } 359 }
334} 360}
@@ -498,11 +524,11 @@ mod eh02 {
498 type Error = Infallible; 524 type Error = Infallible;
499 525
500 fn is_high(&self) -> Result<bool, Self::Error> { 526 fn is_high(&self) -> Result<bool, Self::Error> {
501 Ok(self.is_high()) 527 Ok(!self.pin.ref_is_low())
502 } 528 }
503 529
504 fn is_low(&self) -> Result<bool, Self::Error> { 530 fn is_low(&self) -> Result<bool, Self::Error> {
505 Ok(self.is_low()) 531 Ok(self.pin.ref_is_low())
506 } 532 }
507 } 533 }
508 534
@@ -520,11 +546,20 @@ mod eh02 {
520 546
521 impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { 547 impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> {
522 fn is_set_high(&self) -> Result<bool, Self::Error> { 548 fn is_set_high(&self) -> Result<bool, Self::Error> {
523 Ok(self.is_set_high()) 549 Ok(!self.pin.ref_is_set_low())
524 } 550 }
525 551
526 fn is_set_low(&self) -> Result<bool, Self::Error> { 552 fn is_set_low(&self) -> Result<bool, Self::Error> {
527 Ok(self.is_set_low()) 553 Ok(self.pin.ref_is_set_low())
554 }
555 }
556
557 impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Output<'d, T> {
558 type Error = Infallible;
559 #[inline]
560 fn toggle(&mut self) -> Result<(), Self::Error> {
561 self.toggle();
562 Ok(())
528 } 563 }
529 } 564 }
530 565
@@ -535,11 +570,11 @@ mod eh02 {
535 type Error = Infallible; 570 type Error = Infallible;
536 571
537 fn is_high(&self) -> Result<bool, Self::Error> { 572 fn is_high(&self) -> Result<bool, Self::Error> {
538 Ok(self.is_high()) 573 Ok(!self.ref_is_low())
539 } 574 }
540 575
541 fn is_low(&self) -> Result<bool, Self::Error> { 576 fn is_low(&self) -> Result<bool, Self::Error> {
542 Ok(self.is_low()) 577 Ok(self.ref_is_low())
543 } 578 }
544 } 579 }
545 580
@@ -557,11 +592,20 @@ mod eh02 {
557 592
558 impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { 593 impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> {
559 fn is_set_high(&self) -> Result<bool, Self::Error> { 594 fn is_set_high(&self) -> Result<bool, Self::Error> {
560 Ok(self.is_set_high()) 595 Ok(!self.ref_is_set_low())
561 } 596 }
562 597
563 fn is_set_low(&self) -> Result<bool, Self::Error> { 598 fn is_set_low(&self) -> Result<bool, Self::Error> {
564 Ok(self.is_set_low()) 599 Ok(self.ref_is_set_low())
600 }
601 }
602
603 impl<'d, T: Pin> embedded_hal_02::digital::v2::ToggleableOutputPin for Flex<'d, T> {
604 type Error = Infallible;
605 #[inline]
606 fn toggle(&mut self) -> Result<(), Self::Error> {
607 self.toggle();
608 Ok(())
565 } 609 }
566 } 610 }
567} 611}
@@ -571,11 +615,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {
571} 615}
572 616
573impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { 617impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> {
574 fn is_high(&self) -> Result<bool, Self::Error> { 618 fn is_high(&mut self) -> Result<bool, Self::Error> {
575 Ok(self.is_high()) 619 Ok(self.is_high())
576 } 620 }
577 621
578 fn is_low(&self) -> Result<bool, Self::Error> { 622 fn is_low(&mut self) -> Result<bool, Self::Error> {
579 Ok(self.is_low()) 623 Ok(self.is_low())
580 } 624 }
581} 625}
@@ -595,11 +639,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> {
595} 639}
596 640
597impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { 641impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> {
598 fn is_set_high(&self) -> Result<bool, Self::Error> { 642 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
599 Ok(self.is_set_high()) 643 Ok(self.is_set_high())
600 } 644 }
601 645
602 fn is_set_low(&self) -> Result<bool, Self::Error> { 646 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
603 Ok(self.is_set_low()) 647 Ok(self.is_set_low())
604 } 648 }
605} 649}
@@ -612,11 +656,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> {
612/// 656///
613/// If the pin is not in input mode the result is unspecified. 657/// If the pin is not in input mode the result is unspecified.
614impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { 658impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> {
615 fn is_high(&self) -> Result<bool, Self::Error> { 659 fn is_high(&mut self) -> Result<bool, Self::Error> {
616 Ok(self.is_high()) 660 Ok(self.is_high())
617 } 661 }
618 662
619 fn is_low(&self) -> Result<bool, Self::Error> { 663 fn is_low(&mut self) -> Result<bool, Self::Error> {
620 Ok(self.is_low()) 664 Ok(self.is_low())
621 } 665 }
622} 666}
@@ -632,11 +676,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> {
632} 676}
633 677
634impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { 678impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> {
635 fn is_set_high(&self) -> Result<bool, Self::Error> { 679 fn is_set_high(&mut self) -> Result<bool, Self::Error> {
636 Ok(self.is_set_high()) 680 Ok(self.is_set_high())
637 } 681 }
638 682
639 fn is_set_low(&self) -> Result<bool, Self::Error> { 683 fn is_set_low(&mut self) -> Result<bool, Self::Error> {
640 Ok(self.is_set_low()) 684 Ok(self.is_set_low())
641 } 685 }
642} 686}
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index fd629ea76..07196abf7 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -243,7 +243,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
243 243
244impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { 244impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
245 /// Create a new GPIOTE output channel driver. 245 /// Create a new GPIOTE output channel driver.
246 pub fn new(ch: impl Peripheral<P = C> + 'd, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self { 246 pub fn new(ch: impl Peripheral<P = C> + 'd, mut pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
247 into_ref!(ch); 247 into_ref!(ch);
248 let g = regs(); 248 let g = regs();
249 let num = ch.number(); 249 let num = ch.number();
@@ -481,11 +481,11 @@ mod eh02 {
481 type Error = Infallible; 481 type Error = Infallible;
482 482
483 fn is_high(&self) -> Result<bool, Self::Error> { 483 fn is_high(&self) -> Result<bool, Self::Error> {
484 Ok(self.pin.is_high()) 484 Ok(!self.pin.pin.ref_is_low())
485 } 485 }
486 486
487 fn is_low(&self) -> Result<bool, Self::Error> { 487 fn is_low(&self) -> Result<bool, Self::Error> {
488 Ok(self.pin.is_low()) 488 Ok(self.pin.pin.ref_is_low())
489 } 489 }
490 } 490 }
491} 491}
@@ -495,11 +495,11 @@ impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::ErrorType for InputCha
495} 495}
496 496
497impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::InputPin for InputChannel<'d, C, T> { 497impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::InputPin for InputChannel<'d, C, T> {
498 fn is_high(&self) -> Result<bool, Self::Error> { 498 fn is_high(&mut self) -> Result<bool, Self::Error> {
499 Ok(self.pin.is_high()) 499 Ok(self.pin.is_high())
500 } 500 }
501 501
502 fn is_low(&self) -> Result<bool, Self::Error> { 502 fn is_low(&mut self) -> Result<bool, Self::Error> {
503 Ok(self.pin.is_low()) 503 Ok(self.pin.is_low())
504 } 504 }
505} 505}
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 9093ad919..1510b7265 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -3,6 +3,9 @@
3#![doc = include_str!("../README.md")] 3#![doc = include_str!("../README.md")]
4#![warn(missing_docs)] 4#![warn(missing_docs)]
5 5
6//! ## Feature flags
7#![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)]
8
6#[cfg(not(any( 9#[cfg(not(any(
7 feature = "nrf51", 10 feature = "nrf51",
8 feature = "nrf52805", 11 feature = "nrf52805",
@@ -354,7 +357,11 @@ unsafe fn uicr_write_masked(address: *mut u32, value: u32, mask: u32) -> WriteRe
354 WriteResult::Written 357 WriteResult::Written
355} 358}
356 359
357/// Initialize peripherals with the provided configuration. This should only be called once at startup. 360/// Initialize the `embassy-nrf` HAL with the provided configuration.
361///
362/// This returns the peripheral singletons that can be used for creating drivers.
363///
364/// This should only be called once at startup, otherwise it panics.
358pub fn init(config: config::Config) -> Peripherals { 365pub fn init(config: config::Config) -> Peripherals {
359 // Do this first, so that it panics if user is calling `init` a second time 366 // Do this first, so that it panics if user is calling `init` a second time
360 // before doing anything important. 367 // before doing anything important.
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index 5e1a4e842..f35b83628 100755
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -605,6 +605,9 @@ impl<'d, T: Instance> NorFlash for Qspi<'d, T> {
605 } 605 }
606} 606}
607 607
608#[cfg(feature = "qspi-multiwrite-flash")]
609impl<'d, T: Instance> embedded_storage::nor_flash::MultiwriteNorFlash for Qspi<'d, T> {}
610
608mod _eh1 { 611mod _eh1 {
609 use embedded_storage_async::nor_flash::{NorFlash as AsyncNorFlash, ReadNorFlash as AsyncReadNorFlash}; 612 use embedded_storage_async::nor_flash::{NorFlash as AsyncNorFlash, ReadNorFlash as AsyncReadNorFlash};
610 613