diff --git a/firmware/src/board/mcu/mcu_hal.h b/firmware/src/board/mcu/mcu_hal.h index 42a6495..83c664c 100644 --- a/firmware/src/board/mcu/mcu_hal.h +++ b/firmware/src/board/mcu/mcu_hal.h @@ -8,33 +8,6 @@ namespace mcu { /**** Public definitions ****/ /* -GPIO0 Down -GPIO1 Up -GPIO2 Mode -GPIO3 Handbrake -GPIO4 Brakes -GPIO5 Dimm -GPIO6 LED0 -GPIO7 LED1 -GPIO8 LED2 -GPIO9 LED3 -GPIO10 LED4 -GPIO11 LED5 -GPIO12 DCCD Enable -GPIO13 Handbrake pull -GPIO14 Speed pull -GPIO15 DCCD PWM -GPIO16 LED PWM - -ADC0 Output current -ADC1 Output voltage -ADC2 Battery current -ADC3 Battery voltage -ADC4 Potentiometer -ADC5 Mode -ADC8 MCU temperature -ADC14 MCU internal reference -ADC15 MCU ground */ const uint8_t GPIO0 = 0; //PC5 Mode diff --git a/firmware/src/board/udccd_board.h b/firmware/src/board/udccd_board.h deleted file mode 100644 index 5de104c..0000000 --- a/firmware/src/board/udccd_board.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef UDCCD_BOARD_H_ -#define UDCCD_BOARD_H_ - -/**** Includes ****/ -#include - -using namespace board; - -/**** Public definitions ****/ -static AnalogIn dccd_i(mcu::ADC0); -static AnalogIn dccd_u(mcu::ADC1); -static AnalogIn bat_u(mcu::ADC2); -static AnalogIn bat_i(mcu::ADC3); - -static Hafbridge hbridge(mcu::PWM0, mcu::GPIO15, 95); - -static AnalogIn ain1(mcu::ADC5); -static AnalogIn ain2(mcu::ADC4); - -static DigitalIn din1(mcu::GPIO0, 0, board::DIN_HIGH); -static DigitalIn din2(mcu::GPIO1, 0, board::DIN_HIGH); -static DigitalIn din3(mcu::GPIO2, 0, board::DIN_HIGH); -static DigitalIn din4(mcu::GPIO3, 0, board::DIN_HIGH); - -static DigitalIn hvdin1(mcu::GPIO4, 1, board::DIN_LOW); -static DigitalIn hvdin2(mcu::GPIO5, 1, board::DIN_LOW); -static DigitalIn hvdin3(mcu::GPIO6, 1, board::DIN_LOW); -static DigitalIO hvdin3_pull(mcu::GPIO3, board::DIN_HIGH); - -static DigitalOut odout1(mcu::GPIO9, 1); -static DigitalOut odout2(mcu::GPIO10, 1); -static DigitalOut odout3(mcu::GPIO11, 1); -static DigitalOut odout4(mcu::GPIO12, 1); -static DigitalOut odout5(mcu::GPIO13, 1); -static DigitalOut odout6(mcu::GPIO14, 1); - -static PWMout od_pwm(mcu::PWM1); - -/**** Public function declarations ****/ - -#ifdef TESTING -#endif - -#endif /* UDCCD_BOARD_H_ */ \ No newline at end of file diff --git a/firmware/src/hw/cv_output.h b/firmware/src/hw/cv_output.h index 75a0a27..37a5b66 100644 --- a/firmware/src/hw/cv_output.h +++ b/firmware/src/hw/cv_output.h @@ -3,7 +3,6 @@ /**** Includes ****/ #include -#include "../board/ain.h" #include "../board/halfbridge.h" namespace hw { diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index a2517e0..6e43c7c 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -12,23 +12,65 @@ #include "hw/button.h" #include "hw/potentiometer.h" #include "hw/display_led.h" - -#include "board/udccd_board.h" +#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); + +static board::Hafbridge hbridge(mcu::PWM0, mcu::GPIO15, 95); + +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::Potentiometer pot(&ain2, 500, 4500); + +static hw::DisplayLed display(&odout1, &odout2, &odout3, &odout4, &odout5, &odout6, &od_pwm); + +static hw::CVoutput cvout(&hbridge); + /**** Private constants ****/ /**** Private variables ****/ /**** Private function declarations ****/ +static void board_setup(void); + /**** Public function definitions ****/ int main(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); + board_setup(); + + cvout.target = 0; + cvout.min_out = 500; + cvout.enable(); // Super loop while(1) @@ -41,3 +83,35 @@ 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); +} \ No newline at end of file diff --git a/firmware/src/uDCCD.cppproj b/firmware/src/uDCCD.cppproj index 5fc501d..5f63a83 100644 --- a/firmware/src/uDCCD.cppproj +++ b/firmware/src/uDCCD.cppproj @@ -195,9 +195,6 @@ compile - - compile - compile