GPIO Essentials

~10 min slides

GPIO — General Purpose Input/Output. The most basic peripheral: making pins go high or low, and reading whether they're high or low.

Configurations

Before you can use a GPIO pin, you need to decide how it will behave.

Direction

  • Output — you drive the pin (e.g., turn on an LED)
  • Input — you read the pin (e.g., detect a button press)

Output Modes

  • Push-pull (default) — actively drives the pin high and low
  • Open-drain — actively drives low, but floats when "high" (needs external pull-up)

Pull Resistors (for inputs)

  • Pull-up — pin reads high when nothing is connected; button pulls it low
  • Pull-down — pin reads low when nothing is connected; button pulls it high
  • Floating — no pull resistor; pin state is undefined when nothing is connected

Drive Strength (for outputs)

How much current the pin can source or sink. Higher drive strength = brighter LED, but more power consumption.

Controls

Output Controls

MethodWhat It Does
set_high()Drive the pin high
set_low()Drive the pin low
toggle()Flip the pin state
set_level(Level)Set to a specific level
is_set_high()Check what you last set

Input Controls

MethodWhat It Does
is_high()boolIs the pin high?
is_low()boolIs the pin low?
get_level()LevelGet the level as an enum
`is_high()` returns a `bool` — simple, but you lose information. `get_level()` returns a `Level` enum that you can `match` on. Both work; the enum version is more expressive and more Rusty.

uFerris GPIO Map

Check your pinout card for the exact pin assignments on the uFerris Megalops board:

FunctionPinNotes
Onboard LEDGPIO?Active high/low?
User ButtonGPIO?Needs pull-up?
I2C SDAGPIO?Used in Part 3
I2C SCLGPIO?Used in Part 3
The exact pin numbers depend on your uFerris board revision. Always check the pinout card provided in your workshop kit.

Mapping to docs.rs

Here's how GPIO maps to the Create → Configure → Control pattern:

StepWhat to Look ForWhere on docs.rs
CreateOutput::new(pin, level, config)Struct page → impl Output
ConfigureOutputConfig, InputConfig, Pull, DriveStrengthAssociated types / linked structs
Controlset_high(), toggle(), get_level()Trait impls + inherent methods

Now let's put this into practice.