#ifndef OUTPUT_REGULATOR_H_
#define OUTPUT_REGULATOR_H_

/**** Includes ****/
#include <stdint.h>
#include "../bsp/board.h"

namespace hw {

/**** Public definitions ****/

class OutReg
{
	public:
	typedef struct {
		bsp::PwmOut* pwm_high;
		bsp::DigitalOut* dout_low;
		bsp::AnalogIn* ubat;
		bsp::AnalogIn* uout;
		bsp::AnalogIn* iout;
	} outRegCfg_t;
	
	OutReg(void);
	~OutReg(void);
	
	void init(outRegCfg_t* cfg);
	
	uint8_t cc_mode_en;
	uint8_t update_ain;
	uint16_t cc_tolerance;
	
	void write_voltage(uint16_t voltage);
	void write_current(uint16_t current);
	void write_on(uint8_t state);
	void write_lock(uint8_t state);
	
	uint16_t read_voltage(void);
	uint16_t read_current(void);
	
	void process(void);
	void force_off(void);
	
	#ifndef TESTING
	protected:
	#endif
	bsp::PwmOut* pwm_high;
	bsp::DigitalOut* dout_low;
	bsp::AnalogIn* ubat;
	bsp::AnalogIn* uout;
	bsp::AnalogIn* iout;
	uint16_t voltage;
	uint16_t current;
	uint16_t current_top;
	uint16_t current_bot;
	uint8_t out_on;
	uint8_t lock;
};

/**** Public function declarations ****/

#ifdef TESTING
#endif

} //namespace

#endif /* OUTPUT_REGULATOR_H_ */