


#include "i2cmaster.h"
#include "SI484x.h"
#include <util/delay.h>


#define DevSI484x  0x22

  char si_buf[4];

void si484x_int(void)
{
	PORTD = 0XE8;
	DDRC=0x08;
	PORTC=0X00;
	_delay_ms(1);
	PORTC=0x08; //RESET PIN 
	while((PIND&(1<<PC2))==0){}
	_delay_ms(10);
	i2c_init(); 
	MCUCR = 0x02;
	GICR = 0x40;
}

void si484x_band(uint8_t n_band)
{
	if (n_band == 1)
	{ 
		i2c_start_wait(DevSI484x+I2C_WRITE);
		i2c_write(0xE1);
		i2c_write(0x80);
		i2c_write(0x35);
		i2c_write(0x20);
		i2c_write(0x36);
		i2c_write(0xb0);
		i2c_write(0x0A);	
		i2c_stop();  
	}
	
	if (n_band == 2)
	{
		i2c_start_wait(DevSI484x+I2C_WRITE);
		i2c_write(0xE1);
		i2c_write(0x90);
		i2c_write(0x00);
		i2c_write(0x00);
		i2c_write(0x00);
		i2c_write(0x00);
		i2c_write(0x0A);	
		i2c_stop();
	}
}  

void si484x_vol(uint8_t vol)
{
	i2c_start_wait(DevSI484x+I2C_WRITE);
	i2c_write(0x12);
	i2c_write(0x00);
	i2c_write(0x40);
	i2c_write(0x00);
	i2c_write(0x00);
	i2c_write(vol);	
	i2c_stop();
}

void si484x_red(void)
{
	i2c_start_wait(DevSI484x+I2C_WRITE);      
	i2c_write(0xE0);                         
	i2c_rep_start(DevSI484x+I2C_READ);        
	si_buf[0] = i2c_readAck();                    
	si_buf[1] = i2c_readAck();                       
	si_buf[2] = i2c_readAck();                      
	si_buf[3] = i2c_readNak();                      
	i2c_stop();
}
