diff options
7 files changed, 132 insertions, 0 deletions
diff --git a/driver/accelgyro_bmi260.c b/driver/accelgyro_bmi260.c index 573f8ce288..21d783fe84 100644 --- a/driver/accelgyro_bmi260.c +++ b/driver/accelgyro_bmi260.c @@ -28,6 +28,26 @@ #define CPRINTF(format, args...) cprintf(CC_ACCEL, format, ## args) #define CPRINTS(format, args...) cprints(CC_ACCEL, format, ## args) +#if defined(CONFIG_ZEPHYR) && defined(CONFIG_ACCEL_INTERRUPTS) +/* + * Get the mostion sensor ID of the BMI260 sensor that + * generates the interrupt. + * The interrupt is converted to the event and transferred to motion + * sense task that actually handles the interrupt. + * + * Here, we use alias to get the motion sensor ID + * + * e.g) base_accel is the label of a child node in /motionsense-sensors + * aliases { + * bmi260-int = &base_accel; + * }; + */ +#if DT_NODE_EXISTS(DT_ALIAS(bmi260_int)) +#define CONFIG_ACCELGYRO_BMI260_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(SENSOR_ID(DT_ALIAS(bmi260_int))) +#endif +#endif + STATIC_IF(CONFIG_ACCEL_FIFO) volatile uint32_t last_interrupt_timestamp; /* diff --git a/zephyr/dts/bindings/motionsense/driver/bmi260.yaml b/zephyr/dts/bindings/motionsense/driver/bmi260.yaml new file mode 100644 index 0000000000..1f9c16a2d9 --- /dev/null +++ b/zephyr/dts/bindings/motionsense/driver/bmi260.yaml @@ -0,0 +1,16 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# common fields for both BMI260 accel and BMI260 gyro + +# every motionsense sensor node should include motionsense-sensor-base.yaml +include: motionsense-sensor-base.yaml + +properties: + i2c-spi-addr-flags: + type: string + required: true + description: i2c address or SPI slave logic GPIO + enum: + - "BMI260_ADDR0_FLAGS" diff --git a/zephyr/dts/bindings/motionsense/driver/cros-ec,bmi260-accel.yaml b/zephyr/dts/bindings/motionsense/driver/cros-ec,bmi260-accel.yaml new file mode 100644 index 0000000000..09907d8711 --- /dev/null +++ b/zephyr/dts/bindings/motionsense/driver/cros-ec,bmi260-accel.yaml @@ -0,0 +1,9 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +description: motion sense sensor node for BMI260 accel + +compatible: "cros-ec,bmi260-accel" + +include: bmi260.yaml diff --git a/zephyr/dts/bindings/motionsense/driver/cros-ec,bmi260-gyro.yaml b/zephyr/dts/bindings/motionsense/driver/cros-ec,bmi260-gyro.yaml new file mode 100644 index 0000000000..67da0c4085 --- /dev/null +++ b/zephyr/dts/bindings/motionsense/driver/cros-ec,bmi260-gyro.yaml @@ -0,0 +1,9 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +description: motion sense sensor node for BMI260 gyro + +compatible: "cros-ec,bmi260-gyro" + +include: bmi260.yaml diff --git a/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-bmi260.yaml b/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-bmi260.yaml new file mode 100644 index 0000000000..4d414121d1 --- /dev/null +++ b/zephyr/dts/bindings/motionsense/drvdata/cros-ec,drvdata-bmi260.yaml @@ -0,0 +1,18 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +description: BMI260 driver data node + +compatible: "cros-ec,drvdata-bmi260" + +include: drvdata-base.yaml + +# +# examples: +# +# bmi260_data: bmi260-drv-data { +# compatible = "cros-ec,drvdata-bmi260"; +# status = "okay"; +# }; +# diff --git a/zephyr/shim/src/motionsense_driver/bmi260-drvinfo.inc b/zephyr/shim/src/motionsense_driver/bmi260-drvinfo.inc new file mode 100644 index 0000000000..2457fca31a --- /dev/null +++ b/zephyr/shim/src/motionsense_driver/bmi260-drvinfo.inc @@ -0,0 +1,57 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "driver/accelgyro_bmi_common_public.h" +#include "driver/accelgyro_bmi260_public.h" + +/* + * CREATE_SENSOR_DATA which is defined in motionsense_sensros.c is + * the helper to create sensor driver specific data. + * + * CREATE_SENSOR_DATA gets two arguments. One is the compatible + * property value specified in device tree and the other one is the macro + * that actually creates sensor driver specific data. The macro gets + * node id and the name to be used for the sensor driver data. + */ + +/* + * Create driver data. It can be shared among the entries in + * motion_sensors array which are using the same bmi260 driver. + */ +#define CREATE_SENSOR_DATA_BMI260(id, drvdata_name) \ + static struct bmi_drv_data_t drvdata_name; + +/* + * Create driver data for each BMI260 drvinfo instance in device tree. + * (compatible = "cros-ec,drvdata-bmi260") + */ +CREATE_SENSOR_DATA(cros_ec_drvdata_bmi260, CREATE_SENSOR_DATA_BMI260) +/* + * CREATE_MOTION_SENSOR which is defined in motionsense_sensros.c is + * the macro to create an entry in motion_sensors array. + * The macro gets value of compatible property of + * the sensor in device tree and sensor specific values like chip ID, + * type of sensor, name of driver, default min/max frequency. + * Then using the values, it creates the corresponding motion_sense_t entry + * in motion_sensors array. + */ + +/* + * Here, we call CREATE_MOTION_SENSOR to create a motion_sensor_t entry + * for each BMI260_accel instance(compatible = "cros-ec,bmi260-accel") + * in device tree. + */ +CREATE_MOTION_SENSOR(cros_ec_bmi260_accel, MOTIONSENSE_CHIP_BMI260, \ + MOTIONSENSE_TYPE_ACCEL, bmi260_drv, \ + BMI_ACCEL_MIN_FREQ, BMI_ACCEL_MAX_FREQ) + +/* + * Here, we call CREATE_MOTION_SENSOR to create a motion_sensor_t entry + * for each BMI260_gyro instance (compatible = "cros-ec,bmi260-gyro") + * in device tree. + */ +CREATE_MOTION_SENSOR(cros_ec_bmi260_gyro, MOTIONSENSE_CHIP_BMI260, \ + MOTIONSENSE_TYPE_GYRO, bmi260_drv, \ + BMI_GYRO_MIN_FREQ, BMI_GYRO_MAX_FREQ) diff --git a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc index 968d64b5dc..0bf395c9a0 100644 --- a/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc +++ b/zephyr/shim/src/motionsense_driver/sensor_drv_list.inc @@ -22,3 +22,6 @@ #ifdef CONFIG_ACCEL_BMA255 #include "bma255-drvinfo.inc" #endif +#ifdef CONFIG_ACCELGYRO_BMI260 +#include "bmi260-drvinfo.inc" +#endif |