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 
78 #define ADT7310_CONF_FAULT_QUEUE_MASK (0x03)
79 #define ADT7310_CONF_FAULT_QUEUE_SHIFT (0)
80 #define ADT7310_CONF_FAULT_QUEUE(x) (((x) << ADT7310_CONF_FAULT_QUEUE_SHIFT) & ADT7310_CONF_FAULT_QUEUE_MASK)
81 #define ADT7310_CONF_CT_POL_MASK (0x04)
82 #define ADT7310_CONF_CT_POL_SHIFT (2)
83 #define ADT7310_CONF_CT_POL(x) (((x) << ADT7310_CONF_CT_POL_SHIFT) & ADT7310_CONF_CT_POL_MASK)
84 #define ADT7310_CONF_INT_POL_MASK (0x08)
85 #define ADT7310_CONF_INT_POL_SHIFT (3)
86 #define ADT7310_CONF_INT_POL(x) (((x) << ADT7310_CONF_INT_POL_SHIFT) & ADT7310_CONF_INT_POL_MASK)
87 #define ADT7310_CONF_INTCT_MODE_MASK (0x10)
88 #define ADT7310_CONF_INTCT_MODE_SHIFT (4)
89 #define ADT7310_CONF_INTCT_MODE(x) (((x) << ADT7310_CONF_INTCT_MODE_SHIFT) & ADT7310_CONF_INTCT_MODE_MASK)
90 #define ADT7310_CONF_OPERATION_MODE_MASK (0x60)
91 #define ADT7310_CONF_OPERATION_MODE_SHIFT (5)
92 #define ADT7310_CONF_OPERATION_MODE(x) (((x) << ADT7310_CONF_OPERATION_MODE_SHIFT) & ADT7310_CONF_OPERATION_MODE_MASK)
93 #define ADT7310_CONF_RESOLUTION_MASK (0x80)
94 #define ADT7310_CONF_RESOLUTION_SHIFT (7)
95 #define ADT7310_CONF_RESOLUTION(x) (((x) << ADT7310_CONF_RESOLUTION_SHIFT) & ADT7310_CONF_RESOLUTION_MASK)
96 
100 #define ADT7310_MODE_CONTINUOUS (ADT7310_CONF_OPERATION_MODE(0))
101 
104 #define ADT7310_MODE_ONE_SHOT (ADT7310_CONF_OPERATION_MODE(1))
105 
108 #define ADT7310_MODE_1SPS (ADT7310_CONF_OPERATION_MODE(2))
109 
112 #define ADT7310_MODE_SHUTDOWN (ADT7310_CONF_OPERATION_MODE(3))
113 
124 int adt7310_set_config(adt7310_t *dev, uint8_t config);
125 
139 int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs);
140 
152 int16_t adt7310_read_raw(const adt7310_t *dev);
153 
164 int32_t adt7310_read(const adt7310_t *dev);
165 
174 float adt7310_read_float(const adt7310_t *dev);
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif /* ADT7310_H */
181 
adt7310_read_float
float adt7310_read_float(const adt7310_t *dev)
Read temperature value from sensor and convert to degrees Celsius.
spi.h
Low-level SPI peripheral driver interface definition.
adt7310_t::cs
gpio_t cs
CS pin GPIO handle.
Definition: adt7310.h:69
adt7310_t
Device descriptor for ADT7310 sensors.
Definition: adt7310.h:66
spi_clk_t
spi_clk_t
Available SPI clock speeds.
Definition: spi.h:173
adt7310_set_config
int adt7310_set_config(adt7310_t *dev, uint8_t config)
Set configuration register of an ADT7310 sensor.
adt7310_t::initialized
bool initialized
sensor status, true if sensor is initialized
Definition: adt7310.h:70
adt7310_read
int32_t adt7310_read(const adt7310_t *dev)
Read temperature value from sensor and convert to milli-degrees Celsius.
gpio.h
Low-level GPIO peripheral driver interface definitions.
adt7310_t::high_res
bool high_res
Sensor resolution, true if configured to 16 bit resolution.
Definition: adt7310.h:71
adt7310_init
int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs)
Initialize the ADT7310 sensor driver.
adt7310_t::clk
spi_clk_t clk
SPI bus clock speed.
Definition: adt7310.h:68
spi_t
unsigned int spi_t
Default type for SPI devices.
Definition: spi.h:118
adt7310_t::spi
spi_t spi
SPI bus the sensor is connected to.
Definition: adt7310.h:67
adt7310_read_raw
int16_t adt7310_read_raw(const adt7310_t *dev)
Read raw temperature register value.