/* * Copyright (C) 2021 Inria * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level * directory for more details. */ /** * @ingroup sys_auto_init_saul * @{ * @file * @brief Auto initialization for HM330X particle matter sensor * * @author Francisco Molina * @} */ #include "assert.h" #include "log.h" #include "saul_reg.h" #include "hm330x_params.h" #include "hm330x.h" /** * @brief Allocate memory for the device descriptors */ static hm330x_t hm330x_devs[HM330X_NUMOF]; #if IS_ACTIVE(MODULE_SAUL) /** * @brief Number of logical saul devices per physical sensor */ #define HM330X_SAUL_DEV_NUM (6) /** * @brief Memory for the SAUL registry entries */ static saul_reg_t saul_entries[HM330X_NUMOF * HM330X_SAUL_DEV_NUM]; /** * @brief Define the number of saul info */ #define HM330X_INFO_NUM ARRAY_SIZE(hm330x_saul_info) /** * @name Import SAUL endpoints * @{ */ extern const saul_driver_t hm330x_saul_driver_mc_pm_1; extern const saul_driver_t hm330x_saul_driver_mc_pm_2p5; extern const saul_driver_t hm330x_saul_driver_mc_pm_10; extern const saul_driver_t hm330x_saul_driver_nc_pm_1; extern const saul_driver_t hm330x_saul_driver_nc_pm_2p5; extern const saul_driver_t hm330x_saul_driver_nc_pm_10; /** @} */ #endif void auto_init_hm330x(void) { #if IS_ACTIVE(MODULE_SAUL) assert(HM330X_INFO_NUM == HM330X_NUMOF); #endif for (unsigned int i = 0; i < HM330X_NUMOF; i++) { LOG_DEBUG("[auto_init_saul] initializing hm330x #%u\n", i); if (hm330x_init(&hm330x_devs[i], &hm330x_params[i])) { LOG_ERROR("[auto_init_saul] error initializing hm330x #%u\n", i); continue; } #if IS_ACTIVE(MODULE_SAUL) saul_entries[(i * HM330X_SAUL_DEV_NUM)].driver = &hm330x_saul_driver_mc_pm_1; saul_entries[(i * HM330X_SAUL_DEV_NUM) + 1].driver = &hm330x_saul_driver_mc_pm_2p5; saul_entries[(i * HM330X_SAUL_DEV_NUM) + 2].driver = &hm330x_saul_driver_mc_pm_10; saul_entries[(i * HM330X_SAUL_DEV_NUM) + 3].driver = &hm330x_saul_driver_nc_pm_1; saul_entries[(i * HM330X_SAUL_DEV_NUM) + 4].driver = &hm330x_saul_driver_nc_pm_2p5; saul_entries[(i * HM330X_SAUL_DEV_NUM) + 5].driver = &hm330x_saul_driver_nc_pm_10; /* the physical device is the same for all logical SAUL instances */ for (unsigned x = 0; x < HM330X_SAUL_DEV_NUM; x++) { saul_entries[i * HM330X_SAUL_DEV_NUM + x].dev = &(hm330x_devs[i]); saul_entries[i * HM330X_SAUL_DEV_NUM + x].name = hm330x_saul_info[i].name; saul_reg_add(&saul_entries[i * HM330X_SAUL_DEV_NUM + x]); } #endif } }