Lines Matching +full:gyro +full:- +full:range
1 /* ST Microelectronics ISM330DHCX 6-axis IMU sensor driver
5 * SPDX-License-Identifier: Apache-2.0
39 return -EINVAL; in ism330dhcx_freq_to_odr_val()
50 return ism330dhcx_odr_map[ARRAY_SIZE(ism330dhcx_odr_map) - 1]; in ism330dhcx_odr_to_freq_val()
56 static int ism330dhcx_accel_range_to_fs_val(int32_t range) in ism330dhcx_accel_range_to_fs_val() argument
61 if (range == ism330dhcx_accel_fs_map[i]) { in ism330dhcx_accel_range_to_fs_val()
66 return -EINVAL; in ism330dhcx_accel_range_to_fs_val()
94 static int ism330dhcx_gyro_range_to_fs_val(int32_t range) in ism330dhcx_gyro_range_to_fs_val() argument
99 if (range == ism330dhcx_gyro_fs_map[i]) { in ism330dhcx_gyro_range_to_fs_val()
104 return -EINVAL; in ism330dhcx_gyro_range_to_fs_val()
109 struct ism330dhcx_data *data = dev->data; in ism330dhcx_reboot()
111 if (ism330dhcx_boot_set(data->ctx, 1) < 0) { in ism330dhcx_reboot()
112 return -EIO; in ism330dhcx_reboot()
115 /* Wait sensor turn-on time as per datasheet */ in ism330dhcx_reboot()
123 struct ism330dhcx_data *data = dev->data; in ism330dhcx_accel_set_fs_raw()
125 if (ism330dhcx_xl_full_scale_set(data->ctx, fs) < 0) { in ism330dhcx_accel_set_fs_raw()
126 return -EIO; in ism330dhcx_accel_set_fs_raw()
129 data->accel_fs = fs; in ism330dhcx_accel_set_fs_raw()
136 struct ism330dhcx_data *data = dev->data; in ism330dhcx_accel_set_odr_raw()
138 if (ism330dhcx_xl_data_rate_set(data->ctx, odr) < 0) { in ism330dhcx_accel_set_odr_raw()
139 return -EIO; in ism330dhcx_accel_set_odr_raw()
142 data->accel_freq = ism330dhcx_odr_to_freq_val(odr); in ism330dhcx_accel_set_odr_raw()
149 struct ism330dhcx_data *data = dev->data; in ism330dhcx_gyro_set_fs_raw()
151 if (ism330dhcx_gy_full_scale_set(data->ctx, fs) < 0) { in ism330dhcx_gyro_set_fs_raw()
152 return -EIO; in ism330dhcx_gyro_set_fs_raw()
160 struct ism330dhcx_data *data = dev->data; in ism330dhcx_gyro_set_odr_raw()
162 if (ism330dhcx_gy_data_rate_set(data->ctx, odr) < 0) { in ism330dhcx_gyro_set_odr_raw()
163 return -EIO; in ism330dhcx_gyro_set_odr_raw()
180 return -EIO; in ism330dhcx_accel_odr_set()
186 static int ism330dhcx_accel_range_set(const struct device *dev, int32_t range) in ism330dhcx_accel_range_set() argument
189 struct ism330dhcx_data *data = dev->data; in ism330dhcx_accel_range_set()
191 fs = ism330dhcx_accel_range_to_fs_val(range); in ism330dhcx_accel_range_set()
197 LOG_DBG("failed to set accelerometer full-scale"); in ism330dhcx_accel_range_set()
198 return -EIO; in ism330dhcx_accel_range_set()
201 data->acc_gain = (ism330dhcx_accel_fs_sens[fs] * GAIN_UNIT_XL); in ism330dhcx_accel_range_set()
214 return ism330dhcx_accel_odr_set(dev, val->val1); in ism330dhcx_accel_config()
217 return -ENOTSUP; in ism330dhcx_accel_config()
234 return -EIO; in ism330dhcx_gyro_odr_set()
240 static int ism330dhcx_gyro_range_set(const struct device *dev, int32_t range) in ism330dhcx_gyro_range_set() argument
243 struct ism330dhcx_data *data = dev->data; in ism330dhcx_gyro_range_set()
245 fs = ism330dhcx_gyro_range_to_fs_val(range); in ism330dhcx_gyro_range_set()
251 LOG_DBG("failed to set gyroscope full-scale"); in ism330dhcx_gyro_range_set()
252 return -EIO; in ism330dhcx_gyro_range_set()
255 data->gyro_gain = (ism330dhcx_gyro_fs_sens[fs] * GAIN_UNIT_G); in ism330dhcx_gyro_range_set()
268 return ism330dhcx_gyro_odr_set(dev, val->val1); in ism330dhcx_gyro_config()
270 LOG_DBG("Gyro attribute not supported."); in ism330dhcx_gyro_config()
271 return -ENOTSUP; in ism330dhcx_gyro_config()
295 return -ENOTSUP; in ism330dhcx_attr_set()
303 struct ism330dhcx_data *data = dev->data; in ism330dhcx_sample_fetch_accel()
306 if (ism330dhcx_acceleration_raw_get(data->ctx, buf) < 0) { in ism330dhcx_sample_fetch_accel()
308 return -EIO; in ism330dhcx_sample_fetch_accel()
311 data->acc[0] = buf[0]; in ism330dhcx_sample_fetch_accel()
312 data->acc[1] = buf[1]; in ism330dhcx_sample_fetch_accel()
313 data->acc[2] = buf[2]; in ism330dhcx_sample_fetch_accel()
320 struct ism330dhcx_data *data = dev->data; in ism330dhcx_sample_fetch_gyro()
323 if (ism330dhcx_angular_rate_raw_get(data->ctx, buf) < 0) { in ism330dhcx_sample_fetch_gyro()
325 return -EIO; in ism330dhcx_sample_fetch_gyro()
328 data->gyro[0] = buf[0]; in ism330dhcx_sample_fetch_gyro()
329 data->gyro[1] = buf[1]; in ism330dhcx_sample_fetch_gyro()
330 data->gyro[2] = buf[2]; in ism330dhcx_sample_fetch_gyro()
338 struct ism330dhcx_data *data = dev->data; in ism330dhcx_sample_fetch_temp()
341 if (ism330dhcx_temperature_raw_get(data->ctx, &buf) < 0) { in ism330dhcx_sample_fetch_temp()
343 return -EIO; in ism330dhcx_sample_fetch_temp()
346 data->temp_sample = buf; in ism330dhcx_sample_fetch_temp()
357 return -EIO; in ism330dhcx_sample_fetch_shub()
393 return -ENOTSUP; in ism330dhcx_sample_fetch()
414 struct ism330dhcx_data *data = dev->data; in ism330dhcx_accel_get_channel()
419 ism330dhcx_accel_convert(val, data->acc[0], sensitivity); in ism330dhcx_accel_get_channel()
422 ism330dhcx_accel_convert(val, data->acc[1], sensitivity); in ism330dhcx_accel_get_channel()
425 ism330dhcx_accel_convert(val, data->acc[2], sensitivity); in ism330dhcx_accel_get_channel()
429 ism330dhcx_accel_convert(val++, data->acc[i], sensitivity); in ism330dhcx_accel_get_channel()
433 return -ENOTSUP; in ism330dhcx_accel_get_channel()
442 struct ism330dhcx_data *data = dev->data; in ism330dhcx_accel_channel_get()
444 return ism330dhcx_accel_get_channel(dev, chan, val, data->acc_gain); in ism330dhcx_accel_channel_get()
461 struct ism330dhcx_data *data = dev->data; in ism330dhcx_gyro_get_channel()
466 ism330dhcx_gyro_convert(val, data->gyro[0], sensitivity); in ism330dhcx_gyro_get_channel()
469 ism330dhcx_gyro_convert(val, data->gyro[1], sensitivity); in ism330dhcx_gyro_get_channel()
472 ism330dhcx_gyro_convert(val, data->gyro[2], sensitivity); in ism330dhcx_gyro_get_channel()
476 ism330dhcx_gyro_convert(val++, data->gyro[i], sensitivity); in ism330dhcx_gyro_get_channel()
480 return -ENOTSUP; in ism330dhcx_gyro_get_channel()
489 struct ism330dhcx_data *data = dev->data; in ism330dhcx_gyro_channel_get()
491 return ism330dhcx_gyro_get_channel(dev, chan, val, data->gyro_gain); in ism330dhcx_gyro_channel_get()
498 struct ism330dhcx_data *data = dev->data; in ism330dhcx_gyro_channel_get_temp()
501 val->val1 = data->temp_sample / 256 + 25; in ism330dhcx_gyro_channel_get_temp()
502 val->val2 = (data->temp_sample % 256) * (1000000 / 256); in ism330dhcx_gyro_channel_get_temp()
514 val->val1 = (int32_t)dval / 1000000; in ism330dhcx_magn_convert()
515 val->val2 = (int32_t)dval % 1000000; in ism330dhcx_magn_convert()
521 struct ism330dhcx_data *data = dev->data; in ism330dhcx_magn_get_channel()
528 return -ENOTSUP; in ism330dhcx_magn_get_channel()
532 sample[0] = (int16_t)(data->ext_data[idx][0] | in ism330dhcx_magn_get_channel()
533 (data->ext_data[idx][1] << 8)); in ism330dhcx_magn_get_channel()
534 sample[1] = (int16_t)(data->ext_data[idx][2] | in ism330dhcx_magn_get_channel()
535 (data->ext_data[idx][3] << 8)); in ism330dhcx_magn_get_channel()
536 sample[2] = (int16_t)(data->ext_data[idx][4] | in ism330dhcx_magn_get_channel()
537 (data->ext_data[idx][5] << 8)); in ism330dhcx_magn_get_channel()
541 ism330dhcx_magn_convert(val, sample[0], data->magn_gain); in ism330dhcx_magn_get_channel()
544 ism330dhcx_magn_convert(val, sample[1], data->magn_gain); in ism330dhcx_magn_get_channel()
547 ism330dhcx_magn_convert(val, sample[2], data->magn_gain); in ism330dhcx_magn_get_channel()
550 ism330dhcx_magn_convert(val, sample[0], data->magn_gain); in ism330dhcx_magn_get_channel()
551 ism330dhcx_magn_convert(val + 1, sample[1], data->magn_gain); in ism330dhcx_magn_get_channel()
552 ism330dhcx_magn_convert(val + 2, sample[2], data->magn_gain); in ism330dhcx_magn_get_channel()
555 return -ENOTSUP; in ism330dhcx_magn_get_channel()
563 struct ism330dhcx_data *data = dev->data; in ism330dhcx_hum_convert()
566 struct hts221_data *ht = &data->hts221; in ism330dhcx_hum_convert()
575 raw_val = ((int16_t)(data->ext_data[idx][0] | in ism330dhcx_hum_convert()
576 (data->ext_data[idx][1] << 8))); in ism330dhcx_hum_convert()
579 rh = (ht->y1 - ht->y0) * raw_val + ht->x1 * ht->y0 - ht->x0 * ht->y1; in ism330dhcx_hum_convert()
580 rh /= (ht->x1 - ht->x0); in ism330dhcx_hum_convert()
583 val->val1 = rh; in ism330dhcx_hum_convert()
584 val->val2 = rh * 1000000; in ism330dhcx_hum_convert()
589 struct ism330dhcx_data *data = dev->data; in ism330dhcx_press_convert()
599 raw_val = (int32_t)(data->ext_data[idx][0] | in ism330dhcx_press_convert()
600 (data->ext_data[idx][1] << 8) | in ism330dhcx_press_convert()
601 (data->ext_data[idx][2] << 16)); in ism330dhcx_press_convert()
605 val->val1 = (raw_val >> 12) / 10; in ism330dhcx_press_convert()
606 val->val2 = (raw_val >> 12) % 10 * 100000 + in ism330dhcx_press_convert()
612 struct ism330dhcx_data *data = dev->data; in ism330dhcx_temp_convert()
622 raw_val = (int16_t)(data->ext_data[idx][3] | in ism330dhcx_temp_convert()
623 (data->ext_data[idx][4] << 8)); in ism330dhcx_temp_convert()
626 val->val1 = raw_val / 100; in ism330dhcx_temp_convert()
627 val->val2 = (int32_t)raw_val % 100 * (10000); in ism330dhcx_temp_convert()
674 return -ENOTSUP; in ism330dhcx_channel_get()
691 const struct ism330dhcx_config * const cfg = dev->config; in ism330dhcx_init_chip()
692 struct ism330dhcx_data *ism330dhcx = dev->data; in ism330dhcx_init_chip()
695 ism330dhcx->dev = dev; in ism330dhcx_init_chip()
697 if (ism330dhcx_device_id_get(ism330dhcx->ctx, &chip_id) < 0) { in ism330dhcx_init_chip()
699 return -EIO; in ism330dhcx_init_chip()
706 return -EIO; in ism330dhcx_init_chip()
710 if (ism330dhcx_reset_set(ism330dhcx->ctx, 1) < 0) { in ism330dhcx_init_chip()
711 return -EIO; in ism330dhcx_init_chip()
716 LOG_DBG("accel range is %d", cfg->accel_range); in ism330dhcx_init_chip()
717 if (ism330dhcx_accel_range_set(dev, cfg->accel_range) < 0) { in ism330dhcx_init_chip()
718 LOG_DBG("failed to set accelerometer full-scale"); in ism330dhcx_init_chip()
719 return -EIO; in ism330dhcx_init_chip()
722 LOG_DBG("accel odr is %d", cfg->accel_odr); in ism330dhcx_init_chip()
723 if (ism330dhcx_accel_set_odr_raw(dev, cfg->accel_odr) < 0) { in ism330dhcx_init_chip()
725 return -EIO; in ism330dhcx_init_chip()
728 LOG_DBG("gyro range is %d", cfg->gyro_range); in ism330dhcx_init_chip()
729 if (ism330dhcx_gyro_range_set(dev, cfg->gyro_range) < 0) { in ism330dhcx_init_chip()
730 LOG_DBG("failed to set gyroscope full-scale"); in ism330dhcx_init_chip()
731 return -EIO; in ism330dhcx_init_chip()
734 LOG_DBG("gyro odr is %d", cfg->gyro_odr); in ism330dhcx_init_chip()
735 ism330dhcx->gyro_freq = ism330dhcx_odr_to_freq_val(cfg->gyro_odr); in ism330dhcx_init_chip()
736 if (ism330dhcx_gyro_set_odr_raw(dev, cfg->gyro_odr) < 0) { in ism330dhcx_init_chip()
738 return -EIO; in ism330dhcx_init_chip()
742 if (ism330dhcx_fifo_mode_set(ism330dhcx->ctx, ISM330DHCX_BYPASS_MODE) < 0) { in ism330dhcx_init_chip()
744 return -EIO; in ism330dhcx_init_chip()
747 if (ism330dhcx_block_data_update_set(ism330dhcx->ctx, 1) < 0) { in ism330dhcx_init_chip()
749 return -EIO; in ism330dhcx_init_chip()
757 const struct ism330dhcx_config * const config = dev->config; in ism330dhcx_init()
759 config->bus_init(dev); in ism330dhcx_init()
763 return -EIO; in ism330dhcx_init()
767 if (config->drdy_gpio.port) { in ism330dhcx_init()
770 return -EIO; in ism330dhcx_init()
778 return -EIO; in ism330dhcx_init()