furi-hal-spi.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #include "main.h"
  3. #include "furi-hal-spi-config.h"
  4. #include <furi-hal-gpio.h>
  5. #include <stdbool.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /**
  10. * Init SPI API
  11. */
  12. void furi_hal_spi_init();
  13. /* Bus Level API */
  14. /** Lock SPI bus
  15. * Takes bus mutex, if used
  16. */
  17. void furi_hal_spi_bus_lock(const FuriHalSpiBus* bus);
  18. /** Unlock SPI bus
  19. * Releases BUS mutex, if used
  20. */
  21. void furi_hal_spi_bus_unlock(const FuriHalSpiBus* bus);
  22. /**
  23. * Configure SPI bus
  24. * @param bus - spi bus handler
  25. * @param config - spi configuration structure
  26. */
  27. void furi_hal_spi_bus_configure(const FuriHalSpiBus* bus, const LL_SPI_InitTypeDef* config);
  28. /** SPI Receive
  29. * @param bus - spi bus handler
  30. * @param buffer - receive buffer
  31. * @param size - transaction size
  32. * @param timeout - bus operation timeout in ms
  33. */
  34. bool furi_hal_spi_bus_rx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
  35. /** SPI Transmit
  36. * @param bus - spi bus handler
  37. * @param buffer - transmit buffer
  38. * @param size - transaction size
  39. * @param timeout - bus operation timeout in ms
  40. */
  41. bool furi_hal_spi_bus_tx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
  42. /** SPI Transmit and Receive
  43. * @param bus - spi bus handlere
  44. * @param tx_buffer - device handle
  45. * @param rx_buffer - device handle
  46. * @param size - transaction size
  47. * @param timeout - bus operation timeout in ms
  48. */
  49. bool furi_hal_spi_bus_trx(const FuriHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
  50. /* Device Level API */
  51. /** Reconfigure SPI bus for device
  52. * @param device - device description
  53. */
  54. void furi_hal_spi_device_configure(const FuriHalSpiDevice* device);
  55. /** Get Device handle
  56. * And lock access to the corresponding SPI BUS
  57. * @param device_id - device identifier
  58. * @return device handle
  59. */
  60. const FuriHalSpiDevice* furi_hal_spi_device_get(FuriHalSpiDeviceId device_id);
  61. /** Return Device handle
  62. * And unlock access to the corresponding SPI BUS
  63. * @param device - device handle
  64. */
  65. void furi_hal_spi_device_return(const FuriHalSpiDevice* device);
  66. /** SPI Recieve
  67. * @param device - device handle
  68. * @param buffer - receive buffer
  69. * @param size - transaction size
  70. * @param timeout - bus operation timeout in ms
  71. */
  72. bool furi_hal_spi_device_rx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
  73. /** SPI Transmit
  74. * @param device - device handle
  75. * @param buffer - transmit buffer
  76. * @param size - transaction size
  77. * @param timeout - bus operation timeout in ms
  78. */
  79. bool furi_hal_spi_device_tx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
  80. /** SPI Transmit and Receive
  81. * @param device - device handle
  82. * @param tx_buffer - device handle
  83. * @param rx_buffer - device handle
  84. * @param size - transaction size
  85. * @param timeout - bus operation timeout in ms
  86. */
  87. bool furi_hal_spi_device_trx(const FuriHalSpiDevice* device, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
  88. #ifdef __cplusplus
  89. }
  90. #endif