Lines Matching +full:gyro +full:- +full:odr

1 /* lsm6dsl.c - Driver for LSM6DSL accelerometer, gyroscope and
8 * SPDX-License-Identifier: Apache-2.0
42 return -EINVAL; in lsm6dsl_freq_to_odr_val()
46 static int lsm6dsl_odr_to_freq_val(uint16_t odr) in lsm6dsl_odr_to_freq_val() argument
49 if (odr < ARRAY_SIZE(lsm6dsl_odr_map)) { in lsm6dsl_odr_to_freq_val()
50 return lsm6dsl_odr_map[odr]; in lsm6dsl_odr_to_freq_val()
72 return -EINVAL; in lsm6dsl_accel_range_to_fs_val()
90 return -EINVAL; in lsm6dsl_gyro_range_to_fs_val()
96 struct lsm6dsl_data *data = dev->data; in lsm6dsl_reboot()
98 if (data->hw_tf->update_reg(dev, LSM6DSL_REG_CTRL3_C, in lsm6dsl_reboot()
101 return -EIO; in lsm6dsl_reboot()
104 /* Wait sensor turn-on time as per datasheet */ in lsm6dsl_reboot()
112 struct lsm6dsl_data *data = dev->data; in lsm6dsl_accel_set_fs_raw()
114 if (data->hw_tf->update_reg(dev, in lsm6dsl_accel_set_fs_raw()
118 return -EIO; in lsm6dsl_accel_set_fs_raw()
124 static int lsm6dsl_accel_set_odr_raw(const struct device *dev, uint8_t odr) in lsm6dsl_accel_set_odr_raw() argument
126 struct lsm6dsl_data *data = dev->data; in lsm6dsl_accel_set_odr_raw()
128 if (data->hw_tf->update_reg(dev, in lsm6dsl_accel_set_odr_raw()
131 odr << LSM6DSL_SHIFT_CTRL1_XL_ODR_XL) < 0) { in lsm6dsl_accel_set_odr_raw()
132 return -EIO; in lsm6dsl_accel_set_odr_raw()
135 data->accel_freq = lsm6dsl_odr_to_freq_val(odr); in lsm6dsl_accel_set_odr_raw()
142 struct lsm6dsl_data *data = dev->data; in lsm6dsl_gyro_set_fs_raw()
145 if (data->hw_tf->update_reg(dev, in lsm6dsl_gyro_set_fs_raw()
149 return -EIO; in lsm6dsl_gyro_set_fs_raw()
152 if (data->hw_tf->update_reg(dev, in lsm6dsl_gyro_set_fs_raw()
156 return -EIO; in lsm6dsl_gyro_set_fs_raw()
163 static int lsm6dsl_gyro_set_odr_raw(const struct device *dev, uint8_t odr) in lsm6dsl_gyro_set_odr_raw() argument
165 struct lsm6dsl_data *data = dev->data; in lsm6dsl_gyro_set_odr_raw()
167 if (data->hw_tf->update_reg(dev, in lsm6dsl_gyro_set_odr_raw()
170 odr << LSM6DSL_SHIFT_CTRL2_G_ODR_G) < 0) { in lsm6dsl_gyro_set_odr_raw()
171 return -EIO; in lsm6dsl_gyro_set_odr_raw()
174 data->gyro_freq = lsm6dsl_odr_to_freq_val(odr); in lsm6dsl_gyro_set_odr_raw()
182 int odr; in lsm6dsl_accel_odr_set() local
184 odr = lsm6dsl_freq_to_odr_val(freq); in lsm6dsl_accel_odr_set()
185 if (odr < 0) { in lsm6dsl_accel_odr_set()
186 return odr; in lsm6dsl_accel_odr_set()
189 if (lsm6dsl_accel_set_odr_raw(dev, odr) < 0) { in lsm6dsl_accel_odr_set()
191 return -EIO; in lsm6dsl_accel_odr_set()
202 struct lsm6dsl_data *data = dev->data; in lsm6dsl_accel_range_set()
210 LOG_DBG("failed to set accelerometer full-scale"); in lsm6dsl_accel_range_set()
211 return -EIO; in lsm6dsl_accel_range_set()
214 data->accel_sensitivity = (float)(lsm6dsl_accel_fs_sens[fs] in lsm6dsl_accel_range_set()
232 return lsm6dsl_accel_odr_set(dev, val->val1); in lsm6dsl_accel_config()
236 return -ENOTSUP; in lsm6dsl_accel_config()
245 int odr; in lsm6dsl_gyro_odr_set() local
247 odr = lsm6dsl_freq_to_odr_val(freq); in lsm6dsl_gyro_odr_set()
248 if (odr < 0) { in lsm6dsl_gyro_odr_set()
249 return odr; in lsm6dsl_gyro_odr_set()
252 if (lsm6dsl_gyro_set_odr_raw(dev, odr) < 0) { in lsm6dsl_gyro_odr_set()
254 return -EIO; in lsm6dsl_gyro_odr_set()
265 struct lsm6dsl_data *data = dev->data; in lsm6dsl_gyro_range_set()
273 LOG_DBG("failed to set gyroscope full-scale"); in lsm6dsl_gyro_range_set()
274 return -EIO; in lsm6dsl_gyro_range_set()
277 data->gyro_sensitivity = (float)(lsm6dsl_gyro_fs_sens[fs] in lsm6dsl_gyro_range_set()
295 return lsm6dsl_gyro_odr_set(dev, val->val1); in lsm6dsl_gyro_config()
298 LOG_DBG("Gyro attribute not supported."); in lsm6dsl_gyro_config()
299 return -ENOTSUP; in lsm6dsl_gyro_config()
317 return -ENOTSUP; in lsm6dsl_attr_set()
325 struct lsm6dsl_data *data = dev->data; in lsm6dsl_sample_fetch_accel()
328 if (data->hw_tf->read_data(dev, LSM6DSL_REG_OUTX_L_XL, in lsm6dsl_sample_fetch_accel()
331 return -EIO; in lsm6dsl_sample_fetch_accel()
334 data->accel_sample_x = (int16_t)((uint16_t)(buf[0]) | in lsm6dsl_sample_fetch_accel()
336 data->accel_sample_y = (int16_t)((uint16_t)(buf[2]) | in lsm6dsl_sample_fetch_accel()
338 data->accel_sample_z = (int16_t)((uint16_t)(buf[4]) | in lsm6dsl_sample_fetch_accel()
346 struct lsm6dsl_data *data = dev->data; in lsm6dsl_sample_fetch_gyro()
349 if (data->hw_tf->read_data(dev, LSM6DSL_REG_OUTX_L_G, in lsm6dsl_sample_fetch_gyro()
352 return -EIO; in lsm6dsl_sample_fetch_gyro()
355 data->gyro_sample_x = (int16_t)((uint16_t)(buf[0]) | in lsm6dsl_sample_fetch_gyro()
357 data->gyro_sample_y = (int16_t)((uint16_t)(buf[2]) | in lsm6dsl_sample_fetch_gyro()
359 data->gyro_sample_z = (int16_t)((uint16_t)(buf[4]) | in lsm6dsl_sample_fetch_gyro()
368 struct lsm6dsl_data *data = dev->data; in lsm6dsl_sample_fetch_temp()
371 if (data->hw_tf->read_data(dev, LSM6DSL_REG_OUT_TEMP_L, in lsm6dsl_sample_fetch_temp()
374 return -EIO; in lsm6dsl_sample_fetch_temp()
377 data->temp_sample = (int16_t)((uint16_t)(buf[0]) | in lsm6dsl_sample_fetch_temp()
387 struct lsm6dsl_data *data = dev->data; in lsm6dsl_sample_fetch_magn()
392 return -EIO; in lsm6dsl_sample_fetch_magn()
395 data->magn_sample_x = (int16_t)((uint16_t)(buf[0]) | in lsm6dsl_sample_fetch_magn()
397 data->magn_sample_y = (int16_t)((uint16_t)(buf[2]) | in lsm6dsl_sample_fetch_magn()
399 data->magn_sample_z = (int16_t)((uint16_t)(buf[4]) | in lsm6dsl_sample_fetch_magn()
408 struct lsm6dsl_data *data = dev->data; in lsm6dsl_sample_fetch_press()
413 return -EIO; in lsm6dsl_sample_fetch_press()
416 data->sample_press = (int32_t)((uint32_t)(buf[0]) | in lsm6dsl_sample_fetch_press()
419 data->sample_temp = (int16_t)((uint16_t)(buf[3]) | in lsm6dsl_sample_fetch_press()
466 return -ENOTSUP; in lsm6dsl_sample_fetch()
490 lsm6dsl_accel_convert(val, data->accel_sample_x, sensitivity); in lsm6dsl_accel_get_channel()
493 lsm6dsl_accel_convert(val, data->accel_sample_y, sensitivity); in lsm6dsl_accel_get_channel()
496 lsm6dsl_accel_convert(val, data->accel_sample_z, sensitivity); in lsm6dsl_accel_get_channel()
499 lsm6dsl_accel_convert(val, data->accel_sample_x, sensitivity); in lsm6dsl_accel_get_channel()
500 lsm6dsl_accel_convert(val + 1, data->accel_sample_y, in lsm6dsl_accel_get_channel()
502 lsm6dsl_accel_convert(val + 2, data->accel_sample_z, in lsm6dsl_accel_get_channel()
506 return -ENOTSUP; in lsm6dsl_accel_get_channel()
517 data->accel_sensitivity); in lsm6dsl_accel_channel_get()
538 lsm6dsl_gyro_convert(val, data->gyro_sample_x, sensitivity); in lsm6dsl_gyro_get_channel()
541 lsm6dsl_gyro_convert(val, data->gyro_sample_y, sensitivity); in lsm6dsl_gyro_get_channel()
544 lsm6dsl_gyro_convert(val, data->gyro_sample_z, sensitivity); in lsm6dsl_gyro_get_channel()
547 lsm6dsl_gyro_convert(val, data->gyro_sample_x, sensitivity); in lsm6dsl_gyro_get_channel()
548 lsm6dsl_gyro_convert(val + 1, data->gyro_sample_y, sensitivity); in lsm6dsl_gyro_get_channel()
549 lsm6dsl_gyro_convert(val + 2, data->gyro_sample_z, sensitivity); in lsm6dsl_gyro_get_channel()
552 return -ENOTSUP; in lsm6dsl_gyro_get_channel()
563 data->gyro_sensitivity); in lsm6dsl_gyro_channel_get()
571 val->val1 = data->temp_sample / 256 + 25; in lsm6dsl_gyro_channel_get_temp()
572 val->val2 = (data->temp_sample % 256) * (1000000 / 256); in lsm6dsl_gyro_channel_get_temp()
584 val->val1 = (int32_t)dval / 1000000; in lsm6dsl_magn_convert()
585 val->val2 = (int32_t)dval % 1000000; in lsm6dsl_magn_convert()
595 data->magn_sample_x, in lsm6dsl_magn_get_channel()
596 data->magn_sensitivity); in lsm6dsl_magn_get_channel()
600 data->magn_sample_y, in lsm6dsl_magn_get_channel()
601 data->magn_sensitivity); in lsm6dsl_magn_get_channel()
605 data->magn_sample_z, in lsm6dsl_magn_get_channel()
606 data->magn_sensitivity); in lsm6dsl_magn_get_channel()
610 data->magn_sample_x, in lsm6dsl_magn_get_channel()
611 data->magn_sensitivity); in lsm6dsl_magn_get_channel()
613 data->magn_sample_y, in lsm6dsl_magn_get_channel()
614 data->magn_sensitivity); in lsm6dsl_magn_get_channel()
616 data->magn_sample_z, in lsm6dsl_magn_get_channel()
617 data->magn_sensitivity); in lsm6dsl_magn_get_channel()
620 return -ENOTSUP; in lsm6dsl_magn_get_channel()
640 val->val1 = (raw_val >> 12) / 10; in lps22hb_press_convert()
641 val->val2 = (raw_val >> 12) % 10 * 100000 + in lps22hb_press_convert()
649 val->val1 = raw_val / 100; in lps22hb_temp_convert()
650 val->val2 = (int32_t)raw_val % 100 * (10000); in lps22hb_temp_convert()
658 struct lsm6dsl_data *data = dev->data; in lsm6dsl_channel_get()
688 lps22hb_press_convert(val, data->sample_press); in lsm6dsl_channel_get()
692 lps22hb_temp_convert(val, data->sample_temp); in lsm6dsl_channel_get()
696 return -ENOTSUP; in lsm6dsl_channel_get()
713 struct lsm6dsl_data *data = dev->data; in lsm6dsl_init_chip()
718 return -EIO; in lsm6dsl_init_chip()
721 if (data->hw_tf->read_reg(dev, LSM6DSL_REG_WHO_AM_I, &chip_id) < 0) { in lsm6dsl_init_chip()
723 return -EIO; in lsm6dsl_init_chip()
727 return -EIO; in lsm6dsl_init_chip()
734 LOG_DBG("failed to set accelerometer full-scale"); in lsm6dsl_init_chip()
735 return -EIO; in lsm6dsl_init_chip()
737 data->accel_sensitivity = LSM6DSL_DEFAULT_ACCEL_SENSITIVITY; in lsm6dsl_init_chip()
741 return -EIO; in lsm6dsl_init_chip()
745 LOG_DBG("failed to set gyroscope full-scale"); in lsm6dsl_init_chip()
746 return -EIO; in lsm6dsl_init_chip()
748 data->gyro_sensitivity = LSM6DSL_DEFAULT_GYRO_SENSITIVITY; in lsm6dsl_init_chip()
752 return -EIO; in lsm6dsl_init_chip()
755 if (data->hw_tf->update_reg(dev, in lsm6dsl_init_chip()
760 return -EIO; in lsm6dsl_init_chip()
763 if (data->hw_tf->update_reg(dev, in lsm6dsl_init_chip()
772 return -EIO; in lsm6dsl_init_chip()
775 if (data->hw_tf->update_reg(dev, in lsm6dsl_init_chip()
780 return -EIO; in lsm6dsl_init_chip()
783 if (data->hw_tf->update_reg(dev, in lsm6dsl_init_chip()
788 return -EIO; in lsm6dsl_init_chip()
797 const struct lsm6dsl_config * const config = dev->config; in lsm6dsl_init()
799 ret = config->bus_init(dev); in lsm6dsl_init()
834 struct lsm6dsl_data *data = dev->data; in lsm6dsl_pm_action()
835 int ret = -EIO; in lsm6dsl_pm_action()
841 /* Restore saved ODR values */ in lsm6dsl_pm_action()
842 accel_odr = lsm6dsl_freq_to_odr_val(data->accel_freq); in lsm6dsl_pm_action()
848 gyro_odr = lsm6dsl_freq_to_odr_val(data->gyro_freq); in lsm6dsl_pm_action()
851 LOG_ERR("Failed to resume gyro"); in lsm6dsl_pm_action()
857 * Set accelerometer ODR to power-down. Don't use the direct in lsm6dsl_pm_action()
860 ret = data->hw_tf->update_reg(dev, LSM6DSL_REG_CTRL1_XL, in lsm6dsl_pm_action()
866 /* Set gyro ODR to power-down */ in lsm6dsl_pm_action()
867 ret = data->hw_tf->update_reg(dev, LSM6DSL_REG_CTRL2_G, in lsm6dsl_pm_action()
870 LOG_ERR("Failed to suspend gyro"); in lsm6dsl_pm_action()
876 return -ENOTSUP; in lsm6dsl_pm_action()
951 * bus-specific macro at preprocessor time.