Struct esp_idf_hal::gpio::PinDriver
source · pub struct PinDriver<'d, T: Pin, MODE> { /* private fields */ }
Expand description
A driver for a GPIO pin.
The driver can set the pin as a disconnected/disabled one, input, or output pin, or both or analog. On some chips (i.e. esp32 and esp32s*), the driver can also set the pin in RTC IO mode. Depending on the current operating mode, different sets of functions are available.
The mode-setting depends on the capabilities of the pin as well, i.e. input-only pins cannot be set into output or input-output mode.
Implementations§
source§impl<'d, T: Pin> PinDriver<'d, T, Disabled>
impl<'d, T: Pin> PinDriver<'d, T, Disabled>
sourcepub fn disabled(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
pub fn disabled(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
Creates the driver for a pin in disabled state.
source§impl<'d, T: InputPin> PinDriver<'d, T, Input>
impl<'d, T: InputPin> PinDriver<'d, T, Input>
sourcepub fn input(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
pub fn input(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
Creates the driver for a pin in input state.
source§impl<'d, T: InputPin + OutputPin> PinDriver<'d, T, InputOutput>
impl<'d, T: InputPin + OutputPin> PinDriver<'d, T, InputOutput>
sourcepub fn input_output(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
pub fn input_output(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
Creates the driver for a pin in input-output state.
source§impl<'d, T: InputPin + OutputPin> PinDriver<'d, T, InputOutput>
impl<'d, T: InputPin + OutputPin> PinDriver<'d, T, InputOutput>
sourcepub fn input_output_od(
pin: impl Peripheral<P = T> + 'd
) -> Result<Self, EspError>
pub fn input_output_od( pin: impl Peripheral<P = T> + 'd ) -> Result<Self, EspError>
Creates the driver for a pin in input-output open-drain state.
source§impl<'d, T: OutputPin> PinDriver<'d, T, Output>
impl<'d, T: OutputPin> PinDriver<'d, T, Output>
sourcepub fn output(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
pub fn output(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
Creates the driver for a pin in output state.
source§impl<'d, T: OutputPin> PinDriver<'d, T, Output>
impl<'d, T: OutputPin> PinDriver<'d, T, Output>
sourcepub fn output_od(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
pub fn output_od(pin: impl Peripheral<P = T> + 'd) -> Result<Self, EspError>
Creates the driver for a pin in output open-drain state.
source§impl<'d, T: Pin, MODE> PinDriver<'d, T, MODE>
impl<'d, T: Pin, MODE> PinDriver<'d, T, MODE>
sourcepub fn into_disabled(self) -> Result<PinDriver<'d, T, Disabled>, EspError>
pub fn into_disabled(self) -> Result<PinDriver<'d, T, Disabled>, EspError>
Put the pin into disabled mode.
sourcepub fn into_input(self) -> Result<PinDriver<'d, T, Input>, EspError>where
T: InputPin,
pub fn into_input(self) -> Result<PinDriver<'d, T, Input>, EspError>where T: InputPin,
Put the pin into input mode.
sourcepub fn into_input_output(
self
) -> Result<PinDriver<'d, T, InputOutput>, EspError>where
T: InputPin + OutputPin,
pub fn into_input_output( self ) -> Result<PinDriver<'d, T, InputOutput>, EspError>where T: InputPin + OutputPin,
Put the pin into input + output mode.
sourcepub fn into_input_output_od(
self
) -> Result<PinDriver<'d, T, InputOutput>, EspError>where
T: InputPin + OutputPin,
pub fn into_input_output_od( self ) -> Result<PinDriver<'d, T, InputOutput>, EspError>where T: InputPin + OutputPin,
Put the pin into input + output Open Drain mode.
This is commonly used for “open drain” mode. the hardware will drive the line low if you set it to low, and will leave it floating if you set it to high, in which case you can read the input to figure out whether another device is driving the line low.
sourcepub fn into_output(self) -> Result<PinDriver<'d, T, Output>, EspError>where
T: OutputPin,
pub fn into_output(self) -> Result<PinDriver<'d, T, Output>, EspError>where T: OutputPin,
Put the pin into output mode.
sourcepub fn into_output_od(self) -> Result<PinDriver<'d, T, Output>, EspError>where
T: OutputPin,
pub fn into_output_od(self) -> Result<PinDriver<'d, T, Output>, EspError>where T: OutputPin,
Put the pin into output Open Drain mode.
pub fn get_drive_strength(&self) -> Result<DriveStrength, EspError>where MODE: OutputMode,
pub fn set_drive_strength( &mut self, strength: DriveStrength ) -> Result<(), EspError>where MODE: OutputMode,
pub fn is_high(&self) -> boolwhere MODE: InputMode,
pub fn is_low(&self) -> boolwhere MODE: InputMode,
pub fn get_level(&self) -> Levelwhere MODE: InputMode,
pub fn is_set_high(&self) -> boolwhere MODE: OutputMode,
sourcepub fn is_set_low(&self) -> boolwhere
MODE: OutputMode,
pub fn is_set_low(&self) -> boolwhere MODE: OutputMode,
Is the output pin set as low?
pub fn set_high(&mut self) -> Result<(), EspError>where MODE: OutputMode,
sourcepub fn set_low(&mut self) -> Result<(), EspError>where
MODE: OutputMode,
pub fn set_low(&mut self) -> Result<(), EspError>where MODE: OutputMode,
Set the output as low.
pub fn set_level(&mut self, level: Level) -> Result<(), EspError>where MODE: OutputMode,
sourcepub fn toggle(&mut self) -> Result<(), EspError>where
MODE: OutputMode,
pub fn toggle(&mut self) -> Result<(), EspError>where MODE: OutputMode,
Toggle pin output
pub fn set_pull(&mut self, pull: Pull) -> Result<(), EspError>where T: InputPin + OutputPin, MODE: InputMode,
sourcepub unsafe fn subscribe(
&mut self,
callback: impl FnMut() + 'static
) -> Result<(), EspError>where
MODE: InputMode,
pub unsafe fn subscribe( &mut self, callback: impl FnMut() + 'static ) -> Result<(), EspError>where MODE: InputMode,
Safety
Care should be taken not to call STD, libc or FreeRTOS APIs (except for a few allowed ones) in the callback passed to this function, as it is executed in an ISR context.