Lines Matching +full:gyro +full:- +full:range

5  * SPDX-License-Identifier: Apache-2.0
8 * http://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMI160-DS000-07.pdf
34 const struct bmi160_cfg *cfg = dev->config; in bmi160_transceive()
56 return spi_transceive_dt(&cfg->bus.spi, &tx, &rx); in bmi160_transceive()
59 return spi_write_dt(&cfg->bus.spi, &tx); in bmi160_transceive()
64 const struct bmi160_cfg *cfg = dev->config; in bmi160_bus_ready_spi()
66 return spi_is_ready_dt(&cfg->bus.spi); in bmi160_bus_ready_spi()
94 const struct bmi160_cfg *cfg = dev->config; in bmi160_bus_ready_i2c()
96 return device_is_ready(cfg->bus.i2c.bus); in bmi160_bus_ready_i2c()
102 const struct bmi160_cfg *cfg = dev->config; in bmi160_read_i2c()
104 return i2c_burst_read_dt(&cfg->bus.i2c, reg_addr, buf, len); in bmi160_read_i2c()
110 const struct bmi160_cfg *cfg = dev->config; in bmi160_write_i2c()
112 return i2c_burst_write_dt(&cfg->bus.i2c, reg_addr, buf, len); in bmi160_write_i2c()
125 const struct bmi160_cfg *cfg = dev->config; in bmi160_read()
127 return cfg->bus_io->read(dev, reg_addr, buf, len); in bmi160_read()
153 const struct bmi160_cfg *cfg = dev->config; in bmi160_write()
155 return cfg->bus_io->write(dev, reg_addr, buf, len); in bmi160_write()
181 return -EIO; in bmi160_reg_field_update()
195 {BMI160_CMD_PMU_MAG | pmu_sts->mag, 350}, in bmi160_pmu_set()
196 {BMI160_CMD_PMU_ACC | pmu_sts->acc, 3200}, in bmi160_pmu_set()
197 {BMI160_CMD_PMU_GYR | pmu_sts->gyr, 55000} in bmi160_pmu_set()
206 return -EIO; in bmi160_pmu_set()
219 return -EIO; in bmi160_pmu_set()
223 pmu_set = (pmu_sts->mag == sts.mag); in bmi160_pmu_set()
225 pmu_set = (pmu_sts->acc == sts.acc); in bmi160_pmu_set()
227 pmu_set = (pmu_sts->gyr == sts.gyr); in bmi160_pmu_set()
236 pmu_sts->acc != BMI160_PMU_NORMAL); in bmi160_pmu_set()
265 return -EINVAL; in bmi160_freq_to_odr_val()
276 return -EINVAL; in bmi160_freq_to_odr_val()
316 static int32_t bmi160_range_to_reg_val(uint16_t range, in bmi160_range_to_reg_val() argument
323 if (range <= range_map[i].range) { in bmi160_range_to_reg_val()
328 return -EINVAL; in bmi160_range_to_reg_val()
340 return range_map[i].range; in bmi160_reg_val_to_range()
344 return -EINVAL; in bmi160_reg_val_to_range()
362 return -EIO; in bmi160_do_calibration()
366 return -EIO; in bmi160_do_calibration()
378 struct bmi160_data *data = dev->data; in bmi160_acc_range_set()
403 return -EIO; in bmi160_acc_range_set()
406 data->scale.acc_numerator = BMI160_ACC_SCALE_NUMERATOR(range_g); in bmi160_acc_range_set()
431 return -ENOTSUP; in bmi160_acc_ofs_set()
440 return -EIO; in bmi160_acc_ofs_set()
454 struct bmi160_data *data = dev->data; in bmi160_acc_calibrate()
464 if (data->pmu_sts.acc != BMI160_PMU_NORMAL) { in bmi160_acc_calibrate()
465 return -ENOTSUP; in bmi160_acc_calibrate()
472 return -ENOTSUP; in bmi160_acc_calibrate()
484 } else if (accel_g == -1) { in bmi160_acc_calibrate()
493 return -EIO; in bmi160_acc_calibrate()
514 return bmi160_acc_odr_set(dev, val->val1, val->val2 / 1000); in bmi160_acc_config()
527 return -ENOTSUP; in bmi160_acc_config()
545 return -ENOTSUP; in bmi160_gyr_odr_set()
558 uint16_t range = sensor_rad_to_degrees(val); in bmi160_gyr_range_set() local
559 struct bmi160_data *data = dev->data; in bmi160_gyr_range_set()
560 int32_t reg_val = bmi160_range_to_reg_val(range, in bmi160_gyr_range_set()
569 range = 125; in bmi160_gyr_range_set()
572 range = 250; in bmi160_gyr_range_set()
575 range = 500; in bmi160_gyr_range_set()
578 range = 1000; in bmi160_gyr_range_set()
581 range = 2000; in bmi160_gyr_range_set()
586 return -EIO; in bmi160_gyr_range_set()
589 data->scale.gyr_numerator = BMI160_GYR_SCALE_NUMERATOR(range); in bmi160_gyr_range_set()
597 * Gyro offset scale, taken from pg. 79, converted to micro rad/s:
619 return -ENOTSUP; in bmi160_gyr_ofs_set()
624 ofs_u = ofs->val1 * 1000000ULL + ofs->val2; in bmi160_gyr_ofs_set()
626 val = CLAMP(ofs_u / BMI160_GYR_OFS_LSB, -512, 511); in bmi160_gyr_ofs_set()
631 return -EIO; in bmi160_gyr_ofs_set()
639 return -EIO; in bmi160_gyr_ofs_set()
643 /* activate gyro HW compensation */ in bmi160_gyr_ofs_set()
652 struct bmi160_data *data = dev->data; in bmi160_gyr_calibrate()
657 if (data->pmu_sts.gyr != BMI160_PMU_NORMAL) { in bmi160_gyr_calibrate()
658 return -ENOTSUP; in bmi160_gyr_calibrate()
662 return -EIO; in bmi160_gyr_calibrate()
665 /* activate gyro HW compensation */ in bmi160_gyr_calibrate()
683 return bmi160_gyr_odr_set(dev, val->val1, val->val2 / 1000); in bmi160_gyr_config()
692 LOG_DBG("Gyro attribute not supported."); in bmi160_gyr_config()
693 return -ENOTSUP; in bmi160_gyr_config()
721 return -ENOTSUP; in bmi160_attr_set()
734 return -EINVAL; in bmi160_attr_get()
764 udeg |= 0 - (udeg & 0x200); in bmi160_attr_get()
789 val->val1 = rate_uhz / 1000000; in bmi160_attr_get()
790 val->val2 = rate_uhz - val->val1 * 1000000; in bmi160_attr_get()
808 val->val1 = rate_uhz / 1000000; in bmi160_attr_get()
809 val->val2 = rate_uhz - val->val1 * 1000000; in bmi160_attr_get()
813 return -EINVAL; in bmi160_attr_get()
844 return -EINVAL; in bmi160_attr_get()
846 return -EINVAL; in bmi160_attr_get()
852 struct bmi160_data *data = dev->data; in bmi160_sample_fetch()
861 ret = -EIO; in bmi160_sample_fetch()
867 if (data->pmu_sts.raw == 0U) { in bmi160_sample_fetch()
868 return -EINVAL; in bmi160_sample_fetch()
870 return bmi160_word_read(dev, BMI160_REG_TEMPERATURE0, &data->sample.temperature); in bmi160_sample_fetch()
879 ret = -EIO; in bmi160_sample_fetch()
884 if (bmi160_read(dev, BMI160_SAMPLE_BURST_READ_ADDR, data->sample.raw, in bmi160_sample_fetch()
886 ret = -EIO; in bmi160_sample_fetch()
893 (uint16_t *) &data->sample.raw[i]; in bmi160_sample_fetch()
907 val->val1 = converted_val / 1000000; in bmi160_to_fixed_point()
908 val->val2 = converted_val % 1000000; in bmi160_to_fixed_point()
948 struct bmi160_data *data = dev->data; in bmi160_gyr_channel_get()
950 bmi160_channel_convert(chan, data->scale.gyr_numerator, BMI160_GYR_SCALE_DENOMINATOR, in bmi160_gyr_channel_get()
951 data->sample.gyr, val); in bmi160_gyr_channel_get()
960 struct bmi160_data *data = dev->data; in bmi160_acc_channel_get()
962 bmi160_channel_convert(chan, data->scale.acc_numerator, BMI160_ACC_SCALE_DENOMINATOR, in bmi160_acc_channel_get()
963 data->sample.acc, val); in bmi160_acc_channel_get()
970 struct bmi160_data *data = dev->data; in bmi160_temp_channel_get()
973 int32_t temp_micro = BMI160_TEMP_OFFSET * 1000000ULL + data->sample.temperature * 1953ULL; in bmi160_temp_channel_get()
975 val->val1 = temp_micro / 1000000ULL; in bmi160_temp_channel_get()
976 val->val2 = temp_micro % 1000000ULL; in bmi160_temp_channel_get()
1006 return -ENOTSUP; in bmi160_channel_get()
1025 struct bmi160_data *data = dev->data; in bmi160_resume()
1027 return bmi160_pmu_set(dev, &data->pmu_sts); in bmi160_resume()
1032 struct bmi160_data *data = dev->data; in bmi160_suspend()
1044 memset(data->sample.raw, 0, sizeof(data->sample.raw)); in bmi160_suspend()
1051 const struct bmi160_cfg *cfg = dev->config; in bmi160_init()
1052 struct bmi160_data *data = dev->data; in bmi160_init()
1056 if (!cfg->bus_io->ready(dev)) { in bmi160_init()
1058 return -EINVAL; in bmi160_init()
1064 return -EIO; in bmi160_init()
1072 return -EIO; in bmi160_init()
1079 return -EIO; in bmi160_init()
1084 return -ENODEV; in bmi160_init()
1087 /* set default PMU for gyro, accelerometer */ in bmi160_init()
1088 data->pmu_sts.gyr = BMI160_DEFAULT_PMU_GYR; in bmi160_init()
1089 data->pmu_sts.acc = BMI160_DEFAULT_PMU_ACC; in bmi160_init()
1092 data->pmu_sts.mag = BMI160_PMU_SUSPEND; in bmi160_init()
1102 if (ret < 0 && ret != -ENOSYS) { in bmi160_init()
1104 return -EIO; in bmi160_init()
1114 if (bmi160_pmu_set(dev, &data->pmu_sts) < 0) { in bmi160_init()
1116 return -EIO; in bmi160_init()
1120 /* set accelerometer default range */ in bmi160_init()
1123 LOG_DBG("Cannot set default range for accelerometer."); in bmi160_init()
1124 return -EIO; in bmi160_init()
1129 data->scale.acc_numerator = BMI160_ACC_SCALE_NUMERATOR(acc_range); in bmi160_init()
1131 /* set gyro default range */ in bmi160_init()
1134 LOG_DBG("Cannot set default range for gyroscope."); in bmi160_init()
1135 return -EIO; in bmi160_init()
1140 data->scale.gyr_numerator = BMI160_GYR_SCALE_NUMERATOR(gyr_range); in bmi160_init()
1147 return -EIO; in bmi160_init()
1154 LOG_DBG("Failed to set gyro's default ODR."); in bmi160_init()
1155 return -EIO; in bmi160_init()
1161 return -EINVAL; in bmi160_init()
1180 ret = -ENOTSUP; in bmi160_pm()
1226 * bus-specific macro at preprocessor time.