123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- #ifndef __NRF_ESB_H
- #define __NRF_ESB_H
- #include <stdbool.h>
- #include <stdint.h>
- #include "nrf.h"
- #include "app_util.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #ifndef NRF52840_XXAA
- #define DEBUGPIN1 12
- #define DEBUGPIN2 13
- #define DEBUGPIN3 14
- #define DEBUGPIN4 15
- #else
- #define DEBUGPIN1 24
- #define DEBUGPIN2 25
- #define DEBUGPIN3 26
- #define DEBUGPIN4 27
- #endif
- #ifdef NRF_ESB_DEBUG
- #define DEBUG_PIN_SET(a) (NRF_GPIO->OUTSET = (1 << (a)))
- #define DEBUG_PIN_CLR(a) (NRF_GPIO->OUTCLR = (1 << (a)))
- #else
- #define DEBUG_PIN_SET(a)
- #define DEBUG_PIN_CLR(a)
- #endif
-
- #ifndef NRF_ESB_MAX_PAYLOAD_LENGTH
- #define NRF_ESB_MAX_PAYLOAD_LENGTH 32
- #endif
- #define NRF_ESB_TX_FIFO_SIZE 8
- #define NRF_ESB_RX_FIFO_SIZE 8
- STATIC_ASSERT(NRF_ESB_MAX_PAYLOAD_LENGTH <= 252);
- #define NRF_ESB_SYS_TIMER NRF_TIMER2
- #define NRF_ESB_SYS_TIMER_IRQ_Handler TIMER2_IRQHandler
- #define NRF_ESB_PPI_TIMER_START 10
- #define NRF_ESB_PPI_TIMER_STOP 11
- #define NRF_ESB_PPI_RX_TIMEOUT 12
- #define NRF_ESB_PPI_TX_START 13
- #ifndef NRF_ESB_PIPE_COUNT
- #define NRF_ESB_PIPE_COUNT 8
- #endif
- STATIC_ASSERT(NRF_ESB_PIPE_COUNT <= 8);
- #ifdef NRF52832_XXAA
- #define NRF_ESB_PPI_BUGFIX1 9
- #define NRF_ESB_PPI_BUGFIX2 8
- #define NRF_ESB_PPI_BUGFIX3 7
- #define NRF_ESB_BUGFIX_TIMER NRF_TIMER3
- #define NRF_ESB_BUGFIX_TIMER_IRQn TIMER3_IRQn
- #define NRF_ESB_BUGFIX_TIMER_IRQHandler TIMER3_IRQHandler
- #endif
- #define NRF_ESB_INT_TX_SUCCESS_MSK 0x01
- #define NRF_ESB_INT_TX_FAILED_MSK 0x02
- #define NRF_ESB_INT_RX_DR_MSK 0x04
- #define NRF_ESB_PID_RESET_VALUE 0xFF
- #define NRF_ESB_PID_MAX 3
- #define NRF_ESB_CRC_RESET_VALUE 0xFFFF
- #define ESB_EVT_IRQ SWI0_IRQn
- #define ESB_EVT_IRQHandler SWI0_IRQHandler
- #if defined(NRF52_SERIES)
- #define ESB_IRQ_PRIORITY_MSK 0x07
- #else
- #define ESB_IRQ_PRIORITY_MSK 0x03
- #endif
- #define NRF_ESB_ADDR_DEFAULT \
- { \
- .base_addr_p0 = { 0xE7, 0xE7, 0xE7, 0xE7 }, \
- .base_addr_p1 = { 0xC2, 0xC2, 0xC2, 0xC2 }, \
- .pipe_prefixes = { 0xE7, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8 }, \
- .addr_length = 5, \
- .num_pipes = NRF_ESB_PIPE_COUNT, \
- .rf_channel = 2, \
- .rx_pipes_enabled = 0xFF \
- }
- #define NRF_ESB_DEFAULT_CONFIG {.protocol = NRF_ESB_PROTOCOL_ESB_DPL, \
- .mode = NRF_ESB_MODE_PTX, \
- .event_handler = 0, \
- .bitrate = NRF_ESB_BITRATE_2MBPS, \
- .crc = NRF_ESB_CRC_16BIT, \
- .tx_output_power = NRF_ESB_TX_POWER_0DBM, \
- .retransmit_delay = 250, \
- .retransmit_count = 3, \
- .tx_mode = NRF_ESB_TXMODE_AUTO, \
- .radio_irq_priority = 1, \
- .event_irq_priority = 2, \
- .payload_length = 32, \
- .selective_auto_ack = false \
- }
- #define NRF_ESB_LEGACY_CONFIG {.protocol = NRF_ESB_PROTOCOL_ESB, \
- .mode = NRF_ESB_MODE_PTX, \
- .event_handler = 0, \
- .bitrate = NRF_ESB_BITRATE_2MBPS, \
- .crc = NRF_ESB_CRC_8BIT, \
- .tx_output_power = NRF_ESB_TX_POWER_0DBM, \
- .retransmit_delay = 600, \
- .retransmit_count = 3, \
- .tx_mode = NRF_ESB_TXMODE_AUTO, \
- .radio_irq_priority = 1, \
- .event_irq_priority = 2, \
- .payload_length = 32, \
- .selective_auto_ack = false \
- }
- #define NRF_ESB_CREATE_PAYLOAD(_pipe, ...) \
- {.pipe = _pipe, .length = NUM_VA_ARGS(__VA_ARGS__), .data = {__VA_ARGS__}}; \
- STATIC_ASSERT(NUM_VA_ARGS(__VA_ARGS__) > 0 && NUM_VA_ARGS(__VA_ARGS__) <= 63)
- typedef enum {
- NRF_ESB_PROTOCOL_ESB,
- NRF_ESB_PROTOCOL_ESB_DPL
- } nrf_esb_protocol_t;
- typedef enum {
- NRF_ESB_MODE_PTX,
- NRF_ESB_MODE_PRX
- } nrf_esb_mode_t;
- typedef enum {
- NRF_ESB_BITRATE_2MBPS = RADIO_MODE_MODE_Nrf_2Mbit,
- NRF_ESB_BITRATE_1MBPS = RADIO_MODE_MODE_Nrf_1Mbit,
- #if defined(RADIO_MODE_MODE_Nrf_250Kbit)
- NRF_ESB_BITRATE_250KBPS = RADIO_MODE_MODE_Nrf_250Kbit,
- #endif
- NRF_ESB_BITRATE_1MBPS_BLE = RADIO_MODE_MODE_Ble_1Mbit,
- #if defined(RADIO_MODE_MODE_Ble_2Mbit)
- NRF_ESB_BITRATE_2MBPS_BLE = RADIO_MODE_MODE_Ble_2Mbit
- #endif
- } nrf_esb_bitrate_t;
- typedef enum {
- NRF_ESB_CRC_16BIT = RADIO_CRCCNF_LEN_Two,
- NRF_ESB_CRC_8BIT = RADIO_CRCCNF_LEN_One,
- NRF_ESB_CRC_OFF = RADIO_CRCCNF_LEN_Disabled
- } nrf_esb_crc_t;
- typedef enum {
- #if defined(RADIO_TXPOWER_TXPOWER_Pos8dBm)
- NRF_ESB_TX_POWER_8DBM = RADIO_TXPOWER_TXPOWER_Pos8dBm,
- #endif
- #if defined(RADIO_TXPOWER_TXPOWER_Pos7dBm)
- NRF_ESB_TX_POWER_7DBM = RADIO_TXPOWER_TXPOWER_Pos7dBm,
- #endif
- #if defined(RADIO_TXPOWER_TXPOWER_Pos6dBm)
- NRF_ESB_TX_POWER_6DBM = RADIO_TXPOWER_TXPOWER_Pos6dBm,
- #endif
- #if defined(RADIO_TXPOWER_TXPOWER_Pos5dBm)
- NRF_ESB_TX_POWER_5DBM = RADIO_TXPOWER_TXPOWER_Pos5dBm,
- #endif
- NRF_ESB_TX_POWER_4DBM = RADIO_TXPOWER_TXPOWER_Pos4dBm,
- #if defined(RADIO_TXPOWER_TXPOWER_Pos3dBm)
- NRF_ESB_TX_POWER_3DBM = RADIO_TXPOWER_TXPOWER_Pos3dBm,
- #endif
- #if defined(RADIO_TXPOWER_TXPOWER_Pos2dBm)
- NRF_ESB_TX_POWER_2DBM = RADIO_TXPOWER_TXPOWER_Pos2dBm,
- #endif
- NRF_ESB_TX_POWER_0DBM = RADIO_TXPOWER_TXPOWER_0dBm,
- NRF_ESB_TX_POWER_NEG4DBM = RADIO_TXPOWER_TXPOWER_Neg4dBm,
- NRF_ESB_TX_POWER_NEG8DBM = RADIO_TXPOWER_TXPOWER_Neg8dBm,
- NRF_ESB_TX_POWER_NEG12DBM = RADIO_TXPOWER_TXPOWER_Neg12dBm,
- NRF_ESB_TX_POWER_NEG16DBM = RADIO_TXPOWER_TXPOWER_Neg16dBm,
- NRF_ESB_TX_POWER_NEG20DBM = RADIO_TXPOWER_TXPOWER_Neg20dBm,
- NRF_ESB_TX_POWER_NEG30DBM = RADIO_TXPOWER_TXPOWER_Neg30dBm,
- NRF_ESB_TX_POWER_NEG40DBM = RADIO_TXPOWER_TXPOWER_Neg40dBm
- } nrf_esb_tx_power_t;
- typedef enum {
- NRF_ESB_TXMODE_AUTO,
- NRF_ESB_TXMODE_MANUAL,
- NRF_ESB_TXMODE_MANUAL_START
- } nrf_esb_tx_mode_t;
- typedef enum
- {
- NRF_ESB_EVENT_TX_SUCCESS,
- NRF_ESB_EVENT_TX_FAILED,
- NRF_ESB_EVENT_RX_RECEIVED
- } nrf_esb_evt_id_t;
- typedef struct
- {
- uint8_t length;
- uint8_t pipe;
- int8_t rssi;
- uint8_t noack;
- uint8_t pid;
- uint8_t data[NRF_ESB_MAX_PAYLOAD_LENGTH];
- } nrf_esb_payload_t;
- typedef struct
- {
- nrf_esb_evt_id_t evt_id;
- uint32_t tx_attempts;
- } nrf_esb_evt_t;
- typedef void (* nrf_esb_event_handler_t)(nrf_esb_evt_t const * p_event);
- typedef struct
- {
- nrf_esb_protocol_t protocol;
- nrf_esb_mode_t mode;
- nrf_esb_event_handler_t event_handler;
-
- nrf_esb_bitrate_t bitrate;
- nrf_esb_crc_t crc;
- nrf_esb_tx_power_t tx_output_power;
- uint16_t retransmit_delay;
- uint16_t retransmit_count;
-
- nrf_esb_tx_mode_t tx_mode;
- uint8_t radio_irq_priority;
- uint8_t event_irq_priority;
- uint8_t payload_length;
- bool selective_auto_ack;
- } nrf_esb_config_t;
- uint32_t nrf_esb_init(nrf_esb_config_t const * p_config);
- uint32_t nrf_esb_suspend(void);
- uint32_t nrf_esb_disable(void);
- bool nrf_esb_is_idle(void);
- uint32_t nrf_esb_write_payload(nrf_esb_payload_t const * p_payload);
- uint32_t nrf_esb_read_rx_payload(nrf_esb_payload_t * p_payload);
- uint32_t nrf_esb_start_tx(void);
- uint32_t nrf_esb_start_rx(void);
- uint32_t nrf_esb_stop_rx(void);
- uint32_t nrf_esb_flush_tx(void);
- uint32_t nrf_esb_pop_tx(void);
- uint32_t nrf_esb_skip_tx(void);
- uint32_t nrf_esb_flush_rx(void);
- uint32_t nrf_esb_set_address_length(uint8_t length);
- uint32_t nrf_esb_set_base_address_0(uint8_t const * p_addr);
- uint32_t nrf_esb_set_base_address_1(uint8_t const * p_addr);
- uint32_t nrf_esb_set_prefixes(uint8_t const * p_prefixes, uint8_t num_pipes);
- uint32_t nrf_esb_enable_pipes(uint8_t enable_mask);
- uint32_t nrf_esb_update_prefix(uint8_t pipe, uint8_t prefix);
- uint32_t nrf_esb_set_rf_channel(uint32_t channel);
- uint32_t nrf_esb_get_rf_channel(uint32_t * p_channel);
- uint32_t nrf_esb_set_tx_power(nrf_esb_tx_power_t tx_output_power);
- uint32_t nrf_esb_set_retransmit_delay(uint16_t delay);
- uint32_t nrf_esb_set_retransmit_count(uint16_t count);
- uint32_t nrf_esb_set_bitrate(nrf_esb_bitrate_t bitrate);
- uint32_t nrf_esb_reuse_pid(uint8_t pipe);
- #ifdef __cplusplus
- }
- #endif
- #endif
|