nRF Connect SDK API 2.7.99
Loading...
Searching...
No Matches
esb.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef __ESB_H
8#define __ESB_H
9
10#include <stdbool.h>
11#include <errno.h>
12
13#include <nrf.h>
14#include <hal/nrf_radio.h>
15
16#include <zephyr/sys/util.h>
17#include <zephyr/types.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
36#define ESB_DEFAULT_CONFIG \
37 { \
38 .protocol = ESB_PROTOCOL_ESB_DPL, \
39 .mode = ESB_MODE_PTX, \
40 .event_handler = 0, \
41 .bitrate = ESB_BITRATE_2MBPS, \
42 .crc = ESB_CRC_16BIT, \
43 .tx_output_power = 0, \
44 .retransmit_delay = 600, \
45 .retransmit_count = 3, \
46 .tx_mode = ESB_TXMODE_AUTO, \
47 .payload_length = 32, \
48 .selective_auto_ack = false, \
49 .use_fast_ramp_up = false \
50 }
51
56#define ESB_LEGACY_CONFIG \
57 { \
58 .protocol = ESB_PROTOCOL_ESB, \
59 .mode = ESB_MODE_PTX, \
60 .event_handler = 0, \
61 .bitrate = ESB_BITRATE_2MBPS, \
62 .crc = ESB_CRC_8BIT, \
63 .tx_output_power = 0, \
64 .retransmit_delay = 600, \
65 .retransmit_count = 3, \
66 .tx_mode = ESB_TXMODE_AUTO, \
67 .payload_length = 32, \
68 .selective_auto_ack = false, \
69 .use_fast_ramp_up = false \
70 }
71
84#define ESB_CREATE_PAYLOAD(_pipe, ...) \
85 { \
86 .pipe = _pipe, \
87 .length = NUM_VA_ARGS_LESS_1(_pipe, __VA_ARGS__), \
88 .data = { \
89 __VA_ARGS__ \
90 } \
91 }
92
97};
98
104
108 ESB_BITRATE_1MBPS = NRF_RADIO_MODE_NRF_1MBIT,
110 ESB_BITRATE_2MBPS = NRF_RADIO_MODE_NRF_2MBIT,
111
112#if defined(RADIO_MODE_MODE_Nrf_250Kbit)
114 ESB_BITRATE_250KBPS = NRF_RADIO_MODE_NRF_250KBIT,
115#endif /* defined(RADIO_MODE_MODE_Nrf_250Kbit) */
116
118 ESB_BITRATE_1MBPS_BLE = NRF_RADIO_MODE_BLE_1MBIT,
119
120#if defined(RADIO_MODE_MODE_Ble_2Mbit)
122 ESB_BITRATE_2MBPS_BLE = NRF_RADIO_MODE_BLE_2MBIT,
123#endif /* defined(RADIO_MODE_MODE_Ble_2Mbit) */
124
125#if defined(RADIO_MODE_MODE_Nrf_4Mbit0_5)
127 ESB_BITRATE_4MBPS = NRF_RADIO_MODE_NRF_4MBIT_H_0_5,
128#endif /* defined(RADIO_MODE_MODE_Nrf_4Mbit0_5) */
129};
130
133 ESB_CRC_16BIT = RADIO_CRCCNF_LEN_Two,
134 ESB_CRC_8BIT = RADIO_CRCCNF_LEN_One,
135 ESB_CRC_OFF = RADIO_CRCCNF_LEN_Disabled
137
140#if defined(RADIO_TXPOWER_TXPOWER_Pos10dBm) || defined(DOXYGEN)
142 ESB_TX_POWER_10DBM = RADIO_TXPOWER_TXPOWER_Pos10dBm,
143#endif
144#if defined(RADIO_TXPOWER_TXPOWER_Pos9dBm) || defined(DOXYGEN)
146 ESB_TX_POWER_9DBM = RADIO_TXPOWER_TXPOWER_Pos9dBm,
147#endif
148#if defined(RADIO_TXPOWER_TXPOWER_Pos8dBm) || defined(DOXYGEN)
150 ESB_TX_POWER_8DBM = RADIO_TXPOWER_TXPOWER_Pos8dBm,
151#endif
152#if defined(RADIO_TXPOWER_TXPOWER_Pos7dBm) || defined(DOXYGEN)
154 ESB_TX_POWER_7DBM = RADIO_TXPOWER_TXPOWER_Pos7dBm,
155#endif
156#if defined(RADIO_TXPOWER_TXPOWER_Pos6dBm) || defined(DOXYGEN)
158 ESB_TX_POWER_6DBM = RADIO_TXPOWER_TXPOWER_Pos6dBm,
159#endif
160#if defined(RADIO_TXPOWER_TXPOWER_Pos5dBm) || defined(DOXYGEN)
162 ESB_TX_POWER_5DBM = RADIO_TXPOWER_TXPOWER_Pos5dBm,
163#endif
164#if defined(RADIO_TXPOWER_TXPOWER_Pos4dBm) || defined(DOXYGEN)
166 ESB_TX_POWER_4DBM = RADIO_TXPOWER_TXPOWER_Pos4dBm,
167#endif
168#if defined(RADIO_TXPOWER_TXPOWER_Pos3dBm) || defined(DOXYGEN)
170 ESB_TX_POWER_3DBM = RADIO_TXPOWER_TXPOWER_Pos3dBm,
171#endif
172#if defined(RADIO_TXPOWER_TXPOWER_Pos2dBm) || defined(DOXYGEN)
174 ESB_TX_POWER_2DBM = RADIO_TXPOWER_TXPOWER_Pos2dBm,
175#endif
176#if defined(RADIO_TXPOWER_TXPOWER_Pos1dBm) || defined(DOXYGEN)
178 ESB_TX_POWER_1DBM = RADIO_TXPOWER_TXPOWER_Pos1dBm,
179#endif
180#if defined(RADIO_TXPOWER_TXPOWER_0dBm) || defined(DOXYGEN)
182 ESB_TX_POWER_0DBM = RADIO_TXPOWER_TXPOWER_0dBm,
183#endif
184#if defined(RADIO_TXPOWER_TXPOWER_Neg1dBm) || defined(DOXYGEN)
186 ESB_TX_POWER_NEG1DBM = RADIO_TXPOWER_TXPOWER_Neg1dBm,
187#endif
188#if defined(RADIO_TXPOWER_TXPOWER_Neg2dBm) || defined(DOXYGEN)
190 ESB_TX_POWER_NEG2DBM = RADIO_TXPOWER_TXPOWER_Neg2dBm,
191#endif
192#if defined(RADIO_TXPOWER_TXPOWER_Neg3dBm) || defined(DOXYGEN)
194 ESB_TX_POWER_NEG3DBM = RADIO_TXPOWER_TXPOWER_Neg3dBm,
195#endif
196#if defined(RADIO_TXPOWER_TXPOWER_Neg4dBm) || defined(DOXYGEN)
198 ESB_TX_POWER_NEG4DBM = RADIO_TXPOWER_TXPOWER_Neg4dBm,
199#endif
200#if defined(RADIO_TXPOWER_TXPOWER_Neg5dBm) || defined(DOXYGEN)
202 ESB_TX_POWER_NEG5DBM = RADIO_TXPOWER_TXPOWER_Neg5dBm,
203#endif
204#if defined(RADIO_TXPOWER_TXPOWER_Neg6dBm) || defined(DOXYGEN)
206 ESB_TX_POWER_NEG6DBM = RADIO_TXPOWER_TXPOWER_Neg6dBm,
207#endif
208#if defined(RADIO_TXPOWER_TXPOWER_Neg7dBm) || defined(DOXYGEN)
210 ESB_TX_POWER_NEG7DBM = RADIO_TXPOWER_TXPOWER_Neg7dBm,
211#endif
212#if defined(RADIO_TXPOWER_TXPOWER_Neg8dBm) || defined(DOXYGEN)
214 ESB_TX_POWER_NEG8DBM = RADIO_TXPOWER_TXPOWER_Neg8dBm,
215#endif
216#if defined(RADIO_TXPOWER_TXPOWER_Neg9dBm) || defined(DOXYGEN)
218 ESB_TX_POWER_NEG9DBM = RADIO_TXPOWER_TXPOWER_Neg9dBm,
219#endif
220#if defined(RADIO_TXPOWER_TXPOWER_Neg10dBm) || defined(DOXYGEN)
222 ESB_TX_POWER_NEG10DBM = RADIO_TXPOWER_TXPOWER_Neg10dBm,
223#endif
224#if defined(RADIO_TXPOWER_TXPOWER_Neg12dBm) || defined(DOXYGEN)
226 ESB_TX_POWER_NEG12DBM = RADIO_TXPOWER_TXPOWER_Neg12dBm,
227#endif
228#if defined(RADIO_TXPOWER_TXPOWER_Neg14dBm) || defined(DOXYGEN)
230 ESB_TX_POWER_NEG14DBM = RADIO_TXPOWER_TXPOWER_Neg14dBm,
231#endif
232#if defined(RADIO_TXPOWER_TXPOWER_Neg16dBm) || defined(DOXYGEN)
234 ESB_TX_POWER_NEG16DBM = RADIO_TXPOWER_TXPOWER_Neg16dBm,
235#endif
236#if defined(RADIO_TXPOWER_TXPOWER_Neg20dBm) || defined(DOXYGEN)
238 ESB_TX_POWER_NEG20DBM = RADIO_TXPOWER_TXPOWER_Neg20dBm,
239#endif
240#if defined(RADIO_TXPOWER_TXPOWER_Neg26dBm) || defined(DOXYGEN)
242 ESB_TX_POWER_NEG26DBM = RADIO_TXPOWER_TXPOWER_Neg26dBm,
243#endif
244#if defined(RADIO_TXPOWER_TXPOWER_Neg30dBm) || defined(DOXYGEN)
246 ESB_TX_POWER_NEG30DBM = RADIO_TXPOWER_TXPOWER_Neg30dBm,
247#endif
248#if defined(RADIO_TXPOWER_TXPOWER_Neg40dBm) || defined(DOXYGEN)
250 ESB_TX_POWER_NEG40DBM = RADIO_TXPOWER_TXPOWER_Neg40dBm,
251#endif
252#if defined(RADIO_TXPOWER_TXPOWER_Neg46dBm) || defined(DOXYGEN)
254 ESB_TX_POWER_NEG46DBM = RADIO_TXPOWER_TXPOWER_Neg46dBm,
255#endif
256#if defined(RADIO_TXPOWER_TXPOWER_Neg70dBm) || defined(DOXYGEN)
258 ESB_TX_POWER_NEG70DBM = RADIO_TXPOWER_TXPOWER_Neg70dBm,
259#endif
260};
261
278
285
292 uint8_t length;
293 uint8_t pipe;
294 int8_t rssi;
295 uint8_t noack;
299 uint8_t pid;
300 uint8_t data[CONFIG_ESB_MAX_PAYLOAD_LENGTH];
301};
302
304struct esb_evt {
306 uint32_t tx_attempts;
307};
308
310typedef void (*esb_event_handler)(const struct esb_evt *event);
311
317 /* General RF parameters */
334 /* Control settings */
354};
355
362int esb_init(const struct esb_config *config);
363
372int esb_suspend(void);
373
382void esb_disable(void);
383
388bool esb_is_idle(void);
389
402int esb_write_payload(const struct esb_payload *payload);
403
411int esb_read_rx_payload(struct esb_payload *payload);
412
418int esb_start_tx(void);
419
425int esb_start_rx(void);
426
432int esb_stop_rx(void);
433
441int esb_flush_tx(void);
442
448int esb_pop_tx(void);
449
454bool esb_tx_full(void);
455
461int esb_flush_rx(void);
462
470int esb_set_address_length(uint8_t length);
471
479int esb_set_base_address_0(const uint8_t *addr);
480
488int esb_set_base_address_1(const uint8_t *addr);
489
502int esb_set_prefixes(const uint8_t *prefixes, uint8_t num_pipes);
503
517int esb_enable_pipes(uint8_t enable_mask);
518
527int esb_update_prefix(uint8_t pipe, uint8_t prefix);
528
541int esb_set_rf_channel(uint32_t channel);
542
550int esb_get_rf_channel(uint32_t *channel);
551
560int esb_set_tx_power(int8_t tx_output_power);
561
569int esb_set_retransmit_delay(uint16_t delay);
570
582int esb_set_retransmit_count(uint16_t count);
583
591int esb_set_bitrate(enum esb_bitrate bitrate);
592
605int esb_reuse_pid(uint8_t pipe);
606
609#ifdef __cplusplus
610}
611#endif
612
613#endif /* ESB */
int esb_set_retransmit_delay(uint16_t delay)
Set the packet retransmit delay.
esb_mode
Enhanced ShockBurst modes.
Definition: esb.h:100
@ ESB_MODE_PTX
Definition: esb.h:101
@ ESB_MODE_PRX
Definition: esb.h:102
int esb_start_rx(void)
Start receiving data.
int esb_set_base_address_0(const uint8_t *addr)
Set the base address for pipe 0.
int esb_read_rx_payload(struct esb_payload *payload)
Read a payload.
int esb_set_prefixes(const uint8_t *prefixes, uint8_t num_pipes)
Set the number of pipes and the pipe prefix addresses.
int esb_start_tx(void)
Start transmitting data.
esb_tx_mode
Enhanced ShockBurst transmission modes.
Definition: esb.h:263
@ ESB_TXMODE_MANUAL
Definition: esb.h:271
@ ESB_TXMODE_AUTO
Definition: esb.h:267
@ ESB_TXMODE_MANUAL_START
Definition: esb.h:276
int esb_stop_rx(void)
Stop data reception.
esb_crc
Enhanced ShockBurst CRC modes.
Definition: esb.h:132
@ ESB_CRC_OFF
Definition: esb.h:135
@ ESB_CRC_16BIT
Definition: esb.h:133
@ ESB_CRC_8BIT
Definition: esb.h:134
esb_evt_id
Enhanced ShockBurst event IDs.
Definition: esb.h:280
@ ESB_EVENT_TX_SUCCESS
Definition: esb.h:281
@ ESB_EVENT_TX_FAILED
Definition: esb.h:282
@ ESB_EVENT_RX_RECEIVED
Definition: esb.h:283
int esb_update_prefix(uint8_t pipe, uint8_t prefix)
Update pipe prefix.
int esb_set_tx_power(int8_t tx_output_power)
Set the radio output power.
int esb_set_address_length(uint8_t length)
Set the length of the address.
esb_bitrate
Enhanced ShockBurst bitrate modes.
Definition: esb.h:106
@ ESB_BITRATE_1MBPS
Definition: esb.h:108
@ ESB_BITRATE_1MBPS_BLE
Definition: esb.h:118
@ ESB_BITRATE_2MBPS
Definition: esb.h:110
@ ESB_BITRATE_250KBPS
Definition: esb.h:114
int esb_write_payload(const struct esb_payload *payload)
Write a payload for transmission or acknowledgement.
int esb_set_rf_channel(uint32_t channel)
Set the channel to use for the radio.
int esb_set_bitrate(enum esb_bitrate bitrate)
Set the radio bitrate.
void(* esb_event_handler)(const struct esb_evt *event)
Event handler prototype.
Definition: esb.h:310
esb_tx_power
Enhanced ShockBurst radio transmission power modes.
Definition: esb.h:139
bool esb_tx_full(void)
Check if there is some free space left in TX FIFO.
int esb_reuse_pid(uint8_t pipe)
Reuse a packet ID for a specific pipe.
int esb_set_retransmit_count(uint16_t count)
Set the number of retransmission attempts.
int esb_suspend(void)
Suspend the Enhanced ShockBurst module.
int esb_flush_tx(void)
Flush the TX buffer.
bool esb_is_idle(void)
Check if the Enhanced ShockBurst module is idle.
int esb_pop_tx(void)
Pop the first item from the TX buffer.
esb_protocol
Enhanced ShockBurst protocols.
Definition: esb.h:94
@ ESB_PROTOCOL_ESB
Definition: esb.h:95
@ ESB_PROTOCOL_ESB_DPL
Definition: esb.h:96
int esb_flush_rx(void)
Flush the RX buffer.
int esb_get_rf_channel(uint32_t *channel)
Get the current radio channel.
void esb_disable(void)
Disable the Enhanced ShockBurst module.
int esb_set_base_address_1(const uint8_t *addr)
Set the base address for pipe 1 to pipe 7.
int esb_init(const struct esb_config *config)
Initialize the Enhanced ShockBurst module.
int esb_enable_pipes(uint8_t enable_mask)
Enable select pipes.
uint8_t payload_length
Definition: esb.h:337
esb_event_handler event_handler
Definition: esb.h:316
int8_t tx_output_power
Definition: esb.h:320
enum esb_protocol protocol
Definition: esb.h:314
bool selective_auto_ack
Definition: esb.h:340
enum esb_bitrate bitrate
Definition: esb.h:318
uint16_t retransmit_delay
Definition: esb.h:322
enum esb_crc crc
Definition: esb.h:319
enum esb_mode mode
Definition: esb.h:315
uint16_t retransmit_count
Definition: esb.h:330
enum esb_tx_mode tx_mode
Definition: esb.h:335
bool use_fast_ramp_up
Definition: esb.h:345
Main configuration structure for the module.
Definition: esb.h:313
uint32_t tx_attempts
Definition: esb.h:306
enum esb_evt_id evt_id
Definition: esb.h:305
Enhanced ShockBurst event.
Definition: esb.h:304
uint8_t noack
Definition: esb.h:295
uint8_t data[CONFIG_ESB_MAX_PAYLOAD_LENGTH]
Definition: esb.h:300
uint8_t pid
Definition: esb.h:299
uint8_t length
Definition: esb.h:292
int8_t rssi
Definition: esb.h:294
uint8_t pipe
Definition: esb.h:293
Enhanced ShockBurst payload.
Definition: esb.h:291