驱动开发day8

任务 : 基于GPIO子系统编写LED驱动,编写应用程序进行测试设置定时器,LED每秒翻转引脚状态,并且每五秒打印一次hello world

驱动代码

cs 复制代码
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/gpio.h>

struct device_node *dnode;
struct gpio_desc *ionum;

struct timer_list mtimer;
struct timer_list timer_5;

void my_timer_fun(struct timer_list *timer)
{
    gpiod_set_value(ionum,!gpiod_get_value(ionum));
	printk("__led_timer__\n");
    mod_timer(timer,jiffies + HZ);
}

void timer_5_fun(struct timer_list *timer)
{
	printk("hello world\n");
	mod_timer(timer,jiffies + 5 * HZ);
}


static int __init my_init(void)
{
    dnode = of_find_node_by_path("/myled");
    if(dnode == NULL)
    {
        printk("of_find_node_by_path failed\n");
        return -1;
    }
    printk("of_find_node_by_path success\n");

	ionum = gpiod_get_from_of_node(dnode,"led1-gpioe",0,GPIOD_OUT_LOW,NULL);
	if(IS_ERR(ionum))
	{
		printk("gpiod_get_from_of_node failed\n");
		return -PTR_ERR(ionum);
	}
	printk("gpiod_get_from_of_node success\n");

    timer_setup(&mtimer,my_timer_fun,0);
	timer_setup(&timer_5,timer_5_fun,0);

    mtimer.expires = jiffies + HZ;
	timer_5.expires = jiffies + 5 * HZ;

    add_timer(&mtimer);
	add_timer(&timer_5);

    

	//gpiod_set_value(ionum,1);

    return 0;
}

static void __exit my_exit(void)
{
    gpiod_set_value(ionum,0);
    gpiod_put(ionum);
    del_timer(&mtimer);
	del_timer(&timer_5);
}

module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");

现象 :

相关推荐
weiyvyy8 小时前
从开发视角看硬件接口:接口开发的本质与全景图
驱动开发·单片机·嵌入式硬件·硬件工程
Dylan~~~18 小时前
AI编程新范式:规范驱动开发SpecKit框架完全指南
驱动开发·ai编程
阿拉斯攀登18 小时前
【RK3576 安卓 JNI/NDK 系列 04】JNI 核心语法(下):字符串、数组与对象操作
android·驱动开发·rk3568·瑞芯微·rk安卓驱动·jni字符串操作
weiyvyy19 小时前
接口开发的完整流程:从需求到验证
驱动开发·嵌入式硬件·硬件架构·硬件工程
zly886537221 小时前
windsurf rules与skill的使用
linux·c语言·开发语言·驱动开发
阿拉斯攀登2 天前
【RK3576 安卓 JNI/NDK 系列 09】RK3576 实战(三):JNI 调用 librga 实现 2D 硬件加速图像处理
android·驱动开发·rk3568·瑞芯微·rk安卓驱动·rk3576 rga加速
阿拉斯攀登2 天前
第 19 篇 驱动性能优化与功耗优化实战
android·驱动开发·瑞芯微·嵌入式驱动·安卓驱动
道一云黑板报3 天前
技术拆解:AI低代码架构设计与全链路落地实现
人工智能·驱动开发·低代码·ai·企业微信·ai编程·代码规范
LXY_BUAA3 天前
《嵌入式操作系统》_高级字符设备驱动_20260316
linux·运维·服务器·驱动开发
春日见3 天前
Matlab快速入门 基础语法教学
java·开发语言·驱动开发·matlab·docker·计算机外设