-
Notifications
You must be signed in to change notification settings - Fork 6
/
sht3x.h
70 lines (59 loc) · 2.51 KB
/
sht3x.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include <stdbool.h>
#if (defined STM32L011xx) || (defined STM32L021xx) || \
(defined STM32L031xx) || (defined STM32L041xx) || \
(defined STM32L051xx) || (defined STM32L052xx) || (defined STM32L053xx) || \
(defined STM32L061xx) || (defined STM32L062xx) || (defined STM32L063xx) || \
(defined STM32L071xx) || (defined STM32L072xx) || (defined STM32L073xx) || \
(defined STM32L081xx) || (defined STM32L082xx) || (defined STM32L083xx)
#include "stm32l0xx_hal.h"
#elif defined (STM32L412xx) || defined (STM32L422xx) || \
defined (STM32L431xx) || (defined STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \
defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
defined (STM32L496xx) || defined (STM32L4A6xx) || \
defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
#include "stm32l4xx_hal.h"
#else
#error Platform not implemented
#endif
#ifndef SHT3X_I2C_TIMEOUT
#define SHT3X_I2C_TIMEOUT 30
#endif
#define SHT3X_I2C_DEVICE_ADDRESS_ADDR_PIN_LOW 0x44
#define SHT3X_I2C_DEVICE_ADDRESS_ADDR_PIN_HIGH 0x45
/**
* Structure defining a handle describing a SHT3x device.
*/
typedef struct {
/**
* The handle to the I2C bus for the device.
*/
I2C_HandleTypeDef *i2c_handle;
/**
* The I2C device address.
* @see{PCA9865_I2C_DEVICE_ADDRESS_ADDR_PIN_LOW} and @see{SHT3X_I2C_DEVICE_ADDRESS_ADDR_PIN_HIGH}
*/
uint16_t device_address;
} sht3x_handle_t;
/**
* Checks if an SHT3x is reachable using the given handle.
* @param handle Handle to the SHT3x device.
* @return True on success, false otherwise.
*/
bool sht3x_init(sht3x_handle_t *handle);
/**
* Takes a single temperature and humidity measurement.
* @param handle Handle to the SHT3x device.
* @param temperature Pointer to the storage location for the sampled temperature.
* @param humidity Pointer to the storage location for the sampled humidity.
* @return True on success, false otherwise.
*/
bool sht3x_read_temperature_and_humidity(sht3x_handle_t *handle, float *temperature, float *humidity);
/**
* Turns the SHT3x's internal heater on or of.
* @param handle Handle to the SHT3x device.
* @param enable True to enable to heater, false to disable it.
* @return True on success, false otherwise.
*/
bool sht3x_set_header_enable(sht3x_handle_t *handle, bool enable);