1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/saul/init_devs/auto_init_pir.c
2021-08-13 19:50:38 +02:00

65 lines
1.4 KiB
C

/*
* Copyright (C) 2018 UC Berkeley
*
* 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 PIR devices
*
* @author Hyung-Sin Kim <hs.kim@cs.berkeley.edu>
*
* @}
*/
#include "log.h"
#include "saul_reg.h"
#include "pir_params.h"
/**
* @brief Define the number of configured sensors
*/
#define PIR_NUM ARRAY_SIZE(pir_params)
/**
* @brief Allocate memory for the device descriptors
*/
static pir_t pir_devs[PIR_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[PIR_NUM];
/**
* @brief Reference to the occupancy driver struct
* @{
*/
extern saul_driver_t pir_saul_occup_driver;
/** @} */
void auto_init_pir(void)
{
for (unsigned i = 0; i < PIR_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing pir #%u\n", i);
int res = pir_init(&pir_devs[i], &pir_params[i]);
if (res != 0) {
LOG_ERROR("[auto_init_saul] error initializing pir #%u\n", i);
}
else {
saul_entries[i].dev = &(pir_devs[i]);
saul_entries[i].name = pir_saul_info[i].name;
saul_entries[i].driver = &pir_saul_occup_driver;
saul_reg_add(&(saul_entries[i]));
}
}
}