api-hal-spi.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include "main.h"
  3. #include "api-hal-spi-config.h"
  4. #include <api-hal-gpio.h>
  5. #include <stdbool.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /**
  10. * Init SPI API
  11. */
  12. void api_hal_spi_init();
  13. /* Bus Level API */
  14. /** Lock SPI bus
  15. * Takes bus mutex, if used
  16. */
  17. void api_hal_spi_bus_lock(const ApiHalSpiBus* bus);
  18. /** Unlock SPI bus
  19. * Releases BUS mutex, if used
  20. */
  21. void api_hal_spi_bus_unlock(const ApiHalSpiBus* bus);
  22. /** SPI Receive
  23. * @param bus - spi bus handler
  24. * @param buffer - receive buffer
  25. * @param size - transaction size
  26. * @param timeout - bus operation timeout in ms
  27. */
  28. bool api_hal_spi_bus_rx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
  29. /** SPI Transmit
  30. * @param bus - spi bus handler
  31. * @param buffer - transmit buffer
  32. * @param size - transaction size
  33. * @param timeout - bus operation timeout in ms
  34. */
  35. bool api_hal_spi_bus_tx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
  36. /** SPI Transmit and Receive
  37. * @param bus - spi bus handlere
  38. * @param tx_buffer - device handle
  39. * @param rx_buffer - device handle
  40. * @param size - transaction size
  41. * @param timeout - bus operation timeout in ms
  42. */
  43. bool api_hal_spi_bus_trx(const ApiHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
  44. /* Device Level API */
  45. /** Get Device handle
  46. * And lock access to the corresponding SPI BUS
  47. * @param device_id - device identifier
  48. * @return device handle
  49. */
  50. const ApiHalSpiDevice* api_hal_spi_device_get(ApiHalSpiDeviceId device_id);
  51. /** Return Device handle
  52. * And unlock access to the corresponding SPI BUS
  53. * @param device - device handle
  54. */
  55. void api_hal_spi_device_return(const ApiHalSpiDevice* device);
  56. /** SPI Recieve
  57. * @param device - device handle
  58. * @param buffer - receive buffer
  59. * @param size - transaction size
  60. * @param timeout - bus operation timeout in ms
  61. */
  62. bool api_hal_spi_device_rx(const ApiHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
  63. /** SPI Transmit
  64. * @param device - device handle
  65. * @param buffer - transmit buffer
  66. * @param size - transaction size
  67. * @param timeout - bus operation timeout in ms
  68. */
  69. bool api_hal_spi_device_tx(const ApiHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
  70. /** SPI Transmit and Receive
  71. * @param device - device handle
  72. * @param tx_buffer - device handle
  73. * @param rx_buffer - device handle
  74. * @param size - transaction size
  75. * @param timeout - bus operation timeout in ms
  76. */
  77. bool api_hal_spi_device_trx(const ApiHalSpiDevice* device, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
  78. /**
  79. * Lock SPI device bus and apply config if needed
  80. */
  81. void api_hal_spi_lock_device(const SPIDevice* device);
  82. /**
  83. * Unlock SPI device bus
  84. */
  85. void api_hal_spi_unlock_device(const SPIDevice* device);
  86. #ifdef __cplusplus
  87. }
  88. #endif