Struct rppal::gpio::IoPin[][src]

pub struct IoPin { /* fields omitted */ }

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 Input.

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

The unproven embedded-hal digital::InputPin, digital::StatefulOutputPin, digital::ToggleableOutputPin and Pwm trait implementations for IoPin can be enabled by specifying the optional hal-unproven feature in the dependency declaration for the rppal crate.

Implementations

impl IoPin[src]

pub fn pin(&self) -> u8[src]

Returns the GPIO pin number.

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

pub fn mode(&self) -> Mode[src]

Returns the pin's mode.

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

Sets the pin's mode.

pub fn set_pullupdown(&mut self, pud: PullUpDown)[src]

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

pub fn read(&self) -> Level[src]

Reads the pin's logic level.

pub fn is_low(&self) -> bool[src]

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

pub fn is_high(&self) -> bool[src]

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

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

Sets the pin's output state.

pub fn set_low(&mut self)[src]

Sets the pin's output state to Low.

pub fn set_high(&mut self)[src]

Sets the pin's output state to High.

pub fn toggle(&mut self)[src]

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

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

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.

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

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%).

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

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.

pub fn reset_on_drop(&self) -> bool[src]

Returns the value of reset_on_drop.

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

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

impl Debug for IoPin[src]

impl Drop for IoPin[src]

fn drop(&mut self)[src]

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

impl Eq for IoPin[src]

impl InputPin for IoPin[src]

type Error = Error

Error type

impl OutputPin for IoPin[src]

type Error = Error

Error type

impl<'a> PartialEq<&'a IoPin> for IoPin[src]

impl PartialEq<IoPin> for IoPin[src]

impl<'a> PartialEq<IoPin> for &'a IoPin[src]

impl Pwm for IoPin[src]

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)

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

Disables a PWM channel

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

Enables a PWM channel

fn get_period(&self) -> Self::Time[src]

Returns the current PWM period

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

Returns the current duty cycle

fn get_max_duty(&self) -> Self::Duty[src]

Returns the maximum duty cycle value

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

Sets a new duty cycle

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

Sets a new PWM period

impl PwmPin for IoPin[src]

type Duty = f64

Type for the duty methods Read more

impl StatefulOutputPin for IoPin[src]

impl ToggleableOutputPin for IoPin[src]

type Error = Error

Error type

Auto Trait Implementations

impl !RefUnwindSafe for IoPin[src]

impl Send for IoPin[src]

impl Sync for IoPin[src]

impl Unpin for IoPin[src]

impl !UnwindSafe for IoPin[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.