no-OS
adt7420.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef __ADT7420_H__
40 #define __ADT7420_H__
41 
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 
46 #include "no_os_spi.h"
47 #include "no_os_i2c.h"
48 #include "no_os_util.h"
49 #include <stdbool.h>
50 
51 /******************************************************************************/
52 /************************** ADT7420 Definitions *******************************/
53 /******************************************************************************/
54 
55 /* ADT7420 address */
56 #define ADT7420_A0_PIN(x) (((x) & 0x1) << 0) // I2C Serial Bus Address Selection Pin
57 #define ADT7420_A1_PIN(x) (((x) & 0x1) << 1) // I2C Serial Bus Address Selection Pin
58 #define ADT7420_ADDRESS(x,y) (0x48 + ADT7420_A1_PIN(x) + ADT7420_A0_PIN(y))
59 
60 /* ADT7320 (SPI) registers */
61 #define ADT7320_REG_STATUS 0x00 // Status
62 #define ADT7320_REG_CONFIG 0x01 // Configuration
63 #define ADT7320_REG_TEMP 0x02 // Temperature value
64 #define ADT7320_REG_ID 0x03 // ID
65 #define ADT7320_REG_T_CRIT 0x04 // Temperature CRIT setpoint (147'C)
66 #define ADT7320_REG_HIST 0x05 // Temperature HYST setpoint (5'C)
67 #define ADT7320_REG_T_HIGH 0x06 // Temperature HIGH setpoint (64'C)
68 #define ADT7320_REG_T_LOW 0x07 // Temperature LOW setpoint (10'C)
69 
70 /* ADT7320 SPI command byte */
71 #define ADT7320_WRITE_MASK_CMD 0b00111000 // SPI write command
72 #define ADT7320_READ_CMD 0b01000000 // SPI read command
73 
74 /* ADT7420 (I2C) registers */
75 #define ADT7420_REG_TEMP_MSB 0x00 // Temperature value MSB
76 #define ADT7420_REG_TEMP_LSB 0x01 // Temperature value LSB
77 #define ADT7420_REG_STATUS 0x02 // Status
78 #define ADT7420_REG_CONFIG 0x03 // Configuration
79 #define ADT7420_REG_T_HIGH_MSB 0x04 // Temperature HIGH setpoint MSB
80 #define ADT7420_REG_T_HIGH_LSB 0x05 // Temperature HIGH setpoint LSB
81 #define ADT7420_REG_T_LOW_MSB 0x06 // Temperature LOW setpoint MSB
82 #define ADT7420_REG_T_LOW_LSB 0x07 // Temperature LOW setpoint LSB
83 #define ADT7420_REG_T_CRIT_MSB 0x08 // Temperature CRIT setpoint MSB
84 #define ADT7420_REG_T_CRIT_LSB 0x09 // Temperature CRIT setpoint LSB
85 #define ADT7420_REG_HIST 0x0A // Temperature HYST setpoint
86 #define ADT7420_REG_ID 0x0B // ID
87 #define ADT7420_REG_RESET 0x2F // Software reset
88 
89 /* ADT7420_REG_STATUS definition */
90 #define ADT7420_STATUS_T_LOW NO_OS_BIT(4)
91 #define ADT7420_STATUS_T_HIGH NO_OS_BIT(5)
92 #define ADT7420_STATUS_T_CRIT NO_OS_BIT(6)
93 #define ADT7420_STATUS_RDY NO_OS_BIT(7)
94 
95 /* ADT7420_REG_CONFIG definition */
96 #define ADT7420_CONFIG_OP_MODE(x) ((x) << 5) & (NO_OS_GENMASK(6,5))
97 #define ADT7420_CONFIG_RESOLUTION NO_OS_BIT(7)
98 
99 /* ADT7420_CONFIG_OP_MODE(x) options */
100 #define ADT7420_OP_MODE_CONT_CONV 0
101 #define ADT7420_OP_MODE_ONE_SHOT 1
102 #define ADT7420_OP_MODE_1_SPS 2
103 #define ADT7420_OP_MODE_SHUTDOWN 3
104 
105 /* ADT7420 default ID */
106 #define ADT7xxx_ID 0xC
107 
108 
109 /******************************************************************************/
110 /*************************** Types Declarations *******************************/
111 /******************************************************************************/
112 
116 };
117 
119  uint8_t resolution;
121 };
122 
131 };
132 
133 struct adt7420_dev {
134  /* I2C */
136  /* SPI */
138  /* Device Settings */
140  /* Device Settings */
142 
143 };
144 
147  /* I2C */
149  /* SPI */
151  } interface_init;
152  /* Device Settings */
154  /* Device Settings */
156 };
157 
158 extern const struct adt7420_chip_info chip_info[];
159 
160 /******************************************************************************/
161 /************************ Functions Declarations ******************************/
162 /******************************************************************************/
163 
165 uint16_t adt7420_get_register_value(struct adt7420_dev *dev,
166  uint8_t register_address);
168 uint16_t set_shift_reg(struct adt7420_dev *dev,
169  uint8_t register_address,
170  uint8_t *data) ;
171 
173 int32_t set_register_value(struct adt7420_dev *dev,
174  uint8_t register_address,
175  uint8_t num_data_bytes,
176  uint8_t *data, uint8_t mask, uint8_t value);
177 
179 int32_t adt7420_init(struct adt7420_dev **device,
181 
182 /* Free the resources allocated by adt7420_init(). */
183 int32_t adt7420_remove(struct adt7420_dev *dev);
184 
186 void adt7420_set_operation_mode(struct adt7420_dev *dev,
187  uint8_t mode);
188 
190 void adt7420_set_resolution(struct adt7420_dev *dev,
191  uint8_t resolution);
192 
194 int32_t adt7420_reset(struct adt7420_dev *dev);
195 
197 float adt7420_get_temperature(struct adt7420_dev *dev);
198 
200 uint16_t adt7420_i2c_get_register_value(struct adt7420_dev *dev,
201  uint8_t register_address);
202 
204 uint16_t adt7420_spi_get_register_value(struct adt7420_dev *dev,
205  uint8_t register_address);
206 
208 bool adt7420_is_spi(struct adt7420_dev *dev);
209 
210 #endif /* __ADT7420_H__ */
adt7420_remove
int32_t adt7420_remove(struct adt7420_dev *dev)
Free the resources allocated by adt7420_init().
Definition: adt7420.c:208
adt7420_get_temperature
float adt7420_get_temperature(struct adt7420_dev *dev)
Reads the temperature data and converts it to Celsius degrees.
Definition: adt7420.c:317
adt7420_init
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:148
ADT7320_REG_CONFIG
#define ADT7320_REG_CONFIG
Definition: adt7420.h:62
adt7420_dev::spi_desc
no_os_spi_desc * spi_desc
Definition: adt7420.h:137
adt7420_remove
int32_t adt7420_remove(struct adt7420_dev *dev)
Free the resources allocated by adt7420_init().
Definition: adt7420.c:208
no_os_tdm_platform_ops::tdm_ops_write
int32_t(* tdm_ops_write)(struct no_os_tdm_desc *, void *, uint16_t)
Definition: no_os_tdm.h:111
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:85
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:51
adt7420_get_register_value
uint16_t adt7420_get_register_value(struct adt7420_dev *dev, uint8_t register_address)
Reads the value of a register.
Definition: adt7420.c:81
ADT7xxx_ID
#define ADT7xxx_ID
Definition: adt7420.h:106
no_os_tdm_remove
int32_t no_os_tdm_remove(struct no_os_tdm_desc *desc)
Free the resources allocated by no_os_tdm_init().
Definition: no_os_tdm.c:70
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:82
adt7420_i2c_get_register_value
uint16_t adt7420_i2c_get_register_value(struct adt7420_dev *dev, uint8_t register_address)
Reads the value of a register I2C interface device.
Definition: adt7420.c:418
no_os_tdm_write
int32_t no_os_tdm_write(struct no_os_tdm_desc *desc, void *data, uint16_t nb_samples)
Write data using the TDM interface.
Definition: no_os_tdm.c:96
no_os_spi.h
Header file of SPI Interface.
ID_ADT7422
@ ID_ADT7422
Definition: adt7420.h:126
ADT7320_REG_STATUS
#define ADT7320_REG_STATUS
Definition: adt7420.h:61
adt7420_set_resolution
void adt7420_set_resolution(struct adt7420_dev *dev, uint8_t resolution)
Sets the resolution for ADT7420/ADT7320.
Definition: adt7420.c:261
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:70
set_shift_reg
uint16_t set_shift_reg(struct adt7420_dev *dev, uint8_t register_address, uint8_t *data)
Write to input shift register SPI interface.
Definition: adt7420.c:359
adt7420_get_temperature
float adt7420_get_temperature(struct adt7420_dev *dev)
Reads the temperature data and converts it to Celsius degrees.
Definition: adt7420.c:317
ID_ADT7420
@ ID_ADT7420
Definition: adt7420.h:125
adt7420_init_param::interface_type
Definition: adt7420.h:146
adt7420_dev::resolution_setting
uint8_t resolution_setting
Definition: adt7420.h:141
ID_ADT7410
@ ID_ADT7410
Definition: adt7420.h:124
adt7420_init_param::resolution_setting
uint8_t resolution_setting
Definition: adt7420.h:153
no_os_tdm_init_param::platform_ops
const struct no_os_tdm_platform_ops * platform_ops
Definition: no_os_tdm.h:83
adt7420_reset
int32_t adt7420_reset(struct adt7420_dev *dev)
Resets the SPI or I2C inteface for the ADT7420/ADT7320.
Definition: adt7420.c:287
ID_ADT7310
@ ID_ADT7310
Definition: adt7420.h:127
device
Definition: ad9361_util.h:75
no_os_tdm_platform_ops::tdm_ops_read
int32_t(* tdm_ops_read)(struct no_os_tdm_desc *, void *, uint16_t)
Definition: no_os_tdm.h:109
adt7420_spi_get_register_value
uint16_t adt7420_spi_get_register_value(struct adt7420_dev *dev, uint8_t register_address)
Reads the value of a register SPI interface device.
Definition: adt7420.c:399
ADT7320_READ_CMD
#define ADT7320_READ_CMD
Definition: adt7420.h:72
set_register_value
int32_t set_register_value(struct adt7420_dev *dev, uint8_t register_address, uint8_t num_data_bytes, uint8_t *data, uint8_t mask, uint8_t value)
Sets the value of a register SPI/I2C.
Definition: adt7420.c:102
set_shift_reg
uint16_t set_shift_reg(struct adt7420_dev *dev, uint8_t register_address, uint8_t *data)
Write to input shift register SPI interface.
Definition: adt7420.c:359
no_os_tdm_platform_ops::tdm_ops_remove
int32_t(* tdm_ops_remove)(struct no_os_tdm_desc *)
Definition: no_os_tdm.h:113
adt7420_init_param::interface_type::spi_init
no_os_spi_init_param spi_init
Definition: adt7420.h:150
ID_ADT7312
@ ID_ADT7312
Definition: adt7420.h:129
chip_info
const struct adt7420_chip_info chip_info[]
Definition: adt7420.c:50
ADT7320_REG_ID
#define ADT7320_REG_ID
Definition: adt7420.h:64
adt7420_set_operation_mode
void adt7420_set_operation_mode(struct adt7420_dev *dev, uint8_t mode)
Sets the operational mode for ADT7420/ADT7320.
Definition: adt7420.c:233
ADT7320_REG_TEMP
#define ADT7320_REG_TEMP
Definition: adt7420.h:63
no_os_tdm_desc
Structure holding TDM descriptor.
Definition: no_os_tdm.h:92
adt7420_init_param::interface_type::i2c_init
no_os_i2c_init_param i2c_init
Definition: adt7420.h:148
I2C
@ I2C
Definition: adt7420.h:115
I2C
@ I2C
Definition: adxl372.h:323
no_os_error.h
Error codes definition.
adt7420_spi_get_register_value
uint16_t adt7420_spi_get_register_value(struct adt7420_dev *dev, uint8_t register_address)
Reads the value of a register SPI interface device.
Definition: adt7420.c:399
chip_info
const struct adt7420_chip_info chip_info[]
Definition: adf4106.c:62
SPI
@ SPI
Definition: adt7420.h:114
adt7420_is_spi
bool adt7420_is_spi(struct adt7420_dev *dev)
Check if the interface of the selected device is SPI.
Definition: adt7420.c:442
ADT7420_CONFIG_RESOLUTION
#define ADT7420_CONFIG_RESOLUTION
Definition: adt7420.h:97
ADT7420_OP_MODE_SHUTDOWN
#define ADT7420_OP_MODE_SHUTDOWN
Definition: adt7420.h:103
adt7420_type
adt7420_type
Definition: adt7420.h:123
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
ADT7420_REG_ID
#define ADT7420_REG_ID
Definition: adt7420.h:86
ID_ADT7320
@ ID_ADT7320
Definition: adt7420.h:130
adt7420_dev::i2c_desc
no_os_i2c_desc * i2c_desc
Definition: adt7420.h:135
dev_interface
dev_interface
Definition: adt7420.h:113
ADT7420_REG_CONFIG
#define ADT7420_REG_CONFIG
Definition: adt7420.h:78
adt7420_get_register_value
uint16_t adt7420_get_register_value(struct adt7420_dev *dev, uint8_t register_address)
Reads the value of a register.
Definition: adt7420.c:81
no_os_i2c_desc
Structure holding I2C descriptor.
Definition: no_os_i2c.h:81
adt7420_init_param
Definition: adt7420.h:145
adt7420_set_resolution
void adt7420_set_resolution(struct adt7420_dev *dev, uint8_t resolution)
Sets the resolution for ADT7420/ADT7320.
Definition: adt7420.c:261
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:104
no_os_tdm_platform_ops::tdm_ops_init
int32_t(* tdm_ops_init)(struct no_os_tdm_desc **, const struct no_os_tdm_init_param *)
Definition: no_os_tdm.h:106
ID_ADT7311
@ ID_ADT7311
Definition: adt7420.h:128
no_os_i2c.h
Header file of I2C Interface.
ADT7420_CONFIG_OP_MODE
#define ADT7420_CONFIG_OP_MODE(x)
Definition: adt7420.h:96
ADT7420_REG_TEMP_LSB
#define ADT7420_REG_TEMP_LSB
Definition: adt7420.h:76
adt7420_init_param::interface_init
union adt7420_init_param::interface_type interface_init
adt7420_reset
int32_t adt7420_reset(struct adt7420_dev *dev)
Resets the SPI or I2C inteface for the ADT7420/ADT7320.
Definition: adt7420.c:287
adt7420_chip_info::resolution
uint8_t resolution
Definition: adt7420.h:119
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
adt7420_chip_info
Definition: adt7420.h:118
adt7420_chip_info::communication
enum dev_interface communication
Definition: adt7420.h:120
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
set_register_value
int32_t set_register_value(struct adt7420_dev *dev, uint8_t register_address, uint8_t num_data_bytes, uint8_t *data, uint8_t mask, uint8_t value)
Sets the value of a register SPI/I2C.
Definition: adt7420.c:102
adt7420_dev
Definition: adt7420.h:133
adt7420_dev::active_device
enum adt7420_type active_device
Definition: adt7420.h:139
no_os_tdm_init_param
Structure holding the parameters for TDM initialization.
Definition: no_os_tdm.h:63
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:70
adt7420_set_operation_mode
void adt7420_set_operation_mode(struct adt7420_dev *dev, uint8_t mode)
Sets the operational mode for ADT7420/ADT7320.
Definition: adt7420.c:233
ADT7320_WRITE_MASK_CMD
#define ADT7320_WRITE_MASK_CMD
Definition: adt7420.h:71
ADT7320_REG_HIST
#define ADT7320_REG_HIST
Definition: adt7420.h:66
no_os_tdm_read
int32_t no_os_tdm_read(struct no_os_tdm_desc *desc, void *data, uint16_t nb_samples)
Read data using the TDM interface.
Definition: no_os_tdm.c:82
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:51
ADT7420_REG_TEMP_MSB
#define ADT7420_REG_TEMP_MSB
Definition: adt7420.h:75
adt7420_init_param::active_device
enum adt7420_type active_device
Definition: adt7420.h:155
no_os_util.h
Implementation of utility functions.
adt7420_init
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:148
SPI
@ SPI
Definition: adxl372.h:322
no_os_tdm.h
Header file of TDM Interface.
no_os_tdm_desc::platform_ops
const struct no_os_tdm_platform_ops * platform_ops
Definition: no_os_tdm.h:94
ADT7420_REG_RESET
#define ADT7420_REG_RESET
Definition: adt7420.h:87
no_os_tdm_init
int32_t no_os_tdm_init(struct no_os_tdm_desc **desc, const struct no_os_tdm_init_param *param)
Initialize the TDM communication peripheral.
Definition: no_os_tdm.c:51
adt7420_i2c_get_register_value
uint16_t adt7420_i2c_get_register_value(struct adt7420_dev *dev, uint8_t register_address)
Reads the value of a register I2C interface device.
Definition: adt7420.c:418
adt7420_is_spi
bool adt7420_is_spi(struct adt7420_dev *dev)
Check if the interface of the selected device is SPI.
Definition: adt7420.c:442
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112
adt7420.h
Header file of ADT7420 Driver.