LibDriver ENS160
Loading...
Searching...
No Matches
driver_ens160.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_ENS160_H
38#define DRIVER_ENS160_H
39
40#include <stdint.h>
41#include <stdio.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
67
71typedef enum
72{
73 ENS160_ADDRESS_0 = (0x52 << 1),
74 ENS160_ADDRESS_1 = (0x53 << 1),
76
80typedef enum
81{
85
95
104
113
128
132typedef struct ens160_handle_s
133{
134 uint8_t iic_addr;
135 uint8_t (*iic_init)(void);
136 uint8_t (*iic_deinit)(void);
137 uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
138 uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
139 uint8_t (*spi_init)(void);
140 uint8_t (*spi_deinit)(void);
141 uint8_t (*spi_read)(uint8_t reg, uint8_t *buf, uint16_t len);
142 uint8_t (*spi_write)(uint8_t reg, uint8_t *buf, uint16_t len);
143 void (*receive_callback)(uint8_t type, uint16_t *dat);
144 void (*delay_ms)(uint32_t ms);
145 void (*debug_print)(const char *const fmt, ...);
146 uint8_t inited;
147 uint8_t iic_spi;
149
165
169
176
183#define DRIVER_ENS160_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
184
191#define DRIVER_ENS160_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
192
199#define DRIVER_ENS160_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
200
207#define DRIVER_ENS160_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
208
215#define DRIVER_ENS160_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
216
223#define DRIVER_ENS160_LINK_SPI_INIT(HANDLE, FUC) (HANDLE)->spi_init = FUC
224
231#define DRIVER_ENS160_LINK_SPI_DEINIT(HANDLE, FUC) (HANDLE)->spi_deinit = FUC
232
239#define DRIVER_ENS160_LINK_SPI_READ(HANDLE, FUC) (HANDLE)->spi_read = FUC
240
247#define DRIVER_ENS160_LINK_SPI_WRITE(HANDLE, FUC) (HANDLE)->spi_write = FUC
248
255#define DRIVER_ENS160_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
256
263#define DRIVER_ENS160_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
264
271#define DRIVER_ENS160_LINK_RECEIVE_CALLBACK(HANDLE, FUC) (HANDLE)->receive_callback = FUC
272
276
283
292uint8_t ens160_info(ens160_info_t *info);
293
304
314uint8_t ens160_get_interface(ens160_handle_t *handle, ens160_interface_t *interface);
315
325uint8_t ens160_set_addr_pin(ens160_handle_t *handle, ens160_address_t addr_pin);
326
336uint8_t ens160_get_addr_pin(ens160_handle_t *handle, ens160_address_t *addr_pin);
337
357uint8_t ens160_irq_handler(ens160_handle_t *handle);
358
370uint8_t ens160_init(ens160_handle_t *handle);
371
383uint8_t ens160_deinit(ens160_handle_t *handle);
384
396uint8_t ens160_read_aqi(ens160_handle_t *handle, uint8_t *uba);
397
409uint8_t ens160_read_tvoc(ens160_handle_t *handle, uint16_t *tvoc_ppb);
410
422uint8_t ens160_read_eco2(ens160_handle_t *handle, uint16_t *eco2_ppm);
423
435uint8_t ens160_read_etoh(ens160_handle_t *handle, uint16_t *etoh_ppb);
436
448uint8_t ens160_set_mode(ens160_handle_t *handle, ens160_mode_t mode);
449
461uint8_t ens160_get_mode(ens160_handle_t *handle, ens160_mode_t *mode);
462
473uint8_t ens160_soft_reset(ens160_handle_t *handle);
474
487
500
513
526
539
552
565
578
590uint8_t ens160_set_interrupt(ens160_handle_t *handle, ens160_bool_t enable);
591
603uint8_t ens160_get_interrupt(ens160_handle_t *handle, ens160_bool_t *enable);
604
615uint8_t ens160_nop(ens160_handle_t *handle);
616
630uint8_t ens160_get_app_version(ens160_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *release);
631
642uint8_t ens160_clear(ens160_handle_t *handle);
643
655uint8_t ens160_set_temperature_compensation(ens160_handle_t *handle, uint16_t raw);
656
668uint8_t ens160_get_temperature_compensation(ens160_handle_t *handle, uint16_t *raw);
669
681uint8_t ens160_set_humidity_compensation(ens160_handle_t *handle, uint16_t raw);
682
694uint8_t ens160_get_humidity_compensation(ens160_handle_t *handle, uint16_t *raw);
695
707uint8_t ens160_get_status(ens160_handle_t *handle, uint8_t *status);
708
720uint8_t ens160_get_calculation_temperature(ens160_handle_t *handle, uint16_t *raw);
721
733uint8_t ens160_get_calculation_humidity(ens160_handle_t *handle, uint16_t *raw);
734
746uint8_t ens160_get_checksum(ens160_handle_t *handle, uint8_t *checksum);
747
759uint8_t ens160_set_params(ens160_handle_t *handle, uint8_t params[8]);
760
772uint8_t ens160_get_params(ens160_handle_t *handle, uint8_t params[8]);
773
785uint8_t ens160_get_params_output(ens160_handle_t *handle, uint8_t params[8]);
786
798uint8_t ens160_temperature_convert_to_register(ens160_handle_t *handle, float celsius_deg, uint16_t *reg);
799
811uint8_t ens160_temperature_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *celsius_deg);
812
824uint8_t ens160_humidity_convert_to_register(ens160_handle_t *handle, float percentage, uint16_t *reg);
825
837uint8_t ens160_humidity_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *percentage);
838
850uint8_t ens160_resistance_convert_to_register(ens160_handle_t *handle, float ohm, uint16_t *reg);
851
863uint8_t ens160_resistance_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *ohm);
864
879uint8_t ens160_resistance_split(ens160_handle_t *handle, uint8_t raw[8],
880 uint16_t *resistance0, uint16_t *resistance1,
881 uint16_t *resistance2, uint16_t *resistance3);
882
886
893
907uint8_t ens160_set_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
908
922uint8_t ens160_get_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len);
923
927
931
932#ifdef __cplusplus
933}
934#endif
935
936#endif
ens160_mode_t
ens160 mode enumeration definition
uint8_t ens160_resistance_convert_to_register(ens160_handle_t *handle, float ohm, uint16_t *reg)
convert the resistance to the register raw data
ens160_address_t
ens160 address enumeration definition
uint8_t ens160_get_status(ens160_handle_t *handle, uint8_t *status)
get status
uint8_t ens160_resistance_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *ohm)
convert the register raw data to the resistance
uint8_t ens160_set_params(ens160_handle_t *handle, uint8_t params[8])
set params
uint8_t ens160_deinit(ens160_handle_t *handle)
close the chip
uint8_t ens160_set_addr_pin(ens160_handle_t *handle, ens160_address_t addr_pin)
set the iic address pin
uint8_t ens160_set_interrupt_pin_drive(ens160_handle_t *handle, ens160_pin_drive_t drive)
set interrupt pin drive
ens160_pin_polarity_t
ens160 pin polarity enumeration definition
uint8_t ens160_read_eco2(ens160_handle_t *handle, uint16_t *eco2_ppm)
read eco2
struct ens160_info_s ens160_info_t
ens160 information structure definition
uint8_t ens160_get_data_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t *enable)
get data interrupt pin asserted
uint8_t ens160_humidity_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *percentage)
convert the register raw data to the humidity
uint8_t ens160_info(ens160_info_t *info)
get chip's information
uint8_t ens160_clear(ens160_handle_t *handle)
clear
uint8_t ens160_get_temperature_compensation(ens160_handle_t *handle, uint16_t *raw)
get temperature compensation
uint8_t ens160_temperature_convert_to_register(ens160_handle_t *handle, float celsius_deg, uint16_t *reg)
convert the temperature to the register raw data
uint8_t ens160_get_params_output(ens160_handle_t *handle, uint8_t params[8])
get params output
uint8_t ens160_get_params(ens160_handle_t *handle, uint8_t params[8])
get params
uint8_t ens160_get_interrupt_pin_polarity(ens160_handle_t *handle, ens160_pin_polarity_t *polarity)
get interrupt pin polarity
uint8_t ens160_set_interface(ens160_handle_t *handle, ens160_interface_t interface)
set the chip interface
uint8_t ens160_soft_reset(ens160_handle_t *handle)
soft reset
uint8_t ens160_read_tvoc(ens160_handle_t *handle, uint16_t *tvoc_ppb)
read tvoc
uint8_t ens160_set_interrupt_pin_polarity(ens160_handle_t *handle, ens160_pin_polarity_t polarity)
set interrupt pin polarity
uint8_t ens160_set_mode(ens160_handle_t *handle, ens160_mode_t mode)
set mode
uint8_t ens160_humidity_convert_to_register(ens160_handle_t *handle, float percentage, uint16_t *reg)
convert the humidity to the register raw data
uint8_t ens160_get_interrupt_pin_drive(ens160_handle_t *handle, ens160_pin_drive_t *drive)
get interrupt pin drive
uint8_t ens160_set_humidity_compensation(ens160_handle_t *handle, uint16_t raw)
set humidity compensation
ens160_interface_t
ens160 interface enumeration definition
ens160_status_t
ens160 status enumeration definition
uint8_t ens160_set_interrupt(ens160_handle_t *handle, ens160_bool_t enable)
enable or disable interrupt
uint8_t ens160_get_mode(ens160_handle_t *handle, ens160_mode_t *mode)
get mode
uint8_t ens160_set_general_purpose_read_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t enable)
set general purpose read interrupt pin asserted
uint8_t ens160_read_aqi(ens160_handle_t *handle, uint8_t *uba)
read aqi
uint8_t ens160_irq_handler(ens160_handle_t *handle)
irq handler
uint8_t ens160_temperature_convert_to_data(ens160_handle_t *handle, uint16_t reg, float *celsius_deg)
convert the register raw data to the temperature
uint8_t ens160_get_interface(ens160_handle_t *handle, ens160_interface_t *interface)
get the chip interface
uint8_t ens160_get_humidity_compensation(ens160_handle_t *handle, uint16_t *raw)
get humidity compensation
uint8_t ens160_get_general_purpose_read_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t *enable)
get general purpose read interrupt pin asserted
ens160_bool_t
ens160 bool enumeration definition
uint8_t ens160_get_addr_pin(ens160_handle_t *handle, ens160_address_t *addr_pin)
get the iic address pin
uint8_t ens160_get_interrupt(ens160_handle_t *handle, ens160_bool_t *enable)
get interrupt
ens160_pin_drive_t
ens160 pin drive enumeration definition
uint8_t ens160_get_calculation_temperature(ens160_handle_t *handle, uint16_t *raw)
get calculation temperature
uint8_t ens160_get_app_version(ens160_handle_t *handle, uint8_t *major, uint8_t *minor, uint8_t *release)
get app version
struct ens160_handle_s ens160_handle_t
ens160 handle structure definition
uint8_t ens160_resistance_split(ens160_handle_t *handle, uint8_t raw[8], uint16_t *resistance0, uint16_t *resistance1, uint16_t *resistance2, uint16_t *resistance3)
resistance split
uint8_t ens160_get_calculation_humidity(ens160_handle_t *handle, uint16_t *raw)
get calculation humidity
uint8_t ens160_nop(ens160_handle_t *handle)
nop
uint8_t ens160_set_temperature_compensation(ens160_handle_t *handle, uint16_t raw)
set temperature compensation
uint8_t ens160_init(ens160_handle_t *handle)
initialize the chip
uint8_t ens160_set_data_interrupt_pin_asserted(ens160_handle_t *handle, ens160_bool_t enable)
set data interrupt pin asserted
uint8_t ens160_get_checksum(ens160_handle_t *handle, uint8_t *checksum)
get checksum
uint8_t ens160_read_etoh(ens160_handle_t *handle, uint16_t *etoh_ppb)
read etoh
@ ENS160_MODE_STANDARD
@ ENS160_MODE_DEEP_SLEEP
@ ENS160_MODE_IDLE
@ ENS160_ADDRESS_1
@ ENS160_ADDRESS_0
@ ENS160_PIN_POLARITY_HIGH
@ ENS160_PIN_POLARITY_LOW
@ ENS160_INTERFACE_SPI
@ ENS160_INTERFACE_IIC
@ ENS160_STATUS_NEWDAT
@ ENS160_STATUS_WARM_UP
@ ENS160_STATUS_ERROR
@ ENS160_STATUS_INVALID
@ ENS160_STATUS_START_UP
@ ENS160_STATUS_RUNNING
@ ENS160_STATUS_NEWGPR
@ ENS160_STATUS_NORMAL
@ ENS160_BOOL_TRUE
@ ENS160_BOOL_FALSE
@ ENS160_PIN_DRIVE_PUSH_PULL
@ ENS160_PIN_DRIVE_OPEN_DRAIN
uint8_t ens160_get_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t ens160_set_reg(ens160_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
ens160 handle structure definition
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
void(* receive_callback)(uint8_t type, uint16_t *dat)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
ens160 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]