收集整理了一份《2024年最新物联网嵌入式全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升的朋友。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人
都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) |
BIT_MASK(BTN_EXTRA);
input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
input_set_drvdata(input_dev, mouse);
input_dev->open = usb_mouse_open;
input_dev->close = usb_mouse_close;
usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,
(maxp > 8 ? 8 : maxp),
usb_mouse_irq, mouse, endpoint->bInterval);
mouse->irq->transfer_dma = mouse->data_dma;
mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
error = input_register_device(mouse->dev);
if (error)
goto fail3;
usb_set_intfdata(intf, mouse);
return 0;
fail3:
usb_free_urb(mouse->irq);
fail2:
usb_free_coherent(dev, 8, mouse->data, mouse->data_dma);
fail1:
input_free_device(input_dev);
kfree(mouse);
return error;
}
static void usb_mouse_disconnect(struct usb_interface *intf)
{
struct usb_mouse *mouse = usb_get_intfdata (intf);
usb_set_intfdata(intf, NULL);
if (mouse) {
usb_kill_urb(mouse->irq);
input_unregister_device(mouse->dev);
usb_free_urb(mouse->irq);
usb_free_coherent(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma);
kfree(mouse);
}
}
static struct usb_device_id usb_mouse_id_table [] = {
{
USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
USB_INTERFACE_PROTOCOL_MOUSE)
},
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE (usb, usb_mouse_id_table);
static struct usb_driver usb_mouse_driver = {
.name = “usbmouse”,
.probe = usb_mouse_probe,
.disconnect = usb_mouse_disconnect,
.id_table = usb_mouse_id_table,
};
module_usb_driver(usb_mouse_driver);
应用层的USB测试代码:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/input.h>
#define MACH_NAME “mouse” //匹配的名字
#define EVENT_X_FORMAT “/dev/event%d” //dev目录下设备文件路径
int test_mouse(char *mousedev);
//根据设备名查找输入设备的下标
int get_event_x(char *mach_name);
int main(void)
{
int ret = 0;
int x = 0;
char file_path_buffer[100]= {0};
x = get_event_x(MACH_NAME);
if(x<0) {
printf("%s不存在!\n",MACH_NAME);
exit(0);
}
sprintf(file_path_buffer,EVENT_X_FORMAT,x);
ret = test_mouse(file_path_buffer);
return ret;
}
int init_device(char *dev)
{
int fd;
if((fd = open(dev, O_RDONLY)) < 0) {
printf(“Error open %s\n\n”, dev);
return -1;
}
return fd;
}
int test_mouse(char *mousedev)
{
static struct input_event data;
int fd;
fd=init_device(mousedev);
if( fd < 0) {
return -1;
}
while(1) {
read(fd, &data, sizeof(data));
if (data.type == EV_KEY) {
printf("type = EV_KEY, code = %s, value = %d\n",
data.code == BTN_LEFT ? "MOUSE_LEFT" :
data.code == BTN_RIGHT ? "MOUSE_RIGHT" :
data.code == BTN_MIDDLE ? "MOUSE_MIDDLE" :
data.code == BTN_SIDE ? "MOUSE_SIDE" :
"Unkonw", data.value);
} else if(data.type == EV_REL) {
printf("type = EV_REL, code = %s, value = %d\n",
data.code == REL_X ? "REL_X" :
data.code == REL_Y ? "REL_Y" :
data.code == ABS_WHEEL ? "MOUSE_WHEEL" :
data.code == ABS_PRESSURE ? "ABS_PRESSURE" :
"Unkown", data.value);
}
}
return 0;
}
//判断文件是否存
int file_is_exist(char *filepath)
{
int ret;
if((access(filepath,F_OK))!=-1) {
printf(“文件 %s 存在.\n”,filepath);
ret = 0;
} else {
printf(“%s不存在!\n”,filepath);
ret = -1;
}
return ret;
}
//根据设备名查找输入设备的下标
int get_event_x(char *mach_name)
{
//搜索路径
#define EVENT_FILE_FORMAT “/sys/class/input/event%d/device/name”
int i= 0;
int j;
size_t len = 0;
ssize_t read;
FILE * flip;
char *line;
char file_path_buffer[100]= {0};
char file_data_buffer[100]= {0};
char tem_mach_name[100]= {0};
for(i=0; i<32; i++) {
sprintf(file_path_buffer,EVENT_FILE_FORMAT,i);
if(!file_is_exist(file_path_buffer)) {
flip = fopen(file_path_buffer, “r”);
if(flip==NULL) {
printf(“cant open the file\n”);
continue;
}
//fread(file_data_buffer,100,1,flip);
read = getline(&line, &len, flip);
if(read == -1)
{
printf("read the file error\n");
return -1;
}
stpncpy(file_data_buffer,line,read );
if (line)
free(line);
printf("%s\n",file_data_buffer);
j = 0;
while(file_data_buffer[j++]) {
file_data_buffer[j] = tolower(file_data_buffer[j]);
}
j = 0;
while(tem_mach_name[j++]) {
tem_mach_name[j] = tolower(mach_name[j]);
}
if(strstr(file_data_buffer,mach_name)) {
return i;
}
}
}
return -1;
}
int file_permission(char *filepath)
{
if((access(filepath,F_OK))!=-1) {
printf(“文件 %s 存在.\n”,filepath);
} else {
printf(“%s不存在!\n”,filepath);
}
if(access(filepath,R_OK)!=-1) {
printf("%s 有可读权限\n",filepath);
} else {
printf("test.c 不可读.\n");
}
if(access(filepath,W_OK)!=-1) {
printf("%s 有可写权限\n",filepath);
} else {
printf("%s 不可写.\n",filepath);
}
if(access(filepath,X_OK)!=-1) {
printf("%s 有可执行权限\n",filepath);
} else {
printf("%s 不可执行.\n",filepath);
}
}
![img](https://img-blog.csdnimg.cn/img_convert/e64cdb82a34e3fcdeb68d19cca66cf4c.png)
![img](https://img-blog.csdnimg.cn/img_convert/3b9790df844acf4b4fcd9d9a51e74619.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上物联网嵌入式知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新**
**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618679757)**
N04V-1715625249988)]
[外链图片转存中...(img-0eThYPfq-1715625249988)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上物联网嵌入式知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、电子书籍、讲解视频,并且后续会持续更新**
**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618679757)**