mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ce76125a22
The SI1133 from Silicon Labs is a UV Index Sensor and Ambient Light Sensor in a small 2x2 mm DFN package. The sensor can measure independently ultra violet (UV) light, infra red (IR) light and ambient light, however the ambient light is also influenced by the IR light requiring compensation from the IR readings. The SI1133 is quite different from other Silicon Labs chips in RIOT OS and therefore needs its own driver. In particular, the SI1133 has 7 different photodiode configurations to read but only 6 channels to read them in parallel so only some channels can be read each time. This patch implements a new driver allowing to read the data directly and a saul interface for the three kinds of light source. There are many configuration options including interrupts and continous modes that are left out of this initial driver.
95 lines
2.4 KiB
C
95 lines
2.4 KiB
C
/*
|
|
* Copyright (C) 2020 iosabi
|
|
*
|
|
* 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 of SI1133 driver.
|
|
*
|
|
* @author iosabi <iosabi@protonmail.com>
|
|
*
|
|
* @}
|
|
*/
|
|
|
|
#ifdef MODULE_SI1133
|
|
|
|
#include "assert.h"
|
|
#include "log.h"
|
|
#include "saul_reg.h"
|
|
#include "si1133.h"
|
|
#include "si1133_params.h"
|
|
|
|
/**
|
|
* @brief Define the number of configured sensors
|
|
*/
|
|
#define SI1133_NUMOF ARRAY_SIZE(si1133_params)
|
|
|
|
/**
|
|
* @brief Allocation of memory for device descriptors
|
|
*/
|
|
static si1133_t si1133_devs[SI1133_NUMOF];
|
|
|
|
/**
|
|
* @brief Memory for the SAUL registry entries
|
|
*/
|
|
static saul_reg_t saul_entries[SI1133_NUMOF * 4];
|
|
|
|
/**
|
|
* @brief Define the number of saul info
|
|
*/
|
|
#define SI1133_INFO_NUMOF ARRAY_SIZE(si1133_saul_reg_info)
|
|
|
|
/**
|
|
* @name Reference the driver structs
|
|
* @{
|
|
*/
|
|
extern const saul_driver_t si1133_uv_saul_driver;
|
|
extern const saul_driver_t si1133_ir_saul_driver;
|
|
extern const saul_driver_t si1133_visible_saul_driver;
|
|
/** @} */
|
|
|
|
void auto_init_si1133(void)
|
|
{
|
|
assert(SI1133_INFO_NUMOF == SI1133_NUMOF);
|
|
unsigned entry = 0;
|
|
for (unsigned i = 0; i < SI1133_NUMOF; i++) {
|
|
LOG_DEBUG("[auto_init_saul] initializing SI1133 #%u\n", i);
|
|
|
|
si1133_ret_code_t ret = si1133_init(&si1133_devs[i], &si1133_params[i]);
|
|
if (ret != SI1133_OK) {
|
|
LOG_ERROR("[auto_init_saul] error initializing SI1133 #%u: %d\n",
|
|
i, (int)ret);
|
|
continue;
|
|
}
|
|
|
|
/* UV index */
|
|
saul_entries[entry].dev = &si1133_devs[i];
|
|
saul_entries[entry].name = si1133_saul_reg_info[i].name;
|
|
saul_entries[entry].driver = &si1133_uv_saul_driver;
|
|
saul_reg_add(&saul_entries[entry++]);
|
|
|
|
/* Infra red */
|
|
saul_entries[entry].dev = &si1133_devs[i];
|
|
saul_entries[entry].name = si1133_saul_reg_info[i].name;
|
|
saul_entries[entry].driver = &si1133_ir_saul_driver;
|
|
saul_reg_add(&saul_entries[entry++]);
|
|
|
|
/* Visible */
|
|
saul_entries[entry].dev = &si1133_devs[i];
|
|
saul_entries[entry].name = si1133_saul_reg_info[i].name;
|
|
saul_entries[entry].driver = &si1133_visible_saul_driver;
|
|
saul_reg_add(&saul_entries[entry]);
|
|
}
|
|
}
|
|
|
|
#else
|
|
typedef int dont_be_pedantic;
|
|
#endif /* MODULE_SI1133 */
|