blob: 4fd3df5c8b55471619d662364856df44c7edf35c [file] [log] [blame]
Stefan Reinauerc566d202015-08-25 09:52:42 -07001/*
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 Reinauerc566d202015-08-25 09:52:42 -070012 */
13
14#include <stdio.h>
15#include "em100.h"
16
17/* USB communication */
18
19int send_cmd(libusb_device_handle *dev, void *data)
20{
21 int actual;
22 int length = 16; /* haven't seen any other length yet */
Stefan Reinauer64df0472020-11-18 21:13:49 -080023 int ret = libusb_bulk_transfer(dev, 1 | LIBUSB_ENDPOINT_OUT,
Stefan Reinauer7265d5a2015-08-25 11:06:58 -070024 data, length, &actual, BULK_SEND_TIMEOUT);
Stefan Reinauer64df0472020-11-18 21:13:49 -080025 if (LIBUSB_SUCCESS != ret)
26 printf("ERROR: USB: %s: %s\n", __func__, libusb_strerror(ret));
Stefan Reinauerc566d202015-08-25 09:52:42 -070027 return (actual == length);
28}
29
30int get_response(libusb_device_handle *dev, void *data, int length)
31{
32 int actual;
Stefan Reinauer64df0472020-11-18 21:13:49 -080033 int ret = libusb_bulk_transfer(dev, 2 | LIBUSB_ENDPOINT_IN,
Stefan Reinauer7265d5a2015-08-25 11:06:58 -070034 data, length, &actual, BULK_SEND_TIMEOUT);
Stefan Reinauer64df0472020-11-18 21:13:49 -080035 if (LIBUSB_SUCCESS != ret)
36 printf("ERROR: USB: %s: %s\n", __func__, libusb_strerror(ret));
Stefan Reinauerc566d202015-08-25 09:52:42 -070037 return actual;
38}
39
40