/*
 * MCP9801_Temp.h
 *
 *  Created on: Feb 7, 2017
 *      Author: User
 */

#ifndef SOURCES_MCP9801_TEMP_H_
#define SOURCES_MCP9801_TEMP_H_

#include "Cpu.h"
#include "Events.h"
#include "clockMan1.h"
#include "pin_init.h"
#include "osa1.h"
#include "i2cCom1.h"

#define	I2C_TIMEOUT					100
#define MPC9801_IIC_ADDRESS			0x48

#define MPC9801_SIZE_OF_ALL_DATA	4u
#define MPC9801_TEMP_REGISTER		0x00u
#define MPC9801_CONFIG_REGISTER		0x01u
#define MPC9801_TEMP_HYST_REGISTER	0x02u
#define MPC9801_TEMP_LIMIT_REGISTER	0x03u

#define MPC9801_TEMP_DATA_LENGTH	2u
#define MPC9801_CONFIG_DATA_LENGTH	1u

#define MCP9801_RESOLUTION_MASK		0x60

typedef enum
{
	MCP9801_9bit = 0x00,
	MCP9801_10bit = 0x20,
	MCP9801_11bit = 0x40,
	MCP9801_12bit = 0x60,
}MCP9801_resolution;

typedef struct
{
	i2c_device_t i2c_device;
	i2c_status_t i2c_status;
	uint32_t IIC_instance;
}MPC9801_IIC;


typedef struct
{
	uint8_t hByteTemp;
	uint8_t lByteTemp;
	float temerature;

	uint8_t configData;
	uint8_t buffer[MPC9801_SIZE_OF_ALL_DATA];

	MPC9801_IIC	i2cConfig;

}MCP9801_temperature;

void MCP9801_GetDefaultConfig(MCP9801_temperature* config);

i2c_status_t MCP9801_SetResolution(MCP9801_temperature* config, MCP9801_resolution resolution);

i2c_status_t MCP9801_GetTemperature(MCP9801_temperature* config);

#endif /* SOURCES_MCP9801_TEMP_H_ */
