#include "main.h"
#include "delay.h"
#include "deviceSetup.h"
#include "usart.h"
#include "ascii.h"
#include "timer.h"

int main(int argc, char *argv[])
{
	uint8_t i = 0; 
	uint8_t a = '0';
	
	delayInitMs(8000000, 1000); 
	
	timerActivateBus(timer_2); 
	timerSetPrescaler(timer_2,159999); 
	timerSetAutoReload(timer_2,999999); 
	timerClearCounter(timer_2);
	timerEnableTimer(timer_2);

	pinConfig(pinB3, output, pushPull, def_res, def_speed);
	pinConfig(pinA0, input, def_stage, pullDown, def_speed);	

	usartInit(	usart2, 
				pinA2, 
				pinA15,
				115200,
				eight, 
				NO_PARITY_CTRL,
				noFlowControl); 

	//clears screen and send the wellcome messgae
	print_Usart(usart2, ASCII_clear); 
	print_Usart(usart2, "Wellcome to our KED project\n\r"); 
	

	//blinks 10 times to indicate the sicsessfull init if the device
	for(i = 0 ; i < 10 ; i++)
	{
		delayMs(100); 
		pinToggle(pinB3);
		delayMs(100); 
	}
	
	pinWrite(pinB3,0);
	
	while(1)
	{
		while(!(TIM2->SR & 1));
		TIM2->SR &=~ 1;
		pinToggle(pinB3);
		/*
		//USART will rteturn what wou type and trun led on if you press "1"
		a =	usartGetChar(usart2); 
		usartSendChar(usart2, a);			
		if(a == '1')
		{
			pinWrite(pinB3,1);
		}
		else 
		{
			pinWrite(pinB3,0);
		}	

		//test if the gpio port works as an input
		if(pinRead(pinA0))
		{
			pinWrite(pinB3,1);
		}
		else 
		{
			pinWrite(pinB3,0);
		}
		delayMs(10); 
		*/
	}
	return 1;
}
