• 大小: 27KB
    文件类型: .c
    金币: 1
    下载: 0 次
    发布日期: 2021-06-12
  • 语言: 其他
  • 标签: ec11  

资源简介

在 gpio-keyc的基础上改写的旋转按钮 ec11的驱动,已经经过了测试。可自定义左旋和右旋的键值。如果按键值输入是第三个引脚,也支持按键操作 补存的头文件: gpio_ec11.h #ifndef _GPIO_EC11_H #define _GPIO_EC11_H struct device; struct gpio_desc; /** * struct gpio_ec11_button - configuration parameters * @leftcode: ec11 left direction input event code (KEY_*, SW_*) * @rightcode: ec11 right direction input event code (KEY_*, SW_*) * @gpio: %-1 if this key does not support gpio * @gpio: %-1 if this key does not support gpio * @active_low: %true indicates that button is considered * depressed when gpio is low * @desc: label that will be attached to button's gpio * @type: input event type (%EV_KEY, %EV_SW, %EV_ABS) * @wakeup: configure the button as a wake-up source * @debounce_interval: debounce ticks interval in msecs * @can_disable: %true indicates that userspace is allowed to * disable button via sysfs * @value: axis value for %EV_ABS * @irq: Irq number in case of interrupt keys * @gpiod: GPIO descriptor */ struct gpio_ec11_button { unsigned int code; unsigned int leftcode; /*记录左旋键值*/ unsigned int rightcode; /*记录右旋键值*/ int gpio; /*旋转编码器A引脚的gpio号*/ int subgpio; /*旋转编码器B引脚的gpio号*/ int active_low; const char *desc; unsigned int type; int wakeup; int debounce_interval; bool can_disable; int value; unsigned int irq; unsigned int irq_flags; struct gpio_desc *gpiod; }; /** * struct gpio_ec11_platform_data - platform data for gpio_ec11 driver * @buttons: pointer to array of &gpio;_keys_button structures * describing buttons attached to the device * @nbuttons: number of elements in @buttons array * @poll_interval: polling interval in msecs - for polling driver only * @rep: enable input subsystem auto repeat * @enable: platform hook for enabling the device * @disable: platform hook for disabling the device * @name: input device name */ struct gpio_ec11_platform_data { struct gpio_ec11_button *buttons; int nbuttons; unsigned int poll_interval; unsigned int rep:1; int (*enable)(

资源截图

代码片段和文件信息

/*
 * Driver for keys on GPIO lines capable of generating interrupts.
 *
 * Copyright 2005 Phil Blundell
 * Copyright 2010 2011 David Jander 
 *
 * 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 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include   //20190408
#include   //20190412
#include 
#include 
#include 
#include 
#include 
#include 
#include 

struct gpio_ec11_data {
const struct gpio_ec11_button *button;  //20190408
struct input_dev *input;

struct timer_list release_timer;
unsigned int release_delay; /* in msecs for IRQ-only buttons */

struct delayed_work work;
unsigned int software_debounce; /* in msecs for GPIO-driven buttons */

unsigned int irq;
spinlock_t lock;
bool disabled;
bool key_pressed;
};

struct gpio_ec11_drvdata {
const struct gpio_ec11_platform_data *pdata;  //20190408
struct input_dev *input;
struct mutex disable_lock;
struct gpio_ec11_data data[0];    //20190408
};

/*
 * SYSFS interface for enabling/disabling keys and switches:
 *
 * There are 4 attributes under /sys/devices/platform/gpio-keys/
 * keys [ro]              - bitmap of keys (EV_KEY) which can be
 *                          disabled
 * switches [ro]          - bitmap of switches (EV_SW) which can be
 *                          disabled
 * disabled_keys [rw]     - bitmap of keys currently disabled
 * disabled_switches [rw] - bitmap of switches currently disabled
 *
 * Userland can change these values and hence disable event generation
 * for each key (or switch). Disabling a key means its interrupt line
 * is disabled.
 *
 * For example if we have following switches set up as gpio-keys:
 * SW_DOCK = 5
 * SW_CAMERA_LENS_COVER = 9
 * SW_KEYPAD_SLIDE = 10
 * SW_FRONT_PROXIMITY = 11
 * This is read from switches:
 * 11-95
 * Next we want to disable proximity (11) and dock (5) we write:
 * 115
 * to file disabled_switches. Now proximity and dock IRQs are disabled.
 * This can be verified by reading the file disabled_switches:
 * 115
 * If we now want to enable proximity (11) switch we write:
 * 5
 * to disabled_switches.
 *
 * We can disable only those keys which don‘t allow sharing the irq.
 */

/**
 * get_n_events_by_type() - returns maximum number of events per @type
 * @type: type of button (%EV_KEY %EV_SW)
 *
 * Return value of this function can be used to allocate bitmap
 * large enough to hold all bits for given type.
 */
static int get_n_even

评论

共有 条评论