licheepi nano BS8112A触摸按键

本文介绍了如何在licheepi nano上配置BS8112A触摸芯片驱动,该芯片拥有12个按键并使用I2C接口。通过在Linux内核中添加驱动代码、修改Makefile和Kconfig、调整设备树,最终成功编译并在启动时显示出相关设备信息。
摘要由CSDN通过智能技术生成

BS8112A是一款带有12个按键的触摸芯片。I2C接口,带中断指示,可通过I2C配置寄存器改变按键的触发门槛值。

内核版本:Linux-4.15.0

硬件:荔枝派 licheepi-nano

一、在内核中新增BS8112A的驱动代码。在内核目录drivers/input/keyboard/下新建bs8112a.c,直接上代码

/*
 *  BS8112A - Touch keypad controler.
 *	data	: 2019-12-24
 *  author	: lutao
 */

#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/input.h>
#include <linux/delay.h>


#define BS8112A_CYCLE_INTERVAL	(1*HZ/10)  //100ms

static unsigned char bs8112a_key2code[] = {
	KEY_0, KEY_1, KEY_2, KEY_3,
	KEY_4, KEY_5, KEY_6, KEY_7,
	KEY_8, KEY_9, KEY_A, KEY_B,
};


#define TRIGER_GATE_VAL		0x10   
const unsigned char configbuffer[] = 
{
	0x00,	//B0
	0x00,	//B1
	0x83,	//B2
	0xf3,	//B3
	0xd8,	//B4

	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,
	TRIGER_GATE_VAL,

	0x60,	//C0

	0x5e,	//checksum
};
#define W_FLG           0
#define R_FLG           1

struct bs8112a_data {
	struct i2c_client *client;
	struct input_dev *input;
	struct delayed_work dwork;
	spinlock_t lock;        /* Protects canceling/rescheduling of dwork */
	unsigned short keycodes[ARRAY_SIZE(bs8112a_key2code)];
	u16 key_matrix;
};

static char BS8112A_read_byte(struct i2c_client *client,const u8 reg);
static void BS8112A_write_byte(struct i2c_client *client,const u8 reg,const u8 val);

static int BS8112A_read_block(struct i2c_client *client,
			     u8 inireg, u8 *buffer, unsigned int count)
{
	int error, idx = 0;

	/*
	 * Can't use SMBus block data read. Check for I2C functionality to speed
	 * things up whenever possible. Otherwise we will be forced to read
	 * sequ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值