Module rp2040_hal::gpio
source · Expand description
General Purpose Input and Output (GPIO)
§Basic usage
use embedded_hal::digital::{InputPin, OutputPin};
use rp2040_hal::{clocks::init_clocks_and_plls, gpio::Pins, watchdog::Watchdog, pac, Sio};
let mut peripherals = pac::Peripherals::take().unwrap();
let mut watchdog = Watchdog::new(peripherals.WATCHDOG);
const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; // Typically found in BSP crates
let mut clocks = init_clocks_and_plls(XOSC_CRYSTAL_FREQ, peripherals.XOSC, peripherals.CLOCKS, peripherals.PLL_SYS, peripherals.PLL_USB, &mut peripherals.RESETS, &mut watchdog).ok().unwrap();
let mut pac = pac::Peripherals::take().unwrap();
let sio = Sio::new(pac.SIO);
let pins = rp2040_hal::gpio::Pins::new(pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, &mut pac.RESETS);
// Set a pin to drive output
let mut output_pin = pins.gpio25.into_push_pull_output();
// Drive output to 3.3V
output_pin.set_high().unwrap();
// Drive output to 0V
output_pin.set_low().unwrap();
// Set a pin to input
let mut input_pin = pins.gpio24.into_floating_input();
// pinstate will be true if the pin is above 2V
let pinstate = input_pin.is_high().unwrap();
// pinstate_low will be true if the pin is below 1.15V
let pinstate_low = input_pin.is_low().unwrap();
// you'll want to pull-up or pull-down a switch if it's not done externally
let button_pin = pins.gpio23.into_pull_down_input();
let button2_pin = pins.gpio22.into_pull_up_input();
See examples/gpio_in_out.rs for a more practical example
Re-exports§
pub use bank0::Pins;
Modules§
- Pin bank Bank0
- Pin bank Qspi
Structs§
- Wrapper providing input pin functions for GPIO pins independent of the configured mode.
- Value-level representation for the pin (bank + id).
- Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Type-level
variant
for pinFunction
. - Error type for invalid function conversion.
- Represents a pin, with a given ID (e.g. Gpio3), a given function (e.g. FunctionUart) and a given pull type (e.g. pull-down).
- A group of pins to be controlled together and guaranty single cycle control of several pins.
- Type-level
variant
ofPullType
. - Type-level
variant
ofPullType
. - Type-level
variant
ofPullType
. - Type-level
variant
ofPullType
.
Enums§
- Value-level
enum
for the pin’s bank. - Describes the function currently assigned to a pin with a dynamic type.
- Value-level
enum
for pull resistor types. - Value-level
enum
for SIO configuration. - Input override state.
- Interrupt kind.
- Interrupt override state.
- The amount of current that a pin can drive when used as an output.
- Output enable override state.
- Output override state.
- The slew rate of a pin when used as an output.
- Digital output pin state.
- Type-level
variant
for SIO configuration. - Type-level
variant
for SIO configuration.
Traits§
- Type class for
Pin
types. - Default type state of a pin after reset of the pads, io and sio.
- Type-level
enum
for pin function. - Type-level
enum
for the pin Id (pin number + bank). - Type-level
enum
for pull resistor types. - Type-level
enum
for SIO configuration. - Marker of valid pin -> function combination.
Functions§
- Create a new pin instance.
Type Aliases§
- GPIO error type.
- Alias to
FunctionI2c
. - Alias to
FunctionSio<Input>
. - Alias to
FunctionSio<Output>
.