Lines Matching +full:i2c +full:- +full:errors
5 * SPDX-License-Identifier: Apache-2.0
12 #include <zephyr/drivers/i2c.h>
26 const struct ccs811_config *config = dev->config; in set_wake()
28 gpio_pin_set_dt(&config->wake_gpio, enable); in set_wake()
42 const struct ccs811_config *config = dev->config; in fetch_status()
46 if (i2c_reg_read_byte_dt(&config->i2c, CCS811_REG_STATUS, &status) < 0) { in fetch_status()
48 return -EIO; in fetch_status()
55 if (i2c_reg_read_byte_dt(&config->i2c, CCS811_REG_ERROR_ID, &error_id) < 0) { in fetch_status()
57 return -EIO; in fetch_status()
73 struct ccs811_data *drv_data = dev->data; in ccs811_result()
75 return &drv_data->result; in ccs811_result()
81 struct ccs811_data *drv_data = dev->data; in ccs811_configver_fetch()
82 const struct ccs811_config *config = dev->config; in ccs811_configver_fetch()
87 return -EINVAL; in ccs811_configver_fetch()
92 rc = i2c_write_read_dt(&config->i2c, &cmd, sizeof(cmd), &ptr->hw_version, in ccs811_configver_fetch()
93 sizeof(ptr->hw_version)); in ccs811_configver_fetch()
96 rc = i2c_write_read_dt(&config->i2c, &cmd, sizeof(cmd), in ccs811_configver_fetch()
97 (uint8_t *)&ptr->fw_boot_version, in ccs811_configver_fetch()
98 sizeof(ptr->fw_boot_version)); in ccs811_configver_fetch()
99 ptr->fw_boot_version = sys_be16_to_cpu(ptr->fw_boot_version); in ccs811_configver_fetch()
104 rc = i2c_write_read_dt(&config->i2c, &cmd, sizeof(cmd), in ccs811_configver_fetch()
105 (uint8_t *)&ptr->fw_app_version, in ccs811_configver_fetch()
106 sizeof(ptr->fw_app_version)); in ccs811_configver_fetch()
107 ptr->fw_app_version = sys_be16_to_cpu(ptr->fw_app_version); in ccs811_configver_fetch()
111 ptr->hw_version, ptr->fw_boot_version, in ccs811_configver_fetch()
112 ptr->fw_app_version); in ccs811_configver_fetch()
116 ptr->mode = drv_data->mode & CCS811_MODE_MSK; in ccs811_configver_fetch()
124 const struct ccs811_config *config = dev->config; in ccs811_baseline_fetch()
130 rc = i2c_write_read_dt(&config->i2c, &cmd, sizeof(cmd), (uint8_t *)&baseline, in ccs811_baseline_fetch()
143 const struct ccs811_config *config = dev->config; in ccs811_baseline_update()
150 rc = i2c_write_dt(&config->i2c, buf, sizeof(buf)); in ccs811_baseline_update()
159 const struct ccs811_config *config = dev->config; in ccs811_envdata_update()
165 * system that specified a 9-bit fractional part to represent in ccs811_envdata_update()
166 * milli-units. Since 1000 is greater than 512, the device in ccs811_envdata_update()
168 * indicating 0.5. So we only write the first octet (7-bit in ccs811_envdata_update()
169 * while plus 1-bit half). in ccs811_envdata_update()
176 int value = 2 * humidity->val1; in ccs811_envdata_update()
178 value += (250000 + humidity->val2) / 500000; in ccs811_envdata_update()
185 humidity->val1, humidity->val2, value); in ccs811_envdata_update()
192 * Temperature is offset from -25 Cel. Values below minimum in ccs811_envdata_update()
198 int value = 2 * temperature->val1; in ccs811_envdata_update()
200 if (temperature->val2 < 0) { in ccs811_envdata_update()
201 value += (250000 + temperature->val2) / 500000; in ccs811_envdata_update()
203 value += (-250000 + temperature->val2) / 500000; in ccs811_envdata_update()
205 if (value < (2 * -25)) { in ccs811_envdata_update()
211 temperature->val1, temperature->val2, value); in ccs811_envdata_update()
218 rc = i2c_write_dt(&config->i2c, buf, sizeof(buf)); in ccs811_envdata_update()
226 struct ccs811_data *drv_data = dev->data; in ccs811_sample_fetch()
227 const struct ccs811_config *config = dev->config; in ccs811_sample_fetch()
228 struct ccs811_result_type *rp = &drv_data->result; in ccs811_sample_fetch()
235 rc = i2c_write_read_dt(&config->i2c, &cmd, sizeof(cmd), (uint8_t *)buf, sizeof(buf)); in ccs811_sample_fetch()
238 return -EIO; in ccs811_sample_fetch()
241 rp->co2 = sys_be16_to_cpu(buf[0]); in ccs811_sample_fetch()
242 rp->voc = sys_be16_to_cpu(buf[1]); in ccs811_sample_fetch()
244 rp->status = status; in ccs811_sample_fetch()
245 rp->error = error_from_status(status); in ccs811_sample_fetch()
246 rp->raw = sys_be16_to_cpu(buf[3]); in ccs811_sample_fetch()
249 * zero while it's starting up. Assume a non-zero CO2 with in ccs811_sample_fetch()
253 if ((drv_data->app_fw_ver <= 0x11) in ccs811_sample_fetch()
254 && (rp->co2 != 0)) { in ccs811_sample_fetch()
257 return (status & CCS811_STATUS_DATA_READY) ? 0 : -EAGAIN; in ccs811_sample_fetch()
264 struct ccs811_data *drv_data = dev->data; in ccs811_channel_get()
265 const struct ccs811_result_type *rp = &drv_data->result; in ccs811_channel_get()
270 val->val1 = rp->co2; in ccs811_channel_get()
271 val->val2 = 0; in ccs811_channel_get()
275 val->val1 = rp->voc; in ccs811_channel_get()
276 val->val2 = 0; in ccs811_channel_get()
283 uval = ((rp->raw & CCS811_RAW_VOLTAGE_MSK) in ccs811_channel_get()
285 val->val1 = uval / 1000000U; in ccs811_channel_get()
286 val->val2 = uval % 1000000; in ccs811_channel_get()
294 uval = ((rp->raw & CCS811_RAW_CURRENT_MSK) in ccs811_channel_get()
296 val->val1 = uval / 1000000U; in ccs811_channel_get()
297 val->val2 = uval % 1000000; in ccs811_channel_get()
301 return -ENOTSUP; in ccs811_channel_get()
318 const struct ccs811_config *config = dev->config; in switch_to_app_mode()
326 return -EIO; in switch_to_app_mode()
332 return -EINVAL; in switch_to_app_mode()
343 if (i2c_write_dt(&config->i2c, &buf, 1) < 0) { in switch_to_app_mode()
345 return -EIO; in switch_to_app_mode()
351 return -EIO; in switch_to_app_mode()
357 return -EINVAL; in switch_to_app_mode()
371 struct ccs811_data *drv_data = dev->data; in ccs811_mutate_meas_mode()
372 const struct ccs811_config *config = dev->config; in ccs811_mutate_meas_mode()
374 uint8_t mode = set | (drv_data->mode & ~clear); in ccs811_mutate_meas_mode()
381 return -EINVAL; in ccs811_mutate_meas_mode()
384 if (mode != drv_data->mode) { in ccs811_mutate_meas_mode()
386 rc = i2c_reg_write_byte_dt(&config->i2c, CCS811_REG_MEAS_MODE, mode); in ccs811_mutate_meas_mode()
388 drv_data->mode, mode, rc); in ccs811_mutate_meas_mode()
391 rc = -EIO; in ccs811_mutate_meas_mode()
393 drv_data->mode = mode; in ccs811_mutate_meas_mode()
405 struct ccs811_data *drv_data = dev->data; in ccs811_set_thresholds()
406 const struct ccs811_config *config = dev->config; in ccs811_set_thresholds()
409 drv_data->co2_l2m >> 8, in ccs811_set_thresholds()
410 drv_data->co2_l2m, in ccs811_set_thresholds()
411 drv_data->co2_m2h >> 8, in ccs811_set_thresholds()
412 drv_data->co2_m2h, in ccs811_set_thresholds()
417 rc = i2c_write_dt(&config->i2c, buf, sizeof(buf)); in ccs811_set_thresholds()
426 struct ccs811_data *drv_data = dev->data; in ccs811_init()
427 const struct ccs811_config *config = dev->config; in ccs811_init()
434 if (!device_is_ready(config->i2c.bus)) { in ccs811_init()
435 LOG_ERR("I2C bus device not ready"); in ccs811_init()
436 return -ENODEV; in ccs811_init()
439 if (config->wake_gpio.port) { in ccs811_init()
440 if (!gpio_is_ready_dt(&config->wake_gpio)) { in ccs811_init()
442 return -ENODEV; in ccs811_init()
447 * any I2C transfer. If it has been tied to GND by in ccs811_init()
450 gpio_pin_configure_dt(&config->wake_gpio, GPIO_OUTPUT_INACTIVE); in ccs811_init()
456 if (config->reset_gpio.port) { in ccs811_init()
457 if (!gpio_is_ready_dt(&config->reset_gpio)) { in ccs811_init()
459 return -ENODEV; in ccs811_init()
462 gpio_pin_configure_dt(&config->reset_gpio, GPIO_OUTPUT_ACTIVE); in ccs811_init()
467 if (config->irq_gpio.port) { in ccs811_init()
468 if (!gpio_is_ready_dt(&config->irq_gpio)) { in ccs811_init()
470 return -ENODEV; in ccs811_init()
474 k_msleep(20); /* t_START assuming recent power-on */ in ccs811_init()
477 * and validating any errors or configuration inconsistencies in ccs811_init()
480 if (config->reset_gpio.port) { in ccs811_init()
481 gpio_pin_set_dt(&config->reset_gpio, 1); in ccs811_init()
483 gpio_pin_set_dt(&config->reset_gpio, 0); in ccs811_init()
489 if (i2c_write_dt(&config->i2c, reset_seq, sizeof(reset_seq)) < 0) { in ccs811_init()
491 ret = -EIO; in ccs811_init()
505 if (i2c_reg_read_byte_dt(&config->i2c, CCS811_REG_HW_ID, &hw_id) < 0) { in ccs811_init()
507 ret = -EIO; in ccs811_init()
513 ret = -EINVAL; in ccs811_init()
519 if (i2c_write_read_dt(&config->i2c, &cmd, sizeof(cmd), &fw_ver, sizeof(fw_ver)) < 0) { in ccs811_init()
521 ret = -EIO; in ccs811_init()
526 drv_data->app_fw_ver = fw_ver >> 8U; in ccs811_init()
539 if (i2c_reg_write_byte_dt(&config->i2c, CCS811_REG_MEAS_MODE, meas_mode) < 0) { in ccs811_init()
541 ret = -EIO; in ccs811_init()
544 drv_data->mode = meas_mode; in ccs811_init()
549 ret = -EIO; in ccs811_init()
556 ret = -EINVAL; in ccs811_init()
561 if (config->irq_gpio.port) { in ccs811_init()
576 .i2c = I2C_DT_SPEC_INST_GET(inst), \