diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-01-09 23:58:26 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-01-10 00:00:10 +0100 |
| commit | 495b8b739aaba3d1fe7e105559c830496fabb1d7 (patch) | |
| tree | 6cc6597e9dfa6ac75736ebd4be4a63ca4b546771 /embassy-nrf | |
| parent | 67ed134479886023ec133a3a95074972e6d83236 (diff) | |
Change GPIO inherent methods back to `&self`.
With the embedded-hal rc3 update I changed them to require `&mut self`, but
in retrospect I think `&self` is better, for extra flexibility.
This PR reverts the changes from the rc3 update to inherent methods.
Diffstat (limited to 'embassy-nrf')
| -rw-r--r-- | embassy-nrf/src/gpio.rs | 66 | ||||
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 6 |
2 files changed, 31 insertions, 41 deletions
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index 27c18383f..eabf409dd 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -52,19 +52,19 @@ impl<'d, T: Pin> Input<'d, T> { | |||
| 52 | 52 | ||
| 53 | /// Get whether the pin input level is high. | 53 | /// Get whether the pin input level is high. |
| 54 | #[inline] | 54 | #[inline] |
| 55 | pub fn is_high(&mut self) -> bool { | 55 | pub fn is_high(&self) -> bool { |
| 56 | self.pin.is_high() | 56 | self.pin.is_high() |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | /// Get whether the pin input level is low. | 59 | /// Get whether the pin input level is low. |
| 60 | #[inline] | 60 | #[inline] |
| 61 | pub fn is_low(&mut self) -> bool { | 61 | pub fn is_low(&self) -> bool { |
| 62 | self.pin.is_low() | 62 | self.pin.is_low() |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /// Get the pin input level. | 65 | /// Get the pin input level. |
| 66 | #[inline] | 66 | #[inline] |
| 67 | pub fn get_level(&mut self) -> Level { | 67 | pub fn get_level(&self) -> Level { |
| 68 | self.pin.get_level() | 68 | self.pin.get_level() |
| 69 | } | 69 | } |
| 70 | } | 70 | } |
| @@ -166,19 +166,19 @@ impl<'d, T: Pin> Output<'d, T> { | |||
| 166 | 166 | ||
| 167 | /// Get whether the output level is set to high. | 167 | /// Get whether the output level is set to high. |
| 168 | #[inline] | 168 | #[inline] |
| 169 | pub fn is_set_high(&mut self) -> bool { | 169 | pub fn is_set_high(&self) -> bool { |
| 170 | self.pin.is_set_high() | 170 | self.pin.is_set_high() |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | /// Get whether the output level is set to low. | 173 | /// Get whether the output level is set to low. |
| 174 | #[inline] | 174 | #[inline] |
| 175 | pub fn is_set_low(&mut self) -> bool { | 175 | pub fn is_set_low(&self) -> bool { |
| 176 | self.pin.is_set_low() | 176 | self.pin.is_set_low() |
| 177 | } | 177 | } |
| 178 | 178 | ||
| 179 | /// Get the current output level. | 179 | /// Get the current output level. |
| 180 | #[inline] | 180 | #[inline] |
| 181 | pub fn get_output_level(&mut self) -> Level { | 181 | pub fn get_output_level(&self) -> Level { |
| 182 | self.pin.get_output_level() | 182 | self.pin.get_output_level() |
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| @@ -283,24 +283,19 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 283 | 283 | ||
| 284 | /// Get whether the pin input level is high. | 284 | /// Get whether the pin input level is high. |
| 285 | #[inline] | 285 | #[inline] |
| 286 | pub fn is_high(&mut self) -> bool { | 286 | pub fn is_high(&self) -> bool { |
| 287 | !self.is_low() | 287 | !self.is_low() |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | /// Get whether the pin input level is low. | 290 | /// Get whether the pin input level is low. |
| 291 | #[inline] | 291 | #[inline] |
| 292 | pub fn is_low(&mut self) -> bool { | 292 | pub fn is_low(&self) -> bool { |
| 293 | self.ref_is_low() | ||
| 294 | } | ||
| 295 | |||
| 296 | #[inline] | ||
| 297 | pub(crate) fn ref_is_low(&self) -> bool { | ||
| 298 | self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 | 293 | self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0 |
| 299 | } | 294 | } |
| 300 | 295 | ||
| 301 | /// Get the pin input level. | 296 | /// Get the pin input level. |
| 302 | #[inline] | 297 | #[inline] |
| 303 | pub fn get_level(&mut self) -> Level { | 298 | pub fn get_level(&self) -> Level { |
| 304 | self.is_high().into() | 299 | self.is_high().into() |
| 305 | } | 300 | } |
| 306 | 301 | ||
| @@ -337,24 +332,19 @@ impl<'d, T: Pin> Flex<'d, T> { | |||
| 337 | 332 | ||
| 338 | /// Get whether the output level is set to high. | 333 | /// Get whether the output level is set to high. |
| 339 | #[inline] | 334 | #[inline] |
| 340 | pub fn is_set_high(&mut self) -> bool { | 335 | pub fn is_set_high(&self) -> bool { |
| 341 | !self.is_set_low() | 336 | !self.is_set_low() |
| 342 | } | 337 | } |
| 343 | 338 | ||
| 344 | /// Get whether the output level is set to low. | 339 | /// Get whether the output level is set to low. |
| 345 | #[inline] | 340 | #[inline] |
| 346 | pub fn is_set_low(&mut self) -> bool { | 341 | pub fn is_set_low(&self) -> bool { |
| 347 | self.ref_is_set_low() | ||
| 348 | } | ||
| 349 | |||
| 350 | #[inline] | ||
| 351 | pub(crate) fn ref_is_set_low(&self) -> bool { | ||
| 352 | self.pin.block().out.read().bits() & (1 << self.pin.pin()) == 0 | 342 | self.pin.block().out.read().bits() & (1 << self.pin.pin()) == 0 |
| 353 | } | 343 | } |
| 354 | 344 | ||
| 355 | /// Get the current output level. | 345 | /// Get the current output level. |
| 356 | #[inline] | 346 | #[inline] |
| 357 | pub fn get_output_level(&mut self) -> Level { | 347 | pub fn get_output_level(&self) -> Level { |
| 358 | self.is_set_high().into() | 348 | self.is_set_high().into() |
| 359 | } | 349 | } |
| 360 | } | 350 | } |
| @@ -524,11 +514,11 @@ mod eh02 { | |||
| 524 | type Error = Infallible; | 514 | type Error = Infallible; |
| 525 | 515 | ||
| 526 | fn is_high(&self) -> Result<bool, Self::Error> { | 516 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 527 | Ok(!self.pin.ref_is_low()) | 517 | Ok(self.is_high()) |
| 528 | } | 518 | } |
| 529 | 519 | ||
| 530 | fn is_low(&self) -> Result<bool, Self::Error> { | 520 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 531 | Ok(self.pin.ref_is_low()) | 521 | Ok(self.is_low()) |
| 532 | } | 522 | } |
| 533 | } | 523 | } |
| 534 | 524 | ||
| @@ -546,11 +536,11 @@ mod eh02 { | |||
| 546 | 536 | ||
| 547 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { | 537 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> { |
| 548 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 538 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 549 | Ok(!self.pin.ref_is_set_low()) | 539 | Ok(self.is_set_high()) |
| 550 | } | 540 | } |
| 551 | 541 | ||
| 552 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 542 | fn is_set_low(&self) -> Result<bool, Self::Error> { |
| 553 | Ok(self.pin.ref_is_set_low()) | 543 | Ok(self.is_set_low()) |
| 554 | } | 544 | } |
| 555 | } | 545 | } |
| 556 | 546 | ||
| @@ -570,11 +560,11 @@ mod eh02 { | |||
| 570 | type Error = Infallible; | 560 | type Error = Infallible; |
| 571 | 561 | ||
| 572 | fn is_high(&self) -> Result<bool, Self::Error> { | 562 | fn is_high(&self) -> Result<bool, Self::Error> { |
| 573 | Ok(!self.ref_is_low()) | 563 | Ok(self.is_high()) |
| 574 | } | 564 | } |
| 575 | 565 | ||
| 576 | fn is_low(&self) -> Result<bool, Self::Error> { | 566 | fn is_low(&self) -> Result<bool, Self::Error> { |
| 577 | Ok(self.ref_is_low()) | 567 | Ok(self.is_low()) |
| 578 | } | 568 | } |
| 579 | } | 569 | } |
| 580 | 570 | ||
| @@ -592,11 +582,11 @@ mod eh02 { | |||
| 592 | 582 | ||
| 593 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { | 583 | impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> { |
| 594 | fn is_set_high(&self) -> Result<bool, Self::Error> { | 584 | fn is_set_high(&self) -> Result<bool, Self::Error> { |
| 595 | Ok(!self.ref_is_set_low()) | 585 | Ok(self.is_set_high()) |
| 596 | } | 586 | } |
| 597 | 587 | ||
| 598 | fn is_set_low(&self) -> Result<bool, Self::Error> { | 588 | fn is_set_low(&self) -> Result<bool, Self::Error> { |
| 599 | Ok(self.ref_is_set_low()) | 589 | Ok(self.is_set_low()) |
| 600 | } | 590 | } |
| 601 | } | 591 | } |
| 602 | 592 | ||
| @@ -616,11 +606,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> { | |||
| 616 | 606 | ||
| 617 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { | 607 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> { |
| 618 | fn is_high(&mut self) -> Result<bool, Self::Error> { | 608 | fn is_high(&mut self) -> Result<bool, Self::Error> { |
| 619 | Ok(self.is_high()) | 609 | Ok((*self).is_high()) |
| 620 | } | 610 | } |
| 621 | 611 | ||
| 622 | fn is_low(&mut self) -> Result<bool, Self::Error> { | 612 | fn is_low(&mut self) -> Result<bool, Self::Error> { |
| 623 | Ok(self.is_low()) | 613 | Ok((*self).is_low()) |
| 624 | } | 614 | } |
| 625 | } | 615 | } |
| 626 | 616 | ||
| @@ -640,11 +630,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> { | |||
| 640 | 630 | ||
| 641 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { | 631 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> { |
| 642 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { | 632 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { |
| 643 | Ok(self.is_set_high()) | 633 | Ok((*self).is_set_high()) |
| 644 | } | 634 | } |
| 645 | 635 | ||
| 646 | fn is_set_low(&mut self) -> Result<bool, Self::Error> { | 636 | fn is_set_low(&mut self) -> Result<bool, Self::Error> { |
| 647 | Ok(self.is_set_low()) | 637 | Ok((*self).is_set_low()) |
| 648 | } | 638 | } |
| 649 | } | 639 | } |
| 650 | 640 | ||
| @@ -657,11 +647,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> { | |||
| 657 | /// If the pin is not in input mode the result is unspecified. | 647 | /// If the pin is not in input mode the result is unspecified. |
| 658 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { | 648 | impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> { |
| 659 | fn is_high(&mut self) -> Result<bool, Self::Error> { | 649 | fn is_high(&mut self) -> Result<bool, Self::Error> { |
| 660 | Ok(self.is_high()) | 650 | Ok((*self).is_high()) |
| 661 | } | 651 | } |
| 662 | 652 | ||
| 663 | fn is_low(&mut self) -> Result<bool, Self::Error> { | 653 | fn is_low(&mut self) -> Result<bool, Self::Error> { |
| 664 | Ok(self.is_low()) | 654 | Ok((*self).is_low()) |
| 665 | } | 655 | } |
| 666 | } | 656 | } |
| 667 | 657 | ||
| @@ -677,10 +667,10 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> { | |||
| 677 | 667 | ||
| 678 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { | 668 | impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> { |
| 679 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { | 669 | fn is_set_high(&mut self) -> Result<bool, Self::Error> { |
| 680 | Ok(self.is_set_high()) | 670 | Ok((*self).is_set_high()) |
| 681 | } | 671 | } |
| 682 | 672 | ||
| 683 | fn is_set_low(&mut self) -> Result<bool, Self::Error> { | 673 | fn is_set_low(&mut self) -> Result<bool, Self::Error> { |
| 684 | Ok(self.is_set_low()) | 674 | Ok((*self).is_set_low()) |
| 685 | } | 675 | } |
| 686 | } | 676 | } |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 07196abf7..8020b8dc2 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 | ||
| 244 | impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { | 244 | impl<'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, mut pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self { | 246 | pub fn new(ch: impl Peripheral<P = C> + 'd, 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.pin.ref_is_low()) | 484 | Ok(self.pin.is_high()) |
| 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.pin.ref_is_low()) | 488 | Ok(self.pin.is_low()) |
| 489 | } | 489 | } |
| 490 | } | 490 | } |
| 491 | } | 491 | } |
