//----------------------------------------------------
/**
	\file		ctk/hw/pot_tpl0401.h
	\ingroup	hardware
	\ingroup	all

	\brief		Knihovna pro digitalni potenciometr TPL0401
				<<< ALL >>>

	\author		ConTeK s.r.o., Stanek Jan
	\version	01.01
	\date		25.04.2013
*/
//----------------------------------------------------

#ifndef _TPL_0401_H_
#define _TPL_0401_H_		//!< Definice pritomnosti knihovny

#include <twim.h>
#include <ctktypes.h>
#include <stmachine.h>
#include <hal.h>

//----------------------------------------------------
//!	\name	TPL IO Channel definition
//@{
#define TPL_DINP_COUNT		0	//!< Pocet dig. vstupu
#define TPL_DOUTP_COUNT 	0	//!< Pocet dig. vystupu
#define TPL_AINP_COUNT	 	0	//!< Pocet analogovych vstupu
#define TPL_AOUTP_COUNT 	1	//!< Pocet analogovych vystupu

#define TPL_POS				0	//!< Analog output - pozice jezdce
//@}


//----------------------------------------------------
//!	\name	I2C Protocol definition
//@{
#ifndef USEHW_TPL0401B
 #define TPL_I2C_ADDR	0x2E	//!< I2C Adresa
#else
 #define TPL_I2C_ADDR	0x3E	//!< I2C Adresa
#endif

#define TPL_DUMMY_CMD	0x00	//!< I2C Cmd
//@}


#define TPL_VAL_MAXIMUM	127		//!< Maximalni nastavitelna hodnota

//----------------------------------------------------
/**
	\brief	Kontext obsluhy TPL potenciometru
*/
//----------------------------------------------------
typedef struct _TPL_POT_CTX
{
	IODEVICE	Device;		//!< Rodic IO zarizeni

	TWIDESC	*	Twi;		//!< Kontext pouzivaneho TWI
	uint8_t		TwiCmd;		//!< Prikaz k odeslani po TWI
	uint8_t		TwiData;	//!< Data k odeslani po TWI

	STMACHINE	Stm;		//!< Stavovy automat obsluhy

	uint8_t		updateValue;//!< Aktualni pozice jezdce
	bool_t		TplTwiReady;//!< Priznak volneho TWI kanalu
	bool_t		dir;		//!< Priznak smeru jezdce

	bool_t		flRunning;	//!< Priznak inicializace

}TPL_POT_CTX;

//----------------------------------------------------
/**
	\brief	Inicializace kontextu potenciometru
	\param	_ctx	Kontext obsluhy potenciometru
	\param	_twiCtx	Kontext pouzivaneho TWI
	\param	_dir	Rozliseni smeru jezdce
	\return TRUE	Pokud inicializace probehla v poradku
*/
//----------------------------------------------------
bool_t TplInitialize(TPL_POT_CTX * const _ctx, TWIDESC * const _twiCtx, bool_t _dir);

#endif // _TPL_0401_H_
