]> sigrok.org Git - libsigrok.git/blobdiff - src/libsigrok-internal.h
serial: prepare serial over HID in common layer and build support
[libsigrok.git] / src / libsigrok-internal.h
index 3ea3590ae6c5dec04ddd2e5d075f43d94f3182f5..48e89acd8e7609418eef230a9fef647a5b0febe9 100644 (file)
@@ -29,6 +29,9 @@
 #include "config.h"
 
 #include <glib.h>
+#ifdef HAVE_LIBHIDAPI
+#include <hidapi.h>
+#endif
 #ifdef HAVE_LIBSERIALPORT
 #include <libserialport.h>
 #endif
@@ -36,6 +39,7 @@
 #include <libusb.h>
 #endif
 #include <stdarg.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -723,6 +727,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 {
@@ -737,10 +742,15 @@ struct sr_serial_dev_inst {
                int parity_bits;
                int stop_bits;
        } comm_params;
+       GString *rcv_buffer;
 #ifdef HAVE_LIBSERIALPORT
        /** libserialport port handle */
        struct sp_port *sp_data;
 #endif
+#ifdef HAVE_LIBHIDAPI
+       /* TODO */
+       hid_device *hid_dev;
+#endif
 };
 #endif
 
@@ -843,6 +853,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);
@@ -1115,6 +1149,13 @@ SR_PRIV int serial_source_remove(struct sr_session *session,
 SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
 SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes);
 
+SR_PRIV void sr_ser_discard_queued_data(struct sr_serial_dev_inst *serial);
+SR_PRIV size_t sr_ser_has_queued_data(struct sr_serial_dev_inst *serial);
+SR_PRIV void sr_ser_queue_rx_data(struct sr_serial_dev_inst *serial,
+               const uint8_t *data, size_t len);
+SR_PRIV size_t sr_ser_unqueue_rx_data(struct sr_serial_dev_inst *serial,
+               uint8_t *data, size_t len);
+
 struct ser_lib_functions {
        int (*open)(struct sr_serial_dev_inst *serial, int flags);
        int (*close)(struct sr_serial_dev_inst *serial);
@@ -1143,6 +1184,8 @@ struct ser_lib_functions {
        size_t (*get_rx_avail)(struct sr_serial_dev_inst *serial);
 };
 extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_libsp;
+SR_PRIV int ser_name_is_hid(struct sr_serial_dev_inst *serial);
+extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_hid;
 #endif
 
 /*--- ezusb.c ---------------------------------------------------------------*/