hv_drv_I2c.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * @file hv_drv_I2c.c
  3. * @brief i2c driver layer file.
  4. * @details This file provides the following functions: \n
  5. * (1) i2c master tx/rx \n
  6. * (2) i2c savle tx/rx \n
  7. * (3) i2c init \n
  8. *
  9. * @author HiView SoC Software Team
  10. * @version 1.0.0
  11. * @date 2023-05-08
  12. * @copyright Copyright(c),2023-5, Hiview Software. All rights reserved.
  13. * @par History:
  14. * <table>
  15. * <tr><th>Author <th>Date <th>Change Description
  16. * <tr><td>HiView SoC Software Team <td>2023-05-08 <td>init
  17. * </table>
  18. */
  19. #include "Common/hv_comm_DataType.h"
  20. #include "hv_comm_Define.h"
  21. #include "hv_cal_I2c.h"
  22. #include "hv_drv_I2c.h"
  23. #include "hv_chip_Config.h"
  24. #include "hv_vos_Comm.h"
  25. /** Initialize i2c
  26. * @param pstInitParam pointer to i2c configuration parameters
  27. * @return i2c handler
  28. */
  29. HvCalI2c* Hv_Drv_I2C_Init(I2cInitParam *pstInitParam)
  30. {
  31. return Hv_Cal_I2C_Init(pstInitParam);
  32. }
  33. /** Set i2c transfer speed
  34. * @param pstSelf i2c handler
  35. * @param enI2cSpeed i2c transfer speed
  36. */
  37. void Hv_Drv_I2c_Setpeed(HvCalI2c *pstSelf, I2cSpeed enI2cSpeed)
  38. {
  39. return Hv_Cal_I2C_Setpeed(pstSelf, enI2cSpeed);
  40. }
  41. /** De-initialize i2c
  42. * @param pstSelf i2c handler
  43. * @return result
  44. */
  45. Status Hv_Drv_I2C_Cleanup(HvCalI2c *pstSelf)
  46. {
  47. return Hv_Cal_I2C_Cleanup(pstSelf);
  48. }
  49. USHORT16 Hv_Drv_I2C_GetRxDataCount(HvCalI2c *pstSelf)
  50. {
  51. return Hv_Cal_I2C_GetRxDataCount(pstSelf);
  52. }
  53. /** Transmits in master mode an amount of data in blocking mode.
  54. * @param pstSelf i2c handler
  55. * @param pstParam target device address
  56. * pointer to command data buffer
  57. * command length
  58. * pointer to data buffer to be transmited
  59. * amount of data to be sent
  60. * @param uiTimeout uiTimeout duration
  61. * @retval Status
  62. */
  63. Status Hv_Drv_I2C_MasterPollingTransmit(HvCalI2c *pstSelf, I2cFuncParam *pstParam, UINT32 uiTimeout)
  64. {
  65. return Hv_Cal_I2C_MasterPollingTransmit(pstSelf, pstParam, uiTimeout);
  66. }
  67. /** Transmit in master mode an amount of data in non-blocking mode with interrupt
  68. * @param pstSelf i2c handler
  69. * @param pstParam target device address
  70. * pointer to command data buffer
  71. * command length
  72. * pointer to data buffer to be transmited
  73. * amount of data to be sent
  74. * @retval Status
  75. */
  76. Status Hv_Drv_I2C_MasterIntTransmit(HvCalI2c *pstSelf, I2cFuncParam *pstParam)
  77. {
  78. return Hv_Cal_I2C_MasterIntTransmit(pstSelf, pstParam);
  79. }
  80. /** Receives in master mode an amount of data in blocking mode.
  81. * @param pstSelf i2c handler
  82. * @param pstParam target device address
  83. * pointer to command data buffer
  84. * command length
  85. * pointer to data buffer to be receive
  86. * amount of data to be receive
  87. * @param uiTimeout uiTimeout duration
  88. * @retval Status
  89. */
  90. Status Hv_Drv_I2C_MasterPollingReceive(HvCalI2c *pstSelf, I2cFuncParam *pstParam, UINT32 uiTimeout)
  91. {
  92. return Hv_Cal_I2C_MasterPollingReceive(pstSelf, pstParam, uiTimeout);
  93. }
  94. /** Receive in master mode an amount of data in non-blocking mode with interrupt
  95. * @param pstSelf i2c handler
  96. * @param pstParam target device address
  97. * pointer to command data buffer
  98. * command length
  99. * pointer to data buffer to be receive
  100. * amount of data to be receive
  101. * @retval Status
  102. */
  103. Status Hv_Drv_I2C_MasterIntReceive(HvCalI2c *pstSelf, I2cFuncParam *pstParam)
  104. {
  105. return Hv_Cal_I2C_MasterIntReceive(pstSelf, pstParam);
  106. }
  107. /** Transmits in slave mode an amount of data in blocking mode.
  108. * @param pstSelf i2c handler
  109. * @param pucData pointer to data buffer
  110. * @param usSize amount of data to be sent
  111. * @param uiTimeout uiTimeout duration
  112. * @retval Status
  113. */
  114. Status Hv_Drv_I2C_SlavePollingTransmit(HvCalI2c *pstSelf, UCHAR8 *pucData, USHORT16 usSize, UINT32 uiTimeout)
  115. {
  116. return Hv_Cal_I2C_SlavePollingTransmit(pstSelf, pucData, usSize, uiTimeout);
  117. }
  118. /** Transmit in slave mode an amount of data in non-blocking mode with interrupt
  119. * @param pstSelf i2c handler
  120. * @param pucData pointer to data buffer
  121. * @param usSize amount of data to be sent
  122. * @retval Status
  123. */
  124. Status Hv_Drv_I2C_SlaveIntTransmit(HvCalI2c *pstSelf, UCHAR8 *pucData, USHORT16 usSize)
  125. {
  126. return Hv_Cal_I2C_SlaveIntTransmit(pstSelf, pucData, usSize);
  127. }
  128. /** Receive in slave mode an amount of data in blocking mode
  129. * @param pstSelf i2c handler
  130. * @param pucData pointer to data buffer
  131. * @param usSize amount of data to be sent
  132. * @param uiTimeout uiTimeout duration
  133. * @retval Status
  134. */
  135. Status Hv_Drv_I2C_SlavePollingReceive(HvCalI2c *pstSelf, UCHAR8 *pucData, USHORT16 usSize, UINT32 uiTimeout)
  136. {
  137. return Hv_Cal_I2C_SlavePollingReceive(pstSelf, pucData, usSize, uiTimeout);
  138. }
  139. /** Receive in slave mode an amount of data in non-blocking mode with interrupt
  140. * @param pstSelf i2c handler
  141. * @param pucData pointer to data buffer
  142. * @param usSize amount of data to be sent
  143. * @retval Status
  144. */
  145. Status Hv_Drv_I2C_SlaveIntReceive(HvCalI2c *pstSelf, UCHAR8 *pucData)
  146. {
  147. return Hv_Cal_I2C_SlaveIntReceive(pstSelf, pucData);
  148. }
  149. /** Receive in slave mode an amount of data in non-blocking mode with interrupt
  150. * @param pstSelf i2c handler
  151. * @retval is or not
  152. */
  153. BOOL Hv_Drv_I2C_TransferIsComplete(HvCalI2c *pstSelf)
  154. {
  155. return Hv_Cal_I2C_TransferIsComplete(pstSelf);
  156. }