From fe500cf4de3c62a102b5754aab945a1609e5365f Mon Sep 17 00:00:00 2001 From: Marius Tache <102153746+marius-alex-tache@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:23:31 +0300 Subject: [PATCH] [nxp][examples][common] Make button components configurable (#36077) Introduce the following flags: - CONFIG_APP_BUTTON_ENABLED - flag to configure if ButtonApp instance is registered. - CONFIG_BLE_BUTTON_ENABLED - flag to configure if ButtonBle instance is registered. - CONFIG_APP_BUTTON_HANDLE_SDK_PREDEFINED - flag to configure if the button handle is predefined in the SDK or not. If not set, the handle will be defined and initialized explicitly in the file. Signed-off-by: marius-alex-tache --- .../common/matter_button/source/ButtonApp.cpp | 23 ++++++++++++++-- .../matter_button/source/ButtonManager.cpp | 3 +++ .../source/ButtonRegistrationAppAndBle.cpp | 27 +++++++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/examples/platform/nxp/common/matter_button/source/ButtonApp.cpp b/examples/platform/nxp/common/matter_button/source/ButtonApp.cpp index c380319a1d1840..ce036dbd756682 100644 --- a/examples/platform/nxp/common/matter_button/source/ButtonApp.cpp +++ b/examples/platform/nxp/common/matter_button/source/ButtonApp.cpp @@ -24,11 +24,30 @@ extern "C" { #include "board_comp.h" } +/** + * @brief Flag to describe if the button handles are predefined in SDK. + * + * Set to true by default. Platforms that do not have this support should + * disable the flag, which will enable handle definition in this file. + */ +#ifndef CONFIG_APP_BUTTON_HANDLE_SDK_PREDEFINED +#define CONFIG_APP_BUTTON_HANDLE_SDK_PREDEFINED 1 +#endif + +#if !CONFIG_APP_BUTTON_HANDLE_SDK_PREDEFINED +BUTTON_HANDLE_ARRAY_DEFINE(g_buttonHandle, gAppButtonCnt_c); +#endif + CHIP_ERROR chip::NXP::App::ButtonApp::Init() { - // Button is initialized in otSysInit, when APP_InitServices is called. - // Overwrite the handle to reference the SDK handle. +#if CONFIG_APP_BUTTON_HANDLE_SDK_PREDEFINED + // Button is defined in the SDK and initialized in otSysInit, when APP_InitServices is called. handle = &g_buttonHandle[1]; +#else + // Button handle is defined in this file and it should be initialized here. + handle = &g_buttonHandle[0]; + BOARD_InitButton0(handle); +#endif return CHIP_NO_ERROR; } diff --git a/examples/platform/nxp/common/matter_button/source/ButtonManager.cpp b/examples/platform/nxp/common/matter_button/source/ButtonManager.cpp index 046337397a3c3c..7aa9866edf9a01 100644 --- a/examples/platform/nxp/common/matter_button/source/ButtonManager.cpp +++ b/examples/platform/nxp/common/matter_button/source/ButtonManager.cpp @@ -17,7 +17,10 @@ */ #include "ButtonManager.h" + +extern "C" { #include "fwk_platform.h" +} #include #include diff --git a/examples/platform/nxp/common/matter_button/source/ButtonRegistrationAppAndBle.cpp b/examples/platform/nxp/common/matter_button/source/ButtonRegistrationAppAndBle.cpp index 45037b268f8254..b16bc1ff5cd58e 100644 --- a/examples/platform/nxp/common/matter_button/source/ButtonRegistrationAppAndBle.cpp +++ b/examples/platform/nxp/common/matter_button/source/ButtonRegistrationAppAndBle.cpp @@ -24,14 +24,37 @@ #include -static chip::NXP::App::ButtonApp sAppButton; -static chip::NXP::App::ButtonBle sBleButton; +/** + * @brief Flag to configure if the app button is enabled. + * + * Enabled by default. + */ +#ifndef CONFIG_APP_BUTTON_ENABLED +#define CONFIG_APP_BUTTON_ENABLED 1 +#endif + +/** + * @brief Flag to configure if the BLE button is enabled. + * + * Enabled by default. + */ +#ifndef CONFIG_BLE_BUTTON_ENABLED +#define CONFIG_BLE_BUTTON_ENABLED 1 +#endif CHIP_ERROR chip::NXP::App::RegisterButtons(void) { ReturnErrorOnFailure(ButtonMgr().Init()); + +#if CONFIG_BLE_BUTTON_ENABLED + static chip::NXP::App::ButtonBle sBleButton; ReturnErrorOnFailure(ButtonMgr().RegisterButton(sBleButton)); +#endif + +#if CONFIG_APP_BUTTON_ENABLED + static chip::NXP::App::ButtonApp sAppButton; ReturnErrorOnFailure(ButtonMgr().RegisterButton(sAppButton)); +#endif return CHIP_NO_ERROR; }