博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
驱动Led SBC8600
阅读量:6307 次
发布时间:2019-06-22

本文共 3238 字,大约阅读时间需要 10 分钟。

hot3.png

效果是隔一段时间反转led。

led驱动:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))#define AM335X_led_0 GPIO_TO_PIN(1, 30)#define AM335X_led_1 GPIO_TO_PIN(1, 31)// #define TEST_IO_NUM(117) #define NAME_MISC"GpioTest"#define NAME_MOUDULE"GpioTest1"#define USE_MISC_MODEstatic int major = 251; void GpioTest(void); static long GpioIOctl(struct file *filp, unsigned cmd, unsigned long arg) { GpioTest(); return 1; } void GpioTest(void) { int iCount = 0; for(iCount = 0; iCount <=20; iCount++ ) { if(iCount%2 == 0) { // gpio_direction_output(TEST_IO_NUM, 1); gpio_direction_output(AM335X_led_0, 1);printk(KERN_INFO"#######AM335X_led_0 statu is high.\r\n"); } else { gpio_direction_output(AM335X_led_0, 0); printk(KERN_INFO"#######AM335X_led_0 statu is low.\r\n"); } mdelay(3000); } printk(KERN_INFO"#######App run over!"); } static int GpioOpen(struct inode *inode, struct file *file) { int iRen = -1; iRen = gpio_request(AM335X_led_0, "AM335X_led_0"); if(iRen < 0) { printk(KERN_INFO"#######Failed to request the AM335X_led_0!"); }else { printk(KERN_INFO"#######Success to request the AM335X_led_0"); } return iRen; } static int GpioClose(struct inode *inode, struct file *file) { printk(KERN_INFO"#######Free the AM335X_led_0"); gpio_free(AM335X_led_0); return 1; } //****entry point for TEST GPIO module static const struct file_operations gpio_test_driver = { .owner = THIS_MODULE, .unlocked_ioctl= GpioIOctl, .llseek = no_llseek, .open = GpioOpen, .release = GpioClose, }; #ifdef USE_MISC_MODE static struct miscdevice gpiotest_misc_device = { .minor = MISC_DYNAMIC_MINOR, .name = NAME_MISC, .fops = &gpio_test_driver, }; #endif static int __init GpioTestInit(void) { int iRet; printk(KERN_INFO"#######GpioTest modules is install!\r\n"); #ifdef USE_MISC_MODE iRet = misc_register(&gpiotest_misc_device); if (iRet) { printk(KERN_INFO"#######unable to register a misc device\r\n"); return iRet; } #else iRet = register_chrdev(major, NAME_MOUDULE, &gpio_test_driver); if (iRet < 0) { printk(KERN_INFO"#######unable to register a chr device\r\n"); return iRet; } #endif return iRet; } static void __exit GpioTestExit(void) { #ifdef USE_MISC_MODE misc_deregister(&gpiotest_misc_device); #else unregister_chrdev(major, NAME_MOUDULE); #endif printk(KERN_INFO"#######GpioTest modules is exit!\r\n"); } module_init(GpioTestInit); module_exit(GpioTestExit); MODULE_AUTHOR("linjie");MODULE_DESCRIPTION("description~~");MODULE_ALIAS("word count moduel");MODULE_LICENSE("GPL");
  • 编译驱动 make -C ******* M=*******
  • 安装驱动 insmod ****
  • lsmod
  • ls /dev/

测试

#include 
#include
#include
#include
#include
#include
#include
int main() { int fd; printf("***running\r\n"); fd = open("/dev/GpioTest", O_RDWR); if(fd < 0) { printf("***Can't open the gpiotest!\r\n"); return -1; } ioctl(fd, 0, 0); close(fd); printf("***App run over!\r\n"); return 1; }

编译 native C arm-nono-linux-gcc -static -o testApp testLed.c

转载于:https://my.oschina.net/u/3136970/blog/886818

你可能感兴趣的文章
MySql之基于ssl安全连接的主从复制
查看>>
informix的逻辑日志和物理日志分析
查看>>
VMware.Workstation Linux与windows实现文件夹共享
查看>>
ARM inlinehook小结
查看>>
wordpress admin https + nginx反向代理配置
查看>>
管理/var/spool/clientmqueue/下的大文件
查看>>
HTML学习笔记1—HTML基础
查看>>
mysql dba系统学习(20)mysql存储引擎MyISAM
查看>>
centos 5.5 64 php imagick 模块错误处理记录
查看>>
apache中文url日志分析--php十六进制字符串转换
查看>>
Ansible--playbook介绍
查看>>
浅谈代理
查看>>
php创建桌面快捷方式实现方法
查看>>
基于jquery实现的超酷动画源码
查看>>
fl包下的TransitionManager的使用
查看>>
Factorialize a Number
查看>>
[USB-Blaster] Error (209040): Can't access JTAG chain
查看>>
TreeSet的用法
查看>>
防HTTP慢速攻击的nginx安全配置
查看>>
深入理解PHP内核(十四)类的成员变量及方法
查看>>