drv_soft_i2c.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-12-20 BruceOu the first version
  9. */
  10. #ifndef __DRV_I2C__
  11. #define __DRV_I2C__
  12. #include <rtthread.h>
  13. #include <rthw.h>
  14. #include <rtdevice.h>
  15. #include <board.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* gd32 config class */
  20. struct gd32_soft_i2c_config
  21. {
  22. rt_uint8_t scl;
  23. rt_uint8_t sda;
  24. const char *bus_name;
  25. };
  26. /* gd32 i2c dirver class */
  27. struct gd32_i2c
  28. {
  29. struct rt_i2c_bit_ops ops;
  30. struct rt_i2c_bus_device i2c_bus;
  31. };
  32. #ifdef BSP_USING_I2C0
  33. #define I2C0_BUS_CONFIG \
  34. { \
  35. .scl = BSP_I2C0_SCL_PIN, \
  36. .sda = BSP_I2C0_SDA_PIN, \
  37. .bus_name = "i2c0", \
  38. }
  39. #endif
  40. #ifdef BSP_USING_I2C1
  41. #define I2C1_BUS_CONFIG \
  42. { \
  43. .scl = BSP_I2C1_SCL_PIN, \
  44. .sda = BSP_I2C1_SDA_PIN, \
  45. .bus_name = "i2c1", \
  46. }
  47. #endif
  48. #ifdef BSP_USING_I2C2
  49. #define I2C2_BUS_CONFIG \
  50. { \
  51. .scl = BSP_I2C2_SCL_PIN, \
  52. .sda = BSP_I2C2_SDA_PIN, \
  53. .bus_name = "i2c2", \
  54. }
  55. #endif
  56. #ifdef BSP_USING_I2C3
  57. #define I2C3_BUS_CONFIG \
  58. { \
  59. .scl = BSP_I2C3_SCL_PIN, \
  60. .sda = BSP_I2C3_SDA_PIN, \
  61. .bus_name = "i2c3", \
  62. }
  63. #endif
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* __DRV_I2C__ */