//
// This file is part of the GNU ARM Eclipse distribution.
// Copyright (c) 2014 Liviu Ionescu.
//

// ----------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include "diag/Trace.h"
#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "gpio.h"
#include "timer.h"
#include "uart.h"

#define EXTERN
#include "globals.h"








int
main(int argc, char* argv[])
{
	// At this stage the system clock should have already been configured
	// at high speed.
	uint8_t toggle = 1;
	uint8_t counter = 0;

	/* Init functions */
	gpioInit();
	timer2PWMInit();
	uart1Init();

	// Infinite loop
	while (1)
	{
		if(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13))
		{
			if(toggle == 0)
			{
				toggle = 1;
				setNewPWMValue();
				counter ++;
				//HAL_UART_Transmit(&uart1Handle, &counter, 1, 5000);
			}

		}
		else
		{
			toggle = 0;
		}
	}
}
