LibDriver SFA30
Loading...
Searching...
No Matches
driver_sfa30.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_SFA30_H
38#define DRIVER_SFA30_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
67
80
84typedef struct sfa30_handle_s
85{
86 uint8_t (*iic_init)(void);
87 uint8_t (*iic_deinit)(void);
88 uint8_t (*iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
89 uint8_t (*iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len);
90 uint8_t (*uart_init)(void);
91 uint8_t (*uart_deinit)(void);
92 uint16_t (*uart_read)(uint8_t *buf, uint16_t len);
93 uint8_t (*uart_flush)(void);
94 uint8_t (*uart_write)(uint8_t *buf, uint16_t len);
95 void (*delay_ms)(uint32_t ms);
96 void (*debug_print)(const char *const fmt, ...);
97 uint8_t inited;
98 uint8_t iic_uart;
99 uint8_t buf[256];
101
117
121
128
135#define DRIVER_SFA30_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
136
143#define DRIVER_SFA30_LINK_UART_INIT(HANDLE, FUC) (HANDLE)->uart_init = FUC
144
151#define DRIVER_SFA30_LINK_UART_DEINIT(HANDLE, FUC) (HANDLE)->uart_deinit = FUC
152
159#define DRIVER_SFA30_LINK_UART_READ(HANDLE, FUC) (HANDLE)->uart_read = FUC
160
167#define DRIVER_SFA30_LINK_UART_WRITE(HANDLE, FUC) (HANDLE)->uart_write = FUC
168
175#define DRIVER_SFA30_LINK_UART_FLUSH(HANDLE, FUC) (HANDLE)->uart_flush = FUC
176
183#define DRIVER_SFA30_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
184
191#define DRIVER_SFA30_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
192
199#define DRIVER_SFA30_LINK_IIC_WRITE_COMMAND(HANDLE, FUC) (HANDLE)->iic_write_cmd = FUC
200
207#define DRIVER_SFA30_LINK_IIC_READ_COMMAND(HANDLE, FUC) (HANDLE)->iic_read_cmd = FUC
208
215#define DRIVER_SFA30_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
216
223#define DRIVER_SFA30_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
224
228
235
244uint8_t sfa30_info(sfa30_info_t *info);
245
255uint8_t sfa30_set_interface(sfa30_handle_t *handle, sfa30_interface_t interface);
256
266uint8_t sfa30_get_interface(sfa30_handle_t *handle, sfa30_interface_t *interface);
267
279uint8_t sfa30_init(sfa30_handle_t *handle);
280
292uint8_t sfa30_deinit(sfa30_handle_t *handle);
293
305uint8_t sfa30_read(sfa30_handle_t *handle, sfa30_data_t *data);
306
318
330
341uint8_t sfa30_reset(sfa30_handle_t *handle);
342
354uint8_t sfa30_get_device_information(sfa30_handle_t *handle, char info[32]);
355
359
366
379uint8_t sfa30_set_get_reg_uart(sfa30_handle_t *handle, uint8_t *input, uint16_t in_len, uint8_t *output, uint16_t out_len);
380
394uint8_t sfa30_set_reg_iic(sfa30_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len);
395
409uint8_t sfa30_get_reg_iic(sfa30_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len);
410
414
418
419#ifdef __cplusplus
420}
421#endif
422
423#endif
uint8_t sfa30_info(sfa30_info_t *info)
get chip information
sfa30_interface_t
sfa30 interface enumeration definition
struct sfa30_handle_s sfa30_handle_t
sfa30 handle structure definition
uint8_t sfa30_set_interface(sfa30_handle_t *handle, sfa30_interface_t interface)
set the chip interface
uint8_t sfa30_init(sfa30_handle_t *handle)
initialize the chip
uint8_t sfa30_get_interface(sfa30_handle_t *handle, sfa30_interface_t *interface)
get the chip interface
uint8_t sfa30_deinit(sfa30_handle_t *handle)
close the chip
uint8_t sfa30_get_device_information(sfa30_handle_t *handle, char info[32])
get device information
uint8_t sfa30_reset(sfa30_handle_t *handle)
reset the chip
uint8_t sfa30_read(sfa30_handle_t *handle, sfa30_data_t *data)
read the result
struct sfa30_data_s sfa30_data_t
sfa30 data structure definition
uint8_t sfa30_stop_measurement(sfa30_handle_t *handle)
stop the measurement
uint8_t sfa30_start_measurement(sfa30_handle_t *handle)
start the measurement
struct sfa30_info_s sfa30_info_t
sfa30 information structure definition
@ SFA30_INTERFACE_UART
@ SFA30_INTERFACE_IIC
uint8_t sfa30_get_reg_iic(sfa30_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
get the chip register with iic interface
uint8_t sfa30_set_reg_iic(sfa30_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
set the chip register with iic interface
uint8_t sfa30_set_get_reg_uart(sfa30_handle_t *handle, uint8_t *input, uint16_t in_len, uint8_t *output, uint16_t out_len)
set and get the chip register with uart interface
sfa30 data structure definition
int16_t formaldehyde_raw
int16_t temperature_raw
int16_t humidity_raw
float formaldehyde
float temperature
sfa30 handle structure definition
uint8_t(* uart_flush)(void)
uint8_t buf[256]
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
void(* delay_ms)(uint32_t ms)
uint8_t(* uart_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* uart_init)(void)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
sfa30 information structure definition
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
char interface[16]
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]