2019-09-07 19:47:43 +00:00
|
|
|
#include <stm32f37x_conf.h>
|
2019-08-20 19:27:35 +00:00
|
|
|
|
2019-09-02 11:41:24 +00:00
|
|
|
#include "drivers/display.h"
|
2019-10-28 17:56:37 +00:00
|
|
|
#include "drivers/encoder.h"
|
2019-08-30 09:15:00 +00:00
|
|
|
#include "drivers/gpio.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"
|
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
|
|
|
|
|
|
|
using namespace stmlib;
|
|
|
|
|
2019-08-30 09:15:00 +00:00
|
|
|
GPIO gpio;
|
2019-09-02 11:41:24 +00:00
|
|
|
Display display;
|
2019-10-28 17:56:37 +00:00
|
|
|
Encoder encoder;
|
|
|
|
|
2019-09-19 14:41:32 +00:00
|
|
|
UI ui;
|
2019-10-14 21:51:38 +00:00
|
|
|
Part part[PART_COUNT];
|
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
|
|
|
}
|
|
|
|
void SVC_Handler() {}
|
|
|
|
void DebugMon_Handler() {}
|
|
|
|
void PendSV_Handler() {}
|
2019-08-30 11:07:08 +00:00
|
|
|
|
2019-09-02 11:41:24 +00:00
|
|
|
// called every 1ms
|
|
|
|
void SysTick_Handler()
|
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
IWDG_ReloadCounter();
|
|
|
|
system_clock.Tick();
|
2019-10-28 17:56:37 +00:00
|
|
|
ui.Poll();
|
2019-08-30 11:07:08 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 14:41:32 +00:00
|
|
|
void TIM2_IRQHandler(void)
|
2019-09-02 11:41:24 +00:00
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
if (TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
2019-09-19 20:50:51 +00:00
|
|
|
|
2020-01-03 21:09:11 +00:00
|
|
|
// this will get called with 8kHz (foof)
|
2019-10-06 10:55:04 +00:00
|
|
|
// which still is a lot (60fps would be enough tbh)
|
2020-02-05 00:29:23 +00:00
|
|
|
static uint8_t count = 0;
|
|
|
|
count++;
|
|
|
|
if (count % (192 * 2) == 0) {
|
|
|
|
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)
|
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
|
|
|
TIM_TimeBaseInitTypeDef timer_init;
|
2020-02-05 00:29:23 +00:00
|
|
|
timer_init.TIM_Period = F_CPU / (48000 * 4) - 1;
|
2019-10-06 10:55:04 +00:00
|
|
|
timer_init.TIM_Prescaler = 0;
|
|
|
|
timer_init.TIM_ClockDivision = TIM_CKD_DIV1;
|
|
|
|
timer_init.TIM_CounterMode = TIM_CounterMode_Up;
|
|
|
|
timer_init.TIM_RepetitionCounter = 0;
|
|
|
|
//TIM_InternalClockConfig(TIM2);
|
|
|
|
TIM_TimeBaseInit(TIM2, &timer_init);
|
|
|
|
TIM_Cmd(TIM2, ENABLE);
|
2019-08-30 11:07:08 +00:00
|
|
|
|
2019-10-06 10:55:04 +00:00
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2.2 priority split.
|
2019-08-30 11:07:08 +00:00
|
|
|
|
2019-10-06 10:55:04 +00:00
|
|
|
// DAC interrupt is given highest priority
|
|
|
|
NVIC_InitTypeDef timer_interrupt;
|
|
|
|
timer_interrupt.NVIC_IRQChannel = TIM2_IRQn;
|
|
|
|
timer_interrupt.NVIC_IRQChannelPreemptionPriority = 0;
|
|
|
|
timer_interrupt.NVIC_IRQChannelSubPriority = 1;
|
|
|
|
timer_interrupt.NVIC_IRQChannelCmd = ENABLE;
|
|
|
|
NVIC_Init(&timer_interrupt);
|
|
|
|
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
|
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)
|
|
|
|
{
|
2019-10-06 10:55:04 +00:00
|
|
|
SystemInit();
|
|
|
|
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);
|
|
|
|
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
|
|
|
|
IWDG_SetPrescaler(IWDG_Prescaler_16);
|
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
2019-08-20 19:27:35 +00:00
|
|
|
|
2019-10-06 10:55:04 +00:00
|
|
|
system_clock.Init();
|
|
|
|
SysTick_Config(F_CPU / 8000);
|
2020-02-05 00:29:23 +00:00
|
|
|
|
|
|
|
//IWDG_Enable();
|
2019-10-06 10:55:04 +00:00
|
|
|
gpio.Init();
|
|
|
|
display.Init();
|
2019-10-28 17:56:37 +00:00
|
|
|
encoder.Init();
|
|
|
|
ui.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)
|
|
|
|
{
|
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();
|
2019-10-06 10:55:04 +00:00
|
|
|
}
|
2019-09-02 11:41:24 +00:00
|
|
|
}
|