1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
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 
16 /**
17  * @addtogroup IotHardware
18  * @{
19  *
20  * @brief Provides APIs for operating devices,
21  * including flash, GPIO, I2C, PWM, UART, and watchdog APIs.
22  *
23  *
24  *
25  * @since 2.2
26  * @version 2.2
27  */
28 
29 /**
30  * @file iot_i2c.h
31  *
32  * @brief Declares functions for operating I2C devices.
33  *
34  * These functions are used to initialize or deinitialize an I2C device,
35  * and read data from or write data to an I2C device. \n
36  *
37  * @since 2.2
38  * @version 2.2
39  */
40 
41 #ifndef IOT_I2C_H
42 #define IOT_I2C_H
43 
44 /**
45  * @brief Initializes an I2C device with a specified baud rate.
46  *
47  *
48  *
49  * @param id Indicates the I2C device ID.
50  * @param baudrate Indicates the I2C baud rate.
51  * @return Returns {@link IOT_SUCCESS} if the I2C device is initialized;
52  * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
53  * @since 2.2
54  * @version 2.2
55  */
56 unsigned int IoTI2cInit(unsigned int id, unsigned int baudrate);
57 
58 /**
59  * @brief Deinitializes an I2C device.
60  *
61  * @param id Indicates the I2C device ID.
62  * @return Returns {@link IOT_SUCCESS} if the I2C device is deinitialized;
63  * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
64  * @since 2.2
65  * @version 2.2
66  */
67 unsigned int IoTI2cDeinit(unsigned int id);
68 
69 /**
70  * @brief Writes data to an I2C device.
71  *
72  *
73  *
74  * @param id Indicates the I2C device ID.
75  * @param deviceAddr Indicates the I2C device address.
76  * @param data Indicates the pointer to the data to write.
77  * @param dataLen Indicates the length of the data to write.
78  * @return Returns {@link IOT_SUCCESS} if the data is written to the I2C device successfully;
79  * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
80  * @since 2.2
81  * @version 2.2
82  */
83 unsigned int IoTI2cWrite(unsigned int id, unsigned short deviceAddr, const unsigned char *data, unsigned int dataLen);
84 
85 /**
86  * @brief Reads data from an I2C device.
87  *
88  * The data read will be saved to the address specified by <b>i2cData</b>.
89  *
90  * @param id Indicates the I2C device ID.
91  * @param deviceAddr Indicates the I2C device address.
92  * @param data Indicates the pointer to the data to read.
93  * @param dataLen Indicates the length of the data to read.
94  * @return Returns {@link IOT_SUCCESS} if the data is read from the I2C device successfully;
95  * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
96  * @since 2.2
97  * @version 2.2
98  */
99 unsigned int IoTI2cRead(unsigned int id, unsigned short deviceAddr, unsigned char *data, unsigned int dataLen);
100 
101 /**
102  * @brief Sets the baud rate for an I2C device.
103  *
104  * @param id Indicates the I2C device ID.
105  * @param baudrate Indicates the baud rate to set.
106  * @return Returns {@link IOT_SUCCESS} if the baud rate is set;
107  * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
108  * @since 2.2
109  * @version 2.2
110  */
111 unsigned int IoTI2cSetBaudrate(unsigned int id, unsigned int baudrate);
112 
113 #endif // IOT_I2C_H
114 /** @} */
115