nrf24

package
v0.0.0-...-168ccc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package nrf24 provides interface to use nRF24L01 and nRF24L01+ transceivers. This package follows original naming of commands and registers that can be found in documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CONFIG

type CONFIG byte
const (
	PRIM_RX     CONFIG = 1 << 0 // 1: Receiver (PRX) / 0: Transmitter (PPTX).
	PWR_UP      CONFIG = 1 << 1 // Power: 1: up / 0: down.
	CRCO        CONFIG = 1 << 2 // CRC encoding scheme: 0: one byte / 1: two bytes.
	EN_CRC      CONFIG = 1 << 3 // Enable CRC. Forced 1 if one of bits in EN_AA is 1.
	MASK_MAX_RT CONFIG = 1 << 4 // MAX_RT: 1: does not assert / 0: asserts IRQ.
	MASK_TX_DS  CONFIG = 1 << 5 // TX_DS: 1: does not assert, 0: asserts IRQ.
	MASK_RX_DR  CONFIG = 1 << 6 // RX_DR: 1: does not assert, 0: asserts IRQ.
)

func (CONFIG) Format

func (c CONFIG) Format(fs fmt.State, _ rune)

type DCI

type DCI interface {
	// WriteRead performs full SPI transation: sets CSN low, writes and reads oi
	// data and sets CSN high.
	WriteRead(oi ...[]byte) int

	// Err returns and clears internal error status.
	Err(clear bool) error
}

DCI represents the simplified nRF24L01(+) Data and Control Interface: only SPI part of the full DCI is need.

type FEATURE

type FEATURE byte
const (
	EN_DYN_ACK FEATURE = 1 << 0 // 1: Enables the W_TX_PAYLOAD_NOACK command.
	EN_ACK_PAY FEATURE = 1 << 1 // 1: Enables payload with ACK
	EN_DPL     FEATURE = 1 << 2 // 1: Enables dynamic payload length
)

func (FEATURE) Format

func (f FEATURE) Format(fs fmt.State, _ rune)

type FIFO_STATUS

type FIFO_STATUS byte
const (
	RX_EMPTY FIFO_STATUS = 1 << 0 // 1: Rx FIFO empty, 0: Data in Rx FIFO.
	RX_FULL  FIFO_STATUS = 1 << 1 // 1: Rx FIFO full, 0: Available locations in Rx FIFO.
	TX_EMPTY FIFO_STATUS = 1 << 4 // 1: Tx FIFO empty, 0: Data in Tx FIFO.
	TX_FULL  FIFO_STATUS = 1 << 5 // 1: Tx FIFO full, 0: Available locations in Tx FIFO.
	TX_REUSE FIFO_STATUS = 1 << 6 // Set by TX_REUSE, cleared by W_TX_PAYLOAD, FLUSH_TX.
)

func (FIFO_STATUS) Format

func (f FIFO_STATUS) Format(fs fmt.State, _ rune)

type Pipes

type Pipes byte

Pipes is a bitfield that represents the nRF24L01+ Rx data pipes.

const (
	P0    Pipes = 1 << 0
	P1    Pipes = 1 << 1
	P2    Pipes = 1 << 2
	P3    Pipes = 1 << 3
	P4    Pipes = 1 << 4
	P5    Pipes = 1 << 5
	P_ALL       = P0 | P1 | P2 | P3 | P4 | P5
)

func (Pipes) Format

func (p Pipes) Format(fs fmt.State, _ rune)

type RF_SETUP

type RF_SETUP byte
const (
	LNA_HCURR  RF_SETUP = 1 << 0 // LNA gain 0: -1.5 dB, -0.8 mA (nRF24L01 specific).
	RF_DR_HIGH RF_SETUP = 1 << 3 // High speed data rate 0: 1Mbps, 1: 2Mbps.
	PLL_LOCK   RF_SETUP = 1 << 4 // Force PLL lock signal. Only used in test.
	RF_DR_LOW  RF_SETUP = 1 << 5 // Set RF Data Rate to 250kbps.
	CONT_WAVE  RF_SETUP = 1 << 7 // Enable continuous carrier transmit.
)

func RF_PWR

func RF_PWR(dbm int) RF_SETUP

func (RF_SETUP) Format

func (rf RF_SETUP) Format(fs fmt.State, _ rune)

func (RF_SETUP) RF_PWR

func (rf RF_SETUP) RF_PWR() int

RF_PWR returns RF output power in Tx mode [dBm].

type Radio

type Radio struct {
	DCI DCI
}

Radio provides interface to nRF24L01(+) transceiver. Radio has many methods that are mainly used to send commands that read or write its internal registers. Every such command, as side effect, always reads the value of STATUS regster as it was just before the command was executed. This status value is always returned as the last return value of the command method.

func NewRadio

func NewRadio(dci DCI) *Radio

NewRadio provides convenient way to create heap allocated Radio struct.

func (*Radio) ACTIVATE

func (r *Radio) ACTIVATE(b byte) STATUS

ACTIVATE is nRF24L01 specific command.

func (*Radio) CONFIG

func (r *Radio) CONFIG() (CONFIG, STATUS)

CONFIG returns the value of the Configuration Register.

func (*Radio) ClearIRQ

func (r *Radio) ClearIRQ(s STATUS) STATUS

ClearIRQ allow to clear the interrupt bits of the Status register.

func (*Radio) DYNPD

func (r *Radio) DYNPD() (Pipes, STATUS)

DYNPD returns the value of Enable dynamic payload length register.

func (*Radio) EN_AA

func (r *Radio) EN_AA() (Pipes, STATUS)

EN_AA returns the value of the Enable ‘Auto Acknowledgment’ Function register.

func (*Radio) EN_RXADDR

func (r *Radio) EN_RXADDR() (Pipes, STATUS)

EN_RXADDR returns the value of the Enabled RX Addresses register.

func (*Radio) Err

func (r *Radio) Err(clear bool) error

Err returns the error value of the last executed command. You can freely invoke many commands before check an error. If one command have caused an error the subsequent commands will not be executed until Err(true) will be called.

func (*Radio) FEATURE

func (r *Radio) FEATURE() (FEATURE, STATUS)

FEATURE returns value of Feature Register.

func (*Radio) FIFO_STATUS

func (r *Radio) FIFO_STATUS() (FIFO_STATUS, STATUS)

FIFO_STATUS returns value of FIFO Status Register.

func (*Radio) FLUSH_RX

func (r *Radio) FLUSH_RX() STATUS

func (*Radio) FLUSH_TX

func (r *Radio) FLUSH_TX() STATUS

func (*Radio) NOP

func (r *Radio) NOP() STATUS

func (*Radio) OBSERVE_TX

func (r *Radio) OBSERVE_TX() (plos, arc int, s STATUS)

OBSERVE_TX returns the values of PLOS_CNT and ARC_CNT counters from the Transmit observe register.

func (*Radio) REUSE_TX_PL

func (r *Radio) REUSE_TX_PL() STATUS

func (*Radio) RF_CH

func (r *Radio) RF_CH() (int, STATUS)

RF_CH returns the value of the RF Channel register.

func (*Radio) RF_SETUP

func (r *Radio) RF_SETUP() (RF_SETUP, STATUS)

RF_SETUP returns the value of the RF Setup register.

func (*Radio) RPD

func (r *Radio) RPD() (bool, STATUS)

RPD returns the value of the Received Power Detector register: true if RP > -64dBm, false otherwise. In case of nRF24L01 it returns the value of the CD (Carrier Detect) register.

func (*Radio) RX_PW

func (r *Radio) RX_PW(pn int) (int, STATUS)

RX_PW returns the Rx payload width for pipe pn.

func (*Radio) R_REGISTER

func (r *Radio) R_REGISTER(addr byte, val []byte) STATUS

func (*Radio) R_RX_PAYLOAD

func (r *Radio) R_RX_PAYLOAD(pay []byte) STATUS

func (*Radio) R_RX_PL_WID

func (d *Radio) R_RX_PL_WID() (int, STATUS)

func (*Radio) Read_RX_ADDR

func (r *Radio) Read_RX_ADDR(pn int, addr []byte) STATUS

Read_RX_ADDR reads the receive address of the data pipe pn.

func (*Radio) Read_TX_ADDR

func (r *Radio) Read_TX_ADDR(addr []byte) STATUS

Read_TX_ADDR reads value of Transmit address register into addr.

func (*Radio) SETUP_AW

func (r *Radio) SETUP_AW() (int, STATUS)

SETUP_AW returns the value of the Setup of Address Widths register increased by two, that is it returns the address length in bytes.

func (*Radio) SETUP_RETR

func (r *Radio) SETUP_RETR() (cnt, dlyus int, s STATUS)

SETUP_RETR returns the value of the Setup of Automatic Retransmission register converted to number of retries and delay (µs) between retries.

func (*Radio) Set_CONFIG

func (r *Radio) Set_CONFIG(c CONFIG) STATUS

Set_CONFIG sets the value of the Configuration Register.

func (*Radio) Set_DYNPD

func (r *Radio) Set_DYNPD(p Pipes) STATUS

Set_DYNPD sets the value of Enable dynamic payload length register.

func (*Radio) Set_EN_AA

func (r *Radio) Set_EN_AA(p Pipes) STATUS

Set_EN_AA sets the value of the Enable ‘Auto Acknowledgment’ Function register.

func (*Radio) Set_EN_RXADDR

func (r *Radio) Set_EN_RXADDR(p Pipes) STATUS

Set_EN_RXADDR sets the value of the Enabled RX Addresses) register.

func (*Radio) Set_FEATURE

func (r *Radio) Set_FEATURE(f FEATURE) STATUS

Set_FEATURE sets value of FEATURE register.

func (*Radio) Set_RF_CH

func (r *Radio) Set_RF_CH(ch int) STATUS

Set_RF_CH sets value of RF Channel register.

func (*Radio) Set_RF_SETUP

func (r *Radio) Set_RF_SETUP(rf RF_SETUP) STATUS

Set_RF_SETUP sets the value of the RF Setup register.

func (*Radio) Set_RX_PW

func (r *Radio) Set_RX_PW(pn, pw int) STATUS

Set_RX_PW sets the Rx payload width for pipe pn.

func (*Radio) Set_SETUP_AW

func (r *Radio) Set_SETUP_AW(alen int) STATUS

Set_SETUP_AW sets the value of the Setup of Address Widths register to (aw-2), that is it sets the address length to aw bytes (allowed values: 3, 4, 5).

func (*Radio) Set_SETUP_RETR

func (r *Radio) Set_SETUP_RETR(cnt, dlyus int) STATUS

Set_SETUP_RETR sets the value of the Setup of Automatic Retransmission register using cnt as number of retries and dlyus as delay between retries.

func (*Radio) W_ACK_PAYLOAD

func (r *Radio) W_ACK_PAYLOAD(pn int, pay []byte) STATUS

func (*Radio) W_REGISTER

func (r *Radio) W_REGISTER(addr byte, val ...byte) STATUS

func (*Radio) W_TX_PAYLOAD

func (r *Radio) W_TX_PAYLOAD(pay []byte) STATUS

func (*Radio) W_TX_PAYLOAD_NOACK

func (r *Radio) W_TX_PAYLOAD_NOACK(pay []byte) STATUS

func (*Radio) Write_RX_ADDR

func (r *Radio) Write_RX_ADDR(pn int, addr ...byte) STATUS

Write_RX_ADDR sets the receive address of the data pipe pn.

func (*Radio) Write_TX_ADDR

func (r *Radio) Write_TX_ADDR(addr ...byte) STATUS

Write_TX_ADDR sets value of Transmit address.

type STATUS

type STATUS byte
const (
	FULL_TX STATUS = 1 << 0 // Tx FIFO full flag.
	MAX_RT  STATUS = 1 << 4 // Maximum number of Tx retransmits interrupt.
	TX_DS   STATUS = 1 << 5 // Data Sent Tx FIFO interrupt.
	RX_DR   STATUS = 1 << 6 // Data Ready Rx FIFO interrupt.
)

func (STATUS) Format

func (s STATUS) Format(fs fmt.State, _ rune)

func (STATUS) RX_P_NO

func (s STATUS) RX_P_NO() int

RX_P_NO returns the data pipe number for the payload available for reading from Rx FIFO or -1 if Tx FIFO is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL