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 #define ADT7320_L16 NO_OS_BIT(8) //indicator that register is 16-bit
60 #define ADT7320_ADDR_MSK NO_OS_GENMASK(7,0)
61 
62 /* ADT7320 (SPI) registers */
63 #define ADT7320_REG_STATUS 0x00 // Status
64 #define ADT7320_REG_CONFIG 0x01 // Configuration
65 #define ADT7320_REG_TEMP (ADT7320_L16 | 0x02) // Temperature value
66 #define ADT7320_REG_ID 0x03 // ID
67 #define ADT7320_REG_T_CRIT (ADT7320_L16 | 0x04) // Temperature CRIT setpoint (147'C)
68 #define ADT7320_REG_HIST 0x05 // Temperature HYST setpoint (5'C)
69 #define ADT7320_REG_T_HIGH (ADT7320_L16 | 0x06) // Temperature HIGH setpoint (64'C)
70 #define ADT7320_REG_T_LOW (ADT7320_L16 | 0x07) // Temperature LOW setpoint (10'C)
71 
72 /* ADT7320 SPI command byte */
73 #define ADT7320_WRITE_MASK_CMD 0b00111000 // SPI write command
74 #define ADT7320_READ_CMD 0b01000000 // SPI read command
75 
76 /* ADT7420 (I2C) registers */
77 #define ADT7420_REG_TEMP_MSB (ADT7320_L16 |0x00) // Temperature value MSB
78 #define ADT7420_REG_TEMP_LSB 0x01 // Temperature value LSB
79 #define ADT7420_REG_STATUS 0x02 // Status
80 #define ADT7420_REG_CONFIG 0x03 // Configuration
81 #define ADT7420_REG_T_HIGH_MSB (ADT7320_L16 |0x04 )// Temperature HIGH setpoint MSB
82 #define ADT7420_REG_T_HIGH_LSB 0x05 // Temperature HIGH setpoint LSB
83 #define ADT7420_REG_T_LOW_MSB (ADT7320_L16 |0x06) // Temperature LOW setpoint MSB
84 #define ADT7420_REG_T_LOW_LSB 0x07 // Temperature LOW setpoint LSB
85 #define ADT7420_REG_T_CRIT_MSB (ADT7320_L16 |0x08) // Temperature CRIT setpoint MSB
86 #define ADT7420_REG_T_CRIT_LSB 0x09 // Temperature CRIT setpoint LSB
87 #define ADT7420_REG_HIST 0x0A // Temperature HYST setpoint
88 #define ADT7420_REG_ID 0x0B // ID
89 #define ADT7420_REG_RESET 0x2F // Software reset
90 
91 /* ADT7420_REG_STATUS definition */
92 #define ADT7420_STATUS_T_LOW NO_OS_BIT(4)
93 #define ADT7420_STATUS_T_HIGH NO_OS_BIT(5)
94 #define ADT7420_STATUS_T_CRIT NO_OS_BIT(6)
95 #define ADT7420_STATUS_RDY NO_OS_BIT(7)
96 
97 /* ADT7420_REG_CONFIG definition */
98 #define ADT7420_CONFIG_OP_MODE(x) ((x) << 5) & (NO_OS_GENMASK(6,5))
99 #define ADT7420_CONFIG_RESOLUTION NO_OS_BIT(7)
100 
101 /* ADT7420 temperature conversion definitions */
102 #define ADT7420_16BIT_NEG NO_OS_BIT(16)
103 #define ADT7420_16BIT_SIGN 0x8000
104 #define ADT7420_16BIT_DIV 128
105 #define ADT7420_13BIT_NEG NO_OS_BIT(13)
106 #define ADT7420_13BIT_SIGN 0x1000
107 #define ADT7420_13BIT_DIV 16
108 
109 /* ADT7420_CONFIG_OP_MODE(x) options */
110 #define ADT7420_OP_MODE_CONT_CONV 0
111 #define ADT7420_OP_MODE_ONE_SHOT 1
112 #define ADT7420_OP_MODE_1_SPS 2
113 #define ADT7420_OP_MODE_SHUTDOWN 3
114 
115 /* ADT7420 default ID */
116 #define ADT7xxx_ID 0xC
117 
118 #define ADT7420_RESET_DELAY 1
119 
120 
121 /******************************************************************************/
122 /*************************** Types Declarations *******************************/
123 /******************************************************************************/
124 
128 };
129 
131  uint8_t resolution;
133 };
134 
143 };
144 
145 struct adt7420_dev {
146  /* I2C */
148  /* SPI */
150  /* Device Settings */
152  /* Device Settings */
154 
155 };
156 
159  /* I2C */
161  /* SPI */
163  } interface_init;
164  /* Device Settings */
166  /* Device Settings */
168 };
169 
170 extern const struct adt7420_chip_info chip_info[];
171 
172 /******************************************************************************/
173 /************************ Functions Declarations ******************************/
174 /******************************************************************************/
175 
177 int adt7420_reg_read(struct adt7420_dev *dev,
178  uint16_t register_address, uint16_t *data);
179 
180 /* Read-modify-write operation*/
181 int adt7420_reg_update_bits(struct adt7420_dev *dev,
182  uint16_t register_address, uint8_t mask, uint8_t value);
183 
184 /* Write to SPI register */
185 int adt7420_spi_reg_write(struct adt7420_dev *dev, uint16_t register_address,
186  uint32_t data);
187 
188 /* Write to I2C register */
189 int adt7420_i2c_reg_write(struct adt7420_dev *dev, uint16_t register_address,
190  uint32_t data);
191 
192 /*Sets register value*/
193 int adt7420_reg_write(struct adt7420_dev *dev,
194  uint16_t register_address,
195  uint32_t data);
196 
198 int32_t adt7420_init(struct adt7420_dev **device,
200 
201 /* Free the resources allocated by adt7420_init(). */
202 int32_t adt7420_remove(struct adt7420_dev *dev);
203 
206  uint8_t mode);
207 
209 int adt7420_set_resolution(struct adt7420_dev *dev,
210  uint8_t resolution);
211 
213 int32_t adt7420_reset(struct adt7420_dev *dev);
214 
216 float adt7420_get_temperature(struct adt7420_dev *dev);
217 
219 int adt7420_i2c_reg_read(struct adt7420_dev *dev,
220  uint16_t register_address, uint16_t *data);
221 
223 int adt7420_spi_reg_read(struct adt7420_dev *dev,
224  uint16_t register_address, uint16_t *data);
225 
227 bool adt7420_is_spi(struct adt7420_dev *dev);
228 
229 #endif /* __ADT7420_H__ */
adt7420_remove
int32_t adt7420_remove(struct adt7420_dev *dev)
Free the resources allocated by adt7420_init().
Definition: adt7420.c:269
ADT7320_ADDR_MSK
#define ADT7320_ADDR_MSK
Definition: adt7420.h:60
adt7420_init_param::interface_type::i2c_init
struct no_os_i2c_init_param i2c_init
Definition: adt7420.h:160
adt7420_get_temperature
float adt7420_get_temperature(struct adt7420_dev *dev)
Reads the temperature data and converts it to Celsius degrees.
Definition: adt7420.c:375
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:207
ADT7320_REG_CONFIG
#define ADT7320_REG_CONFIG
Definition: adt7420.h:64
ADT7420_13BIT_DIV
#define ADT7420_13BIT_DIV
Definition: adt7420.h:107
adt7420_remove
int32_t adt7420_remove(struct adt7420_dev *dev)
Free the resources allocated by adt7420_init().
Definition: adt7420.c:269
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:97
adt7420_spi_reg_write
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:121
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
ADT7xxx_ID
#define ADT7xxx_ID
Definition: adt7420.h:116
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:95
adt7420_i2c_reg_write
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:152
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:138
ADT7420_RESET_DELAY
#define ADT7420_RESET_DELAY
Definition: adt7420.h:118
adt7420_i2c_reg_write
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:152
adt7420_i2c_reg_read
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:450
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:76
adt7420_get_temperature
float adt7420_get_temperature(struct adt7420_dev *dev)
Reads the temperature data and converts it to Celsius degrees.
Definition: adt7420.c:375
ID_ADT7420
@ ID_ADT7420
Definition: adt7420.h:137
adt7420_init_param::interface_type
Definition: adt7420.h:158
adt7420_dev::resolution_setting
uint8_t resolution_setting
Definition: adt7420.h:153
ID_ADT7410
@ ID_ADT7410
Definition: adt7420.h:136
adt7420_init_param::resolution_setting
uint8_t resolution_setting
Definition: adt7420.h:165
no_os_tdm_init_param::platform_ops
const struct no_os_tdm_platform_ops * platform_ops
Definition: no_os_tdm.h:83
ADT7420_16BIT_NEG
#define ADT7420_16BIT_NEG
Definition: adt7420.h:102
adt7420_reset
int32_t adt7420_reset(struct adt7420_dev *dev)
Resets the SPI or I2C inteface for the ADT7420/ADT7320.
Definition: adt7420.c:345
ID_ADT7310
@ ID_ADT7310
Definition: adt7420.h:139
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
ADT7320_READ_CMD
#define ADT7320_READ_CMD
Definition: adt7420.h:74
adt7420_reg_read
int adt7420_reg_read(struct adt7420_dev *dev, uint16_t register_address, uint16_t *data)
Reads the value of a register.
Definition: adt7420.c:80
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_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: adt7420.h:149
ID_ADT7312
@ ID_ADT7312
Definition: adt7420.h:141
chip_info
const struct adt7420_chip_info chip_info[]
Definition: adt7420.c:48
ADT7320_REG_ID
#define ADT7320_REG_ID
Definition: adt7420.h:66
ADT7320_REG_TEMP
#define ADT7320_REG_TEMP
Definition: adt7420.h:65
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:132
no_os_tdm_desc
Structure holding TDM descriptor.
Definition: no_os_tdm.h:92
I2C
@ I2C
Definition: adt7420.h:127
ADT7320_L16
#define ADT7320_L16
Definition: adt7420.h:59
I2C
@ I2C
Definition: adxl372.h:323
no_os_error.h
Error codes definition.
ADT7420_16BIT_DIV
#define ADT7420_16BIT_DIV
Definition: adt7420.h:104
chip_info
const struct adt7420_chip_info chip_info[]
Definition: max538x.c:51
SPI
@ SPI
Definition: adt7420.h:126
adt7420_reg_update_bits
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:99
adt7420_is_spi
bool adt7420_is_spi(struct adt7420_dev *dev)
Check if the interface of the selected device is SPI.
Definition: adt7420.c:482
ADT7420_CONFIG_RESOLUTION
#define ADT7420_CONFIG_RESOLUTION
Definition: adt7420.h:99
ADT7420_OP_MODE_SHUTDOWN
#define ADT7420_OP_MODE_SHUTDOWN
Definition: adt7420.h:113
ADT7420_13BIT_NEG
#define ADT7420_13BIT_NEG
Definition: adt7420.h:105
adt7420_reg_update_bits
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:99
adt7420_spi_reg_read
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:416
adt7420_type
adt7420_type
Definition: adt7420.h:135
adt7420_set_operation_mode
int adt7420_set_operation_mode(struct adt7420_dev *dev, uint8_t mode)
Sets the operational mode for ADT7420/ADT7320.
Definition: adt7420.c:294
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:143
ADT7420_REG_ID
#define ADT7420_REG_ID
Definition: adt7420.h:88
adt7420_spi_reg_write
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:121
adt7420_spi_reg_read
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:416
ID_ADT7320
@ ID_ADT7320
Definition: adt7420.h:142
dev_interface
dev_interface
Definition: adt7420.h:125
ADT7420_REG_CONFIG
#define ADT7420_REG_CONFIG
Definition: adt7420.h:80
adt7420_set_resolution
int adt7420_set_resolution(struct adt7420_dev *dev, uint8_t resolution)
Sets the resolution for ADT7420/ADT7320.
Definition: adt7420.c:320
no_os_i2c_desc
Structure holding I2C descriptor.
Definition: no_os_i2c.h:81
adt7420_init_param
Definition: adt7420.h:157
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:122
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
adt7420_i2c_reg_read
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:450
ID_ADT7311
@ ID_ADT7311
Definition: adt7420.h:140
no_os_i2c.h
Header file of I2C Interface.
ADT7420_CONFIG_OP_MODE
#define ADT7420_CONFIG_OP_MODE(x)
Definition: adt7420.h:98
no_os_field_get
uint32_t no_os_field_get(uint32_t mask, uint32_t word)
adt7420_init_param::interface_init
union adt7420_init_param::interface_type interface_init
adt7420_init_param::interface_type::spi_init
struct no_os_spi_init_param spi_init
Definition: adt7420.h:162
adt7420_reset
int32_t adt7420_reset(struct adt7420_dev *dev)
Resets the SPI or I2C inteface for the ADT7420/ADT7320.
Definition: adt7420.c:345
adt7420_chip_info::resolution
uint8_t resolution
Definition: adt7420.h:131
adt7420_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: adt7420.h:147
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
adt7420_chip_info
Definition: adt7420.h:130
adt7420_chip_info::communication
enum dev_interface communication
Definition: adt7420.h:132
adt7420_reg_read
int adt7420_reg_read(struct adt7420_dev *dev, uint16_t register_address, uint16_t *data)
Reads the value of a register.
Definition: adt7420.c:80
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
adt7420_dev
Definition: adt7420.h:145
adt7420_dev::active_device
enum adt7420_type active_device
Definition: adt7420.h:151
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:77
ADT7320_WRITE_MASK_CMD
#define ADT7320_WRITE_MASK_CMD
Definition: adt7420.h:73
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
adt7420_set_operation_mode
int adt7420_set_operation_mode(struct adt7420_dev *dev, uint8_t mode)
Sets the operational mode for ADT7420/ADT7320.
Definition: adt7420.c:294
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
no_os_get_unaligned_be16
uint16_t no_os_get_unaligned_be16(uint8_t *buf)
ADT7420_REG_TEMP_MSB
#define ADT7420_REG_TEMP_MSB
Definition: adt7420.h:77
adt7420_init_param::active_device
enum adt7420_type active_device
Definition: adt7420.h:167
no_os_util.h
Header file 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:207
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:89
adt7420_reg_write
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:183
ADT7420_16BIT_SIGN
#define ADT7420_16BIT_SIGN
Definition: adt7420.h:103
adt7420_set_resolution
int adt7420_set_resolution(struct adt7420_dev *dev, uint8_t resolution)
Sets the resolution for ADT7420/ADT7320.
Definition: adt7420.c:320
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_reg_write
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:183
ADT7420_13BIT_SIGN
#define ADT7420_13BIT_SIGN
Definition: adt7420.h:106
adt7420_is_spi
bool adt7420_is_spi(struct adt7420_dev *dev)
Check if the interface of the selected device is SPI.
Definition: adt7420.c:482
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:121
adt7420.h
Header file of ADT7420 Driver.