diff --git a/lib/libx52/libx52.h b/lib/libx52/libx52.h index 234605c..9bdd6d4 100644 --- a/lib/libx52/libx52.h +++ b/lib/libx52/libx52.h @@ -197,6 +197,21 @@ typedef enum { } libx52_error_code; +/** + * @brief Feature support for libx52 + * + * Each flag is passed to \ref libx52_has_feature to determine if the connected + * device has the given feature. This list of features is only limited to those + * which differ between the supported devices. + * + * @ingroup libx52misc + */ +typedef enum { + /** Individual LED control */ + LIBX52_FEATURE_LED, + +} libx52_feature; + /** * @defgroup libx52init Library Initialization and Deinitialization * @{ @@ -500,6 +515,21 @@ int libx52_update(libx52_device *x52); */ int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value); +/** + * @brief Check if the device supports the given feature. + * + * This will check if the connected device supports the requested feature. + * It will return \ref LIBX52_SUCCESS if it does support it, + * \ref LIBX52_ERROR_NOT_SUPPORTED if it does not, and another \ref + * libx52_error_code on errors. + * + * @param[in] x52 Pointer to the device + * @param[in] feature Feature identifier (\ref libx52_feature) + * + * @returns \ref libx52_error_code indicating status + */ +int libx52_check_feature(libx52_device *x52, libx52_feature feature); + /** * @brief Return a string representation of the error code * diff --git a/lib/libx52/x52_core.c b/lib/libx52/x52_core.c index 297149e..5a18c79 100644 --- a/lib/libx52/x52_core.c +++ b/lib/libx52/x52_core.c @@ -132,3 +132,18 @@ void libx52_exit(libx52_device *dev) free(dev); } +int libx52_check_feature(libx52_device *dev, libx52_feature feature) +{ + if (!dev) { + return LIBX52_ERROR_INVALID_PARAM; + } + + switch (feature) { + case LIBX52_FEATURE_LED: + return tst_bit(&(dev->flags), X52_FLAG_IS_PRO) ? + LIBX52_SUCCESS : + LIBX52_ERROR_NOT_SUPPORTED; + } + + return LIBX52_ERROR_INVALID_PARAM; +}