42 hid_device *dev =
NULL;
44 struct hid_device_info *
devs, *cur_dev;
45 unsigned short target_vid, target_pid;
50 if (hid_init() != 0) {
60 devs = hid_enumerate(0x0, 0x0);
66 if (!cur_dev->product_string) {
67 LOG_DEBUG(
"Cannot read product string of device 0x%x:0x%x",
68 cur_dev->vendor_id, cur_dev->product_id);
69 }
else if (wcsstr(cur_dev->product_string, L
"CMSIS-DAP")) {
77 for (i = 0; vids[i] || pids[i]; i++) {
78 if ((vids[i] == cur_dev->vendor_id) && (pids[i] == cur_dev->product_id))
84 if (cur_dev->vendor_id == 0x1fc9 && cur_dev->product_id == 0x0090 && cur_dev->interface_number != 0)
92 if (cur_dev->serial_number) {
93 size_t len = (strlen(
serial) + 1) *
sizeof(
wchar_t);
94 wchar_t *wserial = malloc(len);
95 mbstowcs(wserial,
serial, len);
97 if (wcscmp(wserial, cur_dev->serial_number) == 0) {
107 cur_dev = cur_dev->next;
111 target_vid = cur_dev->vendor_id;
112 target_pid = cur_dev->product_id;
115 if (target_vid == 0 && target_pid == 0) {
116 hid_free_enumeration(
devs);
126 dev = hid_open_path(cur_dev->path);
127 hid_free_enumeration(
devs);
130 LOG_ERROR(
"unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
139 unsigned int packet_size = 64;
146 if (target_vid == 0x03eb && target_pid != 0x2145 && target_pid != 0x2175)
178 }
else if (retval == -1) {
208 uint8_t *buf = malloc(packet_buffer_size);
210 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 void cmsis_dap_hid_close(struct cmsis_dap *dap)
static int cmsis_dap_hid_read(struct cmsis_dap *dap, int timeout_ms)
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 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
struct cmsis_dap_backend_data * bdata
uint16_t packet_buffer_size