Skip to content

Commit fd54558

Browse files
nika-nordicmasz-nordic
authored andcommitted
samples: peripheral: 802154_phy_test: align to nrfx_gpiote changes
GPIOTE driver instances are no longer defined within nrfx. Signed-off-by: Nikodem Kastelik <[email protected]>
1 parent 3f6b6d2 commit fd54558

File tree

2 files changed

+25
-36
lines changed

2 files changed

+25
-36
lines changed

samples/peripheral/802154_phy_test/src/periph_proc.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#if IS_ENABLED(CONFIG_PTT_CLK_OUT)
2626
#include <nrfx_gpiote.h>
27+
#include <gpiote_nrfx.h>
2728
#endif /* IS_ENABLED(CONFIG_PTT_CLK_OUT) */
2829

2930
#if defined(CONFIG_PTT_CACHE_MGMT)
@@ -52,26 +53,18 @@ LOG_MODULE_REGISTER(periph);
5253
static nrfx_timer_t clk_timer = NRFX_TIMER_INSTANCE(NRF_TIMER_INST_GET(PTT_CLK_TIMER));
5354

5455
#define GPIOTE_NODE(gpio_node) DT_PHANDLE(gpio_node, gpiote_instance)
55-
#define GPIOTE_INST_AND_COMMA(gpio_node) \
56-
[DT_PROP(gpio_node, port)] = \
57-
NRFX_GPIOTE_INSTANCE(DT_PROP(GPIOTE_NODE(gpio_node), instance)),
56+
#define GPIOTE_INST_AND_COMMA(gpio_node) [DT_PROP(gpio_node, port)] = \
57+
COND_CODE_1(DT_NODE_HAS_PROP(gpio_node, gpiote_instance), \
58+
(&GPIOTE_NRFX_INST_BY_NODE(GPIOTE_NODE(gpio_node))), \
59+
(NULL)),
5860

59-
#define COND_GPIOTE_INST_AND_COMMA(gpio_node) \
60-
COND_CODE_1(DT_NODE_HAS_PROP(gpio_node, gpiote_instance), \
61-
(GPIOTE_INST_AND_COMMA(gpio_node)), \
62-
())
63-
64-
static const nrfx_gpiote_t gpiote_inst[GPIO_COUNT] = {
65-
DT_FOREACH_STATUS_OKAY(nordic_nrf_gpio, COND_GPIOTE_INST_AND_COMMA)
61+
static nrfx_gpiote_t * const gpiote_inst[GPIO_COUNT] = {
62+
DT_FOREACH_STATUS_OKAY(nordic_nrf_gpio, GPIOTE_INST_AND_COMMA)
6663
};
6764

68-
#define NRF_GPIOTE_FOR_GPIO(idx) &gpiote_inst[idx]
69-
#define NRF_GPIOTE_FOR_PSEL(psel) &gpiote_inst[psel >> 5]
65+
#define NRF_GPIOTE_FOR_GPIO(idx) gpiote_inst[idx]
66+
#define NRF_GPIOTE_FOR_PSEL(psel) gpiote_inst[NRF_PIN_NUMBER_TO_PORT(psel)]
7067

71-
static inline bool gpiote_is_valid(const nrfx_gpiote_t *gpiote)
72-
{
73-
return gpiote->p_reg != NULL;
74-
}
7568
#endif /* IS_ENABLED(CONFIG_PTT_CLK_OUT) */
7669

7770
#define CLOCK_NODE DT_INST(0, nordic_nrf_clock)
@@ -100,7 +93,7 @@ void periph_init(void)
10093
int ret;
10194

10295
#if IS_ENABLED(CONFIG_PTT_CLK_OUT)
103-
nrfx_err_t err_code;
96+
int err_code;
10497

10598
uint32_t base_frequency = NRF_TIMER_BASE_FREQUENCY_GET(clk_timer.p_reg);
10699
nrfx_timer_config_t clk_timer_cfg = NRFX_TIMER_DEFAULT_CONFIG(base_frequency);
@@ -109,15 +102,15 @@ void periph_init(void)
109102
NRFX_ASSERT(err_code);
110103

111104
for (int i = 0; i < GPIO_COUNT; ++i) {
112-
const nrfx_gpiote_t *gpiote = NRF_GPIOTE_FOR_GPIO(i);
105+
nrfx_gpiote_t *gpiote = NRF_GPIOTE_FOR_GPIO(i);
113106

114-
if (!gpiote_is_valid(gpiote)) {
107+
if (gpiote == NULL) {
115108
continue;
116109
}
117110

118111
if (!nrfx_gpiote_init_check(gpiote)) {
119112
err_code = nrfx_gpiote_init(gpiote, 0);
120-
NRFX_ASSERT(err_code);
113+
__ASSERT_NO_MSG(err_code == 0);
121114
}
122115
}
123116
#endif
@@ -144,10 +137,10 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
144137
#if IS_ENABLED(CONFIG_PTT_CLK_OUT)
145138
uint32_t compare_evt_addr;
146139
uint32_t tep;
147-
nrfx_err_t err;
148-
const nrfx_gpiote_t *gpiote = NRF_GPIOTE_FOR_PSEL(pin);
140+
int err;
141+
nrfx_gpiote_t *gpiote = NRF_GPIOTE_FOR_PSEL(pin);
149142

150-
if (!nrf_gpio_pin_present_check(pin) || !gpiote_is_valid(gpiote)) {
143+
if (!nrf_gpio_pin_present_check(pin) || (gpiote == NULL)) {
151144
return false;
152145
}
153146

@@ -156,8 +149,8 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
156149
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
157150

158151
err = nrfx_gpiote_channel_alloc(gpiote, &task_channel);
159-
if (err != NRFX_SUCCESS) {
160-
LOG_ERR("nrfx_gpiote_channel_alloc error: %08x", err);
152+
if (err != 0) {
153+
LOG_ERR("nrfx_gpiote_channel_alloc error: %d", err);
161154
return false;
162155
}
163156

@@ -172,8 +165,8 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
172165
* CLR will turn it off and OUT will toggle it.
173166
*/
174167
err = nrfx_gpiote_output_configure(gpiote, pin, &config, &out_config);
175-
if (err != NRFX_SUCCESS) {
176-
LOG_ERR("nrfx_gpiote_output_configure error: %08x", err);
168+
if (err != 0) {
169+
LOG_ERR("nrfx_gpiote_output_configure error: %d", err);
177170
return false;
178171
}
179172

@@ -206,8 +199,8 @@ bool ptt_clk_out_ext(uint8_t pin, bool mode)
206199
nrfx_gpiote_pin_uninit(gpiote, pin);
207200
err = nrfx_gpiote_channel_free(gpiote, task_channel);
208201

209-
if (err != NRFX_SUCCESS) {
210-
LOG_ERR("Failed to disable GPIOTE channel, error: %08x", err);
202+
if (err != 0) {
203+
LOG_ERR("Failed to disable GPIOTE channel, error: %d", err);
211204
return false;
212205
}
213206
}

samples/peripheral/802154_phy_test/src/rf_proc.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#if IS_ENABLED(CONFIG_PTT_ANTENNA_DIVERSITY)
1515
#include <nrfx_gpiote.h>
16+
#include <gpiote_nrfx.h>
1617
#endif /* IS_ENABLED(CONFIG_PTT_ANTENNA_DIVERSITY) */
1718

1819
#include <helpers/nrfx_gppi.h>
@@ -34,10 +35,6 @@ static struct rf_rx_pkt_s rf_rx_pool[RF_RX_POOL_N];
3435
static struct rf_rx_pkt_s ack_packet;
3536
static uint8_t temp_tx_pkt[RF_PSDU_MAX_SIZE];
3637

37-
#ifdef CONFIG_PTT_ANTENNA_DIVERSITY
38-
static const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(0);
39-
#endif
40-
4138
static inline void rf_rx_pool_init(void);
4239
static void rf_rx_pool_clear(void);
4340

@@ -141,7 +138,7 @@ void rf_uninit(void)
141138
#if CONFIG_PTT_ANTENNA_DIVERSITY
142139
static void configure_antenna_diversity(void)
143140
{
144-
uint8_t gpiote_channel;
141+
nrfx_gpiote_t *gpiote = &GPIOTE_NRFX_INST_BY_NODE(DT_NODELABEL(gpiote0));
145142
NRF_TIMER_Type *ad_timer = NRF_TIMER3;
146143

147144
nrf_802154_sl_ant_div_cfg_t cfg = {
@@ -151,8 +148,7 @@ static void configure_antenna_diversity(void)
151148
};
152149

153150
(void)nrfx_gppi_channel_alloc(0 ,&cfg.ppi_ch);
154-
nrfx_gpiote_channel_alloc(&gpiote, &gpiote_channel);
155-
cfg.gpiote_ch = gpiote_channel;
151+
(void)nrfx_gpiote_channel_alloc(gpiote, &cfg.gpiote_ch);
156152
nrf_802154_sl_ant_div_mode_t ant_div_auto = 0x02;
157153

158154
nrf_802154_antenna_diversity_config_set(&cfg);

0 commit comments

Comments
 (0)