input子系統(tǒng)介紹
Linux內(nèi)核為了能夠處理各種不同類型的輸入設(shè)備,比如: 觸摸屏 ,鼠標(biāo) , 鍵盤 , 操縱桿等設(shè)備 ,設(shè)計(jì)并實(shí)現(xiàn)了Linux 輸入子系統(tǒng) ,它為驅(qū)動(dòng)和應(yīng)用提供了統(tǒng)一的接口函數(shù),方便實(shí)現(xiàn)各種輸入設(shè)備的驅(qū)動(dòng)。
input子系統(tǒng)架構(gòu)
(1)驅(qū)動(dòng)層功能 :負(fù)責(zé)和底層的硬件設(shè)備打交道,將底層硬件設(shè)備對用戶輸入的響應(yīng)轉(zhuǎn)換為標(biāo)準(zhǔn)的輸入事件以后再向上發(fā)送給輸入子系統(tǒng)核心層。
(2)Input系統(tǒng)核心層 :由driver/input/input.c及相關(guān)頭文件實(shí)現(xiàn),它對下提供了設(shè)備驅(qū)動(dòng)層的接口,對上提供了事件處理層的編程接口。
(3)事件處理層 :將硬件設(shè)備上報(bào)的事件分發(fā)到用戶空間和內(nèi)核。
重要結(jié)構(gòu)體
- input_dev
//輸入設(shè)備
struct input_dev {
const char *name; //設(shè)備名稱
const char *phys; //設(shè)備的物理路徑
const char *uniq; //唯一ID
struct input_id id; //輸入ID
unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)]; //設(shè)備屬性
//所支持的input事件,(鍵盤, 按鍵,坐標(biāo)等)
unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; //事件類型
//下面是根據(jù)具體設(shè)備來決定設(shè)置哪些
unsigned long keybit[BITS_TO_LONGS(KEY_CNT)]; //按鍵
unsigned long relbit[BITS_TO_LONGS(REL_CNT)]; //相對坐標(biāo)
unsigned long absbit[BITS_TO_LONGS(ABS_CNT)]; //絕對坐標(biāo)
unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)]; //其他事件(混雜事件)
unsigned long ledbit[BITS_TO_LONGS(LED_CNT)]; //帶LED
unsigned long sndbit[BITS_TO_LONGS(SND_CNT)]; //音效
unsigned long ffbit[BITS_TO_LONGS(FF_CNT)]; //力反饋效果
unsigned long swbit[BITS_TO_LONGS(SW_CNT)]; //帶開關(guān)
unsigned int hint_events_per_packet; //每個(gè)包中的平均事件數(shù)
unsigned int keycodemax;
unsigned int keycodesize;
void *keycode; //掃描碼到鍵碼的映射
int (*setkeycode)(struct input_dev *dev,
const struct input_keymap_entry *ke,
unsigned int *old_keycode);
int (*getkeycode)(struct input_dev *dev,
struct input_keymap_entry *ke);
struct ff_device *ff;
unsigned int repeat_key; //保存上次按下的按鍵
struct timer_list timer;
int rep[REP_CNT];
struct input_mt *mt; //多點(diǎn)觸摸狀態(tài)
struct input_absinfo *absinfo; //絕對坐標(biāo)信息
//保存設(shè)備的當(dāng)前狀態(tài)
unsigned long key[BITS_TO_LONGS(KEY_CNT)];
unsigned long led[BITS_TO_LONGS(LED_CNT)];
unsigned long snd[BITS_TO_LONGS(SND_CNT)];
unsigned long sw[BITS_TO_LONGS(SW_CNT)];
int (*open)(struct input_dev *dev);
void (*close)(struct input_dev *dev);
int (*flush)(struct input_dev *dev, struct file *file);
int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
struct input_handle __rcu *grab;
spinlock_t event_lock;
struct mutex mutex;
unsigned int users;
bool going_away;
struct device dev; //設(shè)備
struct list_head h_list;
struct list_head node;
unsigned int num_vals;
unsigned int max_vals;
struct input_value *vals;
};
input_dev代表了一個(gè)輸入設(shè)備,結(jié)構(gòu)體里面就是保存了輸入設(shè)備的信息,以及不同輸入設(shè)備的不同事件。
API函數(shù)
//分配一個(gè)輸入設(shè)備
struct input_dev *input_allocate_device(void)
//釋放輸入設(shè)備
void input_free_device(struct input_dev *dev)
//注冊輸入設(shè)備到輸入核心層
int input_register_device(struct input_dev *dev)
//注銷輸入設(shè)備
void input_unregister_device(struct input_dev *dev)
/*
報(bào)告輸入事件
參數(shù)說明:
dev: 產(chǎn)生事件的設(shè)備
type: 事件的類型
code:事件碼
value:事件的值
*/
void input_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
//報(bào)告按鍵事件,內(nèi)部調(diào)用input_event
void input_report_key(struct input_dev *dev, unsigned int code, int value)
//報(bào)告相對坐標(biāo)
void input_report_rel(struct input_dev *dev, unsigned int code, int value)
//報(bào)告絕對坐標(biāo)
void input_report_abs(struct input_dev *dev, unsigned int code, int value)
//報(bào)告同步事件,用來告訴上層,本次的事件已經(jīng)完成了
void input_sync(struct input_dev *dev)
//用來設(shè)置設(shè)備所產(chǎn)生的事件以及上報(bào)的按鍵值
#define set_bit(nr,p) ATOMIC_BITOP(set_bit,nr,p)
#define clear_bit(nr,p) ATOMIC_BITOP(clear_bit,nr,p)
輸入設(shè)備事件類型
EV_SYN 0x00 //同步事件
EV_KEY 0x01 //按鍵事件
EV_REL 0x02 //相對坐標(biāo)
EV_ABS 0x03 //絕對坐標(biāo)
EV_MSC 0x04 //其它
EV_LED 0x11 //LED
EV_SND 0x12 //聲音
EV_REP 0x14 //Repeat
EV_FF 0x15 //力反饋
EV_PWR //電源
EV_FF_STATUS //狀態(tài)
每個(gè)事件類型下面會有一些事件碼(Event Codes),它會更精準(zhǔn)的描述事件類型。
總結(jié)
輸入設(shè)備驅(qū)動(dòng)的內(nèi)容并不多,主要還是要對設(shè)備的工作原理有深入的了解,才能編寫對應(yīng)驅(qū)動(dòng)。
-
內(nèi)核
+關(guān)注
關(guān)注
3文章
1383瀏覽量
40438 -
Linux
+關(guān)注
關(guān)注
87文章
11350瀏覽量
210476 -
鍵盤
+關(guān)注
關(guān)注
4文章
859瀏覽量
39884 -
子系統(tǒng)
+關(guān)注
關(guān)注
0文章
110瀏覽量
12462 -
結(jié)構(gòu)體
+關(guān)注
關(guān)注
1文章
130瀏覽量
10872
發(fā)布評論請先 登錄
相關(guān)推薦
關(guān)于Linux設(shè)備驅(qū)動(dòng)中input子系統(tǒng)的介紹
linux驅(qū)動(dòng)-Input輸入子系統(tǒng)
Linux設(shè)備驅(qū)動(dòng)之input子系統(tǒng)
linux input子系統(tǒng)的input core、input drivers和event handles
如何使用Linux內(nèi)核中的input子系統(tǒng)
迅為i.MX6ULL終結(jié)者Linux INPUT子系統(tǒng)實(shí)驗(yàn)Input子系統(tǒng)
介紹下input子系統(tǒng)
【OpenHarmony資料合集】Sensor子系統(tǒng)/圖形子系統(tǒng)/Ability子系統(tǒng)介紹
Linux input 子系統(tǒng)范例和基本函數(shù)解析
詳細(xì)了解Linux設(shè)備模型中的input子系統(tǒng)
![詳細(xì)了解Linux設(shè)備模型中的<b class='flag-5'>input</b><b class='flag-5'>子系統(tǒng)</b>](https://file.elecfans.com/web1/M00/91/DE/pIYBAFzVPpaAUS9dAAC5ovMfQhA395.png)
驅(qū)動(dòng)之路-input子系統(tǒng)
面向運(yùn)載火箭能源子系統(tǒng)的架構(gòu)設(shè)計(jì)方法
嵌入式Linux input
![嵌入式Linux <b class='flag-5'>input</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
OpenHarmony Dev-Board-SIG專場:OpenHarmony音頻子系統(tǒng)以及相機(jī)子系統(tǒng)架構(gòu)
![OpenHarmony Dev-Board-SIG專場:OpenHarmony音頻<b class='flag-5'>子系統(tǒng)</b>以及相機(jī)<b class='flag-5'>子系統(tǒng)</b><b class='flag-5'>架構(gòu)</b>](https://file.elecfans.com/web2/M00/2A/82/poYBAGHKtlCAd-9ZAAKwz5KuqFw601.png)
Linux驅(qū)動(dòng)學(xué)習(xí)筆記:input子系統(tǒng)機(jī)制
![Linux驅(qū)動(dòng)學(xué)習(xí)筆記:<b class='flag-5'>input</b><b class='flag-5'>子系統(tǒng)</b>機(jī)制](https://file1.elecfans.com/web2/M00/89/F4/wKgaomSNUiOAdqWIAADiZhbkXJg556.jpg)
評論