全志A33驱动开发 之 LED操作

本文详细介绍了在全志A33平台上进行LED驱动开发的过程,包括整体说明、注意事项、LED驱动的实现、测试应用程序的编写,以及相关的原理图。在开发中,通过修改GPIO配置和内核设置,利用probe函数注册misc设备,并通过ioctl操作控制LED灯的开关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、整体说明

  本次使用的开发板是锐尔威视RERVISION的vstar2。开发板如下图所示。本例使用平台设备的probe函数来注册一个misc设备。从面在/dev/目录下形成Jay_leds的设备文件。通过ioctl函数操作。打开关闭LED灯。

在这里插入图片描述

二、注意事项

1、GPIO 在fex文件中的配置说明:

  GPIO配置脚本的使用:
  Port:端口+组内序号<功能分配><内部电阻状态><驱动能力><输出电平状态>

2、sys_config.fex中的配置:
  ;----------------------------------------------------------------------------------
  ;leds config parameters
  ;leds_used 0:uboot charging, 1:android charging
  ;----------------------------------------------------------------------------------
  [leds_para]
  leds_used = 0
  red_led = port:PB02<1><0>

3、获取sys_config.fex中的配置:(详细的看驱动文件)
  type = script_get_item(“leds_para”, “red_led”, &led_val);

4、内核配置:
  因为a33提供的开发包是用脚本编译的,buildroot自带生成编译工具。在linux kernel也没有明确  的指定编译工具跟架构。
  这里要设置如下两项配置:(去掉原来的配置)
  #ARCH ?= $(SUBARCH)
  #CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
  ARCH ?= arm
  CROSS_COMPILE ?=   /home/mydocuments/linux_kernel/a33/dragonboard/out/sun8iw5p1/dragonboard/common/buildroot/external-toolchain/bin/arm-linux-gnueabi-

5、编译测试程序:
  /home/mydocument/arm-gcc/arm-2009q3/bin/arm-none-linux-gnueabi-gcc led.c -o leds_test

三、实现led驱动

1、源文件

/**************************************************START OF FILE*****************************************************/




/*  ------------------------------------------------------------------------------------------------------------------
包含头文件
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <mach/gpio.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <asm/io.h>
#include <linux/regulator/consumer.h>
#include <linux/delay.h>
#include <mach/hardware.h>
#include <mach/platform.h>
#include <mach/sys_config.h>
#include <linux/gpio.h>




/*  ------------------------------------------------------------------------------------------------------------------
宏定义
*/

//配置是否开启打印信息
#define DEBUG	1
#ifdef	DEBUG
#define	dprintk( argc, argv... )		printk( argc, ##argv )
#else
#define	dprintk( argc, argv... )		
#endif



//platform device相关函数
static int leds_probe(struct platform_device *pdev);
static int leds_remove (struct platform_device *pdev);
static int leds_suspend (struct platform_device *pdev, pm_message_t state);
static int leds_resume (struct platform_device *pdev);



//misc driver 相关函数
int leds_release(struct inode *inode,struct file *filp);
int leds_open(struct inode *inode,struct file *filp);
long leds_ioctl(struct file *filp,unsigned int cmd,unsigned long arg);




/*  ------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值