hpm_sccb.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright (c) 2023 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SCCB_H
  8. #define HPM_SCCB_H
  9. #include "hpm_common.h"
  10. #include "hpm_soc_feature.h"
  11. #include "hpm_i2c_drv.h"
  12. typedef I2C_Type *sccb_type;
  13. typedef enum _sccb_xfer_flag {
  14. /*Normal transfer with start condition, address, data and stop condition.*/
  15. sccb_xfer_no_flags,
  16. /*This flag allows the next transfer to change direction with repeated start*/
  17. sccb_xfer_no_stop,
  18. /*This flag allows chaining multiple writes or reads with the same direction*/
  19. sccb_xfer_suspend,
  20. } sccb_xfer_flags_t;
  21. typedef struct _sccb_bus {
  22. uint8_t initialzed;
  23. sccb_type sccb;
  24. } hpm_sccb_bus_t;
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. /**
  30. * @brief sccb master initialization
  31. *
  32. * @details Initialized sccb working at master mode
  33. *
  34. * @param [in] sccb sccb base address
  35. * @retval hpm_stat_t: status_success if initialization is completed without any error
  36. */
  37. hpm_stat_t sccb_master_init(sccb_type sccb);
  38. /**
  39. * @brief sccb master scan slave addr
  40. *
  41. * @details master scan the slave
  42. *
  43. * @param [in] sccb sccb base address
  44. * @retval uint8_t: the slave address val is zero if scan slave fail
  45. */
  46. uint8_t sccb_master_scan(sccb_type sccb);
  47. /**
  48. * @brief sccb master gen call slave
  49. *
  50. * @details the controller sends the command to determine whether the slave responds
  51. *
  52. * @param [in] sccb sccb base address
  53. * @param [in] cmd sccb master sends command
  54. * @retval hpm_stat_t: status_success if the slave responds
  55. */
  56. hpm_stat_t sccb_master_gencall(sccb_type sccb, uint8_t cmd);
  57. /**
  58. * @brief sccb master read 8bit data of specify 8bit register from certain slave device
  59. *
  60. * @details the function used to access 8 bit register address,read 8bit data
  61. * @note the register address must be 8bit
  62. *
  63. * @param [in] sccb sccb base address
  64. * @param [in] slv_addr sccb slave address
  65. * @param [out] reg_addr 8bit register address of sccb slave device
  66. * @param [out] reg_data point of the buffer to store 8bit data from device the number of bytes is 1
  67. * @retval hpm_stat_t: status_success if reading is completed without any error
  68. */
  69. hpm_stat_t sccb_master_readb(sccb_type sccb, uint8_t slv_addr, uint8_t reg_addr, uint8_t *reg_data);
  70. /**
  71. * @brief sccb master write 8bit data of specify 8bit register from certain slave device
  72. *
  73. * @details the function used to access 8 bit register address,write 8bit data
  74. * @note the register address must be 8bit
  75. *
  76. * @param [in] sccb sccb base address
  77. * @param [in] slv_addr sccb slave address
  78. * @param [out] reg_addr 8bit register address of sccb slave device
  79. * @param [out] reg_data write 8bit data
  80. * @retval hpm_stat_t: status_success if writing is completed without any error
  81. */
  82. hpm_stat_t sccb_master_writeb(sccb_type sccb, uint8_t slv_addr, uint8_t reg_addr, uint8_t reg_data);
  83. /**
  84. * @brief sccb master read 8bit data of specify 16bit register from certain slave device
  85. *
  86. * @details the function used to access 16 bit register address,read 8bit data
  87. * @note the register address must be 16bit
  88. *
  89. * @param [in] sccb sccb base address
  90. * @param [in] slv_addr sccb slave address
  91. * @param [out] reg_addr 16bit register address of sccb slave device
  92. * @param [out] reg_data point of the buffer to store 8bit data from device the number of bytes is 1
  93. * @retval hpm_stat_t: status_success if reading is completed without any error
  94. */
  95. hpm_stat_t sccb_master_readb2(sccb_type sccb, uint8_t slv_addr, uint16_t reg_addr, uint8_t *reg_data);
  96. /**
  97. * @brief sccb master write 8bit data of specify 16bit register from certain slave device
  98. *
  99. * @details the function used to access 16 bit register address,write 8bit data
  100. * @note the register address must be 8bit
  101. *
  102. * @param [in] sccb sccb base address
  103. * @param [in] slv_addr sccb slave address
  104. * @param [out] reg_addr 16bit register address of sccb slave device
  105. * @param [out] reg_data wirite 8bit data
  106. * @retval hpm_stat_t: status_success if writing is completed without any error
  107. */
  108. hpm_stat_t sccb_master_writeb2(sccb_type sccb, uint8_t slv_addr, uint16_t reg_addr, uint8_t reg_data);
  109. /**
  110. * @brief sccb master read 16bit data of specify 8bit register from certain slave device
  111. *
  112. * @details the function used to access 8 bit register address,read 16bit data
  113. * @note the register address must be 8bit
  114. *
  115. * @param [in] sccb sccb base address
  116. * @param [in] slv_addr sccb slave address
  117. * @param [out] reg_addr 8bit register address of sccb slave device
  118. * @param [out] reg_data point of the buffer to store 16bit data from device the number of bytes is 1
  119. * @retval hpm_stat_t: status_success if reading is completed without any error
  120. */
  121. hpm_stat_t sccb_master_readw(sccb_type sccb, uint8_t slv_addr, uint8_t reg_addr, uint16_t *reg_data);
  122. /**
  123. * @brief sccb master write 16bit data of specify 8bit register from certain slave device
  124. *
  125. * @details the function used to access 8 bit register address,write 16bit data
  126. * @note the register address must be 8bit
  127. *
  128. * @param [in] sccb sccb base address
  129. * @param [in] slv_addr sccb slave address
  130. * @param [out] reg_addr 8bit register address of sccb slave device
  131. * @param [out] reg_data wirite 16bit data
  132. * @retval hpm_stat_t: status_success if writing is completed without any error
  133. */
  134. hpm_stat_t sccb_master_writew(sccb_type sccb, uint8_t slv_addr, uint8_t reg_addr, uint16_t reg_data);
  135. /**
  136. * @brief sccb master read 16bit data of specify 16it register from certain slave device
  137. *
  138. * @details the function used to access 16 bit register address,read 16bit data
  139. * @note the register address must be 16bit
  140. *
  141. * @param [in] sccb sccb base address
  142. * @param [in] slv_addr sccb slave address
  143. * @param [out] reg_addr 16bit register address of sccb slave device
  144. * @param [out] reg_data point of the buffer to store 16bit data from device the number of bytes is 1
  145. * @retval hpm_stat_t: status_success if reading is completed without any error
  146. */
  147. hpm_stat_t sccb_master_readw2(sccb_type sccb, uint8_t slv_addr, uint16_t reg_addr, uint16_t *reg_data);
  148. /**
  149. * @brief sccb master write 16bit data of specify 16bit register from certain slave device
  150. *
  151. * @details the function used to access 16bit register address,write 16bit data
  152. * @note the register address must be 16bit
  153. *
  154. * @param [in] sccb sccb base address
  155. * @param [in] slv_addr sccb slave address
  156. * @param [out] reg_addr 16bit register address of sccb slave device
  157. * @param [out] reg_data wirite 16bit data
  158. * @retval hpm_stat_t: status_success if writing is completed without any error
  159. */
  160. hpm_stat_t sccb_master_writew2(sccb_type sccb, uint8_t slv_addr, uint16_t reg_addr, uint16_t reg_data);
  161. /**
  162. * @brief sccb master reads the specified number of bytes continuously at the specified flag
  163. *
  164. * @details the size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  165. *
  166. * @param [in] sccb sccb base address
  167. * @param [in] slv_addr sccb slave address
  168. * @param [out] buf point of the buffer to store 8bit data from device
  169. * @param [out] len size of data to be read in bytes
  170. * @param [in] len 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 sccb_master_read_bytes(sccb_type sccb, uint8_t slv_addr, uint8_t *buf, const uint32_t len, uint8_t flags);
  174. /**
  175. * @brief sccb master weite the specified number of bytes continuously at the specified flag
  176. *
  177. * @details the size should not not greater than I2C_SOC_TRANSFER_COUNT_MAX
  178. *
  179. * @param [in] sccb sccb base address
  180. * @param [in] slv_addr sccb slave address
  181. * @param [out] buf point of the buffer to store 8bit data from device
  182. * @param [out] len size of data to be write in bytes
  183. * @param [in] len size of data to be write in bytes
  184. * @retval hpm_stat_t: status_success if writing is completed without any error
  185. */
  186. hpm_stat_t cambus_write_bytes(sccb_type sccb, uint8_t slv_addr, uint8_t *buf, const uint32_t len, uint8_t flags);
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif