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 
Low-level GPIO peripheral driver interface definitions.
float adt7310_read_float(const adt7310_t *dev)
Read temperature value from sensor and convert to degrees Celsius.
int16_t adt7310_read_raw(const adt7310_t *dev)
Read raw temperature register value.
Low-level SPI peripheral driver interface definition.
gpio_t cs
CS pin GPIO handle.
Definition: adt7310.h:69
int32_t adt7310_read(const adt7310_t *dev)
Read temperature value from sensor and convert to milli-degrees Celsius.
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
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