1 /* 2 * Copyright (c) 2024 Jan Fäh 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_SCD4X_SCD4X_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_SCD4X_SCD4X_H_ 9 10 #include <zephyr/device.h> 11 12 #define SCD4X_CMD_REINIT 0 13 #define SCD4X_CMD_START_PERIODIC_MEASUREMENT 1 14 #define SCD4X_CMD_STOP_PERIODIC_MEASUREMENT 2 15 #define SCD4X_CMD_READ_MEASUREMENT 3 16 #define SCD4X_CMD_SET_TEMPERATURE_OFFSET 4 17 #define SCD4X_CMD_GET_TEMPERATURE_OFFSET 5 18 #define SCD4X_CMD_SET_SENSOR_ALTITUDE 6 19 #define SCD4X_CMD_GET_SENSOR_ALTITUDE 7 20 #define SCD4X_CMD_SET_AMBIENT_PRESSURE 8 21 #define SCD4X_CMD_GET_AMBIENT_PRESSURE 9 22 #define SCD4X_CMD_FORCED_RECALIB 10 23 #define SCD4X_CMD_SET_AUTOMATIC_CALIB_ENABLE 11 24 #define SCD4X_CMD_GET_AUTOMATIC_CALIB_ENABLE 12 25 #define SCD4X_CMD_LOW_POWER_PERIODIC_MEASUREMENT 13 26 #define SCD4X_CMD_GET_DATA_READY_STATUS 14 27 #define SCD4X_CMD_PERSIST_SETTINGS 15 28 #define SCD4X_CMD_SELF_TEST 16 29 #define SCD4X_CMD_FACTORY_RESET 17 30 #define SCD4X_CMD_MEASURE_SINGLE_SHOT 18 31 #define SCD4X_CMD_MEASURE_SINGLE_SHOT_RHT 19 32 #define SCD4X_CMD_POWER_DOWN 10 33 #define SCD4X_CMD_WAKE_UP 21 34 #define SCD4X_CMD_SET_SELF_CALIB_INITIAL_PERIOD 22 35 #define SCD4X_CMD_GET_SELF_CALIB_INITIAL_PERIOD 23 36 #define SCD4X_CMD_SET_SELF_CALIB_STANDARD_PERIOD 24 37 #define SCD4X_CMD_GET_SELF_CALIB_STANDARD_PERIOD 25 38 39 #define SCD4X_CRC_POLY 0x31 40 #define SCD4X_CRC_INIT 0xFF 41 42 #define SCD4X_STARTUP_TIME_MS 30 43 44 #define SCD4X_TEMPERATURE_OFFSET_IDX_MAX 20 45 #define SCD4X_SENSOR_ALTITUDE_IDX_MAX 3000 46 #define SCD4X_AMBIENT_PRESSURE_IDX_MAX 1200 47 #define SCD4X_BOOL_IDX_MAX 1 48 49 #define SCD4X_MAX_TEMP 175 50 #define SCD4X_MIN_TEMP -45 51 52 enum scd4x_model_t { 53 SCD4X_MODEL_SCD40, 54 SCD4X_MODEL_SCD41, 55 }; 56 57 enum scd4x_mode_t { 58 SCD4X_MODE_NORMAL, 59 SCD4X_MODE_LOW_POWER, 60 SCD4X_MODE_SINGLE_SHOT, 61 }; 62 63 struct scd4x_config { 64 struct i2c_dt_spec bus; 65 enum scd4x_model_t model; 66 enum scd4x_mode_t mode; 67 }; 68 69 struct scd4x_data { 70 uint16_t temp_sample; 71 uint16_t humi_sample; 72 uint16_t co2_sample; 73 }; 74 75 struct cmds_t { 76 uint16_t cmd; 77 uint16_t cmd_duration_ms; 78 }; 79 80 const struct cmds_t scd4x_cmds[] = { 81 {0x3646, 30}, {0x21B1, 0}, {0x3F86, 500}, {0xEC05, 1}, {0x241D, 1}, {0x2318, 1}, 82 {0x2427, 1}, {0x2322, 1}, {0xE000, 1}, {0xE000, 1}, {0x362F, 400}, {0x2416, 1}, 83 {0x2313, 1}, {0x21AC, 0}, {0xE4B8, 1}, {0x3615, 800}, {0x3639, 10000}, {0x3632, 1200}, 84 {0x219D, 5000}, {0x2196, 50}, {0x36E0, 1}, {0x36F6, 30}, {0x2445, 1}, {0x2340, 1}, 85 {0x244E, 1}, {0x234B, 1}, 86 }; 87 88 #endif /* ZEPHYR_DRIVERS_SENSOR_SCD4X_SCD4X_H_ */ 89