#ifndef _TWIS_MASTER
#define _TWIS_MASTER

#include "api.h"
#define TWIM_READ    1
#define TWIM_WRITE   0
/*minimum number of arguments to TWIS: 1/0, address, length*/
#warning READ/WRITE mins differ!
#define TWIS_MIN_NARGS 3

/* Elements necessary for TWI communication */
#define TWI_MAX_DATA_ELEMENTS 8					// Maximum data elements in one transfer
extern uint16_t twi_data[TWI_MAX_DATA_ELEMENTS];	// Data array
extern uint8_t twi_bytes_to_transceive;			// How much bytes to send/receive.

/* Function-declaration for writing/reading TWI */
uint8_t Twim_Write_Data(uint8_t Address, uint8_t twi_bytes_to_transceive, uint16_t twi_data[TWI_MAX_DATA_ELEMENTS]);
uint8_t Twim_Read_Data(uint8_t Address, uint8_t twi_bytes_to_transceive, uint16_t twi_data[TWI_MAX_DATA_ELEMENTS]);

uint8_t Twim_Init (uint32_t TWI_Bitrate);
void Write_to_slave( struct uartStruct *ptr_uartStruct );
void Read_from_slave( struct uartStruct *ptr_uartStruct );
void Twim_Stop (void);
uint8_t Twim_Start (uint8_t Address, uint8_t TWIM_Type);
uint8_t Twim_Write (uint8_t byte);
uint8_t Twim_ReadAck (void);
uint8_t Twim_ReadNack (void);

void    twiMaster(struct uartStruct *ptr_uartStruct);
uint8_t twiMasterParseUartStruct(struct uartStruct *ptr_uartStruct);
uint8_t twiMasterCheckParameterFormatAndRanges(struct uartStruct *ptr_uartStruct);
uint8_t twiMasterCheckError(struct uartStruct *ptr_uartStruct);
uint8_t twiCreateRecvString(struct uartStruct *ptr_uartStruct, uint32_t length, uint16_t array[TWI_MAX_DATA_ELEMENTS]);

#endif
