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_gpio.h 310f99eeccSopenharmony_ci * 320f99eeccSopenharmony_ci * @brief Declares functions for operating GPIO devices. 330f99eeccSopenharmony_ci * 340f99eeccSopenharmony_ci * These functions are used for GPIO initialization, input/output settings, and level settings. \n 350f99eeccSopenharmony_ci * 360f99eeccSopenharmony_ci * @since 2.2 370f99eeccSopenharmony_ci * @version 2.2 380f99eeccSopenharmony_ci */ 390f99eeccSopenharmony_ci#ifndef IOT_GPIO_H 400f99eeccSopenharmony_ci#define IOT_GPIO_H 410f99eeccSopenharmony_ci 420f99eeccSopenharmony_ci/** 430f99eeccSopenharmony_ci * @brief Enumerates GPIO level values. 440f99eeccSopenharmony_ci */ 450f99eeccSopenharmony_citypedef enum { 460f99eeccSopenharmony_ci /** Low GPIO level */ 470f99eeccSopenharmony_ci IOT_GPIO_VALUE0 = 0, 480f99eeccSopenharmony_ci /** High GPIO level */ 490f99eeccSopenharmony_ci IOT_GPIO_VALUE1 500f99eeccSopenharmony_ci} IotGpioValue; 510f99eeccSopenharmony_ci 520f99eeccSopenharmony_ci/** 530f99eeccSopenharmony_ci * @brief Enumerates GPIO directions. 540f99eeccSopenharmony_ci */ 550f99eeccSopenharmony_citypedef enum { 560f99eeccSopenharmony_ci /** Input */ 570f99eeccSopenharmony_ci IOT_GPIO_DIR_IN = 0, 580f99eeccSopenharmony_ci /** Output */ 590f99eeccSopenharmony_ci IOT_GPIO_DIR_OUT 600f99eeccSopenharmony_ci} IotGpioDir; 610f99eeccSopenharmony_ci 620f99eeccSopenharmony_ci/** 630f99eeccSopenharmony_ci * @brief Enumerates GPIO interrupt trigger modes. 640f99eeccSopenharmony_ci */ 650f99eeccSopenharmony_citypedef enum { 660f99eeccSopenharmony_ci /** Level-sensitive interrupt */ 670f99eeccSopenharmony_ci IOT_INT_TYPE_LEVEL = 0, 680f99eeccSopenharmony_ci /** Edge-sensitive interrupt */ 690f99eeccSopenharmony_ci IOT_INT_TYPE_EDGE 700f99eeccSopenharmony_ci} IotGpioIntType; 710f99eeccSopenharmony_ci 720f99eeccSopenharmony_ci/** 730f99eeccSopenharmony_ci * @brief Enumerates I/O interrupt polarities. 740f99eeccSopenharmony_ci */ 750f99eeccSopenharmony_citypedef enum { 760f99eeccSopenharmony_ci /** Interrupt at a low level or falling edge */ 770f99eeccSopenharmony_ci IOT_GPIO_EDGE_FALL_LEVEL_LOW = 0, 780f99eeccSopenharmony_ci /** Interrupt at a high level or rising edge */ 790f99eeccSopenharmony_ci IOT_GPIO_EDGE_RISE_LEVEL_HIGH 800f99eeccSopenharmony_ci} IotGpioIntPolarity; 810f99eeccSopenharmony_ci 820f99eeccSopenharmony_ci/** 830f99eeccSopenharmony_ci * @brief Indicates the GPIO interrupt callback. 840f99eeccSopenharmony_ci * 850f99eeccSopenharmony_ci */ 860f99eeccSopenharmony_citypedef void (*GpioIsrCallbackFunc) (char *arg); 870f99eeccSopenharmony_ci 880f99eeccSopenharmony_ci/** 890f99eeccSopenharmony_ci * @brief Initializes a GPIO device. 900f99eeccSopenharmony_ci * 910f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 920f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the GPIO device is initialized; 930f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 940f99eeccSopenharmony_ci * @since 2.2 950f99eeccSopenharmony_ci * @version 2.2 960f99eeccSopenharmony_ci */ 970f99eeccSopenharmony_ciunsigned int IoTGpioInit(unsigned int id); 980f99eeccSopenharmony_ci 990f99eeccSopenharmony_ci/** 1000f99eeccSopenharmony_ci * @brief Deinitializes a GPIO device. 1010f99eeccSopenharmony_ci * 1020f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1030f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the GPIO device is deinitialized; 1040f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1050f99eeccSopenharmony_ci * @since 2.2 1060f99eeccSopenharmony_ci * @version 2.2 1070f99eeccSopenharmony_ci */ 1080f99eeccSopenharmony_ciunsigned int IoTGpioDeinit(unsigned int id); 1090f99eeccSopenharmony_ci 1100f99eeccSopenharmony_ci/** 1110f99eeccSopenharmony_ci * @brief Sets the direction for a GPIO pin. 1120f99eeccSopenharmony_ci * 1130f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1140f99eeccSopenharmony_ci * @param dir Indicates the GPIO input/output direction. 1150f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the direction is set; 1160f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1170f99eeccSopenharmony_ci * @since 2.2 1180f99eeccSopenharmony_ci * @version 2.2 1190f99eeccSopenharmony_ci */ 1200f99eeccSopenharmony_ciunsigned int IoTGpioSetDir(unsigned int id, IotGpioDir dir); 1210f99eeccSopenharmony_ci 1220f99eeccSopenharmony_ci/** 1230f99eeccSopenharmony_ci * @brief Obtains the direction for a GPIO pin. 1240f99eeccSopenharmony_ci * 1250f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1260f99eeccSopenharmony_ci * @param dir Indicates the pointer to the GPIO input/output direction. 1270f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the direction is obtained; 1280f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1290f99eeccSopenharmony_ci * @since 2.2 1300f99eeccSopenharmony_ci * @version 2.2 1310f99eeccSopenharmony_ci */ 1320f99eeccSopenharmony_ciunsigned int IoTGpioGetDir(unsigned int id, IotGpioDir *dir); 1330f99eeccSopenharmony_ci 1340f99eeccSopenharmony_ci/** 1350f99eeccSopenharmony_ci * @brief Sets the output level value for a GPIO pin. 1360f99eeccSopenharmony_ci * 1370f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1380f99eeccSopenharmony_ci * @param val Indicates the output level value. 1390f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the output level value is set; 1400f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1410f99eeccSopenharmony_ci * @since 2.2 1420f99eeccSopenharmony_ci * @version 2.2 1430f99eeccSopenharmony_ci */ 1440f99eeccSopenharmony_ciunsigned int IoTGpioSetOutputVal(unsigned int id, IotGpioValue val); 1450f99eeccSopenharmony_ci 1460f99eeccSopenharmony_ci/** 1470f99eeccSopenharmony_ci * @brief Obtains the output level value of a GPIO pin. 1480f99eeccSopenharmony_ci * 1490f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1500f99eeccSopenharmony_ci * @param val Indicates the pointer to the output level value. 1510f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the output level value is obtained; 1520f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1530f99eeccSopenharmony_ci * @since 2.2 1540f99eeccSopenharmony_ci * @version 2.2 1550f99eeccSopenharmony_ci */ 1560f99eeccSopenharmony_ciunsigned int IoTGpioGetOutputVal(unsigned int id, IotGpioValue *val); 1570f99eeccSopenharmony_ci 1580f99eeccSopenharmony_ci/** 1590f99eeccSopenharmony_ci * @brief Obtains the input level value of a GPIO pin. 1600f99eeccSopenharmony_ci * 1610f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1620f99eeccSopenharmony_ci * @param val Indicates the pointer to the input level value. 1630f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the input level value is obtained; 1640f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1650f99eeccSopenharmony_ci * @since 2.2 1660f99eeccSopenharmony_ci * @version 2.2 1670f99eeccSopenharmony_ci */ 1680f99eeccSopenharmony_ciunsigned int IoTGpioGetInputVal(unsigned int id, IotGpioValue *val); 1690f99eeccSopenharmony_ci 1700f99eeccSopenharmony_ci/** 1710f99eeccSopenharmony_ci * @brief Enables the interrupt feature for a GPIO pin. 1720f99eeccSopenharmony_ci * 1730f99eeccSopenharmony_ci * This function can be used to set the interrupt type, interrupt polarity, and interrupt callback for a GPIO pin. 1740f99eeccSopenharmony_ci * 1750f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1760f99eeccSopenharmony_ci * @param intType Indicates the interrupt type. 1770f99eeccSopenharmony_ci * @param intPolarity Indicates the interrupt polarity. 1780f99eeccSopenharmony_ci * @param func Indicates the interrupt callback function. 1790f99eeccSopenharmony_ci * @param arg Indicates the pointer to the argument used in the interrupt callback function. 1800f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the interrupt feature is enabled; 1810f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1820f99eeccSopenharmony_ci * @since 2.2 1830f99eeccSopenharmony_ci * @version 2.2 1840f99eeccSopenharmony_ci */ 1850f99eeccSopenharmony_ciunsigned int IoTGpioRegisterIsrFunc(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity, 1860f99eeccSopenharmony_ci GpioIsrCallbackFunc func, char *arg); 1870f99eeccSopenharmony_ci 1880f99eeccSopenharmony_ci/** 1890f99eeccSopenharmony_ci * @brief Disables the interrupt feature for a GPIO pin. 1900f99eeccSopenharmony_ci * 1910f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 1920f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the interrupt feature is disabled; 1930f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 1940f99eeccSopenharmony_ci * @since 2.2 1950f99eeccSopenharmony_ci * @version 2.2 1960f99eeccSopenharmony_ci */ 1970f99eeccSopenharmony_ciunsigned int IoTGpioUnregisterIsrFunc(unsigned int id); 1980f99eeccSopenharmony_ci 1990f99eeccSopenharmony_ci/** 2000f99eeccSopenharmony_ci * @brief Masks the interrupt feature for a GPIO pin. 2010f99eeccSopenharmony_ci * 2020f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 2030f99eeccSopenharmony_ci * @param mask Indicates whether the interrupt function is masked. 2040f99eeccSopenharmony_ci * The value <b>1</b> means to mask the interrupt function, and <b>0</b> means not to mask the interrupt function. 2050f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the interrupt feature is masked; 2060f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 2070f99eeccSopenharmony_ci * @since 2.2 2080f99eeccSopenharmony_ci * @version 2.2 2090f99eeccSopenharmony_ci */ 2100f99eeccSopenharmony_ciunsigned int IoTGpioSetIsrMask(unsigned int id, unsigned char mask); 2110f99eeccSopenharmony_ci 2120f99eeccSopenharmony_ci/** 2130f99eeccSopenharmony_ci * @brief Sets the interrupt trigger mode of a GPIO pin. 2140f99eeccSopenharmony_ci * 2150f99eeccSopenharmony_ci * This function configures a GPIO pin based on the interrupt type and interrupt polarity. 2160f99eeccSopenharmony_ci * 2170f99eeccSopenharmony_ci * @param id Indicates the GPIO pin number. 2180f99eeccSopenharmony_ci * @param intType Indicates the interrupt type. 2190f99eeccSopenharmony_ci * @param intPolarity Indicates the interrupt polarity. 2200f99eeccSopenharmony_ci * @return Returns {@link IOT_SUCCESS} if the interrupt trigger mode is set; 2210f99eeccSopenharmony_ci * returns {@link IOT_FAILURE} otherwise. For details about other return values, see the chip description. 2220f99eeccSopenharmony_ci * @since 2.2 2230f99eeccSopenharmony_ci * @version 2.2 2240f99eeccSopenharmony_ci */ 2250f99eeccSopenharmony_ciunsigned int IoTGpioSetIsrMode(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity); 2260f99eeccSopenharmony_ci 2270f99eeccSopenharmony_ci#endif // IOT_GPIO_H 2280f99eeccSopenharmony_ci/** @} */ 229