2 * This file is part of the libsigrok project.
4 * Copyright (C) 2019 Gerhard Sittig <gerhard.sittig@gmx.net>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * This implements serial communication primitives for the Brymen BU-86X
22 * infrared adapter for handheld multimeters. The vendor's protocol spec
23 * http://brymen.com/product-html/images/DownloadList/ProtocolList/BM860-BM860s_List/BM860-BM860s-500000-count-dual-display-DMMs-protocol.pdf
24 * suggests that HID reports get communicated, but only report number 0
25 * is involved, which carries a mere byte stream in 8 byte chunks each.
26 * The frame format and bitrate are fixed, and need not get configured.
28 * The meter's packet consists of 24 bytes which get received in three
29 * HID reports. Packet reception gets initiated by sending a short HID
30 * report to the meter. It's uncertain which parts of this exchange are
31 * specific to the adapter and to the meter. Using the IR adapter with
32 * other devices, or using the meter with other cables/adapters may need
33 * a little more adjustment with respect to layering.
38 #include <libsigrok/libsigrok.h>
39 #include "libsigrok-internal.h"
40 #include "serial_hid.h"
44 #define LOG_PREFIX "serial-bu86x"
47 #ifdef HAVE_SERIAL_COMM
53 * Support serial-over-HID, specifically the Brymen BU-86X infrared adapter.
56 #define BU86X_MAX_BYTES_PER_REQUEST 8
58 static const struct vid_pid_item vid_pid_items_bu86x[] = {
63 static int bu86x_read_bytes(struct sr_serial_dev_inst *serial,
64 uint8_t *data, int space, unsigned int timeout)
68 if (space > BU86X_MAX_BYTES_PER_REQUEST)
69 space = BU86X_MAX_BYTES_PER_REQUEST;
70 rc = ser_hid_hidapi_get_data(serial, 0, data, space, timeout);
71 if (rc == SR_ERR_TIMEOUT)
80 static int bu86x_write_bytes(struct sr_serial_dev_inst *serial,
81 const uint8_t *data, int size)
83 return ser_hid_hidapi_set_data(serial, 0, data, size, 0);
86 static struct ser_hid_chip_functions chip_bu86x = {
88 .chipdesc = "Brymen BU-86X",
89 .vid_pid_items = vid_pid_items_bu86x,
90 .max_bytes_per_request = BU86X_MAX_BYTES_PER_REQUEST,
92 * The IR adapter's communication parameters are fixed and need
93 * not get configured. Just silently ignore the caller's spec.
95 .set_params = std_dummy_set_params,
96 .read_bytes = bu86x_read_bytes,
97 .write_bytes = bu86x_write_bytes,
99 SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = &chip_bu86x;
103 SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x = NULL;