UEFI开发探索90- YIE002USB开发板(13 Linux编程)
发布日期:2021-05-15 16:34:27 浏览次数:22 分类:精选文章

本文共 4460 字,大约阅读时间需要 14 分钟。

YIE002USB������������Linux������

1 ������������������

���������������������������������������������������������������������hidlibusb���������������������������������

libusb/hid.chidapi/hidapi.hhidtest/test.c

���������������������Makefile������������������

all: hidtest-libusb libs
libs: libhidapi-libusb.so
CC ?= gcc
CFLAGS ?= -Wall -g -fpic
LDFLAGS ?= -Wall -g
COBJS_LIBUSB = hid.o
COBJS = $(COBJS_LIBUSB) test.o
OBJS = $(COBJS)
LIBS_USB = `pkg-config libusb-1.0 --libs` -lrt -lpthread
LIBS = $(LIBS_USB)
INCLUDES ?= `pkg-config libusb-1.0 --cflags`
# Console Test Program
hidtest-libusb: $(COBJS) $(CC) $(LDFLAGS) $^ $(LIBS_USB) -o $@
# Shared Libs
libhidapi-libusb.so: $(COBJS_LIBUSB) $(CC) $(LDFLAGS) $(LIBS_USB) -shared -fpic -Wl,-soname,$@.0 $^ -o $@
# Objects
$(COBJS): %.o: %.c $(CC) $(CFLAGS) -c $(INCLUDES) $< -o $@
clean: rm -f $(OBJS) hidtest-libusb libhidapi-libusb.so hidtest.o
.PHONY: clean libs

2 ������������

������������������������������������������������USB HID���������������������������hid_read()���hid_write()���������������������Feature report���������������������������������������������������������������������libusb������hid.c������������������������������������������������������������������������������������������������������Input report���Output report������������������

2.1 ������Output report���������������

���������������libusb������������hid.c������������������������Input report���������hid_get_input_report()������������������������������Output report���������������������������Output report���������������������������������

���hid_send_feature_report()���������������������������������

int HID_API_EXPORT HID_API_CALL
hid_set_output_report(hid_device *dev, const unsigned char *data, size_t length) {
int res = -1;
int skipped_report_id = 0;
int report_number = data[0];
if (report_number == 0x0) {
data++;
length--;
skipped_report_id = 1;
}
res = libusb_control_transfer(dev->device_handle,
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE | LIBUSB_ENDPOINT_OUT,
0x09/*HID set_report*/,
(2/*HID Output*/ << 8) | report_number,
dev->interface,
(unsigned char *)data,
length,
1000/*timeout millis*/);
if (res < 0) {
return -1;
}
if (skipped_report_id) {
length++;
}
return length;
}

2.2 Input report���Output report������������

������������������������������������������������������������������������������������������������������������������Output report���������Input report���������������������������

memset(yie_buf, 0, sizeof(yie_buf));
yie_buf[0] = 0x00;
yie_buf[1] = 0xA0;
yie_buf[2] = 0x0A;
yie_buf[3] = 0x0B;
yie_buf[4] = 0x0C;
res = hid_set_output_report(handle, yie_buf, 17);
if (res < 0) {
printf("Unable to send a output report.\n");
}
memset(yie_buf, 0, sizeof(yie_buf));
res = hid_get_input_report(handle, yie_buf, sizeof(yie_buf));
if (res < 0) {
printf("Unable to get a input report.\n");
printf("%ls", hid_error(handle));
} else {
// Print out the returned buffer.
printf("Input Report\n ");
printf("report number:%d\n ", yie_buf[0]);
for (i = 1; i < res; i++) {
printf("%02x ", yie_buf[i]);
}
printf("\n");
}

##������������������������make���������������������������������hidtest-libusb���

##���������������USB HID���������������hidtest-libusb������������������������

robin@NUC6CAYHC:~/luotest/hidapi$ sudo ./ hidtest-libusb
������
Manufacturer String: Robin
Product String: Robin's UEFI Explorer
Serial Number: (77) My123
Indexed String 1: Robin
Feature Report report number:0
a0 03 0b 0c 00 00 00 00 00 00 00 00 00 00 00 00
Input Report report number:0
a0 02 0b 0c 00 00 00 00 00 00 00 00 00 00 00 00
Read data,Length=16
a0 01 0b 0c 00 00 00 00 00 00 00 00 00 00 00 00

������������������USB HID������������������������������������������������������������������

������������������YIE002���������������������������������������������������������������������������������USB HID������������������������������Windows���������UEFI���������Linux������������������������������

YIE002���������������UEFI������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������

���������������������gitee.com/luobing4365/uefi-explorer

���������������������/90/hidlibusb���

上一篇:ubuntu16.04下系统配置
下一篇:UEFI开发探索89- YIE002USB开发板(12 Linux编程)

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年04月24日 04时30分00秒