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.
This commit is contained in:
@@ -52,19 +52,19 @@ impl<'d, T: Pin> Input<'d, T> {
|
||||
|
||||
/// Get whether the pin input level is high.
|
||||
#[inline]
|
||||
pub fn is_high(&mut self) -> bool {
|
||||
pub fn is_high(&self) -> bool {
|
||||
self.pin.is_high()
|
||||
}
|
||||
|
||||
/// Get whether the pin input level is low.
|
||||
#[inline]
|
||||
pub fn is_low(&mut self) -> bool {
|
||||
pub fn is_low(&self) -> bool {
|
||||
self.pin.is_low()
|
||||
}
|
||||
|
||||
/// Get the pin input level.
|
||||
#[inline]
|
||||
pub fn get_level(&mut self) -> Level {
|
||||
pub fn get_level(&self) -> Level {
|
||||
self.pin.get_level()
|
||||
}
|
||||
}
|
||||
@@ -166,19 +166,19 @@ impl<'d, T: Pin> Output<'d, T> {
|
||||
|
||||
/// Get whether the output level is set to high.
|
||||
#[inline]
|
||||
pub fn is_set_high(&mut self) -> bool {
|
||||
pub fn is_set_high(&self) -> bool {
|
||||
self.pin.is_set_high()
|
||||
}
|
||||
|
||||
/// Get whether the output level is set to low.
|
||||
#[inline]
|
||||
pub fn is_set_low(&mut self) -> bool {
|
||||
pub fn is_set_low(&self) -> bool {
|
||||
self.pin.is_set_low()
|
||||
}
|
||||
|
||||
/// Get the current output level.
|
||||
#[inline]
|
||||
pub fn get_output_level(&mut self) -> Level {
|
||||
pub fn get_output_level(&self) -> Level {
|
||||
self.pin.get_output_level()
|
||||
}
|
||||
}
|
||||
@@ -283,24 +283,19 @@ impl<'d, T: Pin> Flex<'d, T> {
|
||||
|
||||
/// Get whether the pin input level is high.
|
||||
#[inline]
|
||||
pub fn is_high(&mut self) -> bool {
|
||||
pub fn is_high(&self) -> bool {
|
||||
!self.is_low()
|
||||
}
|
||||
|
||||
/// Get whether the pin input level is low.
|
||||
#[inline]
|
||||
pub fn is_low(&mut self) -> bool {
|
||||
self.ref_is_low()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn ref_is_low(&self) -> bool {
|
||||
pub fn is_low(&self) -> bool {
|
||||
self.pin.block().in_.read().bits() & (1 << self.pin.pin()) == 0
|
||||
}
|
||||
|
||||
/// Get the pin input level.
|
||||
#[inline]
|
||||
pub fn get_level(&mut self) -> Level {
|
||||
pub fn get_level(&self) -> Level {
|
||||
self.is_high().into()
|
||||
}
|
||||
|
||||
@@ -337,24 +332,19 @@ impl<'d, T: Pin> Flex<'d, T> {
|
||||
|
||||
/// Get whether the output level is set to high.
|
||||
#[inline]
|
||||
pub fn is_set_high(&mut self) -> bool {
|
||||
pub fn is_set_high(&self) -> bool {
|
||||
!self.is_set_low()
|
||||
}
|
||||
|
||||
/// Get whether the output level is set to low.
|
||||
#[inline]
|
||||
pub fn is_set_low(&mut self) -> bool {
|
||||
self.ref_is_set_low()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn ref_is_set_low(&self) -> bool {
|
||||
pub fn is_set_low(&self) -> bool {
|
||||
self.pin.block().out.read().bits() & (1 << self.pin.pin()) == 0
|
||||
}
|
||||
|
||||
/// Get the current output level.
|
||||
#[inline]
|
||||
pub fn get_output_level(&mut self) -> Level {
|
||||
pub fn get_output_level(&self) -> Level {
|
||||
self.is_set_high().into()
|
||||
}
|
||||
}
|
||||
@@ -524,11 +514,11 @@ mod eh02 {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(!self.pin.ref_is_low())
|
||||
Ok(self.is_high())
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.pin.ref_is_low())
|
||||
Ok(self.is_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,11 +536,11 @@ mod eh02 {
|
||||
|
||||
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Output<'d, T> {
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(!self.pin.ref_is_set_low())
|
||||
Ok(self.is_set_high())
|
||||
}
|
||||
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.pin.ref_is_set_low())
|
||||
Ok(self.is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,11 +560,11 @@ mod eh02 {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(!self.ref_is_low())
|
||||
Ok(self.is_high())
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.ref_is_low())
|
||||
Ok(self.is_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,11 +582,11 @@ mod eh02 {
|
||||
|
||||
impl<'d, T: Pin> embedded_hal_02::digital::v2::StatefulOutputPin for Flex<'d, T> {
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(!self.ref_is_set_low())
|
||||
Ok(self.is_set_high())
|
||||
}
|
||||
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.ref_is_set_low())
|
||||
Ok(self.is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,11 +606,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Input<'d, T> {
|
||||
|
||||
impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Input<'d, T> {
|
||||
fn is_high(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_high())
|
||||
Ok((*self).is_high())
|
||||
}
|
||||
|
||||
fn is_low(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_low())
|
||||
Ok((*self).is_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,11 +630,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Output<'d, T> {
|
||||
|
||||
impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Output<'d, T> {
|
||||
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_high())
|
||||
Ok((*self).is_set_high())
|
||||
}
|
||||
|
||||
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_low())
|
||||
Ok((*self).is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,11 +647,11 @@ impl<'d, T: Pin> embedded_hal_1::digital::ErrorType for Flex<'d, T> {
|
||||
/// If the pin is not in input mode the result is unspecified.
|
||||
impl<'d, T: Pin> embedded_hal_1::digital::InputPin for Flex<'d, T> {
|
||||
fn is_high(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_high())
|
||||
Ok((*self).is_high())
|
||||
}
|
||||
|
||||
fn is_low(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_low())
|
||||
Ok((*self).is_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -677,10 +667,10 @@ impl<'d, T: Pin> embedded_hal_1::digital::OutputPin for Flex<'d, T> {
|
||||
|
||||
impl<'d, T: Pin> embedded_hal_1::digital::StatefulOutputPin for Flex<'d, T> {
|
||||
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_high())
|
||||
Ok((*self).is_set_high())
|
||||
}
|
||||
|
||||
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_low())
|
||||
Ok((*self).is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
|
||||
|
||||
impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
|
||||
/// Create a new GPIOTE output channel driver.
|
||||
pub fn new(ch: impl Peripheral<P = C> + 'd, mut pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
|
||||
pub fn new(ch: impl Peripheral<P = C> + 'd, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
|
||||
into_ref!(ch);
|
||||
let g = regs();
|
||||
let num = ch.number();
|
||||
@@ -481,11 +481,11 @@ mod eh02 {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(!self.pin.pin.ref_is_low())
|
||||
Ok(self.pin.is_high())
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.pin.pin.ref_is_low())
|
||||
Ok(self.pin.is_low())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user