Module atmega32u4_hal::port[][src]

Port{B,C,D,E,F}

Abstraction of the IO pins.

Design

For each port, you can call .split() on the raw periperal to separate the pins.

By default, each pin is Input<Floating>. There are three methods to change the mode:

  • into_floating_input(): Turn a pin into a floating input
  • into_pull_up_input(): Turn a pin into a pull-up input
  • into_output(): Turn a pin into an output

For input pins embedded_hal::digital::InputPin is implemented, for output pins embedded_hal::digital::OutputPin & embedded_hal::digital::StatefulOutputPin.

Downgrading

After .split() each pin is of a separate type. This means you can't store them in an array. To allow doing so you can .downgrade() a pin. This can be done twice: The first downgrade makes the pin generic for its port, the second downgrade makes it fully generic.

Note: After downgrading a pin, you can no longer change its mode!

PWM

Some pins can be configured to output a PWM signal. This is not implemented in the port module but in the [timer] module.

Example

// Get the raw peripherals
let dp = atmega32u4::Peripherals::take().unwrap();

// Split the port and create an output pin
let mut portc = dp.PORTC.split();
let mut pc7 = portc.pc7.into_output(&mut portc.ddr);

// Use the pin
pc7.set_high();
pc7.set_low();

Modules

mode

Pin modes

portb

Port Types

portc

Port Types

portd

Port Types

porte

Port Types

portf

Port Types

Structs

Pin

A completely generic pin

Traits

PortExt

A splittable port