/*
 * true's NRF24L01 C library
 * STM32L1xx interface driver header
 * basically: it's better than nothing
 */


#ifndef __TRUE_NRF24L01_STM32L1XX_H
#define __TRUE_NRF24L01_STM32L1XX_H



// include stm libraries
#include "stm32l1xx_conf.h"

// and the nrf libraries
#include "true_nrf24l01.h"


/********************/
/**** SPI SELECT ****/
  // which SPI to use?
#define _TRNRF_SPI_PORT_USE 		1
#define _TRNRF_SPI_BAUD 			SPI_BaudRatePrescaler_4

  // nRF24L01 CS (Chip Select) pin (SPI CS)
#define _TRNRF_SPI_CS_PORT 			GPIOD
#define _TRNRF_SPI_CS_PIN 			GPIO_Pin_2 		// PD2

  // nRF24L01 CE (Chip Enable) pin (handles RX/TX mode)
#define _TRNRF_nRF24_CE_PORT 		GPIOC
#define _TRNRF_nRF24_CE_PIN 		GPIO_Pin_10 	// PC10

  // nRF24L01 IRQ pin
#define _TRNRF_nRF24_IRQ_PORT 		GPIOC
#define _TRNRF_nRF24_IRQ_PIN 		GPIO_Pin_11 	// PC11


/********************/
/**** SPI CONFIG ****/
#if _TRNRF_SPI_PORT_USE == 1
	#define _TRNRF_SPI_PORT 		SPI1

	#define _TRNRF_SPI_GPIO_AF 		GPIO_AF_SPI1
	#define _TRNRF_SPI_GPIO_PORT 	GPIOB

	#define _TRNRF_SPI_SCK_PIN 		GPIO_Pin_3
	#define _TRNRF_SPI_MISO_PIN 	GPIO_Pin_4
	#define _TRNRF_SPI_MOSI_PIN 	GPIO_Pin_5
	#define _TRNRF_SPI_SCK_PINSRC 	GPIO_PinSource3
	#define _TRNRF_SPI_MISO_PINSRC 	GPIO_PinSource4
	#define _TRNRF_SPI_MOSI_PINSRC 	GPIO_PinSource5
#elif _TRNRF_SPI_PORT_USE == 2
	#define _TRNRF_SPI_PORT 		SPI2

	#define _TRNRF_SPI_GPIO_AF 		GPIO_AF_SPI2
	#define _TRNRF_SPI_GPIO_PORT 	GPIOB

	#define _TRNRF_SPI_SCK_PIN 		GPIO_Pin_13
	#define _TRNRF_SPI_MISO_PIN 	GPIO_Pin_14
	#define _TRNRF_SPI_MOSI_PIN 	GPIO_Pin_15
	#define _TRNRF_SPI_SCK_PINSRC 	GPIO_PinSource13
	#define _TRNRF_SPI_MISO_PINSRC 	GPIO_PinSource14
	#define _TRNRF_SPI_MOSI_PINSRC 	GPIO_PinSource15
#endif



/********************/
/**** PIN MACROS ****/
  // chip-enable (activates rx/tx modes)
#define _TRNRF_CE_L() 				GPIO_ResetBits(_TRNRF_nRF24_CE_PORT, _TRNRF_nRF24_CE_PIN)
#define _TRNRF_CE_H() 				GPIO_SetBits(_TRNRF_nRF24_CE_PORT, _TRNRF_nRF24_CE_PIN)

  // SPI chipselect
#define _TRNRF_CSN_L() 				GPIO_ResetBits(_TRNRF_SPI_CS_PORT, _TRNRF_SPI_CS_PIN)
#define _TRNRF_CSN_H() 				GPIO_SetBits(_TRNRF_SPI_CS_PORT, _TRNRF_SPI_CS_PIN)



/********************/
/**** PROTOTYPES ****/
void nRF24_driver_init();

uint8_t nRF24_spi_rw(uint8_t data);



#endif /* __TRUE_NRF24L01_STM32L1XX_H */
