furi_hal_spi.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #pragma once
  2. #include <furi_hal_spi_config.h>
  3. #include <stdbool.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /** Early initialize SPI HAL */
  8. void furi_hal_spi_config_init_early();
  9. /** Early deinitialize SPI HAL */
  10. void furi_hal_spi_config_deinit_early();
  11. /** Initialize SPI HAL */
  12. void furi_hal_spi_config_init();
  13. /** Initialize SPI DMA HAL */
  14. void furi_hal_spi_dma_init();
  15. /** Initialize SPI Bus
  16. *
  17. * @param handle pointer to FuriHalSpiBus instance
  18. */
  19. void furi_hal_spi_bus_init(FuriHalSpiBus* bus);
  20. /** Deinitialize SPI Bus
  21. *
  22. * @param handle pointer to FuriHalSpiBus instance
  23. */
  24. void furi_hal_spi_bus_deinit(FuriHalSpiBus* bus);
  25. /** Initialize SPI Bus Handle
  26. *
  27. * @param handle pointer to FuriHalSpiBusHandle instance
  28. */
  29. void furi_hal_spi_bus_handle_init(FuriHalSpiBusHandle* handle);
  30. /** Deinitialize SPI Bus Handle
  31. *
  32. * @param handle pointer to FuriHalSpiBusHandle instance
  33. */
  34. void furi_hal_spi_bus_handle_deinit(FuriHalSpiBusHandle* handle);
  35. /** Acquire SPI bus
  36. *
  37. * @warning blocking, calls `furi_crash` on programming error, CS transition is up to handler event routine
  38. *
  39. * @param handle pointer to FuriHalSpiBusHandle instance
  40. */
  41. void furi_hal_spi_acquire(FuriHalSpiBusHandle* handle);
  42. /** Release SPI bus
  43. *
  44. * @warning calls `furi_crash` on programming error, CS transition is up to handler event routine
  45. *
  46. * @param handle pointer to FuriHalSpiBusHandle instance
  47. */
  48. void furi_hal_spi_release(FuriHalSpiBusHandle* handle);
  49. /** SPI Receive
  50. *
  51. * @param handle pointer to FuriHalSpiBusHandle instance
  52. * @param buffer receive buffer
  53. * @param size transaction size (buffer size)
  54. * @param timeout operation timeout in ms
  55. *
  56. * @return true on sucess
  57. */
  58. bool furi_hal_spi_bus_rx(
  59. FuriHalSpiBusHandle* handle,
  60. uint8_t* buffer,
  61. size_t size,
  62. uint32_t timeout);
  63. /** SPI Transmit
  64. *
  65. * @param handle pointer to FuriHalSpiBusHandle instance
  66. * @param buffer transmit buffer
  67. * @param size transaction size (buffer size)
  68. * @param timeout operation timeout in ms
  69. *
  70. * @return true on success
  71. */
  72. bool furi_hal_spi_bus_tx(
  73. FuriHalSpiBusHandle* handle,
  74. const uint8_t* buffer,
  75. size_t size,
  76. uint32_t timeout);
  77. /** SPI Transmit and Receive
  78. *
  79. * @param handle pointer to FuriHalSpiBusHandle instance
  80. * @param tx_buffer pointer to tx buffer
  81. * @param rx_buffer pointer to rx buffer
  82. * @param size transaction size (buffer size)
  83. * @param timeout operation timeout in ms
  84. *
  85. * @return true on success
  86. */
  87. bool furi_hal_spi_bus_trx(
  88. FuriHalSpiBusHandle* handle,
  89. const uint8_t* tx_buffer,
  90. uint8_t* rx_buffer,
  91. size_t size,
  92. uint32_t timeout);
  93. /** SPI Transmit and Receive with DMA
  94. *
  95. * @param handle pointer to FuriHalSpiBusHandle instance
  96. * @param tx_buffer pointer to tx buffer
  97. * @param rx_buffer pointer to rx buffer
  98. * @param size transaction size (buffer size)
  99. * @param timeout_ms operation timeout in ms
  100. *
  101. * @return true on success
  102. */
  103. bool furi_hal_spi_bus_trx_dma(
  104. FuriHalSpiBusHandle* handle,
  105. uint8_t* tx_buffer,
  106. uint8_t* rx_buffer,
  107. size_t size,
  108. uint32_t timeout_ms);
  109. #ifdef __cplusplus
  110. }
  111. #endif