/**
  ******************************************************************************
  * @file           : nfc_conf.h
  * @brief          : This file contains definitions for the NFC12 components bus interfaces
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2026 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __NFC0XA1_CONF_H__
#define __NFC0XA1_CONF_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "stm32wbaxx_hal.h"
#include "stm32wbaxx_nucleo_bus.h"
#include "stm32wbaxx_nucleo_errno.h"
#include "stm32wbaxx_hal_exti.h"
#include "RTE_Components.h"
#include "rfal_defConfig.h"

#define TEST               4
#define TEST_LINE          EXTI4_IRQn

#define TEST_RFAL_DEFAULT

#define TESTED_VAR_OK_BMP

#define LED_FIELD_Pin 1         /*!< Enable usage of led field pin on the platform      */
#define LED_FIELD_GPIO_Port 1   /*!< Enable usage of led field port on the platform     */
#define USE_LOGGER 1

#define NFC12A1_LED_A_PIN_CLK_ENABLE()     __HAL_RCC_GPIOC_CLK_ENABLE()
#define NFC12A1_LED_B_PIN_CLK_ENABLE()     __HAL_RCC_GPIOA_CLK_ENABLE()
#define NFC12A1_LED_F_PIN_CLK_ENABLE()     __HAL_RCC_GPIOD_CLK_ENABLE()
#define NFC12A1_LED_V_PIN_CLK_ENABLE()     __HAL_RCC_GPIOB_CLK_ENABLE()
#define NFC12A1_LED_FIELD_PIN_CLK_ENABLE()     __HAL_RCC_GPIOA_CLK_ENABLE()
#define NFC12A1_LED_A_PIN                  GPIO_PIN_4
#define NFC12A1_LED_A_PIN_PORT             GPIOC
#define NFC12A1_LED_B_PIN                  GPIO_PIN_6
#define NFC12A1_LED_B_PIN_PORT             GPIOA
#define NFC12A1_LED_F_PIN                  GPIO_PIN_14
#define NFC12A1_LED_F_PIN_PORT             GPIOD
#define NFC12A1_LED_V_PIN                  GPIO_PIN_0
#define NFC12A1_LED_V_PIN_PORT             GPIOB
#define NFC12A1_LED_FIELD_PIN              GPIO_PIN_1
#define NFC12A1_LED_FIELD_PIN_PORT         GPIOA

#define NFC12A1_ALLLED_GPIO_CLK_ENABLE() {NFC12A1_LED_A_PIN_CLK_ENABLE();NFC12A1_LED_B_PIN_CLK_ENABLE();NFC12A1_LED_F_PIN_CLK_ENABLE();NFC12A1_LED_V_PIN_CLK_ENABLE();NFC12A1_LED_FIELD_PIN_CLK_ENABLE();}
#define NFC12A1_NFCTAG_INSTANCE         (0)
#define NFC12A1_NFCTAG_GPO_PRIORITY     (0)

#ifdef LED_FIELD_Pin
/* Case of ST25R500 */
#define PLATFORM_LED_FIELD_PIN       GPIO_PIN_1         /*!< GPIO pin used as field LED                        */
#endif /* LED_FIELD_Pin */

#ifdef LED_FIELD_GPIO_Port
/* Case of ST25R500 */
#define PLATFORM_LED_FIELD_PORT       GPIOA    /*!< GPIO port used as field LED                       */
#endif  /* LED_FIELD_GPIO_Port */

/* Case of ST25R500 */
#define PLATFORM_LED_A_PIN           GPIO_PIN_4         /*!< GPIO pin used for LED A    */
#define PLATFORM_LED_A_PORT          GPIOC    /*!< GPIO port used for LED A   */
#define PLATFORM_LED_B_PIN           GPIO_PIN_6         /*!< GPIO pin used for LED B    */
#define PLATFORM_LED_B_PORT          GPIOA    /*!< GPIO port used for LED B   */
#define PLATFORM_LED_F_PIN           GPIO_PIN_14         /*!< GPIO pin used for LED F    */
#define PLATFORM_LED_F_PORT          GPIOD    /*!< GPIO port used for LED F   */
#define PLATFORM_LED_V_PIN           GPIO_PIN_0         /*!< GPIO pin used for LED V    */
#define PLATFORM_LED_V_PORT          GPIOB    /*!< GPIO port used for LED V   */

#define BUS_SPI2_NSS_GPIO_PIN           GPIO_PIN_9
#define BUS_SPI2_NSS_GPIO_PORT          GPIOB
#define BUS_SPI2_IRQ_GPIO_PIN           GPIO_PIN_4
#define BUS_SPI2_IRQ_GPIO_PORT          GPIOA
#define BUS_SPI2_RST_GPIO_PIN           GPIO_PIN_10
#define BUS_SPI2_RST_GPIO_PORT          GPIOA

/* Exported constants --------------------------------------------------------*/
/** @defgroup PTD_Platform_Exported_Constants
  *  @{
  */
#define ST25R_SS_PIN             BUS_SPI2_NSS_GPIO_PIN    /*!< GPIO pin used for ST25R SPI SS                */
#define ST25R_SS_PORT            BUS_SPI2_NSS_GPIO_PORT   /*!< GPIO port used for ST25R SPI SS port          */

#define ST25R_INT_PIN            BUS_SPI2_IRQ_GPIO_PIN    /*!< GPIO pin used for ST25R IRQ                   */
#define ST25R_INT_PORT           BUS_SPI2_IRQ_GPIO_PORT   /*!< GPIO port used for ST25R IRQ port             */

#define IRQ_ST25R_EXTI_IRQn      EXTI4_IRQn

#define PLATFORM_USER_BUTTON_PIN     USER_BUTTON_PIN          /*!< GPIO pin user button       */
#define PLATFORM_USER_BUTTON_PORT    USER_BUTTON_GPIO_PORT    /*!< GPIO port user button      */

#define USR_INT_LINE             H_EXTI_4
#define USR_INT_LINE_NUM         EXTI_LINE_4
#define BSP_NFC0XCOMM_Init             BSP_SPI2_Init
//#define BSP_NFC0XCOMM_IRQ_Callback     BSP_SPI2_IRQ_Callback

#define BSP_NFC0XCOMM_SequencialSend  BSP_SPI2_SequencialSend
#define BSP_NFC0XCOMM_SequencialRecv  BSP_SPI2_SequencialRecv

void BSP_SPI2_IRQ_Callback(void);

/**
  * @}
  */

/**
  * @}
  */

/*
******************************************************************************
* GLOBAL VARIABLES
******************************************************************************
*/

/* Exported variables --------------------------------------------------------*/
extern SPI_HandleTypeDef hspi2;

extern uint8_t globalCommProtectCnt;
extern  EXTI_HandleTypeDef H_EXTI_4;
/* Exported functions ------------------------------------------------------- */
int32_t BSP_NFC0XCOMM_SendRecv(const uint8_t *const pTxData, uint8_t *const pRxData, uint16_t Length);

int32_t BSP_NFC0XCOMM_Init(void);

#define  COMM_HANDLE                                     hspi2

void _Error_Handler(char *file, int line);

#ifdef __cplusplus
}
#endif

#endif /* __NFC0XA1_CONF_H__*/

