驱动开发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");

现象 :

相关推荐
是翎13 小时前
图解大语言模型部署
人工智能·驱动开发·深度学习·开源协议·imagen
智购科技无人售货机工厂14 小时前
2026自动售货机AI智能体架构:从47个小模型到33.7亿Token的工程实践~YH
android·人工智能·驱动开发·单片机·pandas
普普通通的一名码农18 小时前
DAC1220 芯片手册
驱动开发·芯片手册
secondyoung2 天前
I2C通信协议详解
arm开发·驱动开发·stm32·单片机·嵌入式硬件·mcu·51单片机
不怕犯错,就怕不做3 天前
RK linux在buildroot中如何添加linux命令
linux·驱动开发·嵌入式硬件
喵叔哟3 天前
从 Prompt 到可执行规格:认识 GitHub Spec Kit
驱动开发·prompt·github
飞多学堂3 天前
每日开源硬件精选简报 2026-09-11
驱动开发·开源·开源硬件·硬件开源·电子制作
码农客栈3 天前
Linux I2C驱动实验
linux·运维·驱动开发
智者知已应修善业4 天前
【如何将此图变为000到101就返回】2026-4-7
驱动开发·经验分享·笔记·硬件架构·硬件工程
国产化创客5 天前
创客开发入门(七)Arduino ESP32-WS2812开发
驱动开发·单片机·物联网·智能硬件