//----------------------------------------------------------------------------
// C main line
//----------------------------------------------------------------------------

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

#define RED_LED		0
#define GREEN_LED	1
#define BLUE_LED	2

struct I2C_Regs {    // Example I2C interface structure  
    BYTE ledNo;  
    BYTE ledState;  
    BYTE fUpdate;
    BYTE byteTest; //RO - just for Test with USB2IIC GUI
    INT  intTest;  //RO - just for Test with USB2IIC GUI
    LONG longTest;//RO - just for Test with USB2IIC GUI
    float floatTest;//RO - just for Test with USB2IIC GUI
} MyI2C_Regs;  


void LED_State(char ledNo, char ledState)
{
	char mask;
	switch (ledNo)
	{
	   case RED_LED  : mask=0x08; break;
	   case GREEN_LED: mask=0x10; break;
	   case BLUE_LED : mask=0x04; break;
	   default: mask=0x08;
	}
	if (ledState) PRT1DR|=mask; else PRT1DR&=~mask;
}

void delay(long pause)
{
	long i;
	for (i=pause; i--; );
}

void main(void)
{
   // Insert your main routine code here.
   char counter;
	
   // Set up RAM buffer  
   I2C_SetRamBuffer(sizeof(MyI2C_Regs), 14, (BYTE *) &MyI2C_Regs);  
   M8C_EnableGInt ;                           // Turn on interrupts  
      
   I2C_Start();                            // Turn on I2C  

   MyI2C_Regs.byteTest = 0x12;
   MyI2C_Regs.intTest = 0x3456;
   MyI2C_Regs.longTest = 0x7890ABCD;
   MyI2C_Regs.floatTest = 1.25;

   LED_State(RED_LED,0x01);
   LED_State(GREEN_LED,0x01);
   LED_State(BLUE_LED,0x01);
	
   while(1)
   {	
		//PRT1DR = counter;
		//counter++;
		//delay(5000);
		if (MyI2C_Regs.fUpdate){
			LED_State(MyI2C_Regs.ledNo, MyI2C_Regs.ledState);
			MyI2C_Regs.fUpdate = 0;
		}
	}
    
}
