加入收藏
举报
02-14 20:03
#0
文件名称:
gpio.md
所在目录:
Openharmony v1.0 / docs / docs-en / api / api-SmartVision-Devices
文件大小:
28.58 KB
下载地址:
fenwii/OpenHarmony
   
免责声明:本网站仅提供指向 GitHub 上的文件的链接,所有文件的版权归原作者所有,本网站不对文件内容的合法性、准确性或安全性承担任何责任。
文本预览:
# GPIO
## **Overview**
Provides standard general-purpose input/output \(GPIO\) interfaces for driver development.
You can use this module to perform operations on a GPIO pin, including setting the input/output direction, reading/writing the level value, and setting the interrupt service routine \(ISR\) function.
**Since:**
1.0
## **Summary**
## Files









File Name


Description


gpio_if.h


Declares the standard GPIO interface functions.



## Typedefs









Typedef Name


Description


GpioIrqFunc) (uint16_t gpio, void *data)


typedef int32_t(*


Defines the function type of a GPIO interrupt service routine (ISR).



## Enumerations












Enumeration Name


Description


GpioValue { GPIO_VAL_LOW = 0, GPIO_VAL_HIGH = 1, GPIO_VAL_ERR }


Enumerates GPIO level values.


GpioDirType { GPIO_DIR_IN = 0, GPIO_DIR_OUT = 1, GPIO_DIR_ERR }


Enumerates GPIO directions.



## Functions






























Function Name


Description


GpioRead (uint16_t gpio, uint16_t *val)


int32_t


Reads the level value of a GPIO pin.


GpioWrite (uint16_t gpio, uint16_t val)


int32_t


Writes the level value for a GPIO pin.


GpioSetDir (uint16_t gpio, uint16_t dir)


int32_t


Sets the input/output direction for a GPIO pin.


GpioGetDir (uint16_t gpio, uint16_t *dir)


int32_t


Obtains the input/output direction of a GPIO pin.


GpioSetIrq (uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg)


int32_t


Sets the ISR function for a GPIO pin.


GpioUnSetIrq (uint16_t gpio)


int32_t


Cancels the setting of the ISR function for a GPIO pin.


GpioEnableIrq (uint16_t gpio)


int32_t


Enables a GPIO pin interrupt.


GpioDisableIrq (uint16_t gpio)


int32_t


Disables a GPIO pin interrupt.



## **Details**
## **Typedef Documentation**
## GpioIrqFunc
```
typedef int32_t(* GpioIrqFunc) (uint16_t gpio, void *data)
```
**Description:**
Defines the function type of a GPIO interrupt service routine \(ISR\).
This function is used when you call [GpioSetIrq](gpio.md#ga6ea5d16b8d73cb74e36d367f05cb7f6e) to register the ISR for a GPIO pin.
**Parameters:**












Name


Description


gpio Indicates the GPIO number of the ISR.
data Indicates the pointer to the private data passed to this ISR (The data is specified when the ISR is registered).

**Returns:**
Returns **0** if the ISR function type is successfully defined; returns a negative value otherwise.
**See also:**
[GpioSetIrq](gpio.md#ga6ea5d16b8d73cb74e36d367f05cb7f6e)
## **Enumeration Type Documentation**
## GpioDirType
```
enum [GpioDirType](gpio.md#ga71f27d3ba7ca04d9448199fca38ae19d)
```
**Description:**
Enumerates GPIO directions.















Enumerator


Description


GPIO_DIR_IN

Input direction


GPIO_DIR_OUT

Output direction


GPIO_DIR_ERR

Invalid direction



## GpioValue
```
enum [GpioValue](gpio.md#ga6a25a3efddf2301c7b01a7f0af44fb11)
```
**Description:**
Enumerates GPIO level values.















Enumerator


Description


GPIO_VAL_LOW

Low GPIO level


GPIO_VAL_HIGH

High GPIO level


GPIO_VAL_ERR

Invalid GPIO level



## **Function Documentation**
## GpioDisableIrq\(\)
```
int32_t GpioDisableIrq (uint16_t gpio)
```
**Description:**
Disables a GPIO pin interrupt.
You can call this function when you need to temporarily mask a GPIO pin interrupt or cancel an ISR function.
**Parameters:**









Name


Description


gpio Indicates the GPIO pin number.

**Returns:**
Returns **0** if the GPIO pin interrupt is successfully disabled; returns a negative value otherwise.
## GpioEnableIrq\(\)
```
int32_t GpioEnableIrq (uint16_t gpio)
```
**Description:**
Enables a GPIO pin interrupt.
Before enabling the interrupt, you must call [GpioSetIrq](gpio.md#ga6ea5d16b8d73cb74e36d367f05cb7f6e) to set the ISR function for the GPIO pin.
**Parameters:**









Name


Description


gpio Indicates the GPIO pin number.

**Returns:**
Returns **0** if the GPIO pin interrupt is successfully enabled; returns a negative value otherwise.
## GpioGetDir\(\)
```
int32_t GpioGetDir (uint16_t gpio, uint16_t * dir )
```
**Description:**
Obtains the input/output direction of a GPIO pin.
**Parameters:**












Name


Description


gpio Indicates the GPIO pin number.
dir Indicates the pointer to the obtained input/output direction. For details, see GpioDirType.

**Returns:**
Returns **0** if the GPIO pin direction is successfully obtained; returns a negative value otherwise.
## GpioRead\(\)
```
int32_t GpioRead (uint16_t gpio, uint16_t * val )
```
**Description:**
Reads the level value of a GPIO pin.
Before using this function, you need to call [GpioSetDir](gpio.md#ga5c628216d209fa76c69eca69856bc0ae) to set the GPIO pin direction to input.
**Parameters:**












Name


Description


gpio Indicates the GPIO pin number.
val Indicates the pointer to the read level value. For details, see GpioValue.

**Returns:**
Returns **0** if the GPIO pin level value is successfully read; returns a negative value otherwise.
## GpioSetDir\(\)
```
int32_t GpioSetDir (uint16_t gpio, uint16_t dir )
```
**Description:**
Sets the input/output direction for a GPIO pin.
Generally, you can set the direction to input when external level signals need to be read, and set the direction to output when the level signals need to be sent externally.
**Parameters:**












Name


Description


gpio Indicates the GPIO pin number.
dir Indicates the direction to set. For details, see GpioDirType.

**Returns:**
Returns **0** if the GPIO pin direction is successfully set; returns a negative value otherwise.
## GpioSetIrq\(\)
```
int32_t GpioSetIrq (uint16_t gpio, uint16_t mode, [GpioIrqFunc](gpio.md#ga8f3b7d0f0aaa1da8117781efe4b1670e) func, void * arg )
```
**Description:**
Sets the ISR function for a GPIO pin.
Before using a GPIO pin as an interrupt, you must call this function to set an ISR function for this GPIO pin, including the ISR parameters and the interrupt trigger mode. After the setting is successful, you also need to call [GpioEnableIrq](gpio.md#gafcf00796a949245d665e672ae0294aee) to enable the interrupt, so that the ISR function can respond correctly.
**Parameters:**


















Name


Description


gpio Indicates the GPIO pin number.
mode Indicates the interrupt trigger mode. For details, see OSAL_IRQF_TRIGGER_RISING.
func Indicates the ISR function to set, which is specified by GpioIrqFunc.
arg Indicates the pointer to the parameters passed to the ISR function.

**Returns:**
Returns **0** if the ISR function of the GPIO pin is successfully set; returns a negative value otherwise.
## GpioUnSetIrq\(\)
```
int32_t GpioUnSetIrq (uint16_t gpio)
```
**Description:**
Cancels the setting of the ISR function for a GPIO pin.
If you do not need the GPIO pin as an interrupt, call this function to cancel the ISR function set via [GpioSetIrq](gpio.md#ga6ea5d16b8d73cb74e36d367f05cb7f6e). Since this ISR function is no longer valid, you are advised to use [GpioDisableIrq](gpio.md#gafa01dc510f26d5aff102d72679920929) to disable the GPIO pin interrupt.
**Parameters:**









Name


Description


gpio Indicates the GPIO pin number.

**Returns:**
Returns **0** if the ISR function of the GPIO pin is successfully cancelled; returns a negative value otherwise.
## GpioWrite\(\)
```
int32_t GpioWrite (uint16_t gpio, uint16_t val )
```
**Description:**
Writes the level value for a GPIO pin.
Before using this function, you need to call [GpioSetDir](gpio.md#ga5c628216d209fa76c69eca69856bc0ae) to set the GPIO pin direction to output.
**Parameters:**












Name


Description


gpio Indicates the GPIO pin number.
val Indicates the level value to be written. For details, see GpioValue.

**Returns:**
Returns **0** if the GPIO pin level value is successfully written; returns a negative value otherwise.
点赞 回复
回帖
支持markdown部分语法 ?