gpio_interrupt.rs 1.76 KiB
//! GPIO interrupt. When KEY1 on the dev board is pressed down, a falling edge is detected and the
//! LED is toggled. Because we don't debounce at all, the LED sometimes also toggles when releasing
//! the button.
#![no_main]
#![no_std]
#![feature(panic_info_message)]
uart_panic_handler!(pac::USART3);
use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin};
use hal::{
    debug::PanicInfo,
    io::pin::{
        split_ports, Gpio, GpioInterrupts, GpioPinInt, IntoGpioPin, Output, Pin, PinSplit,
        TriggerMode, U0, U7,
    pac,
    serial::Serial,
    uart_panic_handler,
use lpc43xx_hal as hal;
use rtfm::app;
#[app(device = lpc43xx_hal::pac)]
const APP: () = {
    static mut LED: Pin<U7, U7, Gpio<Output>> = ();
    //static mut PIN_INT: pac::GPIO_PIN_INT = ();
    static mut KEY1_INT: GpioPinInt<U0> = ();
    #[init]
    fn init() -> init::LateResources {
        let ports = split_ports(device.SCU, device.GPIO_PORT);
        let mut key1_pin = ports.port_c.split_pins().pc_9.into_gpio();
        //let mut key1_int = ports.gpio_interrupts.pin_int_0;
        let mut key1_int = GpioInterrupts::new(device.GPIO_PIN_INT).pin_int_0;
        key1_int.set_interrupt_source(&key1_pin);
        key1_int.trigger_mode(TriggerMode::EdgeFalling);
        // Configure LED GPIO
        let mut led_pin = ports.port_7.split_pins().p7_7.into_gpio().into_output();
        led_pin.set_low().unwrap();
        init::LateResources {
            LED: led_pin,
            //PIN_INT: device.GPIO_PIN_INT,
            KEY1_INT: key1_int,
    #[idle]
    fn idle() -> ! {
        loop {}
    #[interrupt(resources = [LED, KEY1_INT])]
    fn PIN_INT0() {
        resources.KEY1_INT.clear_pending_bit();
        resources.LED.toggle().unwrap();