ESP32-P4 OBC Firmware
ESP-IDF firmware for Plant-B CubeSat OBC
 
Loading...
Searching...
No Matches
scd30_sensor.c File Reference

I²C driver for the SCD30 environmental sensor. More...

#include "scd30_sensor.h"

Macros

#define CMD_TRIGGER_CONTINUOUS_MEASUREMENT   (0x0010)
 
#define CMD_STOP_CONTINUOUS_MEASUREMENT   (0x0104)
 
#define CMD_SET_MEASUREMENT_INTERVAL   (0x4600)
 
#define CMD_GET_DATA_READY_STATUS   (0x0202)
 
#define CMD_READ_MEASUREMENT   (0x0300)
 
#define CMD_ACTIVATE_AUTOMATIC_SELF_CALIBRATION   (0x5306)
 
#define CMD_SET_FORCED_RECALIBRATION_VALUE   (0x5204)
 
#define CMD_SET_TEMPERATURE_OFFSET   (0x5403)
 
#define CMD_ALTITUDE_COMPENSATION   (0x5102)
 
#define CMD_READ_FIRMWARE_VERSION   (0xD100)
 
#define CMD_SOFT_RESET   (0XD304)
 
#define CHECK(x)
 
#define CHECK_ARG(VAL)
 

Functions

static uint8_t crc8 (const uint8_t *data, size_t count)
 
static esp_err_t i2c_write_uint16 (scd30_handle_t sensor, uint16_t cmd, const uint16_t *data, size_t words)
 
static esp_err_t i2c_read_uint16 (scd30_handle_t sensor, uint16_t *data, size_t words)
 
static esp_err_t i2c_execute_uint16 (scd30_handle_t sensor, uint16_t cmd, uint32_t timeout_ms, const uint16_t *out_data, size_t out_words, uint16_t *in_data, size_t in_words)
 
scd30_handle_t scd30_i2c_create (i2c_bus_handle_t bus, i2c_addr_t dev_addr)
 Create a handle for an SCD30 sensor but does not apply any configuration.
 
scd30_handle_t scd30_i2c_init (i2c_bus_handle_t bus, i2c_addr_t dev_addr)
 Initialize the SCD30 sensor on the I²C bus with a default configuration.
 
void scd30_i2c_delete (scd30_handle_t sensor)
 Deinitialize the SCD30 sensor and free resources.
 
esp_err_t scd30_i2c_trigger_continuous_measurement (scd30_handle_t sensor, p_mbar_t p_comp)
 Trigger continuous measurement.
 
esp_err_t scd30_i2c_stop_continuous_measurement (scd30_handle_t sensor)
 Stop continuous measurement.
 
esp_err_t scd30_i2c_read_measurement_interval (scd30_handle_t sensor, i_sec_t *interval)
 Read the measurement interval.
 
esp_err_t scd30_i2c_write_measurement_interval (scd30_handle_t sensor, i_sec_t interval)
 Set measurement interval.
 
esp_err_t scd30_i2c_read_data_ready_status (scd30_handle_t sensor, bool *data_ready)
 Check whether new measurement data is available for read-out.
 
esp_err_t scd30_i2c_read_measurement (scd30_handle_t sensor, co2_ppm_t *co2, t_celsius_t *temperature, rh_percent_t *humidity)
 Read CO₂, temperature and humidity measurements.
 
esp_err_t scd30_i2c_read_automatic_self_calibration (scd30_handle_t sensor, bool *enabled)
 Get automatic self calibration (ASC) state.
 
esp_err_t scd30_i2c_write_automatic_self_calibration (scd30_handle_t sensor, bool enabled)
 Enable or disable automatic self calibration (ASC).
 
esp_err_t scd30_i2c_read_forced_recalibration_value (scd30_handle_t sensor, uco2_ppm_t *frc)
 Get forced recalibration (FRC) value.
 
esp_err_t scd30_i2c_write_forced_recalibration_value (scd30_handle_t sensor, uco2_ppm_t target)
 Set forced recalibration (FRC) value.
 
esp_err_t scd30_i2c_read_temperature_offset_ticks (scd30_handle_t sensor, tx100_celsius_t *offset)
 Get temperature offset in ticks.
 
esp_err_t scd30_i2c_read_temperature_offset (scd30_handle_t sensor, t_celsius_t *offset)
 Get temperature offset.
 
esp_err_t scd30_i2c_write_temperature_offset_ticks (scd30_handle_t sensor, tx100_celsius_t offset)
 Set temperature offset in ticks.
 
esp_err_t scd30_i2c_write_temperature_offset (scd30_handle_t sensor, t_celsius_t offset)
 Set temperature offset.
 
esp_err_t scd30_i2c_read_sensor_altitude (scd30_handle_t sensor, alt_m_t *altitude)
 Get configured sensor altitude.
 
esp_err_t scd30_i2c_write_sensor_altitude (scd30_handle_t sensor, alt_m_t altitude)
 Set sensor altitude above sea level.
 
esp_err_t scd30_i2c_read_firmware_version (scd30_handle_t sensor, uint16_t *firmware_version)
 Get firmware version.
 
esp_err_t scd30_i2c_soft_reset (scd30_handle_t sensor)
 Reset the sensor.
 

Variables

static const char * TAG = "scd30"
 

Detailed Description

I²C driver for the SCD30 environmental sensor.

Author
Adrien Chevrier

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Version
0.1
Date
2026-02-04

Macro Definition Documentation

◆ CHECK

#define CHECK ( x)
Value:
do \
{ \
esp_err_t __; \
if ((__ = x) != ESP_OK) \
return __; \
} while (0)

◆ CHECK_ARG

#define CHECK_ARG ( VAL)
Value:
do \
{ \
if (!(VAL)) \
return ESP_ERR_INVALID_ARG; \
} while (0)

◆ CMD_ACTIVATE_AUTOMATIC_SELF_CALIBRATION

#define CMD_ACTIVATE_AUTOMATIC_SELF_CALIBRATION   (0x5306)

◆ CMD_ALTITUDE_COMPENSATION

#define CMD_ALTITUDE_COMPENSATION   (0x5102)

◆ CMD_GET_DATA_READY_STATUS

#define CMD_GET_DATA_READY_STATUS   (0x0202)

◆ CMD_READ_FIRMWARE_VERSION

#define CMD_READ_FIRMWARE_VERSION   (0xD100)

◆ CMD_READ_MEASUREMENT

#define CMD_READ_MEASUREMENT   (0x0300)

◆ CMD_SET_FORCED_RECALIBRATION_VALUE

#define CMD_SET_FORCED_RECALIBRATION_VALUE   (0x5204)

◆ CMD_SET_MEASUREMENT_INTERVAL

#define CMD_SET_MEASUREMENT_INTERVAL   (0x4600)

◆ CMD_SET_TEMPERATURE_OFFSET

#define CMD_SET_TEMPERATURE_OFFSET   (0x5403)

◆ CMD_SOFT_RESET

#define CMD_SOFT_RESET   (0XD304)

◆ CMD_STOP_CONTINUOUS_MEASUREMENT

#define CMD_STOP_CONTINUOUS_MEASUREMENT   (0x0104)

◆ CMD_TRIGGER_CONTINUOUS_MEASUREMENT

#define CMD_TRIGGER_CONTINUOUS_MEASUREMENT   (0x0010)

Function Documentation

◆ crc8()

static uint8_t crc8 ( const uint8_t * data,
size_t count )
static

◆ i2c_execute_uint16()

static esp_err_t i2c_execute_uint16 ( scd30_handle_t sensor,
uint16_t cmd,
uint32_t timeout_ms,
const uint16_t * out_data,
size_t out_words,
uint16_t * in_data,
size_t in_words )
static

◆ i2c_read_uint16()

static esp_err_t i2c_read_uint16 ( scd30_handle_t sensor,
uint16_t * data,
size_t words )
static

◆ i2c_write_uint16()

static esp_err_t i2c_write_uint16 ( scd30_handle_t sensor,
uint16_t cmd,
const uint16_t * data,
size_t words )
static

Variable Documentation

◆ TAG

const char* TAG = "scd30"
static