drv_soft_i2c.h 1.9 KB

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