nrf24l01p_ng.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
21 #ifndef NRF24L01P_NG_H
22 #define NRF24L01P_NG_H
23 
24 #include <stdint.h>
25 
26 #include "board.h"
27 #include "kernel_defines.h"
28 #include "net/gnrc/nettype.h"
29 #include "net/netdev.h"
30 #include "periph/gpio.h"
31 #include "periph/spi.h"
32 
33 #include "nrf24l01p_ng_types.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
42 #define NRF24L01P_NG_MIN_ADDR_WIDTH (3)
43 
47 #define NRF24L01P_NG_MAX_ADDR_WIDTH (5)
48 
53 #ifndef NRF24L01P_NG_ADDR_WIDTH
54 #define NRF24L01P_NG_ADDR_WIDTH NRF24L01P_NG_MAX_ADDR_WIDTH
55 #elif (NRF24L01P_NG_ADDR_WIDTH < NRF24L01P_NG_MIN_ADDR_WIDTH) || \
56  (NRF24L01P_NG_ADDR_WIDTH > NRF24L01P_NG_MAX_ADDR_WIDTH)
57 #error "NRF24L01P_NG_ADDR_WIDTH must be within [3, 5]"
58 #endif
59 
65 #define NRF24L01P_NG_BROADCAST_ADDR { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
66 
70 #define NRF24L01P_NG_ADDR_P0(dev) ((dev)->arxaddr.rx_addr_long[NRF24L01P_NG_P0])
71 
75 #define NRF24L01P_NG_ADDR_P1(dev) ((dev)->arxaddr.rx_addr_long[NRF24L01P_NG_P1])
76 
83 #define NRF24L01P_NG_ADDR_PX_LSB(dev, pipe) ((dev)->arxaddr.rx_addr_short[(pipe) - 2])
84 
88 typedef struct __attribute__((packed)) {
92  uint8_t : 1;
96  uint8_t cfg_channel : 7;
100  uint8_t : 2;
105  uint8_t cfg_crc : 2;
110  uint8_t cfg_tx_power : 2;
115  uint8_t cfg_data_rate : 2;
119  uint8_t cfg_max_retr : 4;
124  uint8_t cfg_retr_delay : 4;
126 
130 typedef struct {
131  spi_t spi;
133  gpio_t pin_cs;
134  gpio_t pin_ce;
135  gpio_t pin_irq;
138 
142 struct nrf24l01p_ng {
145  uint8_t state;
146  uint8_t idle_state;
164  struct {
175  uint8_t rx_addr_short[4];
177 };
178 
193  const nrf24l01p_ng_params_t *params,
194  uint8_t index);
195 
213  bool enable);
214 
226  bool* enable);
227 
239  nrf24l01p_ng_rfdr_t data_rate);
240 
250  nrf24l01p_ng_rfdr_t *data_rate);
251 
264 
274  nrf24l01p_ng_crc_t *crc);
275 
288 
298  nrf24l01p_ng_tx_power_t *power);
299 
310 int nrf24l01p_ng_set_channel(nrf24l01p_ng_t *dev, uint8_t channel);
311 
320 
338 int nrf24l01p_ng_set_rx_address(nrf24l01p_ng_t *dev, const uint8_t *addr,
339  nrf24l01p_ng_pipe_t pipe);
340 
353 int nrf24l01p_ng_get_rx_address(const nrf24l01p_ng_t *dev, uint8_t *addr,
354  nrf24l01p_ng_pipe_t pipe);
355 
368 
377 
390  nrf24l01p_ng_ard_t rt_delay);
391 
401  nrf24l01p_ng_ard_t *rt_delay);
402 
417 
426 
436 void nrf24l01p_ng_eui_get(const netdev_t *dev, uint8_t *eui);
437 
438 #if IS_USED(MODULE_NRF24L01P_NG_DIAGNOSTICS)
446 const char *
447 nrf24l01p_ng_diagnostics_state_to_string(nrf24l01p_ng_state_t state);
448 
457 nrf24l01p_ng_diagnostics_string_to_state(const char *sstate);
458 
464 void nrf24l01p_ng_print_all_regs(nrf24l01p_ng_t *dev);
465 
471 void nrf24l01p_ng_print_dev_info(const nrf24l01p_ng_t *dev);
472 #endif
473 
474 #ifdef __cplusplus
475 }
476 #endif
477 
478 #endif /* NRF24L01P_NG_H */
spi_clk_t
Definition: periph_cpu.h:352
Definitions low-level network driver interface.
Low-level GPIO peripheral driver interface definitions.
int nrf24l01p_ng_set_retransm_delay(nrf24l01p_ng_t *dev, nrf24l01p_ng_ard_t rt_delay)
Set retransmission delay for ESB.
int nrf24l01p_ng_set_tx_power(nrf24l01p_ng_t *dev, nrf24l01p_ng_tx_power_t power)
Configure Tx trasceiver power.
uint8_t nrf24l01p_ng_get_max_retransm(const nrf24l01p_ng_t *dev)
Get currently configured number of maximum retransmissions for ESB.
int nrf24l01p_ng_get_enable_pipe(nrf24l01p_ng_t *dev, nrf24l01p_ng_pipe_t pipe, bool *enable)
Query if data pipe pipe is enabled.
int nrf24l01p_ng_set_crc(nrf24l01p_ng_t *dev, nrf24l01p_ng_crc_t crc)
Configure CRC length.
#define NRF24L01P_NG_ADDR_WIDTH
Pass the compiler a definition of NRF24L01P_NG_ADDR_WIDTH to configure the layer-2 address width of t...
Definition: nrf24l01p_ng.h:54
uint8_t nrf24l01p_ng_get_crc(const nrf24l01p_ng_t *dev, nrf24l01p_ng_crc_t *crc)
Get currently configured CRC length.
int nrf24l01p_ng_setup(nrf24l01p_ng_t *dev, const nrf24l01p_ng_params_t *params, uint8_t index)
Setup the NRF24L01+ driver, but perform no initialization.
int nrf24l01p_ng_set_channel(nrf24l01p_ng_t *dev, uint8_t channel)
Set transceiver channel.
int nrf24l01p_ng_set_state(nrf24l01p_ng_t *dev, nrf24l01p_ng_state_t state)
Put device into sleep mode(NRF24L01P_NG_STATE_POWER_DOWN), standby mode (NRF24L01P_NG_STATE_STANDBY_1...
uint8_t nrf24l01p_ng_get_channel(const nrf24l01p_ng_t *dev)
Get currently configured transceiver channel.
int nrf24l01p_ng_set_rx_address(nrf24l01p_ng_t *dev, const uint8_t *addr, nrf24l01p_ng_pipe_t pipe)
Set Rx address of a certain data pipe.
nrf24l01p_ng_state_t nrf24l01p_ng_get_state(const nrf24l01p_ng_t *dev)
Get current device state.
void nrf24l01p_ng_eui_get(const netdev_t *dev, uint8_t *eui)
Retrieve a unique layer-2 address for an nrf24l01p_ng instance.
int8_t nrf24l01p_ng_get_tx_power(const nrf24l01p_ng_t *dev, nrf24l01p_ng_tx_power_t *power)
Get currently configured Tx transceiver power.
int nrf24l01p_ng_set_max_retransm(nrf24l01p_ng_t *dev, uint8_t max_rt)
Configure maximum number of retransmissions for ESB.
uint16_t nrf24l01p_ng_get_retransm_delay(const nrf24l01p_ng_t *dev, nrf24l01p_ng_ard_t *rt_delay)
Get retransmission delay for ESB.
int nrf24l01p_ng_set_air_data_rate(nrf24l01p_ng_t *dev, nrf24l01p_ng_rfdr_t data_rate)
Configure air data rate.
int nrf24l01p_ng_set_enable_pipe(nrf24l01p_ng_t *dev, nrf24l01p_ng_pipe_t pipe, bool enable)
Enable or disable data pipe pipe.
uint16_t nrf24l01p_ng_get_air_data_rate(const nrf24l01p_ng_t *dev, nrf24l01p_ng_rfdr_t *data_rate)
Get currently configured data rate.
int nrf24l01p_ng_get_rx_address(const nrf24l01p_ng_t *dev, uint8_t *addr, nrf24l01p_ng_pipe_t pipe)
Get current Rx address of a certain data pipe.
Common macros and compiler attributes/pragmas configuration.
Protocol type definitions.
Definitions of user visible types for the NRF24L01+ (NG) device driver.
enum nrf24l01p_ng_rfdr nrf24l01p_ng_rfdr_t
Possible values to configure the data rate.
enum nrf24l01p_ng_pipe nrf24l01p_ng_pipe_t
Enumeration of NRF24L01+ data pipes.
enum nrf24l01p_ng_ard nrf24l01p_ng_ard_t
Possible values to configure the retransmission delay in ESB.
enum nrf24l01p_ng_state nrf24l01p_ng_state_t
NRF24L01+ operation states.
enum nrf24l01p_ng_crc nrf24l01p_ng_crc_t
Possible values to configure the CRC length.
enum nrf24l01p_ng_tx_power nrf24l01p_ng_tx_power_t
Possible values to configure the radio power.
Low-level SPI peripheral driver interface definition.
Structure to hold driver state.
Definition: netdev.h:365
Struct that holds all active configuration values.
Definition: nrf24l01p_ng.h:88
uint8_t cfg_data_rate
Current data rate configuration value.
Definition: nrf24l01p_ng.h:115
uint8_t cfg_tx_power
Current tx power configuration value.
Definition: nrf24l01p_ng.h:110
uint8_t cfg_crc
Current CRC length configuration value.
Definition: nrf24l01p_ng.h:105
uint8_t cfg_retr_delay
Current retransmission delay configuration value.
Definition: nrf24l01p_ng.h:124
uint8_t cfg_channel
Current channel.
Definition: nrf24l01p_ng.h:96
uint8_t cfg_max_retr
Current maximum number of retransmissions.
Definition: nrf24l01p_ng.h:119
Struct of NRF24L01+ initialization parameters.
Definition: nrf24l01p_ng.h:130
gpio_t pin_irq
NRF24L01+ IRQ gpio pin.
Definition: nrf24l01p_ng.h:135
gpio_t pin_ce
NRF24L01+ chip enable gpio pin.
Definition: nrf24l01p_ng.h:134
gpio_t pin_cs
SPI chip select gpio pin.
Definition: nrf24l01p_ng.h:133
nrf24l01p_ng_cfg_t config
Current configuration values.
Definition: nrf24l01p_ng.h:136
spi_clk_t spi_clk
SPI clock speed.
Definition: nrf24l01p_ng.h:132
NRF24L01+ device struct.
Definition: nrf24l01p_ng.h:142
nrf24l01p_ng_params_t params
Parameters.
Definition: nrf24l01p_ng.h:144
uint8_t rx_addr_short[4]
Array to access the addresses of pipe 2, pipe 3, pipe 4 and pipe 5 via pipe indices.
Definition: nrf24l01p_ng.h:175
uint8_t state
Current operation state.
Definition: nrf24l01p_ng.h:145
struct nrf24l01p_ng::@230 arxaddr
Rx addresses.
uint8_t rx_addr_long[2][NRF24L01P_NG_ADDR_WIDTH]
Array to access the addresses of pipe 0 and pipe 1 via pipe indices.
Definition: nrf24l01p_ng.h:169
uint8_t idle_state
State to return to after sending.
Definition: nrf24l01p_ng.h:146
netdev_t netdev
Netdev member.
Definition: nrf24l01p_ng.h:143