furi-hal-spi.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. /** Configure SPI bus
  23. * @param bus - spi bus handler
  24. * @param config - spi configuration structure
  25. */
  26. void furi_hal_spi_bus_configure(const FuriHalSpiBus* bus, const LL_SPI_InitTypeDef* config);
  27. /** SPI Receive
  28. * @param bus - spi bus handler
  29. * @param buffer - receive buffer
  30. * @param size - transaction size
  31. * @param timeout - bus operation timeout in ms
  32. */
  33. bool furi_hal_spi_bus_rx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
  34. /** SPI Transmit
  35. * @param bus - spi bus handler
  36. * @param buffer - transmit buffer
  37. * @param size - transaction size
  38. * @param timeout - bus operation timeout in ms
  39. */
  40. bool furi_hal_spi_bus_tx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
  41. /** SPI Transmit and Receive
  42. * @param bus - spi bus handlere
  43. * @param tx_buffer - device handle
  44. * @param rx_buffer - device handle
  45. * @param size - transaction size
  46. * @param timeout - bus operation timeout in ms
  47. */
  48. bool furi_hal_spi_bus_trx(const FuriHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
  49. /* Device Level API */
  50. /** Reconfigure SPI bus for device
  51. * @param device - device description
  52. */
  53. void furi_hal_spi_device_configure(const FuriHalSpiDevice* device);
  54. /** Get Device handle
  55. * And lock access to the corresponding SPI BUS
  56. * @param device_id - device identifier
  57. * @return device handle
  58. */
  59. const FuriHalSpiDevice* furi_hal_spi_device_get(FuriHalSpiDeviceId device_id);
  60. /** Return Device handle
  61. * And unlock access to the corresponding SPI BUS
  62. * @param device - device handle
  63. */
  64. void furi_hal_spi_device_return(const FuriHalSpiDevice* device);
  65. /** SPI Recieve
  66. * @param device - device handle
  67. * @param buffer - receive buffer
  68. * @param size - transaction size
  69. * @param timeout - bus operation timeout in ms
  70. */
  71. bool furi_hal_spi_device_rx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
  72. /** SPI Transmit
  73. * @param device - device handle
  74. * @param buffer - transmit buffer
  75. * @param size - transaction size
  76. * @param timeout - bus operation timeout in ms
  77. */
  78. bool furi_hal_spi_device_tx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
  79. /** SPI Transmit and Receive
  80. * @param device - device handle
  81. * @param tx_buffer - device handle
  82. * @param rx_buffer - device handle
  83. * @param size - transaction size
  84. * @param timeout - bus operation timeout in ms
  85. */
  86. bool furi_hal_spi_device_trx(const FuriHalSpiDevice* device, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
  87. #ifdef __cplusplus
  88. }
  89. #endif