Linux input子系统 (2)

从VLM到VLA概论 智驾视觉大模型 阅读详情

原文:http://blog.youkuaiyun.com/guoshaobei/article/details/5792635


Linux input子系统一个很重要的特性是它提供了 event interface。它通过字符设备节点对用户空间导出了原生event,允许用户程序操作任何 event,不会遗失任何信息。

 

查找 event interface版本

使用 EVIOCGVERSION ioctl function。参数是 32位 int类型,代表 major version (two high bytes), minor version (third byte), patch level (low byte)。 Listing 1显示了使用 EVIOCGVERSION的例子:第 1个参数是event device node的打开文件描述符。你需要传递一个指向 int数据的一个指针作为第 3个参数。

Listing 1. Sample EVIOCGVERSION Function
/* ioctl() accesses the underlying driver */ if (ioctl(fd, EVIOCGVERSION, &version)) { perror("evdev ioctl"); } /* the EVIOCGVERSION ioctl() returns an int */ /* so we unpack it and display it */ printf("evdev driver version is %d.%d.%d/n", version >> 16, (version >> 8) & 0xff, version & 0xff);

 

查找设备身份信息

event interface支持获取设备的身份信息,使用 EVIOCGID ioctl function。参数是指向 input_id数据结构的指针。 input_id数据结构定义如 listing 2所示。 _u16数据类型是 16为无符号整型。

Figure 2. input_id Structure Definitions
struct input_id { __u16 bustype; __u16 vendor; __u16 product; __u16 version; };

 

bustype 域包含了你需要的准确的数据信息。你应把它当作是一个非透明的枚举类型,需要与通过<linux/input.h>里定义的 BUG_x 类型比较获知。 vendor/product/version是与 bus type相关的表示设备身份信息的域。现代设备(如 USB, PCI)都使用了这些域,但是传统的设备( serial mice, ps/2 keyboard, ISA sound card)没有这些域。 EVIOCGID的使用如 listing 3所示。这个例子调用了 ioctl并打印了结果。

Listing 3. Sample EVIOCGID ioctl
/* suck out some device information */ if(ioctl(fd, EVIOCGID, &device_info)) { perror("evdev ioctl"); } /* the EVIOCGID ioctl() returns input_devinfo * structure - see <linux/input.h> * So we work through the various elements, * displaying each of them */ printf("vendor %04hx product %04hx version %04hx", device_info.vendor, device_info.product, device_info.version); switch ( device_info.bustype) { case BUS_PCI : printf(" is on a PCI bus/n"); break; case BUS_USB : printf(" is on a Universal Serial Bus/n"); break; ...

 

除了 bus type/vendor/product/version等设备信息,某些设备还会提供一个有意义的名字字符串,使用EVIOCGNAME获取。如果名字串太长,则在返回的参数里被截取。 Listing 4显示了它的使用的例子。

Listing 4. Example Truncated String
int fd = -1; char name[256]= "Unknown"; if ((fd = open(argv[1], O_RDONLY)) < 0) { perror("evdev open"); exit(1); } if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) { perror("evdev ioctl"); } printf("The device on %s says its name is %s/n", argv[1], name); close(fd);

 

下面是上述例子运行的结果样例:

The device on /dev/input/event0 says its name is Logitech USB-PS/2 Optical Mouse

 

尽管设备身份信息和名字信息通常很有用,但是它也许并没有提供足够的信息告诉你当前在使用哪个设备。例如,你当前有两个完全相同的遥控杆,你需要确定每个使用哪个端口。这通常属于拓扑信息( topology information),可以使用 EVIOCGPHYS ioctl获取。它返回一串字符串(或者一个负值错误码)。 Listing 5显示了它的使用的例子。

Listing 5. Using EVIOCGPHYS for Topology Information
if(ioctl(fd, EVIOCGPHYS(sizeof(phys)), phys) < 0) { perror("event ioctl"); } printf("The device on %s says its path is %s/n", argv[1], phys);

 

它的运行结果样例如下所示:

The device on /dev/input/event0 says its path is usb-00:01.2-2.1/input0

 

为了了解输出的含义,你需要将其分成几部分。 Usb部分意味着这使用 usb系统的一个物理拓扑。 00:01.2是usb host controller所在的 pci bus information (bus 0, slot 1, function 2)。 2.1表示了从 root hub到 device的路径,这里表示上行 hub接在 root hub的第 2个端口上,设备接在上行 hub的第 1个端口上。 Input0表示这是设备的第 1个 event device 节点。大部分设备只有一个 event device节点,但是有些设备例外。比如多媒体键盘,它有一个 event device节点用于 normal keyboard,另一个 event device节点用于 multimedia keyboard。拓扑示例如下图表示。

input subsystem topology

如果你在同一根连接线上将一个设备还成另外一个同样的设备,你无法区分设备更换,除非每一个设备有一个唯一号,比如 serial number。使用 EVIOCGUNIQ可以获取。 Listing 6是其示例。绝大多数设备没有这样的唯一号,所以你使用该 ioctl将返回一个空字符串。

Listing 6. Finding a Unique Identifier
if(ioctl(fd, EVIOCGUNIQ(sizeof(uniq)), uniq) < 0) { perror("event ioctl"); } printf("The device on %s says its identity is %s/n", argv[1], uniq);

 

确定设备能力和特性

对于一些设备,也许知道设备的身份信息就足够了,因为它允许你根据设备的使用情况处理设备的任何 case。但是这总做法的尺度不好。比如,你有一个设备仅有一个滑轮,你想使能处理滑轮的 handler,但是你并不想在code里列出每个带有滑轮的鼠标的 vendor/product信息。为此, event interface允许你对于某个设备确定有哪些功能和特性。 Event interface支持的 feature types有:

  • EV_KEY: absolute binary results, such as keys and buttons.

  • EV_REL: relative results, such as the axes on a mouse.

  • EV_ABS: absolute integer results, such as the axes on a joystick or for a tablet.

  • EV_MSC: miscellaneous uses that didn't fit anywhere else.

  • EV_LED: LEDs and similar indications.

  • EV_SND: sound output, such as buzzers.

  • EV_REP: enables autorepeat of keys in the input core.

  • EV_FF: sends force-feedback effects to a device.

  • EV_FF_STATUS: device reporting of force-feedback effects back to the host.

  • EV_PWR: power management events

这些仅仅是 type features。每个 type feature包含了很大范围的不同的个体 feature。例如, EV_REL type区别了 x轴, y轴, z轴,横轮,竖轮。同样, EV_KEY type包含了成千上百个 keys和 buttons。

使用 EVIOCGBIT ioctl可以获取设备的能力和特性。它告知你设备是否有 key或者 button。

EVIOCGBIT ioctl处理 4个参数 ( ioctl(fd, EVIOCGBIT(ev_type, max_bytes), bitfield))。 ev_type是返回的 type feature( 0是个特殊 case,表示返回设备支持的所有的 type features)。 max_bytes表示返回的最大字节数。bitfield域是指向保存结果的内存指针。 return value表示保存结果的实际字节数,如果调用失败,则返回负值。Listing 7展现了其使用示例,测试了 /dev/input/event0设备节点支持哪些 type feature。

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <fcntl.h>

#include <string.h>

#include <linux/input.h>

 

#define BITS_PER_LONG 32

#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)

 

static int test_bit(int nr, const volatile unsigned long *addr)

{

return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1)));

}

 

 

int main(int argc, char ** argv)

{

 

int fd;

unsigned long *evtype_b = malloc(sizeof(int));

int yalv;

 

 

if ((fd = open(argv[1], O_RDONLY)) < 0) {

perror("evdev open");

exit(1);

}

 

memset(evtype_b, 0, sizeof(evtype_b));

if (ioctl(fd, EVIOCGBIT(0, EV_MAX), evtype_b) < 0) {

perror("evdev ioctl");

}

 

printf("Supported event types:/n");

 

for (yalv = 0; yalv < EV_MAX; yalv++) {

if (test_bit(yalv, evtype_b)) {

/* the bit is set in the event types list */

printf(" Event type 0x%02x ", yalv);

switch ( yalv)

{

case EV_SYN :

printf(" (Synch Events)/n");

break;

case EV_KEY :

printf(" (Keys or Buttons)/n");

break;

case EV_REL :

printf(" (Relative Axes)/n");

break;

case EV_ABS :

printf(" (Absolute Axes)/n");

break;

case EV_MSC :

printf(" (Miscellaneous)/n");

break;

case EV_LED :

printf(" (LEDs)/n");

break;

case EV_SND :

printf(" (Sounds)/n");

break;

case EV_REP :

printf(" (Repeat)/n");

break;

case EV_FF :

case EV_FF_STATUS:

printf(" (Force Feedback)/n");

break;

case EV_PWR:

printf(" (Power Management)/n");

break;

default:

printf(" (Unknown: 0x%04hx)/n",

yalv);

}

}

}

 

close(fd);

 

}

 

这个例子使用了 evtype_bit掩码 EV_MAX(在 <linux/input.h>里定义),觉得 bit array需要多少内存。当 ioctl提交后,由 event layer填充 bit array。我们测试 bit array里的每一个 bit,来确定设备支持哪些 feature type。所有的设备都支持 EV_SYNC,该 bit由 input core来设置。

下面是运行结果的样例:

如果是 keyboard,则

Supported event types: Event type 0x00 (Synchronization Events) Event type 0x01 (Keys or Buttons) Event type 0x11 (LEDs) Event type 0x14 (Repeat

 

如果是 mouse,则

Supported event types: Event type 0x00 (Synchronization Events) Event type 0x01 (Keys or Buttons) Event type 0x02 (Relative Axes)

 

获取设备 (from or to)的 input

 

当确定了设备的能力和特性后,你就知道了设备的事件类型。

获取设备的 event通过 char设备的 read function。当你从 event device (例如 /dev/input/event0)里读取event时,你将获得一系列 events,每个 event由 input_event结构表示。

Listing 8示例展示了读取一个打开文件描述符 fd的事件。它过滤了不属于 key的事件,并打印 input_event结构里的每个域。

Listing 8. Checking for Busy Spots
/* how many bytes were read */ size_t rb; /* the events (up to 64 at once) */ struct input_event ev[64]; rb=read(fd,ev,sizeof(struct input_event)*64); if (rb < (int) sizeof(struct input_event)) { perror("evtest: short read"); exit (1); } for (yalv = 0; yalv < (int) (rb / sizeof(struct input_event)); yalv++) { if (EV_KEY == ev[yalv].type) printf("%ld.%06ld ", ev[yalv].time.tv_sec, ev[yalv].time.tv_usec, printf("type %d code %d value %d/n", ev[yalv].type, ev[yalv].code, ev[yalv].value); }

 

下面是运行的结果样例:

Event: time 1033621164.003838, type 1, code 37, value 1 Event: time 1033621164.027829, type 1, code 38, value 0 Event: time 1033621164.139813, type 1, code 38, value 1 Event: time 1033621164.147807, type 1, code 37, value 0 Event: time 1033621164.259790, type 1, code 38, value 0 Event: time 1033621164.283772, type 1, code 36, value 1 Event: time 1033621164.419761, type 1, code 36, value 0 Event: time 1033621164.691710, type 1, code 14, value 1 Event: time 1033621164.795691, type 1, code 14, value 0

 

对于每个 key,你会获得一个 key press和一个 key depress的 event。

这是 char设备的标准 read接口,所以你不需要在程序里 busy loop。此外,如果你想同时获得许多设备的input事件时,使用 poll/select函数。

给设备发送信息,使用 char设备的标准 write函数,发送的数据必须是 input_event数据结构。

Listing 9展示了简单的给设备写数据的示例。这个例子先让 Caps Lock LED打开,等 200毫秒,然后让 Caps Lock LED关闭;然后让 Num Lock LED打开,等 200毫秒,然后让 Num Lock LED关闭。不断循环这个过程,你会看到键盘上的指示灯交替闪烁。

Listing 9. Sample Data Write Function
struct input_event ev; /* the event */ /* we turn off all the LEDs to start */ ev.type = EV_LED; ev.code = LED_CAPSL; ev.value = 0; retval = write(fd, &ev, sizeof(struct input_event)); ev.code = LED_NUML; retval = write(fd, &ev, sizeof(struct input_event)); ev.code = LED_SCROLLL; retval = write(fd, &ev, sizeof(struct input_event)); while (1) { ev.code = LED_CAPSL; ev.value = 1; write(fd, &ev, sizeof(struct input_event)); usleep(200000); ev.value = 0; write(fd, &ev, sizeof(struct input_event)); ev.code = LED_NUML; ev.value = 1; write(fd, &ev, sizeof(struct input_event)); usleep(200000); ev.value = 0; write(fd, &ev, sizeof(struct input_event)); }

 

现在我们清楚的知道如何接收或者发送一个事件 ---key按下 /抬起,鼠标移动等等。对于一些程序,可能还需要知道设备的一些全局状态。比如,一个管理 keyboard的程序需要知道当前的哪些指示灯在亮,哪些键被释放。

EVIOCGKEY ioctl用于确定一个设备的全局 key/button状态,它在 bit array里设置了每个 key/button是否被释放。 Listing 10展示了该示例。

Listing 10. Determining a Device's Global Key and Button

State

uint8_t key_b[KEY_MAX/8 + 1]; memset(key_b, 0, sizeof(key_b)); ioctl(fd, EVIOCGKEY(sizeof(key_b)), key_b); for (yalv = 0; yalv < KEY_MAX; yalv++) { if (test_bit(yalv, key_b)) { /* the bit is set in the key state */ printf(" Key 0x%02x ", yalv); switch ( yalv) { case KEY_RESERVED : printf(" (Reserved)/n"); break; case KEY_ESC : printf(" (Escape)/n"); break; /* other keys / buttons not shown */ case BTN_STYLUS2 : printf(" (2nd Stylus Button )/n"); break; default: printf(" (Unknown key)/n"); } } }

 

EVIOCGLED和 EVIOCGSND ioctl与 EVIOCGKEY类似,分别表示当前 LED亮灯和声音通道打开。 Listing 11展示了 EVIOCGLED的使用。

Listing 11. Using EVIOCGLED
memset(led_b, 0, sizeof(led_b)); ioctl(fd, EVIOCGLED(sizeof(led_b)), led_b); for (yalv = 0; yalv < LED_MAX; yalv++) { if (test_bit(yalv, led_b)) { /* the bit is set in the LED state */ printf(" LED 0x%02x ", yalv); switch ( yalv) { case LED_NUML : printf(" (Num Lock)/n"); break; case LED_CAPSL : printf(" (Caps Lock)/n"); break; /* other LEDs not shown here*/ default: printf(" (Unknown LED: 0x%04hx)/n", yalv); } } }

 

 

使用 EVIOCGREP ioctl来获取键盘的重复速率。 Listing 12展示了该示例。(重复速率指你按下键后,输出的事件的次数。例如,按下 1键且不释放, console里会输出多个 1的速率)

Listing 12. Checking the Repeat Rate Settings
int rep[2]; if(ioctl(fd, EVIOCGREP, rep)) { perror("evdev ioctl"); } printf("[0]= %d, [1] = %d/n", rep[0], rep[1]);

其中, rep[0]表示在按键重复出现之前 delay的时间; rep[1]表示按键重复出现的时间间隔。

 

使用 EVIOCSREP ioctl来设置键盘的重复速率。 Listing 13展示了该示例。

Listing 13. Setting the Repeat Rates
int rep[2]; rep[0] = 2500; rep[1] = 1000; if(ioctl(fd, EVIOCSREP, rep)) { perror("evdev ioctl"); }

rep[0]/rep[1]的含义同 Listing 12。

 

有些 input driver支持 key mapping。使用 EVIOCGKEYCODE ioctl获取一个 key对应的 scancode。 Listing 14/Listing 15展示了 key mapping的示例。注意有些键盘驱动并不支持这个特性(比如 USB键盘)。如果你想修改 key mapping,使用 EVIOCSKEYCODE ioctl即可。

Listing 14. Looping over Scancodes
int codes[2]; for (i=0; i<130; i++) { codes[0] = i; if(ioctl(fd, EVIOCGKEYCODE, codes)) { perror("evdev ioctl"); } printf("[0]= %d, [1] = %d/n", codes[0], codes[1]); }

 

 

Listing 15. Mapping Keys
int codes[2]; codes[0] = 58; /* M keycap */ codes[1] = 49; /* assign to N */ if(ioctl(fd, EVIOCSKEYCODE, codes)) { perror("evdev ioctl"); }

 

使用 EVIOCGABS ioctl提供绝对坐标轴设备的状态信息。它为每一个绝对坐标轴提供了一个 input_absinfo数据结构(参考 Listing 16)。如果你想查看设备的全局状态,对每一个坐标轴调用 EVIOCGABS ioctl函数。 Listing 17展示了该示例。

Listing 16. input_absinfo for an Absolute Axis
struct input_absinfo { __s32 value; // current value of the axis __s32 minimum; // current limits of the axis __s32 maximum; // current limits of the axis __s32 fuzz; __s32 flat; };

 

Listing 17. Checking Global State by Axis
uint8_t abs_b[ABS_MAX/8 + 1]; struct input_absinfo abs_feat; ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_b)), abs_b); printf("Supported Absolute axes:/n"); for (yalv = 0; yalv < ABS_MAX; yalv++) { if (test_bit(yalv, abs_b)) { printf(" Absolute axis 0x%02x ", yalv); switch ( yalv) { case ABS_X : printf("(X Axis) "); break; case ABS_Y : printf("(Y Axis) "); break; default: printf("(Unknown abs feature)"); } if(ioctl(fd, EVIOCGABS(yalv), &abs_feat)) { perror("evdev EVIOCGABS ioctl"); } printf("%d (min:%d max:%d flat:%d fuzz:%d)", abs_feat.value, abs_feat.minimum, abs_feat.maximum, abs_feat.flat, abs_feat.fuzz); printf("/n"); } }

 

Force Feedback (力回馈)

有三个 ioctl用于控制 force-feedback设备: EVIOCSFF, EVIOCRMFF, EVIOCGEFFECT。这三个 ioctl分别表示发送一个 force-feedback effect,删除一个 force-feedback effect,获取当前多少个 effect在同时使用。


【YOLO11改进 - 注意力机制】SCSA通过结合空间注意力和通道注意力,提高各种下游视觉任务的性能。 阅读详情

相关推荐

搞定8GB/s数据流:一个FPGA工程师的XDMA驱动调优实战(附避坑清单)

本文详细记录了FPGA工程师在XDMA驱动调优过程中实现8GB/s高带宽数据流的实战经验。通过优化DDR访问、中断响应、DMA映射等关键环节,解决了PCIE数据采集卡在高带宽场景下的性能瓶颈,并提供了实用的避坑清单和技术方案。

weixin_29194255的博客 202

RK3568驱动指南|第十三篇 输入子系统-第148章 通用事件处理层open函数分析

在错误处理中,函数调用evdev_detach_client函数将client从输入设备中分离,然后使用kvfree函数释放client占用的内存空间,并返回相应的错误码。比如我们在应用程序中使用open函数打开设备节点,会执行文件操作集中的open函数,当我们在应用程序中使用read函数读设备节点的时候,会执行文件操作集中的read函数。在上述代码中,首先使用mutex_lock_interruptible函数获取输入设备的互斥锁,如果无法获取锁,函数将返回相应的错误码。

BeiJingXunWei的博客 897

Ubuntu登录界面黑屏?手把手教你排查和修复LightDM启动失败(附debug命令详解)

本文详细介绍了Ubuntu系统中LightDM(Light Display Manager)启动失败导致登录界面黑屏的排查与修复方法。通过系统状态检查、调试模式分析、常见故障解决方案及高级调试技巧,帮助用户快速定位并解决LightDM相关问题,恢复正常的图形登录环境。

weixin_34005090的博客 314

Linux input子系统 io控制字段

include/linux/input.h   #define EVIOCGVERSION        _IOR('E', 0x01, int)            /* get driver version */ #define EVIOCGID        _IOR('E', 0x02, struct input_id)    /* get device ID */ #de

快乐&&平凡 3590

浅谈迪杰斯特拉(Dijkstra)算法和A*算法原理及实现

迪杰斯特拉(Dijkstra)算法和A*算法的原理及实现。

Guo_Zhanyu 9597

Reactor 响应式编程(第一篇:Reactor核心)

响应式:响应式编程: 全异步、消息、事件回调默认还是用当前线程,生成整个流、发布流、流操作.log();//只要不指定线程池,默认发布者用的线程就是订阅者的线程;

moments的博客 1571

linux设备驱动之输入(input)子系统——核心层实现

/*************************************************************************************************************************************/ /* input.h */ #ifndef _INPUT_H #define _INPUT_H /*  *

highfly591的专栏 5133

高级数据库--作业及答案

中科大金培权老师的高级数据库课程作业及答案

一杯水果茶!足矣~ 1655

Linux input子系统 io控制字段【转】

转自:http://www.cnblogs.com/leaven/archive/2011/02/12/1952793.html http://blog.youkuaiyun.com/guoshaobei/archive/2010/08/06/5792635.aspx include/linux/input.h   #define EVIOCGVERSION        _IOR('E', 0x01...

weixin_34061555的博客 339

Android15音频进阶之解underrun与overrun思路(一百一十七)

本篇目的:Android15音频进阶之解underrun与overrun思路Underrun:发生在播放:APP准备的数据太少,导致底层没有音频数据可以播放,导致ADSP被“饿死了“,即Underrun。Overrun: 发声在录音:APP录音数据获取太慢了,导致底层录出来的数据太多了,APP播放不了,导致APP被“撑死了”,即Overrun。

Android系统攻城狮 2102

StarRocks 面试题及参考答案详解(万字详解)

Broker Load的过程通常涉及到数据的解析、转换和加载,它支持多种数据格式,并且可以处理复杂的数据导入任务。一方面,压缩可以减少磁盘I/O操作,因为压缩后的数据占用的空间更小,需要读取的数据块数量也就更少。在StarRocks中,表数据可以被划分成多个分区,每个分区包含表的一部分数据。在传统的行存储模型中,数据是按行组织的,这意味着在执行分析查询时,系统需要读取并处理整行数据,即使很多时候只需要查询其中的少数几列。物化视图的更新可以是完全重算,也可以是增量更新,取决于物化视图的定义和数据变更的模式。

大模型大数据攻城狮的专栏 2075

【Linux系统编程应用】 Linux输入子系统(二)

1. 设备ID信息结构体结构体如下:/* * IOCTLs (0x00 - 0x7f) */ struct input_id { __u16 bustype; __u16 vendor; __u16 product; __u16 version; }; struct input_absinfo { __s32 value; __s32 min

C/C++软件工程师、嵌入式软件工程师、物联网研发工程师、C/C++讲师、物联网讲师、嵌入式讲师、鸿蒙讲师---欢迎大家一起交流(私信添加博主微信) 1819

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Linux Input子系统2

Linux Input子系统2(基于Linux6.6)---框架介绍

ListQ的博客 1060

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

linux 设备模型详解,Linux2.6 设备模型之input子系统详解

Linux2.6 设备模型之input子系统详解一:前言在键盘驱动代码分析的笔记中,接触到了input子系统.键盘驱动,键盘驱动将检测到的所有按键都上报给了input子系统。Input子系统是所有I/O设备驱动的中间层,为上层提供了一个统一的界面。例如,在终端系统中,我们不需要去管有多少个键盘,多少个鼠标。它只要从input子系统中去取对应的事件(按键,鼠标移位等)就可以了。今天就对input子系...

weixin_42102634的博客 235

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

2 Linux input子系统之input初始化

input函数路径:drivers/input/input.c。是 Linux 输入子系统中的一个关键函数,用于。

枫潇潇 359

input分析linux,linux2.6input子系统中部分相关结构体的分析

1.input_dev说明:输入子系统(input subsystem)的驱动层的核心结构。头文件:include/linux/input.h成员说明:void *private;//不清楚。char *name;//设备名字,如键盘名字。char *phys;//设备文件节点名,如input/kbd0。char *uniq;//全球唯一的ID号。struct input_id id;//后文作详...

weixin_29025911的博客 294

深层次分析linux2.6input子系统

在linux下,按键、触摸屏、鼠标等都可以利用input接口函数来实现设备驱动。     从上图可知: 输入子系统由三部分构成: 1 驱动 2 输入子系统 3 处理函数 其中2,3都是内核已经完成,我们要完成的就是1驱动 设备用input_dev结构体描述,使用input子系统实现输入设备驱动的时候,驱动的核心工作是向系统报告按键、触摸屏、键盘、鼠标等输入事件(event,通

wu7585535的专栏 1047

Linux驱动学习(2) 从usb驱动到input子系统3

input输入子系统 (一)Input子系统简介 1.内核中有一些文档对input子系统有详细的描述 例如\linux-source-4.15.0\Documentation\input\input.rst : For the most usual configuration, with one USB mouse and one USB keyboard, you'll have to load...

xiaoshixiu的专栏 1000

Input子系统详解-基于Linux2.6.22内核

(1)输入子系统框架 Input子系统框架 app: open() read() write() --------------------------------------------- 内核: xxx_drv的 fos 结构体里面的 xxx_open() xxx_write xxx_write -----------------------------...

简单博客 380

Linux驱动学习(2) 从usb驱动到input子系统2

USB驱动的学习 参考博客:https://blog.youkuaiyun.com/qq_21792169/article/details/48790745 参考书籍:《Linux设备驱动程序》 (一)USB驱动概述 1.要写鼠标驱动,首先必须理解USB设备层次,《Linux设备驱动程序》中给出的层次图如下。USB层次主要有三层架构,USB主控制器驱动(USB Host Controllers)直接和USB硬...

xiaoshixiu的专栏 454

linux驱动——input输入子系统(2)——handler

linux驱动——input输入子系统(1)—输入子系统核心层(Input Core)的链接地址 input_handler一般称为handler处理器,表示对输入事件的具体处理。 input_handler为输入设备的功能实现了一个接口,输入事件最终传递到handler处理器,handler处理器根据一定的规则,然后对事件进行处理。 input_handler是输

思考的智慧,知识源于思考 7483

Linux输入子系统(2):初识input输入子系统

转载:https://blog.youkuaiyun.com/ielife/article/details/7798952 1开发环境 主机:ubuntu10.04 开发板:mini2440 内核:linux-2.6.22.6 编译器:arm-linux-gcc(3.4.5) 2linux输入子系统 本节从整体上讲解了输入子系统的框架结构。有助于读者从整体上认识lin...

zjy900507的博客 181

[转]linux2.6input子系统中部分相关结构体的分析

最近在做linux2.6的键盘驱动程序的工作,接触到了input subsystem这一概念,现把我对其中相关结构体的理解写出来。如果我的理解有错误,希望大家指正,谢谢! 1.input_dev 说明:输入子系统(input subsystem)的驱动层的核心结构。   头文件:include/linux/input.h 成员说明:void *private;      

wind20的专栏 2364

【转】Linux input子系统 (2)

译文地址:https://blog.youkuaiyun.com/guoshaobei/article/details/5792635 原文:http://www.linuxjournal.com/article/6429 尽管原文写于2003,仍有参考价值。 <!-- @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom:...

weixin_30412013的博客 206

linux 驱动 (2)---Linux input子系统最清晰、详尽的分析

Linux input子系统最清晰、详尽的分析Linux input分析之二:解构input_handler、input_core、input_device       输入输出是用户和产品交互的手段,因此输入驱动开发在Linux驱动开发中很常见。同时,input子系统的分层架构思想在Linux驱动设计中极具代表性和先进性,因此对Linux input子系统进行深入分析很有意义。本文继续在《Lin...

zhangbijun1230的专栏 528
上一篇: ubuntu 下不能识别 eth0 解决方法
下一篇: [转] GCC 中文手册
code09
博客等级 码龄18年 31粉丝 56原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值