/**** Includes ****/
#include "../utils/utils.h"
#include "devices.h"

/**** Private definitions ****/
/**** Private constants ****/
static const uint16_t def_button_hold_time = 1000;
static const uint16_t def_max_voltage = 7000;
static const uint16_t def_min_voltage = 100;
static const uint16_t def_fuse_treshold = 6000;
static const uint16_t def_fuse_hold_cycles = 50;
static const uint16_t def_fuse_cooldown_cycles = 1000;

/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
void devices_init(void)
{
	board_init();
	
	btn_up.hold_time = def_button_hold_time;
	btn_down.hold_time = def_button_hold_time;
	
	ccout.max_voltage = def_max_voltage;
	ccout.max_current = 0;
	ccout.min_voltage = def_min_voltage;
	
	sup_fuse.hold_current = def_fuse_treshold;
	sup_fuse.trip_cycles = def_fuse_hold_cycles;
	sup_fuse.cooldown_cycles = def_fuse_cooldown_cycles;
	
	out_fuse.hold_current = def_fuse_treshold;
	out_fuse.trip_cycles = def_fuse_hold_cycles;
	out_fuse.cooldown_cycles = def_fuse_cooldown_cycles;
	
	hvdin3_pull.write(bsp::DOUT_HIGH);
	
	devices_update_inputs();
	
	display.write(0x00);
	display.set_brigthness(100);
	
	ccout.update();
	ccout.enable();
}

void devices_update_inputs(void)
{
	board_read();
	
	pot.update();
	
	btn_mode.update();
	btn_up.update();
	btn_down.update();
	
	sw_dimm.update();
	sw_brakes.update();
	sw_hbrake.update();
	
	sup_fuse.update();
	out_fuse.update();
	
	display.process_timer();
}

/**** Private function definitions ****/
