drv_soft_i2c.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-10-30 CDT first version
  9. */
  10. #ifndef __DRV_I2C_H__
  11. #define __DRV_I2C_H__
  12. /*******************************************************************************
  13. * Include files
  14. ******************************************************************************/
  15. #include <rtdevice.h>
  16. #include "hc32_ddl.h"
  17. /* C binding of definitions if building with C++ compiler */
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. /*******************************************************************************
  23. * Global type definitions ('typedef')
  24. ******************************************************************************/
  25. struct hc32_soft_i2c_config
  26. {
  27. rt_uint16_t scl_pin;
  28. rt_uint16_t sda_pin;
  29. const char *bus_name;
  30. };
  31. #ifdef BSP_USING_I2C1
  32. #define I2C1_BUS_CONFIG \
  33. { \
  34. .scl_pin = BSP_I2C1_SCL_PIN, \
  35. .sda_pin = BSP_I2C1_SDA_PIN, \
  36. .bus_name = "i2c1", \
  37. }
  38. #endif
  39. #ifdef BSP_USING_I2C2
  40. #define I2C2_BUS_CONFIG \
  41. { \
  42. .scl = BSP_I2C2_SCL_PIN, \
  43. .sda = BSP_I2C2_SDA_PIN, \
  44. .bus_name = "i2c2", \
  45. }
  46. #endif
  47. #ifdef BSP_USING_I2C3
  48. #define I2C3_BUS_CONFIG \
  49. { \
  50. .scl = BSP_I2C3_SCL_PIN, \
  51. .sda = BSP_I2C3_SDA_PIN, \
  52. .bus_name = "i2c3", \
  53. }
  54. #endif
  55. #ifdef BSP_USING_I2C4
  56. #define I2C4_BUS_CONFIG \
  57. { \
  58. .scl = BSP_I2C4_SCL_PIN, \
  59. .sda = BSP_I2C4_SDA_PIN, \
  60. .bus_name = "i2c4", \
  61. }
  62. #endif
  63. #ifdef BSP_USING_I2C5
  64. #define I2C5_BUS_CONFIG \
  65. { \
  66. .scl = BSP_I2C5_SCL_PIN, \
  67. .sda = BSP_I2C5_SDA_PIN, \
  68. .bus_name = "i2c5", \
  69. }
  70. #endif
  71. #ifdef BSP_USING_I2C6
  72. #define I2C6_BUS_CONFIG \
  73. { \
  74. .scl = BSP_I2C6_SCL_PIN, \
  75. .sda = BSP_I2C6_SDA_PIN, \
  76. .bus_name = "i2c6", \
  77. }
  78. #endif
  79. /**
  80. *******************************************************************************
  81. ** \brief Open parameters.
  82. *******************************************************************************
  83. */
  84. struct hc32_i2c_config
  85. {
  86. rt_uint8_t scl;
  87. rt_uint8_t sda;
  88. const char *bus_name;
  89. };
  90. struct hc32_i2c
  91. {
  92. struct rt_i2c_bit_ops ops;
  93. struct rt_i2c_bus_device i2c1_bus;
  94. };
  95. typedef struct hc32_i2c_instance
  96. {
  97. rt_uint32_t id;
  98. void *handle;
  99. stc_i2c_init_t init;
  100. } hc32_i2c_instance_t;
  101. int hc32_hw_i2c_init(void);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* __DRV_I2C_H__ */
  106. /*******************************************************************************
  107. * EOF (not truncated)
  108. ******************************************************************************/