linux驱动:[1]LED驱动/dev/led
LED Linux驱动程序
测试平台: Xunlong Orange Pi Zero
代码一览(解析见下方)
驱动程序以及Makefile如下:
- sun8i_opizero_led.c:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <asm/uaccess.h>
#include <asm/io.h>
static struct class *sun8i_opizero_led_class;
//STATUS-LED:PA17
#define PIO_BASE 0x1C20800
volatile unsigned long *pacfg[4] = {NULL};
volatile unsigned long *padat = NULL;
static int sun8i_opizero_led_open(struct inode *inode, struct file *file)
{
//configure pa17 to output mode
*pacfg[2] &= ~(3 << 5);
return 0;
}
static ssize_t sun8i_opizero_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
int val;
copy_from_user(&val, buf, count);
if (val == 1)
*padat |= (

本文介绍Linux下LED驱动的实现,以Xunlong Orange Pi Zero为测试平台,通过分析代码展示了如何使用ioremap将物理地址映射为虚拟地址,以及驱动程序的框架构建和硬件操作。
最低0.47元/天 解锁文章
2023

被折叠的 条评论
为什么被折叠?



