Continued work
This commit is contained in:
110
firmware/src/hw/dccd_hw.cpp
Normal file
110
firmware/src/hw/dccd_hw.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/**** Includes ****/
|
||||
#include "../utils/utils.h"
|
||||
#include "../bsp/mcu/mcu_hal.h"
|
||||
#include "dccd_hw.h"
|
||||
|
||||
using namespace hw;
|
||||
|
||||
/**** Private definitions ****/
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
/**** Public function definitions ****/
|
||||
hw::DccdHw::DccdHw(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hw::DccdHw::~DccdHw(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void hw::DccdHw::init(dccdHwCfg_t* cfg)
|
||||
{
|
||||
this->board_hw.init();
|
||||
|
||||
this->counter.init(0xFFFF, 900);
|
||||
|
||||
this->out_voltage = 0;
|
||||
this->out_current = 0;
|
||||
this->battery_voltage = 12000;
|
||||
this->battery_current = 0;
|
||||
|
||||
this->btn_up.init(&(this->board_hw.din4), 0, &(this->counter), 10);
|
||||
this->btn_up.update_din = 0;
|
||||
|
||||
this->btn_down.init(&(this->board_hw.din3), 0, &(this->counter), 10);
|
||||
this->btn_down.update_din = 0;
|
||||
|
||||
this->btn_mode.init(&(this->board_hw.din1), 0, &(this->counter), 10);
|
||||
this->btn_mode.update_din = 0;
|
||||
|
||||
this->handbrake.init(&(this->board_hw.hvdin3), 0, &(this->counter), 10);
|
||||
this->handbrake.update_din = 0;
|
||||
|
||||
this->brakes.init(&(this->board_hw.hvdin2), 1, &(this->counter), 10);
|
||||
this->brakes.update_din = 0;
|
||||
|
||||
this->dimm.init(&(this->board_hw.hvdin1), 1, &(this->counter), 10);
|
||||
this->dimm.update_din = 0;
|
||||
|
||||
this->pot.init(&(this->board_hw.ain2), 500, 4500);
|
||||
this->pot.update_ain = 0;
|
||||
|
||||
this->outdriver.init(&(this->board_hw.out_pwm), &(this->board_hw.out_low));
|
||||
|
||||
LedDisplay::doutCfg_t dsp_cfg;
|
||||
dsp_cfg.led0_dout_ch = &(this->board_hw.od1);
|
||||
dsp_cfg.led1_dout_ch = &(this->board_hw.od2);
|
||||
dsp_cfg.led2_dout_ch = &(this->board_hw.od3);
|
||||
dsp_cfg.led3_dout_ch = &(this->board_hw.od4);
|
||||
dsp_cfg.led4_dout_ch = &(this->board_hw.od5);
|
||||
dsp_cfg.led5_dout_ch = &(this->board_hw.od6);
|
||||
|
||||
this->display.init(&dsp_cfg, 0, &(this->counter), &(this->board_hw.od_pwm));
|
||||
|
||||
// Apply configuration
|
||||
if(cfg->handbrake_pull_up)
|
||||
{
|
||||
this->board_hw.hvdin3_pull.write(1);
|
||||
}
|
||||
else this->board_hw.hvdin3_pull.write(0);
|
||||
|
||||
if(cfg->speed_hall)
|
||||
{
|
||||
this->board_hw.freq_pull.write(1);
|
||||
}
|
||||
else this->board_hw.freq_pull.write(0);
|
||||
|
||||
// Set initial output states
|
||||
this->outdriver.write((uint16_t)0);
|
||||
this->outdriver.enable();
|
||||
|
||||
this->display.write_backlight(100);
|
||||
this->display.write(0x00);
|
||||
}
|
||||
|
||||
void hw::DccdHw::read(void)
|
||||
{
|
||||
// Update low level inputs
|
||||
this->board_hw.read();
|
||||
|
||||
this->counter.increment();
|
||||
|
||||
this->out_voltage = this->board_hw.out_voltage.last_read;
|
||||
this->out_current = this->board_hw.out_current.last_read;
|
||||
this->battery_voltage = this->board_hw.battery_voltage.last_read;
|
||||
this->battery_current = this->board_hw.battery_current.last_read;
|
||||
|
||||
this->btn_up.process();
|
||||
this->btn_down.process();
|
||||
this->btn_mode.process();
|
||||
this->handbrake.process();
|
||||
this->brakes.process();
|
||||
this->dimm.process();
|
||||
|
||||
this->pot.read();
|
||||
}
|
||||
|
||||
/**** Private function definitions ***/
|
||||
Reference in New Issue
Block a user