#include "common.h" /* include peripheral declarations */
#define printf print_str

#include "i2c.h"
#include "i2c_cfg.h"

void i2c_master_TX_test(void);
void i2c_master_RX_test(void);
void i2c_basic(void);
void run_test(void);


void i2c_master_TX_test(void)
{
	uint8 i;
	
	printf("***Mini I2C Basic Master TX_Polling Test***\r\n");
    i2c_tx_buffer.tx_index = 0;
    i2c_tx_buffer.rx_index = 0;
    i2c_tx_buffer.data_present = TRUE;
    i2c_tx_buffer.length = 64;
    i2c_tx_buffer.buf[0] = (uint8)(I2C_SLAVE_ADDR&0x0FF);
	
	for(i=1;i<64;i++)
	{
		i2c_tx_buffer.buf[i] = i;
	}
	
	i2c_init(3, I2C_MASTER_ADDR, 50000);
	i2c_master(3, I2C_TX, I2C_SLAVE_ADDR);	
}

void i2c_master_RX_test(void)
{
	uint8 i;
	
	printf("***Mini I2C Basic Master RX_Polling Test***\r\n");	
	i2c_rx_buffer.length = 64;
	i2c_init(0, I2C_MASTER_ADDR, 50000);
	i2c_master(0, I2C_RX, I2C_SLAVE_ADDR);		
}


void i2c_basic(void) 
{
	SIM_SCGC1 |= 0xF0; // enable I2C clock gate 
	
	i2c_master_TX_test();
//	i2c_master_RX_test();
}

void run_test(void)
{
	/* This function will call the testcase function */
	i2c_basic();
}

