Refactors all sensor drivers to use SENSOR_DEVICE_DT_INST_DEFINE, which
is a sensor-specific variant of DEVICE_DT_INST_DEFINE that provides a
common place to instantiate additional data structures for the future
sensor subsystem and/or sensor driver stats.
This approach was inspired by I2C_DEVICE_DT_INST_DEFINE to streamline
adding I2C stats support across all I2C drivers.
Signed-off-by: Maureen Helm <maureen.helm@intel.com>
This change in pattern is meant to address a misconfiguration issue
that can occur for sensors that support being on multiple busses
like I2C & SPI.
For example, you can have a configuration in which such a sensor is
on the I2C bus in the devicetree and the sensor is enabled. However
the application configuration enables CONFIG_SPI=y and CONFIG_I2C=n
and this will cause the sensor driver to be built by default, however
since we don't have the I2C bus enabled the driver will not compile
correctly.
Previously we had been adding to board Kconfig.defconfig something
like:
config I2C
default y if SENSOR
This pattern doesn't scale well and may differ from what an application
specific need/use is.
So instead move to a pattern in which we leave the default enablement
up to the devicetree "status" property for the sensor. We then have
the Kconfig move from 'depends on <BUS>' to 'select <BUS>' and in
the case of drivers that support multiple busses we have the Kconfig
be: 'select <BUS> if $(dt_compat_on_bus,$(<DT_COMPAT>),<BUS>) for
each bus type the sensor supports.
This removes the need to add Kconfig logic to each board and enables
the bus subsystem and bus controller driver if the sensor requires
it by default in the build system.
Fixes: #48518
Signed-off-by: Kumar Gala <galak@kernel.org>
Update sensor drivers to use DT_HAS_<compat>_ENABLED Kconfig symbol
to expose the driver and enable it by default based on devicetree.
Signed-off-by: Kumar Gala <galak@kernel.org>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
In drivers/sensor/CMakeLists.txt, we have various lines like this:
add_subdirectory_ifdef(CONFIG_FOO foo)
Then drivers/sensor/foo/CMakeLists.txt says:
zephyr_library()
zephyr_library_sources_ifdef(CONFIG_FOO foo.c)
This is redundant; the foo/CMakeLists.txt won't be added to the build
system unless CONFIG_FOO=y in the first place, so there's no need for
extra boilerplate testing it again.
Remove all these unnecessary instances in each sensor driver's
CMakeLists.txt using this pattern:
zephyr_library()
zephyr_library_sources(foo.c)
In a couple of places, the '.c' extension is missing. Add them in for
consistency when that happens.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Before this change, the sw reset did not work after power-on, because
I2C commands are only accepted after 20msec (t_START after power-on).
Now the 20msec delay is moved before performing the reset to ensure that
the SW reset command can be executed. An additional 2msec delay is added
after the reset (see datasheet t_START after reset).
Signed-off-by: Christian Taedcke <christian.taedcke@lemonbeat.com>
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".
Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.
In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.
These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.
Signed-off-by: James Harris <james.harris@intel.com>
Move users that are DEVICE_DT_DECLARE(DT_DRV_INST(n, ...)) to
DEVICE_DT_INST_DECLARE(n, ...) and similar for DEVICE_DT_DEFINE.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Use the devicetree node as the source of object name and other
information used when defining the device structure.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
HAS_DTS_I2C is now selected by I2C and
always used as I2C && HAS_DTS_I2C.
It could then be purely removed.
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
It is necessary to wrap the device pointer into data.
Which was done already on most of them when global trigger is enabled.
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.
A coccinelle rule is used for this:
@r_const_dev_1
disable optional_qualifier
@
@@
-struct device *
+const struct device *
@r_const_dev_2
disable optional_qualifier
@
@@
-struct device * const
+const struct device *
Fixes#27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Run the int_literal_to_timeout Coccinelle script to fix places where
it is clear that an integer duration is being passed where a timeout
value is required.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Kernel timeouts have always been a 32 bit integer despite the
existence of generation macros, and existing code has been
inconsistent about using them. Upcoming commits are going to make the
timeout arguments opaque, so fix things up to be rigorously correct.
Changes include:
+ Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout
values for equality (e.g. with K_FOREVER or K_NO_WAIT).
+ Adding a k_msleep() synonym for k_sleep() which can continue to take
integral arguments as k_sleep() moves away to timeout arguments.
+ Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to
generate timeout arguments.
+ Removing the usage of K_NO_WAIT as the final argument to
K_THREAD_DEFINE(). This is just a count of milliseconds and we need
to use a zero.
This patch include no logic changes and should not affect generated
code at all.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Update devicetree sources and bindings, switch to new GPIO API. Use
devicetree property name to identify interrupt signal.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The build infrastructure should not be adding the drivers subdirectory
to the include path. Fix the legacy uses that depended on that
addition.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The firmware version on the CCS811 on nrf52_pca20020 is generally
version 1.1, which does not set the data ready bit in the status
register. Assume that a non-zero CO2 measurement on that version is
fresh for the purposes of determining the fetch status.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The application may want to know the configured mode without inspecting
Kconfig macros; this is important for proper management of BASELINE
which is mode-dependent.
It also may need to know the version of the hardware and firmware, as
the behavior of application firmware 2.0 is significantly better than
version 1.1.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This mode is documented as producing a raw result every 250 ms that the
application must convert to eCO2 and eTVOC readings. In practice
application firmware 2.0 appears to convert the readings as with all
other rates.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Expose the entire content of the ALG_RESULT_DATA block to the
application, primarily so the status and error flags can be seen. With
those available the application has the ability to detect that a stale
result has been provided so sensor_fetch_sample() can return -EAGAIN in
this case instead of -EIO, and it doesn't need to block which is
annoying.
This should also make the sensor usable on older Nordic Thingy:52
devices with outdated CCS811 application firmware that doesn't properly
implement the DATA_READY bit.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Accurate estimate of gas presence requires temperature and humidity
data. Add API to update these values.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Use CMSIS-standard bit mask and offset macros. Rename the field to more
closely match the data sheet. Use slightly less magic numbers for the
scale multipliers.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Proper use of the CCS811 requires maintenance of the BASELINE
register value measured in clean air at various points in the sensor
life cycle. The sensor driver abstraction has no facility to support
this, so add an application header with functions to fetch and update
the register value.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Add the standard suite of trigger configuration options. Add driver
support for the DATA_READY and THRESHOLD triggers. Note cross-module
dependency as configuring the trigger requires a controlled modification
of the sensor registers and the sensor driver API doesn't support this.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
The original implementation relied on the DATA_READY bit of the STATUS
register to indicate when a reading was available. This bit remains
clear for the first several readings produced by the CCS811.
When INT_DATARDY is set in MEAS_MODE the nINT signal will remain
asserted until ALG_RESULT_DATA is read. If this is treated as a LEVEL
signal, which is the common case in Zephyr, gating the read of
ALG_RESULT_DATA on DATA_READY means the signal will never be cleared,
and the interrupt callback will be repeated immediately.
Since the STATUS register value is part of the ALG_RESULT_DATA block
just read the whole thing, and provide its content to the user only if
the DATA_READY bit is set.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
The CCS811 has a measurement lifecycle that includes certain timing
constraints, including that calibration constants should not be applied
until the conditioning period has completed. If a device resets but the
CCS811 remains the process of inspecting current state and initializing
the device properly can be complicated.
Simplify this by forcing a reset of the device when the driver is
initialized. Should this cause hardship the necessary logic and
infrastructure to record time-of-last-reset across reboots and verify
measurement mode/baseline consistency can be added at that point.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Read the status and error in one function that provides its own
diagnostics.
Also change name of register to match datasheet.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
The CCS811 can be in either boot mode (after powerup) or application
mode, and these modes have distinct register maps that share only some
content. The register written to switch from boot mode to application
mode is not available in application mode, so don't write to it in that
case.
Also respect the required timeout between APP_START and next I2C
operation.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Allow application to choose the measurement rate.
Measurement mode 4 (250 ms rate) is not supported because it we have no
support for processing the raw data it produces.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Asserting the WAKEn increases current draw. Turn it off when I2C is
not being used.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Update ccs811 dts binding to include GPIO pins for wakeup, reset, and
interrupt and change driver code to get the GPIO pin and controller
info from DT instead of Kconfig.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Use this short header style in all Kconfig files:
# <description>
# <copyright>
# <license>
...
Also change all <description>s from
# Kconfig[.extension] - Foo-related options
to just
# Foo-related options
It's clear enough that it's about Kconfig.
The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)
git ls-files '*Kconfig*' | \
xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
All sensors were using legacy log module registeration method
where LOG_LEVEL was defined before registeration. This method
was error prone as it requires preserving includes order.
Replaced with LOG_MODULE_REGISTER(foo, level).
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Re-run with updated script to convert integer literal delay arguments to
k_sleep to use the standard timeout macros.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move sensor.h to drivers/sensor.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
move i2c.h to drivers/i2c.h and
create a shim for backward-compatibility.
No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.
Related to #16539
Signed-off-by: Anas Nashif <anas.nashif@intel.com>