• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: Provides I2C driver api \n
16  *
17  * History: \n
18  * 2022-06-01, Create file. \n
19  */
20 #ifndef I2C_H
21 #define I2C_H
22 
23 #include <stdint.h>
24 #include "common_def.h"
25 #include "errcode.h"
26 #include "hal_i2c.h"
27 #include "i2c_porting.h"
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33 #endif /* __cplusplus */
34 
35 /**
36  * @defgroup drivers_driver_i2c I2C
37  * @ingroup  drivers_driver
38  * @{
39  */
40 
41 /**
42  * @if Eng
43  * @brief  Definition of I2C TX/RX data.
44  * @else
45  * @brief  I2C发送/接收数据结构定义。
46  * @endif
47  */
48 typedef struct i2c_data {
49     uint8_t *send_buf;              /*!< @if Eng Send buffer pointer.
50                                          @else   发送数据的buffer指针。  @endif */
51     uint32_t send_len;              /*!< @if Eng Send buffer len.
52                                          @else   发送数据的buffer长度。  @endif */
53     uint8_t *receive_buf;           /*!< @if Eng Receive buffer pointer.
54                                          @else   接收数据的buffer指针。  @endif */
55     uint32_t receive_len;           /*!< @if Eng Receive buffer pointer.
56                                          @else   接收数据的buffer长度。  @endif */
57 } i2c_data_t;
58 
59 /**
60  * @if Eng
61  * @brief  Definition of I2C TX/RX wait condition.
62  * @else
63  * @brief  I2C发送/接收等待条件数据结构定义。
64  * @endif
65  */
66 typedef struct i2c_wait_condition {
67     uint32_t evt_mask;              /*!< @if Eng Wait event condition, will trigger task schedule if blocked.
68                                          @else   等待事件条件,如果不成立会引起任务调度,释放cpu占用。  @endif */
69     uint32_t ctrl_mask;             /*!< @if Eng Wait control condition, will polling if blocked.
70                                          @else   等待控制条件,如果不成立一直轮询,不释放cpu占用。  @endif */
71 } i2c_wait_condition_t;
72 
73 #if defined(CONFIG_I2C_SUPPORT_MASTER) && (CONFIG_I2C_SUPPORT_MASTER == 1)
74 /**
75  * @if Eng
76  * @brief  Initialize the I2C as master according to the specified parameters.
77  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
78  * @param  [in]  baudrate The baudrate of I2C, high limit by ip:
79  *                        - Standard speed mode baudrate high limit : 100KHz
80  *                        - Fast speed mode baudrate high limit : 400KHz
81  *                        - High speed mode baudrate high limit : 3.4MHz
82  * @param  [in]  hscode The I2C high speed mode master code, each master has its unique master code, \n
83  *                      valid values 0 ~ 7, only configured in high speed mode.
84  * @retval ERRCODE_SUCC Success.
85  * @retval Other        Failure. For details, see @ref errcode_t.
86  * @else
87  * @brief  根据指定的参数初始化该I2C为主机。
88  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
89  * @param  [in]  baudrate I2C波特率,不能超过IP的上限:
90  *                        - 标准模式波特率上限:100KHz
91  *                        - 快速模式波特率上限:400KHz
92  *                        - 高速模式波特率上限:3.4MHz
93  * @param  [in]  hscode I2C高速模式主机码, 每个主机有自己唯一的主机码,有效取值范围 0 ~ 7,仅在高速模式下需要配置。
94  * @retval ERRCODE_SUCC 成功。
95  * @retval Other        失败,参考 @ref errcode_t 。
96  * @endif
97  */
98 errcode_t uapi_i2c_master_init(i2c_bus_t bus, uint32_t baudrate, uint8_t hscode);
99 
100 /**
101  * @if Eng
102  * @brief  I2C Master writes a buffer to target slave. There are two ways to write data from master to slave,
103  *         one is manual switching mode, the other is automatic switching mode, and the two methods are statically
104  *         configured. The manual switching method has the following three transmission modes, but cannot be used in the
105  *         same bus at the same time.
106  *         - Manually switching modes includes:
107  *           - Polling mode
108  *           - DMA mode
109  *           - Interrupt mode
110  *         - The automatic switching mode (automatically switching between the polling mode and the DMA mode by
111  *           comparing the data length and the threshold value. For the threshold value, please refer to POLL and DMA
112  *           automatic switching threshold setting in I2C KCONFIG) includes:
113  *           - Polling mode: When the length of transmitted data is less than or equal to the threshold, it defaults
114  *                           to polling mode
115  *           - DMA mode: When the length of the transmitted data exceeds the threshold, it automatically switches to
116  *                       DMA mode
117  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
118  * @param  [in]  dev_addr The target slave address for master to write data.
119  * @param  [in]  data The information pointer of send data, see @ref i2c_data_t.
120  * @retval ERRCODE_SUCC Success.
121  * @retval Other        Failure. For details, see @ref errcode_t.
122  * @else
123  * @brief  将数据从主机写入到从机。有两种方式,一种是手动切换模式,另外一种是自动切换模式,两种方式是静态配置的。
124  *         手动切换方式一共有以下三种传输模式,但是不能在同一bus中同时使用。
125  *         - 手动切换模式包括:
126  *           - 轮询模式
127  *           - DMA模式
128  *           - 中断模式
129  *         - 自动切换模式(通过比较数据长度和阈值的大小自动切换轮询模式与DMA模式, 阈值具体请参考I2C KCONFIG中POLL和DMA自动切换阈值设置)包括:
130  *           - 轮询模式:当传输数据长度小于等于阈值时,默认为轮询模式
131  *           - DMA模式:当传输数据长度大于阈值时,自动切换为DMA模式
132  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
133  * @param  [in]  dev_addr 主机发送数据的目标从机地址。
134  * @param  [in]  data 发送数据的信息指针,参考 @ref i2c_data_t 。
135  * @retval ERRCODE_SUCC 成功。
136  * @retval Other        失败,参考 @ref errcode_t 。
137  * @endif
138  */
139 errcode_t uapi_i2c_master_write(i2c_bus_t bus, uint16_t dev_addr, i2c_data_t *data);
140 
141 /**
142  * @if Eng
143  * @brief  I2C Master receives a buffer from target slave. There are two ways to read data from slave to master, one is
144  *         manual switching mode, the other is automatic switching mode, and the two methods are statically configured.
145  *         The manual switching method has the following three transmission modes, but cannot be used in the same bus at
146  *         the same time.
147  *         - Manually switching modes includes:
148  *           - Polling mode
149  *           - DMA mode
150  *           - Interrupt mode
151  *         - The automatic switching mode (automatically switching between the polling mode and the DMA mode by
152  *           comparing the data length and the threshold value. For the threshold value, please refer to POLL and DMA
153  *           automatic switching threshold setting in I2C KCONFIG) includes:
154  *           - Polling mode: When the length of transmitted data is less than or equal to the threshold, it defaults
155  *                           to polling mode
156  *           - DMA mode: When the length of the transmitted data exceeds the threshold, it automatically switches to
157  *                       DMA mode
158  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
159  * @param  [in]  dev_addr The target slave address for master to receive data.
160  * @param  [in]  data The information pointer of receive data, see @ref i2c_data_t.
161  * @retval ERRCODE_SUCC Success.
162  * @retval Other        Failure. For details, see @ref errcode_t.
163  * @else
164  * @brief  主机接收来自目标I2C从机的数据。有两种方式,一种是手动切换模式,另外一种是自动切换模式,两种方式是静态配置的。
165  *         手动切换方式一共有以下三种传输模式,但是不能在同一bus中同时使用。
166  *         - 手动切换模式包括:
167  *           - 轮询模式
168  *           - DMA模式
169  *           - 中断模式
170  *         - 自动切换模式(通过比较数据长度和阈值的大小自动切换轮询模式与DMA模式, 阈值具体请参考I2C KCONFIG中POLL和DMA自动切换阈值设置)包括:
171  *           - 轮询模式:当传输数据长度小于等于阈值时,默认为轮询模式
172  *           - DMA模式:当传输数据长度大于阈值时,自动切换为DMA模式
173  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
174  * @param  [in]  dev_addr 主机接收数据的目标从机地址。
175  * @param  [in]  data 接收数据的信息指针,参考 @ref i2c_data_t 。
176  * @retval ERRCODE_SUCC 成功。
177  * @retval Other        失败,参考 @ref errcode_t 。
178  * @endif
179  */
180 errcode_t uapi_i2c_master_read(i2c_bus_t bus, uint16_t dev_addr, i2c_data_t *data);
181 
182 /**
183  * @if Eng
184  * @brief  I2C Master writes a buffer to target slave and receives a buffer from it. There are two ways to write and
185  *         read data, one is manual switching mode, the other is automatic switching mode, and the two methods are
186  *         statically configured. The manual switching method has the following three transmission modes, but cannot be
187  *         used in the same bus at the same time.
188  *         - Manually switching modes includes:
189  *           - Polling mode
190  *           - DMA mode
191  *           - Interrupt mode
192  *         - The automatic switching mode (automatically switching between the polling mode and the DMA mode by
193  *           comparing the data length and the threshold value. For the threshold value, please refer to POLL and DMA
194  *           automatic switching threshold setting in I2C KCONFIG) includes:
195  *           - Polling mode: When the length of transmitted data is less than or equal to the threshold, it defaults
196  *                           to polling mode
197  *           - DMA mode: When the length of the transmitted data exceeds the threshold, it automatically switches to
198  *                       DMA mode
199  * @param  [in]  bus The I2C bus. see @ref i2c_bus_t.
200  * @param  [in]  dev_addr The target slave address for master to receive data.
201  * @param  [in]  data The information pointer of receive data, see @ref i2c_data_t.
202  * @retval ERRCODE_SUCC Success.
203  * @retval Other        Failure. For details, see @ref errcode_t.
204  * @else
205  * @brief  主机发送数据到目标I2C从机,并接收来自此从机的数据。有两种方式,一种是手动切换模式,另外一种是自动切换模式,两种方式是静态配置的。
206  *         手动切换方式一共有以下三种传输模式,但是不能在同一bus中同时使用。
207  *         - 手动切换模式包括:
208  *           - 轮询模式
209  *           - DMA模式
210  *           - 中断模式
211  *         - 自动切换模式(通过比较数据长度和阈值的大小自动切换轮询模式与DMA模式, 阈值具体请参考I2C KCONFIG中POLL和DMA自动切换阈值设置)包括:
212  *           - 轮询模式:当传输数据长度小于等于阈值时,默认为轮询模式
213  *           - DMA模式:当传输数据长度大于阈值时,自动切换为DMA模式
214  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
215  * @param  [in]  dev_addr 主机接收数据的目标从机地址。
216  * @param  [in]  data 接收数据的信息指针,参考 @ref i2c_data_t 。
217  * @retval ERRCODE_SUCC 成功。
218  * @retval Other        失败,参考 @ref errcode_t 。
219  * @endif
220  */
221 errcode_t uapi_i2c_master_writeread(i2c_bus_t bus, uint16_t dev_addr, i2c_data_t *data);
222 #endif  /* CONFIG_I2C_SUPPORT_MASTER */
223 
224 #if defined(CONFIG_I2C_SUPPORT_SLAVE) && (CONFIG_I2C_SUPPORT_SLAVE == 1)
225 /**
226  * @if Eng
227  * @brief  Initialize the I2C as slave according to the specified parameters.
228  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
229  * @param  [in]  baudrate The baudrate of I2C, need to be consistent with the master.
230  * @param  [in]  addr The slave address when the I2C is operating as a slave:
231  *                    - 7-bits address range is [0x8, 0x77]
232  *                    - 10-bits address range is [0x7800, 0x7BFF]
233  * @retval ERRCODE_SUCC Success.
234  * @retval Other        Failure. For details, see @ref errcode_t.
235  * @else
236  * @brief  根据指定的参数初始化该I2C为从机。
237  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
238  * @param  [in]  baudrate I2C波特率,需要与主机保持一致:
239  *                        - 标准模式波特率上限:100KHz
240  *                        - 快速模式波特率上限:400KHz
241  *                        - 高速模式波特率上限:3.4MHz
242  * @param  [in]  addr I2C作为从机工作时的从机地址:
243  *                    - 7比特地址范围 [0x8, 0x77]
244  *                    - 10比特地址范围 [0x7800, 0x7BFF]
245  * @retval ERRCODE_SUCC 成功。
246  * @retval Other        失败,参考 @ref errcode_t 。
247  * @endif
248  */
249 
250 errcode_t uapi_i2c_slave_init(i2c_bus_t bus, uint32_t baudrate, uint16_t addr);
251 
252 /**
253  * @if Eng
254  * @brief  Slave writes a buffer to Master. There are two ways to write data from slave to master, one is manual
255  *         switching mode, the other is automatic switching mode, and the two methods are statically configured. The
256  *         manual switching method has the following three transmission modes, but cannot be used in the same bus at
257  *         the same time.
258  *         - Manually switching modes includes:
259  *           - Polling mode
260  *           - DMA mode
261  *           - Interrupt mode
262  *         - The automatic switching mode (automatically switching between the polling mode and the DMA mode by
263  *           comparing the data length and the threshold value. For the threshold value, please refer to POLL and DMA
264  *           automatic switching threshold setting in I2C KCONFIG) includes:
265  *           - Polling mode: When the length of transmitted data is less than or equal to the threshold, it defaults
266  *                           to polling mode
267  *           - DMA mode: When the length of the transmitted data exceeds the threshold, it automatically switches to
268  *                       DMA mode
269  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
270  * @param  [in]  data The information pointer of send data, see @ref i2c_data_t.
271  * @retval ERRCODE_SUCC Success.
272  * @retval Other        Failure. For details, see @ref errcode_t.
273  * @else
274  * @brief  从机将数据发送给主机。有两种方式,一种是手动切换模式,另外一种是自动切换模式,两种方式是静态配置的。
275  *         手动切换方式一共有以下三种传输模式,但是不能在同一bus中同时使用。
276  *         - 手动切换模式包括:
277  *           - 轮询模式
278  *           - DMA模式
279  *           - 中断模式
280  *         - 自动切换模式(通过比较数据长度和阈值的大小自动切换轮询模式与DMA模式, 阈值具体请参考I2C KCONFIG中POLL和DMA自动切换阈值设置)包括:
281  *           - 轮询模式:当传输数据长度小于等于阈值时,默认为轮询模式
282  *           - DMA模式:当传输数据长度大于阈值时,自动切换为DMA模式
283  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
284  * @param  [in]  data 发送数据的信息指针,参考 @ref i2c_data_t 。
285  * @retval ERRCODE_SUCC 成功。
286  * @retval Other        失败,参考 @ref errcode_t 。
287  * @endif
288  */
289 errcode_t uapi_i2c_slave_write(i2c_bus_t bus, i2c_data_t *data);
290 
291 /**
292  * @if Eng
293  * @brief  Slave receives a buffer form Master. There are two ways to read data from master to slave, one is manual
294  *         switching mode, the other is automatic switching mode, and the two methods are statically configured. The
295  *         manual switching method has the following three transmission modes, but cannot be used in the same bus at
296  *         the same time.
297  *         - Manually switching modes includes:
298  *           - Polling mode
299  *           - DMA mode
300  *           - Interrupt mode
301  *         - The automatic switching mode (automatically switching between the polling mode and the DMA mode by
302  *           comparing the data length and the threshold value. For the threshold value, please refer to POLL and DMA
303  *           automatic switching threshold setting in I2C KCONFIG) includes:
304  *           - Polling mode: When the length of transmitted data is less than or equal to the threshold, it defaults
305  *                           to polling mode
306  *           - DMA mode: When the length of the transmitted data exceeds the threshold, it automatically switches to
307  *                       DMA mode
308  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
309  * @param  [in]  data The information pointer of receive data, see @ref i2c_data_t.
310  * @retval ERRCODE_SUCC Success.
311  * @retval Other        Failure. For details, see @ref errcode_t.
312  * @else
313  * @brief  从机从主机读取数据。有两种方式,一种是手动切换模式,另外一种是自动切换模式,两种方式是静态配置的。
314  *         手动切换方式一共有以下三种传输模式,但是不能在同一bus中同时使用。
315  *         - 手动切换模式包括:
316  *           - 轮询模式
317  *           - DMA模式
318  *           - 中断模式
319  *         - 自动切换模式(通过比较数据长度和阈值的大小自动切换轮询模式与DMA模式, 阈值具体请参考I2C KCONFIG中POLL和DMA自动切换阈值设置)包括:
320  *           - 轮询模式:当传输数据长度小于等于阈值时,默认为轮询模式
321  *           - DMA模式:当传输数据长度大于阈值时,自动切换为DMA模式
322  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
323  * @param  [in]  data 接收数据的信息指针,参考 @ref i2c_data_t 。
324  * @retval ERRCODE_SUCC 成功。
325  * @retval Other        失败,参考 @ref errcode_t 。
326  * @endif
327  */
328 errcode_t uapi_i2c_slave_read(i2c_bus_t bus, i2c_data_t *data);
329 #endif /* CONFIG_I2C_SUPPORT_SLAVE */
330 
331 #if defined(CONFIG_I2C_SUPPORT_INT) && (CONFIG_I2C_SUPPORT_INT == 1)
332 /**
333  * @if Eng
334  * @brief  Set whether to use the interrupt mode to transfer data.
335  * @param  [in]  bus The I2C bus. For details, see @ref i2c_bus_t.
336  * @param  [in]  irq_en Whether to use the interrupt mode.
337  * @retval ERRCODE_SUCC Success.
338  * @retval Other        Failure. For details, see @ref errcode_t.
339  * @else
340  * @brief  设置是否使用中断模式传输数据。
341  * @param  [in]  bus 指定的I2C接口,参考 @ref i2c_bus_t 。
342  * @param  [in]  irq_en 是否使用中断模式。
343  * @retval ERRCODE_SUCC 成功。
344  * @retval Other        失败,参考 @ref errcode_t 。
345  * @endif
346  */
347 errcode_t uapi_i2c_set_irq_mode(i2c_bus_t bus, bool irq_en);
348 
349 /**
350  * @if Eng
351  * @brief  Definition of I2C irq event.
352  * @else
353  * @brief  I2C中断事件枚举。
354  * @endif
355  */
356 typedef enum {
357     I2C_IRQ_EVT_RX_DONE,
358     I2C_IRQ_EVT_TX_DONE,
359     I2C_IRQ_EVT_I2C_BUSY,
360     I2C_IRQ_EVT_I2C_ERR,
361 }i2c_irq_event_t;
362 
363 /**
364  * @if Eng
365  * @brief  i2c irq event callback to be called when irq callback set
366            @ref uapi_i2c_register_irq_callback is invoked.
367  * @note   This callback is invoked in an interrupt context.
368  * @param  bus The I2C bus. For details, see @ref i2c_bus_t.
369  * @param  event Pointer to the event for i2c irq @ref i2c_irq_event_t.
370 
371  * @else
372  * @brief  i2c中断事件的回调函数,通过 @ref uapi_i2c_register_irq_callback 注册到驱动中。
373  * @note   这个函数是在中断上下文中执行的。
374  * @param  bus 指定的I2C接口,参考 @ref i2c_bus_t 。
375  * @param  event 指向i2c中断事件。
376 
377  * @endif
378  */
379 typedef void (*i2c_irq_callback_t)(i2c_bus_t bus, uint8_t event);
380 /**
381  * @if Eng
382  * @brief  register i2c irq event callback.
383  * @param  [in]  bus The I2C bus. For details, see @ref i2c_bus_t.
384  * @param  [in]  callback  Event callback.
385  * @retval ERRCODE_SUCC Success.
386  * @retval Other        Failure. For details, see @ref errcode_t.
387  * @else
388  * @brief  注册I2C中断事件回调函数。
389  * @param  [in]  bus 指定的I2C接口,参考 @ref i2c_bus_t 。
390  * @param  [in]  callback 事件回调函数。
391  * @retval ERRCODE_SUCC 成功。
392  * @retval Other        失败,参考 @ref errcode_t 。
393  * @endif
394  */
395 errcode_t uapi_i2c_register_irq_callback(i2c_bus_t bus, i2c_irq_callback_t callback);
396 
397 /**
398  * @if Eng
399  * @brief  unregister i2c irq event callback.
400  * @param  [in]  bus The I2C bus. For details, see @ref i2c_bus_t.
401  * @retval ERRCODE_SUCC Success.
402  * @retval Other        Failure. For details, see @ref errcode_t.
403  * @else
404  * @brief  取消注册I2C中断事件回调函数。
405  * @param  [in]  bus 指定的I2C接口,参考 @ref i2c_bus_t 。
406  * @retval ERRCODE_SUCC 成功。
407  * @retval Other        失败,参考 @ref errcode_t 。
408  * @endif
409  */
410 errcode_t uapi_i2c_unregister_irq_callback(i2c_bus_t bus);
411 
412 #endif  /* CONFIG_I2C_SUPPORT_INT */
413 
414 #if defined(CONFIG_I2C_SUPPORT_DMA) && (CONFIG_I2C_SUPPORT_DMA == 1)
415 /**
416  * @if Eng
417  * @brief  Enable/disable data transfer function in dma mode.
418  * @param  [in]  bus The I2C bus. For details, see @ref i2c_bus_t.
419  * @param  [in]  en Enable/disable data transfer.
420  * @retval ERRCODE_SUCC Success.
421  * @retval Other        Failure. For details, see @ref errcode_t.
422  * @else
423  * @brief  使能/去使能DMA模式下I2C传输。
424  * @param  [in]  bus 指定的I2C接口。参考 @ref i2c_bus_t 。
425  * @param  [in]  en 是否使能DMA传输。
426  * @retval ERRCODE_SUCC 成功。
427  * @retval Other        失败,参考 @ref errcode_t 。
428  * @endif
429  */
430 errcode_t uapi_i2c_set_dma_mode(i2c_bus_t bus, bool en);
431 #endif  /* CONFIG_I2C_SUPPORT_DMA */
432 
433 /**
434  * @if Eng
435  * @brief  Deinitialize the I2C peripheral, valid for both master and slave mode.
436  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
437  * @retval ERRCODE_SUCC Success.
438  * @retval Other        Failure. For details, see @ref errcode_t.
439  * @else
440  * @brief  去初始化I2C,支持主从机。
441  * @param  [in]  bus I2C总线,参考 @ref i2c_bus_t 。
442  * @retval ERRCODE_SUCC 成功。
443  * @retval Other        失败,参考 @ref errcode_t 。
444  * @endif
445  */
446 errcode_t uapi_i2c_deinit(i2c_bus_t bus);
447 
448 /**
449  * @if Eng
450  * @brief  Reset I2C baudrate for initialized I2C, valid for both master and slave mode.
451  * @param  [in]  bus The I2C bus, see @ref i2c_bus_t.
452  * @param  [in]  baudrate The baudrate of I2C, high limit by ip:
453  *                        - Standard speed mode baudrate high limit : 100KHz
454  *                        - Fast speed mode baudrate high limit : 400KHz
455  *                        - High speed mode baudrate high limit : 3.4MHz
456  * @retval ERRCODE_SUCC Success.
457  * @retval Other        Failure. For details, see @ref errcode_t
458  * @else
459  * @brief  对已初始化的I2C重置波特率,支持主从机。
460  * @param  [in]  bus I2C总线id,参考 @ref i2c_bus_t 。
461  * @param  [in]  baudrate I2C波特率,不能超过IP的上限:
462  *                        - 标准模式波特率上限:100KHz
463  *                        - 快速模式波特率上限:400KHz
464  *                        - 高速模式波特率上限:3.4MHz
465  * @retval ERRCODE_SUCC 成功。
466  * @retval Other        失败,参考 @ref errcode_t 。
467  * @endif
468  */
469 errcode_t uapi_i2c_set_baudrate(i2c_bus_t bus, uint32_t baudrate);
470 
471 #if defined(CONFIG_I2C_SUPPORT_LPM)
472 /**
473  * @if Eng
474  * @brief  Suspend all of the I2C channels.
475  * @param  [in]  arg Argument for suspend.
476  * @retval ERRCODE_SUCC Success.
477  * @retval Other        Failure. For details, see @ref errcode_t.
478  * @else
479  * @brief  挂起所有I2C通道。
480  * @param  [in]  arg 挂起所需要的参数。
481  * @retval ERRCODE_SUCC 成功。
482  * @retval Other        失败,参考 @ref errcode_t 。
483  * @endif
484  */
485 errcode_t uapi_i2c_suspend(uintptr_t arg);
486 
487 /**
488  * @if Eng
489  * @brief  Resume all of the I2C channels.
490  * @param  [in]  arg Argument for resume.
491  * @retval ERRCODE_SUCC Success.
492  * @retval Other        Failure. For details, see @ref errcode_t.
493  * @else
494  * @brief  恢复所有I2C通道。
495  * @param  [in]  arg 恢复所需要的参数。
496  * @retval ERRCODE_SUCC 成功。
497  * @retval Other        失败,参考 @ref errcode_t 。
498  * @endif
499  */
500 errcode_t uapi_i2c_resume(uintptr_t arg);
501 #endif
502 
503 /**
504  * @}
505  */
506 
507 #ifdef __cplusplus
508 #if __cplusplus
509 }
510 #endif /* __cplusplus */
511 #endif /* __cplusplus */
512 
513 #endif