//PMC153
//=========================================================================
//         PB5 |1    14| PB2
//         PB6 |2    13| PB1
//         PB7 |3    12| PB0/INT1
//         VDD |4    11| GND
//         PA7 |5    10| PA0
//         PA6 |6     9| PA4
//   PA5/PRST# |7     8| PA3
//==========================================================================

//=================================预定义===================================


// #define SPI_SS			PB.1
// #define SPI_CLK			PB.0
// #define SPI_MISO 		PB.6
// #define SPI_MOSI 		PB.2

#define SPI_SS		PB.4
#define SPI_CLK		PB.0
#define SPI_MOSI	PB.1
#define SPI_MISO    PB.3

#define LED_PIN	    PB.5		//闪灯在定时器中断函数里有做异或处理，改变LED驱动引脚时需要改变定时器中断函数里的异或方式

#define LED_OFF		LED_PIN = 0
#define LED_ON		LED_PIN = 1

#define OFF 0
#define ON  1

#define Drive_R		PA.6
#define Drive_L		PA.7
#define Drive_B		PA.4
#define Drive_F		PA.3

#define KEY			PB.2

//设备预定义
#define	WIRLESS_CMD_PACKLEN		0x07//数据包大小

#define SYNC_BYTE1       0x28 
#define SYNC_BYTE2       0x63  
#define SYNC_BYTE3       0x75  
#define SYNC_BYTE4       0x66  
#define SYNC_BYTE5       0x23  
#define SYNC_BYTE6       0x32  
#define SYNC_BYTE7       0x42
#define SYNC_BYTE8       0x98

#define RF_PLL_CH_NO     0x7F//f=2402+ RF_PLL_CH_NO---30

/***************************************************************/
//公共地址定义
#define Public_Address_0	0x5c
#define Public_Address_1	0x6e
#define Public_Address_2	0x54
#define Public_Address_3	0x9c
#define Public_Address_4	0x52
/********************************************************************************
*
	HS6200
*
********************************************************************************/

//-----------------RF command---------------------
#define HS6200_RD_REG						0x00 // Define read command to register
#define HS6200_WR_REG						0x20 // Define write command to register
#define HS6200_R_RX_PAYLOAD					0x61 // Define RX payload register address
#define HS6200_W_TX_PAYLOAD					0xA0 // Define TX payload register address
#define HS6200_FLUSH_TX						0xE1 // Define flush TX register command
#define HS6200_FLUSH_RX						0xE2 // Define flush RX register command
#define HS6200_REUSE_TX_PL					0xE3 // Define reuse TX payload register command
#define HS6200_ACTIVATE						0x50 // Define ACTIVATE features register command   
#define HS6200_R_RX_PL_WID					0x60 // Define read RX payload width register command
#define HS6200_W_ACK_PAYLOAD				0xA8 // Define write ACK payload register command
#define HS6200_W_TX_PAYLOAD_NOACK			0xB0 // Define disable TX ACK for one time register command
#define HS6200_NOP							0xFF // Define No Operation, might be used to read status register
#define HS6200_READ_STATUS					0xFF

#define HS6200_ACTIVATE_DATA				0x53


//----------------------defines--------------------------
//#define HS6200_BANK1						0x80
//#define HS6200_BANK0						0x00

//HS6200 Bank0 Register Addr
/**************************************************/               
#define HS6200_BANK0_CONFIG				0x00 // 'Config' register address
#define HS6200_BANK0_EN_AA				0x01 // 'Enable Auto Acknowledgment' register address
#define HS6200_BANK0_EN_RXADDR			0x02 // 'Enabled RX addresses' register address
#define HS6200_BANK0_SETUP_AW			0x03 // 'Setup address width' register address
#define HS6200_BANK0_SETUP_RETR			0x04 // 'Setup Auto. Retrans' register address
#define HS6200_BANK0_RF_CH				0x05 // 'RF channel' register address
#define HS6200_BANK0_RF_SETUP			0x06 // 'RF setup' register address
#define HS6200_BANK0_STATUS				0x07 // 'Status' register address
#define HS6200_BANK0_OBSERVE_TX			0x08 // 'Observe TX' register address
#define HS6200_BANK0_RPD				0x09 // 'Received Power Detector' register address
#define HS6200_BANK0_RX_ADDR_P0			0x0A // 'RX address pipe0' register address
#define HS6200_BANK0_RX_ADDR_P1			0x0B // 'RX address pipe1' register address
#define HS6200_BANK0_RX_ADDR_P2			0x0C // 'RX address pipe2' register address
#define HS6200_BANK0_RX_ADDR_P3			0x0D // 'RX address pipe3' register address
#define HS6200_BANK0_RX_ADDR_P4			0x0E // 'RX address pipe4' register address
#define HS6200_BANK0_RX_ADDR_P5			0x0F // 'RX address pipe5' register address
#define HS6200_BANK0_TX_ADDR			0x10 // 'TX address' register address
#define HS6200_BANK0_RX_PW_P0			0x11 // 'RX payload width, pipe0' register address
#define HS6200_BANK0_RX_PW_P1			0x12 // 'RX payload width, pipe1' register address
#define HS6200_BANK0_RX_PW_P2			0x13 // 'RX payload width, pipe2' register address
#define HS6200_BANK0_RX_PW_P3			0x14 // 'RX payload width, pipe3' register address
#define HS6200_BANK0_RX_PW_P4			0x15 // 'RX payload width, pipe4' register address
#define HS6200_BANK0_RX_PW_P5			0x16 // 'RX payload width, pipe5' register address
#define HS6200_BANK0_FIFO_STATUS		0x17 // 'FIFO Status Register' register address
#define HS6200_BANK0_DYNPD				0x1C // 'Enable dynamic payload length' register address
#define HS6200_BANK0_FEATURE			0x1D // 'Feature' register address
#define HS6200_BANK0_SETUP_VALUE		0x1E
#define HS6200_BANK0_PRE_GURD			0x1F


//HS6200 Bank1 register
#define HS6200_BANK1_LINE				0x00
#define HS6200_BANK1_PLL_CTL0			0x01
#define HS6200_BANK1_PLL_CTL1			0x02
#define HS6200_BANK1_CAL_CTL			0x03
#define HS6200_BANK1_A_CNT_REG			0x04
#define HS6200_BANK1_B_CNT_REG			0x05				
#define HS6200_BANK1_STATUS				0x07				
#define HS6200_BANK1_STATE				0x08				
#define HS6200_BANK1_CHAN				0x09				
#define HS6200_BANK1_IF_FREQ			0x0A				
#define HS6200_BANK1_AFC_COR			0x0B				
#define HS6200_BANK1_FDEV				0x0C				
#define HS6200_BANK1_DAC_RANGE			0x0D				
#define HS6200_BANK1_DAC_IN				0x0E				
#define HS6200_BANK1_CTUNING			0x0F				
#define HS6200_BANK1_FTUNING			0x10				
#define HS6200_BANK1_RX_CTRL			0x11				
#define HS6200_BANK1_FAGC_CTRL			0x12				
#define HS6200_BANK1_FAGC_CTRL_1		0x13				
#define HS6200_BANK1_DAC_CAL_LOW		0x17				
#define HS6200_BANK1_DAC_CAL_HI			0x18				
#define HS6200_BANK1_DOC_DACI			0x1A				
#define HS6200_BANK1_DOC_DACQ			0x1B				
#define HS6200_BANK1_AGC_CTRL			0x1C				
#define HS6200_BANK1_AGC_GAIN			0x1D				
#define HS6200_BANK1_RF_IVGEN			0x1E				
#define HS6200_BANK1_TEST_PKDET			0x1F	

/*register bit Mask define*/
/*R 0x17:*/
#define HS6200_FIFO_STA_TX_REUSE		0x40
#define HS6200_FIFO_STA_TX_FULL			0x20
#define HS6200_FIFO_STA_TX_EMPTY		0x10
#define HS6200_FIFO_STA_RX_FULL			0x02
#define HS6200_FIFO_STA_RX_EMPTY		0x01
/*R 0x07*/
#define HS6200_STATUS_RX_DR				0x40
#define HS6200_STATUS_TX_DS				0x20
#define HS6200_STATUS_MAX_RT			0x10
#define HS6200_STATUS_TX_FULL			0x01

/*pramr define*/
#define HS6200_FIFO_MAX_PACK_SIZE		0x20

//发送功率
#define HS6200_TR_2MKPS                         0x08
#define HS6200_TR_1MKPS                         0x00

#define HS6200_TR_MKPS                          HS6200_TR_1MKPS

enum {
	Rf_PRX_Mode = 0,
	Rf_PTX_Mode,
	Rf_Carrier_Mode,
	Rf_Bank0 = 0,
	Rf_Bank1
};

//=================================无线发送接口================================
extern void     Delay100US(void);
extern void	HS6200_CalibrationAndIntialize(void);
extern void	Wirless_Sleep(void);
extern void	Wirless_WeakUp(void);
extern void	Wirless_Init(void);
extern void	Wirless_SentKey(void);
extern void    SPI_WR_Byte(void);
extern void 	RW1600_spicmd_ReadReg(void);
extern void 	RW1600_spicmd_WriteReg(void);
extern void  	SPI_CE_LOW(void);
extern void	SPI_CE_HIGH(void);
extern void	RW1600_ModeSwitch(void);
extern void	Wirless_IOset(void);
extern void RW1600_start_TXsend_data(void);
extern void Set_TX_RX_ADDR(void);
extern void Set_Freq_Point(void);
