Skip to content

Commit e24703e

Browse files
PavelVPVrlubos
authored andcommitted
samples: bluetooth: event_trigger: Use DT alias to get EGU instance
Use DT_ALIAS and DT_REG_ADDR to extract EGU instance instead of hardcoding instance id in the code. This will simplify porting this sample to other platforms. Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
1 parent a2c70b4 commit e24703e

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
aliases {
9+
egu = &egu0;
10+
};
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
aliases {
9+
egu = &egu0;
10+
};
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/ {
8+
aliases {
9+
egu = &egu0;
10+
};
11+
};

samples/bluetooth/event_trigger/src/main.c

+11-13
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020

2121
#include <hal/nrf_egu.h>
2222

23-
#if defined(DPPIC_PRESENT)
24-
#define SWI_IRQn EGU0_IRQn
25-
#else
26-
#define SWI_IRQn SWI0_IRQn
27-
#endif
23+
#define EGU_NODE DT_ALIAS(egu)
24+
#define NRF_EGU ((NRF_EGU_Type *) DT_REG_ADDR(EGU_NODE))
2825

2926
#define NUM_TRIGGERS (50)
3027
#define INTERVAL_10MS (0x8)
@@ -48,9 +45,9 @@ static const struct bt_data sd[] = {
4845
BT_DATA(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME, sizeof(CONFIG_BT_DEVICE_NAME) - 1),
4946
};
5047

51-
static void egu0_handler(const void *context)
48+
static void egu_handler(const void *context)
5249
{
53-
nrf_egu_event_clear(NRF_EGU0, NRF_EGU_EVENT_TRIGGERED0);
50+
nrf_egu_event_clear(NRF_EGU, NRF_EGU_EVENT_TRIGGERED0);
5451

5552
if (timestamp_log_index < NUM_TRIGGERS) {
5653
k_work_submit(&work);
@@ -83,14 +80,15 @@ static int setup_connection_event_trigger(struct bt_conn *conn, bool enable)
8380
*/
8481
if (enable) {
8582
cmd_params.task_address =
86-
nrf_egu_task_address_get(NRF_EGU0, NRF_EGU_TASK_TRIGGER0);
87-
IRQ_DIRECT_CONNECT(SWI_IRQn, 5, egu0_handler, 0);
88-
nrf_egu_int_enable(NRF_EGU0, NRF_EGU_INT_TRIGGERED0);
89-
NVIC_EnableIRQ(SWI_IRQn);
83+
nrf_egu_task_address_get(NRF_EGU, NRF_EGU_TASK_TRIGGER0);
84+
85+
IRQ_DIRECT_CONNECT(DT_IRQN(EGU_NODE), 5, egu_handler, 0);
86+
nrf_egu_int_enable(NRF_EGU, NRF_EGU_INT_TRIGGERED0);
87+
NVIC_EnableIRQ(DT_IRQN(EGU_NODE));
9088
} else {
9189
cmd_params.task_address = 0;
92-
nrf_egu_int_disable(NRF_EGU0, NRF_EGU_INT_TRIGGERED0);
93-
NVIC_DisableIRQ(SWI_IRQn);
90+
nrf_egu_int_disable(NRF_EGU, NRF_EGU_INT_TRIGGERED0);
91+
NVIC_DisableIRQ(DT_IRQN(EGU_NODE));
9492
}
9593

9694
err = hci_vs_sdc_set_event_start_task(&cmd_params);

0 commit comments

Comments
 (0)