furi-hal-i2c.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @file furi-hal-i2c.h
  3. * I2C HAL API
  4. */
  5. #pragma once
  6. #include <stdbool.h>
  7. #include <stdint.h>
  8. #include <furi-hal-i2c-config.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /** Init I2C
  13. */
  14. void furi_hal_i2c_init();
  15. /** Acquire i2c bus handle
  16. *
  17. * @return Instance of FuriHalI2cBus
  18. */
  19. void furi_hal_i2c_acquire(FuriHalI2cBusHandle* handle);
  20. /** Release i2c bus handle
  21. *
  22. * @param bus instance of FuriHalI2cBus aquired in `furi_hal_i2c_acquire`
  23. */
  24. void furi_hal_i2c_release(FuriHalI2cBusHandle* handle);
  25. /** Perform I2C tx transfer
  26. *
  27. * @param handle pointer to FuriHalI2cBusHandle instance
  28. * @param address I2C slave address
  29. * @param data pointer to data buffer
  30. * @param size size of data buffer
  31. * @param timeout timeout in ticks
  32. *
  33. * @return true on successful transfer, false otherwise
  34. */
  35. bool furi_hal_i2c_tx(
  36. FuriHalI2cBusHandle* handle,
  37. const uint8_t address,
  38. const uint8_t* data,
  39. const uint8_t size,
  40. uint32_t timeout);
  41. /** Perform I2C rx transfer
  42. *
  43. * @param handle pointer to FuriHalI2cBusHandle instance
  44. * @param address I2C slave address
  45. * @param data pointer to data buffer
  46. * @param size size of data buffer
  47. * @param timeout timeout in ticks
  48. *
  49. * @return true on successful transfer, false otherwise
  50. */
  51. bool furi_hal_i2c_rx(
  52. FuriHalI2cBusHandle* handle,
  53. const uint8_t address,
  54. uint8_t* data,
  55. const uint8_t size,
  56. uint32_t timeout);
  57. /** Perform I2C tx and rx transfers
  58. *
  59. * @param handle pointer to FuriHalI2cBusHandle instance
  60. * @param address I2C slave address
  61. * @param tx_data pointer to tx data buffer
  62. * @param tx_size size of tx data buffer
  63. * @param rx_data pointer to rx data buffer
  64. * @param rx_size size of rx data buffer
  65. * @param timeout timeout in ticks
  66. *
  67. * @return true on successful transfer, false otherwise
  68. */
  69. bool furi_hal_i2c_trx(
  70. FuriHalI2cBusHandle* handle,
  71. const uint8_t address,
  72. const uint8_t* tx_data,
  73. const uint8_t tx_size,
  74. uint8_t* rx_data,
  75. const uint8_t rx_size,
  76. uint32_t timeout);
  77. #ifdef __cplusplus
  78. }
  79. #endif