一、目的
- 在上一篇文章的驱动框架之下,写led和按键的驱动:
- 课程基于:韦东山教程,uboot-第五课字符设备-(1-4)
一、看图:
1.1、原理图中的灯:
1.2、寄存器配置:
三、大致流程:
- 在init中,配置GPFCON
- 在wrtie中,配置GPFDAT
3.1、创建寄存器变量:
volatile unsigned long *gpfcon = NULL;
volatile unsigned long *gpfdat = NULL;
3.2、映射和去除映射寄存器变量:
gpfcon = (volatile unsigned long *)ioremap(0x56000050,16);
gpfdat = gpfcon + 1;
ioumap(gpfcon);
3.3、在open和write函数中编写函数:
static int first_drv_open(struct inode *inode,struct file *file)
{
*gpfcon &= ~((0x3<<(4*2)) | (0x3<<(5*2)) | (0x3<<(6*2)));
*gpfcon |= ((0x1<<(4*2))|(0x1<<(5*2))|(0x1<<(6*2)));
return 0;
}
static ssize_t first_drv_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)
{
*gpfdat &= ~((1<<4)|(1<<5)|(1<<6));
}
else
{
*gpfdat |=(1<<4)|(1<<5)|(1<<6);
}
return 0;
}
3.4、编写测试函数: