mirror of
https://github.com/jhbruhn/eurorack.git
synced 2025-03-15 02:55:49 +00:00
Create Part class, think about output assignments
This commit is contained in:
parent
59424f01bb
commit
88916400d2
3 changed files with 109 additions and 93 deletions
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include "drivers/display.h"
|
||||
#include "drivers/gpio.h"
|
||||
#include "part.h"
|
||||
#include "stmlib/system/system_clock.h"
|
||||
#include "ui.h"
|
||||
#include "part.h"
|
||||
|
||||
using namespace stmlib;
|
||||
|
||||
|
@ -12,29 +12,30 @@ GPIO gpio;
|
|||
Display display;
|
||||
UI ui;
|
||||
//SystemClock system_clock;
|
||||
Part part[4];
|
||||
|
||||
// Default interrupt handlers.
|
||||
extern "C" {
|
||||
void NMI_Handler() {}
|
||||
void HardFault_Handler()
|
||||
{
|
||||
while (1)
|
||||
;
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
void MemManage_Handler()
|
||||
{
|
||||
while (1)
|
||||
;
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
void BusFault_Handler()
|
||||
{
|
||||
while (1)
|
||||
;
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
void UsageFault_Handler()
|
||||
{
|
||||
while (1)
|
||||
;
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
void SVC_Handler() {}
|
||||
void DebugMon_Handler() {}
|
||||
|
@ -43,87 +44,87 @@ void PendSV_Handler() {}
|
|||
// called every 1ms
|
||||
void SysTick_Handler()
|
||||
{
|
||||
IWDG_ReloadCounter();
|
||||
system_clock.Tick();
|
||||
IWDG_ReloadCounter();
|
||||
system_clock.Tick();
|
||||
}
|
||||
|
||||
void TIM2_IRQHandler(void)
|
||||
{
|
||||
if (TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) {
|
||||
return;
|
||||
}
|
||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
||||
if (TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) {
|
||||
return;
|
||||
}
|
||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
||||
|
||||
// this will get called with 192 kHz (foof)
|
||||
// we want to reduce the amount of times the ui gets polled to 1kHz
|
||||
// which still is a lot (60fps would be enough tbh)
|
||||
// this will get called with 192 kHz (foof)
|
||||
// we want to reduce the amount of times the ui gets polled to 1kHz
|
||||
// which still is a lot (60fps would be enough tbh)
|
||||
|
||||
static uint8_t count = 0;
|
||||
count++;
|
||||
if (count % 192 == 0) {
|
||||
ui.Flush();
|
||||
count = 0;
|
||||
}
|
||||
static uint8_t count = 0;
|
||||
count++;
|
||||
if (count % 192 == 0) {
|
||||
ui.Flush();
|
||||
count = 0;
|
||||
}
|
||||
|
||||
if (count % 48 == 0) { // write audiodac1
|
||||
}
|
||||
if (count % 48 == 1) { // write audiodac2
|
||||
}
|
||||
if (count % 48 == 2) { // write audiodac3
|
||||
}
|
||||
if (count % 48 == 3) { // write audiodac4
|
||||
}
|
||||
if (count % 48 == 0) { // write audiodac1
|
||||
}
|
||||
if (count % 48 == 1) { // write audiodac2
|
||||
}
|
||||
if (count % 48 == 2) { // write audiodac3
|
||||
}
|
||||
if (count % 48 == 3) { // write audiodac4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InitTimers(void)
|
||||
{
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||
TIM_TimeBaseInitTypeDef timer_init;
|
||||
timer_init.TIM_Period = F_CPU / (48000 * 4) - 1; // 192 kHz, 48kHz for each audio DAC
|
||||
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);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
|
||||
TIM_TimeBaseInitTypeDef timer_init;
|
||||
timer_init.TIM_Period = F_CPU / (48000 * 4) - 1; // 192 kHz, 48kHz for each audio DAC
|
||||
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);
|
||||
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2.2 priority split.
|
||||
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2.2 priority split.
|
||||
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
void Init(void)
|
||||
{
|
||||
//SystemInit();
|
||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);
|
||||
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
|
||||
IWDG_SetPrescaler(IWDG_Prescaler_16);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
||||
SystemInit();
|
||||
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);
|
||||
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
|
||||
IWDG_SetPrescaler(IWDG_Prescaler_16);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
|
||||
|
||||
system_clock.Init();
|
||||
SysTick_Config(F_CPU / 8000);
|
||||
IWDG_Enable();
|
||||
gpio.Init();
|
||||
// asm("bkpt #0");
|
||||
display.Init();
|
||||
InitTimers();
|
||||
system_clock.Init();
|
||||
SysTick_Config(F_CPU / 8000);
|
||||
IWDG_Enable();
|
||||
gpio.Init();
|
||||
// asm("bkpt #0");
|
||||
display.Init();
|
||||
InitTimers();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Init();
|
||||
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
|
||||
ui.Update();
|
||||
}
|
||||
Init();
|
||||
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
|
||||
ui.Update();
|
||||
}
|
||||
}
|
||||
|
|
BIN
midi2cv/output_assignment.ods
Normal file
BIN
midi2cv/output_assignment.ods
Normal file
Binary file not shown.
|
@ -5,50 +5,65 @@ enum MIDIThruMode { OFF,
|
|||
ON,
|
||||
POLYCHAIN };
|
||||
|
||||
enum BiOutputMode {
|
||||
PITCH_UNI,
|
||||
PITCH_BI,
|
||||
SAWTOOTH,
|
||||
SQUARE,
|
||||
SINE,
|
||||
TRIANGLE
|
||||
enum BiOutputType {
|
||||
BI_OFF = 0,
|
||||
BI_PITCH_UNI,
|
||||
BI_PITCH_BI,
|
||||
BI_SAWTOOTH,
|
||||
BI_SQUARE,
|
||||
BI_SINE,
|
||||
BI_TRIANGLE
|
||||
};
|
||||
|
||||
enum UniOutputMode {
|
||||
PITCH,
|
||||
VELOCITY,
|
||||
AFTERTOUCH
|
||||
enum UniOutputType {
|
||||
UNI_OFF = 0,
|
||||
UNI_PITCH,
|
||||
UNI_VELOCITY,
|
||||
UNI_MODULATION,
|
||||
UNI_AFTERTOUCH,
|
||||
UNI_BREATH,
|
||||
UNI_EXP,
|
||||
UNI_GATE
|
||||
};
|
||||
|
||||
enum GateOutputMode {
|
||||
GATE,
|
||||
TRIGGER
|
||||
enum GateOutputType {
|
||||
GATE_OFF = 0,
|
||||
GATE_GATE,
|
||||
GATE_TRIGGER
|
||||
};
|
||||
|
||||
class Part {
|
||||
public:
|
||||
Part()
|
||||
: voice_count(1)
|
||||
: poly_voice_count(1)
|
||||
, output_column_count(1)
|
||||
, midi_filter_channel_enabled(true)
|
||||
, midi_filter_channel(1)
|
||||
, midi_filter_lowest_note(0)
|
||||
, midi_filter_highest_note(127)
|
||||
, 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 */);
|
||||
|
||||
private:
|
||||
uint8_t voice_count;
|
||||
uint8_t poly_voice_count;
|
||||
uint8_t output_column_count;
|
||||
bool midi_filter_channel_enabled;
|
||||
uint8_t midi_filter_channel;
|
||||
uint8_t midi_filter_lowest_note;
|
||||
uint8_t midi_filter_highest_note;
|
||||
MIDIThruMode midi_thru_mode;
|
||||
BiOutputMode output_mode_0;
|
||||
UniOutputMode output_mode_1;
|
||||
UniOutputMode output_mode_2;
|
||||
GateOutputMode output_mode_3;
|
||||
BiOutputType output_type_row_0[4];
|
||||
UniOutputType output_type_row_1[4];
|
||||
UniOutputType output_type_row_2[4];
|
||||
GateOutputType output_type_row_3[4];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue