LibDriver SCD4X
Loading...
Searching...
No Matches
driver_scd4x.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_SCD4X_H
38#define DRIVER_SCD4X_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62typedef enum
63{
64 SCD40 = 0x00,
65 SCD41 = 0x01,
66 SCD43 = 0x02,
67} scd4x_t;
68
72typedef enum
73{
77
81typedef struct scd4x_handle_s
82{
83 uint8_t (*iic_init)(void);
84 uint8_t (*iic_deinit)(void);
85 uint8_t (*iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
86 uint8_t (*iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
87 void (*delay_ms)(uint32_t ms);
88 void (*debug_print)(const char *const fmt, ...);
89 uint8_t inited;
90 uint8_t type;
92
108
112
119
126#define DRIVER_SCD4X_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
127
134#define DRIVER_SCD4X_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
135
142#define DRIVER_SCD4X_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
143
150#define DRIVER_SCD4X_LINK_IIC_READ_COMMAND(HANDLE, FUC) (HANDLE)->iic_read_cmd = FUC
151
158#define DRIVER_SCD4X_LINK_IIC_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->iic_write_cmd = FUC
159
166#define DRIVER_SCD4X_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
167
174#define DRIVER_SCD4X_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
175
179
186
195uint8_t scd4x_info(scd4x_info_t *info);
196
206uint8_t scd4x_set_type(scd4x_handle_t *handle, scd4x_t type);
207
217uint8_t scd4x_get_type(scd4x_handle_t *handle, scd4x_t *type);
218
229uint8_t scd4x_init(scd4x_handle_t *handle);
230
242uint8_t scd4x_deinit(scd4x_handle_t *handle);
243
255
274uint8_t scd4x_read(scd4x_handle_t *handle, uint16_t *co2_raw, uint16_t *co2_ppm,
275 uint16_t *temperature_raw, float *temperature_s,
276 uint16_t *humidity_raw, float *humidity_s);
277
289
301uint8_t scd4x_set_temperature_offset(scd4x_handle_t *handle, uint16_t offset);
302
315uint8_t scd4x_get_temperature_offset(scd4x_handle_t *handle, uint16_t *offset);
316
328uint8_t scd4x_temperature_offset_convert_to_register(scd4x_handle_t *handle, float degrees, uint16_t *reg);
329
341uint8_t scd4x_temperature_offset_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *degrees);
342
354uint8_t scd4x_set_sensor_altitude(scd4x_handle_t *handle, uint16_t altitude);
355
368uint8_t scd4x_get_sensor_altitude(scd4x_handle_t *handle, uint16_t *altitude);
369
381uint8_t scd4x_sensor_altitude_convert_to_register(scd4x_handle_t *handle, float m, uint16_t *reg);
382
394uint8_t scd4x_sensor_altitude_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *m);
395
407uint8_t scd4x_set_ambient_pressure(scd4x_handle_t *handle, uint16_t pressure);
408
421uint8_t scd4x_get_ambient_pressure(scd4x_handle_t *handle, uint16_t *pressure);
422
434uint8_t scd4x_ambient_pressure_convert_to_register(scd4x_handle_t *handle, float pa, uint16_t *reg);
435
447uint8_t scd4x_ambient_pressure_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *pa);
448
462uint8_t scd4x_perform_forced_recalibration(scd4x_handle_t *handle, uint16_t co2_raw, uint16_t *frc);
463
475uint8_t scd4x_co2_convert_to_register(scd4x_handle_t *handle, float ppm, uint16_t *reg);
476
488uint8_t scd4x_co2_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *ppm);
489
502
516
528
542
554
567uint8_t scd4x_get_serial_number(scd4x_handle_t *handle, uint16_t number[3]);
568
581uint8_t scd4x_perform_self_test(scd4x_handle_t *handle, scd4x_bool_t *malfunction_detected);
582
594
605uint8_t scd4x_reinit(scd4x_handle_t *handle);
606
610
617
630
643
655uint8_t scd4x_power_down(scd4x_handle_t *handle);
656
668uint8_t scd4x_wake_up(scd4x_handle_t *handle);
669
684
699
714
729
733
740
754uint8_t scd4x_set_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len);
755
770uint8_t scd4x_get_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len, uint16_t delay_ms);
771
775
779
780#ifdef __cplusplus
781}
782#endif
783
784#endif
uint8_t scd4x_wake_up(scd4x_handle_t *handle)
wake up
uint8_t scd4x_set_automatic_self_calibration_standard_period(scd4x_handle_t *handle, uint16_t hour)
set automatic self calibration standard period
uint8_t scd4x_set_automatic_self_calibration_initial_period(scd4x_handle_t *handle, uint16_t hour)
set automatic self calibration initial period
uint8_t scd4x_power_down(scd4x_handle_t *handle)
power down
uint8_t scd4x_measure_single_shot(scd4x_handle_t *handle)
measure single shot
uint8_t scd4x_get_automatic_self_calibration_standard_period(scd4x_handle_t *handle, uint16_t *hour)
get automatic self calibration standard period
uint8_t scd4x_get_automatic_self_calibration_initial_period(scd4x_handle_t *handle, uint16_t *hour)
get automatic self calibration initial period
uint8_t scd4x_measure_single_shot_rht_only(scd4x_handle_t *handle)
measure single shot rht only
struct scd4x_info_s scd4x_info_t
scd4x information structure definition
uint8_t scd4x_get_type(scd4x_handle_t *handle, scd4x_t *type)
get type
uint8_t scd4x_get_data_ready_status(scd4x_handle_t *handle, scd4x_bool_t *enable)
get data ready status
uint8_t scd4x_stop_periodic_measurement(scd4x_handle_t *handle)
stop periodic measurement
uint8_t scd4x_get_sensor_altitude(scd4x_handle_t *handle, uint16_t *altitude)
get sensor altitude
uint8_t scd4x_sensor_altitude_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *m)
convert the register raw data to the sensor altitude
uint8_t scd4x_set_temperature_offset(scd4x_handle_t *handle, uint16_t offset)
set temperature offset
uint8_t scd4x_get_serial_number(scd4x_handle_t *handle, uint16_t number[3])
get serial number
uint8_t scd4x_deinit(scd4x_handle_t *handle)
close the chip
uint8_t scd4x_get_automatic_self_calibration(scd4x_handle_t *handle, scd4x_bool_t *enable)
get automatic self calibration status
uint8_t scd4x_set_ambient_pressure(scd4x_handle_t *handle, uint16_t pressure)
set ambient pressure
uint8_t scd4x_co2_convert_to_register(scd4x_handle_t *handle, float ppm, uint16_t *reg)
convert the co2 to the register raw data
uint8_t scd4x_read(scd4x_handle_t *handle, uint16_t *co2_raw, uint16_t *co2_ppm, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data
uint8_t scd4x_set_type(scd4x_handle_t *handle, scd4x_t type)
set type
uint8_t scd4x_get_temperature_offset(scd4x_handle_t *handle, uint16_t *offset)
get temperature offset
uint8_t scd4x_temperature_offset_convert_to_register(scd4x_handle_t *handle, float degrees, uint16_t *reg)
convert the temperature offset to the register raw data
uint8_t scd4x_reinit(scd4x_handle_t *handle)
reinit
uint8_t scd4x_ambient_pressure_convert_to_register(scd4x_handle_t *handle, float pa, uint16_t *reg)
convert the ambient pressure to the register raw data
uint8_t scd4x_co2_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *ppm)
convert the register raw data to the co2
uint8_t scd4x_set_automatic_self_calibration(scd4x_handle_t *handle, scd4x_bool_t enable)
enable or disable automatic self calibration
uint8_t scd4x_init(scd4x_handle_t *handle)
initialize the chip
uint8_t scd4x_perform_forced_recalibration(scd4x_handle_t *handle, uint16_t co2_raw, uint16_t *frc)
perform forced recalibration
uint8_t scd4x_perform_factory_reset(scd4x_handle_t *handle)
perform factory reset
uint8_t scd4x_persist_settings(scd4x_handle_t *handle)
persist settings
uint8_t scd4x_start_periodic_measurement(scd4x_handle_t *handle)
start periodic measurement
struct scd4x_handle_s scd4x_handle_t
scd4x handle structure definition
uint8_t scd4x_perform_self_test(scd4x_handle_t *handle, scd4x_bool_t *malfunction_detected)
perform self test
uint8_t scd4x_info(scd4x_info_t *info)
get chip information
uint8_t scd4x_ambient_pressure_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *pa)
convert the register raw data to the ambient pressure
uint8_t scd4x_set_sensor_altitude(scd4x_handle_t *handle, uint16_t altitude)
set sensor altitude
uint8_t scd4x_sensor_altitude_convert_to_register(scd4x_handle_t *handle, float m, uint16_t *reg)
convert the sensor altitude to the register raw data
uint8_t scd4x_temperature_offset_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *degrees)
convert the register raw data to the temperature offset
scd4x_t
scd4x type enumeration definition
scd4x_bool_t
scd4x bool enumeration definition
uint8_t scd4x_get_ambient_pressure(scd4x_handle_t *handle, uint16_t *pressure)
get ambient pressure
uint8_t scd4x_start_low_power_periodic_measurement(scd4x_handle_t *handle)
start low power periodic measurement
@ SCD41
@ SCD40
@ SCD43
@ SCD4X_BOOL_TRUE
@ SCD4X_BOOL_FALSE
uint8_t scd4x_set_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t scd4x_get_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len, uint16_t delay_ms)
get the chip register
scd4x handle structure definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
scd4x information structure definition
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]