platform.h 8.8 KB

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