資源簡介
在 gpio-keyc的基礎(chǔ)上改寫的旋轉(zhuǎn)按鈕 ec11的驅(qū)動(dòng),已經(jīng)經(jīng)過了測試。可自定義左旋和右旋的鍵值。如果按鍵值輸入是第三個(gè)引腳,也支持按鍵操作
補(bǔ)存的頭文件:
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; /*旋轉(zhuǎn)編碼器A引腳的gpio號(hào)*/
int subgpio; /*旋轉(zhuǎn)編碼器B引腳的gpio號(hào)*/
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
評(píng)論
共有 條評(píng)論