当前位置: 首页 > news >正文

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_

相关文章:

  • 6. PromQL的metric name(在node exporter复制下来交给AI解释的)
  • k8s v1.28.15部署(kubeadm方式)
  • GAT从理论到实践——基于图注意力网络的节点特征计算与表示
  • 【运维笔记】Navicat中删除mongo 某个时间之前的数据
  • 分布式存储—— HBase数据模型 详解
  • 创建阿里云CDN
  • Spring Boot整合Resilience4j教程
  • 单例模式的五种实现方式
  • 基于BMO磁性细菌优化的WSN网络最优节点部署算法matlab仿真
  • 获取当前页面的 url 参数
  • Ubuntu20.04本地配置IsaacLab 4.5.0的训练环境(一)
  • 安卓基础组件Looper - 02 native层面的剖析
  • 单线程 Redis 如何实现高可用?深入图解主从复制与哨兵模式
  • HuggingFace 模型转换为 GGUF/GGML
  • [MySQL初阶]MySQL(4)基本查询
  • K8s 1.27.1 实战系列(一)介绍及准备工作
  • 使用阿里云 API 进行声音身份识别的方案
  • Pycharm 远程执行无法显示 cv2.imshow() 的原因分析及解决方案
  • wheel_legged_genesis 开源项目复现与问题记录
  • Linux - 进程控制
  • 河南一县政府党组成员签订抵制违规吃喝问题承诺书,现场交给县长
  • 上海市税务局:收到对刘某某存在涉税问题的举报,正依法依规办理
  • “85后”贵阳市政府驻重庆办事处主任吴育材拟任新职
  • 著名植物学家、园艺学家,国际植物园协会原主席贺善安逝世
  • 夜读|尊重生命的棱角
  • 吉林:消纳绿电,“氢”装上阵