#ifndef _NRF24L01_API_H_
#define _NRF24L01_API_H_

#include "Common.h"
#include "Delay.h"

/**********  NRF24L01敵湔ん紱釬韜鍔  ***********/
#define READ_REG        0x00  //黍饜离敵湔ん,腴5弇峈敵湔ん華硊
#define WRITE_REG       0x20  //迡饜离敵湔ん,腴5弇峈敵湔ん華硊
#define RD_RX_PLOAD     0x61  //黍RX衄虴杅擂,1~32趼誹
#define WR_TX_PLOAD     0xA0  //迡TX衄虴杅擂,1~32趼誹
#define FLUSH_TX        0xE1  //ь壺TX FIFO敵湔ん.楷扞耀宒狟蚚
#define FLUSH_RX        0xE2  //ь壺RX FIFO敵湔ん.諉彶耀宒狟蚚
#define REUSE_TX_PL     0xE3  //笭陔妏蚚奻珨婦杅擂,CE峈詢,杅擂婦掩祥剿楷冞.
#define NOP             0xFF  //諾紱釬,褫眕蚚懂黍袨怓敵湔ん	 
/**********  NRF24L01敵湔ん華硊   *************/
#define CONFIG          0x00  //饜离敵湔ん華硊                             
#define EN_AA           0x01  //妏夔赻雄茼湘髡夔 
#define EN_RXADDR       0x02  //諉彶華硊埰勍
#define SETUP_AW        0x03  //扢离華硊遵僅(垀衄杅擂籵耋)
#define SETUP_RETR      0x04  //膘蕾赻雄笭楷
#define RF_CH           0x05  //RF籵耋
#define RF_SETUP        0x06  //RF敵湔ん
#define STATUS          0x07  //袨怓敵湔ん
#define OBSERVE_TX      0x08  // 楷冞潰聆敵湔ん
#define CD              0x09  // 婥疏潰聆敵湔ん
#define RX_ADDR_P0      0x0A  // 杅擂籵耋0諉彶華硊
#define RX_ADDR_P1      0x0B  // 杅擂籵耋1諉彶華硊
#define RX_ADDR_P2      0x0C  // 杅擂籵耋2諉彶華硊
#define RX_ADDR_P3      0x0D  // 杅擂籵耋3諉彶華硊
#define RX_ADDR_P4      0x0E  // 杅擂籵耋4諉彶華硊
#define RX_ADDR_P5      0x0F  // 杅擂籵耋5諉彶華硊
#define TX_ADDR         0x10  // 楷冞華硊敵湔ん
#define RX_PW_P0        0x11  // 諉彶杅擂籵耋0衄虴杅擂遵僅(1~32趼誹) 
#define RX_PW_P1        0x12  // 諉彶杅擂籵耋1衄虴杅擂遵僅(1~32趼誹) 
#define RX_PW_P2        0x13  // 諉彶杅擂籵耋2衄虴杅擂遵僅(1~32趼誹) 
#define RX_PW_P3        0x14  // 諉彶杅擂籵耋3衄虴杅擂遵僅(1~32趼誹) 
#define RX_PW_P4        0x15  // 諉彶杅擂籵耋4衄虴杅擂遵僅(1~32趼誹)
#define RX_PW_P5        0x16  // 諉彶杅擂籵耋5衄虴杅擂遵僅(1~32趼誹)
#define FIFO_STATUS     0x17  // FIFO袨怓敵湔ん
/*〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞*/

/******   STATUS敵湔んbit弇隅砱      *******/
#define MAX_TX  	0x10  	  //湛善郔湮楷冞棒杅笢剿
#define TX_OK   	0x20  	  //TX楷冞俇傖笢剿
#define RX_OK   	0x40  	  //諉彶善杅擂笢剿
/*〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞〞*/

/*********     24L01楷冞諉彶杅擂遵僅隅砱	  ***********/
#define TX_ADR_WIDTH    5     //5趼誹華硊遵僅
#define RX_ADR_WIDTH    5     //5趼誹華硊遵僅
#define TX_PLOAD_WIDTH  32    //32趼誹衄虴杅擂遵僅
#define RX_PLOAD_WIDTH  32    //32趼誹衄虴杅擂遵僅

#if 0
sbit NRF_CE   = P1 ^ 6;
sbit NRF_CSN  = P1 ^ 7;
sbit NRF_SCK  = P1 ^ 2;
sbit NRF_MOSI = P1 ^ 5;
sbit NRF_MISO = P1 ^ 0;
sbit NRF_IRQ  = P1 ^ 1;
#else
#define NRF_CE          P11
#define NRF_CSN         P15
#define NRF_SCK         P10
#define NRF_MOSI        P00
#define NRF_MISO        P01
#define NRF_IRQ         P03
#endif

typedef unsigned char         uchar;

extern uchar NRF24L01_Check ( void );
extern void NRF24L01_RT_Init ( uchar PLOAD_WIDTH, uchar *TX_ADR, uchar TX_ADDR_WIDTH, uchar *RX_ADR, uchar RX_ADDR_WIDTH, uchar RATE );
extern uchar NRF24L01_RxPacket ( uchar *rxbuf );
extern uchar NRF24L01_TxPacket ( uchar *txbuf );
extern uchar SEND_BUF ( uchar *buf );


#endif
