Lines Matching +full:write +full:- +full:command
4 * SPDX-License-Identifier: Apache-2.0
33 const struct scd4x_config *cfg = dev->config; in scd4x_write_command()
39 ret = i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf)); in scd4x_write_command()
50 const struct scd4x_config *cfg = dev->config; in scd4x_read_reg()
53 ret = i2c_read_dt(&cfg->bus, rx_buf, rx_buf_size); in scd4x_read_reg()
63 return -EIO; in scd4x_read_reg()
72 const struct scd4x_config *cfg = dev->config; in scd4x_write_reg()
86 ret = i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf)); in scd4x_write_reg()
88 LOG_ERR("Failed to write i2c data."); in scd4x_write_reg()
106 LOG_ERR("Failed to write get_data_ready_status command."); in scd4x_data_ready()
117 /* Least significant 11 bits = 0 --> data not ready */ in scd4x_data_ready()
127 struct scd4x_data *data = dev->data; in scd4x_read_sample()
133 LOG_ERR("Failed to write read_measurement command."); in scd4x_read_sample()
143 data->co2_sample = sys_get_be16(rx_data); in scd4x_read_sample()
144 data->temp_sample = sys_get_be16(&rx_data[3]); in scd4x_read_sample()
145 data->humi_sample = sys_get_be16(&rx_data[6]); in scd4x_read_sample()
152 const struct scd4x_config *cfg = dev->config; in scd4x_setup_measurement()
155 switch ((enum scd4x_mode_t)cfg->mode) { in scd4x_setup_measurement()
159 LOG_ERR("Failed to write start_periodic_measurement command."); in scd4x_setup_measurement()
166 LOG_ERR("Failed to write start_low_power_periodic_measurement command."); in scd4x_setup_measurement()
173 LOG_ERR("Failed to write power_down command."); in scd4x_setup_measurement()
178 return -EINVAL; in scd4x_setup_measurement()
185 const struct scd4x_config *cfg = dev->config; in scd4x_set_idle_mode()
188 if (cfg->mode == SCD4X_MODE_SINGLE_SHOT) { in scd4x_set_idle_mode()
189 /*send wake up command twice because of an expected nack return in power down mode*/ in scd4x_set_idle_mode()
193 LOG_ERR("Failed write wake_up command."); in scd4x_set_idle_mode()
199 LOG_ERR("Failed to write stop_periodic_measurement command."); in scd4x_set_idle_mode()
212 (float)(val->val1 + (val->val2 / 1000000.0)) * 0xFFFF / SCD4X_MAX_TEMP; in scd4x_set_temperature_offset()
216 LOG_ERR("Failed to write set_temperature_offset register."); in scd4x_set_temperature_offset()
226 uint16_t altitude = val->val1; in scd4x_set_sensor_altitude()
230 LOG_ERR("Failed to write set_sensor_altitude register."); in scd4x_set_sensor_altitude()
240 uint16_t ambient_pressure = val->val1; in scd4x_set_ambient_pressure()
244 LOG_ERR("Failed to write set_ambient_pressure register."); in scd4x_set_ambient_pressure()
255 uint16_t automatic_calib_enable = val->val1; in scd4x_set_automatic_calib_enable()
260 LOG_ERR("Failed to write set_automatic_calibration_enable register."); in scd4x_set_automatic_calib_enable()
271 uint16_t initial_period = val->val1; in scd4x_set_self_calib_initial_period()
275 LOG_ERR("Failed to write set_automatic_self_calibration_initial_period register."); in scd4x_set_self_calib_initial_period()
286 uint16_t standard_period = val->val1; in scd4x_set_self_calib_standard_period()
290 LOG_ERR("Failed to write set_automatic_self_calibration_standard_period register."); in scd4x_set_self_calib_standard_period()
304 LOG_ERR("Failed to write get_temperature_offset command."); in scd4x_get_temperature_offset()
318 val->val1 = (int32_t)(temp / 0xFFFF); in scd4x_get_temperature_offset()
319 val->val2 = ((temp % 0xFFFF) * 1000000) / 0xFFFF; in scd4x_get_temperature_offset()
331 LOG_ERR("Failed to write get_sensor_altitude command."); in scd4x_get_sensor_altitude()
341 val->val1 = sys_get_be16(rx_buf); in scd4x_get_sensor_altitude()
342 val->val2 = 0; in scd4x_get_sensor_altitude()
354 LOG_ERR("Failed to write get_ambient_pressure command."); in scd4x_get_ambient_pressure()
364 val->val1 = sys_get_be16(rx_buf); in scd4x_get_ambient_pressure()
365 val->val2 = 0; in scd4x_get_ambient_pressure()
377 LOG_ERR("Failed to write get_automatic_calibration_enable command."); in scd4x_get_automatic_calib_enable()
387 val->val1 = sys_get_be16(rx_buf); in scd4x_get_automatic_calib_enable()
388 val->val2 = 0; in scd4x_get_automatic_calib_enable()
400 LOG_ERR("Failed to write get_automati_calibration_initial_period command."); in scd4x_get_self_calib_initial_period()
410 val->val1 = sys_get_be16(rx_buf); in scd4x_get_self_calib_initial_period()
411 val->val2 = 0; in scd4x_get_self_calib_initial_period()
423 LOG_ERR("Failed to write get_automatic_self_calibration_standard_period command."); in scd4x_get_self_calib_standard_period()
433 val->val1 = sys_get_be16(rx_buf); in scd4x_get_self_calib_standard_period()
434 val->val2 = 0; in scd4x_get_self_calib_standard_period()
453 LOG_ERR("Failed to write perform_forced_recalibration register."); in scd4x_forced_recalibration()
468 return -EIO; in scd4x_forced_recalibration()
471 *frc_correction -= 0x8000; in scd4x_forced_recalibration()
495 LOG_ERR("Failed to write perform_self_test command."); in scd4x_self_test()
509 return -EIO; in scd4x_self_test()
533 LOG_ERR("Failed to write persist_settings command."); in scd4x_persist_settings()
558 LOG_ERR("Failed to write perfom_factory_reset command."); in scd4x_factory_reset()
573 const struct scd4x_config *cfg = dev->config; in scd4x_sample_fetch()
579 return -ENOTSUP; in scd4x_sample_fetch()
582 if (cfg->mode == SCD4X_MODE_SINGLE_SHOT) { in scd4x_sample_fetch()
592 LOG_ERR("Failed to write measure_single_shot_rht_only command."); in scd4x_sample_fetch()
598 LOG_ERR("Failed to write measure_single_shot command."); in scd4x_sample_fetch()
619 if (cfg->mode == SCD4X_MODE_SINGLE_SHOT) { in scd4x_sample_fetch()
632 const struct scd4x_data *data = dev->data; in scd4x_channel_get()
638 tmp_val = data->temp_sample * SCD4X_MAX_TEMP; in scd4x_channel_get()
639 val->val1 = (int32_t)(tmp_val / 0xFFFF) + SCD4X_MIN_TEMP; in scd4x_channel_get()
640 val->val2 = ((tmp_val % 0xFFFF) * 1000000) / 0xFFFF; in scd4x_channel_get()
644 tmp_val = data->humi_sample * 100; in scd4x_channel_get()
645 val->val1 = (int32_t)(tmp_val / 0xFFFF); in scd4x_channel_get()
646 val->val2 = ((tmp_val % 0xFFFF) * 1000000) / 0xFFFF; in scd4x_channel_get()
649 val->val1 = data->co2_sample; in scd4x_channel_get()
650 val->val2 = 0; in scd4x_channel_get()
653 return -ENOTSUP; in scd4x_channel_get()
661 const struct scd4x_config *cfg = dev->config; in scd4x_attr_set()
666 return -ENOTSUP; in scd4x_attr_set()
677 if (val->val1 < 0 || val->val2 < 0) { in scd4x_attr_set()
678 return -EINVAL; in scd4x_attr_set()
683 if (val->val1 > SCD4X_TEMPERATURE_OFFSET_IDX_MAX) { in scd4x_attr_set()
684 return -EINVAL; in scd4x_attr_set()
693 if (val->val1 > SCD4X_SENSOR_ALTITUDE_IDX_MAX) { in scd4x_attr_set()
694 return -EINVAL; in scd4x_attr_set()
703 if (val->val1 > SCD4X_AMBIENT_PRESSURE_IDX_MAX || val->val1 < 700) { in scd4x_attr_set()
704 return -EINVAL; in scd4x_attr_set()
714 if (val->val1 > SCD4X_BOOL_IDX_MAX) { in scd4x_attr_set()
715 return -EINVAL; in scd4x_attr_set()
724 if (val->val1 % 4) { in scd4x_attr_set()
725 return -EINVAL; in scd4x_attr_set()
727 if (cfg->model == SCD4X_MODEL_SCD40) { in scd4x_attr_set()
729 return -ENOTSUP; in scd4x_attr_set()
738 if (val->val1 % 4) { in scd4x_attr_set()
739 return -EINVAL; in scd4x_attr_set()
741 if (cfg->model == SCD4X_MODEL_SCD40) { in scd4x_attr_set()
743 return -ENOTSUP; in scd4x_attr_set()
752 return -ENOTSUP; in scd4x_attr_set()
767 const struct scd4x_config *cfg = dev->config; in scd4x_attr_get()
772 return -ENOTSUP; in scd4x_attr_get()
776 cfg->mode == SCD4X_MODE_SINGLE_SHOT) { in scd4x_attr_get()
815 if (cfg->model == SCD4X_MODEL_SCD40) { in scd4x_attr_get()
817 return -ENOTSUP; in scd4x_attr_get()
826 if (cfg->model == SCD4X_MODEL_SCD40) { in scd4x_attr_get()
828 return -ENOTSUP; in scd4x_attr_get()
837 return -ENOTSUP; in scd4x_attr_get()
851 const struct scd4x_config *cfg = dev->config; in scd4x_init()
854 if (!i2c_is_ready_dt(&cfg->bus)) { in scd4x_init()
856 return -ENODEV; in scd4x_init()
861 /*send wake up command twice because of an expected nack return in power down mode*/ in scd4x_init()