/*
 * main.h
 *
 *  Created on: 7. 3. 2020
 *      Author: Ondrej Vitoslavsky
 */

#ifndef MAIN_H_
#define MAIN_H_

#include "stm32f4xx.h"
#include "stm32f4_discovery.h"

typedef enum _MTX_Status
{
	NewSettingIsRequested = 0,
	AO0_IsBeingSimulated = 1,
	AO1_IsBeingSimulated = 2,
	AB_AreBeingRead = 3,
	MeasurementModeIsActive = 4,
}MTX_Status;

typedef enum _MTX_Command
{
	NewSettingSend = 0,
	Simulate_AO0 = 1,
	Simulate_AO1 = 2,
	ReadSensorSignals_AB = 3,
	ActivateMeasurementMode = 4,
}MTX_Command;

typedef enum _AO_Type
{
	Deviation_Bipolar_20mA = 1,
	Deviation_Unipolar_0_20mA = 2,
	Deviation_Unipolar_4_20mA = 3,
	Nominal_Unipolar_0_20mA = 12,
	Nominal_Unipolar_4_20mA = 13,
}AO_Type;



typedef struct {
	float 	INP_SC;
	float 	INP_OF;
	float 	RDG_SC;
	float 	RDG_OF;
	AO_Type AO0_Type;
	AO_Type AO1_Type;
	float 	AO0_R;
	float 	AO0_Nom;
	float 	AO1_R;
	float 	AO1_Nom;
	float 	T_Limitation;
	uint16_t AD_Rate;

	uint16_t BOM;
	MTX_Command Command0;
	MTX_Command Command1;
	float 	Simulate_Nom;
	float 	Simulate_T;
}Settings_struct;


#define IS_AO_TYPE(TYPE) (((TYPE) == 1)		||\
                            ((TYPE) == 2)	||\
                            ((TYPE) == 3)	||\
                            ((TYPE) == 12)	||\
                            ((TYPE) == 13))



void SystemClock_Config(void);

void Error_Handler(void);

void MTX_Set_Status0(MTX_Status Status);

void MTX_Reset_Status0(MTX_Status Status);

uint8_t MTX_Read_Status0(MTX_Status Status);

uint8_t MTX_Read_Command0(MTX_Command Command, Settings_struct *Settings);



uint32_t get_Us(void);
/*Wait in microseconds*/
void Delay_us(uint16_t micros);


#endif /* MAIN_H_ */
