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