//-------------------------------------------------------------------------------------------------------
// Title          : DA
//-------------------------------------------------------------------------------------------------------
// Funktion       : LED Beleuchtngskzept
// Schaltung      : Belechtung
// Datei          : PCA9635.h
//-------------------------------------------------------------------------------------------------------
// Prozessor      : ATmega8
// Takt           : 1 MHz
// Sprache        : C
// letzte Änderung: 04.06.2014
// Autor          : Kay Ulbricht
//-------------------------------------------------------------------------------------------------------


#ifndef PCA9635_H_
#define PCA9635_H_


/**************************************
** TLC59116 device Address/Registers **
***************************************/

#define PCA9635_ADD1				0b0010101//0x60			// I2C PWM1 Device Address, 0b1100000 , Assumes A0 to A3 are connected to ground
#define PCA9635_ADD2				0b0010111//0x61			// I2C PWM2 Device Address, 0b1100000 , Assumes A0 to A2 are connected to ground

#define PCA9635_AI_NONE				0x0
#define PCA9635_AI_ALL				0x4
#define PCA9635_AI_PWMONLY			0x5
#define PCA9635_AI_CTLONLY			0x6
#define PCA9635_AI_CTLPWMONLY		0x7

#define PCA9635_REG_MODE1			0x00
#define PCA9635_REG_MODE2			0x01
#define PCA9635_REG_PWM0			0x02
#define PCA9635_REG_PWM1			0x03
#define PCA9635_REG_PWM2			0x04
#define PCA9635_REG_PWM3			0x05
#define PCA9635_REG_PWM4			0x06
#define PCA9635_REG_PWM5			0x07
#define PCA9635_REG_PWM6			0x08
#define PCA9635_REG_PWM7			0x09
#define PCA9635_REG_PWM8			0x0A
#define PCA9635_REG_PWM9			0x0B
#define PCA9635_REG_PWM10			0x0C
#define PCA9635_REG_PWM11			0x0D
#define PCA9635_REG_PWM12			0x0E
#define PCA9635_REG_PWM13			0x0F
#define PCA9635_REG_PWM14			0x10
#define PCA9635_REG_PWM15			0x11
#define PCA9635_REG_GRPPWM			0x12
#define PCA9635_REG_GRPFREQ			0x13
#define PCA9635_REG_LEDOUT0			0x14
#define PCA9635_REG_LEDOUT1			0x15
#define PCA9635_REG_LEDOUT2			0x16
#define PCA9635_REG_LEDOUT3			0x17
#define PCA9635_REG_SUBADR1			0x18
#define PCA9635_REG_SUBADR2			0x19
#define PCA9635_REG_SUBADR3			0x1A
#define PCA9635_REG_ALLCALLADR		0x1B
#define PCA9635_REG_IREF			0x1C
#define PCA9635_REG_EFLAG1			0x1D
#define PCA9635_REG_EFLAG2			0x1E

// I2C bus addresses (excludes the R/W bit)
#define ALLCALL_ADDRESS						0x68		//0b1101000
#define RESET_ADDRESS						0x6B		//0b1101011

// Control register (three MSB control auto-increment)
#define NO_AUTO_INCREMENT					0x00
#define AUTO_INCREMENT_ALL_REGISTERS		0x80
#define AUTO_INCREMENT_BRIGHTNESS			0xA0
#define AUTO_INCREMENT_CONTROL				0xC0
#define AUTO_INCREMENT_BRIGHT_CONTROL		0xE0

// LED output state for LEDOUT0 to LEDOUT3
#define LED_OUTPUT_OFF						0b00
#define LED_OUTPUT_GROUP					0b11

/**************
** Variablen **
***************/

//Reg 0x01 = MODE2 - set to 0xFF - noninverted logic state, open-drain
unsigned char MODE2;

// LED_OUT_Variablen
// RGB_LED1:
unsigned char LED0;
unsigned char LED1;
unsigned char LED2;

// RGB_LED2:
unsigned char LED3;
unsigned char LED4;
unsigned char LED5;

// RGB_LED3:
unsigned char LED6;
unsigned char LED7;
unsigned char LED8;

// RGB_LED4:
unsigned char LED9;
unsigned char LED10;
unsigned char LED11;

// RGB_LED5:
unsigned char LED12;
unsigned char LED13;
unsigned char LED14;

// RGB_LED6:
unsigned char LED15;
unsigned char LED16;
unsigned char LED17;

//RGB_LED7:
unsigned char LED18;
unsigned char LED19;
unsigned char LED20;

//RGB_LED8:
unsigned char LED21;
unsigned char LED22;
unsigned char LED23;

//RGB_LED9:
unsigned char LED24;
unsigned char LED25;
unsigned char LED26;

//LED_OFF:
unsigned char LED_OFF;

//Reg 0x12 - Group PWM - Variablen
unsigned char GROUP_PWM;

//Reg 0x13 - Group Freq - Variablen
unsigned char GROUP_FREQ;

//Reg 0x14-0x17 - LED Output State Control - Variablen
unsigned char LED_OUTPUT0;
unsigned char LED_OUTPUT1;
unsigned char LED_OUTPUT2;
unsigned char LED_OUTPUT3;

/************************
** PCA9635 Funktionen **
*************************/

void Variablen_Init(void);
void Full_Output(void);
void PCA9635(void);


//void setLEDs(int LEDs);
//void setBrightness(int brightness);


#endif /* PCA9635_H_ */