samples: bme280: enable the appropriate bus by default

I personally don't find it very useful to have to maintain prj.conf
and prj_spi.conf for this sample. The information we need to make
this application "just work" with regards to the bus is available in
the devicetree, and Kconfig can now access it using
dt_compat_on_bus().

Do so, enabling I2C and SPI appropriately when a sensor of the right
type is on either of those buses.

If no sensors are enabled, the user gets the build-time error message
in main.c about no devices being found.

This approach is prone to the "stuck symbol" Kconfig problem covered
in our documentation, so a pristine build is necessary to change the
default settings from a previous build.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2020-04-10 15:40:01 -07:00 committed by Kumar Gala
parent 1d1ed154da
commit 24260e6c3a
3 changed files with 13 additions and 4 deletions

View file

@ -10,4 +10,17 @@ config LOG_PRINTK
config SENSOR_LOG_LEVEL
default 4
# Workaround for not being able to have commas in macro arguments
DT_COMPAT_BOSCH_BME280 := bosch,bme280
# Enable SPI support by default if there are any BME280 sensors
# on a SPI bus.
config SPI
default $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BME280),spi)
# Enable I2C support by default if there are any BME280 sensors
# on an I2C bus.
config I2C
default $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BME280),i2c)
source "Kconfig.zephyr"

View file

@ -1,3 +1,2 @@
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_BME280=y

View file

@ -1,3 +0,0 @@
CONFIG_SPI=y
CONFIG_SENSOR=y
CONFIG_BME280=y