platform.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. #include <stdbool.h>
  5. #include <limits.h>
  6. #include <cmsis_os2.h>
  7. #include <gpio.h>
  8. #include "timer.h"
  9. #include "math.h"
  10. #include "spi.h"
  11. #include "main.h"
  12. #include <api-hal.h>
  13. typedef void (*PlatformIrqCallback)();
  14. void platformSetIrqCallback(PlatformIrqCallback cb);
  15. HAL_StatusTypeDef platformSpiTxRx(const uint8_t *txBuf, uint8_t *rxBuf, uint16_t len);
  16. void platformProtectST25RComm();
  17. void platformUnprotectST25RComm();
  18. #define ST25R_SS_PIN NFC_CS_Pin
  19. #define ST25R_SS_PORT NFC_CS_GPIO_Port
  20. #define ST25R_INT_PIN NFC_IRQ_Pin
  21. #define ST25R_INT_PORT NFC_IRQ_GPIO_Port
  22. #define PLATFORM_LED_RX_PIN LightRed
  23. #define PLATFORM_LED_RX_PORT NULL
  24. #define PLATFORM_LED_FIELD_PIN LightBlue
  25. #define PLATFORM_LED_FIELD_PORT NULL
  26. #define RFAL_FEATURE_LISTEN_MODE true /*!< Enable/Disable RFAL support for Listen Mode */
  27. #define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable/Disable RFAL support for the Wake-Up mode */
  28. #define RFAL_FEATURE_LOWPOWER_MODE true /*!< Enable/Disable RFAL support for the Low Power mode */
  29. #define RFAL_FEATURE_NFCA true /*!< Enable/Disable RFAL support for NFC-A (ISO14443A) */
  30. #define RFAL_FEATURE_NFCB true /*!< Enable/Disable RFAL support for NFC-B (ISO14443B) */
  31. #define RFAL_FEATURE_NFCF true /*!< Enable/Disable RFAL support for NFC-F (FeliCa) */
  32. #define RFAL_FEATURE_NFCV true /*!< Enable/Disable RFAL support for NFC-V (ISO15693) */
  33. #define RFAL_FEATURE_T1T true /*!< Enable/Disable RFAL support for T1T (Topaz) */
  34. #define RFAL_FEATURE_T2T true /*!< Enable/Disable RFAL support for T2T (MIFARE Ultralight) */
  35. #define RFAL_FEATURE_T4T true /*!< Enable/Disable RFAL support for T4T */
  36. #define RFAL_FEATURE_ST25TB true /*!< Enable/Disable RFAL support for ST25TB */
  37. #define RFAL_FEATURE_ST25xV true /*!< Enable/Disable RFAL support for ST25TV/ST25DV */
  38. #define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Enable/Disable Analog Configs to be dynamically updated (RAM) */
  39. #define RFAL_FEATURE_DPO false /*!< Enable/Disable RFAL Dynamic Power Output upport */
  40. #define RFAL_FEATURE_ISO_DEP true /*!< Enable/Disable RFAL support for ISO-DEP (ISO14443-4) */
  41. #define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable/Disable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */
  42. #define RFAL_FEATURE_ISO_DEP_LISTEN true /*!< Enable/Disable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */
  43. #define RFAL_FEATURE_NFC_DEP true /*!< Enable/Disable RFAL support for NFC-DEP (NFCIP1/P2P) */
  44. #define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */
  45. #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 254U /*!< NFC-DEP Block/Payload length. Allowed values: 64, 128, 192, 254 */
  46. #define RFAL_FEATURE_NFC_RF_BUF_LEN 256U /*!< RF buffer length used by RFAL NFC layer */
  47. #define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 512U /*!< ISO-DEP APDU max length. */
  48. #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 512U /*!< NFC-DEP PDU max length. */
  49. #define platformIrqST25RSetCallback( cb ) platformSetIrqCallback(cb)
  50. #define platformProtectST25RIrqStatus() platformProtectST25RComm() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
  51. #define platformUnprotectST25RIrqStatus() platformUnprotectST25RComm() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
  52. #define platformLedOff( port, pin ) api_hal_light_set(pin, 0x00)
  53. #define platformLedOn( port, pin ) api_hal_light_set(pin, 0xFF)
  54. #define platformGpioSet( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET) /*!< Turns the given GPIO High */
  55. #define platformGpioClear( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET) /*!< Turns the given GPIO Low */
  56. #define platformGpioToogle( port, pin ) HAL_GPIO_TogglePin(port, pin) /*!< Toogles the given GPIO */
  57. #define platformGpioIsHigh( port, pin ) (HAL_GPIO_ReadPin(port, pin) == GPIO_PIN_SET) /*!< Checks if the given LED is High */
  58. #define platformGpioIsLow( port, pin ) (!platformGpioIsHigh(port, pin)) /*!< Checks if the given LED is Low */
  59. #define platformTimerCreate( t ) timerCalculateTimer(t) /*!< Create a timer with the given time (ms) */
  60. #define platformTimerIsExpired( timer ) timerIsExpired(timer) /*!< Checks if the given timer is expired */
  61. #define platformDelay( t ) osDelay( t ) /*!< Performs a delay for the given time (ms) */
  62. #define platformGetSysTick() osKernelGetTickCount() /*!< Get System Tick (1 tick = 1 ms) */
  63. #define platformAssert( exp ) assert_param( exp ) /*!< Asserts whether the given expression is true*/
  64. #define platformSpiSelect() platformGpioClear( ST25R_SS_PORT, ST25R_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Select */
  65. #define platformSpiDeselect() platformGpioSet( ST25R_SS_PORT, ST25R_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Deselect */
  66. #define platformI2CTx( txBuf, len, last, txOnly ) /*!< I2C Transmit */
  67. #define platformI2CRx( txBuf, len ) /*!< I2C Receive */
  68. #define platformI2CStart() /*!< I2C Start condition */
  69. #define platformI2CStop() /*!< I2C Stop condition */
  70. #define platformI2CRepeatStart() /*!< I2C Repeat Start */
  71. #define platformI2CSlaveAddrWR(add) /*!< I2C Slave address for Write operation */
  72. #define platformI2CSlaveAddrRD(add) /*!< I2C Slave address for Read operation */
  73. #define platformLog(...) /*!< Log method */
  74. /*
  75. ******************************************************************************
  76. * RFAL OPTIONAL MACROS (Do not change)
  77. ******************************************************************************
  78. */
  79. #ifndef platformProtectST25RIrqStatus
  80. #define platformProtectST25RIrqStatus() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
  81. #endif /* platformProtectST25RIrqStatus */
  82. #ifndef platformUnprotectST25RIrqStatus
  83. #define platformUnprotectST25RIrqStatus() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
  84. #endif /* platformUnprotectST25RIrqStatus */
  85. #ifndef platformProtectWorker
  86. #define platformProtectWorker() /* Protect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
  87. #endif /* platformProtectWorker */
  88. #ifndef platformUnprotectWorker
  89. #define platformUnprotectWorker() /* Unprotect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
  90. #endif /* platformUnprotectWorker */
  91. #ifndef platformIrqST25RPinInitialize
  92. #define platformIrqST25RPinInitialize() /*!< Initializes ST25R IRQ pin */
  93. #endif /* platformIrqST25RPinInitialize */
  94. #ifndef platformIrqST25RSetCallback
  95. #define platformIrqST25RSetCallback( cb ) /*!< Sets ST25R ISR callback */
  96. #endif /* platformIrqST25RSetCallback */
  97. #ifndef platformLedsInitialize
  98. #define platformLedsInitialize() /*!< Initializes the pins used as LEDs to outputs */
  99. #endif /* platformLedsInitialize */
  100. #ifndef platformLedOff
  101. #define platformLedOff( port, pin ) /*!< Turns the given LED Off */
  102. #endif /* platformLedOff */
  103. #ifndef platformLedOn
  104. #define platformLedOn( port, pin ) /*!< Turns the given LED On */
  105. #endif /* platformLedOn */
  106. #ifndef platformLedToogle
  107. #define platformLedToogle( port, pin ) /*!< Toggles the given LED */
  108. #endif /* platformLedToogle */
  109. #ifndef platformGetSysTick
  110. #define platformGetSysTick() /*!< Get System Tick (1 tick = 1 ms) */
  111. #endif /* platformGetSysTick */
  112. #ifndef platformTimerDestroy
  113. #define platformTimerDestroy( timer ) /*!< Stops and released the given timer */
  114. #endif /* platformTimerDestroy */
  115. #ifndef platformAssert
  116. #define platformAssert( exp ) /*!< Asserts whether the given expression is true */
  117. #endif /* platformAssert */
  118. #ifndef platformErrorHandle
  119. #define platformErrorHandle() /*!< Global error handler or trap */
  120. #endif /* platformErrorHandle */