Stefan Reinauer | c566d20 | 2015-08-25 09:52:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012-2015 Google Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Stefan Reinauer | c566d20 | 2015-08-25 09:52:42 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <stdio.h> |
| 15 | #include "em100.h" |
| 16 | |
| 17 | /* USB communication */ |
| 18 | |
| 19 | int send_cmd(libusb_device_handle *dev, void *data) |
| 20 | { |
| 21 | int actual; |
| 22 | int length = 16; /* haven't seen any other length yet */ |
Stefan Reinauer | 64df047 | 2020-11-18 21:13:49 -0800 | [diff] [blame] | 23 | int ret = libusb_bulk_transfer(dev, 1 | LIBUSB_ENDPOINT_OUT, |
Stefan Reinauer | 7265d5a | 2015-08-25 11:06:58 -0700 | [diff] [blame] | 24 | data, length, &actual, BULK_SEND_TIMEOUT); |
Stefan Reinauer | 64df047 | 2020-11-18 21:13:49 -0800 | [diff] [blame] | 25 | if (LIBUSB_SUCCESS != ret) |
| 26 | printf("ERROR: USB: %s: %s\n", __func__, libusb_strerror(ret)); |
Stefan Reinauer | c566d20 | 2015-08-25 09:52:42 -0700 | [diff] [blame] | 27 | return (actual == length); |
| 28 | } |
| 29 | |
| 30 | int get_response(libusb_device_handle *dev, void *data, int length) |
| 31 | { |
| 32 | int actual; |
Stefan Reinauer | 64df047 | 2020-11-18 21:13:49 -0800 | [diff] [blame] | 33 | int ret = libusb_bulk_transfer(dev, 2 | LIBUSB_ENDPOINT_IN, |
Stefan Reinauer | 7265d5a | 2015-08-25 11:06:58 -0700 | [diff] [blame] | 34 | data, length, &actual, BULK_SEND_TIMEOUT); |
Stefan Reinauer | 64df047 | 2020-11-18 21:13:49 -0800 | [diff] [blame] | 35 | if (LIBUSB_SUCCESS != ret) |
| 36 | printf("ERROR: USB: %s: %s\n", __func__, libusb_strerror(ret)); |
Stefan Reinauer | c566d20 | 2015-08-25 09:52:42 -0700 | [diff] [blame] | 37 | return actual; |
| 38 | } |
| 39 | |
| 40 | |