ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
nrf24.h File Reference

nRF24L01+ radio driver (PROTOCORE_ENABLE_NRF24) - Nordic 2.4 GHz over SPI. More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  nrf_bus
 The bus a driver call uses: your SPI transfer + CE control behind it. More...
 
struct  nrf_config
 Radio configuration applied by protocore_nrf24_init(). More...
 
struct  Nrf24Ns
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Typedefs

typedef void(* nrf_spi_fn) (const uint8_t *tx, uint8_t *rx, uint8_t len, void *ctx)
 Full-duplex SPI transfer of len bytes (chip-select toggled by the callback).
 
typedef void(* nrf_ce_fn) (proto_bool level, void *ctx)
 Drive the CE pin (true = high).
 

Functions

 PROTOCORE_NS_LAYOUT (Nrf24Ns, init, send, tx_done, set_rx, recv)
 
proto_bool protocore_nrf24_init (uint8_t *work, const nrf_bus *bus, const nrf_config *cfg)
 Configure the nRF24L01+ and power it up (standby).
 
proto_bool protocore_nrf24_send (uint8_t *work, const nrf_bus *bus, const uint8_t *data, uint8_t len)
 Transmit len bytes (zero-padded to PROTOCORE_NRF24_PAYLOAD). Poll .
 
proto_bool protocore_nrf24_tx_done (uint8_t *work, const nrf_bus *bus)
 True once a transmit has finished (STATUS TX_DS); clears the flag.
 
void protocore_nrf24_set_rx (uint8_t *work, const nrf_bus *bus)
 Enter receive mode (PRX + CE high); then poll protocore_nrf24_recv().
 
int protocore_nrf24_recv (uint8_t *work, const nrf_bus *bus, uint8_t *buf, uint8_t cap, uint8_t *pipe)
 If a frame is waiting, copy it into buf and report the pipe it .
 

Variables

PROTOCORE_NS Nrf24Ns Nrf24 PROTOCORE_UNUSED
 Module namespace.
 

Detailed Description

nRF24L01+ radio driver (PROTOCORE_ENABLE_NRF24) - Nordic 2.4 GHz over SPI.

A radio driver plugin for the gateway (PROTOCORE_ENABLE_GATEWAY): cheap point-to-multipoint 2.4 GHz sensor links bridged to the web stack. Unlike the SX127x (plain register read/write), the nRF24L01+ speaks an SPI command protocol (each transaction is a command byte + data, and every command returns the STATUS register) and needs a separate CE pin to key RX/TX - so the driver runs over an nrf_bus that carries a full-duplex SPI transfer plus a CE-set callback. That is the only board-specific code.

The nRF24 does its own hardware addressing (5-byte pipe addresses), so a received frame's "source" is the pipe number it arrived on - there is no in-payload header and therefore no separate codec. It uses a static payload width (PROTOCORE_NRF24_PAYLOAD): every frame is that many bytes (a short send is zero-padded). Bridge received payloads northbound with protocore_gateway_uplink(port, pipe, payload, width, 0). The register/command protocol is host-testable against a mock; the RF link needs the module.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file nrf24.h.

Typedef Documentation

◆ nrf_spi_fn

typedef void(* nrf_spi_fn)(const uint8_t *tx, uint8_t *rx, uint8_t len, void *ctx)

Full-duplex SPI transfer of len bytes (chip-select toggled by the callback).

Definition at line 42 of file nrf24.h.

◆ nrf_ce_fn

typedef void(* nrf_ce_fn) (proto_bool level, void *ctx)

Drive the CE pin (true = high).

Definition at line 45 of file nrf24.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( Nrf24Ns  ,
init  ,
send  ,
tx_done  ,
set_rx  ,
recv   
)

◆ protocore_nrf24_init()

proto_bool protocore_nrf24_init ( uint8_t *  work,
const nrf_bus *  bus,
const nrf_config *  cfg 
)

Configure the nRF24L01+ and power it up (standby).

Parameters
workPROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call.
busBus
cfgCfg
Returns
PROTO_TRUE on success.

◆ protocore_nrf24_send()

proto_bool protocore_nrf24_send ( uint8_t *  work,
const nrf_bus *  bus,
const uint8_t *  data,
uint8_t  len 
)

Transmit len bytes (zero-padded to PROTOCORE_NRF24_PAYLOAD). Poll .

Parameters
workPROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call.
busBus
dataData
lenLen
Returns
PROTO_TRUE on success.

◆ protocore_nrf24_tx_done()

proto_bool protocore_nrf24_tx_done ( uint8_t *  work,
const nrf_bus *  bus 
)

True once a transmit has finished (STATUS TX_DS); clears the flag.

Parameters
workPROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call.
busBus
Returns
PROTO_TRUE on success.

◆ protocore_nrf24_set_rx()

void protocore_nrf24_set_rx ( uint8_t *  work,
const nrf_bus *  bus 
)

Enter receive mode (PRX + CE high); then poll protocore_nrf24_recv().

Parameters
workPROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call.
busBus

◆ protocore_nrf24_recv()

int protocore_nrf24_recv ( uint8_t *  work,
const nrf_bus *  bus,
uint8_t *  buf,
uint8_t  cap,
uint8_t *  pipe 
)

If a frame is waiting, copy it into buf and report the pipe it .

Parameters
workPROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call.
busBus
bufBuf
capCap
pipePipe
Returns
The int.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS Nrf24Ns Nrf24 PROTOCORE_UNUSED
Initial value:
proto_bool protocore_nrf24_tx_done(uint8_t *work, const nrf_bus *bus)
True once a transmit has finished (STATUS TX_DS); clears the flag.
int protocore_nrf24_recv(uint8_t *work, const nrf_bus *bus, uint8_t *buf, uint8_t cap, uint8_t *pipe)
If a frame is waiting, copy it into buf and report the pipe it .
proto_bool protocore_nrf24_init(uint8_t *work, const nrf_bus *bus, const nrf_config *cfg)
Configure the nRF24L01+ and power it up (standby).
void protocore_nrf24_set_rx(uint8_t *work, const nrf_bus *bus)
Enter receive mode (PRX + CE high); then poll protocore_nrf24_recv().
proto_bool protocore_nrf24_send(uint8_t *work, const nrf_bus *bus, const uint8_t *data, uint8_t len)
Transmit len bytes (zero-padded to PROTOCORE_NRF24_PAYLOAD). Poll .

Module namespace.

Definition at line 120 of file nrf24.h.