2020-04-13 13:38:56 +00:00
|
|
|
#include <stm32f3xx_hal.h>
|
2019-08-20 19:27:35 +00:00
|
|
|
|
2020-02-23 16:14:07 +00:00
|
|
|
#include "config.h"
|
2019-09-02 11:41:24 +00:00
|
|
|
#include "drivers/display.h"
|
2019-10-28 17:56:37 +00:00
|
|
|
#include "drivers/encoder.h"
|
2020-04-13 13:38:56 +00:00
|
|
|
#include "drivers/peripherals.h"
|
2020-01-03 21:09:11 +00:00
|
|
|
#include "menu/menu.h"
|
2020-02-05 00:29:23 +00:00
|
|
|
#include "menu/menu_items.h"
|
2019-10-06 10:55:04 +00:00
|
|
|
#include "part.h"
|
2020-02-24 00:53:33 +00:00
|
|
|
#include "settings.h"
|
2020-04-13 13:38:56 +00:00
|
|
|
#include "stm32f3xx_hal_cortex.h"
|
|
|
|
#include "stm32f3xx_hal_tim.h"
|
2019-09-19 14:41:32 +00:00
|
|
|
#include "stmlib/system/system_clock.h"
|
|
|
|
#include "ui.h"
|
2019-08-20 19:27:35 +00:00
|
|
|
|
2020-02-26 00:22:26 +00:00
|
|
|
namespace std {
|
|
|
|
void __throw_bad_function_call()
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void __cxa_pure_virtual()
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2019-08-20 19:27:35 +00:00
|
|
|
using namespace stmlib;
|
|
|
|
|
2019-09-02 11:41:24 +00:00
|
|
|
Display display;
|
2019-10-28 17:56:37 +00:00
|
|
|
Encoder encoder;
|
|
|
|
|
2020-02-24 00:53:33 +00:00
|
|
|
Settings settings;
|
|
|
|
|
2020-02-23 16:14:07 +00:00
|
|
|
Part parts[PART_COUNT];
|
|
|
|
Part* part_pointers[PART_COUNT] = { &parts[0], &parts[1], &parts[2], &parts[3] };
|
2020-02-25 20:48:04 +00:00
|
|
|
UI ui(part_pointers, &display, &settings);
|
2019-08-30 11:07:08 +00:00
|
|
|
|
|
|
|
// Default interrupt handlers.
|
|
|
|
extern "C" {
|
2019-09-02 11:41:24 +00:00
|
|
|
void NMI_Handler() {}
|
|
|
|
void HardFault_Handler()
|
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
while (1)
|
|
|
|
;
|
2019-09-02 11:41:24 +00:00
|
|
|
}
|
|
|
|
void MemManage_Handler()
|
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
while (1)
|
|
|
|
;
|
2019-09-02 11:41:24 +00:00
|
|
|
}
|
|
|
|
void BusFault_Handler()
|
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
while (1)
|
|
|
|
;
|
2019-09-02 11:41:24 +00:00
|
|
|
}
|
|
|
|
void UsageFault_Handler()
|
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
while (1)
|
|
|
|
;
|
2019-09-02 11:41:24 +00:00
|
|
|
}
|
2020-04-13 13:38:56 +00:00
|
|
|
void Error_Handler()
|
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|
2019-09-02 11:41:24 +00:00
|
|
|
void SVC_Handler() {}
|
|
|
|
void DebugMon_Handler() {}
|
|
|
|
void PendSV_Handler() {}
|
2019-08-30 11:07:08 +00:00
|
|
|
|
2020-04-13 13:38:56 +00:00
|
|
|
void SystemClock_Config(void)
|
|
|
|
{
|
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
|
|
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
|
|
|
|
|
|
|
|
/** Initializes the CPU, AHB and APB busses clocks
|
|
|
|
*/
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE;
|
|
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
|
|
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
|
|
|
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
|
|
|
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
|
|
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
|
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
/** Initializes the CPU, AHB and APB busses clocks
|
|
|
|
*/
|
|
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
|
|
|
|
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
|
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
|
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-02 11:41:24 +00:00
|
|
|
// called every 1ms
|
2020-04-13 13:38:56 +00:00
|
|
|
void SysTick_Handler(void)
|
2019-09-02 11:41:24 +00:00
|
|
|
{
|
2020-04-13 13:38:56 +00:00
|
|
|
HAL_IncTick();
|
2019-10-28 17:56:37 +00:00
|
|
|
ui.Poll();
|
2020-02-21 00:39:20 +00:00
|
|
|
system_clock.Tick();
|
2019-08-30 11:07:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-13 13:38:56 +00:00
|
|
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
|
2019-09-02 11:41:24 +00:00
|
|
|
{
|
2020-04-13 13:38:56 +00:00
|
|
|
if (htim != &htim2) {
|
2019-10-06 10:55:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-09-19 20:50:51 +00:00
|
|
|
|
2020-04-13 13:38:56 +00:00
|
|
|
static uint16_t count = 0;
|
2020-02-05 00:29:23 +00:00
|
|
|
count++;
|
2020-04-13 13:38:56 +00:00
|
|
|
if (count % (8000L / 24) == 0) {
|
|
|
|
// refresh display with 24fps
|
2020-02-05 00:29:23 +00:00
|
|
|
ui.Flush();
|
|
|
|
count = 0;
|
|
|
|
}
|
2019-09-19 20:50:51 +00:00
|
|
|
|
2020-01-03 21:09:11 +00:00
|
|
|
// write audiodac1
|
|
|
|
// write audiodac2
|
|
|
|
// write audiodac3
|
|
|
|
// write audiodac4
|
2019-09-19 14:41:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitTimers(void)
|
|
|
|
{
|
2020-04-13 13:38:56 +00:00
|
|
|
__HAL_RCC_TIM2_CLK_ENABLE();
|
|
|
|
htim2.Init.Period = F_CPU / (8000 * 1) - 1;
|
|
|
|
htim2.Init.Prescaler = 0;
|
|
|
|
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
|
|
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
|
|
htim2.Init.RepetitionCounter = 0;
|
2019-10-06 10:55:04 +00:00
|
|
|
//TIM_InternalClockConfig(TIM2);
|
2020-04-13 13:38:56 +00:00
|
|
|
HAL_TIM_Base_Init(&htim2);
|
|
|
|
HAL_TIM_Base_Start_IT(&htim2);
|
|
|
|
|
|
|
|
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); // 2.2 priority split.
|
|
|
|
HAL_NVIC_SetPriority(TIM2_IRQn, 0, 1);
|
|
|
|
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
2019-09-19 14:41:32 +00:00
|
|
|
}
|
2019-08-30 11:07:08 +00:00
|
|
|
|
2019-09-19 14:41:32 +00:00
|
|
|
void Init(void)
|
|
|
|
{
|
2020-04-13 13:38:56 +00:00
|
|
|
//NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);
|
|
|
|
hiwdg.Init.Prescaler = IWDG_PRESCALER_16;
|
|
|
|
//HAL_IWDG_Init(&hiwdg);
|
2019-08-20 19:27:35 +00:00
|
|
|
|
2019-10-06 10:55:04 +00:00
|
|
|
system_clock.Init();
|
2020-02-05 00:29:23 +00:00
|
|
|
|
|
|
|
//IWDG_Enable();
|
2019-10-06 10:55:04 +00:00
|
|
|
display.Init();
|
2019-10-28 17:56:37 +00:00
|
|
|
encoder.Init();
|
2019-10-06 10:55:04 +00:00
|
|
|
InitTimers();
|
2019-08-30 11:07:08 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 11:41:24 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
2020-04-13 13:38:56 +00:00
|
|
|
SystemInit();
|
|
|
|
SCB->VTOR = 0x8000;
|
|
|
|
HAL_DeInit();
|
|
|
|
HAL_Init();
|
|
|
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
SystemClock_Config();
|
2019-10-06 10:55:04 +00:00
|
|
|
Init();
|
2020-01-03 21:09:11 +00:00
|
|
|
|
2019-10-06 10:55:04 +00:00
|
|
|
while (1) {
|
|
|
|
// In this loop we do things that dont depend on any timing, but that have to be done.
|
|
|
|
// you should not write on spi here because that should happen in the TIM2 interrupt
|
2019-10-28 17:56:37 +00:00
|
|
|
// do we want to call the watchdog here? it's the only part thats getting interrupted after all
|
|
|
|
// (next to the interrupts themselves potentially interrupting each other)
|
|
|
|
ui.DoEvents();
|
2020-04-13 13:38:56 +00:00
|
|
|
HAL_IWDG_Refresh(&hiwdg);
|
2019-10-06 10:55:04 +00:00
|
|
|
}
|
2019-09-02 11:41:24 +00:00
|
|
|
}
|