47 { .
vid = 0x03eb, .pid = 0x2140, .report_size = 512 },
49 { .vid = 0x03eb, .pid = 0x2141, .report_size = 512 },
51 { .vid = 0x03eb, .pid = 0x2144, .report_size = 512 },
53 { .vid = 0x03eb, .pid = 0x2111, .report_size = 512 },
55 { .vid = 0x03eb, .pid = 0x2157, .report_size = 512 },
57 { .vid = 0x03eb, .pid = 0x2169, .report_size = 512 },
59 { .vid = 0x03eb, .pid = 0x216a, .report_size = 512 },
61 { .vid = 0x03eb, .pid = 0x2170, .report_size = 512 },
63 { .vid = 0, .pid = 0, .report_size = 0 }
73 hid_device *dev =
NULL;
75 struct hid_device_info *
devs, *cur_dev;
76 unsigned short target_vid, target_pid;
81 if (hid_init() != 0) {
91 devs = hid_enumerate(0x0, 0x0);
97 if (!cur_dev->product_string) {
98 LOG_DEBUG(
"Cannot read product string of device 0x%x:0x%x",
99 cur_dev->vendor_id, cur_dev->product_id);
100 }
else if (wcsstr(cur_dev->product_string, L
"CMSIS-DAP")) {
108 for (i = 0; vids[i] || pids[i]; i++) {
109 if ((vids[i] == cur_dev->vendor_id) && (pids[i] == cur_dev->product_id))
115 if (cur_dev->vendor_id == 0x1fc9 && cur_dev->product_id == 0x0090 && cur_dev->interface_number != 0)
123 if (cur_dev->serial_number) {
125 wchar_t *wserial = malloc(len *
sizeof(
wchar_t));
127 LOG_ERROR(
"unable to allocate serial number buffer");
130 mbstowcs(wserial,
serial, len);
132 if (wcscmp(wserial, cur_dev->serial_number) == 0) {
142 cur_dev = cur_dev->next;
146 target_vid = cur_dev->vendor_id;
147 target_pid = cur_dev->product_id;
150 if (target_vid == 0 && target_pid == 0) {
151 hid_free_enumeration(
devs);
161 dev = hid_open_path(cur_dev->path);
162 hid_free_enumeration(
devs);
165 LOG_ERROR(
"unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
174 unsigned int packet_size = 64;
213 timeout_ms = wait_timeout->
tv_usec / 1000 + wait_timeout->
tv_sec * 1000;
215 timeout_ms = transfer_timeout_ms;
222 }
else if (retval == -1) {
252 uint8_t *buf = malloc(packet_buffer_size);
254 LOG_ERROR(
"unable to allocate CMSIS-DAP packet buffer");
static int cmsis_dap_hid_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], const char *serial)
static int cmsis_dap_hid_read(struct cmsis_dap *dap, int transfer_timeout_ms, struct timeval *wait_timeout)
static void cmsis_dap_hid_close(struct cmsis_dap *dap)
static void cmsis_dap_hid_cancel_all(struct cmsis_dap *dap)
static void cmsis_dap_hid_free(struct cmsis_dap *dap)
const struct cmsis_dap_backend cmsis_dap_hid_backend
static int cmsis_dap_hid_write(struct cmsis_dap *dap, int txlen, int timeout_ms)
static const struct cmsis_dap_report_size report_size_quirks[]
static struct libusb_device ** devs
The usb device list.
#define LOG_ERROR(expr ...)
#define ERROR_TIMEOUT_REACHED
#define LOG_DEBUG(expr ...)
struct libusb_device_handle * dev_handle
unsigned int packet_buffer_size
unsigned int packet_usable_size
struct cmsis_dap_backend_data * bdata