//*****************************************************************************
//
// I2Cdriver.h - Stellaris development board Peripheral Device Controller definitions
//         and prototypes.
//
// Copyright (c) 2005-2008 Luminary Micro, Inc.  All rights reserved.
// 
// Software License Agreement
// 
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
// 
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws.  All rights are reserved.  You may not combine
// this software with "viral" open-source software in order to form a larger
// program.  Any use in violation of the foregoing restrictions may subject
// the user to criminal sanctions under applicable laws, as well as to civil
// liability for the breach of the terms and conditions of this license.
// 
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 3416 of the Stellaris Peripheral Driver Library.
//
//*****************************************************************************

#ifndef __I2CDRIVER_H__
#define __I2CDRIVER_H__

//Definice konstant
#define I2C_VER                 0x0           // Version register

#define I2C_RD                  0x80          //prikaz I2C read
#define I2C_WR                  0x00          //prikaz I2C write

//Definice stavu pro stavovy automat IIC----
#define I2C_STATE_IDLE         0
#define I2C_STATE_WRITE_NEXT   1
#define I2C_STATE_WRITE_FINAL  2
#define I2C_STATE_WAIT_ACK     3
#define I2C_STATE_SEND_ACK     4
#define I2C_STATE_READ_ONE     5
#define I2C_STATE_READ_FIRST   6
#define I2C_STATE_READ_NEXT    7
#define I2C_STATE_READ_FINAL   8
#define I2C_STATE_READ_WAIT    9

//konstanty pro nastaveni komunikace IIC------
#define ADDR_ERROR              0x00          //Status pro identifikaci chybne adresy
#define EEPROM                  0x10          //identifikace EEPROM                           
#define TEMP_SENS               0x20          //id pro snimac teploty
#define EP_IO                   0x30          //id pro rozsireny port s dig.IO
#define EP_LED                  0x40          //id pro rozsireny port s LED
#define EP_ADDR                 0x50          //id pro rozsireny port s adresou karty
#define ADDRESS_TEMP_SENS       0x48          //Adresa teplotniho snimace na IIC sbernici
#define ADDRESS_EEPROM          0x50          //Adresa EEPROM na IIC sbernici
#define ADDRESS_EP_DIGIO        0x20          //Adresa rozsirujiciho portu s digitalnimi vstupy vystupy (8bit)
#define ADDRESS_EP_LED          0x21          //Adresa rozsirijiciho portu s indikacnimi LED (16bit)
#define ADDRESS_EP_ADDR         0x22          //Adresa rozsirujiciho portu s adresami

//struktura pro komunikaci po IIC sbernici-----
struct IICData
{
  unsigned char *Data;                            //ukazatel na misto, kam/odkud se budou data zapisovat/cist
  unsigned char Count;                            //Pocet datovych bytu 
  unsigned char SlaveAddress;                     //Adresa chipu pro komunikaci / HW adresa
  unsigned char DataAddress;                      //Adresa dat / napriklad v EEPROM
  unsigned char State;                            //Stav stavoveho automatu
};

//Deklarace funkci-------------------------------------------------------------
extern void I2C_Init(void);                             
extern void I2C_Write(unsigned char address, unsigned char *data, unsigned char count);
extern void I2C_Read(unsigned char address, unsigned char *data, unsigned char info);     // info - Bity 0-3 udavaji pocet bytu pro cteni/zapis, bity 4-7 identifikuji zarizeni
//extern void EEPROMByteRead(unsigned char address, unsigned char *data);



#endif // __I2CDRIVER_H__
