hpm_smbus.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SMBUS_H
  8. #define HPM_SMBUS_H
  9. #include "hpm_common.h"
  10. #include "hpm_soc_feature.h"
  11. #include "hpm_i2c_drv.h"
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /**
  17. * @brief SMbus master write data
  18. *
  19. * @details write data at slave mode
  20. *
  21. * @param [in] ptr I2C base address
  22. * @param [in] device_address SMbus slave address
  23. * @param [in] data byte to be writed
  24. * @retval hpm_stat_t: status_success if writing is completed without any error
  25. */
  26. hpm_stat_t hpm_smbus_master_write_byte(I2C_Type *ptr, uint8_t slave_address,
  27. uint8_t data);
  28. /**
  29. * @brief SMbus master read byte from certain slave device
  30. *
  31. * @details Read byte from SMbus device
  32. *
  33. * @param [in] ptr I2C base address
  34. * @param [in] device_address SMbus slave address
  35. * @param [out] data pointer of the byte read from device
  36. * @retval hpm_stat_t: status_success if reading is completed without any error
  37. */
  38. hpm_stat_t hpm_smbus_master_read_byte(I2C_Type *ptr, uint8_t slave_address,
  39. uint8_t *data);
  40. /**
  41. * @brief SMbus master write byte from certain slave device in command code
  42. *
  43. * @details write byte from SMbus device in command code
  44. *
  45. * @param [in] ptr I2C base address
  46. * @param [in] device_address SMbus slave address
  47. * @param [in] command command code
  48. * @param [in] data byte to be writed
  49. * @retval hpm_stat_t: status_success if writing is completed without any error
  50. */
  51. hpm_stat_t hpm_smbus_master_write_byte_in_command(I2C_Type *ptr, uint8_t slave_address,
  52. uint8_t command, uint8_t data);
  53. /**
  54. * @brief SMbus master write word(16bits) from certain slave device in command code
  55. *
  56. * @details write word(16bits) from SMbus device in command code
  57. *
  58. * @param [in] ptr I2C base address
  59. * @param [in] device_address SMbus slave address
  60. * @param [in] command command code
  61. * @param [in] data word to be writed
  62. * @retval hpm_stat_t: status_success if writing is completed without any error
  63. */
  64. hpm_stat_t hpm_smbus_master_write_word_in_command(I2C_Type *ptr, uint8_t slave_address,
  65. uint8_t command, uint16_t data);
  66. /**
  67. * @brief SMbus master read byte from certain slave device in command code
  68. *
  69. * @details read byte from SMbus device in command code
  70. *
  71. * @param [in] ptr I2C base address
  72. * @param [in] device_address SMbus slave address
  73. * @param [in] command command code
  74. * @param [in] data byte to be read
  75. * @retval hpm_stat_t: status_success if reading is completed without any error
  76. */
  77. hpm_stat_t hpm_smbus_master_read_byte_in_command(I2C_Type *ptr, uint8_t slave_address,
  78. uint8_t command, uint8_t *data);
  79. /**
  80. * @brief SMbus master read word(16bits) from certain slave device in command code
  81. *
  82. * @details read word from SMbus device in command code
  83. *
  84. * @param [in] ptr I2C base address
  85. * @param [in] device_address SMbus slave address
  86. * @param [in] command command code
  87. * @param [in] data word to be read
  88. * @retval hpm_stat_t: status_success if reading is completed without any error
  89. */
  90. hpm_stat_t hpm_smbus_master_read_word_in_command(I2C_Type *ptr, uint8_t slave_address,
  91. uint8_t command, uint16_t *data);
  92. /**
  93. * @brief SMbus master block write from certain slave device in command code
  94. *
  95. * @details block write from SMbus device in command code
  96. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  97. *
  98. * @param [in] ptr I2C base address
  99. * @param [in] device_address SMbus slave address
  100. * @param [in] command command code
  101. * @param [in] data pointer of the buffer to store data read from device
  102. * @param [in] size size of data to be read in bytes
  103. * @retval hpm_stat_t: status_success if writing is completed without any error
  104. */
  105. hpm_stat_t hpm_smbus_master_write_block_in_command(I2C_Type *ptr, uint8_t slave_address,
  106. uint8_t command, uint8_t *data, uint32_t size);
  107. /**
  108. * @brief SMbus master block read from certain slave device in command code
  109. *
  110. * @details block read from SMbus device in command code
  111. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  112. *
  113. * @param [in] ptr I2C base address
  114. * @param [in] device_address SMbus slave address
  115. * @param [in] command command code
  116. * @param [out] data pointer of the buffer to store data read from device
  117. * @param [in] size size of data to be read in bytes
  118. * @retval hpm_stat_t: status_success if reading is completed without any error
  119. */
  120. hpm_stat_t hpm_smbus_master_read_block_in_command(I2C_Type *ptr, uint8_t slave_address,
  121. uint8_t command, uint8_t *data, uint32_t size);
  122. /**
  123. * @brief SMbus master write data to certain slave device
  124. *
  125. * @details Write data to SMbus device
  126. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  127. *
  128. * @param [in] ptr I2C base address
  129. * @param [in] device_address SMbus slave address
  130. * @param [in] data pointer of the data to be sent
  131. * @param [in] size size of data to be sent in bytes
  132. * @retval hpm_stat_t: status_success if writing is completed without any error
  133. */
  134. hpm_stat_t hpm_smbus_master_write(I2C_Type *ptr, uint8_t slave_address,
  135. uint8_t *data, uint32_t size);
  136. /**
  137. * @brief SMbus master read data from certain slave device
  138. *
  139. * @details Read data from SMbus device
  140. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  141. *
  142. * @param [in] ptr I2C base address
  143. * @param [in] device_address SMbus slave address
  144. * @param [out] data pointer of the buffer to store data read from device
  145. * @param [in] size size of data to be read in bytes
  146. * @retval hpm_stat_t: status_success if reading is completed without any error
  147. */
  148. hpm_stat_t hpm_smbus_master_read(I2C_Type *ptr, uint8_t slave_address,
  149. uint8_t *data, uint32_t size);
  150. /**
  151. * @brief SMbus slave write data
  152. *
  153. * @details Write data at SMbus slave mode.
  154. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  155. *
  156. * @param [in] ptr I2C base address
  157. * @param [in] buf pointer of the buffer to store data sent from device
  158. * @param [in] size size of data to be sent in bytes
  159. * @retval hpm_stat_t status_success if writing is completed without any error
  160. */
  161. hpm_stat_t hpm_smbus_slave_write(I2C_Type *ptr, uint8_t *data, uint32_t size);
  162. /**
  163. * @brief SMbus slave read data
  164. *
  165. * @details Read data at SMbus slave mode
  166. * @note size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  167. *
  168. * @param [in] ptr I2C base address
  169. * @param [in] buf pointer of the buffer to store data read from device
  170. * @param [in] size size of data to be read in bytes
  171. * @retval hpm_stat_t: status_success if reading is completed without any error
  172. */
  173. hpm_stat_t hpm_smbus_slave_read(I2C_Type *ptr, uint8_t *data, uint32_t size);
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif