/* nRF24L01.h
 * Register definitions for manipulating the Nordic Semiconductor
 * nRF24L01+ RF transceiver chipsets.
 *

    Copyright (c) 2007 Stefan Engelke <mbox@stefanengelke.de>
    Some parts copyright (c) 2012 Eric Brundick <spirilis [at] linux dot com>

    Permission is hereby granted, free of charge, to any person 
    obtaining a copy of this software and associated documentation 
    files (the "Software"), to deal in the Software without 
    restriction, including without limitation the rights to use, copy, 
    modify, merge, publish, distribute, sublicense, and/or sell copies 
    of the Software, and to permit persons to whom the Software is 
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be 
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
    DEALINGS IN THE SOFTWARE.
 */
#ifndef __NRF24L01_H
#define __NRF24L01_H


#define	NRF_BIT0	1 << 0
#define	NRF_BIT1	1 << 1
#define	NRF_BIT2	1 << 2
#define	NRF_BIT3	1 << 3
#define	NRF_BIT4	1 << 4
#define	NRF_BIT5	1 << 5
#define	NRF_BIT6	1 << 6
#define	NRF_BIT7	1 << 7


/* Register Map */
#define RF24_CONFIG        0x00	// Configuration register
#define RF24_EN_AA         0x01	// Enable "Auto acknowledgment"
#define RF24_EN_RXADDR     0x02	// Enable RX addresses
#define RF24_SETUP_AW      0x03	// Setup of address widths
#define RF24_SETUP_RETR    0x04	// Setup of automatic retranslation
#define RF24_RF_CH         0x05	// RF channel
#define RF24_RF_SETUP      0x06	// RF setup register
#define RF24_STATUS        0x07	// Status register
#define RF24_OBSERVE_TX    0x08	// Transmit observe register
#define RF24_CD            0x09	// Carrier detect
#define RF24_RPD           0x09
#define RF24_RX_ADDR_P0    0x0A	// Receive address data pipe 0
#define RF24_RX_ADDR_P1    0x0B	// ..
#define RF24_RX_ADDR_P2    0x0C	// ..
#define RF24_RX_ADDR_P3    0x0D	// ..
#define RF24_RX_ADDR_P4    0x0E	// ..
#define RF24_RX_ADDR_P5    0x0F	// Receive address data pipe 5
#define RF24_TX_ADDR       0x10	// Transmit address
#define RF24_RX_PW_P0      0x11	// Number of bytes in RX payload id data pipe 0
#define RF24_RX_PW_P1      0x12	// ..
#define RF24_RX_PW_P2      0x13	// ..
#define RF24_RX_PW_P3      0x14	// ..
#define RF24_RX_PW_P4      0x15	// ..
#define RF24_RX_PW_P5      0x16	// Number of bytes in RX payload id data pipe 5
#define RF24_FIFO_STATUS   0x17	// FIFO status register
#define RF24_DYNPD         0x1C	// Enable dynamic payload length
#define RF24_FEATURE       0x1D	// Feature register


/* Register NRF_BITs */
#define RF24_MASK_RX_DR    NRF_BIT6	// Mask interrupt caused by RX_DR
#define RF24_MASK_TX_DS    NRF_BIT5	// Mask interrupt caused by TX_DS
#define RF24_MASK_MAX_RT   NRF_BIT4	// Mask interrupt caused by MAX_RT
#define RF24_EN_CRC        NRF_BIT3
#define RF24_CRCO          NRF_BIT2
#define RF24_PWR_UP        NRF_BIT1
#define RF24_PRIM_RX       NRF_BIT0
#define RF24_ENAA_P5       NRF_BIT5
#define RF24_ENAA_P4       NRF_BIT4
#define RF24_ENAA_P3       NRF_BIT3
#define RF24_ENAA_P2       NRF_BIT2
#define RF24_ENAA_P1       NRF_BIT1
#define RF24_ENAA_P0       NRF_BIT0
#define RF24_ERX_P5        NRF_BIT5
#define RF24_ERX_P4        NRF_BIT4
#define RF24_ERX_P3        NRF_BIT3
#define RF24_ERX_P2        NRF_BIT2
#define RF24_ERX_P1        NRF_BIT1
#define RF24_ERX_P0        NRF_BIT0
#define RF24_DYNPL_P5	   NRF_BIT5
#define RF24_DYNPL_P4	   NRF_BIT4
#define RF24_DYNPL_P3	   NRF_BIT3
#define RF24_DYNPL_P2	   NRF_BIT2
#define RF24_DYNPL_P1	   NRF_BIT1
#define RF24_DYNPL_P0	   NRF_BIT0
#define RF24_AW            NRF_BIT0
#define RF24_ARD           NRF_BIT4
#define RF24_ARC           NRF_BIT0
#define RF24_PLL_LOCK      NRF_BIT4
#define RF24_CONT_WAVE     NRF_BIT7
#define RF24_RF_DR         NRF_BIT3
#define RF24_RF_DR_LOW     NRF_BIT5
#define RF24_RF_DR_HIGH    NRF_BIT3
#define RF24_RF_PWR        NRF_BIT1
#define RF24_LNA_HCURR     NRF_BIT0
#define RF24_RX_DR         NRF_BIT6
#define RF24_TX_DS         NRF_BIT5
#define RF24_MAX_RT        NRF_BIT4
#define RF24_RX_P_NO       NRF_BIT1
#define RF24_TX_FULL       NRF_BIT0
#define RF24_PLOS_CNT      NRF_BIT4
#define RF24_ARC_CNT       NRF_BIT0
#define RF24_TX_REUSE      NRF_BIT6
#define RF24_FIFO_FULL     NRF_BIT5
#define RF24_TX_EMPTY      NRF_BIT4
#define RF24_RX_FULL       NRF_BIT1	// RX FIFO full flag
#define RF24_RX_EMPTY      NRF_BIT0	// RX FIFO empty flag
#define RF24_EN_DPL        NRF_BIT2
#define RF24_EN_ACK_PAY    NRF_BIT1
#define RF24_EN_DYN_ACK    NRF_BIT0

#define RF24_SPEED_250 	   NRF_BIT5
#define RF24_SPEED_1000    0
#define RF24_SPEED_2000    NRF_BIT3

#define RF24_POWER_FULL    NRF_BIT2 | NRF_BIT1
#define RF24_POWER_HIGH    NRF_BIT2
#define RF24_POWER_MED     NRF_BIT1
#define RF24_POWER_LOW     0

#define RF24_RETRY_250US   0x00
#define RF24_RETRY_500US   0x10
#define RF24_RETRY_750US   0x20
#define RF24_RETRY_1000US  0x30
#define RF24_RETRY_1250US  0x40
#define RF24_RETRY_1500US  0x50
#define RF24_RETRY_1750US  0x60
#define RF24_RETRY_2000US  0x70
#define RF24_RETRY_2250US  0x80
#define RF24_RETRY_2500US  0x90
#define RF24_RETRY_2750US  0xa0
#define RF24_RETRY_3000US  0xb0
#define RF24_RETRY_3250US  0xc0
#define RF24_RETRY_3500US  0xd0
#define RF24_RETRY_3750US  0xe0
#define RF24_RETRY_4000US  0xf0

#define RF24_RETRANS_OFF   0
#define RF24_RETRANS_1X    1
#define RF24_RETRANS_2X    2
#define RF24_RETRANS_3X    3
#define RF24_RETRANS_4X    4
#define RF24_RETRANS_5X    5
#define RF24_RETRANS_6X    6
#define RF24_RETRANS_7X    7
#define RF24_RETRANS_8X    8
#define RF24_RETRANS_9X    9
#define RF24_RETRANS_10X   10
#define RF24_RETRANS_11X   11
#define RF24_RETRANS_12X   12
#define RF24_RETRANS_13X   13
#define RF24_RETRANS_14X   14
#define RF24_RETRANS_15X   15


/* Instructions */
#define RF24_RREG 				0x00	// R_REGISTER -> Read command and status registers
#define RF24_WREG 				0x20	// W_REGISTER -> Write command and status registers
#define RF24_REGISTER_MASK 		0x1F
#define RF24_R_RX_PAYLOAD 		0x61	// R_RX_PAYLOAD -> Read RX payload
#define RF24_W_TX_PAYLOAD 		0xA0	// W_TX_PAYLOAD -> Write TX payload
#define RF24_FLUSH_TX 			0xE1	// FLUSH_TX -> Flush TX FIFO
#define RF24_FLUSH_RX 			0xE2	// FLUSH_RX -> Flush RX FIFO
#define RF24_REUSE_TX_PL 		0xE3	// REUSE_TX_PL -> Reuse last transmitted payload
#define RF24_R_RX_PL_WID 		0x60
#define RF24_W_ACK_PAYLOAD 		0xA8
#define RF24_W_TX_PAYLOAD_NOACK 0xB0
#define RF24_ACTIVATE 			0x50
#define RF24_NOP 				0xFF	// No operation (to read status register)



#endif /* __NRF24L01_H */
