nrf24l01p.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Hamburg University of Applied Sciences
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
9 #pragma once
10 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #include <stdint.h>
30 #include <stdio.h>
31 #include "periph/gpio.h"
32 #include "periph/spi.h"
33 
37 typedef struct {
38  spi_t spi;
39  gpio_t ce;
40  gpio_t cs;
41  gpio_t irq;
42  unsigned listener;
43 } nrf24l01p_t;
44 
48 typedef enum {
53 
57 typedef enum {
62 
66 typedef enum {
72 
76 typedef enum {
84 
88 typedef enum {
92 
97 typedef enum {
115 
119 typedef enum {
122 
133 int nrf24l01p_read_reg(const nrf24l01p_t *dev, char reg, char *answer);
134 
145 int nrf24l01p_write_reg(const nrf24l01p_t *dev, char reg, char write);
146 
162 int nrf24l01p_init(nrf24l01p_t *dev, spi_t spi, gpio_t ce, gpio_t csn, gpio_t irq);
163 
172 int nrf24l01p_on(const nrf24l01p_t *dev);
173 
182 int nrf24l01p_off(const nrf24l01p_t *dev);
183 
191 
202 int nrf24l01p_read_payload(const nrf24l01p_t *dev, char *answer, unsigned int size);
203 
211 void nrf24l01p_register(nrf24l01p_t *dev, unsigned int *pid);
212 
223 
233 
243 int nrf24l01p_unregister(nrf24l01p_t *dev, unsigned int pid);
244 
252 void nrf24l01p_get_id(const nrf24l01p_t *dev, unsigned int *pid);
253 
260 void nrf24l01p_start(const nrf24l01p_t *dev);
261 
268 void nrf24l01p_stop(const nrf24l01p_t *dev);
269 
280 int nrf24l01p_preload(const nrf24l01p_t *dev, char *data, unsigned int size);
281 
295 int nrf24l01p_set_channel(const nrf24l01p_t *dev, uint8_t chan);
296 
307 
323  nrf24l01p_rx_pipe_t pipe, uint8_t width);
324 
340 int nrf24l01p_set_tx_address(const nrf24l01p_t *dev, const uint8_t *saddr, unsigned int length);
341 
352 int nrf24l01p_set_tx_address_long(const nrf24l01p_t *dev, uint64_t saddr, unsigned int length);
353 
370 int nrf24l01p_set_rx_address(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, const uint8_t *saddr, unsigned int length);
371 
383 int nrf24l01p_set_rx_address_long(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, uint64_t saddr, unsigned int length);
384 
394 
405 
419 
428 
441 int nrf24l01p_set_power(const nrf24l01p_t *dev, int pwr);
442 
451 
461 
471 
481 
491 int nrf24l01p_reset_interrupts(const nrf24l01p_t *dev, char intrs);
492 
507 int nrf24l01p_mask_interrupt(const nrf24l01p_t *dev, char intr);
508 
523 int nrf24l01p_unmask_interrupt(const nrf24l01p_t *dev, char intr);
524 
535 
546 
555 
566 
583 int nrf24l01p_setup_auto_ack(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, nrf24l01p_retransmit_delay_t delay_retrans, char count_retrans);
584 
594 
604 
614 
621 void nrf24l01p_rx_cb(void *arg);
622 
623 #ifdef __cplusplus
624 }
625 #endif
626 
Low-level GPIO peripheral driver interface definitions.
int nrf24l01p_write_reg(const nrf24l01p_t *dev, char reg, char write)
Write one register to the nrf24l01+ transceiver.
int nrf24l01p_reset_all_interrupts(const nrf24l01p_t *dev)
Reset all interrupts on the nrf24l01+ transceiver.
int nrf24l01p_flush_rx_fifo(const nrf24l01p_t *dev)
Flush RX FIFO on the nrf24l01+ transceiver.
int nrf24l01p_set_rx_address_long(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, uint64_t saddr, unsigned int length)
Set the RX address for the nrf24l01+ transceiver (long int).
int nrf24l01p_set_payload_width(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, uint8_t width)
Set the RX payload width for the nrf24l01+ transceiver.
int nrf24l01p_off(const nrf24l01p_t *dev)
Power off the nrf24l01+ transceiver.
int nrf24l01p_enable_dynamic_payload(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe)
Enable dynamic payload for the pipe on give nrf24l01+ transceiver.
int nrf24l01p_set_rx_address(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, const uint8_t *saddr, unsigned int length)
Set the RX address for the nrf24l01+ transceiver (byte array).
int nrf24l01p_set_power(const nrf24l01p_t *dev, int pwr)
Set the transmit power for the nrf24l01+ transceiver device.
int nrf24l01p_set_txmode(const nrf24l01p_t *dev)
Set the nrf24l01+ into TX mode.
void nrf24l01p_stop(const nrf24l01p_t *dev)
Stop searching packets while in RX mode.
nrf24l01p_rx_pipe_t
Defines the datapipe on which the receiver searches for packets.
Definition: nrf24l01p.h:76
void nrf24l01p_rx_cb(void *arg)
Callback that is called when interrupt occurs on interrupt pin from the nrf24l01+ transceiver.
nrf24l01p_retransmit_delay_t
Defines the automatic retransmission delay defined from end of transmission to start of next treansmi...
Definition: nrf24l01p.h:97
void nrf24l01p_get_id(const nrf24l01p_t *dev, unsigned int *pid)
Get ID from the nrf24l01p transceiver.
nrf24l01p_rx_event_t
Defines states for the nrf24l01+ transceiver.
Definition: nrf24l01p.h:119
int nrf24l01p_flush_tx_fifo(const nrf24l01p_t *dev)
Flush TX FIFO on the nrf24l01+ transceiver.
int nrf24l01p_disable_pipe(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe)
Disable RX datapipe on the nrf24l01+ transceiver.
int nrf24l01p_mask_interrupt(const nrf24l01p_t *dev, char intr)
Mask one interrupt on the nrf24l01+ transceiver.
nrf24l01p_aw_t
Defines the address width of the nrf24l01+ transceiver.
Definition: nrf24l01p.h:48
uint64_t nrf24l01p_get_tx_address_long(const nrf24l01p_t *dev)
Get the TX address for the nrf24l01+ transceiver (long int).
int nrf24l01p_on(const nrf24l01p_t *dev)
Power on the nrf24l01+ transceiver.
int nrf24l01p_get_status(const nrf24l01p_t *dev)
Get the status (register) of the nrf24l01+ transceiver device.
int nrf24l01p_set_channel(const nrf24l01p_t *dev, uint8_t chan)
Set the RF channel for the nrf24l01+ transceiver.
int nrf24l01p_set_tx_address_long(const nrf24l01p_t *dev, uint64_t saddr, unsigned int length)
Set the TX address for the nrf24l01+ transceiver (long int).
int nrf24l01p_disable_crc(const nrf24l01p_t *dev)
Disable CRC error detection on the nrf24l01+ transceiver.
int nrf24l01p_set_datarate(const nrf24l01p_t *dev, nrf24l01p_dr_t dr)
Get the TX address for the nrf24l01+ transceiver (long int).
void nrf24l01p_transmit(const nrf24l01p_t *dev)
Transmit payload laying in TX FIFO of the nrf24l01+ transceiver.
int nrf24l01p_read_reg(const nrf24l01p_t *dev, char reg, char *answer)
Read one register of the nrf24l01+ transceiver.
void nrf24l01p_start(const nrf24l01p_t *dev)
Start searching packets while in RX mode.
int nrf24l01p_unmask_interrupt(const nrf24l01p_t *dev, char intr)
Unmask one interrupt on the nrf24l01+ transceiver.
nrf24l01p_dr_t
Defines the RF datarate.
Definition: nrf24l01p.h:57
int nrf24l01p_disable_all_auto_ack(const nrf24l01p_t *dev)
Disable automatic ACK on the nrf24l01+ transceiver.
int nrf24l01p_unregister(nrf24l01p_t *dev, unsigned int pid)
Unregister the nrf24l01+ transceiver from his ID.
int nrf24l01p_set_rxmode(const nrf24l01p_t *dev)
Set the nrf24l01+ into RX mode.
int nrf24l01p_reset_interrupts(const nrf24l01p_t *dev, char intrs)
Reset interrupts on the nrf24l01+ transceiver.
int nrf24l01p_preload(const nrf24l01p_t *dev, char *data, unsigned int size)
Preload TX FIFO with payload to transmit.
uint64_t nrf24l01p_get_rx_address_long(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe)
Get the RX address for the nrf24l01+ transceiver (long int).
int nrf24l01p_setup_auto_ack(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe, nrf24l01p_retransmit_delay_t delay_retrans, char count_retrans)
Setup and enable automatic ACK and retransmission on the nrf24l01+ transceiver.
int nrf24l01p_enable_dynamic_ack(const nrf24l01p_t *dev)
Enable dynamic ack for the nrf24l01+ transceiver.
nrf24l01p_pwr_t
Defines the RF power level.
Definition: nrf24l01p.h:66
int nrf24l01p_enable_pipe(const nrf24l01p_t *dev, nrf24l01p_rx_pipe_t pipe)
Enable RX datapipe on the nrf24l01+ transceiver.
int nrf24l01p_enable_crc(const nrf24l01p_t *dev, nrf24l01p_crc_t crc)
Enable CRC error detection on the nrf24l01+ transceiver.
int nrf24l01p_set_tx_address(const nrf24l01p_t *dev, const uint8_t *saddr, unsigned int length)
Set the TX address for the nrf24l01+ transceiver (byte array).
nrf24l01p_crc_t
Defines the error detection encoding scheme for the nrf24l01p transceiver.
Definition: nrf24l01p.h:88
int nrf24l01p_get_power(const nrf24l01p_t *dev)
Get the transmit power for the nrf24l01+ transceiver device.
int nrf24l01p_init(nrf24l01p_t *dev, spi_t spi, gpio_t ce, gpio_t csn, gpio_t irq)
Initialize the nrf24l01+ transceiver.
int nrf24l01p_read_payload(const nrf24l01p_t *dev, char *answer, unsigned int size)
Read payload from RX FIFO of the nrf24l01+ transceiver.
int nrf24l01p_set_address_width(const nrf24l01p_t *dev, nrf24l01p_aw_t aw)
Set the address width for the nrf24l01+ transceiver.
void nrf24l01p_register(nrf24l01p_t *dev, unsigned int *pid)
Register a given ID to the nrf24l01+ transceiver.
@ NRF24L01P_PIPE0
RX pipe 0.
Definition: nrf24l01p.h:77
@ NRF24L01P_PIPE5
RX pipe 5.
Definition: nrf24l01p.h:82
@ NRF24L01P_PIPE1
RX pipe 1.
Definition: nrf24l01p.h:78
@ NRF24L01P_PIPE2
RX pipe 2.
Definition: nrf24l01p.h:79
@ NRF24L01P_PIPE3
RX pipe 3.
Definition: nrf24l01p.h:80
@ NRF24L01P_PIPE4
RX pipe 4.
Definition: nrf24l01p.h:81
@ NRF24L01P_RETR_3500US
retransmit delay is 3500us
Definition: nrf24l01p.h:111
@ NRF24L01P_RETR_2000US
retransmit delay is 2000us
Definition: nrf24l01p.h:105
@ NRF24L01P_RETR_1000US
retransmit delay is 1000us
Definition: nrf24l01p.h:101
@ NRF24L01P_RETR_250US
retransmit delay is 250us
Definition: nrf24l01p.h:98
@ NRF24L01P_RETR_3000US
retransmit delay is 3000us
Definition: nrf24l01p.h:109
@ NRF24L01P_RETR_3750US
retransmit delay is 3750us
Definition: nrf24l01p.h:112
@ NRF24L01P_RETR_1750US
retransmit delay is 1750us
Definition: nrf24l01p.h:104
@ NRF24L01P_RETR_2250US
retransmit delay is 2250us
Definition: nrf24l01p.h:106
@ NRF24L01P_RETR_2500US
retransmit delay is 2500us
Definition: nrf24l01p.h:107
@ NRF24L01P_RETR_3250US
retransmit delay is 3250us
Definition: nrf24l01p.h:110
@ NRF24L01P_RETR_1500US
retransmit delay is 1500us
Definition: nrf24l01p.h:103
@ NRF24L01P_RETR_1250US
retransmit delay is 1250us
Definition: nrf24l01p.h:102
@ NRF24L01P_RETR_500US
retransmit delay is 500us
Definition: nrf24l01p.h:99
@ NRF24L01P_RETR_4000US
retransmit delay is 4000us
Definition: nrf24l01p.h:113
@ NRF24L01P_RETR_750US
retransmit delay is 750us
Definition: nrf24l01p.h:100
@ NRF24L01P_RETR_2750US
retransmit delay is 2750us
Definition: nrf24l01p.h:108
@ RCV_PKT_NRF24L01P
transceiver received data
Definition: nrf24l01p.h:120
@ NRF24L01P_AW_3BYTE
address width is 3 Byte
Definition: nrf24l01p.h:49
@ NRF24L01P_AW_5BYTE
address width is 5 Byte
Definition: nrf24l01p.h:51
@ NRF24L01P_AW_4BYTE
address width is 4 Byte
Definition: nrf24l01p.h:50
@ NRF24L01P_DR_250KBS
datarate is 250 kbps
Definition: nrf24l01p.h:58
@ NRF24L01P_DR_2MBS
datarate is 2 Mbps
Definition: nrf24l01p.h:60
@ NRF24L01P_DR_1MBS
datarate is 1 Mbps
Definition: nrf24l01p.h:59
@ NRF24L01P_PWR_0DBM
power is 0dBm
Definition: nrf24l01p.h:70
@ NRF24L01P_PWR_N6DBM
power is - 6dBm
Definition: nrf24l01p.h:69
@ NRF24L01P_PWR_N18DBM
power is -18dBm
Definition: nrf24l01p.h:67
@ NRF24L01P_PWR_N12DBM
power is -12dBm
Definition: nrf24l01p.h:68
@ NRF24L01P_CRC_2BYTE
encoding scheme generates 2 Bytes redundancy
Definition: nrf24l01p.h:90
@ NRF24L01P_CRC_1BYTE
encoding scheme generates 1 Byte redundancy
Definition: nrf24l01p.h:89
Low-level SPI peripheral driver interface definition.
Structure that represents the hardware setup of the nrf24l01+ transceiver.
Definition: nrf24l01p.h:37
gpio_t cs
GPIO pin to initialize as chip select.
Definition: nrf24l01p.h:40
unsigned listener
Place to store an ID in.
Definition: nrf24l01p.h:42
gpio_t irq
GPIO pin to initialize as interrupt request.
Definition: nrf24l01p.h:41
gpio_t ce
GPIO pin to initialize as chip enable.
Definition: nrf24l01p.h:39
spi_t spi
SPI device to initialize.
Definition: nrf24l01p.h:38