adt7310.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Eistec AB
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
50 #ifndef ADT7310_H
51 #define ADT7310_H
52 
53 #include <stdint.h>
54 #include <stdbool.h>
55 #include "periph/spi.h"
56 #include "periph/gpio.h"
57 
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
66 typedef struct {
69  gpio_t cs;
70  bool initialized;
71  bool high_res;
72 } adt7310_t;
73 
76 #define ADT7310_CONF_FAULT_QUEUE_MASK (0x03)
77 #define ADT7310_CONF_FAULT_QUEUE_SHIFT (0)
78 #define ADT7310_CONF_FAULT_QUEUE(x) (((x) << ADT7310_CONF_FAULT_QUEUE_SHIFT) & ADT7310_CONF_FAULT_QUEUE_MASK)
79 #define ADT7310_CONF_CT_POL_MASK (0x04)
80 #define ADT7310_CONF_CT_POL_SHIFT (2)
81 #define ADT7310_CONF_CT_POL(x) (((x) << ADT7310_CONF_CT_POL_SHIFT) & ADT7310_CONF_CT_POL_MASK)
82 #define ADT7310_CONF_INT_POL_MASK (0x08)
83 #define ADT7310_CONF_INT_POL_SHIFT (3)
84 #define ADT7310_CONF_INT_POL(x) (((x) << ADT7310_CONF_INT_POL_SHIFT) & ADT7310_CONF_INT_POL_MASK)
85 #define ADT7310_CONF_INTCT_MODE_MASK (0x10)
86 #define ADT7310_CONF_INTCT_MODE_SHIFT (4)
87 #define ADT7310_CONF_INTCT_MODE(x) (((x) << ADT7310_CONF_INTCT_MODE_SHIFT) & ADT7310_CONF_INTCT_MODE_MASK)
88 #define ADT7310_CONF_OPERATION_MODE_MASK (0x60)
89 #define ADT7310_CONF_OPERATION_MODE_SHIFT (5)
90 #define ADT7310_CONF_OPERATION_MODE(x) (((x) << ADT7310_CONF_OPERATION_MODE_SHIFT) & ADT7310_CONF_OPERATION_MODE_MASK)
91 #define ADT7310_CONF_RESOLUTION_MASK (0x80)
92 #define ADT7310_CONF_RESOLUTION_SHIFT (7)
93 #define ADT7310_CONF_RESOLUTION(x) (((x) << ADT7310_CONF_RESOLUTION_SHIFT) & ADT7310_CONF_RESOLUTION_MASK)
94 
96 #define ADT7310_MODE_CONTINUOUS (ADT7310_CONF_OPERATION_MODE(0))
97 
98 #define ADT7310_MODE_ONE_SHOT (ADT7310_CONF_OPERATION_MODE(1))
99 
100 #define ADT7310_MODE_1SPS (ADT7310_CONF_OPERATION_MODE(2))
101 
102 #define ADT7310_MODE_SHUTDOWN (ADT7310_CONF_OPERATION_MODE(3))
103 
114 int adt7310_set_config(adt7310_t *dev, uint8_t config);
115 
129 int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs);
130 
142 int16_t adt7310_read_raw(adt7310_t *dev);
143 
154 int32_t adt7310_read(adt7310_t *dev);
155 
164 float adt7310_read_float(adt7310_t *dev);
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif /* ADT7310_H */
171 
Low-level GPIO peripheral driver interface definitions.
int32_t adt7310_read(adt7310_t *dev)
Read temperature value from sensor and convert to milli-degrees Celsius.
Low-level SPI peripheral driver interface definition.
gpio_t cs
CS pin GPIO handle.
Definition: adt7310.h:69
int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs)
Initialize the ADT7310 sensor driver.
int adt7310_set_config(adt7310_t *dev, uint8_t config)
Set configuration register of an ADT7310 sensor.
bool initialized
sensor status, true if sensor is initialized
Definition: adt7310.h:70
float adt7310_read_float(adt7310_t *dev)
Read temperature value from sensor and convert to degrees Celsius.
int16_t adt7310_read_raw(adt7310_t *dev)
Read raw temperature register value.
spi_t spi
SPI bus the sensor is connected to.
Definition: adt7310.h:67
bool high_res
Sensor resolution, true if configured to 16 bit resolution.
Definition: adt7310.h:71
Device descriptor for ADT7310 sensors.
Definition: adt7310.h:66
spi_clk_t clk
SPI bus clock speed.
Definition: adt7310.h:68
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:105