drv_i2c.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_I2C_H_
  13. #define _DRV_I2C_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @brief i2c bps enumeration
  22. */
  23. typedef enum
  24. {
  25. DRV_I2C_BPS_100K, ///< normal 100Kbps
  26. DRV_I2C_BPS_400K, ///< fast 400Kbps
  27. DRV_I2C_BPS_3P5M, ///< high speed 3.5Mbps
  28. } drvI2cBps_t;
  29. /**
  30. * @brief i2c slave definition
  31. */
  32. typedef struct
  33. {
  34. uint8_t addr_device; ///< device address
  35. uint8_t addr_data; ///< data high 8 bits
  36. uint8_t addr_data_low; ///< data low 8 bits
  37. bool reg_16bit; ///< true:16bit reg address;false:8bit reg address
  38. } drvI2cSlave_t;
  39. struct drvI2cMaster;
  40. /**
  41. * @brief the i2c master indicator
  42. */
  43. typedef struct drvI2cMaster drvI2cMaster_t;
  44. /**
  45. * @brief acquire the i2c master
  46. *
  47. * @param name name of the i2c master
  48. * @param bps the i2c speed
  49. * @return
  50. * - (NULL) fail
  51. * - otherwise the i2c master instance
  52. */
  53. drvI2cMaster_t *drvI2cMasterAcquire(uint32_t name, drvI2cBps_t bps);
  54. /**
  55. * @brief release the i2c master
  56. *
  57. * @param i2c the i2c master
  58. */
  59. void drvI2cMasterRelease(drvI2cMaster_t *i2c);
  60. /**
  61. * @brief i2c master send data
  62. *
  63. * @param i2c the i2c master
  64. * @param slave the i2c slave
  65. * @param data data to send
  66. * @param length data length
  67. * @return
  68. * - true success
  69. * - false fail
  70. */
  71. bool drvI2cWrite(drvI2cMaster_t *i2c, const drvI2cSlave_t *slave, const uint8_t *data, uint32_t length);
  72. /**
  73. * @brief i2c master get data
  74. *
  75. * @param i2c the i2c master
  76. * @param slave the i2c slave
  77. * @param buf buffer to receive data
  78. * @param length buffer length
  79. * @return
  80. * - true success
  81. * - false fail
  82. */
  83. bool drvI2cRead(drvI2cMaster_t *i2c, const drvI2cSlave_t *slave, uint8_t *buf, uint32_t length);
  84. /**
  85. * @brief i2c master send raw byte
  86. *
  87. * @param i2c the i2c master
  88. * @param data raw byte to send
  89. * @param cmd_mask command associated with this byte.
  90. * @return
  91. * - true success
  92. * - false fail
  93. */
  94. bool drvI2cWriteRawByte(drvI2cMaster_t *i2c, uint8_t data, uint32_t cmd_mask);
  95. /**
  96. * @brief i2c master read raw byte
  97. *
  98. * @param i2c the i2c master
  99. * @param data room for the byte
  100. * @param cmd_mask the command mask required for the final phase of the
  101. * SCCB read cycle.
  102. * @return
  103. * - true success
  104. * - false fail
  105. */
  106. bool drvI2cReadRawByte(drvI2cMaster_t *i2c, uint8_t *data, uint32_t cmd_mask);
  107. #ifdef CONFIG_QUEC_PROJECT_FEATURE_I2C
  108. //added by ryan.yi 20211020
  109. //增加读写I2C纯数据的接口
  110. /**
  111. * @brief i2c master send data
  112. *
  113. * @param i2c the i2c master
  114. * @param slave the i2c slave address
  115. * @param data data to send
  116. * @param length data length
  117. * @return
  118. * - true success
  119. * - false fail
  120. */
  121. bool drvI2cWriteSalveData(drvI2cMaster_t *d, uint8_t slave, const uint8_t *data, uint32_t length);
  122. /**
  123. * @brief i2c master get data
  124. *
  125. * @param i2c the i2c master
  126. * @param slave the i2c slave address
  127. * @param buf buffer to receive data
  128. * @param length buffer length
  129. * @return
  130. * - true success
  131. * - false fail
  132. */
  133. bool drvI2cReadSlaveData(drvI2cMaster_t *d, uint8_t slave, uint8_t *buf, uint32_t length);
  134. drvI2cMaster_t *quec_getI2cMaster(int i2c_no);
  135. #endif
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /*_DRV_I2C_H_*/