Could be working version

This commit is contained in:
2024-04-12 15:18:31 +03:00
parent 5bb3ebe1bf
commit f8b62d4b00
19 changed files with 632 additions and 53 deletions

View File

@@ -0,0 +1,62 @@
/**** Includes ****/
#include "../utils/utils.h"
#include "board.h"
/**** Private definitions ****/
/**** Private constants ****/
/**** Private variables ****/
/**** Private function declarations ****/
/**** Public function definitions ****/
void board_init(void)
{
// MCU setup
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);
// Board setup
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;
}
void board_read(void)
{
dccd_i.read();
dccd_u.read();
bat_u.read();
bat_i.read();
ain1.read();
ain2.read();
din1.read();
din2.read();
din3.read();
din4.read();
hvdin1.read();
hvdin2.read();
hvdin3.read();
}
/**** Private function definitions ****/

41
firmware/src/bsp/board.h Normal file
View File

@@ -0,0 +1,41 @@
#ifndef BSP_BOARD_H_
#define BSP_BOARD_H_
/**** Includes ****/
#include <stdint.h>
#include "mcu/mcu_hal.h"
#include "ain.h"
#include "din.h"
#include "dout.h"
#include "dio.h"
#include "halfbridge.h"
#include "pwm.h"
static bsp::AnalogIn dccd_i = bsp::AnalogIn(mcu::ADC0);
static bsp::AnalogIn dccd_u = bsp::AnalogIn(mcu::ADC1);
static bsp::AnalogIn bat_u = bsp::AnalogIn(mcu::ADC2);
static bsp::AnalogIn bat_i = bsp::AnalogIn(mcu::ADC3);
static bsp::Hafbridge hbridge = bsp::Hafbridge(mcu::PWM0, mcu::GPIO15, 95);
static bsp::AnalogIn ain1 = bsp::AnalogIn(mcu::ADC5); // mode
static bsp::AnalogIn ain2 = bsp::AnalogIn(mcu::ADC4); // pot
static bsp::DigitalIn din1 = bsp::DigitalIn(mcu::GPIO0, 0, bsp::DIN_HIGH); //mode
static bsp::DigitalIn din2 = bsp::DigitalIn(mcu::GPIO1, 0, bsp::DIN_HIGH); //pot
static bsp::DigitalIn din3 = bsp::DigitalIn(mcu::GPIO2, 0, bsp::DIN_HIGH); //down
static bsp::DigitalIn din4 = bsp::DigitalIn(mcu::GPIO3, 0, bsp::DIN_HIGH); //up
static bsp::DigitalIn hvdin1 = bsp::DigitalIn(mcu::GPIO4, 1, bsp::DIN_LOW); //dimm
static bsp::DigitalIn hvdin2 = bsp::DigitalIn(mcu::GPIO5, 1, bsp::DIN_LOW); //brakes
static bsp::DigitalIn hvdin3 = bsp::DigitalIn(mcu::GPIO6, 1, bsp::DIN_LOW); //hbrake
static bsp::DigitalIO hvdin3_pull = bsp::DigitalIO(mcu::GPIO7, bsp::DIN_HIGH); //hbrake pull
static bsp::DigitalOut odout1 = bsp::DigitalOut(mcu::GPIO9, 1);
static bsp::DigitalOut odout2 = bsp::DigitalOut(mcu::GPIO10, 1);
static bsp::DigitalOut odout3 = bsp::DigitalOut(mcu::GPIO11, 1);
static bsp::DigitalOut odout4 = bsp::DigitalOut(mcu::GPIO12, 1);
static bsp::DigitalOut odout5 = bsp::DigitalOut(mcu::GPIO13, 1);
static bsp::DigitalOut odout6 = bsp::DigitalOut(mcu::GPIO14, 1);
static bsp::PWMout od_pwm = bsp::PWMout(mcu::PWM1);
void board_init(void);
void board_read(void);
#endif /* BSP_BOARD_H_ */