Create Part class, think about output assignments

This commit is contained in:
Jan-Henrik 2019-10-06 12:55:04 +02:00
parent 59424f01bb
commit 88916400d2
3 changed files with 109 additions and 93 deletions

View file

@ -2,9 +2,9 @@
#include "drivers/display.h" #include "drivers/display.h"
#include "drivers/gpio.h" #include "drivers/gpio.h"
#include "part.h"
#include "stmlib/system/system_clock.h" #include "stmlib/system/system_clock.h"
#include "ui.h" #include "ui.h"
#include "part.h"
using namespace stmlib; using namespace stmlib;
@ -12,29 +12,30 @@ GPIO gpio;
Display display; Display display;
UI ui; UI ui;
//SystemClock system_clock; //SystemClock system_clock;
Part part[4];
// Default interrupt handlers. // Default interrupt handlers.
extern "C" { extern "C" {
void NMI_Handler() {} void NMI_Handler() {}
void HardFault_Handler() void HardFault_Handler()
{ {
while (1) while (1)
; ;
} }
void MemManage_Handler() void MemManage_Handler()
{ {
while (1) while (1)
; ;
} }
void BusFault_Handler() void BusFault_Handler()
{ {
while (1) while (1)
; ;
} }
void UsageFault_Handler() void UsageFault_Handler()
{ {
while (1) while (1)
; ;
} }
void SVC_Handler() {} void SVC_Handler() {}
void DebugMon_Handler() {} void DebugMon_Handler() {}
@ -43,87 +44,87 @@ void PendSV_Handler() {}
// called every 1ms // called every 1ms
void SysTick_Handler() void SysTick_Handler()
{ {
IWDG_ReloadCounter(); IWDG_ReloadCounter();
system_clock.Tick(); system_clock.Tick();
} }
void TIM2_IRQHandler(void) void TIM2_IRQHandler(void)
{ {
if (TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) { if (TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) {
return; return;
} }
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
// this will get called with 192 kHz (foof) // this will get called with 192 kHz (foof)
// we want to reduce the amount of times the ui gets polled to 1kHz // we want to reduce the amount of times the ui gets polled to 1kHz
// which still is a lot (60fps would be enough tbh) // which still is a lot (60fps would be enough tbh)
static uint8_t count = 0; static uint8_t count = 0;
count++; count++;
if (count % 192 == 0) { if (count % 192 == 0) {
ui.Flush(); ui.Flush();
count = 0; count = 0;
} }
if (count % 48 == 0) { // write audiodac1 if (count % 48 == 0) { // write audiodac1
} }
if (count % 48 == 1) { // write audiodac2 if (count % 48 == 1) { // write audiodac2
} }
if (count % 48 == 2) { // write audiodac3 if (count % 48 == 2) { // write audiodac3
} }
if (count % 48 == 3) { // write audiodac4 if (count % 48 == 3) { // write audiodac4
} }
} }
} }
void InitTimers(void) void InitTimers(void)
{ {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseInitTypeDef timer_init; TIM_TimeBaseInitTypeDef timer_init;
timer_init.TIM_Period = F_CPU / (48000 * 4) - 1; // 192 kHz, 48kHz for each audio DAC timer_init.TIM_Period = F_CPU / (48000 * 4) - 1; // 192 kHz, 48kHz for each audio DAC
timer_init.TIM_Prescaler = 0; timer_init.TIM_Prescaler = 0;
timer_init.TIM_ClockDivision = TIM_CKD_DIV1; timer_init.TIM_ClockDivision = TIM_CKD_DIV1;
timer_init.TIM_CounterMode = TIM_CounterMode_Up; timer_init.TIM_CounterMode = TIM_CounterMode_Up;
timer_init.TIM_RepetitionCounter = 0; timer_init.TIM_RepetitionCounter = 0;
//TIM_InternalClockConfig(TIM2); //TIM_InternalClockConfig(TIM2);
TIM_TimeBaseInit(TIM2, &timer_init); TIM_TimeBaseInit(TIM2, &timer_init);
TIM_Cmd(TIM2, ENABLE); TIM_Cmd(TIM2, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2.2 priority split. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2.2 priority split.
// DAC interrupt is given highest priority // DAC interrupt is given highest priority
NVIC_InitTypeDef timer_interrupt; NVIC_InitTypeDef timer_interrupt;
timer_interrupt.NVIC_IRQChannel = TIM2_IRQn; timer_interrupt.NVIC_IRQChannel = TIM2_IRQn;
timer_interrupt.NVIC_IRQChannelPreemptionPriority = 0; timer_interrupt.NVIC_IRQChannelPreemptionPriority = 0;
timer_interrupt.NVIC_IRQChannelSubPriority = 1; timer_interrupt.NVIC_IRQChannelSubPriority = 1;
timer_interrupt.NVIC_IRQChannelCmd = ENABLE; timer_interrupt.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&timer_interrupt); NVIC_Init(&timer_interrupt);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
} }
void Init(void) void Init(void)
{ {
//SystemInit(); SystemInit();
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000); NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
IWDG_SetPrescaler(IWDG_Prescaler_16); IWDG_SetPrescaler(IWDG_Prescaler_16);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
system_clock.Init(); system_clock.Init();
SysTick_Config(F_CPU / 8000); SysTick_Config(F_CPU / 8000);
IWDG_Enable(); IWDG_Enable();
gpio.Init(); gpio.Init();
// asm("bkpt #0"); // asm("bkpt #0");
display.Init(); display.Init();
InitTimers(); InitTimers();
} }
int main(void) int main(void)
{ {
Init(); Init();
while (1) { while (1) {
// In this loop we do things that dont depend on any timing, but that have to be done. // 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 // you should not write on spi here because that should happen in the TIM2 interrupt
ui.Update(); ui.Update();
} }
} }

Binary file not shown.

View file

@ -5,50 +5,65 @@ enum MIDIThruMode { OFF,
ON, ON,
POLYCHAIN }; POLYCHAIN };
enum BiOutputMode { enum BiOutputType {
PITCH_UNI, BI_OFF = 0,
PITCH_BI, BI_PITCH_UNI,
SAWTOOTH, BI_PITCH_BI,
SQUARE, BI_SAWTOOTH,
SINE, BI_SQUARE,
TRIANGLE BI_SINE,
BI_TRIANGLE
}; };
enum UniOutputMode { enum UniOutputType {
PITCH, UNI_OFF = 0,
VELOCITY, UNI_PITCH,
AFTERTOUCH UNI_VELOCITY,
UNI_MODULATION,
UNI_AFTERTOUCH,
UNI_BREATH,
UNI_EXP,
UNI_GATE
}; };
enum GateOutputMode { enum GateOutputType {
GATE, GATE_OFF = 0,
TRIGGER GATE_GATE,
GATE_TRIGGER
}; };
class Part { class Part {
public: public:
Part() Part()
: voice_count(1) : poly_voice_count(1)
, output_column_count(1)
, midi_filter_channel_enabled(true) , midi_filter_channel_enabled(true)
, midi_filter_channel(1) , midi_filter_channel(1)
, midi_filter_lowest_note(0)
, midi_filter_highest_note(127)
, midi_thru_mode(OFF) , midi_thru_mode(OFF)
, output_mode_0(PITCH_UNI)
, output_mode_1(VELOCITY)
, output_mode_2(AFTERTOUCH)
, output_mode_3(GATE)
{ {
for (int i = 0; i < 4; i++) {
output_type_row_0[i] = BI_OFF;
output_type_row_1[i] = UNI_OFF;
output_type_row_2[i] = UNI_OFF;
output_type_row_3[i] = GATE_OFF;
}
} }
void ProcessMidiInput(/* TODO: Inputs */); void ProcessMidiInput(/* TODO: Inputs */);
private: private:
uint8_t voice_count; uint8_t poly_voice_count;
uint8_t output_column_count;
bool midi_filter_channel_enabled; bool midi_filter_channel_enabled;
uint8_t midi_filter_channel; uint8_t midi_filter_channel;
uint8_t midi_filter_lowest_note;
uint8_t midi_filter_highest_note;
MIDIThruMode midi_thru_mode; MIDIThruMode midi_thru_mode;
BiOutputMode output_mode_0; BiOutputType output_type_row_0[4];
UniOutputMode output_mode_1; UniOutputType output_type_row_1[4];
UniOutputMode output_mode_2; UniOutputType output_type_row_2[4];
GateOutputMode output_mode_3; GateOutputType output_type_row_3[4];
}; };
#endif #endif