api-hal-i2c.h 955 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <stdint.h>
  4. #include <api-hal-resources.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. void api_hal_i2c_init();
  9. void api_hal_i2c_tx(I2C_TypeDef* instance, const uint8_t address, const uint8_t *data, const uint8_t size);
  10. void api_hal_i2c_rx(I2C_TypeDef* instance, const uint8_t address, uint8_t *data, const uint8_t size);
  11. void api_hal_i2c_trx(
  12. I2C_TypeDef* instance, const uint8_t address,
  13. const uint8_t *tx_data, const uint8_t tx_size,
  14. uint8_t *rx_data, const uint8_t rx_size
  15. );
  16. void api_hal_i2c_lock();
  17. void api_hal_i2c_unlock();
  18. #define with_api_hal_i2c(type, pointer, function_body) \
  19. { \
  20. api_hal_i2c_lock(); \
  21. *pointer = ({ type __fn__ function_body __fn__; })(); \
  22. api_hal_i2c_unlock(); \
  23. }
  24. #ifdef __cplusplus
  25. }
  26. #endif