Skip to content

Commit

Permalink
samples: matter: Unification of events, buttons and LEDs
Browse files Browse the repository at this point in the history
This commit unifies events, buttons and LEDs for all Matter
samples.

Changelog in this commit:

- Separated Events to the system-specific and application-specific.
- Created EventManager module which is responsible for posting and
dispatching events.
- Created the common board configuration file (board_config.h)
that contains all board definitions, which can be overwritten in
the app_config.h file in the sample directory.
- Created the common board_const.h file that contains all constant
definitions of timeouts and LED blinking intervals.
Those definitions are the same for all samples and boards.
- Created the BoardInterface module in board_interface.c/.h files.
The BoardInterface module:
	- Initializes LEDs and buttons on the DK, taking
into account the number of LEDs and buttons on the DK.
	- Manages LEDs and buttons operations.
	- Manages Matter Identify service.
	- Manages to start Bluetooth LE Advertising using a button.
	- Exposes a button callback which can be used in the
Application code. Users have 3 or 1 available buttons and LEDs
depending on the availability on the DK.
	- Manages the factory reset service.
- Aligned Matter Lock sample to all changes.
	- Aligned Lock operations after clicking the button.
	- Aligned WiFi-Thread switching.
- Limitations:
	- Events cannot be called directly from the Timer timeout
event context.

Signed-off-by: Arkadiusz Balys <[email protected]>
  • Loading branch information
ArekBalysNordic committed Dec 1, 2023
1 parent 3e47421 commit 6840e62
Show file tree
Hide file tree
Showing 17 changed files with 841 additions and 464 deletions.
73 changes: 73 additions & 0 deletions samples/matter/common/src/board_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#pragma once

#include <zephyr/devicetree.h>
#include <dk_buttons_and_leds.h>

/* Override application configuration */
#include "app_config.h"

#define LEDS_NODE_ID DT_PATH(leds)
#define BUTTONS_NODE_ID DT_PATH(buttons)
#define INCREMENT_BY_ONE(button_or_led) +1
#define NUMBER_OF_LEDS (0 DT_FOREACH_CHILD(LEDS_NODE_ID, INCREMENT_BY_ONE))
#define NUMBER_OF_BUTTONS (0 DT_FOREACH_CHILD(BUTTONS_NODE_ID, INCREMENT_BY_ONE))

/* Basic Identify Endpoint */
#ifndef IDENTIFY_ENDPOINT
#define IDENTIFY_ENDPOINT 1
#endif

/* User configurable BUTTONS */
#ifndef FUNCTION_BUTTON
#define FUNCTION_BUTTON DK_BTN1
#endif
#ifndef APPLICATION_BUTTON
#define APPLICATION_BUTTON DK_BTN2
#endif
/* User buttons 1 & 2 are available only on DKs that have 4 buttons located on the board */
#if NUMBER_OF_BUTTONS == 4
#ifndef USER_BUTTON_1
#define USER_BUTTON_1 DK_BTN3
#endif
#ifndef USER_BUTTON_2
#define USER_BUTTON_2 DK_BTN4
#endif
#endif

/* User configurable LEDS */
#ifndef SYSTEM_STATE_LED
#define SYSTEM_STATE_LED DK_LED1
#endif
#ifndef APPLICATION_STATE_LED
#define APPLICATION_STATE_LED DK_LED2
#endif
/* User leds 1 & 2 are available only on DKs that have 4 buttons located on the board */
#if NUMBER_OF_LEDS == 4
#ifndef USER_LED_1
#define USER_LED_1 DK_LED3
#endif
#ifndef USER_LED_2
#define USER_LED_2 DK_LED4
#endif
#endif

/* Non-configurable Consts */
#define FUNCTION_BUTTON_MASK BIT(FUNCTION_BUTTON)
#define APPLICATION_BUTTON_MASK BIT(APPLICATION_BUTTON)
#if NUMBER_OF_LEDS == 4
#define USER_BUTTON_1_MASK BIT(USER_BUTTON_1)
#define USER_BUTTON_2_MASK BIT(USER_BUTTON_2)
#endif

#if NUMBER_OF_BUTTONS == 4
#define BLUETOOTH_ADV_BUTTON USER_BUTTON_2
#else
#define BLUETOOTH_ADV_BUTTON APPLICATION_BUTTON
#endif
#define BLUETOOTH_ADV_BUTTON_MASK BIT(BLUETOOTH_ADV_BUTTON)
42 changes: 42 additions & 0 deletions samples/matter/common/src/board_consts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#pragma once

#include <cstdint>

namespace FactoryResetConsts
{
constexpr uint32_t kFactoryResetTriggerTimeout = 3000;
constexpr uint32_t kFactoryResetCancelWindowTimeout = 3000;
} /* namespace FactoryResetConsts */

namespace AdvertisingConsts
{
#if NUMBER_OF_BUTTONS == 2
constexpr uint32_t kAdvertisingTriggerTimeout = 3000;
#endif
} // namespace AdvertisingConsts

namespace LedConsts
{
constexpr uint32_t kBlinkRate_ms{ 500 };
constexpr uint32_t kIdentifyBlinkRate_ms{ 500 };
namespace StatusLed
{
namespace BleConnected
{
constexpr uint32_t kOn_ms{ 100 };
constexpr uint32_t kOff_ms{ kOn_ms };
} /* namespace BleConnected */
namespace Disconnected
{
constexpr uint32_t kOn_ms{ 50 };
constexpr uint32_t kOff_ms{ 950 };
} /* namespace Disconnected */

} /* namespace StatusLed */
} /* namespace LedConsts */
Loading

0 comments on commit 6840e62

Please sign in to comment.