drv_hard_i2c.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-02-17 Dyyt587 first version
  9. */
  10. #ifndef __DRV_HARD_I2C_H__
  11. #define __DRV_HARD_I2C_H__
  12. #include "drv_config.h"
  13. #include <rtthread.h>
  14. #include "rtdevice.h"
  15. #include <rthw.h>
  16. #include <drv_common.h>
  17. #include "drv_dma.h"
  18. #include <ipc/completion.h>
  19. #ifdef (RT_USING_I2C && BSP_USING_I2C)
  20. /* C binding of definitions if building with C++ compiler */
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. struct stm32_i2c_config
  26. {
  27. const char *name;
  28. I2C_TypeDef *Instance;
  29. rt_uint32_t timing;
  30. rt_uint32_t timeout;
  31. IRQn_Type evirq_type;
  32. IRQn_Type erirq_type;
  33. struct dma_config *dma_rx, *dma_tx;
  34. };
  35. struct stm32_i2c
  36. {
  37. I2C_HandleTypeDef handle;
  38. struct
  39. {
  40. DMA_HandleTypeDef handle_rx;
  41. DMA_HandleTypeDef handle_tx;
  42. } dma;
  43. struct stm32_i2c_config *config;
  44. struct rt_i2c_bus_device i2c_bus;
  45. rt_uint8_t i2c_dma_flag;
  46. struct rt_completion completion;
  47. };
  48. #define I2C_USING_TX_DMA_FLAG (1U)
  49. #define I2C_USING_RX_DMA_FLAG (1U << 1)
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. #endif /* BSP_USING_I2C */
  54. #endif /* __DRV_I2C_H__ */