drv_soft_i2c.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-08 balanceTWK first version
  9. */
  10. #ifndef __DRV_I2C__
  11. #define __DRV_I2C__
  12. #include <rtthread.h>
  13. #include <rthw.h>
  14. #include <rtdevice.h>
  15. /* stm32 config class */
  16. struct stm32_soft_i2c_config
  17. {
  18. rt_uint8_t scl;
  19. rt_uint8_t sda;
  20. const char *bus_name;
  21. };
  22. /* stm32 i2c dirver class */
  23. struct stm32_i2c
  24. {
  25. struct rt_i2c_bit_ops ops;
  26. struct rt_i2c_bus_device i2c2_bus;
  27. };
  28. #ifdef BSP_USING_I2C1
  29. #define I2C1_BUS_CONFIG \
  30. { \
  31. .scl = BSP_I2C1_SCL_PIN, \
  32. .sda = BSP_I2C1_SDA_PIN, \
  33. .bus_name = "i2c1", \
  34. }
  35. #endif
  36. #ifdef BSP_USING_I2C2
  37. #define I2C2_BUS_CONFIG \
  38. { \
  39. .scl = BSP_I2C2_SCL_PIN, \
  40. .sda = BSP_I2C2_SDA_PIN, \
  41. .bus_name = "i2c2", \
  42. }
  43. #endif
  44. #ifdef BSP_USING_I2C3
  45. #define I2C3_BUS_CONFIG \
  46. { \
  47. .scl = BSP_I2C3_SCL_PIN, \
  48. .sda = BSP_I2C3_SDA_PIN, \
  49. .bus_name = "i2c3", \
  50. }
  51. #endif
  52. #ifdef BSP_USING_I2C4
  53. #define I2C4_BUS_CONFIG \
  54. { \
  55. .scl = BSP_I2C4_SCL_PIN, \
  56. .sda = BSP_I2C4_SDA_PIN, \
  57. .bus_name = "i2c4", \
  58. }
  59. #endif
  60. int rt_hw_i2c_init(void);
  61. #endif