pub struct OutputPin { /* private fields */ }
Expand description
GPIO pin configured as output.
OutputPin
s are constructed by converting a Pin
using Pin::into_output
,
Pin::into_output_low
or Pin::into_output_high
. The pin’s mode is automatically set to
Mode::Output
.
An OutputPin
can be used to change a pin’s output state.
The embedded-hal
digital::OutputPin
and PwmPin
trait implementations for OutputPin
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 OutputPin
can be enabled
by specifying the optional hal-unproven
feature in the dependency declaration for
the rppal
crate.
Implementations§
source§impl OutputPin
impl OutputPin
sourcepub fn pin(&self) -> u8
pub fn pin(&self) -> u8
Returns the GPIO pin number.
Pins are addressed by their BCM numbers, rather than their physical location.
sourcepub fn is_set_low(&self) -> bool
pub fn is_set_low(&self) -> bool
Returns true
if the pin’s output state is set to Low
.
sourcepub fn is_set_high(&self) -> bool
pub fn is_set_high(&self) -> bool
Returns true
if the pin’s output state is set to High
.
sourcepub fn set_pwm(&mut self, period: Duration, pulse_width: Duration) -> Result<()>
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.
sourcepub fn set_pwm_frequency(
&mut self,
frequency: f64,
duty_cycle: f64
) -> Result<()>
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%).
sourcepub fn clear_pwm(&mut self) -> Result<()>
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.
sourcepub fn reset_on_drop(&self) -> bool
pub fn reset_on_drop(&self) -> bool
Returns the value of reset_on_drop
.
sourcepub fn set_reset_on_drop(&mut self, reset_on_drop: bool)
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 ErrorType for OutputPin
impl ErrorType for OutputPin
ErrorType
trait implementation for embedded-hal
v1.0.0.
§type Error = Infallible
type Error = Infallible
source§impl OutputPin for OutputPin
impl OutputPin for OutputPin
OutputPin
trait implementation for embedded-hal
v0.2.7.
§type Error = Infallible
type Error = Infallible
source§impl<'a> PartialEq<&'a OutputPin> for OutputPin
impl<'a> PartialEq<&'a OutputPin> for OutputPin
source§impl<'a> PartialEq<OutputPin> for &'a OutputPin
impl<'a> PartialEq<OutputPin> for &'a OutputPin
source§impl PartialEq<OutputPin> for OutputPin
impl PartialEq<OutputPin> for OutputPin
source§impl Pwm for OutputPin
impl Pwm for OutputPin
Unproven Pwm
trait implementation for embedded-hal
v0.2.7.
source§fn get_period(&self) -> Self::Time
fn get_period(&self) -> Self::Time
Returns the current PWM period.
source§fn get_max_duty(&self) -> Self::Duty
fn get_max_duty(&self) -> Self::Duty
Returns the maximum duty cycle value.
source§fn set_period<P>(&mut self, period: P)where
P: Into<Self::Time>,
fn set_period<P>(&mut self, period: P)where P: Into<Self::Time>,
Sets a new PWM period.
source§impl PwmPin for OutputPin
impl PwmPin for OutputPin
PwmPin
trait implementation for embedded-hal
v0.2.7.
source§fn get_max_duty(&self) -> Self::Duty
fn get_max_duty(&self) -> Self::Duty
source§impl StatefulOutputPin for OutputPin
impl StatefulOutputPin for OutputPin
Unproven StatefulOutputPin
trait implementation for embedded-hal
v0.2.7.
source§impl StatefulOutputPin for OutputPin
impl StatefulOutputPin for OutputPin
StatefulOutputPin
trait implementation for embedded-hal
v1.0.0.
source§impl ToggleableOutputPin for OutputPin
impl ToggleableOutputPin for OutputPin
ToggleableOutputPin
trait implementation for embedded-hal
v1.0.0.
source§impl ToggleableOutputPin for OutputPin
impl ToggleableOutputPin for OutputPin
Unproven ToggleableOutputPin
trait implementation for embedded-hal
v0.2.7.