linux驱动:[1]LED驱动/dev/led

本文介绍Linux下LED驱动的实现,以Xunlong Orange Pi Zero为测试平台,通过分析代码展示了如何使用ioremap将物理地址映射为虚拟地址,以及驱动程序的框架构建和硬件操作。
摘要由CSDN通过智能技术生成

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 |= (1 << 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值