Lines Matching +full:divide +full:- +full:10
5 * SPDX-License-Identifier: Apache-2.0
26 const struct fxls8974_config *cfg = dev->config; in fxls8974_transceive()
30 return spi_transceive_dt(&cfg->bus_cfg.spi, &s, &s); in fxls8974_transceive()
38 const struct fxls8974_config *cfg = dev->config; in fxls8974_read_spi()
49 return spi_transceive_dt(&cfg->bus_cfg.spi, &tx, &rx); in fxls8974_read_spi()
84 return -EIO; in fxls8974_reg_field_update_spi()
104 const struct fxls8974_config *cfg = dev->config; in fxls8974_read_i2c()
106 return i2c_burst_read_dt(&cfg->bus_cfg.i2c, reg, data, length); in fxls8974_read_i2c()
113 const struct fxls8974_config *cfg = dev->config; in fxls8974_byte_read_i2c()
115 return i2c_reg_read_byte_dt(&cfg->bus_cfg.i2c, reg, byte); in fxls8974_byte_read_i2c()
122 const struct fxls8974_config *cfg = dev->config; in fxls8974_byte_write_i2c()
124 return i2c_reg_write_byte_dt(&cfg->bus_cfg.i2c, reg, byte); in fxls8974_byte_write_i2c()
132 const struct fxls8974_config *cfg = dev->config; in fxls8974_reg_field_update_i2c()
134 return i2c_reg_update_byte_dt(&cfg->bus_cfg.i2c, reg, mask, val); in fxls8974_reg_field_update_i2c()
147 const struct fxls8974_config *cfg = dev->config; in fxls8974_set_odr()
150 switch (val->val1) { in fxls8974_set_odr()
173 if (val->val2 == 500000) { in fxls8974_set_odr()
177 return -EINVAL; in fxls8974_set_odr()
179 if (val->val2 == 250000) { in fxls8974_set_odr()
183 return -EINVAL; in fxls8974_set_odr()
185 if (val->val2 == 125000) { in fxls8974_set_odr()
189 return -EINVAL; in fxls8974_set_odr()
191 if (val->val2 == 563000) { in fxls8974_set_odr()
195 return -EINVAL; in fxls8974_set_odr()
197 if (val->val2 == 781000) { in fxls8974_set_odr()
201 return -EINVAL; in fxls8974_set_odr()
203 return -EINVAL; in fxls8974_set_odr()
210 return cfg->ops->reg_field_update(dev, FXLS8974_REG_CTRLREG3, in fxls8974_set_odr()
214 return cfg->ops->reg_field_update(dev, FXLS8974_REG_CTRLREG3, in fxls8974_set_odr()
226 return -ENOTSUP; in fxls8974_attr_set()
233 return -ENOTSUP; in fxls8974_attr_set()
240 const struct fxls8974_config *cfg = dev->config; in fxls8974_sample_fetch()
241 struct fxls8974_data *data = dev->data; in fxls8974_sample_fetch()
247 k_sem_take(&data->sem, K_FOREVER); in fxls8974_sample_fetch()
250 if (cfg->ops->read(dev, FXLS8974_REG_OUTXLSB, buf, FXLS8974_MAX_ACCEL_BYTES)) { in fxls8974_sample_fetch()
252 ret = -EIO; in fxls8974_sample_fetch()
256 if (cfg->ops->byte_read(dev, FXLS8974_REG_OUTTEMP, buf+FXLS8974_DATA_TEMP_OFFSET)) { in fxls8974_sample_fetch()
258 ret = -EIO; in fxls8974_sample_fetch()
262 /* Parse the buf into raw channel data (16-bit integers). To save in fxls8974_sample_fetch()
266 __ASSERT(FXLS8974_MAX_NUM_CHANNELS <= ARRAY_SIZE(data->raw), in fxls8974_sample_fetch()
269 raw = &data->raw[FXLS8974_CHANNEL_ACCEL_X]; in fxls8974_sample_fetch()
278 k_sem_give(&data->sem); in fxls8974_sample_fetch()
292 * always fits into 32-bits. Cast down to int32_t so we can use a in fxls8974_accel_convert()
293 * faster divide. in fxls8974_accel_convert()
295 val->val1 = (int32_t) micro_ms2 / 1000000; in fxls8974_accel_convert()
296 val->val2 = (int32_t) micro_ms2 % 1000000; in fxls8974_accel_convert()
302 const struct fxls8974_config *cfg = dev->config; in fxls8974_get_accel_data()
303 struct fxls8974_data *data = dev->data; in fxls8974_get_accel_data()
307 k_sem_take(&data->sem, K_FOREVER); in fxls8974_get_accel_data()
309 if (cfg->ops->byte_read(dev, FXLS8974_REG_CTRLREG1, &fsr)) { in fxls8974_get_accel_data()
311 return -EIO; in fxls8974_get_accel_data()
317 fsr = 10U; in fxls8974_get_accel_data()
331 raw = &data->raw[FXLS8974_CHANNEL_ACCEL_X]; in fxls8974_get_accel_data()
338 raw = &data->raw[FXLS8974_CHANNEL_ACCEL_X]; in fxls8974_get_accel_data()
341 raw = &data->raw[FXLS8974_CHANNEL_ACCEL_Y]; in fxls8974_get_accel_data()
344 raw = &data->raw[FXLS8974_CHANNEL_ACCEL_Z]; in fxls8974_get_accel_data()
347 return -ENOTSUP; in fxls8974_get_accel_data()
351 k_sem_give(&data->sem); in fxls8974_get_accel_data()
358 struct fxls8974_data *data = dev->data; in fxls8974_get_temp_data()
361 k_sem_take(&data->sem, K_FOREVER); in fxls8974_get_temp_data()
362 raw = &data->raw[FXLS8974_CHANNEL_TEMP]; in fxls8974_get_temp_data()
363 val->val1 = *raw+FXLS8974_ZERO_TEMP; in fxls8974_get_temp_data()
364 k_sem_give(&data->sem); in fxls8974_get_temp_data()
377 return -EIO; in fxls8974_channel_get()
383 return -EIO; in fxls8974_channel_get()
398 return -ENOTSUP; in fxls8974_channel_get()
406 const struct fxls8974_config *cfg = dev->config; in fxls8974_get_active()
409 if (cfg->ops->byte_read(dev, FXLS8974_REG_CTRLREG1, &val)) { in fxls8974_get_active()
411 return -EIO; in fxls8974_get_active()
422 const struct fxls8974_config *cfg = dev->config; in fxls8974_set_active()
424 return cfg->ops->reg_field_update(dev, FXLS8974_REG_CTRLREG1, in fxls8974_set_active()
430 const struct fxls8974_config *cfg = dev->config; in fxls8974_print_config()
433 if (cfg->ops->read(dev, FXLS8974_REG_CTRLREG1, regVal, 5)) { in fxls8974_print_config()
443 const struct fxls8974_config *cfg = dev->config; in fxls8974_init()
444 struct fxls8974_data *data = dev->data; in fxls8974_init()
449 const struct i2c_dt_spec i2c_spec = cfg->bus_cfg.i2c; in fxls8974_init()
451 if (cfg->inst_on_bus == FXLS8974_BUS_I2C) { in fxls8974_init()
454 return -ENODEV; in fxls8974_init()
460 const struct spi_dt_spec spi_spec = cfg->bus_cfg.spi; in fxls8974_init()
462 if (cfg->inst_on_bus == FXLS8974_BUS_SPI) { in fxls8974_init()
465 return -ENODEV; in fxls8974_init()
477 cfg->ops->byte_write(dev, FXLS8974_REG_CTRLREG1, in fxls8974_init()
490 if (cfg->ops->byte_read(dev, FXLS8974_REG_WHOAMI, in fxls8974_init()
491 &data->whoami)) { in fxls8974_init()
493 return -EIO; in fxls8974_init()
496 if (data->whoami == WHOAMI_ID_FXLS8974) { in fxls8974_init()
497 LOG_DBG("Device ID 0x%x, FXLS8974", data->whoami); in fxls8974_init()
499 LOG_ERR("Unknown Device ID 0x%x", data->whoami); in fxls8974_init()
500 return -EIO; in fxls8974_init()
505 return -EIO; in fxls8974_init()
510 return -EIO; in fxls8974_init()
513 if (cfg->ops->byte_write(dev, FXLS8974_REG_CTRLREG4, in fxls8974_init()
516 return -EIO; in fxls8974_init()
518 if (cfg->ops->byte_read(dev, FXLS8974_REG_CTRLREG4, ®Val)) { in fxls8974_init()
520 return -EIO; in fxls8974_init()
525 return -EIO; in fxls8974_init()
530 return -EIO; in fxls8974_init()
533 /* Set the +-2G mode */ in fxls8974_init()
534 if (cfg->ops->byte_write(dev, FXLS8974_REG_CTRLREG1, in fxls8974_init()
537 return -EIO; in fxls8974_init()
540 if (cfg->ops->byte_read(dev, FXLS8974_REG_CTRLREG1, in fxls8974_init()
543 return -EIO; in fxls8974_init()
548 return -EIO; in fxls8974_init()
551 k_sem_init(&data->sem, 0, K_SEM_MAX_LIMIT); in fxls8974_init()
556 return -EIO; in fxls8974_init()
562 return -EIO; in fxls8974_init()
567 return -EIO; in fxls8974_init()
572 return -EIO; in fxls8974_init()
576 k_sem_give(&data->sem); in fxls8974_init()