Lines Matching +full:tx +full:- +full:inst +full:- +full:mode
1 /* adxl362.c - ADXL362 Three-Axis Digital Accelerometers */
6 * SPDX-License-Identifier: Apache-2.0
29 const struct adxl362_config *cfg = dev->config; in adxl362_reg_access()
41 struct spi_buf_set tx = { in adxl362_reg_access() local
51 tx.count = 1; in adxl362_reg_access()
53 return spi_transceive_dt(&cfg->bus, &tx, &rx); in adxl362_reg_access()
56 tx.count = 2; in adxl362_reg_access()
58 return spi_write_dt(&cfg->bus, &tx); in adxl362_reg_access()
162 return -EINVAL; in adxl362_freq_to_odr_val()
173 return -EINVAL; in adxl362_freq_to_odr_val()
197 return -EINVAL; in adxl362_range_to_reg_val()
203 struct adxl362_data *adxl362_data = dev->data; in adxl362_set_range()
220 adxl362_data->selected_range = range; in adxl362_set_range()
229 struct adxl362_data *adxl362_data = dev->data; in adxl362_set_output_rate()
238 adxl362_data->accel_odr = out_rate; in adxl362_set_output_rate()
257 return -ENOTSUP; in axl362_acc_config()
269 out_rate = adxl362_freq_to_odr_val(val->val1, in axl362_acc_config()
270 val->val2 / 1000); in axl362_acc_config()
273 return -ENOTSUP; in axl362_acc_config()
282 return -ENOTSUP; in axl362_acc_config()
294 uint16_t threshold = val->val1; in adxl362_attr_set_thresh()
300 return -EINVAL; in adxl362_attr_set_thresh()
304 return -EINVAL; in adxl362_attr_set_thresh()
330 uint16_t timeout = val->val1; in adxl362_attr_set()
347 return -ENOTSUP; in adxl362_attr_set()
354 int adxl362_fifo_setup(const struct device *dev, uint8_t mode, in adxl362_fifo_setup() argument
357 static int adxl362_fifo_setup(const struct device *dev, uint8_t mode, in adxl362_fifo_setup()
364 struct adxl362_data *data = (struct adxl362_data *)dev->data; in adxl362_fifo_setup()
366 data->fifo_mode = mode; in adxl362_fifo_setup()
367 data->water_mark_lvl = water_mark_lvl; in adxl362_fifo_setup()
368 data->en_temp_read = en_temp_read; in adxl362_fifo_setup()
371 write_val = ADXL362_FIFO_CTL_FIFO_MODE(mode) | in adxl362_fifo_setup()
401 * mode in adxl362_setup_activity_detection()
403 * ADXL362_FIFO_DISABLE - FIFO is disabled. in adxl362_setup_activity_detection()
404 * ADXL362_FIFO_OLDEST_SAVED - Oldest saved mode. in adxl362_setup_activity_detection()
405 * ADXL362_FIFO_STREAM - Stream mode. in adxl362_setup_activity_detection()
406 * ADXL362_FIFO_TRIGGERED - Triggered mode. in adxl362_setup_activity_detection()
411 * 1 - temperature data is stored in the FIFO in adxl362_setup_activity_detection()
412 * together with x-, y- and x-axis data. in adxl362_setup_activity_detection()
413 * 0 - temperature data is skipped. in adxl362_setup_activity_detection()
492 int adxl362_set_interrupt_mode(const struct device *dev, uint8_t mode) in adxl362_set_interrupt_mode() argument
498 LOG_DBG("Mode: %d", mode); in adxl362_set_interrupt_mode()
500 if (mode != ADXL362_MODE_DEFAULT && in adxl362_set_interrupt_mode()
501 mode != ADXL362_MODE_LINK && in adxl362_set_interrupt_mode()
502 mode != ADXL362_MODE_LOOP) { in adxl362_set_interrupt_mode()
503 LOG_ERR("Wrong mode"); in adxl362_set_interrupt_mode()
504 return -EINVAL; in adxl362_set_interrupt_mode()
507 /* Select desired interrupt mode. */ in adxl362_set_interrupt_mode()
517 ADXL362_ACT_INACT_CTL_LINKLOOP(mode); in adxl362_set_interrupt_mode()
532 struct adxl362_data *data = dev->data; in adxl362_sample_fetch()
544 data->acc_x = sys_le16_to_cpu(buf[0]); in adxl362_sample_fetch()
545 data->acc_y = sys_le16_to_cpu(buf[1]); in adxl362_sample_fetch()
546 data->acc_z = sys_le16_to_cpu(buf[2]); in adxl362_sample_fetch()
547 data->temp = sys_le16_to_cpu(buf[3]); in adxl362_sample_fetch()
556 struct adxl362_data *data = dev->data; in adxl362_rtio_fetch()
567 sample_data->is_fifo = 0; in adxl362_rtio_fetch()
570 sample_data->acc_x = sys_le16_to_cpu(buf[0]); in adxl362_rtio_fetch()
571 sample_data->acc_y = sys_le16_to_cpu(buf[1]); in adxl362_rtio_fetch()
572 sample_data->acc_z = sys_le16_to_cpu(buf[2]); in adxl362_rtio_fetch()
573 sample_data->temp = sys_le16_to_cpu(buf[3]); in adxl362_rtio_fetch()
574 sample_data->selected_range = data->selected_range; in adxl362_rtio_fetch()
591 return -EINVAL; in adxl362_range_to_scale()
606 __ASSERT_NO_MSG(scale != -EINVAL); in adxl362_accel_convert()
608 val->val1 = micro_ms2 / 1000000; in adxl362_accel_convert()
609 val->val2 = micro_ms2 % 1000000; in adxl362_accel_convert()
619 int milli_c = (temp - ADXL362_TEMP_BIAS_LSB) * ADXL362_TEMP_MC_PER_LSB + in adxl362_temp_convert()
622 val->val1 = milli_c / 1000; in adxl362_temp_convert()
623 val->val2 = (milli_c % 1000) * 1000; in adxl362_temp_convert()
630 struct adxl362_data *data = dev->data; in adxl362_channel_get()
634 adxl362_accel_convert(val, data->acc_x, data->selected_range); in adxl362_channel_get()
637 adxl362_accel_convert(val, data->acc_y, data->selected_range); in adxl362_channel_get()
640 adxl362_accel_convert(val, data->acc_z, data->selected_range); in adxl362_channel_get()
644 adxl362_accel_convert(&val[i], data->acc_xyz[i], data->selected_range); in adxl362_channel_get()
648 adxl362_temp_convert(val, data->temp); in adxl362_channel_get()
651 return -ENOTSUP; in adxl362_channel_get()
672 const struct adxl362_config *config = dev->config; in adxl362_chip_init()
677 * 0 - absolute mode. in adxl362_chip_init()
678 * 1 - referenced mode. in adxl362_chip_init()
680 * 11-bit unsigned value that the adxl362 samples are in adxl362_chip_init()
683 * 8-bit value written to the activity timer register. in adxl362_chip_init()
686 * where ODR - is the output data rate. in adxl362_chip_init()
699 * 0 - absolute mode. in adxl362_chip_init()
700 * 1 - referenced mode. in adxl362_chip_init()
702 * 11-bit unsigned value that the adxl362 samples are in adxl362_chip_init()
705 * 16-bit value written to the activity timer register. in adxl362_chip_init()
708 * where ODR - is the output data rate. in adxl362_chip_init()
727 * ADXL362_RANGE_2G - +-2 g in adxl362_chip_init()
728 * ADXL362_RANGE_4G - +-4 g in adxl362_chip_init()
729 * ADXL362_RANGE_8G - +-8 g in adxl362_chip_init()
738 * ADXL362_ODR_12_5_HZ - 12.5Hz in adxl362_chip_init()
739 * ADXL362_ODR_25_HZ - 25Hz in adxl362_chip_init()
740 * ADXL362_ODR_50_HZ - 50Hz in adxl362_chip_init()
741 * ADXL362_ODR_100_HZ - 100Hz in adxl362_chip_init()
742 * ADXL362_ODR_200_HZ - 200Hz in adxl362_chip_init()
743 * ADXL362_ODR_400_HZ - 400Hz in adxl362_chip_init()
750 /* Places the device into measure mode, enable wakeup mode and autosleep if desired. */ in adxl362_chip_init()
751 LOG_DBG("setting pwrctl: 0x%02x", config->power_ctl); in adxl362_chip_init()
752 ret = adxl362_set_reg(dev, config->power_ctl, ADXL362_REG_POWER_CTL, 1); in adxl362_chip_init()
764 * @return 0 - the initialization was successful and the device is present;
765 * -1 - an error occurred.
770 const struct adxl362_config *config = dev->config; in adxl362_init()
774 if (!spi_is_ready_dt(&config->bus)) { in adxl362_init()
775 LOG_DBG("spi device not ready: %s", config->bus.bus->name); in adxl362_init()
776 return -EINVAL; in adxl362_init()
783 return -ENODEV; in adxl362_init()
791 return -ENODEV; in adxl362_init()
795 return -ENODEV; in adxl362_init()
799 if (config->interrupt.port) { in adxl362_init()
802 return -EIO; in adxl362_init()
806 config->int1_config, in adxl362_init()
807 config->int2_config) < 0) { in adxl362_init()
809 return -EIO; in adxl362_init()
819 #define ADXL362_RTIO_DEFINE(inst) \ argument
820 SPI_DT_IODEV_DEFINE(adxl362_iodev_##inst, DT_DRV_INST(inst), \
822 RTIO_DEFINE(adxl362_rtio_ctx_##inst, 8, 8);
824 #define ADXL362_DEFINE(inst) \ argument
825 IF_ENABLED(CONFIG_ADXL362_STREAM, (ADXL362_RTIO_DEFINE(inst))); \
826 static struct adxl362_data adxl362_data_##inst = { \
827 IF_ENABLED(CONFIG_ADXL362_STREAM, (.rtio_ctx = &adxl362_rtio_ctx_##inst, \
828 .iodev = &adxl362_iodev_##inst,)) \
830 static const struct adxl362_config adxl362_config_##inst = { \
831 .bus = SPI_DT_SPEC_INST_GET(inst, ADXL362_SPI_CFG, 0), \
833 (DT_INST_PROP(inst, wakeup_mode) * ADXL362_POWER_CTL_WAKEUP) | \
834 (DT_INST_PROP(inst, autosleep) * ADXL362_POWER_CTL_AUTOSLEEP), \
836 (.interrupt = GPIO_DT_SPEC_INST_GET_OR(inst, int1_gpios, { 0 }),)) \
839 SENSOR_DEVICE_DT_INST_DEFINE(inst, adxl362_init, NULL, &adxl362_data_##inst, \
840 &adxl362_config_##inst, POST_KERNEL, \