Lines Matching +full:gyro +full:- +full:fs
1 /* ST Microelectronics LSM6DSO 6-axis IMU sensor driver
5 * SPDX-License-Identifier: Apache-2.0
36 return -EINVAL; in lsm6dso_freq_to_odr_val()
47 return lsm6dso_odr_map[ARRAY_SIZE(lsm6dso_odr_map) - 1]; in lsm6dso_odr_to_freq_val()
62 return -EINVAL; in lsm6dso_accel_range_to_fs_val()
65 static int lsm6dso_accel_fs_val_to_gain(int fs, bool double_range) in lsm6dso_accel_fs_val_to_gain() argument
69 lsm6dso_accel_fs_map[fs] * GAIN_UNIT_XL : in lsm6dso_accel_fs_val_to_gain()
70 lsm6dso_accel_fs_map[fs] * GAIN_UNIT_XL / 2; in lsm6dso_accel_fs_val_to_gain()
86 return -EINVAL; in lsm6dso_gyro_range_to_fs_val()
91 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_reboot()
92 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_reboot()
95 return -EIO; in lsm6dso_reboot()
98 /* Wait sensor turn-on time as per datasheet */ in lsm6dso_reboot()
104 static int lsm6dso_accel_set_fs_raw(const struct device *dev, uint8_t fs) in lsm6dso_accel_set_fs_raw() argument
106 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_accel_set_fs_raw()
107 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_accel_set_fs_raw()
108 struct lsm6dso_data *data = dev->data; in lsm6dso_accel_set_fs_raw()
110 if (lsm6dso_xl_full_scale_set(ctx, fs) < 0) { in lsm6dso_accel_set_fs_raw()
111 return -EIO; in lsm6dso_accel_set_fs_raw()
114 data->accel_fs = fs; in lsm6dso_accel_set_fs_raw()
121 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_accel_set_odr_raw()
122 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_accel_set_odr_raw()
123 struct lsm6dso_data *data = dev->data; in lsm6dso_accel_set_odr_raw()
126 return -EIO; in lsm6dso_accel_set_odr_raw()
129 data->accel_freq = lsm6dso_odr_to_freq_val(odr); in lsm6dso_accel_set_odr_raw()
134 static int lsm6dso_gyro_set_fs_raw(const struct device *dev, uint8_t fs) in lsm6dso_gyro_set_fs_raw() argument
136 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_gyro_set_fs_raw()
137 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_gyro_set_fs_raw()
139 if (lsm6dso_gy_full_scale_set(ctx, fs) < 0) { in lsm6dso_gyro_set_fs_raw()
140 return -EIO; in lsm6dso_gyro_set_fs_raw()
148 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_gyro_set_odr_raw()
149 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_gyro_set_odr_raw()
152 return -EIO; in lsm6dso_gyro_set_odr_raw()
169 return -EIO; in lsm6dso_accel_odr_set()
177 int fs; in lsm6dso_accel_range_set() local
178 struct lsm6dso_data *data = dev->data; in lsm6dso_accel_range_set()
179 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_accel_range_set()
180 bool range_double = !!(cfg->accel_range & ACCEL_RANGE_DOUBLE); in lsm6dso_accel_range_set()
182 fs = lsm6dso_accel_range_to_fs_val(range, range_double); in lsm6dso_accel_range_set()
183 if (fs < 0) { in lsm6dso_accel_range_set()
184 return fs; in lsm6dso_accel_range_set()
187 if (lsm6dso_accel_set_fs_raw(dev, fs) < 0) { in lsm6dso_accel_range_set()
188 LOG_DBG("failed to set accelerometer full-scale"); in lsm6dso_accel_range_set()
189 return -EIO; in lsm6dso_accel_range_set()
192 data->acc_gain = lsm6dso_accel_fs_val_to_gain(fs, range_double); in lsm6dso_accel_range_set()
205 return lsm6dso_accel_odr_set(dev, val->val1); in lsm6dso_accel_config()
208 return -ENOTSUP; in lsm6dso_accel_config()
225 return -EIO; in lsm6dso_gyro_odr_set()
233 int fs; in lsm6dso_gyro_range_set() local
234 struct lsm6dso_data *data = dev->data; in lsm6dso_gyro_range_set()
236 fs = lsm6dso_gyro_range_to_fs_val(range); in lsm6dso_gyro_range_set()
237 if (fs < 0) { in lsm6dso_gyro_range_set()
238 return fs; in lsm6dso_gyro_range_set()
241 if (lsm6dso_gyro_set_fs_raw(dev, fs) < 0) { in lsm6dso_gyro_range_set()
242 LOG_DBG("failed to set gyroscope full-scale"); in lsm6dso_gyro_range_set()
243 return -EIO; in lsm6dso_gyro_range_set()
246 data->gyro_gain = (lsm6dso_gyro_fs_sens[fs] * GAIN_UNIT_G); in lsm6dso_gyro_range_set()
259 return lsm6dso_gyro_odr_set(dev, val->val1); in lsm6dso_gyro_config()
261 LOG_DBG("Gyro attribute not supported."); in lsm6dso_gyro_config()
262 return -ENOTSUP; in lsm6dso_gyro_config()
274 struct lsm6dso_data *data = dev->data; in lsm6dso_attr_set()
286 if (!data->shub_inited) { in lsm6dso_attr_set()
288 return -ENOTSUP; in lsm6dso_attr_set()
295 return -ENOTSUP; in lsm6dso_attr_set()
303 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_sample_fetch_accel()
304 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_sample_fetch_accel()
305 struct lsm6dso_data *data = dev->data; in lsm6dso_sample_fetch_accel()
307 if (lsm6dso_acceleration_raw_get(ctx, data->acc) < 0) { in lsm6dso_sample_fetch_accel()
309 return -EIO; in lsm6dso_sample_fetch_accel()
317 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_sample_fetch_gyro()
318 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_sample_fetch_gyro()
319 struct lsm6dso_data *data = dev->data; in lsm6dso_sample_fetch_gyro()
321 if (lsm6dso_angular_rate_raw_get(ctx, data->gyro) < 0) { in lsm6dso_sample_fetch_gyro()
323 return -EIO; in lsm6dso_sample_fetch_gyro()
332 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_sample_fetch_temp()
333 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_sample_fetch_temp()
334 struct lsm6dso_data *data = dev->data; in lsm6dso_sample_fetch_temp()
336 if (lsm6dso_temperature_raw_get(ctx, &data->temp_sample) < 0) { in lsm6dso_sample_fetch_temp()
338 return -EIO; in lsm6dso_sample_fetch_temp()
350 return -EIO; in lsm6dso_sample_fetch_shub()
361 struct lsm6dso_data *data = dev->data; in lsm6dso_sample_fetch()
383 if (data->shub_inited) { in lsm6dso_sample_fetch()
389 return -ENOTSUP; in lsm6dso_sample_fetch()
415 lsm6dso_accel_convert(val, data->acc[0], sensitivity); in lsm6dso_accel_get_channel()
418 lsm6dso_accel_convert(val, data->acc[1], sensitivity); in lsm6dso_accel_get_channel()
421 lsm6dso_accel_convert(val, data->acc[2], sensitivity); in lsm6dso_accel_get_channel()
425 lsm6dso_accel_convert(val++, data->acc[i], sensitivity); in lsm6dso_accel_get_channel()
429 return -ENOTSUP; in lsm6dso_accel_get_channel()
439 return lsm6dso_accel_get_channel(chan, val, data, data->acc_gain); in lsm6dso_accel_channel_get()
462 lsm6dso_gyro_convert(val, data->gyro[0], sensitivity); in lsm6dso_gyro_get_channel()
465 lsm6dso_gyro_convert(val, data->gyro[1], sensitivity); in lsm6dso_gyro_get_channel()
468 lsm6dso_gyro_convert(val, data->gyro[2], sensitivity); in lsm6dso_gyro_get_channel()
472 lsm6dso_gyro_convert(val++, data->gyro[i], sensitivity); in lsm6dso_gyro_get_channel()
476 return -ENOTSUP; in lsm6dso_gyro_get_channel()
486 return lsm6dso_gyro_get_channel(chan, val, data, data->gyro_gain); in lsm6dso_gyro_channel_get()
494 val->val1 = data->temp_sample / 256 + 25; in lsm6dso_gyro_channel_get_temp()
495 val->val2 = (data->temp_sample % 256) * (1000000 / 256); in lsm6dso_gyro_channel_get_temp()
507 val->val1 = (int32_t)dval / 1000000; in lsm6dso_magn_convert()
508 val->val2 = (int32_t)dval % 1000000; in lsm6dso_magn_convert()
518 idx = lsm6dso_shub_get_idx(data->dev, SENSOR_CHAN_MAGN_XYZ); in lsm6dso_magn_get_channel()
521 return -ENOTSUP; in lsm6dso_magn_get_channel()
525 sample[0] = (int16_t)(data->ext_data[idx][0] | in lsm6dso_magn_get_channel()
526 (data->ext_data[idx][1] << 8)); in lsm6dso_magn_get_channel()
527 sample[1] = (int16_t)(data->ext_data[idx][2] | in lsm6dso_magn_get_channel()
528 (data->ext_data[idx][3] << 8)); in lsm6dso_magn_get_channel()
529 sample[2] = (int16_t)(data->ext_data[idx][4] | in lsm6dso_magn_get_channel()
530 (data->ext_data[idx][5] << 8)); in lsm6dso_magn_get_channel()
534 lsm6dso_magn_convert(val, sample[0], data->magn_gain); in lsm6dso_magn_get_channel()
537 lsm6dso_magn_convert(val, sample[1], data->magn_gain); in lsm6dso_magn_get_channel()
540 lsm6dso_magn_convert(val, sample[2], data->magn_gain); in lsm6dso_magn_get_channel()
543 lsm6dso_magn_convert(val, sample[0], data->magn_gain); in lsm6dso_magn_get_channel()
544 lsm6dso_magn_convert(val + 1, sample[1], data->magn_gain); in lsm6dso_magn_get_channel()
545 lsm6dso_magn_convert(val + 2, sample[2], data->magn_gain); in lsm6dso_magn_get_channel()
548 return -ENOTSUP; in lsm6dso_magn_get_channel()
559 struct hts221_data *ht = &data->hts221; in lsm6dso_hum_convert()
562 idx = lsm6dso_shub_get_idx(data->dev, SENSOR_CHAN_HUMIDITY); in lsm6dso_hum_convert()
568 raw_val = (int16_t)(data->ext_data[idx][0] | in lsm6dso_hum_convert()
569 (data->ext_data[idx][1] << 8)); in lsm6dso_hum_convert()
572 rh = (ht->y1 - ht->y0) * raw_val + ht->x1 * ht->y0 - ht->x0 * ht->y1; in lsm6dso_hum_convert()
573 rh /= (ht->x1 - ht->x0); in lsm6dso_hum_convert()
576 val->val1 = rh; in lsm6dso_hum_convert()
577 val->val2 = rh * 1000000; in lsm6dso_hum_convert()
586 idx = lsm6dso_shub_get_idx(data->dev, SENSOR_CHAN_PRESS); in lsm6dso_press_convert()
592 raw_val = (int32_t)(data->ext_data[idx][0] | in lsm6dso_press_convert()
593 (data->ext_data[idx][1] << 8) | in lsm6dso_press_convert()
594 (data->ext_data[idx][2] << 16)); in lsm6dso_press_convert()
598 val->val1 = (raw_val >> 12) / 10; in lsm6dso_press_convert()
599 val->val2 = (raw_val >> 12) % 10 * 100000 + in lsm6dso_press_convert()
609 idx = lsm6dso_shub_get_idx(data->dev, SENSOR_CHAN_PRESS); in lsm6dso_temp_convert()
615 raw_val = (int16_t)(data->ext_data[idx][3] | in lsm6dso_temp_convert()
616 (data->ext_data[idx][4] << 8)); in lsm6dso_temp_convert()
619 val->val1 = raw_val / 100; in lsm6dso_temp_convert()
620 val->val2 = (int32_t)raw_val % 100 * (10000); in lsm6dso_temp_convert()
628 struct lsm6dso_data *data = dev->data; in lsm6dso_channel_get()
653 if (!data->shub_inited) { in lsm6dso_channel_get()
655 return -ENOTSUP; in lsm6dso_channel_get()
662 if (!data->shub_inited) { in lsm6dso_channel_get()
664 return -ENOTSUP; in lsm6dso_channel_get()
671 if (!data->shub_inited) { in lsm6dso_channel_get()
673 return -ENOTSUP; in lsm6dso_channel_get()
680 if (!data->shub_inited) { in lsm6dso_channel_get()
682 return -ENOTSUP; in lsm6dso_channel_get()
689 return -ENOTSUP; in lsm6dso_channel_get()
706 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_init_chip()
707 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso_init_chip()
708 struct lsm6dso_data *lsm6dso = dev->data; in lsm6dso_init_chip()
710 uint8_t odr, fs; in lsm6dso_init_chip() local
719 return -EIO; in lsm6dso_init_chip()
724 return -EIO; in lsm6dso_init_chip()
731 return -EIO; in lsm6dso_init_chip()
737 return -EIO; in lsm6dso_init_chip()
745 return -EIO; in lsm6dso_init_chip()
755 return -EIO; in lsm6dso_init_chip()
761 LOG_DBG("accel pm is %d", cfg->accel_pm); in lsm6dso_init_chip()
762 switch (cfg->accel_pm) { in lsm6dso_init_chip()
775 fs = cfg->accel_range & ACCEL_RANGE_MASK; in lsm6dso_init_chip()
776 LOG_DBG("accel range is %d", fs); in lsm6dso_init_chip()
777 if (lsm6dso_accel_set_fs_raw(dev, fs) < 0) { in lsm6dso_init_chip()
778 LOG_ERR("failed to set accelerometer range %d", fs); in lsm6dso_init_chip()
779 return -EIO; in lsm6dso_init_chip()
781 lsm6dso->acc_gain = lsm6dso_accel_fs_val_to_gain(fs, cfg->accel_range & ACCEL_RANGE_DOUBLE); in lsm6dso_init_chip()
783 odr = cfg->accel_odr; in lsm6dso_init_chip()
785 lsm6dso->accel_freq = lsm6dso_odr_to_freq_val(odr); in lsm6dso_init_chip()
788 return -EIO; in lsm6dso_init_chip()
791 /* set gyro power mode */ in lsm6dso_init_chip()
792 LOG_DBG("gyro pm is %d", cfg->gyro_pm); in lsm6dso_init_chip()
793 switch (cfg->gyro_pm) { in lsm6dso_init_chip()
803 fs = cfg->gyro_range; in lsm6dso_init_chip()
804 LOG_DBG("gyro range is %d", fs); in lsm6dso_init_chip()
805 if (lsm6dso_gyro_set_fs_raw(dev, fs) < 0) { in lsm6dso_init_chip()
806 LOG_ERR("failed to set gyroscope range %d", fs); in lsm6dso_init_chip()
807 return -EIO; in lsm6dso_init_chip()
809 lsm6dso->gyro_gain = (lsm6dso_gyro_fs_sens[fs] * GAIN_UNIT_G); in lsm6dso_init_chip()
811 odr = cfg->gyro_odr; in lsm6dso_init_chip()
812 LOG_DBG("gyro odr is %d", odr); in lsm6dso_init_chip()
813 lsm6dso->gyro_freq = lsm6dso_odr_to_freq_val(odr); in lsm6dso_init_chip()
816 return -EIO; in lsm6dso_init_chip()
822 return -EIO; in lsm6dso_init_chip()
827 return -EIO; in lsm6dso_init_chip()
836 const struct lsm6dso_config *cfg = dev->config; in lsm6dso_init()
838 struct lsm6dso_data *data = dev->data; in lsm6dso_init()
840 LOG_INF("Initialize device %s", dev->name); in lsm6dso_init()
841 data->dev = dev; in lsm6dso_init()
845 return -EIO; in lsm6dso_init()
849 if (cfg->trig_enabled) { in lsm6dso_init()
852 return -EIO; in lsm6dso_init()
858 data->shub_inited = true; in lsm6dso_init()
861 data->shub_inited = false; in lsm6dso_init()
940 * bus-specific macro at preprocessor time.