#include "libsigrok.h"
#include "libsigrok-internal.h"
-/*
- * This enumerates which driver capabilities correspond to user-settable
- * options.
- */
-/* TODO: This shouldn't be a global. */
-SR_API struct sr_hwcap_option sr_hwcap_options[] = {
- /* Driver scanning options. */
+
+/* Driver scanning options. */
+SR_API struct sr_hwcap_option sr_drvopts[] = {
{SR_HWOPT_MODEL, SR_T_KEYVALUE, "Model", "model"},
{SR_HWOPT_CONN, SR_T_CHAR, "Connection", "conn"},
{SR_HWOPT_SERIALCOMM, SR_T_CHAR, "Serial communication", "serialcomm"},
- /* Device instance options. */
+ {0, 0, NULL, NULL},
+};
+
+/* Device instance options. */
+SR_API struct sr_hwcap_option sr_hwcap_options[] = {
{SR_HWCAP_SAMPLERATE, SR_T_UINT64, "Sample rate", "samplerate"},
{SR_HWCAP_CAPTURE_RATIO, SR_T_UINT64, "Pre-trigger capture ratio", "captureratio"},
{SR_HWCAP_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "pattern"},
}
}
+/**
+ * Returns information about the given driver or device instance.
+ *
+ * @param driver The sr_dev_driver struct to query.
+ * @param id The type of information, in the form of an SR_HWCAP_* option.
+ * @param data Pointer where the value. will be stored. Must not be NULL.
+ * @param sdi Pointer to the struct sr_dev_inst to be checked. Must not be NULL.
+ *
+ * @return SR_OK upon success or SR_ERR in case of error. Note SR_ERR_ARG
+ * may be returned by the driver indicating it doesn't know that id,
+ * but this is not to be flagged as an error by the caller; merely
+ * as an indication that it's not applicable.
+ */
+SR_API int sr_info_get(struct sr_dev_driver *driver, int id,
+ const void **data, const struct sr_dev_inst *sdi)
+{
+ int ret;
+
+ if (driver == NULL || data == NULL)
+ return SR_ERR;
+
+ ret = driver->info_get(id, data, sdi);
+
+ return ret;
+}
+
SR_PRIV struct sr_dev_inst *sr_dev_inst_new(int index, int status,
const char *vendor, const char *model, const char *version)
{
sdi->vendor = vendor ? g_strdup(vendor) : NULL;
sdi->model = model ? g_strdup(model) : NULL;
sdi->version = version ? g_strdup(version) : NULL;
+ sdi->probes = NULL;
sdi->priv = NULL;
return sdi;
g_free(sdi);
}
+SR_PRIV struct sr_probe *sr_probe_new(int index, int type,
+ gboolean enabled, const char *name)
+{
+ struct sr_probe *probe;
+
+ if (!(probe = g_try_malloc0(sizeof(struct sr_probe)))) {
+ sr_err("hwdriver: probe malloc failed");
+ return NULL;
+ }
+
+ probe->index = index;
+ probe->type = type;
+ probe->enabled = enabled;
+ if (name)
+ probe->name = g_strdup(name);
+
+ return probe;
+}
+
#ifdef HAVE_LIBUSB_1_0
SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
return FALSE;
}
- if (!(hwcaps = driver->hwcap_get_all())) {
- sr_err("hwdriver: %s: hwcap_get_all() returned NULL", __func__);
+ if (driver->info_get(SR_DI_HWCAPS, (const void **)&hwcaps, NULL) != SR_OK)
return FALSE;
- }
for (i = 0; hwcaps[i]; i++) {
if (hwcaps[i] == hwcap)
return FALSE;
}
+/**
+ * Get a hardware driver option.
+ *
+ * @param hwopt The option to get.
+ *
+ * @return A pointer to a struct with information about the parameter, or NULL
+ * if the option was not found.
+ */
+SR_API const struct sr_hwcap_option *sr_drvopt_get(int hwopt)
+{
+ int i;
+
+ for (i = 0; sr_drvopts[i].hwcap; i++) {
+ if (sr_drvopts[i].hwcap == hwopt)
+ return &sr_drvopts[i];
+ }
+
+ return NULL;
+}
+
/**
* Get a hardware driver capability option.
*