Expand description
General Purpose Input and Output (GPIO)
§Basic usage
use embedded_hal::digital::{InputPin, OutputPin};
use rp235x_hal::{
self as hal, clocks::init_clocks_and_plls, gpio::Pins, watchdog::Watchdog, Sio,
};
let mut peripherals = hal::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 = hal::pac::Peripherals::take().unwrap();
let sio = Sio::new(pac.SIO);
let pins = rp235x_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
Modules§
Structs§
- AsInput
Pin - Wrapper providing input pin functions for GPIO pins independent of the configured mode.
- DynPin
Id - Value-level representation for the pin (bank + id).
- Function
Clock - Type-level
variantfor pinFunction. - Function
I2c - Type-level
variantfor pinFunction. - Function
Null - Type-level
variantfor pinFunction. - Function
Pio0 - Type-level
variantfor pinFunction. - Function
Pio1 - Type-level
variantfor pinFunction. - Function
Pio2 - Type-level
variantfor pinFunction. - Function
Pwm - Type-level
variantfor pinFunction. - Function
Sio - Type-level
variantfor pinFunction. - Function
Spi - Type-level
variantfor pinFunction. - Function
Uart - Type-level
variantfor pinFunction. - Function
Uart Aux - Type-level
variantfor pinFunction. - Function
Usb - Type-level
variantfor pinFunction. - Function
Xip - Type-level
variantfor pinFunction. - Function
XipCs1 - Type-level
variantfor pinFunction. - InOut
Pin - A wrapper
AnyPin<Function =FunctionSioOutput>emulating open-drain function. - Invalid
Function - Error type for invalid function conversion.
- Pin
- 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).
- PinGroup
- A group of pins to be controlled together and guaranty single cycle control of several pins.
- Pins
- Collection of all the individual
Pins - Pull
BusKeep - Type-level
variantofPullType. - Pull
Down - Type-level
variantofPullType. - Pull
None - Type-level
variantofPullType. - PullUp
- Type-level
variantofPullType.
Enums§
- DynBank
Id - Value-level
enumfor the pin’s bank. - DynFunction
- Describes the function currently assigned to a pin with a dynamic type.
- DynPull
Type - Value-level
enumfor pull resistor types. - DynSio
Config - Value-level
enumfor SIO configuration. - Input
Override - Input override state.
- Interrupt
- Interrupt kind.
- Interrupt
Override - Interrupt override state.
- Output
Drive Strength - The amount of current that a pin can drive when used as an output.
- Output
Enable Override - Output enable override state.
- Output
Override - Output override state.
- Output
Slew Rate - The slew rate of a pin when used as an output.
- PinState
- Digital output pin state.
- SioInput
- Type-level
variantfor SIO configuration. - SioOutput
- Type-level
variantfor SIO configuration.
Traits§
- AnyPin
- Type class for
Pintypes. - Default
Type State - Default type state of a pin after reset of the pads, io and sio.
- Function
- Type-level
enumfor pin function. - PinId
- Type-level
enumfor the pin Id (pin number + bank). - Pull
Type - Type-level
enumfor pull resistor types. - SioConfig
- Type-level
enumfor SIO configuration. - Valid
Function - Marker of valid pin -> function combination.
Functions§
- new_pin⚠
- Create a new pin instance.
Type Aliases§
- Error
- GPIO error type.
- Function
I2C - Alias to
FunctionI2c. - Function
SioInput - Alias to
FunctionSio<Input>. - Function
SioOutput - Alias to
FunctionSio<Output>. - Specific
Pin - Type alias to recover the specific
Pintype from an implementation ofAnyPin.