drivers: sensor: bma280: convert from Kconfig to devicetree
Define a binding for the Bosch BMA280 sensor. Remove the Kconfig settings and update the driver to use the devicetree information. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
16805018bb
commit
1a5368a07b
|
@ -12,50 +12,6 @@ menuconfig BMA280
|
|||
|
||||
if BMA280
|
||||
|
||||
choice
|
||||
prompt "Chip type"
|
||||
default BMA280_CHIP_BMA280
|
||||
help
|
||||
Choose desired chip type from the BMA280 family.
|
||||
|
||||
config BMA280_CHIP_BMA280
|
||||
bool "BMA280"
|
||||
help
|
||||
Choose this option to enable the BMA280 chip.
|
||||
|
||||
config BMA280_CHIP_BMC150_ACCEL
|
||||
bool "BMC150_ACCEL"
|
||||
help
|
||||
Choose this option to enable the accelerometer of the BMC150 chip.
|
||||
|
||||
endchoice
|
||||
|
||||
config BMA280_NAME
|
||||
string "Driver name"
|
||||
default "BMA280" if BMA280_CHIP_BMA280
|
||||
default "BMC150_ACCEL" if BMA280_CHIP_BMC150_ACCEL
|
||||
help
|
||||
Device name with which the sensor is identified.
|
||||
|
||||
config BMA280_I2C_ADDR
|
||||
hex "BMA280 I2C address"
|
||||
default 0x18 if BMA280_CHIP_BMA280
|
||||
default 0x10 if BMA280_CHIP_BMC150_ACCEL
|
||||
help
|
||||
I2C address of the BMA280 sensor.
|
||||
|
||||
0x10: Use if the SDO pin is pulled to GND.
|
||||
0x10: Use if the SDO pin is pulled to VDDIO.
|
||||
0x18: Use if the SDO pin is pulled to GND.
|
||||
0x19: Use if the SDO pin is pulled to VDDIO.
|
||||
|
||||
config BMA280_I2C_MASTER_DEV_NAME
|
||||
string "I2C master device name"
|
||||
default "I2C_0"
|
||||
help
|
||||
Specify the device name of the I2C master device to which chip is
|
||||
connected.
|
||||
|
||||
choice
|
||||
prompt "Trigger mode"
|
||||
default BMA280_TRIGGER_GLOBAL_THREAD
|
||||
|
@ -80,22 +36,6 @@ endchoice
|
|||
config BMA280_TRIGGER
|
||||
bool
|
||||
|
||||
config BMA280_GPIO_DEV_NAME
|
||||
string "GPIO device"
|
||||
default "GPIO_0"
|
||||
depends on BMA280_TRIGGER
|
||||
help
|
||||
The device name of the GPIO device to which the chip's interrupt pins
|
||||
are connected.
|
||||
|
||||
config BMA280_GPIO_PIN_NUM
|
||||
int "Interrupt GPIO pin number"
|
||||
default 0
|
||||
depends on BMA280_TRIGGER
|
||||
help
|
||||
The number of the GPIO on which the interrupt signal from the chip
|
||||
will be received.
|
||||
|
||||
config BMA280_THREAD_PRIORITY
|
||||
int "Thread priority"
|
||||
depends on BMA280_TRIGGER_OWN_THREAD
|
||||
|
|
|
@ -116,10 +116,10 @@ int bma280_init(struct device *dev)
|
|||
struct bma280_data *drv_data = dev->driver_data;
|
||||
u8_t id = 0U;
|
||||
|
||||
drv_data->i2c = device_get_binding(CONFIG_BMA280_I2C_MASTER_DEV_NAME);
|
||||
drv_data->i2c = device_get_binding(DT_INST_0_BOSCH_BMA280_BUS_NAME);
|
||||
if (drv_data->i2c == NULL) {
|
||||
LOG_DBG("Could not get pointer to %s device",
|
||||
CONFIG_BMA280_I2C_MASTER_DEV_NAME);
|
||||
DT_INST_0_BOSCH_BMA280_BUS_NAME);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,7 @@ int bma280_init(struct device *dev)
|
|||
|
||||
struct bma280_data bma280_driver;
|
||||
|
||||
DEVICE_AND_API_INIT(bma280, CONFIG_BMA280_NAME, bma280_init, &bma280_driver,
|
||||
DEVICE_AND_API_INIT(bma280, DT_INST_0_BOSCH_BMA280_LABEL,
|
||||
bma280_init, &bma280_driver,
|
||||
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
|
||||
&bma280_driver_api);
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
#include <zephyr/types.h>
|
||||
#include <drivers/gpio.h>
|
||||
|
||||
#define BMA280_I2C_ADDRESS CONFIG_BMA280_I2C_ADDR
|
||||
#define BMA280_I2C_ADDRESS DT_INST_0_BOSCH_BMA280_BASE_ADDRESS
|
||||
|
||||
#define BMA280_REG_CHIP_ID 0x00
|
||||
#if CONFIG_BMA280_CHIP_BMA280
|
||||
#define BMA280_CHIP_ID 0xFB
|
||||
#elif CONFIG_BMA280_CHIP_BMC150_ACCEL
|
||||
#if DT_INST_0_BOSCH_BMA280_IS_BMC150
|
||||
#define BMA280_CHIP_ID 0xFA
|
||||
#else
|
||||
#define BMA280_CHIP_ID 0xFB
|
||||
#endif
|
||||
|
||||
#define BMA280_REG_PMU_BW 0x10
|
||||
|
@ -96,12 +96,12 @@
|
|||
#define BMA280_REG_ACCEL_Y_LSB 0x4
|
||||
#define BMA280_REG_ACCEL_Z_LSB 0x6
|
||||
|
||||
#if CONFIG_BMA280_CHIP_BMA280
|
||||
#define BMA280_ACCEL_LSB_BITS 6
|
||||
#define BMA280_ACCEL_LSB_SHIFT 2
|
||||
#elif CONFIG_BMA280_CHIP_BMC150_ACCEL
|
||||
#if DT_INST_0_BOSCH_BMA280_IS_BMC150
|
||||
#define BMA280_ACCEL_LSB_BITS 4
|
||||
#define BMA280_ACCEL_LSB_SHIFT 4
|
||||
#else
|
||||
#define BMA280_ACCEL_LSB_BITS 6
|
||||
#define BMA280_ACCEL_LSB_SHIFT 2
|
||||
#endif
|
||||
#define BMA280_ACCEL_LSB_MASK \
|
||||
(BIT_MASK(BMA280_ACCEL_LSB_BITS) << BMA280_ACCEL_LSB_SHIFT)
|
||||
|
|
|
@ -61,7 +61,7 @@ static void bma280_gpio_callback(struct device *dev,
|
|||
|
||||
ARG_UNUSED(pins);
|
||||
|
||||
gpio_pin_disable_callback(dev, CONFIG_BMA280_GPIO_PIN_NUM);
|
||||
gpio_pin_disable_callback(dev, DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
|
||||
|
||||
#if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD)
|
||||
k_sem_give(&drv_data->gpio_sem);
|
||||
|
@ -108,7 +108,8 @@ static void bma280_thread_cb(void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
gpio_pin_enable_callback(drv_data->gpio, CONFIG_BMA280_GPIO_PIN_NUM);
|
||||
gpio_pin_enable_callback(drv_data->gpio,
|
||||
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BMA280_TRIGGER_OWN_THREAD
|
||||
|
@ -209,20 +210,22 @@ int bma280_init_interrupt(struct device *dev)
|
|||
}
|
||||
|
||||
/* setup data ready gpio interrupt */
|
||||
drv_data->gpio = device_get_binding(CONFIG_BMA280_GPIO_DEV_NAME);
|
||||
drv_data->gpio =
|
||||
device_get_binding(DT_INST_0_BOSCH_BMA280_INT1_GPIOS_CONTROLLER);
|
||||
if (drv_data->gpio == NULL) {
|
||||
LOG_DBG("Cannot get pointer to %s device",
|
||||
CONFIG_BMA280_GPIO_DEV_NAME);
|
||||
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_CONTROLLER);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
gpio_pin_configure(drv_data->gpio, CONFIG_BMA280_GPIO_PIN_NUM,
|
||||
gpio_pin_configure(drv_data->gpio,
|
||||
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
|
||||
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL |
|
||||
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
|
||||
|
||||
gpio_init_callback(&drv_data->gpio_cb,
|
||||
bma280_gpio_callback,
|
||||
BIT(CONFIG_BMA280_GPIO_PIN_NUM));
|
||||
BIT(DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN));
|
||||
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
LOG_DBG("Could not set gpio callback");
|
||||
|
@ -275,7 +278,8 @@ int bma280_init_interrupt(struct device *dev)
|
|||
drv_data->dev = dev;
|
||||
#endif
|
||||
|
||||
gpio_pin_enable_callback(drv_data->gpio, CONFIG_BMA280_GPIO_PIN_NUM);
|
||||
gpio_pin_enable_callback(drv_data->gpio,
|
||||
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
26
dts/bindings/sensor/bosch,bma280.yaml
Normal file
26
dts/bindings/sensor/bosch,bma280.yaml
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Copyright (c) 2020 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
Bosch BMA280 triaxial acceleration sensor. See more info at:
|
||||
https://www.bosch-sensortec.com/products/motion-sensors/accelerometers/bma280.html
|
||||
|
||||
compatible: "bosch,bma280"
|
||||
|
||||
include: i2c-device.yaml
|
||||
|
||||
properties:
|
||||
int1-gpios:
|
||||
type: phandle-array
|
||||
required: false
|
||||
description: |
|
||||
Identifies pin for the INT1 signal on the sensor. The sensor
|
||||
INT2 signal is not supported by the driver.
|
||||
|
||||
is-bmc150:
|
||||
type: boolean
|
||||
required: false
|
||||
description: |
|
||||
Specifies that the driver should adapt to the accelerometer
|
||||
capability provided by the BMC150 6-axis eCompass. This affects
|
||||
the chip ID and the resolution of the measurements.
|
|
@ -42,6 +42,17 @@
|
|||
#define DT_INST_0_AVAGO_APDS9960_INT_GPIOS_PIN 0
|
||||
#endif
|
||||
|
||||
#ifndef DT_INST_0_BOSCH_BMA280_LABEL
|
||||
#define DT_INST_0_BOSCH_BMA280_LABEL ""
|
||||
#define DT_INST_0_BOSCH_BMA280_BASE_ADDRESS 0
|
||||
#define DT_INST_0_BOSCH_BMA280_BUS_NAME ""
|
||||
#define DT_INST_0_BOSCH_BMA280_IS_BMC150 0
|
||||
#define DT_INST_0_BOSCH_BMA280_INT1_GPIOS_CONTROLLER ""
|
||||
#define DT_INST_0_BOSCH_BMA280_INT1_GPIOS_FLAGS 0
|
||||
#define DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN 0
|
||||
#define DT_BOSCH_BMA280_BUS_I2C 1
|
||||
#endif
|
||||
|
||||
#ifndef DT_INST_0_BOSCH_BME280_LABEL
|
||||
#define DT_INST_0_BOSCH_BME280_LABEL ""
|
||||
#define DT_INST_0_BOSCH_BME280_BASE_ADDRESS 0
|
||||
|
|
Loading…
Reference in a new issue