this is testing

Committer:
pmallick
Date:
Thu Jan 14 19:12:57 2021 +0530
Revision:
0:e8a1ba50c46b
this is testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmallick 0:e8a1ba50c46b 1 /***************************************************************************//**
pmallick 0:e8a1ba50c46b 2 * @file adt7420.h
pmallick 0:e8a1ba50c46b 3 * @brief Header file of ADT7420 Driver.
pmallick 0:e8a1ba50c46b 4 * @author DBogdan (dragos.bogdan@analog.com)
pmallick 0:e8a1ba50c46b 5 ********************************************************************************
pmallick 0:e8a1ba50c46b 6 * Copyright 2012(c) Analog Devices, Inc.
pmallick 0:e8a1ba50c46b 7 *
pmallick 0:e8a1ba50c46b 8 * All rights reserved.
pmallick 0:e8a1ba50c46b 9 *
pmallick 0:e8a1ba50c46b 10 * Redistribution and use in source and binary forms, with or without
pmallick 0:e8a1ba50c46b 11 * modification, are permitted provided that the following conditions are met:
pmallick 0:e8a1ba50c46b 12 * - Redistributions of source code must retain the above copyright
pmallick 0:e8a1ba50c46b 13 * notice, this list of conditions and the following disclaimer.
pmallick 0:e8a1ba50c46b 14 * - Redistributions in binary form must reproduce the above copyright
pmallick 0:e8a1ba50c46b 15 * notice, this list of conditions and the following disclaimer in
pmallick 0:e8a1ba50c46b 16 * the documentation and/or other materials provided with the
pmallick 0:e8a1ba50c46b 17 * distribution.
pmallick 0:e8a1ba50c46b 18 * - Neither the name of Analog Devices, Inc. nor the names of its
pmallick 0:e8a1ba50c46b 19 * contributors may be used to endorse or promote products derived
pmallick 0:e8a1ba50c46b 20 * from this software without specific prior written permission.
pmallick 0:e8a1ba50c46b 21 * - The use of this software may or may not infringe the patent rights
pmallick 0:e8a1ba50c46b 22 * of one or more patent holders. This license does not release you
pmallick 0:e8a1ba50c46b 23 * from the requirement that you obtain separate licenses from these
pmallick 0:e8a1ba50c46b 24 * patent holders to use this software.
pmallick 0:e8a1ba50c46b 25 * - Use of the software either in source or binary form, must be run
pmallick 0:e8a1ba50c46b 26 * on or directly connected to an Analog Devices Inc. component.
pmallick 0:e8a1ba50c46b 27 *
pmallick 0:e8a1ba50c46b 28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
pmallick 0:e8a1ba50c46b 29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
pmallick 0:e8a1ba50c46b 30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
pmallick 0:e8a1ba50c46b 31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
pmallick 0:e8a1ba50c46b 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
pmallick 0:e8a1ba50c46b 33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
pmallick 0:e8a1ba50c46b 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
pmallick 0:e8a1ba50c46b 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
pmallick 0:e8a1ba50c46b 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
pmallick 0:e8a1ba50c46b 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
pmallick 0:e8a1ba50c46b 38 *******************************************************************************/
pmallick 0:e8a1ba50c46b 39 #ifndef __ADT7420_H__
pmallick 0:e8a1ba50c46b 40 #define __ADT7420_H__
pmallick 0:e8a1ba50c46b 41
pmallick 0:e8a1ba50c46b 42 /******************************************************************************/
pmallick 0:e8a1ba50c46b 43 /***************************** Include Files **********************************/
pmallick 0:e8a1ba50c46b 44 /******************************************************************************/
pmallick 0:e8a1ba50c46b 45 #include <stdint.h>
pmallick 0:e8a1ba50c46b 46 #include "platform_drivers.h"
pmallick 0:e8a1ba50c46b 47
pmallick 0:e8a1ba50c46b 48 /******************************************************************************/
pmallick 0:e8a1ba50c46b 49 /************************** ADT7420 Definitions *******************************/
pmallick 0:e8a1ba50c46b 50 /******************************************************************************/
pmallick 0:e8a1ba50c46b 51
pmallick 0:e8a1ba50c46b 52 /* ADT7420 address */
pmallick 0:e8a1ba50c46b 53 #define ADT7420_A0_PIN(x) (((x) & 0x1) << 0) // I2C Serial Bus Address Selection Pin
pmallick 0:e8a1ba50c46b 54 #define ADT7420_A1_PIN(x) (((x) & 0x1) << 1) // I2C Serial Bus Address Selection Pin
pmallick 0:e8a1ba50c46b 55 #define ADT7420_ADDRESS(x,y) (0x48 + ADT7420_A1_PIN(x) + ADT7420_A0_PIN(y))
pmallick 0:e8a1ba50c46b 56
pmallick 0:e8a1ba50c46b 57 /* ADT7420 registers */
pmallick 0:e8a1ba50c46b 58 #define ADT7420_REG_TEMP_MSB 0x00 // Temperature value MSB
pmallick 0:e8a1ba50c46b 59 #define ADT7420_REG_TEMP_LSB 0x01 // Temperature value LSB
pmallick 0:e8a1ba50c46b 60 #define ADT7420_REG_STATUS 0x02 // Status
pmallick 0:e8a1ba50c46b 61 #define ADT7420_REG_CONFIG 0x03 // Configuration
pmallick 0:e8a1ba50c46b 62 #define ADT7420_REG_T_HIGH_MSB 0x04 // Temperature HIGH setpoint MSB
pmallick 0:e8a1ba50c46b 63 #define ADT7420_REG_T_HIGH_LSB 0x05 // Temperature HIGH setpoint LSB
pmallick 0:e8a1ba50c46b 64 #define ADT7420_REG_T_LOW_MSB 0x06 // Temperature LOW setpoint MSB
pmallick 0:e8a1ba50c46b 65 #define ADT7420_REG_T_LOW_LSB 0x07 // Temperature LOW setpoint LSB
pmallick 0:e8a1ba50c46b 66 #define ADT7420_REG_T_CRIT_MSB 0x08 // Temperature CRIT setpoint MSB
pmallick 0:e8a1ba50c46b 67 #define ADT7420_REG_T_CRIT_LSB 0x09 // Temperature CRIT setpoint LSB
pmallick 0:e8a1ba50c46b 68 #define ADT7420_REG_HIST 0x0A // Temperature HYST setpoint
pmallick 0:e8a1ba50c46b 69 #define ADT7420_REG_ID 0x0B // ID
pmallick 0:e8a1ba50c46b 70 #define ADT7420_REG_RESET 0x2F // Software reset
pmallick 0:e8a1ba50c46b 71
pmallick 0:e8a1ba50c46b 72 /* ADT7420_REG_STATUS definition */
pmallick 0:e8a1ba50c46b 73 #define ADT7420_STATUS_T_LOW (1 << 4)
pmallick 0:e8a1ba50c46b 74 #define ADT7420_STATUS_T_HIGH (1 << 5)
pmallick 0:e8a1ba50c46b 75 #define ADT7420_STATUS_T_CRIT (1 << 6)
pmallick 0:e8a1ba50c46b 76 #define ADT7420_STATUS_RDY (1 << 7)
pmallick 0:e8a1ba50c46b 77
pmallick 0:e8a1ba50c46b 78 /* ADT7420_REG_CONFIG definition */
pmallick 0:e8a1ba50c46b 79 #define ADT7420_CONFIG_FAULT_QUEUE(x) (x & 0x3)
pmallick 0:e8a1ba50c46b 80 #define ADT7420_CONFIG_CT_POL (1 << 2)
pmallick 0:e8a1ba50c46b 81 #define ADT7420_CONFIG_INT_POL (1 << 3)
pmallick 0:e8a1ba50c46b 82 #define ADT7420_CONFIG_INT_CT_MODE (1 << 4)
pmallick 0:e8a1ba50c46b 83 #define ADT7420_CONFIG_OP_MODE(x) ((x & 0x3) << 5)
pmallick 0:e8a1ba50c46b 84 #define ADT7420_CONFIG_RESOLUTION (1 << 7)
pmallick 0:e8a1ba50c46b 85
pmallick 0:e8a1ba50c46b 86 /* ADT7420_CONFIG_FAULT_QUEUE(x) options */
pmallick 0:e8a1ba50c46b 87 #define ADT7420_FAULT_QUEUE_1_FAULT 0
pmallick 0:e8a1ba50c46b 88 #define ADT7420_FAULT_QUEUE_2_FAULTS 1
pmallick 0:e8a1ba50c46b 89 #define ADT7420_FAULT_QUEUE_3_FAULTS 2
pmallick 0:e8a1ba50c46b 90 #define ADT7420_FAULT_QUEUE_4_FAULTS 3
pmallick 0:e8a1ba50c46b 91
pmallick 0:e8a1ba50c46b 92 /* ADT7420_CONFIG_OP_MODE(x) options */
pmallick 0:e8a1ba50c46b 93 #define ADT7420_OP_MODE_CONT_CONV 0
pmallick 0:e8a1ba50c46b 94 #define ADT7420_OP_MODE_ONE_SHOT 1
pmallick 0:e8a1ba50c46b 95 #define ADT7420_OP_MODE_1_SPS 2
pmallick 0:e8a1ba50c46b 96 #define ADT7420_OP_MODE_SHUTDOWN 3
pmallick 0:e8a1ba50c46b 97
pmallick 0:e8a1ba50c46b 98 /* ADT7420 default ID */
pmallick 0:e8a1ba50c46b 99 #define ADT7420_DEFAULT_ID 0xCB
pmallick 0:e8a1ba50c46b 100
pmallick 0:e8a1ba50c46b 101 /******************************************************************************/
pmallick 0:e8a1ba50c46b 102 /*************************** Types Declarations *******************************/
pmallick 0:e8a1ba50c46b 103 /******************************************************************************/
pmallick 0:e8a1ba50c46b 104
pmallick 0:e8a1ba50c46b 105 struct adt7420_dev {
pmallick 0:e8a1ba50c46b 106 /* I2C */
pmallick 0:e8a1ba50c46b 107 i2c_desc *i2c_desc;
pmallick 0:e8a1ba50c46b 108 /* Device Settings */
pmallick 0:e8a1ba50c46b 109 uint8_t resolution_setting;
pmallick 0:e8a1ba50c46b 110 };
pmallick 0:e8a1ba50c46b 111
pmallick 0:e8a1ba50c46b 112 struct adt7420_init_param {
pmallick 0:e8a1ba50c46b 113 /* I2C */
pmallick 0:e8a1ba50c46b 114 i2c_init_param i2c_init;
pmallick 0:e8a1ba50c46b 115 /* Device Settings */
pmallick 0:e8a1ba50c46b 116 uint8_t resolution_setting;
pmallick 0:e8a1ba50c46b 117 };
pmallick 0:e8a1ba50c46b 118
pmallick 0:e8a1ba50c46b 119 /******************************************************************************/
pmallick 0:e8a1ba50c46b 120 /************************ Functions Declarations ******************************/
pmallick 0:e8a1ba50c46b 121 /******************************************************************************/
pmallick 0:e8a1ba50c46b 122
pmallick 0:e8a1ba50c46b 123 /*! Reads the value of a register. */
pmallick 0:e8a1ba50c46b 124 uint8_t adt7420_get_register_value(struct adt7420_dev *dev,
pmallick 0:e8a1ba50c46b 125 uint8_t register_address);
pmallick 0:e8a1ba50c46b 126
pmallick 0:e8a1ba50c46b 127 /*! Sets the value of a register. */
pmallick 0:e8a1ba50c46b 128 void adt7420_set_register_value(struct adt7420_dev *dev,
pmallick 0:e8a1ba50c46b 129 uint8_t register_address,
pmallick 0:e8a1ba50c46b 130 uint8_t register_value);
pmallick 0:e8a1ba50c46b 131
pmallick 0:e8a1ba50c46b 132 /*! Initializes the comm. peripheral and checks if the device is present. */
pmallick 0:e8a1ba50c46b 133 int32_t adt7420_init(struct adt7420_dev **device,
pmallick 0:e8a1ba50c46b 134 struct adt7420_init_param init_param);
pmallick 0:e8a1ba50c46b 135
pmallick 0:e8a1ba50c46b 136 /* Free the resources allocated by adt7420_init(). */
pmallick 0:e8a1ba50c46b 137 int32_t adt7420_remove(struct adt7420_dev *dev);
pmallick 0:e8a1ba50c46b 138
pmallick 0:e8a1ba50c46b 139 /*! Resets the ADT7420. */
pmallick 0:e8a1ba50c46b 140 void adt7420_reset(struct adt7420_dev *dev);
pmallick 0:e8a1ba50c46b 141
pmallick 0:e8a1ba50c46b 142 /*! Sets the operational mode for ADT7420. */
pmallick 0:e8a1ba50c46b 143 void adt7420_set_operation_mode(struct adt7420_dev *dev,
pmallick 0:e8a1ba50c46b 144 uint8_t mode);
pmallick 0:e8a1ba50c46b 145
pmallick 0:e8a1ba50c46b 146 /*! Sets the resolution for ADT7420. */
pmallick 0:e8a1ba50c46b 147 void adt7420_set_resolution(struct adt7420_dev *dev,
pmallick 0:e8a1ba50c46b 148 uint8_t resolution);
pmallick 0:e8a1ba50c46b 149
pmallick 0:e8a1ba50c46b 150 /*! Reads the temperature data and converts it to Celsius degrees. */
pmallick 0:e8a1ba50c46b 151 float adt7420_get_temperature(struct adt7420_dev *dev);
pmallick 0:e8a1ba50c46b 152
pmallick 0:e8a1ba50c46b 153 #endif /* __ADT7420_H__ */