Lines Matching +full:reset +full:- +full:val

5  * SPDX-License-Identifier: Apache-2.0
19 #define RANGE2FS(x) (__builtin_ctz(x) - 1)
29 const struct fxos8700_config *cfg = dev->config; in fxos8700_transceive()
33 return spi_transceive_dt(&cfg->bus_cfg.spi, &s, &s); in fxos8700_transceive()
41 const struct fxos8700_config *cfg = dev->config; in fxos8700_read_spi()
52 return spi_transceive_dt(&cfg->bus_cfg.spi, &tx, &rx); in fxos8700_read_spi()
82 uint8_t val) in fxos8700_reg_field_update_spi() argument
87 return -EIO; in fxos8700_reg_field_update_spi()
90 return fxos8700_byte_write_spi(dev, reg, (old_val & ~mask) | (val & mask)); in fxos8700_reg_field_update_spi()
107 const struct fxos8700_config *config = dev->config; in fxos8700_read_i2c()
109 return i2c_burst_read_dt(&config->bus_cfg.i2c, reg, data, length); in fxos8700_read_i2c()
116 const struct fxos8700_config *config = dev->config; in fxos8700_byte_read_i2c()
118 return i2c_reg_read_byte_dt(&config->bus_cfg.i2c, reg, byte); in fxos8700_byte_read_i2c()
125 const struct fxos8700_config *config = dev->config; in fxos8700_byte_write_i2c()
127 return i2c_reg_write_byte_dt(&config->bus_cfg.i2c, reg, byte); in fxos8700_byte_write_i2c()
133 uint8_t val) in fxos8700_reg_field_update_i2c() argument
135 const struct fxos8700_config *config = dev->config; in fxos8700_reg_field_update_i2c()
137 return i2c_reg_update_byte_dt(&config->bus_cfg.i2c, reg, mask, val); in fxos8700_reg_field_update_i2c()
148 const struct sensor_value *val) in fxos8700_set_odr() argument
150 const struct fxos8700_config *config = dev->config; in fxos8700_set_odr()
156 if (val->val1 == 400 && val->val2 == 0) { in fxos8700_set_odr()
158 } else if (val->val1 == 200 && val->val2 == 0) { in fxos8700_set_odr()
160 } else if (val->val1 == 100 && val->val2 == 0) { in fxos8700_set_odr()
162 } else if (val->val1 == 50 && val->val2 == 0) { in fxos8700_set_odr()
164 } else if (val->val1 == 25 && val->val2 == 0) { in fxos8700_set_odr()
166 } else if (val->val1 == 6 && val->val2 == 250000) { in fxos8700_set_odr()
168 } else if (val->val1 == 3 && val->val2 == 125000) { in fxos8700_set_odr()
170 } else if (val->val1 == 0 && val->val2 == 781300) { in fxos8700_set_odr()
173 return -EINVAL; in fxos8700_set_odr()
176 if (val->val1 == 800 && val->val2 == 0) { in fxos8700_set_odr()
178 } else if (val->val1 == 400 && val->val2 == 0) { in fxos8700_set_odr()
180 } else if (val->val1 == 200 && val->val2 == 0) { in fxos8700_set_odr()
182 } else if (val->val1 == 100 && val->val2 == 0) { in fxos8700_set_odr()
184 } else if (val->val1 == 50 && val->val2 == 0) { in fxos8700_set_odr()
186 } else if (val->val1 == 12 && val->val2 == 500000) { in fxos8700_set_odr()
188 } else if (val->val1 == 6 && val->val2 == 250000) { in fxos8700_set_odr()
190 } else if (val->val1 == 1 && val->val2 == 562500) { in fxos8700_set_odr()
193 return -EINVAL; in fxos8700_set_odr()
205 return -EIO; in fxos8700_set_odr()
211 return -EIO; in fxos8700_set_odr()
215 return config->ops->reg_field_update(dev, FXOS8700_REG_CTRLREG1, in fxos8700_set_odr()
221 const struct sensor_value *val) in fxos8700_set_mt_ths() argument
224 const struct fxos8700_config *config = dev->config; in fxos8700_set_mt_ths()
225 uint64_t micro_ms2 = abs(val->val1 * 1000000LL + val->val2); in fxos8700_set_mt_ths()
230 return -EINVAL; in fxos8700_set_mt_ths()
235 return config->ops->reg_field_update(dev, FXOS8700_REG_FF_MT_THS, in fxos8700_set_mt_ths()
238 return -ENOTSUP; in fxos8700_set_mt_ths()
245 const struct sensor_value *val) in fxos8700_attr_set() argument
248 return -ENOTSUP; in fxos8700_attr_set()
252 return fxos8700_set_odr(dev, val); in fxos8700_attr_set()
254 return fxos8700_set_mt_ths(dev, val); in fxos8700_attr_set()
256 return -ENOTSUP; in fxos8700_attr_set()
265 const struct fxos8700_config *config = dev->config; in fxos8700_sample_fetch()
266 struct fxos8700_data *data = dev->data; in fxos8700_sample_fetch()
275 return -ENOTSUP; in fxos8700_sample_fetch()
278 k_sem_take(&data->sem, K_FOREVER); in fxos8700_sample_fetch()
282 * configuration (accel-only, mag-only, or hybrid). in fxos8700_sample_fetch()
284 num_bytes = config->num_channels * FXOS8700_BYTES_PER_CHANNEL_NORMAL; in fxos8700_sample_fetch()
288 if (config->ops->read(dev, config->start_addr, buffer, num_bytes)) { in fxos8700_sample_fetch()
290 ret = -EIO; in fxos8700_sample_fetch()
294 /* Parse the buffer into raw channel data (16-bit integers). To save in fxos8700_sample_fetch()
298 __ASSERT(config->start_channel + config->num_channels in fxos8700_sample_fetch()
299 <= ARRAY_SIZE(data->raw), in fxos8700_sample_fetch()
302 raw = &data->raw[config->start_channel]; in fxos8700_sample_fetch()
309 if (config->ops->byte_read(dev, FXOS8700_REG_TEMP, in fxos8700_sample_fetch()
310 &data->temp)) { in fxos8700_sample_fetch()
312 ret = -EIO; in fxos8700_sample_fetch()
318 k_sem_give(&data->sem); in fxos8700_sample_fetch()
323 static void fxos8700_accel_convert(struct sensor_value *val, int16_t raw, in fxos8700_accel_convert() argument
331 * - 2g mode (fs = 0) has 14 fractional bits in fxos8700_accel_convert()
332 * - 4g mode (fs = 1) has 13 fractional bits in fxos8700_accel_convert()
333 * - 8g mode (fs = 2) has 12 fractional bits in fxos8700_accel_convert()
335 frac_bits = 14 - RANGE2FS(range); in fxos8700_accel_convert()
343 * always fits into 32-bits. Cast down to int32_t so we can use a in fxos8700_accel_convert()
346 val->val1 = (int32_t) micro_ms2 / 1000000; in fxos8700_accel_convert()
347 val->val2 = (int32_t) micro_ms2 % 1000000; in fxos8700_accel_convert()
350 static void fxos8700_magn_convert(struct sensor_value *val, int16_t raw) in fxos8700_magn_convert() argument
359 val->val1 = micro_g / 1000000; in fxos8700_magn_convert()
360 val->val2 = micro_g % 1000000; in fxos8700_magn_convert()
364 static void fxos8700_temp_convert(struct sensor_value *val, int8_t raw) in fxos8700_temp_convert() argument
373 val->val1 = micro_c / 1000000; in fxos8700_temp_convert()
374 val->val2 = micro_c % 1000000; in fxos8700_temp_convert()
380 struct sensor_value *val) in fxos8700_channel_get() argument
382 const struct fxos8700_config *config = dev->config; in fxos8700_channel_get()
383 struct fxos8700_data *data = dev->data; in fxos8700_channel_get()
390 k_sem_take(&data->sem, K_FOREVER); in fxos8700_channel_get()
395 ret = -ENOTSUP; in fxos8700_channel_get()
397 /* If we're in an accelerometer-enabled mode (accel-only or hybrid), in fxos8700_channel_get()
401 if (config->mode != FXOS8700_MODE_MAGN) { in fxos8700_channel_get()
425 raw = &data->raw[start_channel]; in fxos8700_channel_get()
427 fxos8700_accel_convert(val++, *raw++, config->range); in fxos8700_channel_get()
435 /* If we're in an magnetometer-enabled mode (mag-only or hybrid), then in fxos8700_channel_get()
438 if (config->mode != FXOS8700_MODE_ACCEL) { in fxos8700_channel_get()
462 raw = &data->raw[start_channel]; in fxos8700_channel_get()
464 fxos8700_magn_convert(val++, *raw++); in fxos8700_channel_get()
472 fxos8700_temp_convert(val, data->temp); in fxos8700_channel_get()
482 k_sem_give(&data->sem); in fxos8700_channel_get()
489 const struct fxos8700_config *config = dev->config; in fxos8700_get_power()
490 uint8_t val; in fxos8700_get_power() local
492 if (config->ops->byte_read(dev, FXOS8700_REG_CTRLREG1, &val)) { in fxos8700_get_power()
494 return -EIO; in fxos8700_get_power()
496 val &= FXOS8700_M_CTRLREG1_MODE_MASK; in fxos8700_get_power()
497 *power = val; in fxos8700_get_power()
504 const struct fxos8700_config *config = dev->config; in fxos8700_set_power()
506 return config->ops->reg_field_update(dev, FXOS8700_REG_CTRLREG1, in fxos8700_set_power()
512 const struct fxos8700_config *config = dev->config; in fxos8700_init()
513 struct fxos8700_data *data = dev->data; in fxos8700_init()
517 if (config->inst_on_bus == FXOS8700_BUS_I2C) { in fxos8700_init()
518 if (!device_is_ready(config->bus_cfg.i2c.bus)) { in fxos8700_init()
520 return -ENODEV; in fxos8700_init()
526 if (config->inst_on_bus == FXOS8700_BUS_SPI) { in fxos8700_init()
527 if (!device_is_ready(config->bus_cfg.spi.bus)) { in fxos8700_init()
529 return -ENODEV; in fxos8700_init()
534 if (config->reset_gpio.port) { in fxos8700_init()
535 /* Pulse RST pin high to perform a hardware reset of in fxos8700_init()
539 if (!gpio_is_ready_dt(&config->reset_gpio)) { in fxos8700_init()
541 return -ENODEV; in fxos8700_init()
544 gpio_pin_configure_dt(&config->reset_gpio, GPIO_OUTPUT_INACTIVE); in fxos8700_init()
546 gpio_pin_set_dt(&config->reset_gpio, 1); in fxos8700_init()
548 * the RST pin high in order to reset. Stay on the in fxos8700_init()
552 gpio_pin_set_dt(&config->reset_gpio, 0); in fxos8700_init()
554 /* Software reset the sensor. Upon issuing a software in fxos8700_init()
555 * reset command over the I2C interface, the sensor in fxos8700_init()
561 config->ops->byte_write(dev, FXOS8700_REG_CTRLREG2, in fxos8700_init()
565 /* The sensor requires us to wait 1 ms after a reset before in fxos8700_init()
575 if (config->ops->byte_read(dev, FXOS8700_REG_WHOAMI, in fxos8700_init()
576 &data->whoami)) { in fxos8700_init()
578 return -EIO; in fxos8700_init()
581 switch (data->whoami) { in fxos8700_init()
585 if (config->mode != FXOS8700_MODE_ACCEL) { in fxos8700_init()
588 data->whoami); in fxos8700_init()
589 return -EIO; in fxos8700_init()
593 LOG_DBG("Device ID 0x%x", data->whoami); in fxos8700_init()
596 LOG_ERR("Unknown Device ID 0x%x", data->whoami); in fxos8700_init()
597 return -EIO; in fxos8700_init()
602 return -EIO; in fxos8700_init()
605 if (config->ops->reg_field_update(dev, FXOS8700_REG_CTRLREG2, in fxos8700_init()
607 config->power_mode)) { in fxos8700_init()
609 return -EIO; in fxos8700_init()
612 /* Set the mode (accel-only, mag-only, or hybrid) */ in fxos8700_init()
613 if (config->ops->reg_field_update(dev, FXOS8700_REG_M_CTRLREG1, in fxos8700_init()
615 config->mode)) { in fxos8700_init()
617 return -EIO; in fxos8700_init()
623 if (config->ops->reg_field_update(dev, FXOS8700_REG_M_CTRLREG2, in fxos8700_init()
627 return -EIO; in fxos8700_init()
630 /* Set the full-scale range */ in fxos8700_init()
631 if (config->ops->reg_field_update(dev, FXOS8700_REG_XYZ_DATA_CFG, in fxos8700_init()
633 RANGE2FS(config->range))) { in fxos8700_init()
635 return -EIO; in fxos8700_init()
638 k_sem_init(&data->sem, 0, K_SEM_MAX_LIMIT); in fxos8700_init()
643 return -EIO; in fxos8700_init()
650 return -EIO; in fxos8700_init()
652 k_sem_give(&data->sem); in fxos8700_init()