Working version
No protections though
This commit is contained in:
@@ -6,6 +6,37 @@ using namespace dccd;
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
static const uint8_t def_dbnc_time = 10;
|
||||
|
||||
static const uint16_t def_pot_dead_bot = 500;
|
||||
static const uint16_t def_pot_dead_top = 4500;
|
||||
|
||||
static const uint8_t def_cc_mode_en = 1;
|
||||
|
||||
static const uint16_t def_cnter_us = 900;
|
||||
|
||||
static const uint16_t def_out_voltage_under_treshold = 0;
|
||||
static const uint16_t def_out_voltage_over_treshold = 9000;
|
||||
static const uint16_t def_out_voltage_hold_time = 1000;
|
||||
static const uint16_t def_out_voltage_cooldown_time = 0;
|
||||
|
||||
static const uint16_t def_out_current_under_treshold = 0;
|
||||
static const uint16_t def_out_current_over_treshold = 6000;
|
||||
static const uint16_t def_out_current_hold_time = 200;
|
||||
static const uint16_t def_out_current_cooldown_time = 1000;
|
||||
|
||||
static const uint16_t def_battery_voltage_under_treshold = 9000;
|
||||
static const uint16_t def_battery_voltage_over_treshold = 18000;
|
||||
static const uint16_t def_battery_voltage_hold_time = 1000;
|
||||
static const uint16_t def_battery_voltage_cooldown_time = 0;
|
||||
|
||||
static const uint16_t def_battery_current_under_treshold = 0;
|
||||
static const uint16_t def_battery_current_over_treshold = 8000;
|
||||
static const uint16_t def_battery_current_hold_time = 200;
|
||||
static const uint16_t def_battery_current_cooldown_time = 1000;
|
||||
|
||||
static const uint16_t def_inital_bat_voltage = 12000;
|
||||
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
/**** Public function definitions ****/
|
||||
@@ -20,66 +51,68 @@ dccd::DccdHw::~DccdHw(void)
|
||||
}
|
||||
|
||||
void dccd::DccdHw::init(dccdHwCfg_t* cfg)
|
||||
{
|
||||
{
|
||||
// Apply config
|
||||
bsp::Board::boardCfg_t board_cfg;
|
||||
board_cfg.pwm_f_khz = cfg->pwm_f_khz;
|
||||
board_cfg.od_common_is_pwm = 1;
|
||||
this->board_hw.init(&board_cfg);
|
||||
|
||||
this->counter.init(0xFFFF, 900);
|
||||
this->counter.init(0xFFFF, cfg->counter_step_us);
|
||||
this->counter.disabled = 0;
|
||||
|
||||
this->out_voltage.init(&(this->board_hw.out_voltage), &(this->counter));
|
||||
this->out_voltage.under_treshold = 0;
|
||||
this->out_voltage.over_treshold = 9000;
|
||||
this->out_voltage.hold_time = 1000;
|
||||
this->out_voltage.cooldown_time = 0;
|
||||
this->out_voltage.under_treshold = def_out_voltage_under_treshold;
|
||||
this->out_voltage.over_treshold = def_out_voltage_over_treshold;
|
||||
this->out_voltage.hold_time = def_out_voltage_hold_time;
|
||||
this->out_voltage.cooldown_time = def_out_voltage_cooldown_time;
|
||||
this->out_voltage.update_ain = 0;
|
||||
this->out_voltage.auto_reset = 1;
|
||||
|
||||
this->out_current.init(&(this->board_hw.out_current), &(this->counter));
|
||||
this->out_current.under_treshold = 0;
|
||||
this->out_current.over_treshold = 6000;
|
||||
this->out_current.hold_time = 200;
|
||||
this->out_current.cooldown_time = 1000;
|
||||
this->out_current.under_treshold = def_out_current_under_treshold;
|
||||
this->out_current.over_treshold = def_out_current_over_treshold;
|
||||
this->out_current.hold_time = def_out_current_hold_time;
|
||||
this->out_current.cooldown_time = def_out_current_cooldown_time;
|
||||
this->out_current.update_ain = 0;
|
||||
this->out_current.auto_reset = 1;
|
||||
|
||||
this->battery_voltage.init(&(this->board_hw.battery_voltage), &(this->counter));
|
||||
this->battery_voltage.under_treshold = 9000;
|
||||
this->battery_voltage.over_treshold = 18000;
|
||||
this->battery_voltage.hold_time = 1000;
|
||||
this->battery_voltage.cooldown_time = 0;
|
||||
this->battery_voltage.under_treshold = def_battery_voltage_under_treshold;
|
||||
this->battery_voltage.over_treshold = def_battery_voltage_over_treshold;
|
||||
this->battery_voltage.hold_time = def_battery_voltage_hold_time;
|
||||
this->battery_voltage.cooldown_time = def_battery_voltage_cooldown_time;
|
||||
this->battery_voltage.update_ain = 0;
|
||||
this->battery_voltage.auto_reset = 1;
|
||||
this->battery_voltage.last_read = 12000;
|
||||
this->battery_voltage.last_read = def_inital_bat_voltage;
|
||||
|
||||
this->battery_current.init(&(this->board_hw.battery_current), &(this->counter));
|
||||
this->battery_current.under_treshold = 0;
|
||||
this->battery_current.over_treshold = 8000;
|
||||
this->battery_current.hold_time = 200;
|
||||
this->battery_current.cooldown_time = 1000;
|
||||
this->battery_current.under_treshold = def_battery_current_under_treshold;
|
||||
this->battery_current.over_treshold = def_battery_current_over_treshold;
|
||||
this->battery_current.hold_time = def_battery_current_hold_time;
|
||||
this->battery_current.cooldown_time = def_battery_current_cooldown_time;
|
||||
this->battery_current.update_ain = 0;
|
||||
this->battery_current.auto_reset = 1;
|
||||
|
||||
this->btn_up.init(&(this->board_hw.din4), 0, &(this->counter), 10);
|
||||
this->btn_up.init(&(this->board_hw.din4), 0, &(this->counter), def_dbnc_time);
|
||||
this->btn_up.update_din = 0;
|
||||
|
||||
this->btn_down.init(&(this->board_hw.din3), 0, &(this->counter), 10);
|
||||
this->btn_down.init(&(this->board_hw.din3), 0, &(this->counter), def_dbnc_time);
|
||||
this->btn_down.update_din = 0;
|
||||
|
||||
this->btn_mode.init(&(this->board_hw.din1), 0, &(this->counter), 10);
|
||||
this->btn_mode.init(&(this->board_hw.din1), 0, &(this->counter), def_dbnc_time);
|
||||
this->btn_mode.update_din = 0;
|
||||
|
||||
this->handbrake.init(&(this->board_hw.hvdin3), 0, &(this->counter), 10);
|
||||
this->handbrake.init(&(this->board_hw.hvdin3), 0, &(this->counter), def_dbnc_time);
|
||||
this->handbrake.update_din = 0;
|
||||
|
||||
this->brakes.init(&(this->board_hw.hvdin2), 1, &(this->counter), 10);
|
||||
this->brakes.init(&(this->board_hw.hvdin2), 1, &(this->counter), def_dbnc_time);
|
||||
this->brakes.update_din = 0;
|
||||
|
||||
this->dimm.init(&(this->board_hw.hvdin1), 1, &(this->counter), 10);
|
||||
this->dimm.init(&(this->board_hw.hvdin1), 1, &(this->counter), def_dbnc_time);
|
||||
this->dimm.update_din = 0;
|
||||
|
||||
this->pot.init(&(this->board_hw.ain2), 500, 4500);
|
||||
this->pot.init(&(this->board_hw.ain2), def_pot_dead_bot, def_pot_dead_top);
|
||||
this->pot.update_ain = 0;
|
||||
|
||||
hw::OutReg::outRegCfg_t outreg_cfg;
|
||||
@@ -89,6 +122,8 @@ void dccd::DccdHw::init(dccdHwCfg_t* cfg)
|
||||
outreg_cfg.uout = &this->board_hw.out_voltage;
|
||||
outreg_cfg.iout = &this->board_hw.out_current;
|
||||
this->outreg.init(&outreg_cfg);
|
||||
this->outreg.cc_mode_en = def_cc_mode_en;
|
||||
this->outreg.update_ain = 0;
|
||||
|
||||
hw::LedDisplay::doutCfg_t dsp_cfg;
|
||||
dsp_cfg.led0_dout_ch = &(this->board_hw.od1);
|
||||
@@ -114,12 +149,10 @@ void dccd::DccdHw::init(dccdHwCfg_t* cfg)
|
||||
else this->board_hw.freq_pull.write(0);
|
||||
|
||||
// Set initial output states
|
||||
this->outreg.voltage = 0;
|
||||
this->outreg.current = 0;
|
||||
this->outreg.out_on = 0;
|
||||
this->outreg.lock = 0;
|
||||
this->outreg.cc_mode_en = 0;
|
||||
this->outreg.update_ain = 0;
|
||||
this->outreg.write_voltage(0);
|
||||
this->outreg.write_current(0);
|
||||
this->outreg.write_on(0);
|
||||
this->outreg.write_lock(0);
|
||||
this->outreg.process();
|
||||
|
||||
this->display.write_backlight(100);
|
||||
|
||||
Reference in New Issue
Block a user