C

Qt Quick Ultralite interrupt_handler Example

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

// Note: the following headers are written in C, they must be included in .c file to avoid compile errors
#include "board.h"
#include "fsl_gpio.h"
#include "fsl_common.h"

#ifdef NXP_FREERTOS
#include "FreeRTOSConfig.h"
#endif

void userButtonCallback(void);

void nxpConfig(void)
{
    const gpio_pin_config_t sw_config = {
        kGPIO_DigitalInput,
        0,
        kGPIO_IntRisingEdge,
    };

    const status_t status = EnableIRQ(BOARD_USER_BUTTON_IRQ);
    if (status != kStatus_Fail) {
        GPIO_PinInit(BOARD_USER_BUTTON_GPIO, BOARD_USER_BUTTON_GPIO_PIN, &sw_config);
        GPIO_PortEnableInterrupts(BOARD_USER_BUTTON_GPIO, 1U << BOARD_USER_BUTTON_GPIO_PIN);
    }

#ifdef NXP_FREERTOS
    NVIC_SetPriority(BOARD_USER_BUTTON_IRQ, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY);
#endif
}
void BOARD_USER_BUTTON_IRQ_HANDLER(void)
{
    GPIO_PortClearInterruptFlags(BOARD_USER_BUTTON_GPIO, 1U << BOARD_USER_BUTTON_GPIO_PIN);
    userButtonCallback();
}