完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
|
相关推荐
1个回答
|
|
一、硬件信息配置
#include #include #include /*定义结构体对象,用于保存LED灯硬件信息 phy_addr :用于保存寄存器的物理地址 gpio :用于保存LED灯所在的GPIO编号 */ struct led_phy_struct { unsigned long phy_addr; int gpio; }; struct led_phy_struct led_phy_obj[] ={ { .phy_addr = 0XC001B000, .gpio = 26 }, { .phy_addr = 0XC001C000, .gpio = 11 }, { .phy_addr = 0XC001C000, .gpio = 7 }, { .phy_addr = 0XC001C000, .gpio = 12 }, { .phy_addr = 0,//做为数组结束标志 .gpio = 0 } }; void dd_close(struct device *dev){};//用于消除警告 struct platform_device pd_myled_struct = { .name = "LED_", .id = 1, .dev = { .platform_data = led_phy_obj, .release = dd_close } }; static int myled_init(void){ platform_device_register(&pd_myled_struct); return 0; } static void myled_exit(void){ platform_device_unregister(&pd_myled_struct); } module_init(myled_init); module_exit(myled_exit); MODULE_LICENSE("GPL"); 二 、软件驱动代码: #include #include #include #include /* 定义和硬件信息匹配的结构体对象,用于获取硬件信息 */ struct led_phy_struct { unsigned long phy_addr ; int gpio; }; struct led_phy_struct *led_phy_obj; int myled_probe(struct platform_device * pd){ int i = 0; void * void_addr; unsigned long *base,*outenb,*altfn; led_phy_obj = (struct led_phy_struct *)pd->dev.platform_data; while(led_phy_obj.phy_addr != 0){//当phy_addr == 0时,为硬件信息结构体结束标志 void_addr = ioremap(led_phy_obj.phy_addr,0x24); base = (unsigned long *)void_addr; outenb = (unsigned long *)(void_addr+0x4); altfn = (unsigned long *)(void_addr + 0x20); *base &= ~(0x1 << led_phy_obj.gpio); *outenb |= (0x1 << led_phy_obj.gpio); if(led_phy_obj.gpio < 15){ altfn = (unsigned long *)(void_addr + 0x20); *altfn &= ~(0x3 << (led_phy_obj.gpio * 2)); *altfn |= (0x1 << (led_phy_obj.gpio * 2)); } else { altfn = (unsigned long *)(void_addr + 0x24); *altfn &= ~(0x3 << ((led_phy_obj.gpio- 16) * 2)); *altfn |= (0x1 << ((led_phy_obj.gpio- 16) * 2)); } iounmap(void_addr); i ++ ; } return 0; } static int myled_remove(struct platform_device *pd){ int i = 0; void * void_addr; unsigned long *base; led_phy_obj = (struct led_phy_struct *)pd->dev.platform_data; while(led_phy_obj.phy_addr != 0){ void_addr = ioremap(led_phy_obj.phy_addr,0x24); base = (unsigned long *)void_addr; *base |= (0x1 << led_phy_obj.gpio); iounmap(void_addr); i ++; } return 0; } struct platform_driver pd_myled_struct = { .probe = myled_probe, .remove = myled_remove, .driver = { .name = "LED_" } }; static int myled_drv_init(void){ platform_driver_register(&pd_myled_struct); return 0; } static void myled_drv_exit(void){ platform_driver_unregister(&pd_myled_struct); } module_init(myled_drv_init); module_exit(myled_drv_exit); MODULE_LICENSE("GPL"); |
|
|
|
只有小组成员才能发言,加入小组>>
771 浏览 0 评论
1146 浏览 1 评论
2527 浏览 5 评论
2858 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2709 浏览 6 评论
keil5中manage run-time environment怎么是灰色,不可以操作吗?
1054浏览 3评论
189浏览 2评论
453浏览 2评论
364浏览 2评论
M0518 PWM的电压输出只有2V左右,没有3.3V是怎么回事?
449浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-18 12:25 , Processed in 1.419208 second(s), Total 50, Slave 41 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号