
#include <xpcc/architecture.hpp>
#include <stdint.h>
#include "LCD.hpp"

GPIO__OUTPUT(LedOrange, D, 13);		// User LED 3
GPIO__OUTPUT(LedGreen, D, 12);		// User LED 4
GPIO__OUTPUT(LedRed, D, 14);		// User LED 5
GPIO__OUTPUT(LedBlue, D, 15);		// User LED 6


GPIO__OUTPUT(LIS_CS, E, 2); //LIS302DL Chipselect Leitung


typedef xpcc::stm32::SpiMaster1 MySpi; //

static bool
initClock()
{
	// use external 8MHz crystal
	if (!xpcc::stm32::Clock::enableHse(xpcc::stm32::Clock::HSE_CRYSTAL)) {
		return false;
	}
	
	xpcc::stm32::Clock::enablePll(xpcc::stm32::Clock::PLL_HSE, 4, 168);
	return xpcc::stm32::Clock::switchToPll();
}


// ----------------------------------------------------------------------------
MAIN_FUNCTION
{
	initClock();
	init_LCD(); //<---- Diese Zeile


	LIS_CS::setOutput(true);

	MySpi::initialize(MySpi::MODE_0, MySpi::PRESCALER_32);
	MySpi::configurePins(MySpi::REMAP_PA5_PA6_PA7);

//-----------Lese WHO_AM_I------------
	LIS_CS::setOutput(false);
	MySpi::write(0b10001111);
	uint8_t value1 = MySpi::write(0);
	LIS_CS::setOutput(true);
//------------------------------------

	if(value1 == 59)
	{
		LedOrange::setOutput(true);
	}
	else LedBlue::setOutput(true);

	while (1)
	{

	}

	return 0;
}

