drv_i2c.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * 2021-01-13 Lyons first version
  9. * 2021-06-23 RiceChen refactor
  10. */
  11. #ifndef __DRV_I2C_H__
  12. #define __DRV_I2C_H__
  13. #include <board.h>
  14. #include "drv_common.h"
  15. #include "fsl_iomuxc.h"
  16. #include "fsl_clock.h"
  17. #include "fsl_i2c.h"
  18. #define IMX_I2C_IRQ_MODE
  19. struct imx6ull_i2c_config
  20. {
  21. void *hw_base; /* hardware physical address base */
  22. I2C_Type *I2C;
  23. char *name;
  24. rt_uint32_t baud_rate;
  25. rt_uint32_t clk_ip_name;
  26. rt_uint32_t irq_num;
  27. struct imx6ull_iomuxc scl_gpio;
  28. struct imx6ull_iomuxc sda_gpio;
  29. i2c_master_handle_t master_handle;
  30. };
  31. struct imx6ull_i2c_bus
  32. {
  33. struct rt_i2c_bus_device parent;
  34. struct imx6ull_i2c_config *config;
  35. };
  36. #ifdef BSP_USING_I2C1
  37. #define I2C1_BUS_CONFIG \
  38. { \
  39. .I2C = I2C1, \
  40. .name = "i2c1", \
  41. .clk_ip_name = kCLOCK_I2c1S, \
  42. .baud_rate = I2C1_BAUD_RATE, \
  43. .irq_num = IMX_INT_I2C1, \
  44. .scl_gpio = {IOMUXC_UART4_TX_DATA_I2C1_SCL, 1, 0x70B0}, \
  45. .sda_gpio = {IOMUXC_UART4_RX_DATA_I2C1_SDA, 1, 0x70B0}, \
  46. }
  47. #endif /* BSP_USING_I2C1 */
  48. #ifdef BSP_USING_I2C2
  49. #define I2C2_BUS_CONFIG \
  50. { \
  51. .I2C = I2C2, \
  52. .name = "i2c2", \
  53. .clk_ip_name = kCLOCK_I2c2S, \
  54. .baud_rate = I2C2_BAUD_RATE, \
  55. .irq_num = IMX_INT_I2C2, \
  56. .scl_gpio = {IOMUXC_UART5_TX_DATA_I2C2_SCL, 1, 0x70B0}, \
  57. .sda_gpio = {IOMUXC_UART5_RX_DATA_I2C2_SDA, 1, 0x70B0}, \
  58. }
  59. #endif /* BSP_USING_I2C2 */
  60. #ifdef BSP_USING_I2C3
  61. #define I2C3_BUS_CONFIG \
  62. { \
  63. .I2C = I2C3, \
  64. .name = "i2c3", \
  65. .clk_ip_name = kCLOCK_I2c3S, \
  66. .baud_rate = I2C3_BAUD_RATE, \
  67. .irq_num = IMX_INT_I2C3, \
  68. .scl_gpio = {IOMUXC_ENET2_RX_DATA0_I2C3_SCL, 1, 0x70B0}, \
  69. .sda_gpio = {IOMUXC_ENET2_RX_DATA1_I2C3_SDA, 1, 0x70B0}, \
  70. }
  71. #endif /* BSP_USING_I2C3 */
  72. #ifdef BSP_USING_I2C4
  73. #define I2C4_BUS_CONFIG \
  74. { \
  75. .I2C = I2C4, \
  76. .name = "i2c4", \
  77. .clk_ip_name = kCLOCK_I2c4S, \
  78. .baud_rate = I2C4_BAUD_RATE, \
  79. .irq_num = IMX_INT_I2C4, \
  80. .scl_gpio = {IOMUXC_UART2_TX_DATA_I2C4_SCL, 1, 0x70B0}, \
  81. .sda_gpio = {IOMUXC_UART2_RX_DATA_I2C4_SDA, 1, 0x70B0}, \
  82. }
  83. #endif /* BSP_USING_I2C4 */
  84. #endif