diff --git a/sys/include/saul_reg.h b/sys/include/saul_reg.h index ec2ae81588..1320311232 100644 --- a/sys/include/saul_reg.h +++ b/sys/include/saul_reg.h @@ -90,7 +90,7 @@ int saul_reg_add(saul_reg_t *dev); int saul_reg_rm(saul_reg_t *dev); /** - * @brief Find a device by it's position in the registry + * @brief Find a device by its position in the registry * * @param[in] pos position to look up * @@ -100,9 +100,9 @@ int saul_reg_rm(saul_reg_t *dev); saul_reg_t *saul_reg_find_nth(int pos); /** - * @brief Find the first device of the given type in the registry + * @brief Find the first device by its type in the registry * - * @param[in] type device type to look for + * @param[in] type the device type to look for * * @return pointer to the first device matching the given type * @return NULL if no device of that type could be found @@ -110,7 +110,7 @@ saul_reg_t *saul_reg_find_nth(int pos); saul_reg_t *saul_reg_find_type(uint8_t type); /** - * @brief Find a device by its name + * @brief Find the first device by its name in the registry * * @param[in] name the name to look for * @@ -119,6 +119,17 @@ saul_reg_t *saul_reg_find_type(uint8_t type); */ saul_reg_t *saul_reg_find_name(const char *name); +/** + * @brief Find the first device by its type and name in the registry + * + * @param[in] type the device type to look for + * @param[in] name the name to look for + * + * @return pointer to the first device matching the given type and name + * @return NULL if no device with that type and name could be found + */ +saul_reg_t *saul_reg_find_type_and_name(uint8_t type, const char *name); + /** * @brief Read data from the given device * diff --git a/sys/saul_reg/saul_reg.c b/sys/saul_reg/saul_reg.c index 729a7edf53..01abe99cb4 100644 --- a/sys/saul_reg/saul_reg.c +++ b/sys/saul_reg/saul_reg.c @@ -113,6 +113,19 @@ saul_reg_t *saul_reg_find_name(const char *name) return NULL; } +saul_reg_t *saul_reg_find_type_and_name(uint8_t type, const char *name) +{ + saul_reg_t *tmp = saul_reg; + + while (tmp) { + if (tmp->driver->type == type && strcmp(tmp->name, name) == 0) { + return tmp; + } + tmp = tmp->next; + } + return NULL; +} + int saul_reg_read(saul_reg_t *dev, phydat_t *res) { if (dev == NULL) {