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