C

Qt Quick Ultralite interrupt_handler Example

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial
#include "board_config.h"
#include "interrupt_queue.h"
#include "r_typedefs.h"
#include "r_bsp_hmi_api.h"
#include "r_gpio_api.h"
#include "r_bsp_hmi_knob.h"

void button_handler()
{
    HWButtonInput::instance().postEventFromInterrupt(0);
}

static void qulButtonCenterAction(void)
{
    uint8_t level = R_GPIO_ReadIntPin(BSP_BTN_CENTER_INTP);

    if (level == 0u) {
        R_BSP_BtnAction(BSP_BTN_CENTER_PRESS);
    } else {
        R_BSP_BtnAction(BSP_BTN_CENTER_RELEASE);
    }
}
static void overrideButtonAction()
{
    //Disable interrupt
    R_GPIO_DeInitInt(BSP_BTN_CENTER_INTP);

    //Assign custom button action
    r_gpio_IntConfig_t cfg;

    cfg.Port = BSP_BTN_CENTER_PORT;
    cfg.Pin = BSP_BTN_CENTER_PIN;
    cfg.Trigger = R_GPIO_INT_BOTH_EDGES;
    cfg.Callback = &qulButtonCenterAction;
    R_GPIO_InitInt(BSP_BTN_CENTER_INTP, &cfg);

    //Enable interrupt
    R_GPIO_EnableInt(BSP_BTN_CENTER_INTP);
}

void ConfigureBoard()
{
    R_BSP_HMI_Init();
    overrideButtonAction();
    R_BSP_SetButtonCallback(BSP_BTN_CENTER_PRESS, button_handler);
}