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.
87 lines
1.4 KiB
87 lines
1.4 KiB
/*
|
|
* cppmain.cc
|
|
*
|
|
* Created on: Jul 4, 2023
|
|
* Author: heck
|
|
*/
|
|
|
|
#include "cppmain.h"
|
|
#include "main.h"
|
|
#include "usbd_cdc_if.h"
|
|
#include "dac.h"
|
|
#include <cmath>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include "limits"
|
|
|
|
const double pi{ std::acos(-1) };
|
|
|
|
// Serial Logging
|
|
// --------------
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
// DAC
|
|
// ---
|
|
|
|
void set_dac_1(uint32_t val)
|
|
{
|
|
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_L, val);
|
|
}
|
|
|
|
void set_dac_2(uint32_t val)
|
|
{
|
|
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_2, DAC_ALIGN_12B_L, val);
|
|
}
|
|
|
|
|
|
// LED
|
|
// ---
|
|
|
|
void led_green_toggle()
|
|
{
|
|
HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
|
|
}
|
|
|
|
void led_green_on()
|
|
{
|
|
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
void led_green_off()
|
|
{
|
|
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);
|
|
}
|
|
|
|
|
|
// MAIN
|
|
// ----
|
|
|
|
void irq1()
|
|
{
|
|
led_green_toggle();
|
|
}
|
|
|
|
void cppmain(void)
|
|
{
|
|
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
|
|
long t{ 0 };
|
|
while (true) {
|
|
unsigned char res = t * ((t >> 12 | t >> 8) & 63 & t >> 4);
|
|
set_dac_1((res % 256) * 100);
|
|
for (int g = 0; g < 600000; g++) {}
|
|
t++;
|
|
t %= (std::numeric_limits<long>::max() - 1);
|
|
}
|
|
}
|
|
|