/****************************************************************************
 Title	:	TERMINAL FOR VISUALIZATION AND CONTROL CONDITIONS IN HOUSE
 Author	:	Patrik Szalay <xszala01@stud.feec.vutbr.cz>
 File	:	mcp9808.h
 Software:	CodeWarrior Development Studio Version: 10.6 Build Id:140329
 Target	:	MC9S08LH64
*****************************************************************************/
#ifndef MCP9808_H_
#define MCP9808_H_

#include "iiclib.h"
#include <hidef.h>
#include "derivative.h"
#include "temp_meas.h"

/* MCP9808 Pointer register definition */
#define MCP9808_CONF_REG 0x01
#define MCP9808_TUPPER_REG 0x02
#define MCP9808_TLOWER_REG 0x03
#define MCP9808_TCRIT_REG 0x04
#define MCP9808_TEMP_REG 0x05
#define MCP9808_MNF_ID_REG 0x06
#define MCP9808_DEV_ID_REG 0x07
#define MCP9808_RES_REG 0x08

/* MCP9808 Configuration register definition */

#define MCP9808_CONF_MSB_THYST_MASK 0x06
#define MCP9808_CONF_MSB_SHDN_MASK 0x01
#define MCP9808_CONF_LSB_CRITLOCK_MASK 0x80
#define MCP9808_CONF_LSB_WINLOCK_MASK 0x40
#define MCP9808_CONF_LSB_INT_CLEAR_MASK 0x20
#define MCP9808_CONF_LSB_ALERT_STAT_MASK 0x10
#define MCP9808_CONF_LSB_ALERT_CNT_MASK 0x08
#define MCP9808_CONF_LSB_ALERT_SEL_MASK 0x04
#define MCP9808_CONF_LSB_ALERT_POL_MASK 0x02
#define MCP9808_ALERT_LSB_MOD_MASK 0x01

/* MCP9808 Upper/Lower/Critical Temperature Limit register definition */
#define MCP9808_TLIMIT_MSB_SIGN_MASK 0x10


/* MCP9808 Ambient Temperature register definition */
#define MCP9808_TEMP_MSB_TAvsTCRIT_MASK 0x80
#define MCP9808_TEMP_MSB_TAvsTUPPER_MASK 0x40
#define MCP9808_TEMP_MSB_TavsTLOWER_MASK 0x20
#define MCP9808_TEMP_MSB_SIGN_MASK 0x10
#define MCP9808_TEMP_MSB_FLAG_MASK 0x1F

/* MCP9808 Resolution register definition */
#define MCP9808_RES_MASK 0x03
#define MCP9808_RES_0_5 0x00
#define MCP9808_RES_0_25 0x01
#define MCP9808_RES_0_125 0x02
#define MCP9808_RES_0_0625 0x03

void mcp9808_set_conf(ADDRESS addr, unsigned short ConfR, char* data);
unsigned short mcp9808_read_conf(ADDRESS addr, char* data);

void mcp9808_set_tupper(ADDRESS addr, unsigned short ConfR, char* data);
unsigned short mcp9808_read_tupper(ADDRESS addr, char* data);

void mcp9808_set_tlower(ADDRESS addr, unsigned short ConfR, char* data);
unsigned short mcp9808_read_tlower(ADDRESS addr, char* data);

void mcp9808_set_tcrit(ADDRESS addr, unsigned short ConfR, char* data);
unsigned short mcp9808_read_tcrit(ADDRESS addr, char* data);

#ifdef __NO_FLOAT__
	decimal mcp9808_readTemp_decimal(ADDRESS addr, char* data);
#else
	float mcp9808_readTemp_float(unsigned char addr);
#endif

char mcp9808_readTemp_char(ADDRESS addr, char* data);

unsigned short mcp9808_read_mnf_id(ADDRESS addr, char* data);
unsigned short mcp9808_read_dev_id(ADDRESS addr, char* data);

void mcp9808_set_res(ADDRESS addr, unsigned char ConfR, char* data);
unsigned char mcp9808_read_res(ADDRESS addr, char* data);


#endif /* MCP9808_H_ */
