Input PAD

This sample uses the PAD input function to detect the GPIO input signal by interrupt.

It is necessary to configure the PAD to PAD_SW_MODE mode and enable the wake up function. When the input signal changes, it will trigger the system handler interrupt, and the input level information will be printed in the interrupt handler.

Users can modify pin information through different macro configurations. For specific macro configurations, refer to Configurations.

Requirements

For hardware requirements, please refer to the Requirements.

Configurations

  1. The following macros can be configured to modify PAD pin definitions.

    #define GPIO_DEMO_INPUT_PIN0                      P1_0
    #define GPIO_DEMO_INPUT_PIN1                      P1_1
    #define GPIO_DEMO_INPUT_PIN2                      P2_1
    #define GPIO_DEMO_INPUT_PIN3                      P2_2
    
  2. The entry function is as follows, call this function in main() to run this sample code. For more details, please refer to the Initialization.

    pad_int_demo();
    

Building and Downloading

For building and downloading, please refer to the Building and Downloading.

Experimental Verification

  1. Press the Reset button on the EVB and the message will be displayed in the Debug Analyzer.

    pad_int_demo: pad interrupt demo start
    
  2. When a low level input is detected on P1_0, the following message is printed in the Debug Analyzer.

    system_handler: pin0 interrupt triggered, pin_0_state 0
    

Code Overview

This section introduces the code and process description for initialization and corresponding function implementation in the sample.

Source Code Directory

The directory for project file and source code are as follows.

  • For project directory, please refer to Source Code Directory.

  • Source code directory: sdk\sample\io_demo\gpio\interrupt\pad_int_demo.c.

Initialization

The initialization flow for peripherals can refer to Initialization Flow.

  1. Call Pad_Config() to initialize the PAD. The PAD initialization parameters are configured as shown in the table below.

PAD Input0 Initialization Parameters

PAD Hardware Parameters

PAD

Pin Number

GPIO_DEMO_INPUT_PIN0

PAD Mode

PAD_SW_MODE

PAD Power Mode

PAD_IS_PWRON

PAD Pull Mode

PAD_PULL_UP

PAD Output Mode

PAD_OUT_DISABLE

PAD Output Value

PAD_OUT_LOW

PAD Input1 Initialization Parameters

PAD Hardware Parameters

PAD

Pin Number

GPIO_DEMO_INPUT_PIN1

PAD Mode

PAD_SW_MODE

PAD Power Mode

PAD_IS_PWRON

PAD Pull Mode

PAD_PULL_UP

PAD Output Mode

PAD_OUT_DISABLE

PAD Output Value

PAD_OUT_LOW

PAD Input2 Initialization Parameters

PAD Hardware Parameters

PAD

Pin Number

GPIO_DEMO_INPUT_PIN2

PAD Mode

PAD_SW_MODE

PAD Power Mode

PAD_IS_PWRON

PAD Pull Mode

PAD_PULL_UP

PAD Output Mode

PAD_OUT_DISABLE

PAD Output Value

PAD_OUT_LOW

PAD Input3 Initialization Parameters

PAD Hardware Parameters

PAD

Pin Number

GPIO_DEMO_INPUT_PIN3

PAD Mode

PAD_SW_MODE

PAD Power Mode

PAD_IS_PWRON

PAD Pull Mode

PAD_PULL_UP

PAD Output Mode

PAD_OUT_DISABLE

PAD Output Value

PAD_OUT_LOW

  1. Call System_WakeUpPinEnable() to enable wake up function.

  2. Call System_WakeUpInterruptEnable() to enable wake up interrupt.

  3. Configure NVIC, and refer to Interrupt Configuration for NVIC-related configurations.

Functional Implementation

When connecting P1_0 to GND, detecting the low level of P1_0 triggers the system handler. The interrupt handler function system_handler prints interrupt information.

if (System_WakeUpInterruptValue(GPIO_DEMO_INPUT_PIN0))
{
    if (pin_0_state == 0)
    {
        pin_0_state = 1;
        System_WakeUpPinEnable(GPIO_DEMO_INPUT_PIN0, PAD_WAKEUP_POL_LOW);
    }
    else
    {
        pin_0_state = 0;
        System_WakeUpPinEnable(GPIO_DEMO_INPUT_PIN0, PAD_WAKEUP_POL_HIGH);
    }
    IO_PRINT_INFO1("system_handler: pin0 interrupt triggered, pin_0_state %d", pin_0_state);
}