From: Bert Vermeulen Date: Thu, 12 Jul 2012 18:54:45 +0000 (+0200) Subject: sr: split driver options into separate list X-Git-Tag: dsupstream~835 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8bfdc8c4a5fc4bee4b59838bd57c6762ea0cb206;p=libsigrok.git sr: split driver options into separate list --- diff --git a/hwdriver.c b/hwdriver.c index f74d47f0..77082367 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"}, @@ -325,6 +325,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. * diff --git a/libsigrok.h b/libsigrok.h index 2b07236a..68f8ce8e 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -268,6 +268,8 @@ struct sr_hwopt { /* Hardware driver options */ enum { + SR_HWOPT_DUMMY = 0, /* Used to terminate lists. Must be 0! */ + /** Some drivers cannot detect the exact model they're talking to. */ SR_HWOPT_MODEL, diff --git a/proto.h b/proto.h index 81544181..a1d6d7cc 100644 --- a/proto.h +++ b/proto.h @@ -75,6 +75,7 @@ SR_API struct sr_dev_driver **sr_driver_list(void); SR_API int sr_driver_init(struct sr_dev_driver *driver); SR_API GSList *sr_driver_scan(struct sr_dev_driver *driver, GSList *options); SR_API gboolean sr_driver_hwcap_exists(struct sr_dev_driver *driver, int hwcap); +SR_API const struct sr_hwcap_option *sr_drvopt_get(int hwopt); SR_API const struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap); /*--- session.c -------------------------------------------------------------*/