GPIO驱动实例:操作LED开关
应用程序调用ioctl():
[code]
#include
#include
#include
#include
int main(int argc, char **argv)
{
int on;
int led_no;
int fd;
if (argc != 3 || sscanf(argv[1], "%d", led_no) != 1 || sscanf(argv[2],"%d", on) != 1 ||
on < 0 || on > 1 || led_no < 0 || led_no > 3) {
fprintf(stderr, "Usage: leds led_no 0|1\n");
exit(1);
}
fd = open("/dev/led", 0);
if (fd < 0) {
perror("can not open device led");
exit(1);
}
ioctl(fd, on, led_no);
close(fd);
return 0;
}
[/code]
GPIO驱动部分:
[code]
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME"led"
#define LED_MAJOR 233
MODULE_AUTHOR("Luofuchong");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_ALIAS("led");
static unsigned long led_table [] = {
S3C2410_GPB7,
S3C2410_GPB8,
S3C2410_GPB9,
S3C2410_GPB10,
S3C2410_GPB7_OUTP,
S3C2410_GPB8_OUTP,
S3C2410_GPB9_OUTP,
S3C2410_GPB10_OUTP,
};
static int leds_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
switch(cmd) {
case 0:
case 1:
if (arg > 3) {
return -EINVAL;
}
s3c2410_gpio_setpin(led_table[arg],!cmd);
break;
default:
return -EINVAL;
}
return 0;
}
static struct file_operations leds_fops = {
.owner = THIS_MODULE,
.ioctl = leds_ioctl,
};
static struct class *led_class;
static int __init leds_init(void)
{
int err = 0;
int i;
if(register_chrdev(LED_MAJOR,"led",leds_fops)){
printk("led driver:Unable to register driver\n");
return -ENODEV;
}
led_class = class_create(THIS_MODULE, "led");
if(IS_ERR(led_class)){
err = PTR_ERR(led_class);
goto out_chrdev;
}
class_device_create(led_class,MKDEV(LED_MAJOR, 0),NULL,"led");
err = devfs_mk_cdev(MKDEV(LED_MAJOR,0),
S_IFCHR | S_IRUGO | S_IWUSR,"led");
if(err)
goto out_class;
for(i=0;i<4;i ){
s3c2410_gpio_cfgpin(led_table[i],led_table[i 4]);
s3c2410_gpio_setpin(led_table[i],1);
}
printk("led driver initialized\n");
goto out;
out_class:
class_device_destroy(led_class,MKDEV(LED_MAJOR, 0));
class_destroy(led_class);
out_chrdev:
unregister_chrdev(LED_MAJOR, "led");
out:
return err;
}
static void __exit leds_exit(void)
{
class_device_destroy(led_class,MKDEV(LED_MAJOR,0));
class_destroy(led_class);
unregister_chrdev(LED_MAJOR,"led");
devfs_remove("led");
printk("led driver removed\n");
}
module_init(leds_init);
module_exit(leds_exit);
[/code]
转自:
http://www.hhcn.com/cgi-bin/topic.cgi?forum=3topic=367
《Linux Device Driver》example link:
ftp://ftp.ora.com/pub/examples/
ftp://ftp.ora.com/pub/examples/
转载于:https://blog.51cto.com/hanxuefei432/992119
GPIO驱动实例:操作LED开关相关推荐
- android gpio驱动实例,Android/Linux 驱动层对GPIO口的操作方法和相关代码
实例: unsigned int otg_en_pin=952; ----->高通的gpio的基础值为902,这里我们时间的gpio为50,即这里定义值是要设置为952. //young.yan ...
- SylixOS下 i.MX RT1050的GPIO驱动实例
实例源码 下面是 i.MX RT1050 的GPIO驱动实现源码: /***************************************************************** ...
- android gpio驱动实例,安卓gpio操作示例
GPIO值在RK3288中的计算方法为:bank×32+pin,如: GPIO7A3: 7×32 + 0*8 +3=227 GPIO0B5: 0×32+ 1*8 +5=13 1. 导出 /sys/cl ...
- RK3288开发板PopMetal上的GPIO驱动实例
2019独角兽企业重金招聘Python工程师标准>>> 楼主在这边给大家介绍下如何使用PopMetal的GPIO.先讲过程,再讲原理吧, 该驱动需要涉及到的知识点:1,DTS设备树的 ...
- Proteus仿真STM32F103R6微控制器的GPIO(按键控制LED开关)
Proteus仿真STM32F103R6微控制器的GPIO,检查按键,控制LED灯的反转.. 输入:按键检测:输出:高低电平,控制LED. 一.原理图: 二.源码: #include "st ...
- linux驱动开发(一)—GPIO驱动框架
前言 GPIO驱动是Linux驱动开发中最基础.但却是很常用.很重要的驱动.比如你要点亮一个LED灯.键盘扫描.输出高低电平等等.而Linux内核的强大之处在于对最底层的GPIO硬件操作层的基础上封装 ...
- linux gpio设备驱动程序,嵌入式Linux设备驱动开发之:GPIO驱动程序实例-嵌入式系统-与非网...
11.3 GPIO驱动程序实例 11.3.1 GPIO工作原理 FS2410开发板的S3C2410处理器具有117个多功能通用I/O(GPIO)端口管脚,包括GPIO 8个端口组,分别为GPA(2 ...
- 全志A33驱动开发 之 LED操作
全志A33驱动开发 之 LED操作 一.整体说明 二.注意事项 三.实现led驱动 1.源文件 2.Makefile文件 四.实现测试的应用程序 五.原理图 一.整体说明 本次使用的开发板是锐尔威 ...
- gpio驱动广播Android,[RK3288][Android6.0] 调试笔记 --- 通用GPIO驱动控制LED【转】
Platform: ROCKCHIP OS: Android 6.0 Kernel: 3.10.92 由于板子没有lcd无法得知sd卡升级是否完成,因此使用LED显示. Recovery中升级完成后控 ...
- 字符设备驱动基础篇5——驱动如何操控硬件(动静态映射操作LED)
以下内容源于朱有鹏嵌入式课程的学习,,如有侵权,请告知删除. 参考资料:http://www.cnblogs.com/biaohc/p/6575074.html 这里的映射,是指物理地址和虚拟地址的对 ...
最新文章
- 如何在机器学习的框架里实现隐私保护?
- NR 5G 关于gNB-CU和gNB-DU
- POJ1573-Robot Motion
- POJ3608(旋转卡壳--求两凸包的最近点对距离)
- angular6继承类注意几点:
- 批量改名_手把手教你用Python批量给图片添加水印 | 知了干货分享
- 07.30《jQuery》——1.1DOM对和jQuery对象的转化
- 基于 HTML5 WebGL 的 3D 工控裙房系统
- 前端设计必备-Font awesome 插件使用菜鸟言语
- 采用dlopen、dlsym、dlclose加载动态链接库
- 用python模拟clark变换和park变换
- 第1138期AI100_机器学习日报(2017-10-30)
- K8S的pod探针(livenessProbe,readinessProbe),kubelet对pod的状态检查(kubelet-exec,httpGet,tcpSocket)
- 原生JS实现中文简繁切换
- 请仔细核对自己的信息
- [转]经验之谈:成为Debian Maintainer前要做的事
- C# 使用Redis实现粉丝好友互粉数据存储和查询
- 如何利用Slack客户端漏洞窃取Slack用户下载的所有文件
- gaussdb200 理论
- flash的读写擦除
热门文章
- Ubuntu使用技巧集锦(持续追加中……)
- Clash of Clans通关秘诀
- read -p 命令--shell 脚本
- win10下JDK安装,配置环境变量后出现error:could not open '...jvm.cfg'
- (转载)web.xml中 IntrospectorCleanupListener的作用
- Java web切面编程
- poj-3176 Cow Bowling poj-1163 The Triangle hihocoder #1037 : 数字三角形 (基础dp)
- 韩国被申遗 (转自果壳)
- 关于字节对齐(关于align)
- CA SDK 使用简介