X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hwdriver.c;h=0fe7c703f385fe8c385fa10fc764b65c9cfe1424;hb=2bccd322bc40a2ebe41a9d3f1c4b12cd52cb2595;hp=c68d6e0c2167347d68f30283b8f065066f741606;hpb=c30b417f719e20f9f1d29fd8fa72c24278af3a0c;p=libsigrok.git diff --git a/hwdriver.c b/hwdriver.c index c68d6e0c..0fe7c703 100644 --- a/hwdriver.c +++ b/hwdriver.c @@ -23,8 +23,8 @@ #include #include #include -#include "sigrok.h" -#include "sigrok-internal.h" +#include "libsigrok.h" +#include "libsigrok-internal.h" /* * This enumerates which driver capabilities correspond to user-settable @@ -34,17 +34,26 @@ 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", "patternmode"}, + {SR_HWCAP_PATTERN_MODE, SR_T_CHAR, "Pattern generator mode", "pattern"}, {SR_HWCAP_RLE, SR_T_BOOL, "Run Length Encoding", "rle"}, + {SR_HWCAP_TRIGGER_SLOPE, SR_T_UINT64, "Trigger slope", "triggerslope"}, + {SR_HWCAP_TRIGGER_SOURCE, SR_T_CHAR, "Trigger source", "triggersource"}, + {SR_HWCAP_HORIZ_TRIGGERPOS, SR_T_FLOAT, "Horizontal trigger position", + "horiz_triggerpos"}, + {SR_HWCAP_BUFFERSIZE, SR_T_UINT64, "Buffer size", "buffersize"}, + {SR_HWCAP_TIMEBASE, SR_T_RATIONAL_PERIOD, "Time base", "timebase"}, + {SR_HWCAP_FILTER, SR_T_CHAR, "Filter targets", "filter"}, + {SR_HWCAP_VDIV, SR_T_RATIONAL_VOLT, "Volts/div", "vdiv"}, + {SR_HWCAP_COUPLING, SR_T_CHAR, "Coupling", "coupling"}, + {SR_HWCAP_MODEL, SR_T_KEYVALUE, "Model", "model"}, + {SR_HWCAP_CONN, SR_T_CHAR, "Connection", "connect"}, + {SR_HWCAP_SERIALCOMM, SR_T_CHAR, "Serial communication", "serialcomm"}, {0, 0, NULL, NULL}, }; #ifdef HAVE_LA_DEMO extern SR_PRIV struct sr_dev_driver demo_driver_info; #endif -#ifdef HAVE_LA_SALEAE_LOGIC -extern SR_PRIV struct sr_dev_driver saleae_logic_driver_info; -#endif #ifdef HAVE_LA_OLS extern SR_PRIV struct sr_dev_driver ols_driver_info; #endif @@ -66,14 +75,20 @@ extern SR_PRIV struct sr_dev_driver alsa_driver_info; #ifdef HAVE_LA_FX2LAFW extern SR_PRIV struct sr_dev_driver fx2lafw_driver_info; #endif +#ifdef HAVE_HW_HANTEK_DSO +extern SR_PRIV struct sr_dev_driver hantek_dso_driver_info; +#endif +#ifdef HAVE_HW_MASTECH_VA18B +extern SR_PRIV struct sr_dev_driver mastech_va18b_driver_info; +#endif +#ifdef HAVE_HW_GENERICDMM +extern SR_PRIV struct sr_dev_driver genericdmm_driver_info; +#endif static struct sr_dev_driver *drivers_list[] = { #ifdef HAVE_LA_DEMO &demo_driver_info, #endif -#ifdef HAVE_LA_SALEAE_LOGIC - &saleae_logic_driver_info, -#endif #ifdef HAVE_LA_OLS &ols_driver_info, #endif @@ -94,19 +109,25 @@ static struct sr_dev_driver *drivers_list[] = { #endif #ifdef HAVE_LA_FX2LAFW &fx2lafw_driver_info, +#endif +#ifdef HAVE_HW_HANTEK_DSO + &hantek_dso_driver_info, +#endif +#ifdef HAVE_HW_MASTECH_VA18B + &mastech_va18b_driver_info, +#endif +#ifdef HAVE_HW_GENERICDMM + &genericdmm_driver_info, #endif NULL, }; /** - * Return the list of loaded hardware drivers. - * - * The list of drivers is initialized from sr_init(), and can only be reset - * by calling sr_exit(). + * Return the list of supported hardware drivers. * * @return Pointer to the NULL-terminated list of hardware driver pointers. */ -SR_API struct sr_dev_driver **sr_hw_list(void) +SR_API struct sr_dev_driver **sr_driver_list(void) { return drivers_list; } @@ -121,7 +142,7 @@ SR_API struct sr_dev_driver **sr_hw_list(void) * * @return The number of devices found and instantiated by the driver. */ -SR_API int sr_hw_init(struct sr_dev_driver *driver) +SR_API int sr_driver_init(struct sr_dev_driver *driver) { int num_devs, num_probes, i, j; int num_initialized_devs = 0; @@ -156,7 +177,7 @@ SR_PRIV void sr_hw_cleanup_all(void) int i; struct sr_dev_driver **drivers; - drivers = sr_hw_list(); + drivers = sr_driver_list(); for (i = 0; drivers[i]; i++) { if (drivers[i]->cleanup) drivers[i]->cleanup(); @@ -222,7 +243,7 @@ SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus, udi->bus = bus; udi->address = address; - udi->devhdl = hdl; /* TODO: Check if this is NULL? */ + udi->devhdl = hdl; return udi; } @@ -264,13 +285,25 @@ SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial) * @param driver The hardware driver in which to search for the capability. * @param hwcap The capability to find in the list. * - * @return TRUE if found, FALSE otherwise. + * @return TRUE if the specified capability exists in the specified driver, + * FALSE otherwise. Also, if 'driver' is NULL or the respective driver + * returns an invalid capability list, FALSE is returned. */ -SR_API gboolean sr_hw_has_hwcap(struct sr_dev_driver *driver, int hwcap) +SR_API gboolean sr_driver_hwcap_exists(struct sr_dev_driver *driver, int hwcap) { - int *hwcaps, i; + const int *hwcaps; + int i; + + if (!driver) { + sr_err("hwdriver: %s: driver was NULL", __func__); + return FALSE; + } + + if (!(hwcaps = driver->hwcap_get_all())) { + sr_err("hwdriver: %s: hwcap_get_all() returned NULL", __func__); + return FALSE; + } - hwcaps = driver->hwcap_get_all(); for (i = 0; hwcaps[i]; i++) { if (hwcaps[i] == hwcap) return TRUE; @@ -287,7 +320,7 @@ SR_API gboolean sr_hw_has_hwcap(struct sr_dev_driver *driver, int hwcap) * @return A pointer to a struct with information about the parameter, or NULL * if the capability was not found. */ -SR_API struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap) +SR_API const struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap) { int i; @@ -299,15 +332,15 @@ SR_API struct sr_hwcap_option *sr_hw_hwcap_get(int hwcap) return NULL; } -/* unnecessary level of indirection follows. */ +/* Unnecessary level of indirection follows. */ -SR_PRIV void sr_source_remove(int fd) +SR_PRIV int sr_source_remove(int fd) { - sr_session_source_remove(fd); + return sr_session_source_remove(fd); } -SR_PRIV void sr_source_add(int fd, int events, int timeout, - sr_receive_data_callback rcv_cb, void *user_data) +SR_PRIV int sr_source_add(int fd, int events, int timeout, + sr_receive_data_callback_t cb, void *cb_data) { - sr_session_source_add(fd, events, timeout, rcv_cb, user_data); + return sr_session_source_add(fd, events, timeout, cb, cb_data); }