LibDriver STS3X
Loading...
Searching...
No Matches
driver_sts3x.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_STS3X_H
38#define DRIVER_STS3X_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 STS3X_ADDRESS_0 = (0x4A << 1),
65 STS3X_ADDRESS_1 = (0x4B << 1),
67
71typedef enum
72{
76
88
98
111
115typedef struct sts3x_handle_s
116{
117 uint8_t (*iic_init)(void);
118 uint8_t (*iic_deinit)(void);
119 uint8_t (*iic_write_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len);
120 uint8_t (*iic_read_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len);
121 void (*delay_ms)(uint32_t ms);
122 void (*debug_print)(const char *const fmt, ...);
123 uint8_t iic_addr;
125 uint8_t inited;
127
143
147
154
161#define DRIVER_STS3X_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
162
169#define DRIVER_STS3X_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
170
177#define DRIVER_STS3X_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
178
185#define DRIVER_STS3X_LINK_IIC_READ_ADDRESS16(HANDLE, FUC) (HANDLE)->iic_read_address16 = FUC
186
193#define DRIVER_STS3X_LINK_IIC_WRITE_ADDRESS16(HANDLE, FUC) (HANDLE)->iic_write_address16 = FUC
194
201#define DRIVER_STS3X_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
202
209#define DRIVER_STS3X_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
210
214
221
230uint8_t sts3x_info(sts3x_info_t *info);
231
242uint8_t sts3x_set_addr_pin(sts3x_handle_t *handle, sts3x_address_t addr_pin);
243
254uint8_t sts3x_get_addr_pin(sts3x_handle_t *handle, sts3x_address_t *addr_pin);
255
266uint8_t sts3x_init(sts3x_handle_t *handle);
267
278uint8_t sts3x_deinit(sts3x_handle_t *handle);
279
293uint8_t sts3x_single_read(sts3x_handle_t *handle, sts3x_bool_t clock_stretching_enable,
294 uint16_t *temperature_raw, float *temperature_s);
295
308
320
333uint8_t sts3x_continuous_read(sts3x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s);
334
345uint8_t sts3x_get_status(sts3x_handle_t *handle, uint16_t *status);
346
356uint8_t sts3x_clear_status(sts3x_handle_t *handle);
357
368uint8_t sts3x_set_repeatability(sts3x_handle_t *handle, sts3x_repeatability_t repeatability);
369
380uint8_t sts3x_get_repeatability(sts3x_handle_t *handle, sts3x_repeatability_t *repeatability);
381
392uint8_t sts3x_soft_reset(sts3x_handle_t *handle);
393
405uint8_t sts3x_set_heater(sts3x_handle_t *handle, sts3x_bool_t enable);
406
410
417
429uint8_t sts3x_set_reg(sts3x_handle_t *handle, uint16_t command);
430
444uint8_t sts3x_get_reg(sts3x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len);
445
449
453
454#ifdef __cplusplus
455}
456#endif
457
458#endif
uint8_t sts3x_set_addr_pin(sts3x_handle_t *handle, sts3x_address_t addr_pin)
set the iic address pin
uint8_t sts3x_get_repeatability(sts3x_handle_t *handle, sts3x_repeatability_t *repeatability)
get the measurement repeatability
uint8_t sts3x_clear_status(sts3x_handle_t *handle)
clear the current status
sts3x_address_t
sts3x address enumeration definition
uint8_t sts3x_set_repeatability(sts3x_handle_t *handle, sts3x_repeatability_t repeatability)
set the measurement repeatability
sts3x_rate_t
sts3x rate enumeration definition
sts3x_status_t
sts3x status enumeration definition
uint8_t sts3x_continuous_read(sts3x_handle_t *handle, uint16_t *temperature_raw, float *temperature_s)
read data continuously
uint8_t sts3x_soft_reset(sts3x_handle_t *handle)
soft reset the chip
uint8_t sts3x_info(sts3x_info_t *info)
get chip's information
struct sts3x_handle_s sts3x_handle_t
sts3x handle structure definition
uint8_t sts3x_start_continuous_read(sts3x_handle_t *handle, sts3x_rate_t rate)
start reading
uint8_t sts3x_get_addr_pin(sts3x_handle_t *handle, sts3x_address_t *addr_pin)
get the iic address pin
uint8_t sts3x_init(sts3x_handle_t *handle)
initialize the chip
struct sts3x_info_s sts3x_info_t
sts3x information structure definition
uint8_t sts3x_set_heater(sts3x_handle_t *handle, sts3x_bool_t enable)
enable or disable the chip heater
sts3x_repeatability_t
sts3x repeatability enumeration definition
uint8_t sts3x_get_status(sts3x_handle_t *handle, uint16_t *status)
get the current status
uint8_t sts3x_stop_continuous_read(sts3x_handle_t *handle)
stop reading
uint8_t sts3x_deinit(sts3x_handle_t *handle)
close the chip
uint8_t sts3x_single_read(sts3x_handle_t *handle, sts3x_bool_t clock_stretching_enable, uint16_t *temperature_raw, float *temperature_s)
read data once
sts3x_bool_t
sts3x bool enumeration definition
@ STS3X_ADDRESS_1
@ STS3X_ADDRESS_0
@ STS3X_RATE_1HZ
@ STS3X_RATE_4HZ
@ STS3X_RATE_0P5HZ
@ STS3X_RATE_10HZ
@ STS3X_RATE_2HZ
@ STS3X_STATUS_CHECKSUM_STATUS
@ STS3X_STATUS_ALERT_PENDING_STATUS
@ STS3X_STATUS_SYSTEM_RESET
@ STS3X_STATUS_HEATER_ON
@ STS3X_STATUS_TEMPERATURE_ALERT
@ STS3X_STATUS_COMMAND_STATUS
@ STS3X_REPEATABILITY_HIGH
@ STS3X_REPEATABILITY_MEDIUM
@ STS3X_REPEATABILITY_LOW
@ STS3X_BOOL_FALSE
@ STS3X_BOOL_TRUE
uint8_t sts3x_set_reg(sts3x_handle_t *handle, uint16_t command)
set the chip register
uint8_t sts3x_get_reg(sts3x_handle_t *handle, uint16_t command, uint8_t *buf, uint16_t len)
get the chip register
sts3x handle structure definition
void(* delay_ms)(uint32_t ms)
uint8_t repeatability
uint8_t(* iic_read_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write_address16)(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
sts3x 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]