Lines Matching +full:accel +full:- +full:pm

1 /* Bosch BMA4xx 3-axis accelerometer driver
6 * SPDX-License-Identifier: Apache-2.0
15 #include <zephyr/pm/device.h>
29 return -ERANGE; in bma4xx_offset_to_reg_val()
42 struct bma4xx_data *bma4xx = dev->data; in bma4xx_attr_set_offset()
51 reg_addr = BMA4XX_REG_OFFSET_0 + (chan - SENSOR_CHAN_ACCEL_X); in bma4xx_attr_set_offset()
56 return bma4xx->hw_ops->write_reg(dev, reg_addr, reg_val[0]); in bma4xx_attr_set_offset()
66 return bma4xx->hw_ops->write_data(dev, reg_addr, (uint8_t *)reg_val, in bma4xx_attr_set_offset()
69 return -ENOTSUP; in bma4xx_attr_set_offset()
96 return -ERANGE; in bma4xx_odr_to_reg()
107 return -ERANGE; in bma4xx_odr_to_reg()
112 * offsets to nonvolatile memory so they are automatically set during power-on-reset.
116 struct bma4xx_data *bma4xx = dev->data; in bma4xx_attr_set_odr()
121 status = bma4xx_odr_to_reg(val->val1 * 1000000 + val->val2, &reg_val); in bma4xx_attr_set_odr()
126 status = bma4xx->hw_ops->update_reg(dev, BMA4XX_REG_ACCEL_CONFIG, BMA4XX_MASK_ACC_CONF_ODR, in bma4xx_attr_set_odr()
132 bma4xx->accel_odr = reg_val; in bma4xx_attr_set_odr()
137 2000000, /* +/-2G => 0x0 */
138 4000000, /* +/-4G => 0x1 */
139 8000000, /* +/-8G => 0x2 */
140 16000000, /* +/-16G => 0x3 */
147 return -ERANGE; in bma4xx_fs_to_reg()
160 return -ERANGE; in bma4xx_fs_to_reg()
164 * Set the sensor's full-scale range
168 struct bma4xx_data *bma4xx = dev->data; in bma4xx_attr_set_range()
172 /* Convert m/s^2 to micro-G's and find closest register setting */ in bma4xx_attr_set_range()
178 status = bma4xx->hw_ops->update_reg(dev, BMA4XX_REG_ACCEL_RANGE, BMA4XX_MASK_ACC_RANGE, in bma4xx_attr_set_range()
184 bma4xx->accel_fs_range = reg_val; in bma4xx_attr_set_range()
194 if (val->val2 || val->val1 < BMA4XX_BWP_OSR4_AVG1 || val->val1 > BMA4XX_BWP_RES_AVG128) { in bma4xx_attr_set_bwp()
195 return -EINVAL; in bma4xx_attr_set_bwp()
198 struct bma4xx_data *bma4xx = dev->data; in bma4xx_attr_set_bwp()
200 return bma4xx->hw_ops->update_reg(dev, BMA4XX_REG_ACCEL_CONFIG, BMA4XX_MASK_ACC_CONF_BWP, in bma4xx_attr_set_bwp()
201 (((uint8_t)val->val1) << BMA4XX_SHIFT_ACC_CONF_BWP)); in bma4xx_attr_set_bwp()
221 return -ENOTSUP; in bma4xx_attr_set()
230 struct bma4xx_data *bma4xx = dev->data; in bma4xx_chip_init()
231 const struct bma4xx_config *cfg = dev->config; in bma4xx_chip_init()
234 /* Sensor bus-specific initialization */ in bma4xx_chip_init()
235 status = cfg->bus_init(dev); in bma4xx_chip_init()
242 status = bma4xx->hw_ops->read_reg(dev, BMA4XX_REG_CHIP_ID, &bma4xx->chip_id); in bma4xx_chip_init()
247 LOG_DBG("chip_id is 0x%02x", bma4xx->chip_id); in bma4xx_chip_init()
249 if (bma4xx->chip_id != BMA4XX_CHIP_ID_BMA422) { in bma4xx_chip_init()
254 status = bma4xx->hw_ops->write_reg(dev, BMA4XX_REG_CMD, BMA4XX_CMD_SOFT_RESET); in bma4xx_chip_init()
256 LOG_ERR("Could not soft-reset chip: %d", status); in bma4xx_chip_init()
262 /* Default is: range = +/-4G, ODR = 100 Hz, BWP = "NORM_AVG4" */ in bma4xx_chip_init()
263 bma4xx->accel_fs_range = BMA4XX_RANGE_4G; in bma4xx_chip_init()
264 bma4xx->accel_bwp = BMA4XX_BWP_NORM_AVG4; in bma4xx_chip_init()
265 bma4xx->accel_odr = BMA4XX_ODR_100; in bma4xx_chip_init()
268 status = bma4xx->hw_ops->update_reg(dev, BMA4XX_REG_ACCEL_CONFIG, BMA4XX_BIT_ACC_PERF_MODE, in bma4xx_chip_init()
276 status = bma4xx->hw_ops->update_reg(dev, BMA4XX_REG_POWER_CTRL, BMA4XX_BIT_ACC_EN, in bma4xx_chip_init()
279 LOG_ERR("Could not enable accel: %d", status); in bma4xx_chip_init()
295 struct bma4xx_data *bma4xx = dev->data; in bma4xx_sample_fetch()
299 /* Burst read regs DATA_8 through DATA_13, which holds the accel readings */ in bma4xx_sample_fetch()
300 status = bma4xx->hw_ops->read_data(dev, BMA4XX_REG_DATA_8, (uint8_t *)&read_data, in bma4xx_sample_fetch()
301 BMA4XX_REG_DATA_13 - BMA4XX_REG_DATA_8 + 1); in bma4xx_sample_fetch()
303 LOG_ERR("Cannot read accel data: %d", status); in bma4xx_sample_fetch()
309 /* Values in accel_data[N] are left-aligned and will read 16x actual */ in bma4xx_sample_fetch()
325 struct bma4xx_data *bma4xx = dev->data; in bma4xx_temp_fetch()
328 status = bma4xx->hw_ops->read_reg(dev, BMA4XX_REG_TEMPERATURE, temp); in bma4xx_temp_fetch()
345 struct bma4xx_data *bma4xx = dev->data; in bma4xx_submit_one_shot()
347 const struct sensor_read_config *cfg = iodev_sqe->sqe.iodev->data; in bma4xx_submit_one_shot()
348 const struct sensor_chan_spec *const channels = cfg->channels; in bma4xx_submit_one_shot()
349 const size_t num_channels = cfg->count; in bma4xx_submit_one_shot()
367 edata->header.is_fifo = false; in bma4xx_submit_one_shot()
368 edata->header.accel_fs = bma4xx->accel_fs_range; in bma4xx_submit_one_shot()
369 edata->header.timestamp = k_ticks_to_ns_floor64(k_uptime_ticks()); in bma4xx_submit_one_shot()
370 edata->has_accel = 0; in bma4xx_submit_one_shot()
371 edata->has_temp = 0; in bma4xx_submit_one_shot()
377 rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP); in bma4xx_submit_one_shot()
382 edata->has_accel = 1; in bma4xx_submit_one_shot()
384 edata->has_temp = 1; in bma4xx_submit_one_shot()
391 edata->has_accel = 1; in bma4xx_submit_one_shot()
395 edata->has_temp = 1; in bma4xx_submit_one_shot()
401 rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP); in bma4xx_submit_one_shot()
406 if (edata->has_accel) { in bma4xx_submit_one_shot()
407 rc = bma4xx_sample_fetch(dev, &edata->accel_xyz[0], &edata->accel_xyz[1], in bma4xx_submit_one_shot()
408 &edata->accel_xyz[2]); in bma4xx_submit_one_shot()
410 LOG_ERR("Failed to fetch accel samples"); in bma4xx_submit_one_shot()
417 if (edata->has_temp) { in bma4xx_submit_one_shot()
418 rc = bma4xx_temp_fetch(dev, &edata->temp); in bma4xx_submit_one_shot()
432 const struct sensor_read_config *cfg = iodev_sqe->sqe.iodev->data; in bma4xx_submit_sync()
433 const struct device *dev = cfg->sensor; in bma4xx_submit_sync()
436 if (!cfg->is_streaming) { in bma4xx_submit_sync()
439 rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP); in bma4xx_submit_sync()
450 rtio_iodev_sqe_err(iodev_sqe, -ENOMEM); in bma4xx_submit()
465 const struct bma4xx_decoder_header *header = &edata->header; in bma4xx_decoder_get_frame_count()
468 return -ENOTSUP; in bma4xx_decoder_get_frame_count()
471 if (!header->is_fifo) { in bma4xx_decoder_get_frame_count()
477 *frame_count = edata->has_accel ? 1 : 0; in bma4xx_decoder_get_frame_count()
480 *frame_count = edata->has_temp ? 1 : 0; in bma4xx_decoder_get_frame_count()
483 return -ENOTSUP; in bma4xx_decoder_get_frame_count()
489 return -ENOTSUP; in bma4xx_decoder_get_frame_count()
508 return -ENOTSUP; in bma4xx_decoder_get_size_info()
521 /* 2 G's = 19.62 m/s^2. Use shift of 5 (+/-32) */ in bma4xx_get_shift()
534 return -EINVAL; in bma4xx_get_shift()
540 return -EINVAL; in bma4xx_get_shift()
564 * range * 9.8065 = 9.8065 * BIT(31 - 4) in bma4xx_convert_raw_accel_to_q31()
567 const int64_t scale = (int64_t)(9.8065 * BIT64(31 - 4)); in bma4xx_convert_raw_accel_to_q31()
574 * @brief Convert the 8-bit temp register value into a Q31 celsius value
591 const struct bma4xx_decoder_header *header = &edata->header; in bma4xx_one_shot_decode()
598 return -EINVAL; in bma4xx_one_shot_decode()
606 if (!edata->has_accel) { in bma4xx_one_shot_decode()
607 return -ENODATA; in bma4xx_one_shot_decode()
612 out->header.base_timestamp_ns = edata->header.timestamp; in bma4xx_one_shot_decode()
613 out->header.reading_count = 1; in bma4xx_one_shot_decode()
616 header->accel_fs, &out->shift); in bma4xx_one_shot_decode()
618 return -EINVAL; in bma4xx_one_shot_decode()
621 bma4xx_convert_raw_accel_to_q31(edata->accel_xyz[0], &out->readings[0].x); in bma4xx_one_shot_decode()
622 bma4xx_convert_raw_accel_to_q31(edata->accel_xyz[1], &out->readings[0].y); in bma4xx_one_shot_decode()
623 bma4xx_convert_raw_accel_to_q31(edata->accel_xyz[2], &out->readings[0].z); in bma4xx_one_shot_decode()
630 if (!edata->has_temp) { in bma4xx_one_shot_decode()
631 return -ENODATA; in bma4xx_one_shot_decode()
636 out->header.base_timestamp_ns = edata->header.timestamp; in bma4xx_one_shot_decode()
637 out->header.reading_count = 1; in bma4xx_one_shot_decode()
638 rc = bma4xx_get_shift(SENSOR_CHAN_DIE_TEMP, 0, &out->shift); in bma4xx_one_shot_decode()
640 return -EINVAL; in bma4xx_one_shot_decode()
643 bma4xx_convert_raw_temp_to_q31(edata->temp, &out->readings[0].temperature); in bma4xx_one_shot_decode()
650 return -EINVAL; in bma4xx_one_shot_decode()
660 if (header->is_fifo) { in bma4xx_decoder_decode()
662 return -ENOTSUP; in bma4xx_decoder_decode()
712 * Main instantiation macro, which selects the correct bus-specific