drv_i2c.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * File : drv_i2c.h
  3. * This file is part of gkipc BSP for RT-Thread distribution.
  4. *
  5. * Copyright (c) 2017 ChengDu goke Microelectronics Co., Ltd.
  6. * All rights reserved
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * Visit http://www.goke.com to get contact with goke.
  23. *
  24. * Change Logs:
  25. * Date Author Notes
  26. */
  27. #ifndef _I2C_H_
  28. #define _I2C_H_
  29. #include <rtthread.h>
  30. /*!
  31. *******************************************************************************
  32. ** \brief I2C channel number.
  33. *******************************************************************************
  34. */
  35. typedef enum
  36. {
  37. RT_I2C_CHANNEL_ONE = 0, /*!< I2C channel 1.*/
  38. RT_I2C_CHANNEL_TWO, /*!< I2C channel 2.*/
  39. }RT_I2C_ChannelT;
  40. /*!
  41. *******************************************************************************
  42. ** \brief I2C operition modes.
  43. *******************************************************************************
  44. */
  45. typedef enum
  46. {
  47. RT_I2C_GENERIC_MASTER_MODE, /*!< Generic master mode.*/
  48. RT_I2C_GENERIC_SLAVER_MODE, /*!< Generic slave mode.*/
  49. RT_I2C_AUTO_MASTER_MODE, /*!< Auto master mode.*/
  50. RT_I2C_AUTO_SLAVER_MODE, /*!< Auto slave mode.*/
  51. RT_I2C_DMA_MASTER_MODE, /*!< DMA master mode.*/
  52. RT_I2C_DMA_SLAVER_MODE, /*!< DMA slave mode.*/
  53. }RT_I2C_OpenModeT;
  54. /*!
  55. *******************************************************************************
  56. ** \brief Protocol modes.
  57. *******************************************************************************
  58. */
  59. typedef enum
  60. {
  61. RT_I2C_COMMON_PROTOCOL = 0, /*!< Common protocol.*/
  62. RT_I2C_RESTART_PROTOCOL, /*!< Protocol with restart.*/
  63. }RT_I2C_ProtocolT;
  64. /*!
  65. *******************************************************************************
  66. ** \brief I2C datarate speed modes.
  67. *******************************************************************************
  68. */
  69. typedef enum
  70. {
  71. RT_I2C_100KBPS = 100000, /*!< 100kHz datarate.*/
  72. RT_I2C_400KBPS = 400000, /*!< 400kHz datarate.*/
  73. }RT_I2C_SpeedT;
  74. /*!
  75. *******************************************************************************
  76. ** \brief I2C transmit modes.
  77. *******************************************************************************
  78. */
  79. typedef enum
  80. {
  81. RT_I2C_NORMAL = 0,
  82. RT_I2C_TURBO_MODE, // write operation only.
  83. RT_I2C_INTERRUPT,
  84. }RT_I2C_ModeT;
  85. /*!
  86. *******************************************************************************
  87. ** \brief Init parameters.
  88. *******************************************************************************
  89. */
  90. typedef struct
  91. {
  92. RT_I2C_OpenModeT mode; /*!< Operation mode.*/
  93. rt_int8_t priority; /*!< IRQ priority */
  94. rt_int8_t gpioSdaPinCh1; /*!< GPIO SDA pin assigmnet channel 1.*/
  95. rt_int8_t gpioSclPinCh1; /*!< GPIO SCL pin assigmnet channel 1.*/
  96. rt_int8_t gpioSdaPinCh2; /*!< For future use.*/
  97. rt_int8_t gpioSclPinCh2; /*!< For future use.*/
  98. }RT_I2C_InitParamsT;
  99. /*!
  100. *******************************************************************************
  101. ** \brief Open parameters.
  102. *******************************************************************************
  103. */
  104. typedef struct
  105. {
  106. RT_I2C_ChannelT channel; /*!< i2c channel index*/
  107. RT_I2C_SpeedT speed; /*!< i2c speed*/
  108. RT_I2C_ModeT mode; /*!< i2c mode*/
  109. }RT_I2C_OpenParamsT;
  110. typedef struct gk_i2c_config
  111. {
  112. RT_I2C_InitParamsT i2cInitParams;
  113. }gk_i2c_config_s;
  114. typedef struct gk_i2c_obj
  115. {
  116. rt_uint32_t id;
  117. rt_uint32_t handle;
  118. rt_mutex_t lock;
  119. gk_i2c_config_s config;
  120. }gk_i2c_obj_s;
  121. void rt_hw_i2c_init(void);
  122. #endif/*_I2C_H_*/