Loading...
Searching...
No Matches
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
9#pragma once
10
52#include <stdint.h>
53#include <stdbool.h>
54#include "periph/spi.h"
55#include "periph/gpio.h"
56
57#ifdef __cplusplus
58extern "C"
59{
60#endif
61
65typedef struct {
66 spi_t spi;
70 bool high_res;
71} adt7310_t;
72
77#define ADT7310_CONF_FAULT_QUEUE_MASK (0x03)
78#define ADT7310_CONF_FAULT_QUEUE_SHIFT (0)
79#define ADT7310_CONF_FAULT_QUEUE(x) (((x) << ADT7310_CONF_FAULT_QUEUE_SHIFT) & ADT7310_CONF_FAULT_QUEUE_MASK)
80#define ADT7310_CONF_CT_POL_MASK (0x04)
81#define ADT7310_CONF_CT_POL_SHIFT (2)
82#define ADT7310_CONF_CT_POL(x) (((x) << ADT7310_CONF_CT_POL_SHIFT) & ADT7310_CONF_CT_POL_MASK)
83#define ADT7310_CONF_INT_POL_MASK (0x08)
84#define ADT7310_CONF_INT_POL_SHIFT (3)
85#define ADT7310_CONF_INT_POL(x) (((x) << ADT7310_CONF_INT_POL_SHIFT) & ADT7310_CONF_INT_POL_MASK)
86#define ADT7310_CONF_INTCT_MODE_MASK (0x10)
87#define ADT7310_CONF_INTCT_MODE_SHIFT (4)
88#define ADT7310_CONF_INTCT_MODE(x) (((x) << ADT7310_CONF_INTCT_MODE_SHIFT) & ADT7310_CONF_INTCT_MODE_MASK)
89#define ADT7310_CONF_OPERATION_MODE_MASK (0x60)
90#define ADT7310_CONF_OPERATION_MODE_SHIFT (5)
91#define ADT7310_CONF_OPERATION_MODE(x) (((x) << ADT7310_CONF_OPERATION_MODE_SHIFT) & ADT7310_CONF_OPERATION_MODE_MASK)
92#define ADT7310_CONF_RESOLUTION_MASK (0x80)
93#define ADT7310_CONF_RESOLUTION_SHIFT (7)
94#define ADT7310_CONF_RESOLUTION(x) (((x) << ADT7310_CONF_RESOLUTION_SHIFT) & ADT7310_CONF_RESOLUTION_MASK)
95
99#define ADT7310_MODE_CONTINUOUS (ADT7310_CONF_OPERATION_MODE(0))
103#define ADT7310_MODE_ONE_SHOT (ADT7310_CONF_OPERATION_MODE(1))
107#define ADT7310_MODE_1SPS (ADT7310_CONF_OPERATION_MODE(2))
111#define ADT7310_MODE_SHUTDOWN (ADT7310_CONF_OPERATION_MODE(3))
123int adt7310_set_config(adt7310_t *dev, uint8_t config);
124
138int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs);
139
151int16_t adt7310_read_raw(const adt7310_t *dev);
152
163int32_t adt7310_read(const adt7310_t *dev);
164
174
175#ifdef __cplusplus
176}
177#endif
178
spi_clk_t
SPI clock type.
Definition periph_cpu.h:352
Low-level GPIO peripheral driver interface definitions.
int16_t adt7310_read_raw(const adt7310_t *dev)
Read raw temperature register value.
float adt7310_read_float(const adt7310_t *dev)
Read temperature value from sensor and convert to degrees Celsius.
int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs)
Initialize the ADT7310 sensor driver.
int32_t adt7310_read(const adt7310_t *dev)
Read temperature value from sensor and convert to milli-degrees Celsius.
int adt7310_set_config(adt7310_t *dev, uint8_t config)
Set configuration register of an ADT7310 sensor.
uint16_t gpio_t
GPIO type identifier.
Definition periph_cpu.h:117
Low-level SPI peripheral driver interface definition.
Device descriptor for ADT7310 sensors.
Definition adt7310.h:65
spi_t spi
SPI bus the sensor is connected to.
Definition adt7310.h:66
gpio_t cs
CS pin GPIO handle.
Definition adt7310.h:68
bool initialized
sensor status, true if sensor is initialized
Definition adt7310.h:69
bool high_res
Sensor resolution, true if configured to 16 bit resolution.
Definition adt7310.h:70
spi_clk_t clk
SPI bus clock speed.
Definition adt7310.h:67