serial: prepare for the absence of libserialport
Only reference the libserialport header when the library is available. Allow to always compile the serial.c source file, but optionally end up with an empty implementation. Make the sr_serial_dev_inst symbol available outside of HAVE_SERIAL_COMM such that empty stub code can compile. This prepares the introduction of alternative transports for serial communication, while all of them remain optional. The libsigrok serial layer internally uses parity and flow control symbols which are provided by libserialport. Optionally locally declare these symbols when libserialport is not available.
This commit is contained in:
parent
bb15350e59
commit
1ac8c2181b
|
@ -723,6 +723,7 @@ struct sr_usb_dev_inst {
|
|||
};
|
||||
#endif
|
||||
|
||||
struct sr_serial_dev_inst;
|
||||
#ifdef HAVE_SERIAL_COMM
|
||||
struct ser_lib_functions;
|
||||
struct sr_serial_dev_inst {
|
||||
|
@ -843,6 +844,30 @@ SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb);
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_SERIAL_COMM
|
||||
#ifndef HAVE_LIBSERIALPORT
|
||||
/*
|
||||
* Some identifiers which initially got provided by libserialport are
|
||||
* used internally within the libsigrok serial layer's implementation,
|
||||
* while libserialport no longer is the exclusive provider of serial
|
||||
* communication support. Declare the identifiers here so they remain
|
||||
* available across all build configurations.
|
||||
*/
|
||||
enum libsp_parity {
|
||||
SP_PARITY_NONE = 0,
|
||||
SP_PARITY_ODD = 1,
|
||||
SP_PARITY_EVEN = 2,
|
||||
SP_PARITY_MARK = 3,
|
||||
SP_PARITY_SPACE = 4,
|
||||
};
|
||||
|
||||
enum libsp_flowcontrol {
|
||||
SP_FLOWCONTROL_NONE = 0,
|
||||
SP_FLOWCONTROL_XONXOFF = 1,
|
||||
SP_FLOWCONTROL_RTSCTS = 2,
|
||||
SP_FLOWCONTROL_DTRDSR = 3,
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Serial-specific instances */
|
||||
SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
|
||||
const char *serialcomm);
|
||||
|
|
10
src/serial.c
10
src/serial.c
|
@ -25,7 +25,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#ifdef HAVE_LIBSERIALPORT
|
||||
#include <libserialport.h>
|
||||
#endif
|
||||
#include <libsigrok/libsigrok.h>
|
||||
#include "libsigrok-internal.h"
|
||||
#ifdef _WIN32
|
||||
|
@ -50,6 +52,8 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#ifdef HAVE_SERIAL_COMM
|
||||
|
||||
/* See if a (assumed opened) serial port is of any supported type. */
|
||||
static int dev_is_supported(struct sr_serial_dev_inst *serial)
|
||||
{
|
||||
|
@ -870,4 +874,10 @@ SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes)
|
|||
return timeout_ms;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* TODO Put fallback.c content here? */
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
Loading…
Reference in New Issue