no-OS
Classes | Macros | Enumerations | Functions | Variables
adt7420.h File Reference

Header file of ADT7420 Driver. More...

#include "no_os_spi.h"
#include "no_os_i2c.h"
#include "no_os_util.h"
#include <stdbool.h>
Include dependency graph for adt7420.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  adt7420_chip_info
 
struct  adt7420_dev
 
struct  adt7420_init_param
 
union  adt7420_init_param::interface_type
 

Macros

#define ADT7420_A0_PIN(x)   (((x) & 0x1) << 0)
 
#define ADT7420_A1_PIN(x)   (((x) & 0x1) << 1)
 
#define ADT7420_ADDRESS(x, y)   (0x48 + ADT7420_A1_PIN(x) + ADT7420_A0_PIN(y))
 
#define ADT7320_L16   NO_OS_BIT(8)
 
#define ADT7320_ADDR_MSK   NO_OS_GENMASK(7,0)
 
#define ADT7320_REG_STATUS   0x00
 
#define ADT7320_REG_CONFIG   0x01
 
#define ADT7320_REG_TEMP   (ADT7320_L16 | 0x02)
 
#define ADT7320_REG_ID   0x03
 
#define ADT7320_REG_T_CRIT   (ADT7320_L16 | 0x04)
 
#define ADT7320_REG_HIST   0x05
 
#define ADT7320_REG_T_HIGH   (ADT7320_L16 | 0x06)
 
#define ADT7320_REG_T_LOW   (ADT7320_L16 | 0x07)
 
#define ADT7320_WRITE_MASK_CMD   0b00111000
 
#define ADT7320_READ_CMD   0b01000000
 
#define ADT7420_REG_TEMP_MSB   (ADT7320_L16 |0x00)
 
#define ADT7420_REG_TEMP_LSB   0x01
 
#define ADT7420_REG_STATUS   0x02
 
#define ADT7420_REG_CONFIG   0x03
 
#define ADT7420_REG_T_HIGH_MSB   (ADT7320_L16 |0x04 )
 
#define ADT7420_REG_T_HIGH_LSB   0x05
 
#define ADT7420_REG_T_LOW_MSB   (ADT7320_L16 |0x06)
 
#define ADT7420_REG_T_LOW_LSB   0x07
 
#define ADT7420_REG_T_CRIT_MSB   (ADT7320_L16 |0x08)
 
#define ADT7420_REG_T_CRIT_LSB   0x09
 
#define ADT7420_REG_HIST   0x0A
 
#define ADT7420_REG_ID   0x0B
 
#define ADT7420_REG_RESET   0x2F
 
#define ADT7420_STATUS_T_LOW   NO_OS_BIT(4)
 
#define ADT7420_STATUS_T_HIGH   NO_OS_BIT(5)
 
#define ADT7420_STATUS_T_CRIT   NO_OS_BIT(6)
 
#define ADT7420_STATUS_RDY   NO_OS_BIT(7)
 
#define ADT7420_CONFIG_OP_MODE(x)   ((x) << 5) & (NO_OS_GENMASK(6,5))
 
#define ADT7420_CONFIG_RESOLUTION   NO_OS_BIT(7)
 
#define ADT7420_16BIT_NEG   NO_OS_BIT(16)
 
#define ADT7420_16BIT_SIGN   0x8000
 
#define ADT7420_16BIT_DIV   128
 
#define ADT7420_13BIT_NEG   NO_OS_BIT(13)
 
#define ADT7420_13BIT_SIGN   0x1000
 
#define ADT7420_13BIT_DIV   16
 
#define ADT7420_OP_MODE_CONT_CONV   0
 
#define ADT7420_OP_MODE_ONE_SHOT   1
 
#define ADT7420_OP_MODE_1_SPS   2
 
#define ADT7420_OP_MODE_SHUTDOWN   3
 
#define ADT7xxx_ID   0xC
 
#define ADT7420_RESET_DELAY   1
 

Enumerations

enum  dev_interface {
  SPI,
  I2C
}
 
enum  adt7420_type {
  ID_ADT7410,
  ID_ADT7420,
  ID_ADT7422,
  ID_ADT7310,
  ID_ADT7311,
  ID_ADT7312,
  ID_ADT7320
}
 

Functions

int adt7420_reg_read (struct adt7420_dev *dev, uint16_t register_address, uint16_t *data)
 Reads the value of a register. More...
 
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. More...
 
int adt7420_spi_reg_write (struct adt7420_dev *dev, uint16_t register_address, uint32_t data)
 Write a value of a register via SPI. More...
 
int adt7420_i2c_reg_write (struct adt7420_dev *dev, uint16_t register_address, uint32_t data)
 Write a value of a register via I2C. More...
 
int adt7420_reg_write (struct adt7420_dev *dev, uint16_t register_address, uint32_t data)
 Sets the value of a register SPI/I2C. More...
 
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. More...
 
int32_t adt7420_remove (struct adt7420_dev *dev)
 Free the resources allocated by adt7420_init(). More...
 
int adt7420_set_operation_mode (struct adt7420_dev *dev, uint8_t mode)
 Sets the operational mode for ADT7420/ADT7320. More...
 
int adt7420_set_resolution (struct adt7420_dev *dev, uint8_t resolution)
 Sets the resolution for ADT7420/ADT7320. More...
 
int32_t adt7420_reset (struct adt7420_dev *dev)
 Resets the SPI or I2C inteface for the ADT7420/ADT7320. More...
 
float adt7420_get_temperature (struct adt7420_dev *dev)
 Reads the temperature data and converts it to Celsius degrees. More...
 
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. More...
 
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. More...
 
bool adt7420_is_spi (struct adt7420_dev *dev)
 Check if the interface of the selected device is SPI. More...
 

Variables

const struct adt7420_chip_info chip_info []
 

Detailed Description

Header file of ADT7420 Driver.

Author
DBogdan (drago.nosp@m.s.bo.nosp@m.gdan@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2012, 2019, 2021(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ ADT7320_ADDR_MSK

#define ADT7320_ADDR_MSK   NO_OS_GENMASK(7,0)

◆ ADT7320_L16

#define ADT7320_L16   NO_OS_BIT(8)

◆ ADT7320_READ_CMD

#define ADT7320_READ_CMD   0b01000000

◆ ADT7320_REG_CONFIG

#define ADT7320_REG_CONFIG   0x01

◆ ADT7320_REG_HIST

#define ADT7320_REG_HIST   0x05

◆ ADT7320_REG_ID

#define ADT7320_REG_ID   0x03

◆ ADT7320_REG_STATUS

#define ADT7320_REG_STATUS   0x00

◆ ADT7320_REG_T_CRIT

#define ADT7320_REG_T_CRIT   (ADT7320_L16 | 0x04)

◆ ADT7320_REG_T_HIGH

#define ADT7320_REG_T_HIGH   (ADT7320_L16 | 0x06)

◆ ADT7320_REG_T_LOW

#define ADT7320_REG_T_LOW   (ADT7320_L16 | 0x07)

◆ ADT7320_REG_TEMP

#define ADT7320_REG_TEMP   (ADT7320_L16 | 0x02)

◆ ADT7320_WRITE_MASK_CMD

#define ADT7320_WRITE_MASK_CMD   0b00111000

◆ ADT7420_13BIT_DIV

#define ADT7420_13BIT_DIV   16

◆ ADT7420_13BIT_NEG

#define ADT7420_13BIT_NEG   NO_OS_BIT(13)

◆ ADT7420_13BIT_SIGN

#define ADT7420_13BIT_SIGN   0x1000

◆ ADT7420_16BIT_DIV

#define ADT7420_16BIT_DIV   128

◆ ADT7420_16BIT_NEG

#define ADT7420_16BIT_NEG   NO_OS_BIT(16)

◆ ADT7420_16BIT_SIGN

#define ADT7420_16BIT_SIGN   0x8000

◆ ADT7420_A0_PIN

#define ADT7420_A0_PIN (   x)    (((x) & 0x1) << 0)

◆ ADT7420_A1_PIN

#define ADT7420_A1_PIN (   x)    (((x) & 0x1) << 1)

◆ ADT7420_ADDRESS

#define ADT7420_ADDRESS (   x,
 
)    (0x48 + ADT7420_A1_PIN(x) + ADT7420_A0_PIN(y))

◆ ADT7420_CONFIG_OP_MODE

#define ADT7420_CONFIG_OP_MODE (   x)    ((x) << 5) & (NO_OS_GENMASK(6,5))

◆ ADT7420_CONFIG_RESOLUTION

#define ADT7420_CONFIG_RESOLUTION   NO_OS_BIT(7)

◆ ADT7420_OP_MODE_1_SPS

#define ADT7420_OP_MODE_1_SPS   2

◆ ADT7420_OP_MODE_CONT_CONV

#define ADT7420_OP_MODE_CONT_CONV   0

◆ ADT7420_OP_MODE_ONE_SHOT

#define ADT7420_OP_MODE_ONE_SHOT   1

◆ ADT7420_OP_MODE_SHUTDOWN

#define ADT7420_OP_MODE_SHUTDOWN   3

◆ ADT7420_REG_CONFIG

#define ADT7420_REG_CONFIG   0x03

◆ ADT7420_REG_HIST

#define ADT7420_REG_HIST   0x0A

◆ ADT7420_REG_ID

#define ADT7420_REG_ID   0x0B

◆ ADT7420_REG_RESET

#define ADT7420_REG_RESET   0x2F

◆ ADT7420_REG_STATUS

#define ADT7420_REG_STATUS   0x02

◆ ADT7420_REG_T_CRIT_LSB

#define ADT7420_REG_T_CRIT_LSB   0x09

◆ ADT7420_REG_T_CRIT_MSB

#define ADT7420_REG_T_CRIT_MSB   (ADT7320_L16 |0x08)

◆ ADT7420_REG_T_HIGH_LSB

#define ADT7420_REG_T_HIGH_LSB   0x05

◆ ADT7420_REG_T_HIGH_MSB

#define ADT7420_REG_T_HIGH_MSB   (ADT7320_L16 |0x04 )

◆ ADT7420_REG_T_LOW_LSB

#define ADT7420_REG_T_LOW_LSB   0x07

◆ ADT7420_REG_T_LOW_MSB

#define ADT7420_REG_T_LOW_MSB   (ADT7320_L16 |0x06)

◆ ADT7420_REG_TEMP_LSB

#define ADT7420_REG_TEMP_LSB   0x01

◆ ADT7420_REG_TEMP_MSB

#define ADT7420_REG_TEMP_MSB   (ADT7320_L16 |0x00)

◆ ADT7420_RESET_DELAY

#define ADT7420_RESET_DELAY   1

◆ ADT7420_STATUS_RDY

#define ADT7420_STATUS_RDY   NO_OS_BIT(7)

◆ ADT7420_STATUS_T_CRIT

#define ADT7420_STATUS_T_CRIT   NO_OS_BIT(6)

◆ ADT7420_STATUS_T_HIGH

#define ADT7420_STATUS_T_HIGH   NO_OS_BIT(5)

◆ ADT7420_STATUS_T_LOW

#define ADT7420_STATUS_T_LOW   NO_OS_BIT(4)

◆ ADT7xxx_ID

#define ADT7xxx_ID   0xC

Enumeration Type Documentation

◆ adt7420_type

Enumerator
ID_ADT7410 
ID_ADT7420 
ID_ADT7422 
ID_ADT7310 
ID_ADT7311 
ID_ADT7312 
ID_ADT7320 

◆ dev_interface

Enumerator
SPI 
I2C 

Function Documentation

◆ adt7420_get_temperature()

float adt7420_get_temperature ( struct adt7420_dev dev)

Reads the temperature data and converts it to Celsius degrees.

Reads the temperature data and converts it to Celsius degrees.

Parameters
dev- The device structure.
Returns
temperature - Temperature in degrees Celsius.

Negative temperature

Positive temperature

Negative temperature

Positive temperature

Here is the caller graph for this function:

◆ 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.

Read the register value for I2C interface devices

Parameters
dev- The device structure.
register_address- Address of the register.
data- Pointer to the register value
Returns
register_value - Value of the register.
Here is the caller graph for this function:

◆ 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.

Parameters
dev- The device structure.
register_address- Address of the register.
data- Pointer to the register value
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ 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.

Initializes the comm. peripheral and checks if the device is present.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
status - The result of the initialization procedure. Example: -1 - I2C peripheral was not initialized or the device is not present. 0 - I2C peripheral was initialized and the device is present.
Here is the caller graph for this function:

◆ adt7420_is_spi()

bool adt7420_is_spi ( struct adt7420_dev dev)

Check if the interface of the selected device is SPI.

Check if the interface of the selected device is SPI

Parameters
dev- The device structure.
Returns
True in case of an SPI interface, False Otherwise
Here is the caller graph for this function:

◆ adt7420_reg_read()

int adt7420_reg_read ( struct adt7420_dev dev,
uint16_t  register_address,
uint16_t *  data 
)

Reads the value of a register.

Reads the value of a register

Parameters
dev- The device structure.
register_address- Address of the register.
data- Pointer to the register value
Returns
register_value - Value of the register.
Here is the caller graph for this function:

◆ 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.

Parameters
dev- The device structure.
register_address- Address of the register.
mask- Bit Mask of the bit to be written
value- Value of the bit
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ 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.

Parameters
dev- The device structure.
register_address- Address of the register.
data- Data to be written in input register.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ adt7420_remove()

int32_t adt7420_remove ( struct adt7420_dev dev)

Free the resources allocated by adt7420_init().

Parameters
dev- The device structure.
Returns
ret - The result of the remove procedure.
Here is the caller graph for this function:

◆ adt7420_reset()

int32_t adt7420_reset ( struct adt7420_dev dev)

Resets the SPI or I2C inteface for the ADT7420/ADT7320.

Resets the SPI or I2C inteface for the ADT7420/ADT7320

Parameters
dev- The device structure.
Returns
0 in case of Success, -1 otherwise.
Here is the caller graph for this function:

◆ adt7420_set_operation_mode()

int adt7420_set_operation_mode ( struct adt7420_dev dev,
uint8_t  mode 
)

Sets the operational mode for ADT7420/ADT7320.

Sets the operational mode for ADT7420.

Parameters
dev- The device structure.
mode- Operation mode. Example: ADT7420_OP_MODE_CONT_CONV - continuous conversion; ADT7420_OP_MODE_ONE_SHOT - one shot; ADT7420_OP_MODE_1_SPS - 1 SPS mode; ADT7420_OP_MODE_SHUTDOWN - shutdown.
Returns
None.

◆ adt7420_set_resolution()

int adt7420_set_resolution ( struct adt7420_dev dev,
uint8_t  resolution 
)

Sets the resolution for ADT7420/ADT7320.

Sets the resolution for ADT7420.

Parameters
dev- The device structure.
resolution- Resolution. Example: 0 - 13-bit resolution; 1 - 16-bit resolution.
Returns
None.

◆ 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.

Read the register value for SPI interface devices

Parameters
dev- The device structure.
register_address- Address of the register.
data- Pointer to the register value
Returns
register_value - Value of the register.
Here is the caller graph for this function:

◆ 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.

Parameters
dev- The device structure.
register_address- Address of the register.
data- Pointer to the register value
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

Variable Documentation

◆ chip_info

const struct adt7420_chip_info chip_info[]