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