android11使用gpio口控制led状态灯
目录
一、简介
二、解决方法
A、底层驱动
B、上层调用
C、验证
一、简介
1、需求:这里是用2个gpio口来控制LED灯,开机时默认亮蓝灯,按开机键,休眠亮红灯,唤醒亮蓝灯。
原理图:
这里由于主板上电阻R635未贴,所以led_sleep不启用。
2、分析:
a.一开始是想将这2个gpio口的控制写在背光pwm驱动中,但是该设备是不接屏幕(mipi/edp/lvds)的,直接由cpu输出信号到hdmi屏,所以无法控制背光pwm。
同理,想写在和屏启动相关的驱动里面,也是无法控制的。例如由i2c控制的gm8775c。
b.所以想到在底层驱动写一个文件节点,由上层应用去控制。
二、解决方法
A、底层驱动
这里写了一个c文件,gpio_led.c
/*
* Driver for keys on GPIO lines capable of generating interrupts.
*
* Copyright (C) 2015, Fuzhou Rockchip Electronics Co., Ltd
* Copyright 2005 Phil Blundell
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/sched.h>
#include <linux/pm.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/wakelock.h>
#include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
struct vanzeak_gpio_drvdata {
struct gpio_desc *power_gpio;
struct gpio_desc *sleep_gpio;
};
static const struct of_device_id vanzeak_gpio_match[] = {
{ .compatible = "vanzeak,gpio", .data = NULL},
{},
};
MODULE_DEVICE_TABLE(of, vanzeak_