serial_hid: implement serial over HID transport
Do implement the transport methods for serial communication underneath the common layer, by communicating HID requests and payload data by means of HIDAPI library calls. This commit adds the common logic of serial-over-HID communication and implements the full internal serial transport API, including reception in the background. But it does not yet support a single HID chip (which each run their own proprietary protocol). The implementation works with either hidapi-libusb or hidapi-hidraw variant of the HIDAPI library, but was only tested on Linux.
This commit is contained in:
parent
4417074c68
commit
edec0436db
|
@ -730,6 +730,7 @@ struct sr_usb_dev_inst {
|
||||||
struct sr_serial_dev_inst;
|
struct sr_serial_dev_inst;
|
||||||
#ifdef HAVE_SERIAL_COMM
|
#ifdef HAVE_SERIAL_COMM
|
||||||
struct ser_lib_functions;
|
struct ser_lib_functions;
|
||||||
|
struct ser_hid_chip_functions;
|
||||||
struct sr_serial_dev_inst {
|
struct sr_serial_dev_inst {
|
||||||
/** Port name, e.g. '/dev/tty42'. */
|
/** Port name, e.g. '/dev/tty42'. */
|
||||||
char *port;
|
char *port;
|
||||||
|
@ -748,8 +749,16 @@ struct sr_serial_dev_inst {
|
||||||
struct sp_port *sp_data;
|
struct sp_port *sp_data;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBHIDAPI
|
#ifdef HAVE_LIBHIDAPI
|
||||||
/* TODO */
|
enum ser_hid_chip_t {
|
||||||
|
SER_HID_CHIP_UNKNOWN, /**!< place holder */
|
||||||
|
SER_HID_CHIP_LAST, /**!< sentinel */
|
||||||
|
} hid_chip;
|
||||||
|
struct ser_hid_chip_functions *hid_chip_funcs;
|
||||||
|
char *usb_path;
|
||||||
|
char *usb_serno;
|
||||||
|
const char *hid_path;
|
||||||
hid_device *hid_dev;
|
hid_device *hid_dev;
|
||||||
|
GSList *hid_source_args;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -1186,6 +1195,30 @@ struct ser_lib_functions {
|
||||||
extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_libsp;
|
extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_libsp;
|
||||||
SR_PRIV int ser_name_is_hid(struct sr_serial_dev_inst *serial);
|
SR_PRIV int ser_name_is_hid(struct sr_serial_dev_inst *serial);
|
||||||
extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_hid;
|
extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_hid;
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBHIDAPI
|
||||||
|
struct vid_pid_item {
|
||||||
|
uint16_t vid, pid;
|
||||||
|
};
|
||||||
|
#define VID_PID_TERM ALL_ZERO
|
||||||
|
|
||||||
|
struct ser_hid_chip_functions {
|
||||||
|
const char *chipname;
|
||||||
|
const char *chipdesc;
|
||||||
|
const struct vid_pid_item *vid_pid_items;
|
||||||
|
const int max_bytes_per_request;
|
||||||
|
int (*set_params)(struct sr_serial_dev_inst *serial,
|
||||||
|
int baudrate, int bits, int parity, int stopbits,
|
||||||
|
int flowcontrol, int rts, int dtr);
|
||||||
|
int (*read_bytes)(struct sr_serial_dev_inst *serial,
|
||||||
|
uint8_t *data, int space, unsigned int timeout);
|
||||||
|
int (*write_bytes)(struct sr_serial_dev_inst *serial,
|
||||||
|
const uint8_t *data, int space);
|
||||||
|
int (*flush)(struct sr_serial_dev_inst *serial);
|
||||||
|
int (*drain)(struct sr_serial_dev_inst *serial);
|
||||||
|
};
|
||||||
|
SR_PRIV const char *ser_hid_chip_find_name_vid_pid(uint16_t vid, uint16_t pid);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*--- ezusb.c ---------------------------------------------------------------*/
|
/*--- ezusb.c ---------------------------------------------------------------*/
|
||||||
|
|
1386
src/serial_hid.c
1386
src/serial_hid.c
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the libsigrok project.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017-2019 Gerhard Sittig <gerhard.sittig@gmx.net>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SERIAL_HID_H
|
||||||
|
#define SERIAL_HID_H
|
||||||
|
|
||||||
|
/* The prefix for port names which are HID based. */
|
||||||
|
#define SER_HID_CONN_PREFIX "hid"
|
||||||
|
#define SER_HID_USB_PREFIX "usb="
|
||||||
|
#define SER_HID_RAW_PREFIX "raw="
|
||||||
|
#define SER_HID_SNR_PREFIX "sn="
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The maximum number of bytes any supported HID chip can communicate
|
||||||
|
* within a single request.
|
||||||
|
*
|
||||||
|
* CP2110: up to 63bytes
|
||||||
|
* CH9325: up to 7 bytes
|
||||||
|
*/
|
||||||
|
#define SER_HID_CHUNK_SIZE 64
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Routines to get/set reports/data, provided by serial_hid.c and used
|
||||||
|
* in serial_hid_<chip>.c files.
|
||||||
|
*/
|
||||||
|
SR_PRIV int ser_hid_hidapi_get_report(struct sr_serial_dev_inst *serial,
|
||||||
|
uint8_t *data, size_t len);
|
||||||
|
SR_PRIV int ser_hid_hidapi_set_report(struct sr_serial_dev_inst *serial,
|
||||||
|
const uint8_t *data, size_t len);
|
||||||
|
SR_PRIV int ser_hid_hidapi_get_data(struct sr_serial_dev_inst *serial,
|
||||||
|
uint8_t ep, uint8_t *data, size_t len, int timeout);
|
||||||
|
SR_PRIV int ser_hid_hidapi_set_data(struct sr_serial_dev_inst *serial,
|
||||||
|
uint8_t ep, const uint8_t *data, size_t len, int timeout);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue