Lines Matching +full:accel +full:- +full:fs

1 /* ST Microelectronics LSM6DSO16IS 6-axis IMU sensor driver
5 * SPDX-License-Identifier: Apache-2.0
38 return -EINVAL; in lsm6dso16is_freq_to_odr_val()
49 return lsm6dso16is_odr_map[ARRAY_SIZE(lsm6dso16is_odr_map) - 1]; in lsm6dso16is_odr_to_freq_val()
64 return -EINVAL; in lsm6dso16is_accel_range_to_fs_val()
80 return -EINVAL; in lsm6dso16is_gyro_range_to_fs_val()
85 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_reboot()
86 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_reboot()
89 return -EIO; in lsm6dso16is_reboot()
92 /* Wait sensor turn-on time as per datasheet */ in lsm6dso16is_reboot()
93 k_sleep(K_MSEC(35)); /* turn-on time in ms */ in lsm6dso16is_reboot()
98 static int lsm6dso16is_accel_set_fs_raw(const struct device *dev, uint8_t fs) in lsm6dso16is_accel_set_fs_raw() argument
100 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_accel_set_fs_raw()
101 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_accel_set_fs_raw()
102 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_accel_set_fs_raw()
104 if (lsm6dso16is_xl_full_scale_set(ctx, fs) < 0) { in lsm6dso16is_accel_set_fs_raw()
105 return -EIO; in lsm6dso16is_accel_set_fs_raw()
108 data->accel_fs = fs; in lsm6dso16is_accel_set_fs_raw()
115 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_accel_set_odr_raw()
116 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_accel_set_odr_raw()
117 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_accel_set_odr_raw()
120 return -EIO; in lsm6dso16is_accel_set_odr_raw()
123 data->accel_freq = lsm6dso16is_odr_to_freq_val(odr); in lsm6dso16is_accel_set_odr_raw()
128 static int lsm6dso16is_gyro_set_fs_raw(const struct device *dev, uint8_t fs) in lsm6dso16is_gyro_set_fs_raw() argument
130 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_gyro_set_fs_raw()
131 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_gyro_set_fs_raw()
133 if (lsm6dso16is_gy_full_scale_set(ctx, fs) < 0) { in lsm6dso16is_gyro_set_fs_raw()
134 return -EIO; in lsm6dso16is_gyro_set_fs_raw()
142 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_gyro_set_odr_raw()
143 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_gyro_set_odr_raw()
146 return -EIO; in lsm6dso16is_gyro_set_odr_raw()
163 return -EIO; in lsm6dso16is_accel_odr_set()
171 int fs; in lsm6dso16is_accel_range_set() local
172 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_accel_range_set()
174 fs = lsm6dso16is_accel_range_to_fs_val(range); in lsm6dso16is_accel_range_set()
175 if (fs < 0) { in lsm6dso16is_accel_range_set()
176 return fs; in lsm6dso16is_accel_range_set()
179 if (lsm6dso16is_accel_set_fs_raw(dev, fs) < 0) { in lsm6dso16is_accel_range_set()
180 LOG_DBG("failed to set accelerometer full-scale"); in lsm6dso16is_accel_range_set()
181 return -EIO; in lsm6dso16is_accel_range_set()
184 data->acc_gain = lsm6dso16is_accel_fs_map[fs] * GAIN_UNIT_XL / 2; in lsm6dso16is_accel_range_set()
193 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_accel_config()
194 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_accel_config()
201 return lsm6dso16is_accel_odr_set(dev, val->val1); in lsm6dso16is_accel_config()
203 switch (val->val1) { in lsm6dso16is_accel_config()
211 return -EIO; in lsm6dso16is_accel_config()
216 LOG_DBG("Accel attribute not supported."); in lsm6dso16is_accel_config()
217 return -ENOTSUP; in lsm6dso16is_accel_config()
234 return -EIO; in lsm6dso16is_gyro_odr_set()
242 int fs; in lsm6dso16is_gyro_range_set() local
243 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_gyro_range_set()
245 fs = lsm6dso16is_gyro_range_to_fs_val(range); in lsm6dso16is_gyro_range_set()
246 if (fs < 0) { in lsm6dso16is_gyro_range_set()
247 return fs; in lsm6dso16is_gyro_range_set()
250 if (lsm6dso16is_gyro_set_fs_raw(dev, fs) < 0) { in lsm6dso16is_gyro_range_set()
251 LOG_DBG("failed to set gyroscope full-scale"); in lsm6dso16is_gyro_range_set()
252 return -EIO; in lsm6dso16is_gyro_range_set()
255 data->gyro_gain = (lsm6dso16is_gyro_fs_sens[fs] * GAIN_UNIT_G); in lsm6dso16is_gyro_range_set()
264 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_gyro_config()
265 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_gyro_config()
272 return lsm6dso16is_gyro_odr_set(dev, val->val1); in lsm6dso16is_gyro_config()
274 switch (val->val1) { in lsm6dso16is_gyro_config()
282 return -EIO; in lsm6dso16is_gyro_config()
288 return -ENOTSUP; in lsm6dso16is_gyro_config()
300 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_attr_set()
312 if (!data->shub_inited) { in lsm6dso16is_attr_set()
314 return -ENOTSUP; in lsm6dso16is_attr_set()
321 return -ENOTSUP; in lsm6dso16is_attr_set()
329 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_sample_fetch_accel()
330 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_sample_fetch_accel()
331 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_sample_fetch_accel()
333 if (lsm6dso16is_acceleration_raw_get(ctx, data->acc) < 0) { in lsm6dso16is_sample_fetch_accel()
335 return -EIO; in lsm6dso16is_sample_fetch_accel()
343 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_sample_fetch_gyro()
344 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_sample_fetch_gyro()
345 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_sample_fetch_gyro()
347 if (lsm6dso16is_angular_rate_raw_get(ctx, data->gyro) < 0) { in lsm6dso16is_sample_fetch_gyro()
349 return -EIO; in lsm6dso16is_sample_fetch_gyro()
358 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_sample_fetch_temp()
359 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_sample_fetch_temp()
360 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_sample_fetch_temp()
362 if (lsm6dso16is_temperature_raw_get(ctx, &data->temp_sample) < 0) { in lsm6dso16is_sample_fetch_temp()
364 return -EIO; in lsm6dso16is_sample_fetch_temp()
376 return -EIO; in lsm6dso16is_sample_fetch_shub()
387 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_sample_fetch()
409 if (data->shub_inited) { in lsm6dso16is_sample_fetch()
415 return -ENOTSUP; in lsm6dso16is_sample_fetch()
442 lsm6dso16is_accel_convert(val, data->acc[0], sensitivity); in lsm6dso16is_accel_get_channel()
445 lsm6dso16is_accel_convert(val, data->acc[1], sensitivity); in lsm6dso16is_accel_get_channel()
448 lsm6dso16is_accel_convert(val, data->acc[2], sensitivity); in lsm6dso16is_accel_get_channel()
452 lsm6dso16is_accel_convert(val++, data->acc[i], sensitivity); in lsm6dso16is_accel_get_channel()
456 return -ENOTSUP; in lsm6dso16is_accel_get_channel()
466 return lsm6dso16is_accel_get_channel(chan, val, data, data->acc_gain); in lsm6dso16is_accel_channel_get()
489 lsm6dso16is_gyro_convert(val, data->gyro[0], sensitivity); in lsm6dso16is_gyro_get_channel()
492 lsm6dso16is_gyro_convert(val, data->gyro[1], sensitivity); in lsm6dso16is_gyro_get_channel()
495 lsm6dso16is_gyro_convert(val, data->gyro[2], sensitivity); in lsm6dso16is_gyro_get_channel()
499 lsm6dso16is_gyro_convert(val++, data->gyro[i], sensitivity); in lsm6dso16is_gyro_get_channel()
503 return -ENOTSUP; in lsm6dso16is_gyro_get_channel()
513 return lsm6dso16is_gyro_get_channel(chan, val, data, data->gyro_gain); in lsm6dso16is_gyro_channel_get()
525 micro_c = (data->temp_sample * 1000000) / 256; in lsm6dso16is_gyro_channel_get_temp()
527 val->val1 = micro_c / 1000000 + 25; in lsm6dso16is_gyro_channel_get_temp()
528 val->val2 = micro_c % 1000000; in lsm6dso16is_gyro_channel_get_temp()
540 val->val1 = (int32_t)dval / 1000000; in lsm6dso16is_magn_convert()
541 val->val2 = (int32_t)dval % 1000000; in lsm6dso16is_magn_convert()
551 idx = lsm6dso16is_shub_get_idx(data->dev, SENSOR_CHAN_MAGN_XYZ); in lsm6dso16is_magn_get_channel()
554 return -ENOTSUP; in lsm6dso16is_magn_get_channel()
558 sample[0] = (int16_t)(data->ext_data[idx][0] | in lsm6dso16is_magn_get_channel()
559 (data->ext_data[idx][1] << 8)); in lsm6dso16is_magn_get_channel()
560 sample[1] = (int16_t)(data->ext_data[idx][2] | in lsm6dso16is_magn_get_channel()
561 (data->ext_data[idx][3] << 8)); in lsm6dso16is_magn_get_channel()
562 sample[2] = (int16_t)(data->ext_data[idx][4] | in lsm6dso16is_magn_get_channel()
563 (data->ext_data[idx][5] << 8)); in lsm6dso16is_magn_get_channel()
567 lsm6dso16is_magn_convert(val, sample[0], data->magn_gain); in lsm6dso16is_magn_get_channel()
570 lsm6dso16is_magn_convert(val, sample[1], data->magn_gain); in lsm6dso16is_magn_get_channel()
573 lsm6dso16is_magn_convert(val, sample[2], data->magn_gain); in lsm6dso16is_magn_get_channel()
576 lsm6dso16is_magn_convert(val, sample[0], data->magn_gain); in lsm6dso16is_magn_get_channel()
577 lsm6dso16is_magn_convert(val + 1, sample[1], data->magn_gain); in lsm6dso16is_magn_get_channel()
578 lsm6dso16is_magn_convert(val + 2, sample[2], data->magn_gain); in lsm6dso16is_magn_get_channel()
581 return -ENOTSUP; in lsm6dso16is_magn_get_channel()
592 struct hts221_data *ht = &data->hts221; in lsm6dso16is_hum_convert()
595 idx = lsm6dso16is_shub_get_idx(data->dev, SENSOR_CHAN_HUMIDITY); in lsm6dso16is_hum_convert()
601 raw_val = (int16_t)(data->ext_data[idx][0] | in lsm6dso16is_hum_convert()
602 (data->ext_data[idx][1] << 8)); in lsm6dso16is_hum_convert()
605 rh = (ht->y1 - ht->y0) * raw_val + ht->x1 * ht->y0 - ht->x0 * ht->y1; in lsm6dso16is_hum_convert()
606 rh /= (ht->x1 - ht->x0); in lsm6dso16is_hum_convert()
609 val->val1 = rh; in lsm6dso16is_hum_convert()
610 val->val2 = rh * 1000000; in lsm6dso16is_hum_convert()
619 idx = lsm6dso16is_shub_get_idx(data->dev, SENSOR_CHAN_PRESS); in lsm6dso16is_press_convert()
625 raw_val = (int32_t)(data->ext_data[idx][0] | in lsm6dso16is_press_convert()
626 (data->ext_data[idx][1] << 8) | in lsm6dso16is_press_convert()
627 (data->ext_data[idx][2] << 16)); in lsm6dso16is_press_convert()
631 val->val1 = (raw_val >> 12) / 10; in lsm6dso16is_press_convert()
632 val->val2 = (raw_val >> 12) % 10 * 100000 + in lsm6dso16is_press_convert()
642 idx = lsm6dso16is_shub_get_idx(data->dev, SENSOR_CHAN_PRESS); in lsm6dso16is_temp_convert()
648 raw_val = (int16_t)(data->ext_data[idx][3] | in lsm6dso16is_temp_convert()
649 (data->ext_data[idx][4] << 8)); in lsm6dso16is_temp_convert()
652 val->val1 = raw_val / 100; in lsm6dso16is_temp_convert()
653 val->val2 = (int32_t)raw_val % 100 * (10000); in lsm6dso16is_temp_convert()
661 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_channel_get()
686 if (!data->shub_inited) { in lsm6dso16is_channel_get()
688 return -ENOTSUP; in lsm6dso16is_channel_get()
695 if (!data->shub_inited) { in lsm6dso16is_channel_get()
697 return -ENOTSUP; in lsm6dso16is_channel_get()
704 if (!data->shub_inited) { in lsm6dso16is_channel_get()
706 return -ENOTSUP; in lsm6dso16is_channel_get()
713 if (!data->shub_inited) { in lsm6dso16is_channel_get()
715 return -ENOTSUP; in lsm6dso16is_channel_get()
722 return -ENOTSUP; in lsm6dso16is_channel_get()
739 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_init_chip()
740 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lsm6dso16is_init_chip()
741 struct lsm6dso16is_data *lsm6dso16is = dev->data; in lsm6dso16is_init_chip()
743 uint8_t odr, fs; in lsm6dso16is_init_chip() local
752 return -EIO; in lsm6dso16is_init_chip()
757 return -EIO; in lsm6dso16is_init_chip()
764 return -EIO; in lsm6dso16is_init_chip()
769 return -EIO; in lsm6dso16is_init_chip()
772 fs = cfg->accel_range; in lsm6dso16is_init_chip()
773 LOG_DBG("accel range is %d", fs); in lsm6dso16is_init_chip()
774 if (lsm6dso16is_accel_set_fs_raw(dev, fs) < 0) { in lsm6dso16is_init_chip()
775 LOG_ERR("failed to set accelerometer range %d", fs); in lsm6dso16is_init_chip()
776 return -EIO; in lsm6dso16is_init_chip()
778 lsm6dso16is->acc_gain = lsm6dso16is_accel_fs_map[fs] * GAIN_UNIT_XL / 2; in lsm6dso16is_init_chip()
780 odr = cfg->accel_odr; in lsm6dso16is_init_chip()
781 LOG_DBG("accel odr is %d", odr); in lsm6dso16is_init_chip()
784 return -EIO; in lsm6dso16is_init_chip()
787 fs = cfg->gyro_range; in lsm6dso16is_init_chip()
788 LOG_DBG("gyro range is %d", fs); in lsm6dso16is_init_chip()
789 if (lsm6dso16is_gyro_set_fs_raw(dev, fs) < 0) { in lsm6dso16is_init_chip()
790 LOG_ERR("failed to set gyroscope range %d", fs); in lsm6dso16is_init_chip()
791 return -EIO; in lsm6dso16is_init_chip()
793 lsm6dso16is->gyro_gain = (lsm6dso16is_gyro_fs_sens[fs] * GAIN_UNIT_G); in lsm6dso16is_init_chip()
795 odr = cfg->gyro_odr; in lsm6dso16is_init_chip()
797 lsm6dso16is->gyro_freq = lsm6dso16is_odr_to_freq_val(odr); in lsm6dso16is_init_chip()
800 return -EIO; in lsm6dso16is_init_chip()
805 return -EIO; in lsm6dso16is_init_chip()
814 const struct lsm6dso16is_config *cfg = dev->config; in lsm6dso16is_init()
816 struct lsm6dso16is_data *data = dev->data; in lsm6dso16is_init()
818 LOG_INF("Initialize device %s", dev->name); in lsm6dso16is_init()
819 data->dev = dev; in lsm6dso16is_init()
823 return -EIO; in lsm6dso16is_init()
827 if (cfg->trig_enabled) { in lsm6dso16is_init()
830 return -EIO; in lsm6dso16is_init()
836 data->shub_inited = true; in lsm6dso16is_init()
839 data->shub_inited = false; in lsm6dso16is_init()
919 * bus-specific macro at preprocessor time.