搜档网
当前位置:搜档网 › 2 如何使用gpio的接口函数

2 如何使用gpio的接口函数

一、什么是gpio的接口函数
在嵌入式linux中,GPIO是最基本、最简单的外设模块,一般将gpio驱动的访问设计成了标准的接口函数,用法比较简单,不需要操作寄存器。

==========================================================================
二、GPIO的接口函数
#include

1、GPIO的申请
/* request GPIO, returning 0 or negative errno.
* non-null labels may be useful for diagnostics.
*/
int gpio_request(unsigned gpio, const char *label);


2、设置GPIO的方向
/* set as input or output, returning 0 or negative errno */
//将一个GPIO设置为输入
int gpio_direction_input(unsigned gpio);

//将一个GPIO设置为输出,并设置输出的初始值
int gpio_direction_output(unsigned gpio, int value);


3、设置gpio的输出值
/* GPIO OUTPUT */
void gpio_set_value(unsigned gpio, int value);


4、获得gpio的输入值
/* GPIO INPUT: return zero or nonzero */
int gpio_get_value(unsigned gpio);


5、释放gpio
/* release previously-claimed GPIO */
void gpio_free(unsigned gpio);

==========================================================================
三、GPIO号
linux/arch/arm/mach-s5pv210/include/mach/gpio.h

/* S5PV210 GPIO number definitions */
#define S5PV210_GPA0(_nr) (S5PV210_GPIO_A0_START + (_nr))
#define S5PV210_GPA1(_nr) (S5PV210_GPIO_A1_START + (_nr))
#define S5PV210_GPB(_nr) (S5PV210_GPIO_B_START + (_nr))
#define S5PV210_GPC0(_nr) (S5PV210_GPIO_C0_START + (_nr))
#define S5PV210_GPC1(_nr) (S5PV210_GPIO_C1_START + (_nr))
#define S5PV210_GPD0(_nr) (S5PV210_GPIO_D0_START + (_nr))
#define S5PV210_GPD1(_nr) (S5PV210_GPIO_D1_START + (_nr))
#define S5PV210_GPE0(_nr) (S5PV210_GPIO_E0_START + (_nr))
#define S5PV210_GPE1(_nr) (S5PV210_GPIO_E1_START + (_nr))
#define S5PV210_GPF0(_nr) (S5PV210_GPIO_F0_START + (_nr))
#define S5PV210_GPF1(_nr) (S5PV210_GPIO_F1_START + (_nr))
#define S5PV210_GPF2(_nr) (S5PV210_GPIO_F2_START + (_nr))
#define S5PV210_GPF3(_nr) (S5PV210_GPIO_F3_START + (_nr))
#define S5PV210_GPG0(_nr) (S5PV210_GPIO_G0_START + (_nr))
#define S5PV210_GPG1(_nr) (S5PV210_GPIO_G1_START + (_nr))
#define S5PV210_GPG2(_nr) (S5PV210_GPIO_G2_START + (_nr))
#define S5PV210_GPG3(_nr) (S5PV210_GPIO_G3_START + (_nr))
#define S5PV210_GPH0(_nr) (S5PV210_GPIO_H0_START + (_nr))
#define S5PV210_GPH1(_nr) (S5PV210_GPIO_H1_START + (_nr))
#define S5PV210_GPH2(_nr) (S5PV210_GPIO_H2_START + (_nr))
#define S5PV210_GPH3(_nr) (S5PV210_GPIO_H3_START + (_nr))
#define S5PV210_GPI(_nr) (S5PV210_GPIO_I_START + (_nr))
#define S5PV210_GPJ0(_nr) (S5PV210_GPIO_J0_START + (_nr))
#define S5PV210_GPJ1(_nr) (S5PV210_GPIO_J1_START + (_nr))
#define S5PV210_GPJ2(_nr) (S5PV210_GPIO_J2_START + (_nr))
#define S5PV210_GPJ3(_nr) (S5PV210_GPIO_J3_START + (_nr))
#define S5PV210_GPJ4(_nr) (S5PV210_GPIO_J4_START + (_nr))
#define S5PV210_MP01(_nr) (S5PV210_GPIO_MP01_START + (_nr))
#define S5PV210_MP02(_nr) (S5PV210_GPIO_MP02_START

+ (_nr))
#define S5PV210_MP03(_nr) (S5PV210_GPIO_MP03_START + (_nr))
#define S5PV210_MP04(_nr) (S5PV210_GPIO_MP04_START + (_nr))
#define S5PV210_MP05(_nr) (S5PV210_GPIO_MP05_START + (_nr))
#define S5PV210_MP06(_nr) (S5PV210_GPIO_MP06_START + (_nr))
#define S5PV210_MP07(_nr) (S5PV210_GPIO_MP07_START + (_nr))
#define S5PV210_MP10(_nr) (S5PV210_GPIO_MP10_START + (_nr))
#define S5PV210_MP11(_nr) (S5PV210_GPIO_MP11_START + (_nr))
#define S5PV210_MP12(_nr) (S5PV210_GPIO_MP12_START + (_nr))
#define S5PV210_MP13(_nr) (S5PV210_GPIO_MP13_START + (_nr))
#define S5PV210_MP14(_nr) (S5PV210_GPIO_MP14_START + (_nr))
#define S5PV210_MP15(_nr) (S5PV210_GPIO_MP15_START + (_nr))
#define S5PV210_MP16(_nr) (S5PV210_GPIO_MP16_START + (_nr))
#define S5PV210_MP17(_nr) (S5PV210_GPIO_MP17_START + (_nr))
#define S5PV210_MP18(_nr) (S5PV210_GPIO_MP18_START + (_nr))
#define S5PV210_MP20(_nr) (S5PV210_GPIO_MP20_START + (_nr))
#define S5PV210_MP21(_nr) (S5PV210_GPIO_MP21_START + (_nr))
#define S5PV210_MP22(_nr) (S5PV210_GPIO_MP22_START + (_nr))
#define S5PV210_MP23(_nr) (S5PV210_GPIO_MP23_START + (_nr))
#define S5PV210_MP24(_nr) (S5PV210_GPIO_MP24_START + (_nr))
#define S5PV210_MP25(_nr) (S5PV210_GPIO_MP25_START + (_nr))
#define S5PV210_MP26(_nr) (S5PV210_GPIO_MP26_START + (_nr))
#define S5PV210_MP27(_nr) (S5PV210_GPIO_MP27_START + (_nr))
#define S5PV210_MP28(_nr) (S5PV210_GPIO_MP28_START + (_nr))
#define S5PV210_ETC0(_nr) (S5PV210_GPIO_ETC0_START + (_nr))
#define S5PV210_ETC1(_nr) (S5PV210_GPIO_ETC1_START + (_nr))
#define S5PV210_ETC2(_nr) (S5PV210_GPIO_ETC2_START + (_nr))
#define S5PV210_ETC4(_nr) (S5PV210_GPIO_ETC4_START + (_nr))


==========================================================================
四、LED的GPIO号
D1 ---> GPJ2_0 --->S5PV210_GPJ2(0)
D2 ---> GPJ2_1 --->S5PV210_GPJ2(1)
D3 ---> GPJ2_2 --->S5PV210_GPJ2(2)
D4 ---> GPJ2_3 --->S5PV210_GPJ2(3)


BEEP ---> GPD0_0 --->S5PV210_GPD0(0)

相关主题