LibDriver SGP40
Loading...
Searching...
No Matches
driver_sgp40.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_SGP40_H
38#define DRIVER_SGP40_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 struct sgp40_handle_s
63{
64 uint8_t (*iic_init)(void);
65 uint8_t (*iic_deinit)(void);
66 uint8_t (*iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
67 uint8_t (*iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
68 void (*delay_ms)(uint32_t ms);
69 void (*debug_print)(const char *const fmt, ...);
70 uint8_t inited;
72
88
92
99
106#define DRIVER_SGP40_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
107
114#define DRIVER_SGP40_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
115
122#define DRIVER_SGP40_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
123
130#define DRIVER_SGP40_LINK_IIC_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->iic_write_cmd = FUC
131
138#define DRIVER_SGP40_LINK_IIC_READ_COMMAND(HANDLE, FUC) (HANDLE)->iic_read_cmd = FUC
139
146#define DRIVER_SGP40_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
147
154#define DRIVER_SGP40_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
155
159
166
175uint8_t sgp40_info(sgp40_info_t *info);
176
187uint8_t sgp40_init(sgp40_handle_t *handle);
188
200uint8_t sgp40_deinit(sgp40_handle_t *handle);
201
215uint8_t sgp40_get_measure_raw(sgp40_handle_t *handle, uint16_t raw_humidity,
216 uint16_t raw_temperature, uint16_t *sraw_voc);
217
229uint8_t sgp40_get_measure_raw_without_compensation(sgp40_handle_t *handle, uint16_t *sraw_voc);
230
243uint8_t sgp40_humidity_convert_to_register(sgp40_handle_t *handle, float rh, uint16_t *reg);
244
257uint8_t sgp40_temperature_convert_to_register(sgp40_handle_t *handle, float temp, uint16_t *reg);
258
270uint8_t sgp40_get_measure_test(sgp40_handle_t *handle, uint16_t *result);
271
282uint8_t sgp40_soft_reset(sgp40_handle_t *handle);
283
295
307uint8_t sgp40_get_serial_id(sgp40_handle_t *handle, uint16_t id[3]);
308
312
319
333uint8_t sgp40_set_reg(sgp40_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len);
334
348uint8_t sgp40_get_reg(sgp40_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len);
349
353
357
358#ifdef __cplusplus
359}
360#endif
361
362#endif
uint8_t sgp40_get_measure_raw(sgp40_handle_t *handle, uint16_t raw_humidity, uint16_t raw_temperature, uint16_t *sraw_voc)
get the measure raw result
uint8_t sgp40_get_serial_id(sgp40_handle_t *handle, uint16_t id[3])
get the chip serial id
uint8_t sgp40_init(sgp40_handle_t *handle)
initialize the chip
uint8_t sgp40_soft_reset(sgp40_handle_t *handle)
soft reset the chip
uint8_t sgp40_get_measure_raw_without_compensation(sgp40_handle_t *handle, uint16_t *sraw_voc)
get the measure raw result without compensation
uint8_t sgp40_info(sgp40_info_t *info)
get chip information
uint8_t sgp40_humidity_convert_to_register(sgp40_handle_t *handle, float rh, uint16_t *reg)
convert the humidity to the register data
uint8_t sgp40_turn_heater_off(sgp40_handle_t *handle)
turn heater off
uint8_t sgp40_deinit(sgp40_handle_t *handle)
close the chip
uint8_t sgp40_get_measure_test(sgp40_handle_t *handle, uint16_t *result)
get the chip measure test
struct sgp40_handle_s sgp40_handle_t
sgp40 handle structure definition
uint8_t sgp40_temperature_convert_to_register(sgp40_handle_t *handle, float temp, uint16_t *reg)
convert the temperature to the register data
struct sgp40_info_s sgp40_info_t
sgp40 information structure definition
uint8_t sgp40_get_reg(sgp40_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t sgp40_set_reg(sgp40_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
set the chip register
sgp40 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)
sgp40 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]