platform.h 8.9 KB

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