furi-hal-spi.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma once
  2. #include <furi-hal-spi-config.h>
  3. #include <stdbool.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /** Initialize SPI HAL */
  8. void furi_hal_spi_init();
  9. /** Initialize SPI Bus
  10. *
  11. * @param handle pointer to FuriHalSpiBus instance
  12. */
  13. void furi_hal_spi_bus_init(FuriHalSpiBus* bus);
  14. /** Deinitialize SPI Bus
  15. *
  16. * @param handle pointer to FuriHalSpiBus instance
  17. */
  18. void furi_hal_spi_bus_deinit(FuriHalSpiBus* bus);
  19. /** Initialize SPI Bus Handle
  20. *
  21. * @param handle pointer to FuriHalSpiBusHandle instance
  22. */
  23. void furi_hal_spi_bus_handle_init(FuriHalSpiBusHandle* handle);
  24. /** Deinitialize SPI Bus Handle
  25. *
  26. * @param handle pointer to FuriHalSpiBusHandle instance
  27. */
  28. void furi_hal_spi_bus_handle_deinit(FuriHalSpiBusHandle* handle);
  29. /** Acquire SPI bus
  30. *
  31. * @warning blocking, calls `furi_crash` on programming error, CS transition is up to handler event routine
  32. *
  33. * @param handle pointer to FuriHalSpiBusHandle instance
  34. */
  35. void furi_hal_spi_acquire(FuriHalSpiBusHandle* handle);
  36. /** Release SPI bus
  37. *
  38. * @warning calls `furi_crash` on programming error, CS transition is up to handler event routine
  39. *
  40. * @param handle pointer to FuriHalSpiBusHandle instance
  41. */
  42. void furi_hal_spi_release(FuriHalSpiBusHandle* handle);
  43. /** SPI Receive
  44. *
  45. * @param handle pointer to FuriHalSpiBusHandle instance
  46. * @param buffer receive buffer
  47. * @param size transaction size (buffer size)
  48. * @param timeout operation timeout in ms
  49. *
  50. * @return true on sucess
  51. */
  52. bool furi_hal_spi_bus_rx(FuriHalSpiBusHandle* handle, uint8_t* buffer, size_t size, uint32_t timeout);
  53. /** SPI Transmit
  54. *
  55. * @param handle pointer to FuriHalSpiBusHandle instance
  56. * @param buffer transmit buffer
  57. * @param size transaction size (buffer size)
  58. * @param timeout operation timeout in ms
  59. *
  60. * @return true on success
  61. */
  62. bool furi_hal_spi_bus_tx(FuriHalSpiBusHandle* handle, uint8_t* buffer, size_t size, uint32_t timeout);
  63. /** SPI Transmit and Receive
  64. *
  65. * @param handle pointer to FuriHalSpiBusHandle instance
  66. * @param tx_buffer pointer to tx buffer
  67. * @param rx_buffer pointer to rx buffer
  68. * @param size transaction size (buffer size)
  69. * @param timeout operation timeout in ms
  70. *
  71. * @return true on success
  72. */
  73. bool furi_hal_spi_bus_trx(FuriHalSpiBusHandle* handle, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
  74. #ifdef __cplusplus
  75. }
  76. #endif