Conquering the STM32F4 on the discovery board step-by-step. Commit history is tutorialesque, but not clean of course.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
998 B

/*
* cppmain.cc
*
* Created on: Jul 4, 2023
* Author: heck
*/
#include "cppmain.h"
#include "main.h"
#include "usbd_cdc_if.h"
#include <cmath>
#include <functional>
#include <iostream>
const double pi{ std::acos(-1) };
void log(const std::string &msg)
{
std::string out{ msg };
out.append("\r\n");
CDC_Transmit_FS((uint8_t *)out.data(), out.size());
}
void log(std::string &&msg)
{
log(msg);
}
std::function<void()> printheck = [] { log("heck"); };
void cppmain(void)
{
log(pi);
long i{ 0 };
while (true) {
const float piwrap{ std::fmod(float(i / 100.), float(2. * pi)) };
const float sin_factor = std::abs(float(sin(piwrap)));
HAL_Delay(static_cast<int>(sin_factor * 100.0));
HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
log({ "hello heck:" + std::to_string(i) + " piwrap:" + std::to_string(piwrap) +
" fact:" + std::to_string(sin_factor) });
printheck();
i++;
}
}