atsamd_hal

Module eic

Source
Expand description

§External Interrupt Controller

This module provides typesafe APIs for interacting with the EIC peripheral, which is used to generate interrupts based on the state of a GPIO.

Each chip has a number of EXTINT channels:

  • SAMD11: 8 channels
  • SAMD21/SAMx5x: 16 channels

Each channel can operate independently, and sense state changes for a single GPIO pin at a time. Refer to the datasheet for GPIO pin/EXTINT channel compatibility. In this module, an ExtInt represents an EXTINT channel which is tied to a GPIO Pin, and is capable of sensing state changes.

§Steps to create an ExtInt

  1. Start by creating an Eic struct, by calling Eic::new. This initializes the EIC peripheral and sets up the correct clocking.

  2. Turn the Eic into a tuple of Channels by calling Eic::split. Each channel represents a single EXTINT channel.

  3. Assign a pin to a channel by calling Channel::with_pin. This returns a fully configured and ready to use ExtInt. A Pin can also be directly converted into an ExtInt by calling one of the methods provided by the EicPin trait.

§Example setup

let eic_clock = clocks.eic(&gclk0).unwrap();
// Initialize the EIC peripheral
let eic = Eic::new(&mut peripherals.pm, eic_clock, peripherals.eic);
// Split into channels
let eic_channels = eic.split();

// Take the pin that we want to use
let button: Pin<_, PullUpInterrupt> = pins.d10.into();

// Turn the EXTINT[2] channel into an ExtInt struct
let mut extint = eic_channels.2.with_pin(button);

§async operation async

ExtInts can be used for async operations. Configuring the Eic in async mode is relatively simple:

  • Bind the corresponding EIC interrupt source to the SPI InterruptHandler (refer to the module-level async_hal documentation for more information).

  • SAMD11/SAMD21: Turn an Eic into an async-enabled Eic by calling Eic::into_future. Since there is only a single interrupt handler for the EIC peripheral, all EXTINT channels must be turned into async channels at once.

  • SAMx5x: Turn an individuel ExtInt into an async-enabled ExtInt by calling [ExtInt::into_future]. Each channel has a dedicated interrupt source, therefore you must individually choose which channels to turn into async channels.

  • Use the provided wait method. async-enabled ExtInts also implement embedded_hal_async::digital::Wait.

Structs§

  • EIC channel.
  • Struct generating individual handles to each EXTINT channel
  • External Interrupt Controller.
  • A numbered external interrupt, which can be used to sense state changes on its pin.
  • Struct generating individual handles to each EXTINT channel for async operation

Enums§

  • Type alias for a channel number
  • Type alias for a channel number
  • Type alias for a channel number
  • Type alias for a channel number
  • Type alias for a channel number
  • Type alias for a channel number
  • Type alias for a channel number
  • Type alias for a channel number
  • Marker type that represents an EXTINT channel capable of doing async operations.

Constants§

Traits§

  • Trait representing an EXTINT channel ID.
  • Trait representing a GPIO pin which can be used as an external interrupt.

Type Aliases§