Pratyush Mallick / Mbed OS nano_dac
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers adt7420.h Source File

adt7420.h

Go to the documentation of this file.
00001 /***************************************************************************//**
00002  *   @file   adt7420.h
00003  *   @brief  Header file of ADT7420 Driver.
00004  *   @author DBogdan (dragos.bogdan@analog.com)
00005 ********************************************************************************
00006  * Copyright 2012(c) Analog Devices, Inc.
00007  *
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions are met:
00012  *  - Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  *  - Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *  - Neither the name of Analog Devices, Inc. nor the names of its
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *  - The use of this software may or may not infringe the patent rights
00022  *    of one or more patent holders.  This license does not release you
00023  *    from the requirement that you obtain separate licenses from these
00024  *    patent holders to use this software.
00025  *  - Use of the software either in source or binary form, must be run
00026  *    on or directly connected to an Analog Devices Inc. component.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
00029  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
00030  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00031  * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
00032  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00033  * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
00034  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 *******************************************************************************/
00039 #ifndef __ADT7420_H__
00040 #define __ADT7420_H__
00041 
00042 /******************************************************************************/
00043 /***************************** Include Files **********************************/
00044 /******************************************************************************/
00045 #include <stdint.h>
00046 #include "platform_drivers.h"
00047 
00048 /******************************************************************************/
00049 /************************** ADT7420 Definitions *******************************/
00050 /******************************************************************************/
00051 
00052 /* ADT7420 address */
00053 #define ADT7420_A0_PIN(x)   (((x) & 0x1) << 0) // I2C Serial Bus Address Selection Pin
00054 #define ADT7420_A1_PIN(x)   (((x) & 0x1) << 1) // I2C Serial Bus Address Selection Pin
00055 #define ADT7420_ADDRESS(x,y)    (0x48 + ADT7420_A1_PIN(x) + ADT7420_A0_PIN(y))
00056 
00057 /* ADT7420 registers */
00058 #define ADT7420_REG_TEMP_MSB        0x00 // Temperature value MSB
00059 #define ADT7420_REG_TEMP_LSB        0x01 // Temperature value LSB
00060 #define ADT7420_REG_STATUS      0x02 // Status
00061 #define ADT7420_REG_CONFIG      0x03 // Configuration
00062 #define ADT7420_REG_T_HIGH_MSB      0x04 // Temperature HIGH setpoint MSB
00063 #define ADT7420_REG_T_HIGH_LSB      0x05 // Temperature HIGH setpoint LSB
00064 #define ADT7420_REG_T_LOW_MSB       0x06 // Temperature LOW setpoint MSB
00065 #define ADT7420_REG_T_LOW_LSB       0x07 // Temperature LOW setpoint LSB
00066 #define ADT7420_REG_T_CRIT_MSB      0x08 // Temperature CRIT setpoint MSB
00067 #define ADT7420_REG_T_CRIT_LSB      0x09 // Temperature CRIT setpoint LSB
00068 #define ADT7420_REG_HIST        0x0A // Temperature HYST setpoint
00069 #define ADT7420_REG_ID          0x0B // ID
00070 #define ADT7420_REG_RESET       0x2F // Software reset
00071 
00072 /* ADT7420_REG_STATUS definition */
00073 #define ADT7420_STATUS_T_LOW        (1 << 4)
00074 #define ADT7420_STATUS_T_HIGH       (1 << 5)
00075 #define ADT7420_STATUS_T_CRIT       (1 << 6)
00076 #define ADT7420_STATUS_RDY      (1 << 7)
00077 
00078 /* ADT7420_REG_CONFIG definition */
00079 #define ADT7420_CONFIG_FAULT_QUEUE(x)   (x & 0x3)
00080 #define ADT7420_CONFIG_CT_POL       (1 << 2)
00081 #define ADT7420_CONFIG_INT_POL      (1 << 3)
00082 #define ADT7420_CONFIG_INT_CT_MODE  (1 << 4)
00083 #define ADT7420_CONFIG_OP_MODE(x)   ((x & 0x3) << 5)
00084 #define ADT7420_CONFIG_RESOLUTION   (1 << 7)
00085 
00086 /* ADT7420_CONFIG_FAULT_QUEUE(x) options */
00087 #define ADT7420_FAULT_QUEUE_1_FAULT 0
00088 #define ADT7420_FAULT_QUEUE_2_FAULTS    1
00089 #define ADT7420_FAULT_QUEUE_3_FAULTS    2
00090 #define ADT7420_FAULT_QUEUE_4_FAULTS    3
00091 
00092 /* ADT7420_CONFIG_OP_MODE(x) options */
00093 #define ADT7420_OP_MODE_CONT_CONV   0
00094 #define ADT7420_OP_MODE_ONE_SHOT    1
00095 #define ADT7420_OP_MODE_1_SPS       2
00096 #define ADT7420_OP_MODE_SHUTDOWN    3
00097 
00098 /* ADT7420 default ID */
00099 #define ADT7420_DEFAULT_ID      0xCB
00100 
00101 /******************************************************************************/
00102 /*************************** Types Declarations *******************************/
00103 /******************************************************************************/
00104 
00105 struct adt7420_dev {
00106     /* I2C */
00107     i2c_desc    *i2c_desc;
00108     /* Device Settings */
00109     uint8_t     resolution_setting;
00110 };
00111 
00112 struct adt7420_init_param {
00113     /* I2C */
00114     i2c_init_param  i2c_init;
00115     /* Device Settings */
00116     uint8_t     resolution_setting;
00117 };
00118 
00119 /******************************************************************************/
00120 /************************ Functions Declarations ******************************/
00121 /******************************************************************************/
00122 
00123 /*! Reads the value of a register. */
00124 uint8_t adt7420_get_register_value(struct adt7420_dev *dev,
00125                    uint8_t register_address);
00126 
00127 /*! Sets the value of a register. */
00128 void adt7420_set_register_value(struct adt7420_dev *dev,
00129                 uint8_t register_address,
00130                 uint8_t register_value);
00131 
00132 /*! Initializes the comm. peripheral and checks if the device is present. */
00133 int32_t adt7420_init(struct adt7420_dev **device,
00134              struct adt7420_init_param init_param);
00135 
00136 /* Free the resources allocated by adt7420_init(). */
00137 int32_t adt7420_remove(struct adt7420_dev *dev);
00138 
00139 /*! Resets the ADT7420. */
00140 void adt7420_reset(struct adt7420_dev *dev);
00141 
00142 /*! Sets the operational mode for ADT7420. */
00143 void adt7420_set_operation_mode(struct adt7420_dev *dev,
00144                 uint8_t mode);
00145 
00146 /*! Sets the resolution for ADT7420. */
00147 void adt7420_set_resolution(struct adt7420_dev *dev,
00148                 uint8_t resolution);
00149 
00150 /*! Reads the temperature data and converts it to Celsius degrees. */
00151 float adt7420_get_temperature(struct adt7420_dev *dev);
00152 
00153 #endif  /* __ADT7420_H__ */