Linux Audio
Check our new training course
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
/* * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ #define ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ #include <zephyr/device.h> #include <zephyr/sys/util.h> #include <zephyr/types.h> #include <zephyr/drivers/gpio.h> #define BMA280_I2C_ADDRESS DT_INST_REG_ADDR(0) #define BMA280_REG_CHIP_ID 0x00 #if DT_INST_PROP(0, is_bmc150) #define BMA280_CHIP_ID 0xFA #else #define BMA280_CHIP_ID 0xFB #endif #define BMA280_REG_PMU_BW 0x10 #if CONFIG_BMA280_PMU_BW_1 #define BMA280_PMU_BW 0x08 #elif CONFIG_BMA280_PMU_BW_2 #define BMA280_PMU_BW 0x09 #elif CONFIG_BMA280_PMU_BW_3 #define BMA280_PMU_BW 0x0A #elif CONFIG_BMA280_PMU_BW_4 #define BMA280_PMU_BW 0x0B #elif CONFIG_BMA280_PMU_BW_5 #define BMA280_PMU_BW 0x0C #elif CONFIG_BMA280_PMU_BW_6 #define BMA280_PMU_BW 0x0D #elif CONFIG_BMA280_PMU_BW_7 #define BMA280_PMU_BW 0x0E #elif CONFIG_BMA280_PMU_BW_8 #define BMA280_PMU_BW 0x0F #endif /* * BMA280_PMU_FULL_RANGE measured in milli-m/s^2 instead * of m/s^2 to avoid using struct sensor_value for it */ #define BMA280_REG_PMU_RANGE 0x0F #if CONFIG_BMA280_PMU_RANGE_2G #define BMA280_PMU_RANGE 0x03 #define BMA280_PMU_FULL_RANGE (4 * SENSOR_G) #elif CONFIG_BMA280_PMU_RANGE_4G #define BMA280_PMU_RANGE 0x05 #define BMA280_PMU_FULL_RANGE (8 * SENSOR_G) #elif CONFIG_BMA280_PMU_RANGE_8G #define BMA280_PMU_RANGE 0x08 #define BMA280_PMU_FULL_RANGE (16 * SENSOR_G) #elif CONFIG_BMA280_PMU_RANGE_16G #define BMA280_PMU_RANGE 0x0C #define BMA280_PMU_FULL_RANGE (32 * SENSOR_G) #endif #define BMA280_REG_TEMP 0x08 #define BMA280_REG_INT_STATUS_0 0x09 #define BMA280_BIT_SLOPE_INT_STATUS BIT(2) #define BMA280_REG_INT_STATUS_1 0x0A #define BMA280_BIT_DATA_INT_STATUS BIT(7) #define BMA280_REG_INT_EN_0 0x16 #define BMA280_BIT_SLOPE_EN_X BIT(0) #define BMA280_BIT_SLOPE_EN_Y BIT(1) #define BMA280_BIT_SLOPE_EN_Z BIT(2) #define BMA280_SLOPE_EN_XYZ (BMA280_BIT_SLOPE_EN_X | \ BMA280_BIT_SLOPE_EN_Y | BMA280_BIT_SLOPE_EN_X) #define BMA280_REG_INT_EN_1 0x17 #define BMA280_BIT_DATA_EN BIT(4) #define BMA280_REG_INT_MAP_0 0x19 #define BMA280_INT_MAP_0_BIT_SLOPE BIT(2) #define BMA280_REG_INT_MAP_1 0x1A #define BMA280_INT_MAP_1_BIT_DATA BIT(0) #define BMA280_REG_INT_RST_LATCH 0x21 #define BMA280_INT_MODE_LATCH 0x0F #define BMA280_BIT_INT_LATCH_RESET BIT(7) #define BMA280_REG_INT_5 0x27 #define BMA280_SLOPE_DUR_SHIFT 0 #define BMA280_SLOPE_DUR_MASK (3 << BMA280_SLOPE_DUR_SHIFT) #define BMA280_REG_SLOPE_TH 0x28 #define BMA280_REG_ACCEL_X_LSB 0x2 #define BMA280_REG_ACCEL_Y_LSB 0x4 #define BMA280_REG_ACCEL_Z_LSB 0x6 #if DT_INST_PROP(0, 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) #define BMA280_REG_ACCEL_X_MSB 0x3 #define BMA280_REG_ACCEL_Y_MSB 0x5 #define BMA280_REG_ACCEL_Z_MSB 0x7 #define BMA280_THREAD_PRIORITY 10 #define BMA280_THREAD_STACKSIZE_UNIT 1024 struct bma280_data { const struct device *i2c; int16_t x_sample; int16_t y_sample; int16_t z_sample; int8_t temp_sample; #ifdef CONFIG_BMA280_TRIGGER const struct device *dev; const struct device *gpio; struct gpio_callback gpio_cb; struct sensor_trigger data_ready_trigger; sensor_trigger_handler_t data_ready_handler; struct sensor_trigger any_motion_trigger; sensor_trigger_handler_t any_motion_handler; #if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_BMA280_THREAD_STACK_SIZE); struct k_thread thread; struct k_sem gpio_sem; #elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD) struct k_work work; #endif #endif /* CONFIG_BMA280_TRIGGER */ }; #ifdef CONFIG_BMA280_TRIGGER int bma280_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int bma280_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val); int bma280_init_interrupt(const struct device *dev); #endif #endif /* ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ */