linux driver ------ GPIO的驱动编写和调用
判断哪些文件被编译进内核:
1、通过 make menuconfig 查看
2、比如查看gpio类型的文件,输入 ls drivers/gpio/*.o,有生成.o文件表示被编译进内核
在编写驱动程序之前要保证该GPIO口没有被其他程序占用,若被占用则需要取消编译那个驱动程序。
/arch/arm/mach-exynos/include/mach/gpio-exynos4.h
/drivers/gpio/gpio-exynos4.c
#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_ctl" MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("TOPEET"); static long hello_ioctl( struct file *files, unsigned int cmd, unsigned long arg){
printk("cmd is %d,arg is %d\n",cmd,arg); if(cmd > ){
printk(KERN_EMERG "cmd is 0 or 1\n");
}
if(arg > ){
printk(KERN_EMERG "arg is only 1\n");
} gpio_set_value(EXYNOS4_GPL2(),cmd); return ;
} static int hello_release(struct inode *inode, struct file *file){
printk(KERN_EMERG "hello release\n");
return ;
} static int hello_open(struct inode *inode, struct file *file){
printk(KERN_EMERG "hello open\n");
return ;
} 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; printk(KERN_EMERG "\tinitialized\n"); ret = gpio_request(EXYNOS4_GPL2(),"LEDS");
if(ret < ){
printk(KERN_EMERG "gpio_request EXYNOS4_GPL2(0) failed!\n");
return ret;
} s3c_gpio_cfgpin(EXYNOS4_GPL2(),S3C_GPIO_OUTPUT); gpio_set_value(EXYNOS4_GPL2(),); misc_register(&hello_dev); return ;
} static int hello_remove(struct platform_device *pdv){ printk(KERN_EMERG "\tremove\n");
misc_deregister(&hello_dev);
return ;
} static void hello_shutdown(struct platform_device *pdv){ ;
} static int hello_suspend(struct platform_device *pdv,pm_message_t pmt){ return ;
} static int hello_resume(struct platform_device *pdv){ return ;
} 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(KERN_EMERG "HELLO WORLD enter!\n");
DriverState = platform_driver_register(&hello_driver); printk(KERN_EMERG "\tDriverState is %d\n",DriverState);
return ;
} static void hello_exit(void)
{
printk(KERN_EMERG "HELLO WORLD exit!\n"); platform_driver_unregister(&hello_driver);
} module_init(hello_init);
module_exit(hello_exit);
linux driver ------ GPIO的驱动编写和调用的更多相关文章
- linux driver ------ 字符设备驱动 之 “ 创建设备节点流程 ”
在字符设备驱动开发的入门教程中,最常见的就是用device_create()函数来创建设备节点了,但是在之后阅读内核源码的过程中却很少见device_create()的踪影了,取而代之的是device ...
- linux driver error ------ 编译驱动出现 ERROR: Kernel configuration is invalid
ERROR: Kernel configuration is invalid. include/generated/autoconf.h or include/config/au ...
- 树莓派GPIO口驱动编写
一.wiringpi写法 #include <wiringPi.h> #include <stdlib.h> int main(int argc,char *argv[]) { ...
- 如何编写linux下nand flash驱动-4
2. 软件方面 如果想要在Linux下编写Nand Flash驱动,那么就先要搞清楚Linux下,关于此部分的整个框架.弄明白,系统是如何管理你的nand flash的,以及,系统都帮你做 ...
- nand flash详解及驱动编写
https://www.crifan.com/files/doc/docbook/linux_nand_driver/release/html/linux_nand_driver.html#nand_ ...
- Linux驱动:I2C驱动编写要点
继续上一篇博文没讲完的内容“针对 RepStart 型i2c设备的驱动模型”,其中涉及的内容有:i2c_client 的注册.i2c_driver 的注册.驱动程序的编写. 一.i2c 设备的注册分析 ...
- ARM Linux驱动篇 学习温度传感器ds18b20的驱动编写过程
ARM Linux驱动篇 学习温度传感器ds18b20的驱动编写过程 原文地址:http://www.cnblogs.com/NickQ/p/9026545.html 一.开发板与ds18b20的入门 ...
- Linux GPIO键盘驱动开发记录_OMAPL138
Linux GPIO键盘驱动开发记录_OMAPL138 Linux基本配置完毕了,这几天开始着手Linux驱动的开发,从一个最简单的键盘驱动开始,逐步的了解开发驱动的过程有哪些.看了一下Linux3. ...
- 调试exynos4412—ARM嵌入式Linux—LEDS/GPIO驱动之二
/** ****************************************************************************** * @author 暴走的小 ...
随机推荐
- 利用random模块生成验证码
random模块 该模块用于数学或者数据相关的领域,使用方法非常简单下面介绍常用的放法 1.随机小数 random.random() 2.随机整数random.randint(1,5) # 大于等于1 ...
- BZOJ3291Alice与能源计划——匈牙利算法+模拟费用流
题目描述 在梦境中,Alice来到了火星.不知为何,转眼间Alice被任命为火星能源部长,并立刻面临着一个严峻的考验.为 了方便,我们可以将火星抽象成平面,并建立平面直角坐标系.火星上一共有N个居民点 ...
- Android Dialog 简单封装
转载:https://www.cnblogs.com/zjjne/archive/2013/10/03/3350382.html public class MyAlertDialog { //regi ...
- Python中的urllib2模块解析
Name urllib2 - An extensible library for opening URLs using a variety of protocols 1. Description Th ...
- BZOJ2809 dispatching 【可并堆】
题目分析: yy一下就知道了,合并用可并堆少个log. 代码: #include<bits/stdc++.h> using namespace std; ; int n,m; int b[ ...
- Codeforces Global Round 2 D. Frets On Fire (动态开点线段树,沙雕写法)
题目链接:D. Frets On Fire 思路:明明可以离散化+二分写,思路硬是歪到了线段树上,自闭了,真实弟弟,怪不得其他人过得那么快 只和查询的区间长度有关系,排完序如果相邻的两个点的差值小于等 ...
- codeforces 600E . Lomsat gelral (线段树合并)
You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's cal ...
- HDOJ5540 Secrete Master Plan
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5540 题目大意:给一个两个2*2的矩阵,第二个矩阵能不能通过旋转得到第一个矩阵 题目思路:模拟 #in ...
- 【LOJ#6073】距离(主席树)
[LOJ#6073]距离(主席树) 题面 LOJ 题解 两点间的距离是\(dep[x]+dep[y]-2dep[LCA]\). 那么题目要求的东西拆开维护,唯一不好做的就是\(2dep[LCA]\). ...
- 平衡树splay学习笔记#2
讲一下另外的所有操作(指的是普通平衡树中的其他操作) 前一篇的学习笔记连接:[传送门],结尾会带上完整的代码. 操作1,pushup操作 之前学习过线段树,都知道子节点的信息需要更新到父亲节点上. 因 ...