Struct rppal::gpio::IoPin

source ·
pub struct IoPin { /* private fields */ }
Expand description

GPIO pin that can be (re)configured for any mode or alternate function.

IoPins are constructed by converting a Pin using Pin::into_io. The pin’s mode is automatically set to the specified mode.

An IoPin can be reconfigured for any available mode. Depending on the mode, some methods may not have any effect. For instance, calling a method that alters the pin’s output state won’t cause any changes when the pin’s mode is set to Mode::Input.

The embedded-hal trait implementations for IoPin can be enabled by specifying the optional hal feature in the dependency declaration for the rppal crate.

Implementations§

source§

impl IoPin

source

pub fn pin(&self) -> u8

Returns the GPIO pin number.

Pins are addressed by their BCM numbers, rather than their physical location.

source

pub fn mode(&self) -> Mode

Returns the pin’s mode.

source

pub fn set_mode(&mut self, mode: Mode)

Sets the pin’s mode.

source

pub fn set_bias(&mut self, bias: Bias)

Configures the built-in pull-up/pull-down resistors.

source

pub fn read(&self) -> Level

Reads the pin’s logic level.

source

pub fn is_low(&self) -> bool

Reads the pin’s logic level, and returns true if it’s set to Low.

source

pub fn is_high(&self) -> bool

Reads the pin’s logic level, and returns true if it’s set to High.

source

pub fn write(&mut self, level: Level)

Sets the pin’s output state.

source

pub fn set_low(&mut self)

Sets the pin’s output state to Low.

source

pub fn set_high(&mut self)

Sets the pin’s output state to High.

source

pub fn toggle(&mut self)

Toggles the pin’s output state between Low and High.

source

pub fn set_pwm(&mut self, period: Duration, pulse_width: Duration) -> Result<()>

Configures a software-based PWM signal.

period indicates the time it takes to complete one cycle.

pulse_width indicates the amount of time the PWM signal is active during a single period.

Software-based PWM is inherently inaccurate on a multi-threaded OS due to scheduling/preemption. If an accurate or faster PWM signal is required, use the hardware Pwm peripheral instead. More information can be found here.

If set_pwm is called when a PWM thread is already active, the existing thread will be reconfigured at the end of the current cycle.

source

pub fn set_pwm_frequency( &mut self, frequency: f64, duty_cycle: f64 ) -> Result<()>

Configures a software-based PWM signal.

set_pwm_frequency is a convenience method that converts frequency to a period and duty_cycle to a pulse width, and then calls set_pwm.

frequency is specified in hertz (Hz).

duty_cycle is specified as a floating point value between 0.0 (0%) and 1.0 (100%).

source

pub fn clear_pwm(&mut self) -> Result<()>

Stops a previously configured software-based PWM signal.

The thread responsible for emulating the PWM signal is stopped at the end of the current cycle.

source

pub fn reset_on_drop(&self) -> bool

Returns the value of reset_on_drop.

source

pub fn set_reset_on_drop(&mut self, reset_on_drop: bool)

When enabled, resets the pin’s mode to its original state and disables the built-in pull-up/pull-down resistors when the pin goes out of scope. By default, this is set to true.

Note

Drop methods aren’t called when a process is abnormally terminated, for instance when a user presses Ctrl + C, and the SIGINT signal isn’t caught. You can catch those using crates such as simple_signal.

Trait Implementations§

source§

impl Debug for IoPin

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for IoPin

source§

fn drop(&mut self)

Resets the pin’s mode and disables the built-in pull-up/pull-down resistors if reset_on_drop is set to true (default).

source§

impl ErrorType for IoPin

§

type Error = Infallible

Error type
source§

impl InputPin for IoPin

source§

fn is_high(&mut self) -> Result<bool, Self::Error>

Is the input pin high?
source§

fn is_low(&mut self) -> Result<bool, Self::Error>

Is the input pin low?
source§

impl InputPin for IoPin

§

type Error = Infallible

Error type
source§

fn is_high(&self) -> Result<bool, Self::Error>

Is the input pin high?
source§

fn is_low(&self) -> Result<bool, Self::Error>

Is the input pin low?
source§

impl IoPin<IoPin, IoPin> for IoPin

source§

fn into_input_pin(self) -> Result<IoPin, Self::Error>

Tries to convert this pin to input mode.

If the pin is already in input mode, this method should succeed.

source§

fn into_output_pin(self, state: PinState) -> Result<IoPin, Self::Error>

Tries to convert this pin to output mode with the given initial state.

If the pin is already in the requested state, this method should succeed.

§

type Error = Infallible

Error type.
source§

impl OutputPin for IoPin

source§

fn set_low(&mut self) -> Result<(), Self::Error>

Drives the pin low. Read more
source§

fn set_high(&mut self) -> Result<(), Self::Error>

Drives the pin high. Read more
source§

fn set_state(&mut self, state: PinState) -> Result<(), Self::Error>

Drives the pin high or low depending on the provided value. Read more
source§

impl OutputPin for IoPin

§

type Error = Infallible

Error type
source§

fn set_low(&mut self) -> Result<(), Self::Error>

Drives the pin low Read more
source§

fn set_high(&mut self) -> Result<(), Self::Error>

Drives the pin high Read more
source§

fn set_state(&mut self, state: PinState) -> Result<(), Self::Error>

Drives the pin high or low depending on the provided value Read more
source§

impl<'a> PartialEq<&'a IoPin> for IoPin

source§

fn eq(&self, other: &&'a IoPin) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<IoPin> for &'a IoPin

source§

fn eq(&self, other: &IoPin) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for IoPin

source§

fn eq(&self, other: &IoPin) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Pwm for IoPin

source§

fn disable(&mut self, _channel: Self::Channel)

Disables a PWM channel.

source§

fn enable(&mut self, _channel: Self::Channel)

Enables a PWM channel.

source§

fn get_period(&self) -> Self::Time

Returns the current PWM period.

source§

fn get_duty(&self, _channel: Self::Channel) -> Self::Duty

Returns the current duty cycle.

source§

fn get_max_duty(&self) -> Self::Duty

Returns the maximum duty cycle value.

source§

fn set_duty(&mut self, _channel: Self::Channel, duty: Self::Duty)

Sets a new duty cycle.

source§

fn set_period<P>(&mut self, period: P)where P: Into<Self::Time>,

Sets a new PWM period.

§

type Duty = f64

Type for the duty methods Read more
§

type Channel = ()

Enumeration of channels that can be used with this Pwm interface Read more
§

type Time = Duration

A time unit that can be converted into a human time unit (e.g. seconds)
source§

impl PwmPin for IoPin

§

type Duty = f64

Type for the duty methods Read more
source§

fn disable(&mut self)

Disables a PWM channel
source§

fn enable(&mut self)

Enables a PWM channel
source§

fn get_duty(&self) -> Self::Duty

Returns the current duty cycle
source§

fn get_max_duty(&self) -> Self::Duty

Returns the maximum duty cycle value
source§

fn set_duty(&mut self, duty: Self::Duty)

Sets a new duty cycle
source§

impl StatefulOutputPin for IoPin

source§

fn is_set_high(&self) -> Result<bool, Self::Error>

Is the pin in drive high mode? Read more
source§

fn is_set_low(&self) -> Result<bool, Self::Error>

Is the pin in drive low mode? Read more
source§

impl StatefulOutputPin for IoPin

source§

fn is_set_high(&mut self) -> Result<bool, Self::Error>

Is the pin in drive high mode? Read more
source§

fn is_set_low(&mut self) -> Result<bool, Self::Error>

Is the pin in drive low mode? Read more
source§

fn toggle(&mut self) -> Result<(), Self::Error>

Toggle pin output.
source§

impl ToggleableOutputPin for IoPin

§

type Error = Infallible

Error type
source§

fn toggle(&mut self) -> Result<(), Self::Error>

Toggle pin output.
source§

impl Eq for IoPin

Auto Trait Implementations§

§

impl !RefUnwindSafe for IoPin

§

impl Send for IoPin

§

impl Sync for IoPin

§

impl Unpin for IoPin

§

impl !UnwindSafe for IoPin

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.