fix BPM, fix gates not closing, add experimental clk in
This commit is contained in:
parent
83900d0711
commit
5e500086f0
5 changed files with 99 additions and 33 deletions
|
|
@ -38,6 +38,7 @@ class DisplayHandler {
|
||||||
bool onOutScreen = false;
|
bool onOutScreen = false;
|
||||||
bool onMainScreen = true;
|
bool onMainScreen = true;
|
||||||
bool onSettingsScreen = false;
|
bool onSettingsScreen = false;
|
||||||
|
bool engageBPM = false;
|
||||||
|
|
||||||
std::array<std::string, 6> settings = {
|
std::array<std::string, 6> settings = {
|
||||||
"Save",
|
"Save",
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ static constexpr uint8_t OUT_6_PIN = 10;
|
||||||
static constexpr uint8_t OUT_7_PIN = 12;
|
static constexpr uint8_t OUT_7_PIN = 12;
|
||||||
static constexpr uint8_t OUT_8_PIN = 14;
|
static constexpr uint8_t OUT_8_PIN = 14;
|
||||||
|
|
||||||
|
static constexpr uint8_t IN_CLK_PIN = 16;
|
||||||
static constexpr uint8_t IN_RUN_PIN = 17;
|
static constexpr uint8_t IN_RUN_PIN = 17;
|
||||||
|
|
||||||
static constexpr uint8_t SCREEN_SCL_PIN = 18;
|
static constexpr uint8_t SCREEN_SCL_PIN = 18;
|
||||||
|
|
@ -44,6 +45,9 @@ extern volatile bool RUN;
|
||||||
extern volatile uint8_t EXTPPQNIdx;
|
extern volatile uint8_t EXTPPQNIdx;
|
||||||
#define PPQN_OPTS_LEN 5
|
#define PPQN_OPTS_LEN 5
|
||||||
extern const uint16_t PPQNOPTS[PPQN_OPTS_LEN];
|
extern const uint16_t PPQNOPTS[PPQN_OPTS_LEN];
|
||||||
|
extern volatile uint64_t last_clk_us;
|
||||||
|
extern volatile uint64_t last_valid_clk_us;
|
||||||
|
extern volatile bool EXTERNAL_CLOCK;
|
||||||
|
|
||||||
enum WaveShape { SQUARE, TRIANGLE, SAW, RAMP, EXP, HALFSINE, REXP, LOG, SINE, BOUNCE, SIGMO, WOBBLE, STEPDW, STEPUP, SH, SHAPE_COUNT};
|
enum WaveShape { SQUARE, TRIANGLE, SAW, RAMP, EXP, HALFSINE, REXP, LOG, SINE, BOUNCE, SIGMO, WOBBLE, STEPDW, STEPUP, SH, SHAPE_COUNT};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -258,22 +258,32 @@ void DisplayHandler::handleClickOnOutputScreen() {
|
||||||
|
|
||||||
|
|
||||||
void DisplayHandler::handleClickOnMainScreen() {
|
void DisplayHandler::handleClickOnMainScreen() {
|
||||||
if (cursorPosition > 0 && cursorPosition < 9) { // GO TO OUTPUT
|
if (cursorPosition == 0) {
|
||||||
|
if (engageBPM) {
|
||||||
|
cursorClick = 0;
|
||||||
|
engageBPM = false;
|
||||||
|
} else {
|
||||||
|
engageBPM = true;
|
||||||
|
cursorClick = 1;
|
||||||
|
}
|
||||||
|
} if (cursorPosition > 0 && cursorPosition < 9) { // GO TO OUTPUT
|
||||||
currentOut = cursorPosition - 1;
|
currentOut = cursorPosition - 1;
|
||||||
cursorPosition = 1;
|
cursorPosition = 1;
|
||||||
currentScreen = 1;
|
currentScreen = 1;
|
||||||
onOutScreen = true;
|
onOutScreen = true;
|
||||||
onMainScreen = false;
|
onMainScreen = false;
|
||||||
onSettingsScreen = false;;
|
onSettingsScreen = false;
|
||||||
|
cursorClick = 0;
|
||||||
} else if (cursorPosition == 9) { // PLAY/PAUSE BUTTON
|
} else if (cursorPosition == 9) { // PLAY/PAUSE BUTTON
|
||||||
PLAY ^= true;
|
PLAY ^= true;
|
||||||
|
cursorClick = 0;
|
||||||
} else if (cursorPosition == 10) { // GLOBAL SETTINGS
|
} else if (cursorPosition == 10) { // GLOBAL SETTINGS
|
||||||
cursorPosition = 0;
|
cursorPosition = 0;
|
||||||
onSettingsScreen = true;
|
onSettingsScreen = true;
|
||||||
onMainScreen = false;
|
onMainScreen = false;
|
||||||
onOutScreen = false;
|
onOutScreen = false;
|
||||||
}
|
|
||||||
cursorClick = 0;
|
cursorClick = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,10 @@ void Gate::update() {
|
||||||
|
|
||||||
if (elapsedUs >= pulseDurationUs) {
|
if (elapsedUs >= pulseDurationUs) {
|
||||||
state = 0;
|
state = 0;
|
||||||
|
if (width < 100) {
|
||||||
|
scheduledTick = 0xFFFFFFFF;
|
||||||
|
lastTriggerTick = 0xFFFFFFFF;
|
||||||
|
}
|
||||||
if (!sticky)
|
if (!sticky)
|
||||||
writeAnalog(0);
|
writeAnalog(0);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
49
src/main.cpp
49
src/main.cpp
|
|
@ -7,6 +7,8 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <hardware/gpio.h>
|
#include <hardware/gpio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <pico/types.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "DisplayHandler.h"
|
#include "DisplayHandler.h"
|
||||||
|
|
@ -26,6 +28,9 @@ volatile uint32_t MASTER_TICK;
|
||||||
volatile bool RUN = false;
|
volatile bool RUN = false;
|
||||||
const uint16_t PPQNOPTS[] = {1, 2, 4, 24, 48};
|
const uint16_t PPQNOPTS[] = {1, 2, 4, 24, 48};
|
||||||
volatile uint8_t EXTPPQNIdx = 0;
|
volatile uint8_t EXTPPQNIdx = 0;
|
||||||
|
volatile uint64_t last_clk_us = 0;
|
||||||
|
volatile uint64_t last_valid_clk_us;
|
||||||
|
volatile bool EXTERNAL_CLOCK = false;
|
||||||
|
|
||||||
ModMatrix matrix;
|
ModMatrix matrix;
|
||||||
|
|
||||||
|
|
@ -75,6 +80,12 @@ void update_BPM(bool up) {
|
||||||
for (auto g : outputs) {
|
for (auto g : outputs) {
|
||||||
g->setWidth(g->width);
|
g->setWidth(g->width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!EXTERNAL_CLOCK) {
|
||||||
|
init_timer(period_us);
|
||||||
|
} else {
|
||||||
|
cancel_repeating_timer(&bpm_timer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void core1_entry() {
|
void core1_entry() {
|
||||||
|
|
@ -130,6 +141,35 @@ void handle_outs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void gpio_callback(uint gpio, uint32_t events) {
|
void gpio_callback(uint gpio, uint32_t events) {
|
||||||
|
// CLK LOGIC
|
||||||
|
if (gpio == IN_CLK_PIN && (events & GPIO_IRQ_EDGE_RISE)) {
|
||||||
|
uint64_t now = to_us_since_boot(get_absolute_time());
|
||||||
|
|
||||||
|
if (now - last_valid_clk_us < 5000) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
last_valid_clk_us = now;
|
||||||
|
|
||||||
|
uint16_t incomingPPQN;
|
||||||
|
if (last_clk_us > 0) {
|
||||||
|
uint64_t diff = now - last_clk_us;
|
||||||
|
incomingPPQN = PPQNOPTS[EXTPPQNIdx];
|
||||||
|
float calculatedBPM = 60000000.0f / (float)(diff * incomingPPQN);
|
||||||
|
|
||||||
|
if (calculatedBPM >= 30 && calculatedBPM <= 255) {
|
||||||
|
if (fabsf((float)BPM - calculatedBPM) > 0.5f) {
|
||||||
|
BPM = (uint8_t)(calculatedBPM + 0.5f);
|
||||||
|
|
||||||
|
update_period();
|
||||||
|
for (auto g : outputs) {
|
||||||
|
g->setWidth(g->width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MASTER_TICK += (PPQN / incomingPPQN);
|
||||||
|
last_clk_us = now;
|
||||||
|
}
|
||||||
|
|
||||||
if (gpio == IN_RUN_PIN) {
|
if (gpio == IN_RUN_PIN) {
|
||||||
if (RUN) {
|
if (RUN) {
|
||||||
|
|
@ -156,9 +196,16 @@ void setup_ins() {
|
||||||
gpio_init(IN_RUN_PIN);
|
gpio_init(IN_RUN_PIN);
|
||||||
gpio_set_dir(IN_RUN_PIN, GPIO_IN);
|
gpio_set_dir(IN_RUN_PIN, GPIO_IN);
|
||||||
gpio_pull_down(IN_RUN_PIN);
|
gpio_pull_down(IN_RUN_PIN);
|
||||||
gpio_set_irq_enabled_with_callback(IN_RUN_PIN, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, &gpio_callback);
|
gpio_set_irq_enabled_with_callback(IN_RUN_PIN,
|
||||||
|
GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL,
|
||||||
|
true, &gpio_callback);
|
||||||
|
|
||||||
// SETUP CLOCK
|
// SETUP CLOCK
|
||||||
|
gpio_init(IN_CLK_PIN);
|
||||||
|
gpio_set_dir(IN_CLK_PIN, GPIO_IN);
|
||||||
|
gpio_pull_down(IN_CLK_PIN);
|
||||||
|
// Add to existing callback
|
||||||
|
gpio_set_irq_enabled(IN_CLK_PIN, GPIO_IRQ_EDGE_RISE, true);
|
||||||
|
|
||||||
// SETUP CV INS
|
// SETUP CV INS
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue