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_uart.h 310f99eeccSopenharmony_ci * 320f99eeccSopenharmony_ci * @brief Declares UART functions. 330f99eeccSopenharmony_ci * 340f99eeccSopenharmony_ci * These functions are used for UART initialization, 350f99eeccSopenharmony_ci * data input/output, and data flow control. \n 360f99eeccSopenharmony_ci * 370f99eeccSopenharmony_ci * @since 2.2 380f99eeccSopenharmony_ci * @version 2.2 390f99eeccSopenharmony_ci */ 400f99eeccSopenharmony_ci 410f99eeccSopenharmony_ci#ifndef IOT_UART_H 420f99eeccSopenharmony_ci#define IOT_UART_H 430f99eeccSopenharmony_ci 440f99eeccSopenharmony_ci/** 450f99eeccSopenharmony_ci * @brief Enumerates the number of UART data bits. 460f99eeccSopenharmony_ci * 470f99eeccSopenharmony_ci * @since 2.2 480f99eeccSopenharmony_ci * @version 2.2 490f99eeccSopenharmony_ci */ 500f99eeccSopenharmony_citypedef enum { 510f99eeccSopenharmony_ci /** 5 data bits */ 520f99eeccSopenharmony_ci IOT_UART_DATA_BIT_5 = 5, 530f99eeccSopenharmony_ci /** 6 data bits */ 540f99eeccSopenharmony_ci IOT_UART_DATA_BIT_6, 550f99eeccSopenharmony_ci /** 7 data bits */ 560f99eeccSopenharmony_ci IOT_UART_DATA_BIT_7, 570f99eeccSopenharmony_ci /** 8 data bits */ 580f99eeccSopenharmony_ci IOT_UART_DATA_BIT_8, 590f99eeccSopenharmony_ci} IotUartIdxDataBit; 600f99eeccSopenharmony_ci 610f99eeccSopenharmony_ci/** 620f99eeccSopenharmony_ci * @brief Enumerates the number of UART stop bits. 630f99eeccSopenharmony_ci * 640f99eeccSopenharmony_ci * @since 2.2 650f99eeccSopenharmony_ci * @version 2.2 660f99eeccSopenharmony_ci */ 670f99eeccSopenharmony_citypedef enum { 680f99eeccSopenharmony_ci /** 1 stop bit */ 690f99eeccSopenharmony_ci IOT_UART_STOP_BIT_1 = 1, 700f99eeccSopenharmony_ci /** 2 stop bits */ 710f99eeccSopenharmony_ci IOT_UART_STOP_BIT_2 = 2, 720f99eeccSopenharmony_ci} IotUartStopBit; 730f99eeccSopenharmony_ci 740f99eeccSopenharmony_ci/** 750f99eeccSopenharmony_ci * @brief Enumerates UART parity bits. 760f99eeccSopenharmony_ci * 770f99eeccSopenharmony_ci * @since 2.2 780f99eeccSopenharmony_ci * @version 2.2 790f99eeccSopenharmony_ci */ 800f99eeccSopenharmony_citypedef enum { 810f99eeccSopenharmony_ci /** No parity */ 820f99eeccSopenharmony_ci IOT_UART_PARITY_NONE = 0, 830f99eeccSopenharmony_ci /** Odd parity */ 840f99eeccSopenharmony_ci IOT_UART_PARITY_ODD = 1, 850f99eeccSopenharmony_ci /** Even parity */ 860f99eeccSopenharmony_ci IOT_UART_PARITY_EVEN = 2, 870f99eeccSopenharmony_ci} IotUartParity; 880f99eeccSopenharmony_ci 890f99eeccSopenharmony_ci/** 900f99eeccSopenharmony_ci * @brief Enumerates UART block states. 910f99eeccSopenharmony_ci * 920f99eeccSopenharmony_ci * @since 2.2 930f99eeccSopenharmony_ci * @version 2.2 940f99eeccSopenharmony_ci */ 950f99eeccSopenharmony_citypedef enum { 960f99eeccSopenharmony_ci /** Block disabled */ 970f99eeccSopenharmony_ci IOT_UART_BLOCK_STATE_NONE_BLOCK = 0, 980f99eeccSopenharmony_ci /** Block enabled */ 990f99eeccSopenharmony_ci IOT_UART_BLOCK_STATE_BLOCK, 1000f99eeccSopenharmony_ci} IotUartBlockState; 1010f99eeccSopenharmony_ci 1020f99eeccSopenharmony_ci/** 1030f99eeccSopenharmony_ci * @brief Enumerates hardware flow control modes. 1040f99eeccSopenharmony_ci * 1050f99eeccSopenharmony_ci * @since 2.2 1060f99eeccSopenharmony_ci * @version 2.2 1070f99eeccSopenharmony_ci */ 1080f99eeccSopenharmony_citypedef enum { 1090f99eeccSopenharmony_ci /** Hardware flow control disabled */ 1100f99eeccSopenharmony_ci IOT_FLOW_CTRL_NONE, 1110f99eeccSopenharmony_ci /** RTS and CTS hardware flow control enabled */ 1120f99eeccSopenharmony_ci IOT_FLOW_CTRL_RTS_CTS, 1130f99eeccSopenharmony_ci /** RTS hardware flow control enabled */ 1140f99eeccSopenharmony_ci IOT_FLOW_CTRL_RTS_ONLY, 1150f99eeccSopenharmony_ci /** CTS hardware flow control enabled */ 1160f99eeccSopenharmony_ci IOT_FLOW_CTRL_CTS_ONLY, 1170f99eeccSopenharmony_ci} IotFlowCtrl; 1180f99eeccSopenharmony_ci 1190f99eeccSopenharmony_ci/** 1200f99eeccSopenharmony_ci * @brief Defines basic attributes of a UART port. 1210f99eeccSopenharmony_ci * 1220f99eeccSopenharmony_ci * @since 2.2 1230f99eeccSopenharmony_ci * @version 2.2 1240f99eeccSopenharmony_ci */ 1250f99eeccSopenharmony_citypedef struct { 1260f99eeccSopenharmony_ci /** Baud rate */ 1270f99eeccSopenharmony_ci unsigned int baudRate; 1280f99eeccSopenharmony_ci /** Data bits */ 1290f99eeccSopenharmony_ci IotUartIdxDataBit dataBits; 1300f99eeccSopenharmony_ci /** Stop bit */ 1310f99eeccSopenharmony_ci IotUartStopBit stopBits; 1320f99eeccSopenharmony_ci /** Parity */ 1330f99eeccSopenharmony_ci IotUartParity parity; 1340f99eeccSopenharmony_ci /** Rx block state */ 1350f99eeccSopenharmony_ci IotUartBlockState rxBlock; 1360f99eeccSopenharmony_ci /** Tx block state */ 1370f99eeccSopenharmony_ci IotUartBlockState txBlock; 1380f99eeccSopenharmony_ci /** Padding bit */ 1390f99eeccSopenharmony_ci unsigned char pad; 1400f99eeccSopenharmony_ci} IotUartAttribute; 1410f99eeccSopenharmony_ci 1420f99eeccSopenharmony_ci/** 1430f99eeccSopenharmony_ci * @brief Configures a UART device with the port number specified by <b>id</b> 1440f99eeccSopenharmony_ci * based on the basic and extended attributes. 1450f99eeccSopenharmony_ci * 1460f99eeccSopenharmony_ci * 1470f99eeccSopenharmony_ci * 1480f99eeccSopenharmony_ci * @param id Indicates the port number of the UART device. 1490f99eeccSopenharmony_ci * @param param Indicates the pointer to the UART attributes. 1500f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the UART device is configured successfully; 1510f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1520f99eeccSopenharmony_ci * @since 2.2 1530f99eeccSopenharmony_ci * @version 2.2 1540f99eeccSopenharmony_ci */ 1550f99eeccSopenharmony_ciunsigned int IoTUartInit(unsigned int id, const IotUartAttribute *param); 1560f99eeccSopenharmony_ci 1570f99eeccSopenharmony_ci/** 1580f99eeccSopenharmony_ci * @brief Reads a specified length of data from a UART device with the port number specified by <b>id</b>. 1590f99eeccSopenharmony_ci * 1600f99eeccSopenharmony_ci * 1610f99eeccSopenharmony_ci * 1620f99eeccSopenharmony_ci * @param id Indicates the port number of the UART device. 1630f99eeccSopenharmony_ci * @param data Indicates the pointer to the start address of the data to read. 1640f99eeccSopenharmony_ci * @param dataLen Indicates the number of bytes to read. 1650f99eeccSopenharmony_ci * @return Returns the number of bytes read if the operation is successful; returns <b>-1</b> otherwise. 1660f99eeccSopenharmony_ci * @since 2.2 1670f99eeccSopenharmony_ci * @version 2.2 1680f99eeccSopenharmony_ci */ 1690f99eeccSopenharmony_ciint IoTUartRead(unsigned int id, unsigned char *data, unsigned int dataLen); 1700f99eeccSopenharmony_ci 1710f99eeccSopenharmony_ci/** 1720f99eeccSopenharmony_ci * @brief Writes a specified length of data to a UART device with the port number specified by <b>id</b>. 1730f99eeccSopenharmony_ci * 1740f99eeccSopenharmony_ci * 1750f99eeccSopenharmony_ci * 1760f99eeccSopenharmony_ci * @param id Indicates the port number of the UART device. 1770f99eeccSopenharmony_ci * @param data Indicates the pointer to the start address of the data to write. 1780f99eeccSopenharmony_ci * @param dataLen Indicates the number of bytes to write. 1790f99eeccSopenharmony_ci * @return Returns the number of bytes written if the operation is successful; returns <b>-1</b> otherwise. 1800f99eeccSopenharmony_ci * @since 2.2 1810f99eeccSopenharmony_ci * @version 2.2 1820f99eeccSopenharmony_ci */ 1830f99eeccSopenharmony_ciint IoTUartWrite(unsigned int id, const unsigned char *data, unsigned int dataLen); 1840f99eeccSopenharmony_ci 1850f99eeccSopenharmony_ci/** 1860f99eeccSopenharmony_ci * @brief Deinitializes a UART device. 1870f99eeccSopenharmony_ci * 1880f99eeccSopenharmony_ci * @param id Indicates the port number of the UART device. 1890f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the UART device is deinitialized; 1900f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1910f99eeccSopenharmony_ci * @since 2.2 1920f99eeccSopenharmony_ci * @version 2.2 1930f99eeccSopenharmony_ci */ 1940f99eeccSopenharmony_ciunsigned int IoTUartDeinit(unsigned int id); 1950f99eeccSopenharmony_ci 1960f99eeccSopenharmony_ci/** 1970f99eeccSopenharmony_ci * @brief Sets flow control for a UART device with the port number specified by <b>id</b>. 1980f99eeccSopenharmony_ci * 1990f99eeccSopenharmony_ci * 2000f99eeccSopenharmony_ci * 2010f99eeccSopenharmony_ci * @param id Indicates the port number of the UART device. 2020f99eeccSopenharmony_ci * @param flowCtrl Indicates the flow control parameters, as enumerated in {@link IotFlowCtrl}. 2030f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if flow control is set successfully; 2040f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 2050f99eeccSopenharmony_ci * @since 2.2 2060f99eeccSopenharmony_ci * @version 2.2 2070f99eeccSopenharmony_ci */ 2080f99eeccSopenharmony_ciunsigned int IoTUartSetFlowCtrl(unsigned int id, IotFlowCtrl flowCtrl); 2090f99eeccSopenharmony_ci 2100f99eeccSopenharmony_ci#endif // IOT_UART_H 2110f99eeccSopenharmony_ci/** @} */ 212