#ifndef __BOARD_H
#define __BOARD_H

/* MACROs for SET, RESET or TOGGLE Output port */
#define GPIO_HIGH(a,b)    a->ODR |= b
#define GPIO_LOW(a,b)     a->ODR &= ~b
#define GPIO_TOGGLE(a,b)  a->ODR ^= b

/* ADC */
#define ADC_PORT  GPIOD
#define ADC_PINU  GPIO_PIN_2
#define ADC_CHNLU ADC1_CHANNEL_3
#define ADC_SCHTU ADC1_SCHMITTTRIG_CHANNEL3
#define ADC_PINI  GPIO_PIN_3
#define ADC_CHNLI ADC1_CHANNEL_4
#define ADC_SCHTI ADC1_SCHMITTTRIG_CHANNEL4
#define ADC_SMPLS 64
#define ADC_RES   (1023UL << 3)
// Supply voltage in mili volts * fixed coeeficient
#define ADC_VREF  3030UL
// Voltage channel
#define VOLTAGE_MULT_TOP  15UL
#define VOLTAGE_MULT_BOT  100UL
#define VOLT_MUL_K        100UL
#define VOLT_MUL_KD       110UL
#define VOLT_MUL_DIV      (VOLTAGE_MULT_TOP * ADC_RES)
#define VOLTAGE_MUL       (uint16_t)((VOLT_MUL_K * (VOLTAGE_MULT_BOT * ADC_VREF) + (VOLT_MUL_DIV/2)) / VOLT_MUL_DIV)
// Current channel
#define CURREN_SHUNT      (1/0.01)
#define CURRENT_MULT_TOP  15UL
#define CURRENT_MULT_BOT  1UL
#define CUR_MUL_K         100UL
#define CUR_MUL_KD        136UL
#define CUR_MUL_DIV       (CURRENT_MULT_TOP * ADC_RES)
#define CURRENT_MUL       (uint16_t)((CUR_MUL_K * (CURRENT_MULT_BOT * ADC_VREF * CURREN_SHUNT) + (CUR_MUL_DIV/2)) / CUR_MUL_DIV)

#endif /* __BOARD_H */
