Loading...
Searching...
No Matches
adt7310.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Eistec AB
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
48
49#include <stdint.h>
50#include <stdbool.h>
51#include "periph/spi.h"
52#include "periph/gpio.h"
53
54#ifdef __cplusplus
55extern "C"
56{
57#endif
58
62typedef struct {
63 spi_t spi;
65 gpio_t cs;
67 bool high_res;
68} adt7310_t;
69
74#define ADT7310_CONF_FAULT_QUEUE_MASK (0x03)
75#define ADT7310_CONF_FAULT_QUEUE_SHIFT (0)
76#define ADT7310_CONF_FAULT_QUEUE(x) (((x) << ADT7310_CONF_FAULT_QUEUE_SHIFT) & ADT7310_CONF_FAULT_QUEUE_MASK)
77#define ADT7310_CONF_CT_POL_MASK (0x04)
78#define ADT7310_CONF_CT_POL_SHIFT (2)
79#define ADT7310_CONF_CT_POL(x) (((x) << ADT7310_CONF_CT_POL_SHIFT) & ADT7310_CONF_CT_POL_MASK)
80#define ADT7310_CONF_INT_POL_MASK (0x08)
81#define ADT7310_CONF_INT_POL_SHIFT (3)
82#define ADT7310_CONF_INT_POL(x) (((x) << ADT7310_CONF_INT_POL_SHIFT) & ADT7310_CONF_INT_POL_MASK)
83#define ADT7310_CONF_INTCT_MODE_MASK (0x10)
84#define ADT7310_CONF_INTCT_MODE_SHIFT (4)
85#define ADT7310_CONF_INTCT_MODE(x) (((x) << ADT7310_CONF_INTCT_MODE_SHIFT) & ADT7310_CONF_INTCT_MODE_MASK)
86#define ADT7310_CONF_OPERATION_MODE_MASK (0x60)
87#define ADT7310_CONF_OPERATION_MODE_SHIFT (5)
88#define ADT7310_CONF_OPERATION_MODE(x) (((x) << ADT7310_CONF_OPERATION_MODE_SHIFT) & ADT7310_CONF_OPERATION_MODE_MASK)
89#define ADT7310_CONF_RESOLUTION_MASK (0x80)
90#define ADT7310_CONF_RESOLUTION_SHIFT (7)
91#define ADT7310_CONF_RESOLUTION(x) (((x) << ADT7310_CONF_RESOLUTION_SHIFT) & ADT7310_CONF_RESOLUTION_MASK)
92
96#define ADT7310_MODE_CONTINUOUS (ADT7310_CONF_OPERATION_MODE(0))
100#define ADT7310_MODE_ONE_SHOT (ADT7310_CONF_OPERATION_MODE(1))
104#define ADT7310_MODE_1SPS (ADT7310_CONF_OPERATION_MODE(2))
108#define ADT7310_MODE_SHUTDOWN (ADT7310_CONF_OPERATION_MODE(3))
110
120int adt7310_set_config(adt7310_t *dev, uint8_t config);
121
135int adt7310_init(adt7310_t *dev, spi_t spi, spi_clk_t clk, gpio_t cs);
136
148int16_t adt7310_read_raw(const adt7310_t *dev);
149
160int32_t adt7310_read(const adt7310_t *dev);
161
171
172#ifdef __cplusplus
173}
174#endif
175
spi_clk_t
Definition periph_cpu.h:348
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.
Low-level SPI peripheral driver interface definition.
Device descriptor for ADT7310 sensors.
Definition adt7310.h:62
spi_t spi
SPI bus the sensor is connected to.
Definition adt7310.h:63
gpio_t cs
CS pin GPIO handle.
Definition adt7310.h:65
bool initialized
sensor status, true if sensor is initialized
Definition adt7310.h:66
bool high_res
Sensor resolution, true if configured to 16 bit resolution.
Definition adt7310.h:67
spi_clk_t clk
SPI bus clock speed.
Definition adt7310.h:64