platform.h 12 KB

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