ARM驱动学习之22 字符类GPIO
1.将“21_字符驱动”中的文件“char_driver.c”改为“CharDriverLeds.c”
Makefile也做修改
2.头文件
#include "CharDriverLeds.h"#include <linux/gpio.h>
#include <plat/gpio-cfg.h>
#include <mach/gpio-exynos4.h>3.c文件中定义结构体数组
static int led_gpios[] = {EXYNOS4_GPL2(0),EXYNOS4_GPK1(1),
};#define LED_NUM ARRAY_SIZE(led_gpios)4.chardevnode_ioctl操作:
switch(cmd)
{case 0:case 1:if (arg > LED_NUM){return -EINVAL;}gpio_set_value(led_gpios[arg],cmd);break;default:return -EINVAL;}5.GPIO_INIT:
static int gpio_init(void)
{int i = 0,ret = 0;for(i = 0;i < LED_NUM;i ++){ret = gpio_request(led_gpios[i],"LED");if(ret){printf("%s,GPIO failed");}else{s3c_gpio_cfgpin(led_gpios[i],S3C_GPIO_OUTPUT);gpio_set_value(led_gpios[i],1);}}return 0;}6.释放GPIO
for(i = 0;i < LED_NUM;i ++)
{gpio_free(led_gpios[i]);
}
7.应用文件invoke_char_gpios.c修改传参改变led状态
ioctl(fd,atoi(argv[1]),atoi(argv[2]));