Changed logic

This commit is contained in:
Andis Zīle
2024-04-11 23:03:33 +03:00
parent a05c53401f
commit f1edc6e15a
24 changed files with 129 additions and 175 deletions

View File

@@ -1,13 +1,13 @@
/**** Includes ****/
#include "utils/utils.h"
#include "board/mcu/mcu_hal.h"
#include "board/ain.h"
#include "board/din.h"
#include "board/dout.h"
#include "board/dio.h"
#include "board/halfbridge.h"
#include "board/pwm.h"
#include "bsp/mcu/mcu_hal.h"
#include "bsp/ain.h"
#include "bsp/din.h"
#include "bsp/dout.h"
#include "bsp/dio.h"
#include "bsp/halfbridge.h"
#include "bsp/pwm.h"
#include "hw/button.h"
#include "hw/potentiometer.h"
@@ -15,63 +15,49 @@
#include "hw/cv_output.h"
/**** Private definitions ****/
static board::AnalogIn dccd_i(mcu::ADC0);
static board::AnalogIn dccd_u(mcu::ADC1);
static board::AnalogIn bat_u(mcu::ADC2);
static board::AnalogIn bat_i(mcu::ADC3);
/**** Private constants ****/
/**** Private variables ****/
static bsp::AnalogIn dccd_i(mcu::ADC0);
static bsp::AnalogIn dccd_u(mcu::ADC1);
static bsp::AnalogIn bat_u(mcu::ADC2);
static bsp::AnalogIn bat_i(mcu::ADC3);
static bsp::Hafbridge hbridge(mcu::PWM0, mcu::GPIO15, 95);
static bsp::AnalogIn ain1(mcu::ADC5); // mode
static bsp::AnalogIn ain2(mcu::ADC4); // pot
static bsp::DigitalIn din1(mcu::GPIO0, 0, bsp::DIN_HIGH); //mode
static bsp::DigitalIn din2(mcu::GPIO1, 0, bsp::DIN_HIGH); //pot
static bsp::DigitalIn din3(mcu::GPIO2, 0, bsp::DIN_HIGH); //down
static bsp::DigitalIn din4(mcu::GPIO3, 0, bsp::DIN_HIGH); //up
static bsp::DigitalIn hvdin1(mcu::GPIO4, 1, bsp::DIN_LOW); //dimm
static bsp::DigitalIn hvdin2(mcu::GPIO5, 1, bsp::DIN_LOW); //brakes
static bsp::DigitalIn hvdin3(mcu::GPIO6, 1, bsp::DIN_LOW); //hbrake
static bsp::DigitalIO hvdin3_pull(mcu::GPIO7, bsp::DIN_HIGH); //hbrake pull
static bsp::DigitalOut odout1(mcu::GPIO9, 1);
static bsp::DigitalOut odout2(mcu::GPIO10, 1);
static bsp::DigitalOut odout3(mcu::GPIO11, 1);
static bsp::DigitalOut odout4(mcu::GPIO12, 1);
static bsp::DigitalOut odout5(mcu::GPIO13, 1);
static bsp::DigitalOut odout6(mcu::GPIO14, 1);
static bsp::PWMout od_pwm(mcu::PWM1);
static board::Hafbridge hbridge(mcu::PWM0, mcu::GPIO15, 95);
static hw::Button btn_mode(&din1, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
static hw::Button btn_up(&din4, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
static hw::Button btn_down(&din3, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
static board::AnalogIn ain1(mcu::ADC5); // mode
static board::AnalogIn ain2(mcu::ADC4); // pot
static board::DigitalIn din1(mcu::GPIO0, 0, board::DIN_HIGH); //mode
static board::DigitalIn din2(mcu::GPIO1, 0, board::DIN_HIGH); //pot
static board::DigitalIn din3(mcu::GPIO2, 0, board::DIN_HIGH); //down
static board::DigitalIn din4(mcu::GPIO3, 0, board::DIN_HIGH); //up
static board::DigitalIn hvdin1(mcu::GPIO4, 1, board::DIN_LOW); //dimm
static board::DigitalIn hvdin2(mcu::GPIO5, 1, board::DIN_LOW); //brakes
static board::DigitalIn hvdin3(mcu::GPIO6, 1, board::DIN_LOW); //hbrake
static board::DigitalIO hvdin3_pull(mcu::GPIO7, board::DIN_HIGH); //hbrake pull
static board::DigitalOut odout1(mcu::GPIO9, 1);
static board::DigitalOut odout2(mcu::GPIO10, 1);
static board::DigitalOut odout3(mcu::GPIO11, 1);
static board::DigitalOut odout4(mcu::GPIO12, 1);
static board::DigitalOut odout5(mcu::GPIO13, 1);
static board::DigitalOut odout6(mcu::GPIO14, 1);
static board::PWMout od_pwm(mcu::PWM1);
static hw::Button btn_mode(&din1, board::DIN_LOW, 10, hw::BUTTON_OFF);
static hw::Button btn_up(&din4, board::DIN_LOW, 10, hw::BUTTON_OFF);
static hw::Button btn_down(&din3, board::DIN_LOW, 10, hw::BUTTON_OFF);
static hw::Button sw_dimm(&hvdin1, board::DIN_HIGH, 10, hw::BUTTON_OFF);
static hw::Button sw_brakes(&hvdin2, board::DIN_HIGH, 10, hw::BUTTON_OFF);
static hw::Button sw_hbrake(&hvdin3, board::DIN_LOW, 10, hw::BUTTON_OFF);
static hw::Button sw_dimm(&hvdin1, bsp::DIN_HIGH, 10, hw::BUTTON_OFF);
static hw::Button sw_brakes(&hvdin2, bsp::DIN_HIGH, 10, hw::BUTTON_OFF);
static hw::Button sw_hbrake(&hvdin3, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
static hw::Potentiometer pot(&ain2, 500, 4500);
static hw::DisplayLed display(&odout1, &odout2, &odout3, &odout4, &odout5, &odout6, &od_pwm);
static hw::CVoutput cvout(&hbridge);
static hw::CVoutput cvout(&hbridge, &bat_u);
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/
static void board_setup(void);
/**** Public function definitions ****/
int main(void)
{
board_setup();
cvout.target = 0;
cvout.min_out = 500;
cvout.enable();
// Super loop
while(1)
{
@@ -83,35 +69,3 @@ int main(void)
}
/**** Private function definitions ***/
static void board_setup(void)
{
mcu::startupCfg_t mcu_cfg;
mcu_cfg.adc_clk = mcu::ADC_DIV2;
mcu_cfg.pwm_clk = mcu::TIM_DIV1;
mcu_cfg.pwm_top = 200;
mcu_cfg.pwm_ch1_en = 1;
mcu::startup(&mcu_cfg);
dccd_i.mul = 215;
dccd_i.div = 22;
dccd_i.offset = 0;
dccd_i.last_read = 0;
dccd_u.mul = 20;
dccd_u.div = 1;
dccd_u.offset = 0;
dccd_u.last_read = 0;
bat_u.mul = 20;
bat_u.div = 1;
bat_u.offset = 0;
bat_u.last_read = 12000;
bat_i.mul = 235;
bat_i.div = 6;
bat_i.offset = 0;
bat_i.last_read = 0;
od_pwm.write(100);
}