nRF Connect SDK API 0.1.0
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
37#define ESB_DEFAULT_CONFIG \
38 { \
39 .protocol = ESB_PROTOCOL_ESB_DPL, \
40 .mode = ESB_MODE_PTX, \
41 .event_handler = 0, \
42 .bitrate = ESB_BITRATE_2MBPS, \
43 .crc = ESB_CRC_16BIT, \
44 .tx_output_power = 0, \
45 .retransmit_delay = 600, \
46 .retransmit_count = 3, \
47 .tx_mode = ESB_TXMODE_AUTO, \
48 .payload_length = 32, \
49 .selective_auto_ack = false, \
50 .use_fast_ramp_up = false \
51 }
52
57#define ESB_LEGACY_CONFIG \
58 { \
59 .protocol = ESB_PROTOCOL_ESB, \
60 .mode = ESB_MODE_PTX, \
61 .event_handler = 0, \
62 .bitrate = ESB_BITRATE_2MBPS, \
63 .crc = ESB_CRC_8BIT, \
64 .tx_output_power = 0, \
65 .retransmit_delay = 600, \
66 .retransmit_count = 3, \
67 .tx_mode = ESB_TXMODE_AUTO, \
68 .payload_length = 32, \
69 .selective_auto_ack = false, \
70 .use_fast_ramp_up = false \
71 }
72
85#define ESB_CREATE_PAYLOAD(_pipe, ...) \
86 { \
87 .pipe = _pipe, \
88 .length = NUM_VA_ARGS_LESS_1(_pipe, __VA_ARGS__), \
89 .data = { \
90 __VA_ARGS__ \
91 } \
92 }
93
98};
99
105
109 ESB_BITRATE_1MBPS = NRF_RADIO_MODE_NRF_1MBIT,
111 ESB_BITRATE_2MBPS = NRF_RADIO_MODE_NRF_2MBIT,
112
113#if defined(RADIO_MODE_MODE_Nrf_250Kbit)
115 ESB_BITRATE_250KBPS = NRF_RADIO_MODE_NRF_250KBIT,
116#endif /* defined(RADIO_MODE_MODE_Nrf_250Kbit) */
117
119 ESB_BITRATE_1MBPS_BLE = NRF_RADIO_MODE_BLE_1MBIT,
120
121#if defined(RADIO_MODE_MODE_Ble_2Mbit)
123 ESB_BITRATE_2MBPS_BLE = NRF_RADIO_MODE_BLE_2MBIT,
124#endif /* defined(RADIO_MODE_MODE_Ble_2Mbit) */
125
126#if defined(RADIO_MODE_MODE_Nrf_4Mbit0_5)
128 ESB_BITRATE_4MBPS = NRF_RADIO_MODE_NRF_4MBIT_H_0_5,
129#endif /* defined(RADIO_MODE_MODE_Nrf_4Mbit0_5) */
130};
131
134 ESB_CRC_16BIT = RADIO_CRCCNF_LEN_Two,
135 ESB_CRC_8BIT = RADIO_CRCCNF_LEN_One,
136 ESB_CRC_OFF = RADIO_CRCCNF_LEN_Disabled
138
141#if defined(RADIO_TXPOWER_TXPOWER_Pos10dBm) || defined(DOXYGEN)
143 ESB_TX_POWER_10DBM = RADIO_TXPOWER_TXPOWER_Pos10dBm,
144#endif
145#if defined(RADIO_TXPOWER_TXPOWER_Pos9dBm) || defined(DOXYGEN)
147 ESB_TX_POWER_9DBM = RADIO_TXPOWER_TXPOWER_Pos9dBm,
148#endif
149#if defined(RADIO_TXPOWER_TXPOWER_Pos8dBm) || defined(DOXYGEN)
151 ESB_TX_POWER_8DBM = RADIO_TXPOWER_TXPOWER_Pos8dBm,
152#endif
153#if defined(RADIO_TXPOWER_TXPOWER_Pos7dBm) || defined(DOXYGEN)
155 ESB_TX_POWER_7DBM = RADIO_TXPOWER_TXPOWER_Pos7dBm,
156#endif
157#if defined(RADIO_TXPOWER_TXPOWER_Pos6dBm) || defined(DOXYGEN)
159 ESB_TX_POWER_6DBM = RADIO_TXPOWER_TXPOWER_Pos6dBm,
160#endif
161#if defined(RADIO_TXPOWER_TXPOWER_Pos5dBm) || defined(DOXYGEN)
163 ESB_TX_POWER_5DBM = RADIO_TXPOWER_TXPOWER_Pos5dBm,
164#endif
165#if defined(RADIO_TXPOWER_TXPOWER_Pos4dBm) || defined(DOXYGEN)
167 ESB_TX_POWER_4DBM = RADIO_TXPOWER_TXPOWER_Pos4dBm,
168#endif
169#if defined(RADIO_TXPOWER_TXPOWER_Pos3dBm) || defined(DOXYGEN)
171 ESB_TX_POWER_3DBM = RADIO_TXPOWER_TXPOWER_Pos3dBm,
172#endif
173#if defined(RADIO_TXPOWER_TXPOWER_Pos2dBm) || defined(DOXYGEN)
175 ESB_TX_POWER_2DBM = RADIO_TXPOWER_TXPOWER_Pos2dBm,
176#endif
177#if defined(RADIO_TXPOWER_TXPOWER_Pos1dBm) || defined(DOXYGEN)
179 ESB_TX_POWER_1DBM = RADIO_TXPOWER_TXPOWER_Pos1dBm,
180#endif
181#if defined(RADIO_TXPOWER_TXPOWER_0dBm) || defined(DOXYGEN)
183 ESB_TX_POWER_0DBM = RADIO_TXPOWER_TXPOWER_0dBm,
184#endif
185#if defined(RADIO_TXPOWER_TXPOWER_Neg1dBm) || defined(DOXYGEN)
187 ESB_TX_POWER_NEG1DBM = RADIO_TXPOWER_TXPOWER_Neg1dBm,
188#endif
189#if defined(RADIO_TXPOWER_TXPOWER_Neg2dBm) || defined(DOXYGEN)
191 ESB_TX_POWER_NEG2DBM = RADIO_TXPOWER_TXPOWER_Neg2dBm,
192#endif
193#if defined(RADIO_TXPOWER_TXPOWER_Neg3dBm) || defined(DOXYGEN)
195 ESB_TX_POWER_NEG3DBM = RADIO_TXPOWER_TXPOWER_Neg3dBm,
196#endif
197#if defined(RADIO_TXPOWER_TXPOWER_Neg4dBm) || defined(DOXYGEN)
199 ESB_TX_POWER_NEG4DBM = RADIO_TXPOWER_TXPOWER_Neg4dBm,
200#endif
201#if defined(RADIO_TXPOWER_TXPOWER_Neg5dBm) || defined(DOXYGEN)
203 ESB_TX_POWER_NEG5DBM = RADIO_TXPOWER_TXPOWER_Neg5dBm,
204#endif
205#if defined(RADIO_TXPOWER_TXPOWER_Neg6dBm) || defined(DOXYGEN)
207 ESB_TX_POWER_NEG6DBM = RADIO_TXPOWER_TXPOWER_Neg6dBm,
208#endif
209#if defined(RADIO_TXPOWER_TXPOWER_Neg7dBm) || defined(DOXYGEN)
211 ESB_TX_POWER_NEG7DBM = RADIO_TXPOWER_TXPOWER_Neg7dBm,
212#endif
213#if defined(RADIO_TXPOWER_TXPOWER_Neg8dBm) || defined(DOXYGEN)
215 ESB_TX_POWER_NEG8DBM = RADIO_TXPOWER_TXPOWER_Neg8dBm,
216#endif
217#if defined(RADIO_TXPOWER_TXPOWER_Neg9dBm) || defined(DOXYGEN)
219 ESB_TX_POWER_NEG9DBM = RADIO_TXPOWER_TXPOWER_Neg9dBm,
220#endif
221#if defined(RADIO_TXPOWER_TXPOWER_Neg10dBm) || defined(DOXYGEN)
223 ESB_TX_POWER_NEG10DBM = RADIO_TXPOWER_TXPOWER_Neg10dBm,
224#endif
225#if defined(RADIO_TXPOWER_TXPOWER_Neg12dBm) || defined(DOXYGEN)
227 ESB_TX_POWER_NEG12DBM = RADIO_TXPOWER_TXPOWER_Neg12dBm,
228#endif
229#if defined(RADIO_TXPOWER_TXPOWER_Neg14dBm) || defined(DOXYGEN)
231 ESB_TX_POWER_NEG14DBM = RADIO_TXPOWER_TXPOWER_Neg14dBm,
232#endif
233#if defined(RADIO_TXPOWER_TXPOWER_Neg16dBm) || defined(DOXYGEN)
235 ESB_TX_POWER_NEG16DBM = RADIO_TXPOWER_TXPOWER_Neg16dBm,
236#endif
237#if defined(RADIO_TXPOWER_TXPOWER_Neg20dBm) || defined(DOXYGEN)
239 ESB_TX_POWER_NEG20DBM = RADIO_TXPOWER_TXPOWER_Neg20dBm,
240#endif
241#if defined(RADIO_TXPOWER_TXPOWER_Neg26dBm) || defined(DOXYGEN)
243 ESB_TX_POWER_NEG26DBM = RADIO_TXPOWER_TXPOWER_Neg26dBm,
244#endif
245#if defined(RADIO_TXPOWER_TXPOWER_Neg30dBm) || defined(DOXYGEN)
247 ESB_TX_POWER_NEG30DBM = RADIO_TXPOWER_TXPOWER_Neg30dBm,
248#endif
249#if defined(RADIO_TXPOWER_TXPOWER_Neg40dBm) || defined(DOXYGEN)
251 ESB_TX_POWER_NEG40DBM = RADIO_TXPOWER_TXPOWER_Neg40dBm,
252#endif
253#if defined(RADIO_TXPOWER_TXPOWER_Neg46dBm) || defined(DOXYGEN)
255 ESB_TX_POWER_NEG46DBM = RADIO_TXPOWER_TXPOWER_Neg46dBm,
256#endif
257#if defined(RADIO_TXPOWER_TXPOWER_Neg70dBm) || defined(DOXYGEN)
259 ESB_TX_POWER_NEG70DBM = RADIO_TXPOWER_TXPOWER_Neg70dBm,
260#endif
261};
262
279
286
293 uint8_t length;
294 uint8_t pipe;
295 int8_t rssi;
296 uint8_t noack;
300 uint8_t pid;
301 uint8_t data[CONFIG_ESB_MAX_PAYLOAD_LENGTH];
302};
303
305struct esb_evt {
307 uint32_t tx_attempts;
308};
309
311typedef void (*esb_event_handler)(const struct esb_evt *event);
312
318 /* General RF parameters */
335 /* Control settings */
355};
356
363int esb_init(const struct esb_config *config);
364
373int esb_suspend(void);
374
383void esb_disable(void);
384
389bool esb_is_idle(void);
390
403int esb_write_payload(const struct esb_payload *payload);
404
412int esb_read_rx_payload(struct esb_payload *payload);
413
419int esb_start_tx(void);
420
426int esb_start_rx(void);
427
433int esb_stop_rx(void);
434
442int esb_flush_tx(void);
443
449int esb_pop_tx(void);
450
455bool esb_tx_full(void);
456
462int esb_flush_rx(void);
463
471int esb_set_address_length(uint8_t length);
472
480int esb_set_base_address_0(const uint8_t *addr);
481
489int esb_set_base_address_1(const uint8_t *addr);
490
503int esb_set_prefixes(const uint8_t *prefixes, uint8_t num_pipes);
504
518int esb_enable_pipes(uint8_t enable_mask);
519
528int esb_update_prefix(uint8_t pipe, uint8_t prefix);
529
542int esb_set_rf_channel(uint32_t channel);
543
551int esb_get_rf_channel(uint32_t *channel);
552
561int esb_set_tx_power(int8_t tx_output_power);
562
570int esb_set_retransmit_delay(uint16_t delay);
571
583int esb_set_retransmit_count(uint16_t count);
584
592int esb_set_bitrate(enum esb_bitrate bitrate);
593
606int esb_reuse_pid(uint8_t pipe);
607
610#ifdef __cplusplus
611}
612#endif
613
614#endif /* ESB */
int esb_set_retransmit_delay(uint16_t delay)
Set the packet retransmit delay.
esb_mode
Enhanced ShockBurst modes.
Definition: esb.h:101
@ ESB_MODE_PTX
Definition: esb.h:102
@ ESB_MODE_PRX
Definition: esb.h:103
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:264
@ ESB_TXMODE_MANUAL
Definition: esb.h:272
@ ESB_TXMODE_AUTO
Definition: esb.h:268
@ ESB_TXMODE_MANUAL_START
Definition: esb.h:277
int esb_stop_rx(void)
Stop data reception.
esb_crc
Enhanced ShockBurst CRC modes.
Definition: esb.h:133
@ ESB_CRC_OFF
Definition: esb.h:136
@ ESB_CRC_16BIT
Definition: esb.h:134
@ ESB_CRC_8BIT
Definition: esb.h:135
esb_evt_id
Enhanced ShockBurst event IDs.
Definition: esb.h:281
@ ESB_EVENT_TX_SUCCESS
Definition: esb.h:282
@ ESB_EVENT_TX_FAILED
Definition: esb.h:283
@ ESB_EVENT_RX_RECEIVED
Definition: esb.h:284
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:107
@ ESB_BITRATE_1MBPS
Definition: esb.h:109
@ ESB_BITRATE_1MBPS_BLE
Definition: esb.h:119
@ ESB_BITRATE_2MBPS
Definition: esb.h:111
@ ESB_BITRATE_250KBPS
Definition: esb.h:115
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:311
esb_tx_power
Enhanced ShockBurst radio transmission power modes.
Definition: esb.h:140
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:95
@ ESB_PROTOCOL_ESB
Definition: esb.h:96
@ ESB_PROTOCOL_ESB_DPL
Definition: esb.h:97
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:338
esb_event_handler event_handler
Definition: esb.h:317
int8_t tx_output_power
Definition: esb.h:321
enum esb_protocol protocol
Definition: esb.h:315
bool selective_auto_ack
Definition: esb.h:341
enum esb_bitrate bitrate
Definition: esb.h:319
uint16_t retransmit_delay
Definition: esb.h:323
enum esb_crc crc
Definition: esb.h:320
enum esb_mode mode
Definition: esb.h:316
uint16_t retransmit_count
Definition: esb.h:331
enum esb_tx_mode tx_mode
Definition: esb.h:336
bool use_fast_ramp_up
Definition: esb.h:346
Main configuration structure for the module.
Definition: esb.h:314
uint32_t tx_attempts
Definition: esb.h:307
enum esb_evt_id evt_id
Definition: esb.h:306
Enhanced ShockBurst event.
Definition: esb.h:305
uint8_t noack
Definition: esb.h:296
uint8_t data[CONFIG_ESB_MAX_PAYLOAD_LENGTH]
Definition: esb.h:301
uint8_t pid
Definition: esb.h:300
uint8_t length
Definition: esb.h:293
int8_t rssi
Definition: esb.h:295
uint8_t pipe
Definition: esb.h:294
Enhanced ShockBurst payload.
Definition: esb.h:292