X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hwdriver.c;h=7effb6aa978d81b92341fab39d14c3f07a8aab61;hb=c4f3ed4bb075eb3b2015b0cacbf4a8cf4e29d7a4;hp=f74d47f05264b4dbd809ebc862ffbca326417371;hpb=47211d65b4fdaca58694a51cdbf1ba8ee4270ee9;p=libsigrok.git diff --git a/hwdriver.c b/hwdriver.c index f74d47f0..7effb6aa 100644 --- a/hwdriver.c +++ b/hwdriver.c @@ -26,17 +26,17 @@ #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"}, @@ -177,6 +177,32 @@ SR_PRIV void sr_hw_cleanup_all(void) } } +/** + * 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) { @@ -312,10 +338,8 @@ SR_API gboolean sr_driver_hwcap_exists(struct sr_dev_driver *driver, int hwcap) 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) @@ -325,6 +349,26 @@ SR_API gboolean sr_driver_hwcap_exists(struct sr_dev_driver *driver, int 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. *