10f99eeccSopenharmony_ci/*
20f99eeccSopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd.
30f99eeccSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40f99eeccSopenharmony_ci * you may not use this file except in compliance with the License.
50f99eeccSopenharmony_ci * You may obtain a copy of the License at
60f99eeccSopenharmony_ci *
70f99eeccSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80f99eeccSopenharmony_ci *
90f99eeccSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100f99eeccSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110f99eeccSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120f99eeccSopenharmony_ci * See the License for the specific language governing permissions and
130f99eeccSopenharmony_ci * limitations under the License.
140f99eeccSopenharmony_ci */
150f99eeccSopenharmony_ci
160f99eeccSopenharmony_ci/**
170f99eeccSopenharmony_ci * @addtogroup IotHardware
180f99eeccSopenharmony_ci * @{
190f99eeccSopenharmony_ci *
200f99eeccSopenharmony_ci * @brief Provides APIs for operating devices,
210f99eeccSopenharmony_ci * including flash, GPIO, I2C, PWM, UART, and watchdog APIs.
220f99eeccSopenharmony_ci *
230f99eeccSopenharmony_ci *
240f99eeccSopenharmony_ci *
250f99eeccSopenharmony_ci * @since 2.2
260f99eeccSopenharmony_ci * @version 2.2
270f99eeccSopenharmony_ci */
280f99eeccSopenharmony_ci
290f99eeccSopenharmony_ci/**
300f99eeccSopenharmony_ci * @file iot_i2c.h
310f99eeccSopenharmony_ci *
320f99eeccSopenharmony_ci * @brief Declares functions for operating I2C devices.
330f99eeccSopenharmony_ci *
340f99eeccSopenharmony_ci * These functions are used to initialize or deinitialize an I2C device,
350f99eeccSopenharmony_ci * and read data from or write data to an I2C device. \n
360f99eeccSopenharmony_ci *
370f99eeccSopenharmony_ci * @since 2.2
380f99eeccSopenharmony_ci * @version 2.2
390f99eeccSopenharmony_ci */
400f99eeccSopenharmony_ci
410f99eeccSopenharmony_ci#ifndef IOT_I2C_H
420f99eeccSopenharmony_ci#define IOT_I2C_H
430f99eeccSopenharmony_ci
440f99eeccSopenharmony_ci/**
450f99eeccSopenharmony_ci * @brief Initializes an I2C device with a specified baud rate.
460f99eeccSopenharmony_ci *
470f99eeccSopenharmony_ci *
480f99eeccSopenharmony_ci *
490f99eeccSopenharmony_ci * @param id Indicates the I2C device ID.
500f99eeccSopenharmony_ci * @param baudrate Indicates the I2C baud rate.
510f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the I2C device is initialized;
520f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
530f99eeccSopenharmony_ci * @since 2.2
540f99eeccSopenharmony_ci * @version 2.2
550f99eeccSopenharmony_ci */
560f99eeccSopenharmony_ciunsigned int IoTI2cInit(unsigned int id, unsigned int baudrate);
570f99eeccSopenharmony_ci
580f99eeccSopenharmony_ci/**
590f99eeccSopenharmony_ci * @brief Deinitializes an I2C device.
600f99eeccSopenharmony_ci *
610f99eeccSopenharmony_ci * @param id Indicates the I2C device ID.
620f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the I2C device is deinitialized;
630f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
640f99eeccSopenharmony_ci * @since 2.2
650f99eeccSopenharmony_ci * @version 2.2
660f99eeccSopenharmony_ci */
670f99eeccSopenharmony_ciunsigned int IoTI2cDeinit(unsigned int id);
680f99eeccSopenharmony_ci
690f99eeccSopenharmony_ci/**
700f99eeccSopenharmony_ci * @brief Writes data to an I2C device.
710f99eeccSopenharmony_ci *
720f99eeccSopenharmony_ci *
730f99eeccSopenharmony_ci *
740f99eeccSopenharmony_ci * @param id Indicates the I2C device ID.
750f99eeccSopenharmony_ci * @param deviceAddr Indicates the I2C device address.
760f99eeccSopenharmony_ci * @param data Indicates the pointer to the data to write.
770f99eeccSopenharmony_ci * @param dataLen Indicates the length of the data to write.
780f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the data is written to the I2C device successfully;
790f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
800f99eeccSopenharmony_ci * @since 2.2
810f99eeccSopenharmony_ci * @version 2.2
820f99eeccSopenharmony_ci */
830f99eeccSopenharmony_ciunsigned int IoTI2cWrite(unsigned int id, unsigned short deviceAddr, const unsigned char *data, unsigned int dataLen);
840f99eeccSopenharmony_ci
850f99eeccSopenharmony_ci/**
860f99eeccSopenharmony_ci * @brief Reads data from an I2C device.
870f99eeccSopenharmony_ci *
880f99eeccSopenharmony_ci * The data read will be saved to the address specified by <b>i2cData</b>.
890f99eeccSopenharmony_ci *
900f99eeccSopenharmony_ci * @param id Indicates the I2C device ID.
910f99eeccSopenharmony_ci * @param deviceAddr Indicates the I2C device address.
920f99eeccSopenharmony_ci * @param data Indicates the pointer to the data to read.
930f99eeccSopenharmony_ci * @param dataLen Indicates the length of the data to read.
940f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the data is read from the I2C device successfully;
950f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
960f99eeccSopenharmony_ci * @since 2.2
970f99eeccSopenharmony_ci * @version 2.2
980f99eeccSopenharmony_ci */
990f99eeccSopenharmony_ciunsigned int IoTI2cRead(unsigned int id, unsigned short deviceAddr, unsigned char *data, unsigned int dataLen);
1000f99eeccSopenharmony_ci
1010f99eeccSopenharmony_ci/**
1020f99eeccSopenharmony_ci * @brief Sets the baud rate for an I2C device.
1030f99eeccSopenharmony_ci *
1040f99eeccSopenharmony_ci * @param id Indicates the I2C device ID.
1050f99eeccSopenharmony_ci * @param baudrate Indicates the baud rate to set.
1060f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the baud rate is set;
1070f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description.
1080f99eeccSopenharmony_ci * @since 2.2
1090f99eeccSopenharmony_ci * @version 2.2
1100f99eeccSopenharmony_ci */
1110f99eeccSopenharmony_ciunsigned int IoTI2cSetBaudrate(unsigned int id, unsigned int baudrate);
1120f99eeccSopenharmony_ci
1130f99eeccSopenharmony_ci#endif // IOT_I2C_H
1140f99eeccSopenharmony_ci/** @} */
115