Files
MSE-SoftwEng/pico-sensor/McuLib/RNet/McuNRF24L01.h
2025-05-06 13:07:01 +00:00

1047 lines
44 KiB
C

/* ###################################################################
** This component module is generated by Processor Expert. Do not modify it.
** Filename : McuNRF24L01.h
** Component : nRF24L01
** Version : Component 01.103, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2021-07-06, 16:35, # CodeGen: 0
** Abstract :
** This component implements a driver for the Nordic Semiconductor nRF24L01 2.4 GHz transceiver.
** Settings :
** Contents :
** ConfigureSPI - void McuNRF24L01_ConfigureSPI(void);
** WriteRegister - void McuNRF24L01_WriteRegister(uint8_t reg, uint8_t val);
** ReadRegister - uint8_t McuNRF24L01_ReadRegister(uint8_t reg);
** ReadRegisterData - void McuNRF24L01_ReadRegisterData(uint8_t reg, uint8_t *buf, uint8_t bufSize);
** WriteRegisterData - void McuNRF24L01_WriteRegisterData(uint8_t reg, uint8_t *buf, uint8_t bufSize);
** WriteRead - uint8_t McuNRF24L01_WriteRead(uint8_t val);
** Write - void McuNRF24L01_Write(uint8_t val);
** GetStatus - uint8_t McuNRF24L01_GetStatus(void);
** GetStatusClrIRQ - uint8_t McuNRF24L01_GetStatusClrIRQ(void);
** ResetStatusIRQ - void McuNRF24L01_ResetStatusIRQ(uint8_t flags);
** TxPayload - void McuNRF24L01_TxPayload(uint8_t *payload, uint8_t payloadSize);
** RxPayload - void McuNRF24L01_RxPayload(uint8_t *payload, uint8_t payloadSize);
** StopRxTx - void McuNRF24L01_StopRxTx(void);
** StartRxTx - void McuNRF24L01_StartRxTx(void);
** EnableAutoAck - uint8_t McuNRF24L01_EnableAutoAck(uint8_t pipes);
** SetStaticPipePayload - uint8_t McuNRF24L01_SetStaticPipePayload(uint8_t pipe, uint8_t payloadBytes);
** EnableDynamicPayloadLength - uint8_t McuNRF24L01_EnableDynamicPayloadLength(uint8_t pipeMask);
** WriteFeature - uint8_t McuNRF24L01_WriteFeature(uint8_t featureMask);
** ReadFeature - uint8_t McuNRF24L01_ReadFeature(uint8_t *featureMask);
** ReadNofRxPayload - uint8_t McuNRF24L01_ReadNofRxPayload(uint8_t *nof);
** ReadObserveTxRegister - uint8_t McuNRF24L01_ReadObserveTxRegister(uint8_t *nofLoss, uint8_t *nofRetransmitted);
** ReadReceivedPowerDetector - uint8_t McuNRF24L01_ReadReceivedPowerDetector(uint8_t *rpd);
** SetChannel - uint8_t McuNRF24L01_SetChannel(uint8_t channel);
** GetChannel - uint8_t McuNRF24L01_GetChannel(uint8_t *channel);
** ConstantCarrierWave - uint8_t McuNRF24L01_ConstantCarrierWave(bool turnOn);
** SetOutputPower - uint8_t McuNRF24L01_SetOutputPower(int8_t power);
** GetOutputPower - uint8_t McuNRF24L01_GetOutputPower(int8_t *power);
** SetDataRate - uint8_t McuNRF24L01_SetDataRate(uint16_t rate);
** GetDataRate - uint8_t McuNRF24L01_GetDataRate(uint16_t *rate);
** SetAddressWidth - uint8_t McuNRF24L01_SetAddressWidth(uint8_t width);
** GetAddressWidth - uint8_t McuNRF24L01_GetAddressWidth(uint8_t *pAddrWidth);
** SetTxAddress - uint8_t McuNRF24L01_SetTxAddress(uint8_t *address, uint8_t nofAddressBytes);
** GetTxAddress - uint8_t McuNRF24L01_GetTxAddress(uint8_t *address, uint8_t nofAddressBytes);
** SetRxAddress - uint8_t McuNRF24L01_SetRxAddress(uint8_t pipe, uint8_t *address, uint8_t...
** GetRxAddress - uint8_t McuNRF24L01_GetRxAddress(uint8_t pipe, uint8_t *address, uint8_t...
** GetFifoStatus - uint8_t McuNRF24L01_GetFifoStatus(uint8_t *status);
** PollInterrupt - bool McuNRF24L01_PollInterrupt(void);
** Deinit - void McuNRF24L01_Deinit(void);
** Init - void McuNRF24L01_Init(void);
**
** * Copyright (c) 2013-2018, Erich Styger
** * Web: https://mcuoneclipse.com
** * SourceForge: https://sourceforge.net/projects/mcuoneclipse
** * Git: https://github.com/ErichStyger/McuOnEclipse_PEx
** * All rights reserved.
** *
** * Redistribution and use in source and binary forms, with or without modification,
** * are permitted provided that the following conditions are met:
** *
** * - Redistributions of source code must retain the above copyright notice, this list
** * of conditions and the following disclaimer.
** *
** * - Redistributions in binary form must reproduce the above copyright notice, this
** * list of conditions and the following disclaimer in the documentation and/or
** * other materials provided with the distribution.
** *
** * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
** * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
** * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
** ###################################################################*/
/*!
** @file McuNRF24L01.h
** @version 01.00
** @brief
** This component implements a driver for the Nordic Semiconductor nRF24L01 2.4 GHz transceiver.
*/
/*!
** @addtogroup McuNRF24L01_module module documentation
** @{
*/
#ifndef __McuNRF24L01_H
#define __McuNRF24L01_H
/* MODULE McuNRF24L01. */
#include "McuLib.h" /* SDK and API used */
#include "McuNRF24L01config.h" /* configuration */
/* Include inherited beans */
#include "McuWait.h"
#include "McuGPIO.h"
#include "McuSPI.h"
/* event handler prototypes */
void McuNRF24L01_OnInterrupt(void);
void McuNRF24L01_OnActivate(void);
void McuNRF24L01_OnDeactivate(void);
/* if having multiple users on the SPI bus, enable bus sharing/switching */
#ifndef McuNRF24L01_SWITCH_BUS
#define McuNRF24L01_SWITCH_BUS (0)
#endif
//#define McuNRF24L01_BAUD_RATE_MODE 2 /* Index of baud rate mode */
/* Memory Map - register address defines */
#define McuNRF24L01_CONFIG 0x00 /* CONFIG register */
#define McuNRF24L01_EN_AA 0x01 /* EN_AA register: configures auto-acknowledge per pipe */
/* EN_AA register bitwise definitions */
/* masks for auto acknowledge per pipe */
#define McuNRF24L01_EN_AA_RESERVED 0xC0
#define McuNRF24L01_EN_AA_ENAA_ALL 0x3F
#define McuNRF24L01_EN_AA_ENAA_P5 0x20
#define McuNRF24L01_EN_AA_ENAA_P4 0x10
#define McuNRF24L01_EN_AA_ENAA_P3 0x08
#define McuNRF24L01_EN_AA_ENAA_P2 0x04
#define McuNRF24L01_EN_AA_ENAA_P1 0x02
#define McuNRF24L01_EN_AA_ENAA_P0 0x01
#define McuNRF24L01_EN_AA_ENAA_NONE 0x00
#define McuNRF24L01_EN_RXADDR 0x02 /* EN_RXADDR register */
#define McuNRF24L01_SETUP_AW 0x03 /* SETUP_AW register */
#define McuNRF24L01_SETUP_RETR 0x04
#define McuNRF24L01_RF_CH 0x05 /* Channel register, valid channels from 0x0 to 0x7F */
/* RF_CH register bitwise definitions */
#define McuNRF24L01_RF_CH_RESERVED 0x80
#define McuNRF24L01_RF_SETUP 0x06 /* RF_SETUP register */
/* RF_SETUP register bits: */
#define McuNRF24L01_RF_SETUP_CONT_WAVE (1<<7) /* Enables continuous carrier transmit when high. */
#define McuNRF24L01_RF_SETUP_PLL_LOCK (1<<4) /* Force PLL lock signal. Only used in test */
#define McuNRF24L01_RF_SETUP_RF_DR_MASK (McuNRF24L01_RF_SETUP_RF_DR_LOW|McuNRF24L01_RF_SETUP_RF_DR_HIGH) /* xx: mask bits */
#define McuNRF24L01_RF_SETUP_RF_DR_LOW (1<<5) /* Set RF Data Rate to 250kbps. See RF_DR_HIGH for encoding. */
#define McuNRF24L01_RF_SETUP_RF_DR_HIGH (1<<3) /* Select between the high speed data rates. */
#define McuNRF24L01_RF_SETUP_RF_DR_1000 (0) /* RF_DR_LOW|RF_DR_HIGH: 00 */
#define McuNRF24L01_RF_SETUP_RF_DR_2000 (McuNRF24L01_RF_SETUP_RF_DR_HIGH) /* RF_DR_LOW|RF_DR_HIGH: 01 */
#define McuNRF24L01_RF_SETUP_RF_DR_250 (McuNRF24L01_RF_SETUP_RF_DR_LOW) /* RF_DR_LOW|RF_DR_HIGH: 10 */
#define McuNRF24L01_RF_SETUP_RF_PWR_MASK (3<<1) /* xx: mask bits */
#define McuNRF24L01_RF_SETUP_RF_PWR_18 (0<<1) /* 00: -18dBm */
#define McuNRF24L01_RF_SETUP_RF_PWR_12 (1<<1) /* 01: -12dBm */
#define McuNRF24L01_RF_SETUP_RF_PWR_10 (2<<1) /* 10: -10dBm */
#define McuNRF24L01_RF_SETUP_RF_PWR_0 (3<<1) /* 11: 0dBm, default */
#define McuNRF24L01_STATUS 0x07
/* STATUS register bits */
#define McuNRF24L01_STATUS_RESERVED 0x80 /* bit 1xxx xxxx: This bit is reserved */
#define McuNRF24L01_STATUS_RX_DR 0x40 /* bit x1xx xxxx: Data ready RX FIFO interrupt. Asserted when new data arrives RX FIFO */
#define McuNRF24L01_STATUS_TX_DS 0x20 /* bit xx1x xxxx: Data sent TX FIFO interrupt. Asserted when packet transmitted on TX. */
#define McuNRF24L01_STATUS_MAX_RT 0x10 /* bit xxx1 xxxx: maximum number of TX retransmit interrupts */
#define McuNRF24L01_STATUS_RX_P_NO 0x0E
#define McuNRF24L01_STATUS_RX_P_NO_RX_FIFO_EMPTY 0x0E
#define McuNRF24L01_STATUS_RX_P_NO_UNUSED 0x0C
#define McuNRF24L01_STATUS_RX_P_NO_5 0x0A
#define McuNRF24L01_STATUS_RX_P_NO_4 0x08
#define McuNRF24L01_STATUS_RX_P_NO_3 0x06
#define McuNRF24L01_STATUS_RX_P_NO_2 0x04
#define McuNRF24L01_STATUS_RX_P_NO_1 0x02
#define McuNRF24L01_STATUS_RX_P_NO_0 0x00 /* bit xxxx 111x: pipe number for payload */
#define McuNRF24L01_STATUS_TX_FULL 0x01 /* bit xxxx xxx1: if bit set, then TX FIFO is full */
#define McuNRF24L01_OBSERVE_TX 0x08
#define McuNRF24L01_RPD 0x09 /* Received Power Detector */
#define McuNRF24L01_RX_ADDR_P0 0x0A
#define McuNRF24L01_RX_ADDR_P1 0x0B
#define McuNRF24L01_RX_ADDR_P2 0x0C
#define McuNRF24L01_RX_ADDR_P3 0x0D
#define McuNRF24L01_RX_ADDR_P4 0x0E
#define McuNRF24L01_RX_ADDR_P5 0x0F
#define McuNRF24L01_TX_ADDR 0x10
#define McuNRF24L01_RX_PW_P0 0x11 /* register to set static RX payload on pipe 0, 0 to 32 bytes */
#define McuNRF24L01_RX_PW_P1 0x12 /* register to set static RX payload on pipe 1, 0 to 32 bytes */
#define McuNRF24L01_RX_PW_P2 0x13 /* register to set static RX payload on pipe 2, 0 to 32 bytes */
#define McuNRF24L01_RX_PW_P3 0x14 /* register to set static RX payload on pipe 3, 0 to 32 bytes */
#define McuNRF24L01_RX_PW_P4 0x15 /* register to set static RX payload on pipe 4, 0 to 32 bytes */
#define McuNRF24L01_RX_PW_P5 0x16 /* register to set static RX payload on pipe 5, 0 to 32 bytes */
#define McuNRF24L01_FIFO_STATUS 0x17 /* FIFO status register */
/* FIFO_STATUS register bits */
#define McuNRF24L01_FIFO_STATUS_RESERVED (0x8C) /* reserved bits */
#define McuNRF24L01_FIFO_STATUS_TX_REUSE (1<<6)
#define McuNRF24L01_FIFO_STATUS_TX_FULL (1<<5)
#define McuNRF24L01_FIFO_STATUS_TX_EMPTY (1<<4)
#define McuNRF24L01_FIFO_STATUS_RX_FULL (1<<1)
#define McuNRF24L01_FIFO_STATUS_RX_EMPTY (1<<0)
#define McuNRF24L01_DYNPD 0x1C /* enable dynamic payload length */
/* DYNPD register bits: */
#define McuNRF24L01_DYNPD_DPL_ALL (0x3F) /* enable DPL for all pipes */
#define McuNRF24L01_DYNPD_DPL_P0 (1<<0) /* enable DPL for pipe 0 */
#define McuNRF24L01_DYNPD_DPL_P1 (1<<1) /* enable DPL for pipe 1 */
#define McuNRF24L01_DYNPD_DPL_P2 (1<<2) /* enable DPL for pipe 2 */
#define McuNRF24L01_DYNPD_DPL_P3 (1<<3) /* enable DPL for pipe 3 */
#define McuNRF24L01_DYNPD_DPL_P4 (1<<4) /* enable DPL for pipe 4 */
#define McuNRF24L01_DYNPD_DPL_P5 (1<<5) /* enable DPL for pipe 5 */
#define McuNRF24L01_FEATURE 0x1D /* feature register */
/* FEATURE register bits: */
#define McuNRF24L01_FEATURE_EN_DPL (1<<2) /* enables dynamic payload length */
#define McuNRF24L01_FEATURE_EN_ACK_PAY (1<<1) /* enables payload with ACK */
#define McuNRF24L01_FEATURE_EN_DYN_PAY (1<<0) /* enables the W_TX_PAYLOAD_NOACK command */
/* Bit Mnemonics */
/* CONFIG Register Bits */
#define McuNRF24L01_MASK_RX_DR (1<<6) /* Mask interrupt caused by RX_DR: 1: interrupt masked. 0: interrupt enabled */
#define McuNRF24L01_MASK_TX_DS (1<<5) /* Mask interrupt caused by TX_DS: 1: interrupt masked. 0: interrupt enabled */
#define McuNRF24L01_MASK_MAX_RT (1<<4) /* Mask interrupt caused by MAX_RT. 1: interrupt not reflected on IRQ pin. 0: reflect MAX_RT as active low interrupt on IRQ pin */
#define McuNRF24L01_EN_CRC (1<<3) /* Enable CRC. Forced high if on of the bits in EN_AA is high */
#define McuNRF24L01_CRCO (1<<2) /* CRC encoding scheme, 0: 1 byte, 1: 2 bytes */
#define McuNRF24L01_PWR_UP (1<<1) /* 1: Power up, 0: Power down */
#define McuNRF24L01_PRIM_RX (1<<0) /* 1: PRX, 0: PTX */
#define McuNRF24L01_PRIM_TX (0) /* 0: PTX */
#define McuNRF24L01_ERX_P5 5
#define McuNRF24L01_ERX_P4 4
#define McuNRF24L01_ERX_P3 3
#define McuNRF24L01_ERX_P2 2
#define McuNRF24L01_ERX_P1 1
#define McuNRF24L01_ERX_P0 0
#define McuNRF24L01_AW 0
#define McuNRF24L01_ARD 4
#define McuNRF24L01_ARC 0
#define McuNRF24L01_PLL_LOCK 4
#define McuNRF24L01_RF_DR_HIGH 3
#define McuNRF24L01_RF_DR_LOW 5
#define McuNRF24L01_RF_PWR 1
#define McuNRF24L01_LNA_HCURR 0
#define McuNRF24L01_RX_DR 6
#define McuNRF24L01_TX_DS 5
#define McuNRF24L01_MAX_RT 4
#define McuNRF24L01_RX_P_NO 1
#define McuNRF24L01_TX_FULL 0
#define McuNRF24L01_PLOS_CNT 4
#define McuNRF24L01_ARC_CNT 0
#define McuNRF24L01_TX_REUSE 6
#define McuNRF24L01_FIFO_FULL 5
#define McuNRF24L01_TX_EMPTY 4
#define McuNRF24L01_RX_FULL 1
#define McuNRF24L01_RX_EMPTY 0
/* Command Name Mnemonics (Instructions) */
#define McuNRF24L01_R_REGISTER 0x00 /* read register command, the address is encoded into the command (000A AAAA) */
#define McuNRF24L01_W_REGISTER 0x20 /* write register command, the address is encoded into the command (001A AAAA) */
#define McuNRF24L01_REGISTER_MASK 0x1F /* mask used for R_REGISTER and W_REGISTER commands */
#define McuNRF24L01_R_RX_PAYLOAD 0x61 /* read RX payload command */
#define McuNRF24L01_W_TX_PAYLOAD 0xA0 /* write TX payload command */
#define McuNRF24L01_FLUSH_TX 0xE1 /* flush TX FIFO command */
#define McuNRF24L01_FLUSH_RX 0xE2 /* flush RX FIFO command */
#define McuNRF24L01_REUSE_TX_PL 0xE3 /* reuse last transmitted payload command */
#define McuNRF24L01_R_RX_PL_WID 0x60 /* read RX payload width for the top R_RX_PAYLOAD in the RX FIFO */
#define McuNRF24L01_W_ACK_PAYLOAD 0xA8 /* used in RX mode. Write payload to be transmitted with ACK packet to pipe (1010 1PPP) */
#define McuNRF24L01_W_TX_PAYLOAD_NO_ACK 0xB0 /* used in TX mode. Disable AUTOACK on this specific packet */
#define McuNRF24L01_NOP 0xFF /* no operation command, used for reading STATUS register */
#define McuNRF24L01_CONFIG_DEFAULT_VAL 0x08
#define McuNRF24L01_EN_AA_DEFAULT_VAL 0x3F
#define McuNRF24L01_EN_RXADDR_DEFAULT_VAL 0x03
#define McuNRF24L01_SETUP_AW_DEFAULT_VAL 0x03
#define McuNRF24L01_SETUP_RETR_DEFAULT_VAL 0x03
#define McuNRF24L01_RF_CH_DEFAULT_VAL 0x02
#define McuNRF24L01_RF_SETUP_DEFAULT_VAL 0x0F
#define McuNRF24L01_STATUS_DEFAULT_VAL 0x0E
#define McuNRF24L01_OBSERVE_TX_DEFAULT_VAL 0x00
#define McuNRF24L01_CD_DEFAULT_VAL 0x00
#define McuNRF24L01_RX_ADDR_P0_B0_DEFAULT_VAL 0xE7
#define McuNRF24L01_RX_ADDR_P0_B1_DEFAULT_VAL 0xE7
#define McuNRF24L01_RX_ADDR_P0_B2_DEFAULT_VAL 0xE7
#define McuNRF24L01_RX_ADDR_P0_B3_DEFAULT_VAL 0xE7
#define McuNRF24L01_RX_ADDR_P0_B4_DEFAULT_VAL 0xE7
#define McuNRF24L01_RX_ADDR_P1_B0_DEFAULT_VAL 0xC2
#define McuNRF24L01_RX_ADDR_P1_B1_DEFAULT_VAL 0xC2
#define McuNRF24L01_RX_ADDR_P1_B2_DEFAULT_VAL 0xC2
#define McuNRF24L01_RX_ADDR_P1_B3_DEFAULT_VAL 0xC2
#define McuNRF24L01_RX_ADDR_P1_B4_DEFAULT_VAL 0xC2
#define McuNRF24L01_RX_ADDR_P2_DEFAULT_VAL 0xC3
#define McuNRF24L01_RX_ADDR_P3_DEFAULT_VAL 0xC4
#define McuNRF24L01_RX_ADDR_P4_DEFAULT_VAL 0xC5
#define McuNRF24L01_RX_ADDR_P5_DEFAULT_VAL 0xC6
#define McuNRF24L01_TX_ADDR_B0_DEFAULT_VAL 0xE7
#define McuNRF24L01_TX_ADDR_B1_DEFAULT_VAL 0xE7
#define McuNRF24L01_TX_ADDR_B2_DEFAULT_VAL 0xE7
#define McuNRF24L01_TX_ADDR_B3_DEFAULT_VAL 0xE7
#define McuNRF24L01_TX_ADDR_B4_DEFAULT_VAL 0xE7
#define McuNRF24L01_RX_PW_P0_DEFAULT_VAL 0x00
#define McuNRF24L01_RX_PW_P1_DEFAULT_VAL 0x00
#define McuNRF24L01_RX_PW_P2_DEFAULT_VAL 0x00
#define McuNRF24L01_RX_PW_P3_DEFAULT_VAL 0x00
#define McuNRF24L01_RX_PW_P4_DEFAULT_VAL 0x00
#define McuNRF24L01_RX_PW_P5_DEFAULT_VAL 0x00
#define McuNRF24L01_FIFO_STATUS_DEFAULT_VAL 0x11
/* CONFIG register bitwise definitions */
#define McuNRF24L01_CONFIG_RESERVED 0x80
#define McuNRF24L01_CONFIG_MASK_RX_DR 0x40
#define McuNRF24L01_CONFIG_MASK_TX_DS 0x20
#define McuNRF24L01_CONFIG_MASK_MAX_RT 0x10
#define McuNRF24L01_CONFIG_EN_CRC 0x08
#define McuNRF24L01_CONFIG_CRCO 0x04
#define McuNRF24L01_CONFIG_PWR_UP 0x02
#define McuNRF24L01_CONFIG_PRIM_RX 0x01
/* EN_RXADDR register bitwise definitions */
#define McuNRF24L01_EN_RXADDR_RESERVED 0xC0
#define McuNRF24L01_EN_RXADDR_ERX_ALL 0x3F
#define McuNRF24L01_EN_RXADDR_ERX_P5 0x20
#define McuNRF24L01_EN_RXADDR_ERX_P4 0x10
#define McuNRF24L01_EN_RXADDR_ERX_P3 0x08
#define McuNRF24L01_EN_RXADDR_ERX_P2 0x04
#define McuNRF24L01_EN_RXADDR_ERX_P1 0x02
#define McuNRF24L01_EN_RXADDR_ERX_P0 0x01
#define McuNRF24L01_EN_RXADDR_ERX_NONE 0x00
/* SETUP_AW register bitwise definitions */
#define McuNRF24L01_SETUP_AW_RESERVED 0xFC
#define McuNRF24L01_SETUP_AW 0x03
#define McuNRF24L01_SETUP_AW_5BYTES 0x03
#define McuNRF24L01_SETUP_AW_4BYTES 0x02
#define McuNRF24L01_SETUP_AW_3BYTES 0x01
#define McuNRF24L01_SETUP_AW_ILLEGAL 0x00
/* SETUP_RETR register bitwise definitions */
#define McuNRF24L01_SETUP_RETR_ARD 0xF0
#define McuNRF24L01_SETUP_RETR_ARD_4000 0xF0 /* 4400 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_3750 0xE0 /* 3750 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_3500 0xD0 /* 3500 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_3250 0xC0 /* 3250 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_3000 0xB0 /* 3000 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_2750 0xA0 /* 2750 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_2500 0x90 /* 2500 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_2250 0x80 /* 2250 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_2000 0x70 /* 2000 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_1750 0x60 /* 1750 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_1500 0x50 /* 1500 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_1250 0x40 /* 1250 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_1000 0x30 /* 1000 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_750 0x20 /* 750 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_500 0x10 /* 500 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARD_250 0x00 /* 250 us retry delay */
#define McuNRF24L01_SETUP_RETR_ARC 0x0F
#define McuNRF24L01_SETUP_RETR_ARC_15 0x0F /* 15 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_14 0x0E /* 14 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_13 0x0D /* 13 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_12 0x0C /* 12 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_11 0x0B /* 11 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_10 0x0A /* 10 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_9 0x09 /* 9 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_8 0x08 /* 8 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_7 0x07 /* 7 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_6 0x06 /* 6 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_5 0x05 /* 5 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_4 0x04 /* 4 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_3 0x03 /* 3 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_2 0x02 /* 2 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_1 0x01 /* 1 retry count */
#define McuNRF24L01_SETUP_RETR_ARC_0 0x00 /* 0 retry count, retry disabled */
/* OBSERVE_TX register bitwise definitions */
#define McuNRF24L01_OBSERVE_TX_PLOS_CNT 0xF0
#define McuNRF24L01_OBSERVE_TX_ARC_CNT 0x0F
/* CD register bitwise definitions for nRF24L01 */
//#define McuNRF24L01_CD_RESERVED 0xFE
//#define McuNRF24L01_CD_CD 0x01
/* RPD register bitwise definitions for nRF24L01+ */
#define McuNRF24L01_RPD_RESERVED 0xFE
#define McuNRF24L01_RPD_RPD 0x01
/* RX_PW_P0 register bitwise definitions */
#define McuNRF24L01_RX_PW_P0_RESERVED 0xC0
/* RX_PW_P0 register bitwise definitions */
#define McuNRF24L01_RX_PW_P0_RESERVED 0xC0
/* RX_PW_P1 register bitwise definitions */
#define McuNRF24L01_RX_PW_P1_RESERVED 0xC0
/* RX_PW_P2 register bitwise definitions */
#define McuNRF24L01_RX_PW_P2_RESERVED 0xC0
/* RX_PW_P3 register bitwise definitions */
#define McuNRF24L01_RX_PW_P3_RESERVED 0xC0
/* RX_PW_P4 register bitwise definitions */
#define McuNRF24L01_RX_PW_P4_RESERVED 0xC0
/* RX_PW_P5 register bitwise definitions */
#define McuNRF24L01_RX_PW_P5_RESERVED 0xC0
void McuNRF24L01_Init(void);
/*
** ===================================================================
** Method : Init (component nRF24L01)
**
** Description :
** Initialization method
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_WriteRegister(uint8_t reg, uint8_t val);
/*
** ===================================================================
** Method : WriteRegister (component nRF24L01)
**
** Description :
** Write a register value to the transceiver
** Parameters :
** NAME - DESCRIPTION
** reg - Register address to write
** val - Value to write
** Returns : Nothing
** ===================================================================
*/
uint8_t McuNRF24L01_ReadRegister(uint8_t reg);
/*
** ===================================================================
** Method : ReadRegister (component nRF24L01)
**
** Description :
** Reads a register from the transceiver
** Parameters :
** NAME - DESCRIPTION
** reg - Register address
** Returns :
** --- - value read
** ===================================================================
*/
void McuNRF24L01_ReadRegisterData(uint8_t reg, uint8_t *buf, uint8_t bufSize);
/*
** ===================================================================
** Method : ReadRegisterData (component nRF24L01)
**
** Description :
** Read multiple bytes from the bus.
** Parameters :
** NAME - DESCRIPTION
** reg - Register address
** * buf - Pointer to buffer where to store the values
** bufSize - Size of the destination buffer
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_WriteRegisterData(uint8_t reg, uint8_t *buf, uint8_t bufSize);
/*
** ===================================================================
** Method : WriteRegisterData (component nRF24L01)
**
** Description :
** Write multiple bytes to the bus.
** Parameters :
** NAME - DESCRIPTION
** reg - Register address
** * buf - Pointer to data buffer to write
** bufSize - Size of buffer in bytes
** Returns : Nothing
** ===================================================================
*/
uint8_t McuNRF24L01_WriteRead(uint8_t val);
/*
** ===================================================================
** Method : WriteRead (component nRF24L01)
**
** Description :
** Writes a byte and reads back one byte
** Parameters :
** NAME - DESCRIPTION
** val - Value to write to the bus
** Returns :
** --- - Value read from the bus
** ===================================================================
*/
void McuNRF24L01_Write(uint8_t val);
/*
** ===================================================================
** Method : Write (component nRF24L01)
**
** Description :
** Writes a byte to the bus, without returning the byte read.
** Parameters :
** NAME - DESCRIPTION
** val - Value to write
** Returns : Nothing
** ===================================================================
*/
uint8_t McuNRF24L01_GetStatus(void);
/*
** ===================================================================
** Method : GetStatus (component nRF24L01)
**
** Description :
** Returns the device status byte
** Parameters : None
** Returns :
** --- - status byte
** ===================================================================
*/
void McuNRF24L01_ResetStatusIRQ(uint8_t flags);
/*
** ===================================================================
** Method : ResetStatusIRQ (component nRF24L01)
**
** Description :
** Reset the given flags mask of status bits
** Parameters :
** NAME - DESCRIPTION
** flags - Flags, one or more of
** RF24_STATUS_RX_DR, RF24_STATUS_TX_DS,
** RF24_STATUS_MAX_RT
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_TxPayload(uint8_t *payload, uint8_t payloadSize);
/*
** ===================================================================
** Method : TxPayload (component nRF24L01)
**
** Description :
** Send the payload to the Tx FIFO and send it
** Parameters :
** NAME - DESCRIPTION
** * payload - Pointer to buffer with payload to
** send
** payloadSize - Size of payload buffer
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_TxPayloadNoAck(uint8_t *payload, uint8_t payloadSize);
/*
** ===================================================================
** Method : McuNRF24L01_TxPayloadNoAck (component nRF24L01)
**
** Description :
** Send the payload to the Tx FIFO and send it,
** but does not request an acknowledge.
** Parameters :
** NAME - DESCRIPTION
** * payload - Pointer to buffer with payload to
** send
** payloadSize - Size of payload buffer
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_RxPayload(uint8_t *payload, uint8_t payloadSize);
/*
** ===================================================================
** Method : RxPayload (component nRF24L01)
**
** Description :
** Receive the Rx payload from the FIFO and stores it in a
** buffer.
** Parameters :
** NAME - DESCRIPTION
** * payload - Pointer to the payload buffer
** payloadSize - Size of the payload buffer
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_StopRxTx(void);
/*
** ===================================================================
** Method : StopRxTx (component nRF24L01)
**
** Description :
** Stops sending or receiving (sets CE pin to LOW).
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_StartRxTx(void);
/*
** ===================================================================
** Method : StartRxTx (component nRF24L01)
**
** Description :
** Starts sending or receiving (sets CE pin to HIGH).
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
uint8_t McuNRF24L01_SetChannel(uint8_t channel);
/*
** ===================================================================
** Method : SetChannel (component nRF24L01)
**
** Description :
** Sets the radio channel (RF_CH register).
** Parameters :
** NAME - DESCRIPTION
** channel - Channel number, valid channel
** numbers are 0x0 to 0x7F
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_EnableAutoAck(uint8_t pipes);
/*
** ===================================================================
** Method : EnableAutoAck (component nRF24L01)
**
** Description :
** Enables Auto-Acknowledgment for the given pipe(s) (RF_EN_AA
** register).
** Parameters :
** NAME - DESCRIPTION
** pipes - mask of pipes to be enabled (ENAA_P0
** to ENAA_P5)
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_ReadNofRxPayload(uint8_t *nof);
/*
** ===================================================================
** Method : ReadNofRxPayload (component nRF24L01)
**
** Description :
** Returns the number of received payload bytes for the top
** R_RX_PAYLOAD in the RX FIFO
** Parameters :
** NAME - DESCRIPTION
** * nof - Pointer to where to store the number of
** bytes. A return value of 0 means that the
** pipe is not used, and if the value is >32
** then the data is not valid.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_SetStaticPipePayload(uint8_t pipe, uint8_t payloadBytes);
/*
** ===================================================================
** Method : SetStaticPipePayload (component nRF24L01)
**
** Description :
** Specifies the static payload for a pipe.
** Parameters :
** NAME - DESCRIPTION
** pipe - Pipe number, 0 to 5
** payloadBytes - Number of payload pipes
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_EnableDynamicPayloadLength(uint8_t pipeMask);
/*
** ===================================================================
** Method : EnableDynamicPayloadLength (component nRF24L01)
**
** Description :
** Enables dynamic payload length for the give pipes
** Parameters :
** NAME - DESCRIPTION
** pipeMask - Mask of pipes, with 1 for pipe 0,
** 2 for pipe 1, 4 for pipe 2 and so on.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_WriteFeature(uint8_t featureMask);
/*
** ===================================================================
** Method : WriteFeature (component nRF24L01)
**
** Description :
** Writes the FEATURE register
** Parameters :
** NAME - DESCRIPTION
** featureMask - Mask of FEATURE, e.g.
** FEATURE_EN_DPL
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_ReadFeature(uint8_t *featureMask);
/*
** ===================================================================
** Method : ReadFeature (component nRF24L01)
**
** Description :
** Reads the FEATURE register
** Parameters :
** NAME - DESCRIPTION
** * featureMask - Pointer to value of
** FEATURE register
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_ReadObserveTxRegister(uint8_t *nofLoss, uint8_t *nofRetransmitted);
/*
** ===================================================================
** Method : ReadObserveTxRegister (component nRF24L01)
**
** Description :
** Reads the OBSERVE_TX register to return the count of loss
** packets and count of retransmitted packets.
** Parameters :
** NAME - DESCRIPTION
** * nofLoss - Pointer to number of lost packets
** * nofRetransmitted - Pointer to
** number of retransmitted packets
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_ReadReceivedPowerDetector(uint8_t *rpd);
/*
** ===================================================================
** Method : ReadReceivedPowerDetector (component nRF24L01)
**
** Description :
** Reads the RPD (Received Power Detector) register.
** Parameters :
** NAME - DESCRIPTION
** * rpd - Pointer to RPD bit. Bit is one for
** received power levels above -64 dBm, zero
** for less than -64 dBm.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetChannel(uint8_t *channel);
/*
** ===================================================================
** Method : GetChannel (component nRF24L01)
**
** Description :
** Returns the radio channel (RF_CH register).
** Parameters :
** NAME - DESCRIPTION
** * channel - Pointer to where to store the
** channel number.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_ConstantCarrierWave(bool turnOn);
/*
** ===================================================================
** Method : ConstantCarrierWave (component nRF24L01)
**
** Description :
** Put the transceiver into contant carrier wave output for
** testing. The output power of a radio is a critical factor
** for achieving wanted range. Output power is also the first
** test
** Parameters :
** NAME - DESCRIPTION
** turnOn - Set to true to start constant
** carrier wave, false to stop it.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_SetOutputPower(int8_t power);
/*
** ===================================================================
** Method : SetOutputPower (component nRF24L01)
**
** Description :
** Sets the output power
** Parameters :
** NAME - DESCRIPTION
** power - Ouput power in dBm, either 0, -10, -12
** or -18
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetOutputPower(int8_t *power);
/*
** ===================================================================
** Method : GetOutputPower (component nRF24L01)
**
** Description :
** Returns the current output power
** Parameters :
** NAME - DESCRIPTION
** * power - Pointer to where to store the value.
** Returns the output power in dBm
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetStatusClrIRQ(void);
/*
** ===================================================================
** Method : GetStatusClrIRQ (component nRF24L01)
**
** Description :
** Returns the device status byte and clears any IRQ bits in
** the status register.
** Parameters : None
** Returns :
** --- - status byte
** ===================================================================
*/
bool McuNRF24L01_PollInterrupt(void);
/*
** ===================================================================
** Method : PollInterrupt (component nRF24L01)
**
** Description :
** If there is no interrupt line available, this method polls
** the device to check if there is an interrupt. If
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void McuNRF24L01_Deinit(void);
/*
** ===================================================================
** Method : Deinit (component nRF24L01)
**
** Description :
** Driver deinitialization
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
uint8_t McuNRF24L01_SetDataRate(uint16_t rate);
/*
** ===================================================================
** Method : SetDataRate (component nRF24L01)
**
** Description :
** Sets the data rate
** Parameters :
** NAME - DESCRIPTION
** rate - Data rate, either 250, 1000 or 2000
** (kbps)
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetDataRate(uint16_t *rate);
/*
** ===================================================================
** Method : GetDataRate (component nRF24L01)
**
** Description :
** Returns the current data rate
** Parameters :
** NAME - DESCRIPTION
** * rate - Pointer to where to store the value.
** Returns the data rate, either 250, 1000 or
** 2000 (kbps)
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetFifoStatus(uint8_t *status);
/*
** ===================================================================
** Method : GetFifoStatus (component nRF24L01)
**
** Description :
** Returns the FIFO_STATUS register value
** Parameters :
** NAME - DESCRIPTION
** * status - Pointer to where to store the FIFO
** status value.
** Returns :
** --- - Error code
** ===================================================================
*/
void McuNRF24L01_ConfigureSPI(void);
/*
** ===================================================================
** Method : ConfigureSPI (component nRF24L01)
**
** Description :
** Configures the SPI bus
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
uint8_t McuNRF24L01_SetAddressWidth(uint8_t width);
/*
** ===================================================================
** Method : SetAddressWidth (component nRF24L01)
**
** Description :
** Sets the address width using the SETUP_AW register
** Parameters :
** NAME - DESCRIPTION
** width - only 3, 4 or 5 is allowed
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetAddressWidth(uint8_t *pAddrWidth);
/*
** ===================================================================
** Method : GetAddressWidth (component nRF24L01)
**
** Description :
** Returns the address width stored in the SETUP_AW register
** Parameters :
** NAME - DESCRIPTION
** * pAddrWidth - Pointer to where to store
** the value.
** Returns :
** --- - number of address bytes (3, 4 or 5)
** ===================================================================
*/
uint8_t McuNRF24L01_SetTxAddress(uint8_t *address, uint8_t nofAddressBytes);
/*
** ===================================================================
** Method : SetTxAddress (component nRF24L01)
**
** Description :
** Sets the TX address using the RF_TX_ADDR register.
** Parameters :
** NAME - DESCRIPTION
** * address - Pointer to the buffer with the
** address bytes.
** nofAddressBytes - Number of address
** bytes and size of buffer, typically 5.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetTxAddress(uint8_t *address, uint8_t nofAddressBytes);
/*
** ===================================================================
** Method : GetTxAddress (component nRF24L01)
**
** Description :
** Returns the TX address using the RF_TX_ADDR register.
** Parameters :
** NAME - DESCRIPTION
** * address - Pointer to array where the return
** the address bytes.
** nofAddressBytes - Number of address
** bytes and size of buffer, typically 5.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_SetRxAddress(uint8_t pipe, uint8_t *address, uint8_t nofAddressBytes);
/*
** ===================================================================
** Method : SetRxAddress (component nRF24L01)
**
** Description :
** Set the TX address using the RF_RX_ADDR_Px register.
** Parameters :
** NAME - DESCRIPTION
** pipe - pipe number (0-5)
** * address - Pointer to array where the return
** the address bytes.
** nofAddressBytes - Number of address
** bytes and size of buffer, typically 5.
** Returns :
** --- - Error code
** ===================================================================
*/
uint8_t McuNRF24L01_GetRxAddress(uint8_t pipe, uint8_t *address, uint8_t nofAddressBytes);
/*
** ===================================================================
** Method : GetRxAddress (component nRF24L01)
**
** Description :
** Returns the RX address using the RF_RX_ADDR_Px register.
** Parameters :
** NAME - DESCRIPTION
** pipe - pipe number (0-5)
** * address - Pointer to array where the return
** the address bytes.
** nofAddressBytes - Number of address
** bytes and size of buffer, typically 5.
** Returns :
** --- - Error code
** ===================================================================
*/
#include "McuShell.h"
/*!
* \brief Parses a command
* \param cmd Command string to be parsed
* \param handled Sets this variable to TRUE if command was handled
* \param io I/O stream to be used for input/output
* \return Error code, ERR_OK if everything was fine
*/
uint8_t McuNRF24L01_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io);
/* END McuNRF24L01. */
#endif
/* ifndef __McuNRF24L01_H */
/*!
** @}
*/