no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
adt7420.h
Go to the documentation of this file.
1/***************************************************************************/
33#ifndef __ADT7420_H__
34#define __ADT7420_H__
35
36#include "no_os_spi.h"
37#include "no_os_i2c.h"
38#include "no_os_util.h"
39#include <stdbool.h>
40
41/* ADT7420 address */
42#define ADT7420_A0_PIN(x) (((x) & 0x1) << 0) // I2C Serial Bus Address Selection Pin
43#define ADT7420_A1_PIN(x) (((x) & 0x1) << 1) // I2C Serial Bus Address Selection Pin
44#define ADT7420_ADDRESS(x,y) (0x48 + ADT7420_A1_PIN(x) + ADT7420_A0_PIN(y))
45#define ADT7320_L16 NO_OS_BIT(8) //indicator that register is 16-bit
46#define ADT7320_ADDR_MSK NO_OS_GENMASK(7,0)
47
48/* ADT7320 (SPI) registers */
49#define ADT7320_REG_STATUS 0x00 // Status
50#define ADT7320_REG_CONFIG 0x01 // Configuration
51#define ADT7320_REG_TEMP (ADT7320_L16 | 0x02) // Temperature value
52#define ADT7320_REG_ID 0x03 // ID
53#define ADT7320_REG_T_CRIT (ADT7320_L16 | 0x04) // Temperature CRIT setpoint (147'C)
54#define ADT7320_REG_HIST 0x05 // Temperature HYST setpoint (5'C)
55#define ADT7320_REG_T_HIGH (ADT7320_L16 | 0x06) // Temperature HIGH setpoint (64'C)
56#define ADT7320_REG_T_LOW (ADT7320_L16 | 0x07) // Temperature LOW setpoint (10'C)
57
58/* ADT7320 SPI command byte */
59#define ADT7320_WRITE_MASK_CMD 0b00111000 // SPI write command
60#define ADT7320_READ_CMD 0b01000000 // SPI read command
61
62/* ADT7420 (I2C) registers */
63#define ADT7420_REG_TEMP_MSB (ADT7320_L16 |0x00) // Temperature value MSB
64#define ADT7420_REG_TEMP_LSB 0x01 // Temperature value LSB
65#define ADT7420_REG_STATUS 0x02 // Status
66#define ADT7420_REG_CONFIG 0x03 // Configuration
67#define ADT7420_REG_T_HIGH_MSB (ADT7320_L16 |0x04 )// Temperature HIGH setpoint MSB
68#define ADT7420_REG_T_HIGH_LSB 0x05 // Temperature HIGH setpoint LSB
69#define ADT7420_REG_T_LOW_MSB (ADT7320_L16 |0x06) // Temperature LOW setpoint MSB
70#define ADT7420_REG_T_LOW_LSB 0x07 // Temperature LOW setpoint LSB
71#define ADT7420_REG_T_CRIT_MSB (ADT7320_L16 |0x08) // Temperature CRIT setpoint MSB
72#define ADT7420_REG_T_CRIT_LSB 0x09 // Temperature CRIT setpoint LSB
73#define ADT7420_REG_HIST 0x0A // Temperature HYST setpoint
74#define ADT7420_REG_ID 0x0B // ID
75#define ADT7420_REG_RESET 0x2F // Software reset
76
77/* ADT7420_REG_STATUS definition */
78#define ADT7420_STATUS_T_LOW NO_OS_BIT(4)
79#define ADT7420_STATUS_T_HIGH NO_OS_BIT(5)
80#define ADT7420_STATUS_T_CRIT NO_OS_BIT(6)
81#define ADT7420_STATUS_RDY NO_OS_BIT(7)
82
83/* ADT7420_REG_CONFIG definition */
84#define ADT7420_CONFIG_OP_MODE(x) ((x) << 5) & (NO_OS_GENMASK(6,5))
85#define ADT7420_CONFIG_RESOLUTION NO_OS_BIT(7)
86
87/* ADT7420 temperature conversion definitions */
88#define ADT7420_16BIT_NEG NO_OS_BIT(16)
89#define ADT7420_16BIT_SIGN 0x8000
90#define ADT7420_16BIT_DIV 128
91#define ADT7420_13BIT_NEG NO_OS_BIT(13)
92#define ADT7420_13BIT_SIGN 0x1000
93#define ADT7420_13BIT_DIV 16
94
95/* ADT7420_CONFIG_OP_MODE(x) options */
96#define ADT7420_OP_MODE_CONT_CONV 0
97#define ADT7420_OP_MODE_ONE_SHOT 1
98#define ADT7420_OP_MODE_1_SPS 2
99#define ADT7420_OP_MODE_SHUTDOWN 3
100
101/* ADT7420 default ID */
102#define ADT7xxx_ID 0xC
103
104#define ADT7420_RESET_DELAY 1
105
106
111
116
126
128 /* I2C */
130 /* SPI */
132 /* Device Settings */
134 /* Device Settings */
136
137};
138
146 /* Device Settings */
148 /* Device Settings */
150};
151
152extern const struct adt7420_chip_info chip_info[];
153
155int adt7420_reg_read(struct adt7420_dev *dev,
156 uint16_t register_address, uint16_t *data);
157
158/* Read-modify-write operation*/
160 uint16_t register_address, uint8_t mask, uint8_t value);
161
162/* Write to SPI register */
163int adt7420_spi_reg_write(struct adt7420_dev *dev, uint16_t register_address,
164 uint32_t data);
165
166/* Write to I2C register */
167int adt7420_i2c_reg_write(struct adt7420_dev *dev, uint16_t register_address,
168 uint32_t data);
169
170/*Sets register value*/
171int adt7420_reg_write(struct adt7420_dev *dev,
172 uint16_t register_address,
173 uint32_t data);
174
176int32_t adt7420_init(struct adt7420_dev **device,
178
179/* Free the resources allocated by adt7420_init(). */
180int32_t adt7420_remove(struct adt7420_dev *dev);
181
184 uint8_t mode);
185
187int adt7420_set_resolution(struct adt7420_dev *dev,
188 uint8_t resolution);
189
191int32_t adt7420_reset(struct adt7420_dev *dev);
192
194float adt7420_get_temperature(struct adt7420_dev *dev);
195
197int adt7420_i2c_reg_read(struct adt7420_dev *dev,
198 uint16_t register_address, uint16_t *data);
199
201int adt7420_spi_reg_read(struct adt7420_dev *dev,
202 uint16_t register_address, uint16_t *data);
203
205bool adt7420_is_spi(struct adt7420_dev *dev);
206
207#endif /* __ADT7420_H__ */
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
int32_t adt7420_init(struct adt7420_dev **device, struct adt7420_init_param init_param)
Initializes the communication peripheral and checks if the device is present.
Definition adt7420.c:199
float adt7420_get_temperature(struct adt7420_dev *dev)
Reads the temperature data and converts it to Celsius degrees.
Definition adt7420.c:363
int32_t adt7420_remove(struct adt7420_dev *dev)
Free the resources allocated by adt7420_init().
Definition adt7420.c:261
int adt7420_reg_write(struct adt7420_dev *dev, uint16_t register_address, uint32_t data)
Sets the value of a register SPI/I2C.
Definition adt7420.c:175
adt7420_type
Definition adt7420.h:117
@ ID_ADT7310
Definition adt7420.h:121
@ ID_ADT7320
Definition adt7420.h:124
@ ID_ADT7422
Definition adt7420.h:120
@ ID_ADT7410
Definition adt7420.h:118
@ ID_ADT7312
Definition adt7420.h:123
@ ID_ADT7420
Definition adt7420.h:119
@ ID_ADT7311
Definition adt7420.h:122
int32_t adt7420_reset(struct adt7420_dev *dev)
Resets the SPI or I2C inteface for the ADT7420/ADT7320.
Definition adt7420.c:333
bool adt7420_is_spi(struct adt7420_dev *dev)
Check if the interface of the selected device is SPI.
Definition adt7420.c:470
dev_interface
Definition adt7420.h:107
int adt7420_set_operation_mode(struct adt7420_dev *dev, uint8_t mode)
Sets the operational mode for ADT7420/ADT7320.
Definition adt7420.c:284
int adt7420_i2c_reg_write(struct adt7420_dev *dev, uint16_t register_address, uint32_t data)
Write a value of a register via I2C.
Definition adt7420.c:144
int adt7420_reg_update_bits(struct adt7420_dev *dev, uint16_t register_address, uint8_t mask, uint8_t value)
Sets the value of a register SPI/I2C.
Definition adt7420.c:91
int adt7420_i2c_reg_read(struct adt7420_dev *dev, uint16_t register_address, uint16_t *data)
Reads the value of a register I2C interface device.
Definition adt7420.c:438
int adt7420_spi_reg_write(struct adt7420_dev *dev, uint16_t register_address, uint32_t data)
Write a value of a register via SPI.
Definition adt7420.c:113
int adt7420_spi_reg_read(struct adt7420_dev *dev, uint16_t register_address, uint16_t *data)
Reads the value of a register SPI interface device.
Definition adt7420.c:404
int adt7420_reg_read(struct adt7420_dev *dev, uint16_t register_address, uint16_t *data)
Reads the value of a register.
Definition adt7420.c:72
int adt7420_set_resolution(struct adt7420_dev *dev, uint8_t resolution)
Sets the resolution for ADT7420/ADT7320.
Definition adt7420.c:308
@ I2C
Definition adxl372.h:311
@ SPI
Definition adxl372.h:310
int interface_init(struct no_os_gpio_desc **gpio_led_desc)
Interface initialization routines.
Definition interface.c:45
Header file of I2C Interface.
Header file of SPI Interface.
Header file of utility functions.
Definition adt7420.h:112
enum dev_interface communication
Definition adt7420.h:114
uint8_t resolution
Definition adt7420.h:113
Definition adt7420.h:127
struct no_os_spi_desc * spi_desc
Definition adt7420.h:131
enum adt7420_type active_device
Definition adt7420.h:133
uint8_t resolution_setting
Definition adt7420.h:135
struct no_os_i2c_desc * i2c_desc
Definition adt7420.h:129
Definition adt7420.h:139
uint8_t resolution_setting
Definition adt7420.h:147
enum adt7420_type active_device
Definition adt7420.h:149
Definition ad9361_util.h:63
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128
Definition adt7420.h:140
struct no_os_i2c_init_param i2c_init
Definition adt7420.h:142
struct no_os_spi_init_param spi_init
Definition adt7420.h:144