prepare for esp32

This commit is contained in:
2021-10-11 16:37:30 +02:00
parent bb8deeb27d
commit 2cd9db9665
6 changed files with 45 additions and 28 deletions

View File

@@ -213,7 +213,7 @@ void drv95HF_ResetSPI(void);
uint8_t drv95HF_GetSerialInterface(void); uint8_t drv95HF_GetSerialInterface(void);
//int8_t drv95HF_GetIRQOutState(void); //int8_t drv95HF_GetIRQOutState(void);
void drv95HF_InitConfigStructure(void); void drv95HF_InitConfigStructure(void);
void drv95HF_InitilizeSerialInterface(void); void drv95HF_InitilizeSerialInterface(int8_t sck, int8_t miso, int8_t mosi, int8_t ss);
void drv95HF_ReceiveSPIResponse(uint8_t *pData); void drv95HF_ReceiveSPIResponse(uint8_t *pData);
void drv95HF_SendSPICommand(const uint8_t *pData ); void drv95HF_SendSPICommand(const uint8_t *pData );
int8_t drv95HF_SendReceive(const uint8_t *pCommand, uint8_t *pResponse); int8_t drv95HF_SendReceive(const uint8_t *pCommand, uint8_t *pResponse);

View File

@@ -37,6 +37,7 @@
#include "stdbool.h" #include "stdbool.h"
#include "drv_95HF.h" #include "drv_95HF.h"
#include "lib_pcd.h" #include "lib_pcd.h"
#include "Arduino.h"
/** @addtogroup BSP /** @addtogroup BSP
* @{ * @{
@@ -67,7 +68,7 @@ static int8_t drv95HF_SPIPollingCommand(void);
* @brief buffer to exchange data with the RF tranceiver. * @brief buffer to exchange data with the RF tranceiver.
*/ */
uint8_t u95HFBuffer [RFTRANS_95HF_MAX_BUFFER_SIZE+3]; uint8_t u95HFBuffer [RFTRANS_95HF_MAX_BUFFER_SIZE+3];
uint8_t sspin=0;
/** /**
* @brief This uTimeOut variable is used as a timeout duting the communication with the RF tranceiver * @brief This uTimeOut variable is used as a timeout duting the communication with the RF tranceiver
*/ */
@@ -91,9 +92,10 @@ drv95HF_ConfigStruct drv95HFConfig;
* @param None * @param None
* @retval void * @retval void
*/ */
static void drv95HF_InitializeSPI(void) static void drv95HF_InitializeSPI(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
{ {
RFTRANS_SPI_Init(); sspin = ss;
RFTRANS_SPI_Init(sck, miso, mosi, ss);
} }
/** /**
@@ -131,7 +133,7 @@ static int8_t drv95HF_SPIPollingCommand( void )
do do
{ {
/* Low level on NSS */ /* Low level on NSS */
RFTRANS_95HF_NSS_LOW(); RFTRANS_95HF_NSS_LOW(sspin);
delay(2); delay(2);
/* poll the 95HF transceiver until he's ready ! */ /* poll the 95HF transceiver until he's ready ! */
@@ -150,7 +152,7 @@ static int8_t drv95HF_SPIPollingCommand( void )
while( Polling_Status != RFTRANS_95HF_FLAG_DATA_READY && uTimeOut != true ); while( Polling_Status != RFTRANS_95HF_FLAG_DATA_READY && uTimeOut != true );
/* High level on NSS */ /* High level on NSS */
RFTRANS_95HF_NSS_HIGH(); RFTRANS_95HF_NSS_HIGH(sspin);
DEV_SPI.endTransaction(); DEV_SPI.endTransaction();
@@ -193,16 +195,16 @@ void drv95HF_InitConfigStructure (void)
void drv95HF_ResetSPI(void) void drv95HF_ResetSPI(void)
{ {
/* Deselect Rftransceiver over SPI */ /* Deselect Rftransceiver over SPI */
RFTRANS_95HF_NSS_HIGH(); RFTRANS_95HF_NSS_HIGH(sspin);
delay(1); delay(1);
DEV_SPI.beginTransaction(SPISettings(1500000, MSBFIRST, SPI_MODE3)); DEV_SPI.beginTransaction(SPISettings(1500000, MSBFIRST, SPI_MODE3));
/* Select 95HF device over SPI */ /* Select 95HF device over SPI */
RFTRANS_95HF_NSS_LOW(); RFTRANS_95HF_NSS_LOW(sspin);
/* Send reset control byte */ /* Send reset control byte */
drv95HF_SendSPIResetByte(); drv95HF_SendSPIResetByte();
/* Deselect 95HF device over SPI */ /* Deselect 95HF device over SPI */
RFTRANS_95HF_NSS_HIGH(); RFTRANS_95HF_NSS_HIGH(sspin);
DEV_SPI.endTransaction(); DEV_SPI.endTransaction();
@@ -250,7 +252,7 @@ void drv95HF_ResetSPI(void)
* @param None * @param None
* @retval None * @retval None
*/ */
void drv95HF_InitilizeSerialInterface(void) void drv95HF_InitilizeSerialInterface(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
{ {
/* -- Get interface pin state to select UART or SPI mode -- */ /* -- Get interface pin state to select UART or SPI mode -- */
//if (drv95HF_GetInterfacePinState() != RFTRANS_95HF_INTERFACE_UART) //if (drv95HF_GetInterfacePinState() != RFTRANS_95HF_INTERFACE_UART)
@@ -286,7 +288,7 @@ void drv95HF_SendSPICommand(const uint8_t *pData)
DEV_SPI.beginTransaction(SPISettings(1500000, MSBFIRST, SPI_MODE3)); DEV_SPI.beginTransaction(SPISettings(1500000, MSBFIRST, SPI_MODE3));
/* Select xx95HF over SPI */ /* Select xx95HF over SPI */
RFTRANS_95HF_NSS_LOW(); RFTRANS_95HF_NSS_LOW(sspin);
/* Send a sending request to xx95HF */ /* Send a sending request to xx95HF */
SPI_SendReceiveByte(RFTRANS_95HF_COMMAND_SEND); SPI_SendReceiveByte(RFTRANS_95HF_COMMAND_SEND);
@@ -303,7 +305,7 @@ void drv95HF_SendSPICommand(const uint8_t *pData)
} }
/* Deselect xx95HF over SPI */ /* Deselect xx95HF over SPI */
RFTRANS_95HF_NSS_HIGH(); RFTRANS_95HF_NSS_HIGH(sspin);
DEV_SPI.endTransaction(); DEV_SPI.endTransaction();
} }
@@ -322,7 +324,7 @@ void drv95HF_ReceiveSPIResponse(uint8_t *pData)
DEV_SPI.beginTransaction(SPISettings(1500000, MSBFIRST, SPI_MODE3)); DEV_SPI.beginTransaction(SPISettings(1500000, MSBFIRST, SPI_MODE3));
/* Select 95HF transceiver over SPI */ /* Select 95HF transceiver over SPI */
RFTRANS_95HF_NSS_LOW(); RFTRANS_95HF_NSS_LOW(sspin);
/* Request a response from 95HF transceiver */ /* Request a response from 95HF transceiver */
SPI_SendReceiveByte(RFTRANS_95HF_COMMAND_RECEIVE); SPI_SendReceiveByte(RFTRANS_95HF_COMMAND_RECEIVE);
@@ -353,7 +355,7 @@ void drv95HF_ReceiveSPIResponse(uint8_t *pData)
} }
/* Deselect xx95HF over SPI */ /* Deselect xx95HF over SPI */
RFTRANS_95HF_NSS_HIGH(); RFTRANS_95HF_NSS_HIGH(sspin);
DEV_SPI.endTransaction(); DEV_SPI.endTransaction();
} }

View File

@@ -32,6 +32,7 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "SPI.h" #include "SPI.h"
#include "drv_spi.h" #include "drv_spi.h"
#include "Arduino.h"
/** @addtogroup BSP /** @addtogroup BSP
* @{ * @{
@@ -55,27 +56,29 @@
* @param None * @param None
* @retval None * @retval None
*/ */
void RFTRANS_SPI_Init(void) uint8_t ss_pin = 0;
void RFTRANS_SPI_Init(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
{ {
// Configure NSS pin for CR95HF // Configure NSS pin for CR95HF
pinMode(10, OUTPUT); pinMode(ss, OUTPUT);
// Configure interface pin select for CR95HF // Configure interface pin select for CR95HF
pinMode(9, OUTPUT); //pinMode(9, OUTPUT);
// Configure interrupt input pin for CR95HF // Configure interrupt input pin for CR95HF
pinMode(8, OUTPUT); //pinMode(8, OUTPUT);
// Set the interface pin select high in order to configure the NFC reader to use the SPI interface // Set the interface pin select high in order to configure the NFC reader to use the SPI interface
digitalWrite(9, HIGH); //digitalWrite(9, HIGH);
/* SPI_NSS = High Level */ /* SPI_NSS = High Level */
RFTRANS_95HF_NSS_HIGH(); SPI_driveNSS_High();
/* Set signal to high */ /* Set signal to high */
RFTRANS_95HF_IRQIN_HIGH(); RFTRANS_95HF_IRQIN_HIGH();
DEV_SPI.begin(); DEV_SPI.begin(sck,miso, mosi, ss);
} }
/** /**
@@ -104,6 +107,16 @@ void SPI_SendReceiveBuffer(const uint8_t *pCommand, uint8_t length, uint8_t *pRe
} }
void SPI_driveNSS_High(void)
{
digitalWrite(ss_pin, 1);
}
void SPI_driveNSS_Low(void)
{
digitalWrite(ss_pin, 0);
}
/** /**
* @} * @}
*/ */

View File

@@ -52,8 +52,8 @@
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
#define DEV_SPI SPI #define DEV_SPI SPI
/* set state on SPI_NSS pin */ /* set state on SPI_NSS pin */
#define RFTRANS_95HF_NSS_LOW() digitalWrite(10, 0) //#define RFTRANS_95HF_NSS_LOW(pin) digitalWrite(pin, 0)
#define RFTRANS_95HF_NSS_HIGH() digitalWrite(10, 1) //#define RFTRANS_95HF_NSS_HIGH(pin) digitalWrite(pin, 1)
/* set state on IRQ_In pin */ /* set state on IRQ_In pin */
#define RFTRANS_95HF_IRQIN_LOW() digitalWrite(8, 0) #define RFTRANS_95HF_IRQIN_LOW() digitalWrite(8, 0)
#define RFTRANS_95HF_IRQIN_HIGH() digitalWrite(8, 1) #define RFTRANS_95HF_IRQIN_HIGH() digitalWrite(8, 1)
@@ -61,10 +61,12 @@
/** @defgroup X_NUCLEO_NFC03A1_Spi_Exported_Functions /** @defgroup X_NUCLEO_NFC03A1_Spi_Exported_Functions
* @{ * @{
*/ */
void RFTRANS_SPI_Init(void); void RFTRANS_SPI_Init(int8_t sck, int8_t miso, int8_t mosi, int8_t ss);
void SPI_SendReceiveBuffer(const uint8_t *pCommand, uint8_t length, uint8_t *pResponse); void SPI_SendReceiveBuffer(const uint8_t *pCommand, uint8_t length, uint8_t *pResponse);
uint8_t SPI_SendReceiveByte(uint8_t data); uint8_t SPI_SendReceiveByte(uint8_t data);
void SPI_driveNSS_High(void);
void SPI_driveNSS_Low(void);
/** /**
* @} * @}
*/ */

View File

@@ -82,13 +82,13 @@ uint8_t TagUID[16];
* @param None * @param None
* @retval None * @retval None
*/ */
static void ConfigManager_Init( void) static void ConfigManager_Init(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
{ {
/* initialize the structure of the Rf tranceiver */ /* initialize the structure of the Rf tranceiver */
drv95HF_InitConfigStructure (); drv95HF_InitConfigStructure ();
/* configure the Serial interface to communicate with the RF transceiver */ /* configure the Serial interface to communicate with the RF transceiver */
drv95HF_InitilizeSerialInterface ( ); drv95HF_InitilizeSerialInterface (sck, miso, mosi, ss );
} }
/** /**
@@ -192,7 +192,7 @@ void ConfigManager_Stop(void )
* @param None * @param None
* @retval None * @retval None
*/ */
void ConfigManager_HWInit (void) void ConfigManager_HWInit (int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
{ {
/* Initialize HW according to protocol to use */ /* Initialize HW according to protocol to use */

View File

@@ -97,7 +97,7 @@ typedef struct {
/* public function ----------------------------------------------------------------*/ /* public function ----------------------------------------------------------------*/
void ConfigManager_HWInit (void); void ConfigManager_HWInit (int8_t sck, int8_t miso, int8_t mosi, int8_t ss);
uint8_t ConfigManager_TagHunting ( uint8_t tagsToFind ); uint8_t ConfigManager_TagHunting ( uint8_t tagsToFind );