2 * This file is part of the libsigrok project.
4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
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/>.
20 #ifndef LIBSIGROK_LIBSIGROK_H
21 #define LIBSIGROK_LIBSIGROK_H
36 * The public libsigrok header file to be used by frontends.
38 * This is the only file that libsigrok users (frontends) are supposed to
39 * use and \#include. There are other header files which get installed with
40 * libsigrok, but those are not meant to be used directly by frontends.
42 * The correct way to get/use the libsigrok API functions is:
45 * #include <libsigrok/libsigrok.h>
50 * All possible return codes of libsigrok functions must be listed here.
51 * Functions should never return hardcoded numbers as status, but rather
52 * use these enum values. All error codes are negative numbers.
54 * The error codes are globally unique in libsigrok, i.e. if one of the
55 * libsigrok functions returns a "malloc error" it must be exactly the same
56 * return value as used by all other functions to indicate "malloc error".
57 * There must be no functions which indicate two different errors via the
60 * Also, for compatibility reasons, no defined return codes are ever removed
61 * or reused for different errors later. You can only add new entries and
62 * return codes, but never remove or redefine existing ones.
65 /** Status/error codes returned by libsigrok functions. */
67 SR_OK_CONTINUE = 1, /**< Keep going. */
68 SR_OK = 0, /**< No error. */
69 SR_ERR = -1, /**< Generic/unspecified error. */
70 SR_ERR_MALLOC = -2, /**< Malloc/calloc/realloc error. */
71 SR_ERR_ARG = -3, /**< Function argument error. */
72 SR_ERR_BUG = -4, /**< Errors hinting at internal bugs. */
73 SR_ERR_SAMPLERATE = -5, /**< Incorrect samplerate. */
74 SR_ERR_NA = -6, /**< Not applicable. */
75 SR_ERR_DEV_CLOSED = -7, /**< Device is closed, but must be open. */
76 SR_ERR_TIMEOUT = -8, /**< A timeout occurred. */
77 SR_ERR_CHANNEL_GROUP = -9, /**< A channel group must be specified. */
78 SR_ERR_DATA =-10, /**< Data is invalid. */
79 SR_ERR_IO =-11, /**< Input/output error. */
82 * Note: When adding entries here, don't forget to also update the
83 * sr_strerror() and sr_strerror_name() functions in error.c.
87 #define SR_MAX_CHANNELNAME_LEN 32
89 /* Handy little macros */
91 #define SR_KHZ(n) ((n) * (uint64_t)(1000ULL))
92 #define SR_MHZ(n) ((n) * (uint64_t)(1000000ULL))
93 #define SR_GHZ(n) ((n) * (uint64_t)(1000000000ULL))
95 #define SR_HZ_TO_NS(n) ((uint64_t)(1000000000ULL) / (n))
97 /** libsigrok loglevels. */
99 SR_LOG_NONE = 0, /**< Output no messages at all. */
100 SR_LOG_ERR = 1, /**< Output error messages. */
101 SR_LOG_WARN = 2, /**< Output warnings. */
102 SR_LOG_INFO = 3, /**< Output informational messages. */
103 SR_LOG_DBG = 4, /**< Output debug messages. */
104 SR_LOG_SPEW = 5, /**< Output very noisy debug messages. */
108 * Use SR_API to mark public API symbols, and SR_PRIV for private symbols.
110 * Variables and functions marked 'static' are private already and don't
111 * need SR_PRIV. However, functions which are not static (because they need
112 * to be used in other libsigrok-internal files) but are also not meant to
113 * be part of the public libsigrok API, must use SR_PRIV.
115 * This uses the 'visibility' feature of gcc (requires gcc >= 4.0).
117 * This feature is not available on MinGW/Windows, as it is a feature of
118 * ELF files and MinGW/Windows uses PE files.
120 * Details: http://gcc.gnu.org/wiki/Visibility
123 /* Marks public libsigrok API symbols. */
125 #define SR_API __attribute__((visibility("default")))
130 /* Marks private, non-public libsigrok symbols (not part of the API). */
132 #define SR_PRIV __attribute__((visibility("hidden")))
137 /** Type definition for callback function for data reception. */
138 typedef int (*sr_receive_data_callback)(int fd, int revents, void *cb_data);
140 /** Data types used by sr_config_info(). */
146 SR_T_RATIONAL_PERIOD,
154 /** Value for sr_datafeed_packet.type. */
156 /** Payload is sr_datafeed_header. */
157 SR_DF_HEADER = 10000,
158 /** End of stream (no further data). */
160 /** Payload is struct sr_datafeed_meta */
162 /** The trigger matched at this point in the data feed. No payload. */
164 /** Payload is struct sr_datafeed_logic. */
166 /** Payload is struct sr_datafeed_analog. */
168 /** Beginning of frame. No payload. */
170 /** End of frame. No payload. */
172 /** Payload is struct sr_datafeed_analog2. */
176 /** Measured quantity, sr_datafeed_analog.mq. */
178 SR_MQ_VOLTAGE = 10000,
184 /** Duty cycle, e.g. on/off ratio. */
186 /** Continuity test. */
190 /** Electrical power, usually in W, or dBm. */
192 /** Gain (a transistor's gain, or hFE, for example). */
194 /** Logarithmic representation of sound pressure relative to a
195 * reference value. */
196 SR_MQ_SOUND_PRESSURE_LEVEL,
197 /** Carbon monoxide level */
198 SR_MQ_CARBON_MONOXIDE,
200 SR_MQ_RELATIVE_HUMIDITY,
207 /** Parallel inductance (LCR meter model). */
208 SR_MQ_PARALLEL_INDUCTANCE,
209 /** Parallel capacitance (LCR meter model). */
210 SR_MQ_PARALLEL_CAPACITANCE,
211 /** Parallel resistance (LCR meter model). */
212 SR_MQ_PARALLEL_RESISTANCE,
213 /** Series inductance (LCR meter model). */
214 SR_MQ_SERIES_INDUCTANCE,
215 /** Series capacitance (LCR meter model). */
216 SR_MQ_SERIES_CAPACITANCE,
217 /** Series resistance (LCR meter model). */
218 SR_MQ_SERIES_RESISTANCE,
219 /** Dissipation factor. */
220 SR_MQ_DISSIPATION_FACTOR,
221 /** Quality factor. */
222 SR_MQ_QUALITY_FACTOR,
225 /** Difference from reference value. */
229 /** Unit of measured quantity, sr_datafeed_analog.unit. */
232 SR_UNIT_VOLT = 10000,
233 /** Ampere (current). */
235 /** Ohm (resistance). */
237 /** Farad (capacity). */
239 /** Kelvin (temperature). */
241 /** Degrees Celsius (temperature). */
243 /** Degrees Fahrenheit (temperature). */
245 /** Hertz (frequency, 1/s, [Hz]). */
247 /** Percent value. */
249 /** Boolean value. */
251 /** Time in seconds. */
253 /** Unit of conductance, the inverse of resistance. */
256 * An absolute measurement of power, in decibels, referenced to
260 /** Voltage in decibel, referenced to 1 volt (dBV). */
261 SR_UNIT_DECIBEL_VOLT,
263 * Measurements that intrinsically do not have units attached, such
264 * as ratios, gains, etc. Specifically, a transistor's gain (hFE) is
265 * a unitless quantity, for example.
268 /** Sound pressure level, in decibels, relative to 20 micropascals. */
271 * Normalized (0 to 1) concentration of a substance or compound with 0
272 * representing a concentration of 0%, and 1 being 100%. This is
273 * represented as the fraction of number of particles of the substance.
275 SR_UNIT_CONCENTRATION,
276 /** Revolutions per minute. */
277 SR_UNIT_REVOLUTIONS_PER_MINUTE,
278 /** Apparent power [VA]. */
280 /** Real power [W]. */
282 /** Consumption [Wh]. */
284 /** Wind speed in meters per second. */
285 SR_UNIT_METER_SECOND,
286 /** Pressure in hectopascal */
288 /** Relative humidity assuming air temperature of 293 kelvin (%rF). */
289 SR_UNIT_HUMIDITY_293K,
290 /** Plane angle in 1/360th of a full circle. */
292 /** Henry (inductance). */
296 /** Values for sr_datafeed_analog.flags. */
298 /** Voltage measurement is alternating current (AC). */
300 /** Voltage measurement is direct current (DC). */
302 /** This is a true RMS measurement. */
303 SR_MQFLAG_RMS = 0x04,
304 /** Value is voltage drop across a diode, or NAN. */
305 SR_MQFLAG_DIODE = 0x08,
306 /** Device is in "hold" mode (repeating the last measurement). */
307 SR_MQFLAG_HOLD = 0x10,
308 /** Device is in "max" mode, only updating upon a new max value. */
309 SR_MQFLAG_MAX = 0x20,
310 /** Device is in "min" mode, only updating upon a new min value. */
311 SR_MQFLAG_MIN = 0x40,
312 /** Device is in autoranging mode. */
313 SR_MQFLAG_AUTORANGE = 0x80,
314 /** Device is in relative mode. */
315 SR_MQFLAG_RELATIVE = 0x100,
316 /** Sound pressure level is A-weighted in the frequency domain,
317 * according to IEC 61672:2003. */
318 SR_MQFLAG_SPL_FREQ_WEIGHT_A = 0x200,
319 /** Sound pressure level is C-weighted in the frequency domain,
320 * according to IEC 61672:2003. */
321 SR_MQFLAG_SPL_FREQ_WEIGHT_C = 0x400,
322 /** Sound pressure level is Z-weighted (i.e. not at all) in the
323 * frequency domain, according to IEC 61672:2003. */
324 SR_MQFLAG_SPL_FREQ_WEIGHT_Z = 0x800,
325 /** Sound pressure level is not weighted in the frequency domain,
326 * albeit without standards-defined low and high frequency limits. */
327 SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT = 0x1000,
328 /** Sound pressure level measurement is S-weighted (1s) in the
330 SR_MQFLAG_SPL_TIME_WEIGHT_S = 0x2000,
331 /** Sound pressure level measurement is F-weighted (125ms) in the
333 SR_MQFLAG_SPL_TIME_WEIGHT_F = 0x4000,
334 /** Sound pressure level is time-averaged (LAT), also known as
335 * Equivalent Continuous A-weighted Sound Level (LEQ). */
336 SR_MQFLAG_SPL_LAT = 0x8000,
337 /** Sound pressure level represented as a percentage of measurements
338 * that were over a preset alarm level. */
339 SR_MQFLAG_SPL_PCT_OVER_ALARM = 0x10000,
340 /** Time is duration (as opposed to epoch, ...). */
341 SR_MQFLAG_DURATION = 0x20000,
342 /** Device is in "avg" mode, averaging upon each new value. */
343 SR_MQFLAG_AVG = 0x40000,
344 /** Reference value shown. */
345 SR_MQFLAG_REFERENCE = 0x80000,
348 enum sr_trigger_matches {
358 /** The representation of a trigger, consisting of one or more stages
359 * containing one or more matches on a channel.
362 /** A name for this trigger. This may be NULL if none is needed. */
364 /** List of pointers to struct sr_trigger_stage. */
368 /** A trigger stage. */
369 struct sr_trigger_stage {
372 /** List of pointers to struct sr_trigger_match. */
376 /** A channel to match and what to match it on. */
377 struct sr_trigger_match {
378 /** The channel to trigger on. */
379 struct sr_channel *channel;
380 /** The trigger match to use.
381 * For logic channels, only the following matches may be used:
388 * For analog channels, only these matches may be used:
396 /** If the trigger match is one of SR_TRIGGER_OVER or SR_TRIGGER_UNDER,
397 * this contains the value to compare against. */
403 * Opaque structure representing a libsigrok context.
405 * None of the fields of this structure are meant to be accessed directly.
407 * @see sr_init(), sr_exit().
413 * Opaque structure representing a libsigrok session.
415 * None of the fields of this structure are meant to be accessed directly.
417 * @see sr_session_new(), sr_session_destroy().
422 /** Numerator of the rational number. */
424 /** Denominator of the rational number. */
428 /** Packet in a sigrok data feed. */
429 struct sr_datafeed_packet {
434 /** Header of a sigrok data feed. */
435 struct sr_datafeed_header {
437 struct timeval starttime;
440 /** Datafeed payload for type SR_DF_META. */
441 struct sr_datafeed_meta {
445 /** Logic datafeed payload for type SR_DF_LOGIC. */
446 struct sr_datafeed_logic {
452 /** Analog datafeed payload for type SR_DF_ANALOG. */
453 struct sr_datafeed_analog {
454 /** The channels for which data is included in this packet. */
456 /** Number of samples in data */
458 /** Measured quantity (voltage, current, temperature, and so on).
459 * Use SR_MQ_VOLTAGE, ... */
461 /** Unit in which the MQ is measured. Use SR_UNIT_VOLT, ... */
463 /** Bitmap with extra information about the MQ. Use SR_MQFLAG_AC, ... */
465 /** The analog value(s). The data is interleaved according to
466 * the channels list. */
470 /** Analog datafeed payload for type SR_DF_ANALOG2. */
471 struct sr_datafeed_analog2 {
473 uint32_t num_samples;
474 struct sr_analog_encoding *encoding;
475 struct sr_analog_meaning *meaning;
476 struct sr_analog_spec *spec;
479 struct sr_analog_encoding {
483 gboolean is_bigendian;
485 gboolean is_digits_decimal;
486 struct sr_rational scale;
487 struct sr_rational offset;
490 struct sr_analog_meaning {
493 enum sr_mqflag mqflags;
497 struct sr_analog_spec {
501 /** Generic option struct used by various subsystems. */
503 /* Short name suitable for commandline usage, [a-z0-9-]. */
505 /* Short name suitable for GUI usage, can contain UTF-8. */
507 /* Description of the option, in a sentence. */
509 /* Default value for this option. */
511 /* List of possible values, if this is an option with few values. */
516 struct sr_input_module;
518 struct sr_output_module;
520 struct sr_transform_module;
522 /** Constants for channel type. */
523 enum sr_channeltype {
524 /** Channel type is logic channel. */
525 SR_CHANNEL_LOGIC = 10000,
526 /** Channel type is analog channel. */
530 /** Information on single channel. */
532 /** The index of this channel, starting at 0. Logic channels will
533 * be encoded according to this index in SR_DF_LOGIC packets. */
535 /** Channel type (SR_CHANNEL_LOGIC, ...) */
537 /** Is this channel enabled? */
539 /** Name of channel. */
541 /** Private data for driver use. */
545 /** Structure for groups of channels that have common properties. */
546 struct sr_channel_group {
547 /** Name of the channel group. */
549 /** List of sr_channel structs of the channels belonging to this group. */
551 /** Private data for driver use. */
555 /** Used for setting or getting value of a config item. */
557 /** Config key like SR_CONF_CONN, etc. */
559 /** Key-specific data. */
563 /** Information about a config key. */
564 struct sr_config_info {
565 /** Config key like SR_CONF_CONN, etc. */
567 /** Data type like SR_T_STRING, etc. */
569 /** Id string, e.g. "serialcomm". */
571 /** Name, e.g. "Serial communication". */
573 /** Verbose description (unused currently). */
577 #define SR_CONF_GET (1 << 31)
578 #define SR_CONF_SET (1 << 30)
579 #define SR_CONF_LIST (1 << 29)
580 #define SR_CONF_MASK 0x1fffffff
582 /** Configuration keys */
584 /*--- Device classes ------------------------------------------------*/
586 /** The device can act as logic analyzer. */
587 SR_CONF_LOGIC_ANALYZER = 10000,
589 /** The device can act as an oscilloscope. */
590 SR_CONF_OSCILLOSCOPE,
592 /** The device can act as a multimeter. */
595 /** The device is a demo device. */
598 /** The device can act as a sound level meter. */
599 SR_CONF_SOUNDLEVELMETER,
601 /** The device can measure temperature. */
604 /** The device can measure humidity. */
607 /** The device can measure energy consumption. */
610 /** The device can act as a signal demodulator. */
613 /** The device can act as a programmable power supply. */
614 SR_CONF_POWER_SUPPLY,
616 /** The device can act as an LCR meter. */
619 /*--- Driver scan options -------------------------------------------*/
622 * Specification on how to connect to a device.
624 * In combination with SR_CONF_SERIALCOMM, this is a serial port in
625 * the form which makes sense to the OS (e.g., /dev/ttyS0).
626 * Otherwise this specifies a USB device, either in the form of
627 * @verbatim <bus>.<address> @endverbatim (decimal, e.g. 1.65) or
628 * @verbatim <vendorid>.<productid> @endverbatim
629 * (hexadecimal, e.g. 1d6b.0001).
631 SR_CONF_CONN = 20000,
634 * Serial communication specification, in the form:
636 * @verbatim <baudrate>/<databits><parity><stopbits> @endverbatim
640 * The string may also be followed by one or more special settings,
641 * in the form "/key=value". Supported keys and their values are:
643 * rts 0,1 set the port's RTS pin to low or high
644 * dtr 0,1 set the port's DTR pin to low or high
645 * flow 0 no flow control
646 * 1 hardware-based (RTS/CTS) flow control
647 * 2 software-based (XON/XOFF) flow control
649 * This is always an optional parameter, since a driver typically
650 * knows the speed at which the device wants to communicate.
654 /*--- Device (or channel group) configuration -----------------------*/
656 /** The device supports setting its samplerate, in Hz. */
657 SR_CONF_SAMPLERATE = 30000,
659 /** The device supports setting a pre/post-trigger capture ratio. */
660 SR_CONF_CAPTURE_RATIO,
662 /** The device supports setting a pattern (pattern generator mode). */
663 SR_CONF_PATTERN_MODE,
665 /** The device supports run-length encoding (RLE). */
668 /** The device supports setting trigger slope. */
669 SR_CONF_TRIGGER_SLOPE,
671 /** The device supports averaging. */
675 * The device supports setting number of samples to be
680 /** Trigger source. */
681 SR_CONF_TRIGGER_SOURCE,
683 /** Horizontal trigger position. */
684 SR_CONF_HORIZ_TRIGGERPOS,
701 /** Trigger matches. */
702 SR_CONF_TRIGGER_MATCH,
704 /** The device supports setting its sample interval, in ms. */
705 SR_CONF_SAMPLE_INTERVAL,
707 /** Number of timebases, as related to SR_CONF_TIMEBASE. */
708 SR_CONF_NUM_TIMEBASE,
710 /** Number of vertical divisions, as related to SR_CONF_VDIV. */
713 /** Sound pressure level frequency weighting. */
714 SR_CONF_SPL_WEIGHT_FREQ,
716 /** Sound pressure level time weighting. */
717 SR_CONF_SPL_WEIGHT_TIME,
719 /** Sound pressure level measurement range. */
720 SR_CONF_SPL_MEASUREMENT_RANGE,
722 /** Max hold mode. */
725 /** Min hold mode. */
728 /** Logic low-high threshold range. */
729 SR_CONF_VOLTAGE_THRESHOLD,
731 /** The device supports using an external clock. */
732 SR_CONF_EXTERNAL_CLOCK,
735 * The device supports swapping channels. Typical this is between
736 * buffered and unbuffered channels.
740 /** Center frequency.
741 * The input signal is downmixed by this frequency before the ADC
742 * anti-aliasing filter.
744 SR_CONF_CENTER_FREQUENCY,
746 /** The device supports setting the number of logic channels. */
747 SR_CONF_NUM_LOGIC_CHANNELS,
749 /** The device supports setting the number of analog channels. */
750 SR_CONF_NUM_ANALOG_CHANNELS,
755 * @arg get: get measured output voltage
757 SR_CONF_OUTPUT_VOLTAGE,
760 * Maximum output voltage target.
762 * @arg get: get output voltage target
763 * @arg set: change output voltage target
765 SR_CONF_OUTPUT_VOLTAGE_TARGET,
770 * @arg get: get measured output current
772 SR_CONF_OUTPUT_CURRENT,
775 * Output current limit.
777 * @arg get: get output current limit
778 * @arg set: change output current limit
780 SR_CONF_OUTPUT_CURRENT_LIMIT,
783 * Enabling/disabling output.
785 * @arg get: @b true if currently enabled
786 * @arg set: enable/disable
788 SR_CONF_OUTPUT_ENABLED,
791 * Output channel configuration.
793 * @arg get: get current setting
794 * @arg set: change current setting
795 * @arg list: array of possible values
797 SR_CONF_OUTPUT_CHANNEL_CONFIG,
800 * Over-voltage protection (OVP) feature
802 * @arg get: @b true if currently enabled
803 * @arg set: enable/disable
805 SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED,
808 * Over-voltage protection (OVP) active
810 * @arg get: @b true if device has activated OVP, i.e. the output voltage
811 * exceeds the over-voltage protection threshold.
813 SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE,
816 * Over-voltage protection (OVP) threshold
817 * @arg type: double (voltage)
818 * @arg get: get current threshold
819 * @arg set: set new threshold
821 SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD,
824 * Over-current protection (OCP) feature
826 * @arg get: @b true if currently enabled
827 * @arg set: enable/disable
829 SR_CONF_OVER_CURRENT_PROTECTION_ENABLED,
832 * Over-current protection (OCP) active
834 * @arg get: @b true if device has activated OCP, i.e. the output current
835 * exceeds the over-current protection threshold.
837 SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE,
840 * Over-current protection (OCP) threshold
841 * @arg type: double (current)
842 * @arg get: get current threshold
843 * @arg set: set new threshold
845 SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD,
847 /** Choice of clock edge for external clock ("r" or "f"). */
850 /** Amplitude of a source without strictly-defined MQ. */
854 * Output channel regulation
855 * get: "CV", "CC" or "UR", denoting constant voltage, constant current
858 SR_CONF_OUTPUT_REGULATION,
860 /** Over-temperature protection (OTP) */
861 SR_CONF_OVER_TEMPERATURE_PROTECTION,
863 /** Output frequency in Hz. */
864 SR_CONF_OUTPUT_FREQUENCY,
866 /** Measured quantity. */
867 SR_CONF_MEASURED_QUANTITY,
869 /** Measured secondary quantity. */
870 SR_CONF_MEASURED_2ND_QUANTITY,
872 /** Equivalent circuit model. */
873 SR_CONF_EQUIV_CIRCUIT_MODEL,
875 /*--- Special stuff -------------------------------------------------*/
877 /** Scan options supported by the driver. */
878 SR_CONF_SCAN_OPTIONS = 40000,
880 /** Device options for a particular device. */
881 SR_CONF_DEVICE_OPTIONS,
883 /** Session filename. */
886 /** The device supports specifying a capturefile to inject. */
889 /** The device supports specifying the capturefile unit size. */
890 SR_CONF_CAPTURE_UNITSIZE,
892 /** Power off the device. */
896 * Data source for acquisition. If not present, acquisition from
897 * the device is always "live", i.e. acquisition starts when the
898 * frontend asks and the results are sent out as soon as possible.
900 * If present, it indicates that either the device has no live
901 * acquisition capability (for example a pure data logger), or
902 * there is a choice. sr_config_list() returns those choices.
904 * In any case if a device has live acquisition capabilities, it
905 * is always the default.
909 /** The device supports setting a probe factor. */
910 SR_CONF_PROBE_FACTOR,
912 /*--- Acquisition modes, sample limiting ----------------------------*/
915 * The device supports setting a sample time limit (how long
916 * the sample acquisition should run, in ms).
918 SR_CONF_LIMIT_MSEC = 50000,
921 * The device supports setting a sample number limit (how many
922 * samples should be acquired).
924 SR_CONF_LIMIT_SAMPLES,
927 * The device supports setting a frame limit (how many
928 * frames should be acquired).
930 SR_CONF_LIMIT_FRAMES,
933 * The device supports continuous sampling. Neither a time limit
934 * nor a sample number limit has to be supplied, it will just acquire
935 * samples continuously, until explicitly stopped by a certain command.
939 /** The device has internal storage, into which data is logged. This
940 * starts or stops the internal logging. */
943 /** Device mode for multi-function devices. */
946 /** Self test mode. */
951 * Opaque structure representing a libsigrok device instance.
953 * None of the fields of this structure are meant to be accessed directly.
957 /** Types of device instance, struct sr_dev_inst.type */
958 enum sr_dev_inst_type {
959 /** Device instance type for USB devices. */
961 /** Device instance type for serial port devices. */
963 /** Device instance type for SCPI devices. */
965 /** Device-instance type for user-created "devices". */
969 /** Device instance status, struct sr_dev_inst.status */
970 enum sr_dev_inst_status {
971 /** The device instance was not found. */
972 SR_ST_NOT_FOUND = 10000,
973 /** The device instance was found, but is still booting. */
975 /** The device instance is live, but not in use. */
977 /** The device instance is actively in use in a session. */
979 /** The device is winding down its session. */
983 /** Device driver data. See also http://sigrok.org/wiki/Hardware_driver_API . */
984 struct sr_dev_driver {
985 /* Driver-specific */
986 /** Driver name. Lowercase a-z, 0-9 and dashes (-) only. */
988 /** Long name. Verbose driver name shown to user. */
990 /** API version (currently 1). */
992 /** Called when driver is loaded, e.g. program startup. */
993 int (*init) (struct sr_context *sr_ctx);
994 /** Called before driver is unloaded.
995 * Driver must free all resources held by it. */
996 int (*cleanup) (void);
997 /** Scan for devices. Driver should do all initialisation required.
998 * Can be called several times, e.g. with different port options.
999 * \retval NULL Error or no devices found.
1000 * \retval other GSList of a struct sr_dev_inst for each device.
1001 * Must be freed by caller!
1003 GSList *(*scan) (GSList *options);
1004 /** Get list of device instances the driver knows about.
1005 * \returns NULL or GSList of a struct sr_dev_inst for each device.
1006 * Must not be freed by caller!
1008 GSList *(*dev_list) (void);
1009 /** Clear list of devices the driver knows about. */
1010 int (*dev_clear) (void);
1011 /** Query value of a configuration key in driver or given device instance.
1012 * @see sr_config_get().
1014 int (*config_get) (uint32_t key, GVariant **data,
1015 const struct sr_dev_inst *sdi,
1016 const struct sr_channel_group *cg);
1017 /** Set value of a configuration key in driver or a given device instance.
1018 * @see sr_config_set(). */
1019 int (*config_set) (uint32_t key, GVariant *data,
1020 const struct sr_dev_inst *sdi,
1021 const struct sr_channel_group *cg);
1022 /** Channel status change.
1023 * @see sr_dev_channel_enable(). */
1024 int (*config_channel_set) (const struct sr_dev_inst *sdi,
1025 struct sr_channel *ch, unsigned int changes);
1026 /** Apply configuration settings to the device hardware.
1027 * @see sr_config_commit().*/
1028 int (*config_commit) (const struct sr_dev_inst *sdi);
1029 /** List all possible values for a configuration key in a device instance.
1030 * @see sr_config_list().
1032 int (*config_list) (uint32_t key, GVariant **data,
1033 const struct sr_dev_inst *sdi,
1034 const struct sr_channel_group *cg);
1036 /* Device-specific */
1038 int (*dev_open) (struct sr_dev_inst *sdi);
1040 int (*dev_close) (struct sr_dev_inst *sdi);
1041 /** Begin data acquisition on the specified device. */
1042 int (*dev_acquisition_start) (const struct sr_dev_inst *sdi,
1044 /** End data acquisition on the specified device. */
1045 int (*dev_acquisition_stop) (struct sr_dev_inst *sdi,
1049 /** Device driver private data. Initialized by init(). */
1054 * @struct sr_session
1056 * Opaque data structure representing a libsigrok session. None of the fields
1057 * of this structure are meant to be accessed directly.
1061 /** Serial port descriptor. */
1062 struct sr_serial_port {
1063 /** The OS dependent name of the serial port. */
1065 /** An end user friendly description for the serial port. */
1070 #include "version.h"