wideband/firmware/main.cpp

60 lines
1.0 KiB
C++
Raw Normal View History

2020-09-19 02:49:20 -07:00
#include "ch.h"
#include "hal.h"
2020-09-19 21:39:29 -07:00
#include "analog_input.h"
2020-09-19 16:51:02 -07:00
#include "can.h"
2020-09-19 15:44:10 -07:00
#include "pwm.h"
// 400khz / 1024 = 390hz PWM
2020-09-19 15:45:44 -07:00
// TODO: this is wired to an inverted output, what do?
2020-10-26 12:45:50 -07:00
Pwm heaterPwm(PWMD1, 0, 400'000, 1024);
2020-09-19 15:44:10 -07:00
// 48MHz / 1024 = 46.8khz PWM
2020-10-26 12:45:50 -07:00
Pwm pumpDac(PWMD3, 0, 48'000'000, 1024);
2020-09-19 15:44:10 -07:00
2020-10-26 17:25:05 -07:00
static const UARTConfig uartCfg =
{
.txend1_cb = nullptr,
.txend2_cb = nullptr,
.rxend_cb = nullptr,
.rxchar_cb = nullptr,
.rxerr_cb = nullptr,
.timeout_cb = nullptr,
.timeout = 0,
.speed = 230400,
.cr1 = 0,
.cr2 = 0,
.cr3 = 0,
};
2020-09-19 02:49:20 -07:00
/*
* Application entry point.
*/
2020-09-19 21:39:29 -07:00
int main() {
2020-09-19 16:51:02 -07:00
halInit();
chSysInit();
2020-09-19 02:49:20 -07:00
2020-09-19 16:51:02 -07:00
InitCan();
2020-09-19 15:44:10 -07:00
2020-10-26 17:25:05 -07:00
uartStart(&UARTD1, &uartCfg);
2020-10-26 12:45:50 -07:00
adcStart(&ADCD1, nullptr);
2020-09-19 16:51:02 -07:00
heaterPwm.Start();
pumpDac.Start();
2020-09-19 02:49:20 -07:00
2020-09-19 20:44:13 -07:00
heaterPwm.SetDuty(0.2f);
pumpDac.SetDuty(0.4f);
2020-09-19 16:51:02 -07:00
while (true) {
2020-09-19 21:39:29 -07:00
auto result = AnalogSample();
2020-09-19 16:51:02 -07:00
// dummy data
SendCanData(0.5f, 300);
2020-10-26 17:25:05 -07:00
uartStartSend(&UARTD1, 13, "Hello, world!");
2020-09-19 16:51:02 -07:00
chThdSleepMilliseconds(10);
}
2020-09-19 02:49:20 -07:00
}