GPIOS驱动

小编 2026-06-18 阅读:1436 评论:0
    1、去掉占用GPIO的驱动 去掉占用调用的GPIO驱动,包括leds,buzzer,camera ov5640,WIFI   mt6620   VIDEO_OV5640   – D...

 

 

1、去掉占用GPIO的驱动

去掉占用调用的GPIO驱动,包括leds,buzzer,camera ov5640,WIFI

 

mt6620

 

VIDEO_OV5640

 

– Device Drivers

– Multimedia support(MEDIA_SUPPORT [=y])

– Video capture adapters(VIDEO_CAPTURE_DRIVERS [=y])(去掉)

 

\"\"

 

MTK_COMBO_CHIP_MT6620

 

– Device Drivers

– MediaTek Connectivity Combo Chip Config

– MediaTek Connectivity Combo Chip Support (MTK_COMBO [=y])(去掉)

– Select Chip (<choice> [=y])

 

\"\"

 

Enable LEDS config

 

--Device Drivers

--Character devices

--Enable LEDS config

 

 

Enable BUZZER config

--Device Drivers

--Character devices

--Enable BUZZER config

 

 

\"\"

 

/*led的两个IO,网络是KP_COL0,VDD50_EN*/

 

KP_COL0                             GPL2_0

VDD50_EN                          GPK1_1

 

GPL2CON 0x11000100

GPL2DAT 0x11000104

GPK1CON 0x1100060

GPK1DAT 0x11000064

 

/*蜂鸣器的1个IO,网络是MOTOR_PWM*/

 

MOTOR_PWM                GPD0_0

 

/*矩阵键盘的8个IO,网络是CHG_FLT,HOOK_DET,CHG_UOK,XEINT14_BAK,

GM_INT1,6260_GPIO1,CHG_COK,XEINT29/KP_ROW13/ALV_DBG25*/

 

CHG_FLT                                                       GPX1_0

HOOK_DET                                                   GPX1_3

CHG_UOK                                                     GPX1_5

XEINT14_BAK                                              GPX1_6

GM_INT1                                                      GPX3_0

6260_GPIO1                                                GPX2_6

CHG_COK                                                   GPX2_7

XEINT29/KP_ROW13/ALV_DBG25             GPX3_5

 

/*摄像头的14个IO,网络是CAM_MCLK,CAM2M_RST,CAM2M_PWDN,

CAM_D5,CAM_D7,CAM_D6,CAM_D4,CAM_D3,CAM_D2,CAM_D1,

CAM_PCLK,CAM_D0,CAM_VSYNC,CAM_HREF。

I2C_SDA7,I2C_SCL7也是可以设置为GPIO,不过总线一般不要去动它*/

 

CAM_MCLK                                             GPJ1_3

CAM2M_RST                                           GPL0_1

CAM2M_PWDN                                       GPL0_3

CAM_D5                                                  GPJ1_0

CAM_D7                                                 GPJ1_2

CAM_D6                                                 GPJ1_1

CAM_D4                                                 GPJ0_7

CAM_D3                                                 GPJ0_6

CAM_D2                                                 GPJ0_5

CAM_D1                                                  GPJ0_4

CAM_PCLK                                             GPJ0_0

CAM_D0                                                   GPJ0_3

CAM_VSYNC                                           GPJ0_1

CAM_HREF                                             GPJ0_2

 

 

/*WIFI模块的7个IO,WIFI_D3,WIFI_CMD,WIFI_D1,WIFI_CLK,WIFI_D0,WIFI_D2,GPC1_1*/

/*串口RX和TX等也是可以设置为GPIO,一般不要动它*/

 

WIFI_D3                                                          GPK3_6

WIFI_CMD                                                       GPK3_1

WIFI_D1                                                           GPK3_4

WIFI_CLK                                                         GPK3_0

WIFI_D0                                                           GPK3_3

WIFI_D2                                                           GPK3_5

GPC1_1                                                             GPC1_1

数组中有32个引出到端子或者模块的IO,还有类似sd卡等也是可以作为GPIO,其它引到连接器但是没有使用的GPIO等等

 

测试源码:

#include <linux/init.h>
#include <linux/module.h>

/*驱动注册的头文件,包含驱动的结构体和注册和卸载的函数*/
#include <linux/platform_device.h>
/*注册杂项设备头文件*/
#include <linux/miscdevice.h>
/*注册设备节点的文件结构体*/
#include <linux/fs.h>

/*Linux中申请GPIO的头文件*/
#include <linux/gpio.h>
/*三星平台的GPIO配置函数头文件*/
/*三星平台EXYNOS系列平台,GPIO配置参数宏定义头文件*/
#include <plat/gpio-cfg.h>
#include <mach/gpio.h>
/*三星平台4412平台,GPIO宏定义头文件*/
#include <mach/gpio-exynos4.h>

#define DRIVER_NAME \"hello_ctl\"
#define DEVICE_NAME \"hello_gpio\"


MODULE_LICENSE(\"Dual BSD/GPL\");
MODULE_AUTHOR(\"SKYFALL\");




/*led的两个IO,网络是KP_COL0,VDD50_EN*/
/*蜂鸣器的1个IO,网络是MOTOR_PWM*/

/*矩阵键盘的8个IO,网络是CHG_FLT,HOOK_DET,CHG_UOK,XEINT14_BAK,
GM_INT1,6260_GPIO1,CHG_COK,XEINT29/KP_ROW13/ALV_DBG25*/

/*摄像头的14个IO,网络是CAM_MCLK,CAM2M_RST,CAM2M_PWDN,
CAM_D5,CAM_D7,CAM_D6,CAM_D4,CAM_D3,CAM_D2,CAM_D1,
CAM_PCLK,CAM_D0,CAM_VSYNC,CAM_HREF。
I2C_SDA7,I2C_SCL7也是可以设置为GPIO,不过总线一般不要去动它*/

/*WIFI模块的7个IO,WIFI_D3,WIFI_CMD,WIFI_D1,WIFI_CLK,WIFI_D0,WIFI_D2,GPC1_1*/
/*串口RX和TX等也是可以设置为GPIO,一般不要动它*/

/*数组中有32个引出到端子或者模块的IO,还有类似sd卡等也是可以作为GPIO,
其它引到连接器但是没有使用的GPIO等等*/
/*SCP管脚编号和POP的稍微有点不同,下面是SCP的*/
static int led_gpios[] = {
	EXYNOS4_GPL2(0),EXYNOS4_GPK1(1),
	EXYNOS4_GPD0(0),
	
	EXYNOS4_GPX1(0),EXYNOS4_GPX1(3),EXYNOS4_GPX1(5),EXYNOS4_GPX1(6),
	EXYNOS4_GPX3(0),EXYNOS4_GPX2(6),EXYNOS4_GPX2(7),EXYNOS4_GPX3(5),
	
	EXYNOS4212_GPJ1(3),EXYNOS4_GPL0(1),EXYNOS4_GPL0(3),EXYNOS4212_GPJ1(0),
	EXYNOS4212_GPJ1(2),EXYNOS4212_GPJ1(1),EXYNOS4212_GPJ0(7),EXYNOS4212_GPJ0(6),
	EXYNOS4212_GPJ0(5),EXYNOS4212_GPJ0(4),EXYNOS4212_GPJ0(0),EXYNOS4212_GPJ0(3),
	EXYNOS4212_GPJ0(1),EXYNOS4212_GPJ0(2),
	
	EXYNOS4_GPK3(6),EXYNOS4_GPK3(1),EXYNOS4_GPK3(4),EXYNOS4_GPK3(0),
	EXYNOS4_GPK3(3),EXYNOS4_GPK3(5),EXYNOS4_GPC1(1),
};

//#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

#define LED_NUM		ARRAY_SIZE(led_gpios)


static long hello_ioctl( struct file *files, unsigned int cmd, unsigned long arg){
	printk(\"cmd is %d,arg is %d\\n\",cmd,arg);
	
	switch(cmd)
	{
		case 0:
		case 1:
			if (arg > LED_NUM) {
				return -EINVAL;
			}

			gpio_set_value(led_gpios[arg], cmd);
			break;

		default:
			return -EINVAL;
	}
	
	gpio_set_value(led_gpios[2], 0);
	
return 0;
}

static int hello_release(struct inode *inode, struct file *file){

	printk(\"%s,%d\\n\",__func__,__LINE__);
	printk(KERN_EMERG \"hello release\\n\");
	return 0;
}

static int hello_open(struct inode *inode, struct file *file){
	
	printk(\"%s,%d\\n\",__func__,__LINE__);
	printk(KERN_EMERG \"hello open\\n\");
	return 0;
}

static struct file_operations hello_ops = {
	.owner = THIS_MODULE,
	.open = hello_open,
	.release = hello_release,
	.unlocked_ioctl = hello_ioctl,
};

static  struct miscdevice hello_dev = {
	.minor = MISC_DYNAMIC_MINOR,
	.name = DEVICE_NAME,
	.fops = &hello_ops,
};


static int hello_probe(struct platform_device *pdv){
	int ret,i;
	
	printk(KERN_EMERG \"\\tinitialized\\n\");
	
	for(i=0; i<LED_NUM; i++)
	{
		ret = gpio_request(led_gpios[i], \"LED\");
		if (ret) {
			printk(\"%s: request GPIO %d for LED failed, ret = %d\\n\", DRIVER_NAME,
					i, ret);
			}
		else{
			s3c_gpio_cfgpin(led_gpios[i], S3C_GPIO_OUTPUT);
			gpio_set_value(led_gpios[i], 1);			
		}
	}
//单独将蜂鸣器的关掉,为的是不让它开始鸣叫,要不太吵!
	gpio_set_value(led_gpios[2], 0);
	
	printk(\"%s,%d\\n\",__func__,__LINE__);
	misc_register(&hello_dev);
	if(ret<0)
	{
		printk(\"leds:register device failed!\\n\");
		goto exit;
	}
	
exit:
	misc_deregister(&hello_dev);
	return ret;
return 0;
}

static int hello_remove(struct platform_device *pdv){
	int i;
	
	printk(KERN_EMERG \"\\tremove\\n\");
	
	for(i=0; i<LED_NUM; i++)
	{
		gpio_free(led_gpios[i]);
	}
	
	misc_deregister(&hello_dev);
	return 0;
}

static void hello_shutdown(struct platform_device *pdv){
	
	;
}

static int hello_suspend(struct platform_device *pdv,pm_message_t pmt){
	
	return 0;
}

static int hello_resume(struct platform_device *pdv){
	
	return 0;
}

struct platform_driver hello_driver = {
	.probe = hello_probe,
	.remove = hello_remove,
	.shutdown = hello_shutdown,
	.suspend = hello_suspend,
	.resume = hello_resume,
	.driver = {
		.name = DRIVER_NAME,
		.owner = THIS_MODULE,
	}
};


static int hello_init(void)
{
	int DriverState;
	printk(\"%s,%d\\n\",__func__,__LINE__);
	printk(KERN_EMERG \"HELLO WORLD enter!\\n\");
	DriverState = platform_driver_register(&hello_driver);
	
	printk(KERN_EMERG \"\\tDriverState is %d\\n\",DriverState);
	return 0;
}


static void hello_exit(void)
{
	printk(\"%s,%d\\n\",__func__,__LINE__);
	printk(KERN_EMERG \"HELLO WORLD exit!\\n\");
	
	void free_irq(unsigned int irq,void *dev_id);
	
	platform_driver_unregister(&hello_driver);	
}

module_init(hello_init);
module_exit(hello_exit);

 

Makefile文件参考相关博文,生成驱动模块。

 

应用程序测试源码:

 

 

 

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>

#define GPIOS 32


int main(int argc , char *argv[]){
	int fd,i,cmd=2;
	char *hello_node = \"/dev/hello_gpio\";
	char *cmd0 = \"0\"; 
	char *cmd1 = \"1\";
	
	printf(\"argv[0] is %s;argv[1] is %s;\",argv[0],argv[1]);
	
	if(strcmp(argv[1], cmd0) == 0){
		cmd = 0;
		printf(\"cmd is 0!\\n\");
	}
	if(strcmp(argv[1], cmd1) == 0){
		cmd = 1;
		printf(\"cmd is 1!\\n\");
	}
	
/*O_RDWR读写方式,O_NDELAY非阻塞方式*/	
	if((fd = open(hello_node,O_RDWR|O_NDELAY))<0){
		printf(\"APP open %s failed!\\n\",hello_node);
	}
	else{
		printf(\"APP open %s success!\\n\",hello_node);
		
		for(i=0;i<GPIOS;i++){
			ioctl(fd,cmd,i);
			printf(\"APP ioctl %s ,cmd is %d,i is %d!\\n\",hello_node,cmd,i);
		}
	}
	
	close(fd);
return 0;
}

 

2、在开发板上的测试结果:

 

 

 

 

版权声明

本文仅代表作者观点,不代表百度立场。
本文系作者授权百度百家发表,未经许可,不得转载。

热门文章
  • 机房智能化温湿度解决方式之POE供电以太网温湿度传感器

    机房智能化温湿度解决方式之POE供电以太网温湿度传感器
    机房智能化温湿度解决方式之POE供电以太网温湿度传感器 北京盈创力和电子科技有限公司 智能型TCP网口温湿度记录仪 北京IP网络温湿度记录仪厂家,北京盈创力和 北京智能型TCP网口温湿度记录仪IP网络温湿度记录仪是一种新型的基于TCP/IP协议双绞线以太网标准温湿度采集模块,利用它可以实现现场温度值、相对湿度值的采集,同时利用其自身的RJ45通信接口可以方便地和机房监控主机或交换机集线器进行联网。 工作于-40℃~85℃工业级带...
  • Sequential Monte Carlo Methods (SMC) 序列蒙特卡洛/粒子滤波/Bootstrap Filtering

    Sequential Monte Carlo Methods (SMC) 序列蒙特卡洛/粒子滤波/Bootstrap Filtering
    Problem Statement 我们考虑一个具有马尔可夫性质、非线性、非高斯的状态空间模型(State Space Model):对于一个时间序列上的观测结果{yt,t∈N}\\{ y_t , t \\in N \\}{yt​,t∈N},我们认为每个观测结果yty_tyt​的生成依赖于一个无法直接观察的隐变量xt∈{xt,t∈N}x_t \\in \\{x_t , t \\in N \\}xt​∈{xt​,t∈N},即:p(...
  • HTTP状态保持的原理

    HTTP状态保持的原理
    a)在用户登录之后,浏览器返回响应的时候会在响应中添加上cookieb)浏览器接收到cookie之后会自动保存c)当用户再次请求同一服务器中的其他网页的时候,浏览器会自动带上之前保存的cookied)服务接收到请求之后可以请 request 对象中取到cookie 判断当前用户是否登录  Http是无状态的,就是连接时数据互通,关闭后...
  • Hive 系统函数及示例

    Hive 系统函数及示例
    查看所有系统函数 show functions; 函数分类 内置函数【系统函数】 数学函数: floor、round、ceil、cos、log2等 字符串函数: length、reverse、trim、lower、get_json_object、repeat等 收集函数: size 转换函数: cast 日期函数: year、month、datediff、date、date_add等 条件函数: coalesce、case…w...
  • CSRF的原理和防范措施

    CSRF的原理和防范措施
    a)攻击原理:i.用户C访问正常网站A时进行登录,浏览器保存A的cookieii.用户C再访问攻击网站B,网站B上有某个隐藏的链接或者图片标签会自动请求网站A的URL地址,例如表单提交,传指定的参数iii.而攻击网站B在访问网站A的时候,浏览器会自动带上网站A的cookieiv.所以网站A在接收到请求之后可判断当前用户是登录状态,所以...
标签列表