mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #13934 from akshaim/Kconfig_opt3001
drivers/opt3001 : Expose Configurations to Kconfig
This commit is contained in:
commit
028dea2bf2
@ -22,4 +22,5 @@ rsource "ads101x/Kconfig"
|
||||
rsource "hdc1000/Kconfig"
|
||||
rsource "mag3110/Kconfig"
|
||||
rsource "mma8x5x/Kconfig"
|
||||
rsource "opt3001/Kconfig"
|
||||
endmenu # Sensor Device Drivers
|
||||
|
@ -44,6 +44,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "periph/i2c.h"
|
||||
#include "kernel_defines.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -69,8 +70,8 @@ extern "C" {
|
||||
* If set to 0x45 the ADDR PIN should be connected to VDD.
|
||||
* For more information on SerialBus Address, refer section 7.3.4.1 in datasheet.
|
||||
*/
|
||||
#ifndef OPT3001_I2C_ADDRESS
|
||||
#define OPT3001_I2C_ADDRESS (0x45)
|
||||
#ifndef CONFIG_OPT3001_I2C_ADDRESS
|
||||
#define CONFIG_OPT3001_I2C_ADDRESS (0x45)
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -79,8 +80,14 @@ extern "C" {
|
||||
* If set to 0x0000, the conversion time will be 100ms.
|
||||
* If set to 0x0800, the conversion time will be 800ms
|
||||
*/
|
||||
#ifndef OPT3001_CONVERSION_TIME
|
||||
#define OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
|
||||
#if IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_100)
|
||||
#define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_100_MS
|
||||
#elif IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_800)
|
||||
#define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_OPT3001_CONVERSION_TIME
|
||||
#define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
|
41
drivers/opt3001/Kconfig
Normal file
41
drivers/opt3001/Kconfig
Normal file
@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2020 Freie Universitaet Berlin
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
menuconfig KCONFIG_MODULE_OPT3001
|
||||
bool "Configure OPT3001 driver"
|
||||
depends on MODULE_OPT3001
|
||||
help
|
||||
Configure the OPT3001 driver using Kconfig.
|
||||
|
||||
if KCONFIG_MODULE_OPT3001
|
||||
|
||||
config OPT3001_I2C_ADDRESS
|
||||
hex "Default I2C address"
|
||||
range 0x44 0x47
|
||||
default 0x45
|
||||
help
|
||||
The OPT3001 allows up to 4 devices on single bus. The address depends on
|
||||
the state of ADDR Pin. The default value (0x45) corresponds to ADDR pin
|
||||
tied to VDD. For more information check the I2C Address Selection
|
||||
(7.3.4.1) section in the Datasheet.
|
||||
|
||||
choice
|
||||
bool "Conversion time"
|
||||
default OPT3001_CONVERSION_TIME_800
|
||||
help
|
||||
Time over which the results are integrated. A longer integration time
|
||||
allows for a lower noise measurement.
|
||||
time periods.
|
||||
|
||||
config OPT3001_CONVERSION_TIME_100
|
||||
bool "100 ms"
|
||||
|
||||
config OPT3001_CONVERSION_TIME_800
|
||||
bool "800 ms"
|
||||
|
||||
endchoice
|
||||
|
||||
endif # KCONFIG_MODULE_OPT3001
|
@ -36,7 +36,7 @@ extern "C" {
|
||||
#define OPT3001_PARAM_I2C_DEV I2C_DEV(0)
|
||||
#endif
|
||||
#ifndef OPT3001_PARAM_I2C_ADDR
|
||||
#define OPT3001_PARAM_I2C_ADDR (OPT3001_I2C_ADDRESS)
|
||||
#define OPT3001_PARAM_I2C_ADDR (CONFIG_OPT3001_I2C_ADDRESS)
|
||||
#endif
|
||||
|
||||
#ifndef OPT3001_PARAMS
|
||||
|
@ -58,7 +58,7 @@ int opt3001_init(opt3001_t *dev, const opt3001_params_t *params)
|
||||
/* Set range number, mode of conversion and conversion time */
|
||||
reg = OPT3001_CONFIG_RN_FSR;
|
||||
reg |= OPT3001_REGS_CONFIG_MOC(OPT3001_CONFIG_M_SHUTDOWN);
|
||||
reg |= OPT3001_REGS_CONFIG_CT(OPT3001_CONVERSION_TIME);
|
||||
reg |= OPT3001_REGS_CONFIG_CT(CONFIG_OPT3001_CONVERSION_TIME);
|
||||
|
||||
/* Configure for latched window-style comparison operation */
|
||||
reg |= OPT3001_REGS_CONFIG_L;
|
||||
@ -81,7 +81,7 @@ int opt3001_init(opt3001_t *dev, const opt3001_params_t *params)
|
||||
int opt3001_reset(const opt3001_t *dev)
|
||||
{
|
||||
uint16_t reg = OPT3001_CONFIG_RESET;
|
||||
reg &= (0xF0FF | OPT3001_REGS_CONFIG_CT(OPT3001_CONVERSION_TIME));
|
||||
reg &= (0xF0FF | OPT3001_REGS_CONFIG_CT(CONFIG_OPT3001_CONVERSION_TIME));
|
||||
reg = htons(reg);
|
||||
|
||||
/* Acquire exclusive access to the bus. */
|
||||
|
Loading…
Reference in New Issue
Block a user