/*
 * matrix.h
 *
 * Created: 4.3.2015 11:05:52
 *  Author: Matej
 */ 


#ifndef MATRIX_H_
#define MATRIX_H_

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include "global.h"

/*
* Define port C
*/
#define LED1	(1<<PC1)
#define LED2	(1<<PC0)
#define WRITE	(1<<PC7)
#define ENABLE	(1<<PC6)
/*
* Define PORT A
*/
#define  ROW_PORT	PORTA
/*
* Define PORT B
*/
#define COLUMN_PORT	PORTB
/*
* Define direcrt
*/
#define LEFT	0x01
#define RIGHT	0x02
#define UP		0x03
#define DOWN	0x04
/*
* Define units
*/
#define S		0x01
#define MS		0x02		

static const unsigned char rowAddr[19] = 
{
	0x90, 0x88, 0x80, 0x78, 0x70, 0x68, 0x60, 0x58, 0x50, 
	0x48, 0x40,	0x38, 0x30, 0x28, 0x20, 0x18, 0x10, 0x08, 0x00
};

static const unsigned char columnAddr[140] = 
{
	0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
	0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8,
	
	0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
	0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC,
	
	0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
	0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA,
	
	0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
	0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE,
	
	0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
	0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9
};
 

 
struct command 
{
	unsigned char direct;
	unsigned char step;
	unsigned char units;
	uint32_t delay; 
};

void initPort(void);
void initGlobal(void);

void setRow(unsigned int nOfRow);
void setColumn(unsigned int nOfColumn);
void write(void);
void writeAll(void);
void clearAll(void);
void writeXY(unsigned char colour);
void writeFourBit(unsigned char symF);
void writeByte(unsigned char symbol);
void writeThreeBit(unsigned char symT);
void writeColumn(unsigned char index);
void writeC(unsigned char colour);
void writePicture(void);
void rotatePicture(void);
void clearArray(unsigned char array[3][140]);
void clearColumn(unsigned char nOfColumn);

unsigned char setSensorData(void);
unsigned char setText(void);

void setPixel(void);

#endif /* MATRIX_H_ */