9.8.2.1.3 Workflow

  1. Create an EXTINT module channel configuration struct, which can be filled out to adjust the configuration of a single external interrupt channel.
    struct extint_chan_conf config_extint_chan;
    
  2. Initialize the channel configuration struct with the module's default values.
    extint_chan_get_config_defaults(&config_extint_chan);
    
    Note: This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  3. Adjust the configuration struct to configure the pin MUX (to route the desired physical pin to the logical channel) to the board button, and to configure the channel to detect both rising and falling edges.
    config_extint_chan.gpio_pin           = BUTTON_0_EIC_PIN;
    config_extint_chan.gpio_pin_mux       = BUTTON_0_EIC_MUX;
    config_extint_chan.gpio_pin_pull      = EXTINT_PULL_UP;
    config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
    
  4. Configure external interrupt channel with the desired channel settings.
    extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
    
  5. Register a callback function extint_handler() to handle detections from the External Interrupt controller.
    extint_register_callback(extint_detection_callback,
            BUTTON_0_EIC_LINE,
            EXTINT_CALLBACK_TYPE_DETECT);
    
  6. Enable the registered callback function for the configured External Interrupt channel, so that it will be called by the module when the channel detects an edge.
    extint_chan_enable_callback(BUTTON_0_EIC_LINE,
            EXTINT_CALLBACK_TYPE_DETECT);
    
  7. Define the EXTINT callback that will be fired when a detection event occurs. For this example, a LED will mirror the new button state on each detection edge.
    void extint_detection_callback(void)
    {
        bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
        port_pin_set_output_level(LED_0_PIN, pin_state);
    }