gd_i2c.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*!
  2. *******************************************************************************
  3. **
  4. ** \file gd_i2c.h
  5. **
  6. ** \brief I2C.
  7. **
  8. ** Copyright: 2012 - 2013 (C) GoKe Microelectronics ShangHai Branch
  9. **
  10. ** \attention THIS SAMPLE CODE IS PROVIDED AS IS. GOKE MICROELECTRONICS
  11. ** ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
  12. ** OMMISSIONS.
  13. **
  14. ** \note Do not modify this file as it is generated automatically.
  15. **
  16. ******************************************************************************/
  17. #ifndef _GD_I2C_H_
  18. #define _GD_I2C_H_
  19. #include "gmodids.h"
  20. //*****************************************************************************
  21. //*****************************************************************************
  22. //** Defines and Macros
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. #define GD_I2C_ERR_BASE (GD_I2C_MODULE_ID << 16)
  26. //*****************************************************************************
  27. //*****************************************************************************
  28. //** Enumerated types
  29. //*****************************************************************************
  30. //*****************************************************************************
  31. /*!
  32. *******************************************************************************
  33. **
  34. ** \brief I2C driver error codes.
  35. **
  36. *******************************************************************************
  37. */
  38. enum
  39. {
  40. GD_ERR_I2C_TYPE_NOT_SUPPORTED = GD_I2C_ERR_BASE, //!< Device not supported.
  41. GD_ERR_I2C_INT_ERR,
  42. GD_ERR_I2C_NOT_OPEN,
  43. GD_ERR_I2C_NOACK,
  44. GD_ERR_I2C_START_NOACK,
  45. GD_ERR_I2C_RESTART_NOACK,
  46. GD_ERR_I2C_ADDR_NOACK,
  47. GD_ERR_I2C_DATA_NOACK,
  48. GD_ERR_I2C_READ_NOACK,
  49. GD_ERR_I2C_SL_NACK,
  50. GD_ERR_I2C_BUSY,
  51. GD_ERR_I2C_FIFO_OVERFLOW,
  52. };
  53. /*---------------------------------------------------------------------------*/
  54. /* types, enums and structures */
  55. /*---------------------------------------------------------------------------*/
  56. /*!
  57. *******************************************************************************
  58. **
  59. ** \brief I2C channel number.
  60. **
  61. ** \sa GD_I2C_OPEN_PARAMS_S
  62. **
  63. ******************************************************************************/
  64. typedef enum
  65. {
  66. GD_I2C_CHANNEL_ONE = 0, //!< I2C channel 1.
  67. GD_I2C_CHANNEL_TWO, //!< I2C channel 2.
  68. }GD_I2C_CHANNEL_E;
  69. /*!
  70. *******************************************************************************
  71. **
  72. ** \brief I2C operition modes.
  73. **
  74. ** \sa GD_I2C_INIT_PARAMS_S
  75. **
  76. ******************************************************************************/
  77. typedef enum
  78. {
  79. GD_I2C_GENERIC_MASTER_MODE, //!< Generic master mode.
  80. GD_I2C_GENERIC_SLAVER_MODE, //!< Generic slave mode.
  81. GD_I2C_AUTO_MASTER_MODE, //!< Auto master mode.
  82. GD_I2C_AUTO_SLAVER_MODE, //!< Auto slave mode.
  83. GD_I2C_DMA_MASTER_MODE, //!< DMA master mode.
  84. GD_I2C_DMA_SLAVER_MODE, //!< DMA slave mode.
  85. }GD_I2C_OPEN_MODE_E;
  86. /*!
  87. *******************************************************************************
  88. **
  89. ** \brief Protocol modes.
  90. **
  91. ** \sa GD_I2C_SetProtocol()
  92. **
  93. ******************************************************************************/
  94. typedef enum
  95. {
  96. GD_I2C_COMMON_PROTOCOL = 0, //!< Common protocol.
  97. GD_I2C_RESTART_PROTOCOL, //!< Protocol with restart.
  98. } GD_I2C_PROTOCOL_E;
  99. /*!
  100. *******************************************************************************
  101. **
  102. ** \brief I2C datarate speed modes.
  103. **
  104. ** \sa GD_I2C_OPEN_PARAMS_S
  105. **
  106. ******************************************************************************/
  107. typedef enum
  108. {
  109. GD_I2C_100KBPS = 100000, //!< 100kHz datarate.
  110. GD_I2C_400KBPS = 400000, //!< 400kHz datarate.
  111. }GD_I2C_SPEED_E;
  112. /*!
  113. *******************************************************************************
  114. **
  115. ** \brief I2C datarate speed modes.
  116. **
  117. ** \sa GD_I2C_OPEN_PARAMS_S
  118. **
  119. ******************************************************************************/
  120. typedef enum
  121. {
  122. GD_I2C_NORMAL = 0,
  123. GD_I2C_TURBO_MODE, // write operation only.
  124. GD_I2C_INTERRUPT,
  125. }GD_I2C_MODE_E;
  126. //*****************************************************************************
  127. //*****************************************************************************
  128. //** Data Structures
  129. //*****************************************************************************
  130. //*****************************************************************************
  131. /*!
  132. *******************************************************************************
  133. **
  134. ** \brief Init parameters.
  135. **
  136. ** \sa GD_I2C_Init() <BR>
  137. ** GD_I2C_OPEN_MODE_E
  138. **
  139. ******************************************************************************/
  140. typedef struct
  141. {
  142. GD_I2C_OPEN_MODE_E mode; //!< Operation mode.
  143. S8 priority; //!< IRQ priority e.g. \c #GD_INT_LOW_PRIORITY.
  144. S8 gpioSdaPinCh1; //!< GPIO SDA pin assigmnet channel 1.
  145. S8 gpioSclPinCh1; //!< GPIO SCL pin assigmnet channel 1.
  146. S8 gpioSdaPinCh2; //!< For future use.
  147. S8 gpioSclPinCh2; //!< For future use.
  148. }GD_I2C_INIT_PARAMS_S;
  149. typedef struct
  150. {
  151. GD_I2C_CHANNEL_E channel;
  152. GD_I2C_SPEED_E speed;
  153. GD_I2C_MODE_E mode;
  154. } GD_I2C_OPEN_PARAMS_S;
  155. //*****************************************************************************
  156. //*****************************************************************************
  157. //** Global Data
  158. //*****************************************************************************
  159. //*****************************************************************************
  160. //*****************************************************************************
  161. //*****************************************************************************
  162. //** API Functions
  163. //*****************************************************************************
  164. //*****************************************************************************
  165. #ifdef __cplusplus
  166. extern "C" {
  167. #endif
  168. GERR GD_I2C_Init(GD_I2C_INIT_PARAMS_S* paramsP);
  169. GERR GD_I2C_Exit(void);
  170. GERR GD_I2C_Open(GD_I2C_OPEN_PARAMS_S * openParamsP, GD_HANDLE* pHandle );
  171. GERR GD_I2C_Close(GD_HANDLE * pHandle);
  172. GERR GD_I2C_Read(GD_HANDLE *pHandle,U8 address,U8* regbuffer,U32 regbytes,U8 * buffer,U32 bytes);
  173. GERR GD_I2C_Write(GD_HANDLE *pHandle,U8 address,U8 * buffer,U32 bytes);
  174. GERR GD_I2C_SetOperationMode(GD_I2C_CHANNEL_E channel,GD_I2C_OPEN_MODE_E operationMode);
  175. GERR GD_I2C_SetProtocol(GD_HANDLE *handleP,GD_I2C_PROTOCOL_E protocol);
  176. GERR GD_I2C_SetMode(GD_HANDLE *handleP,GD_I2C_MODE_E Mode);
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. #endif /* _GD_I2C_H_ */
  181. /*----------------------------------------------------------------------------*/
  182. /* end of file */
  183. /*----------------------------------------------------------------------------*/