fix input pots and amen break
This commit is contained in:
Vendored
+7
-17
@@ -1,28 +1,18 @@
|
|||||||
{
|
{
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "Cortex Debug",
|
"name": "Cortex Debug (Pico 2W / RP2350)",
|
||||||
"cwd": "${workspaceRoot}",
|
"cwd": "${workspaceRoot}",
|
||||||
"executable": "${command:cmake.launchTargetPath}",
|
"executable": "${workspaceRoot}/build/sint-gauntlet.elf",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "cortex-debug",
|
"type": "cortex-debug",
|
||||||
"servertype": "openocd",
|
"servertype": "external",
|
||||||
"gdbPath": "gdb-multiarch",
|
"gdbPath": "arm-none-eabi-gdb",
|
||||||
"serverArgs": [
|
"gdbTarget": "localhost:3333",
|
||||||
|
"device": "RP2350",
|
||||||
],
|
"svdFile": "${env:PICO_SDK_PATH}/src/rp2350/hardware_regs/rp2350.svd",
|
||||||
"device": "RP2040",
|
|
||||||
"configFiles": [
|
|
||||||
"interface/raspberrypi-swd.cfg",
|
|
||||||
"target/rp2040.cfg"
|
|
||||||
],
|
|
||||||
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
|
|
||||||
"runToEntryPoint": "main",
|
"runToEntryPoint": "main",
|
||||||
// Give restart the same functionality as runToEntryPoint - main
|
|
||||||
"postRestartCommands": [
|
"postRestartCommands": [
|
||||||
"break main",
|
"break main",
|
||||||
"continue"
|
"continue"
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#include <hardware/adc.h>
|
#include <hardware/adc.h>
|
||||||
#include <hardware/gpio.h>
|
#include <hardware/gpio.h>
|
||||||
|
#include <math.h>
|
||||||
#include <pico/stdlib.h>
|
#include <pico/stdlib.h>
|
||||||
#include <pico/time.h>
|
#include <pico/time.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <math.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
bool is_toggle[BUTTON_COUNT] = { false };
|
bool is_toggle[BUTTON_COUNT] = {false};
|
||||||
bool btn_prev[BUTTON_COUNT] = { false };
|
bool btn_prev[BUTTON_COUNT] = {false};
|
||||||
|
|
||||||
void set_mux_addr(uint8_t addr) {
|
void set_mux_addr(uint8_t addr) {
|
||||||
gpio_put(MUX_S0, addr & 1);
|
gpio_put(MUX_S0, addr & 1);
|
||||||
@@ -19,30 +19,54 @@ void set_mux_addr(uint8_t addr) {
|
|||||||
gpio_put(MUX_S2, (addr >> 2) & 1);
|
gpio_put(MUX_S2, (addr >> 2) & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_inputs(input_t* input) {
|
void update_pot(input_t *input) {
|
||||||
// Pots
|
static volatile uint function_call_counter = 0;
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
function_call_counter++;
|
||||||
set_mux_addr(i);
|
static uint8_t i = 0;
|
||||||
sleep_us(50); // Let multiplexers multiplex
|
for (; i < 2; i++, adc_select_input(i)) {
|
||||||
for (uint8_t j = 0; j < 2; j++) {
|
{
|
||||||
adc_select_input(j);
|
static uint8_t j = 0;
|
||||||
float old_val = input->pots[i + j * 8];
|
for (; j < 8;) {
|
||||||
|
set_mux_addr(j);
|
||||||
|
sleep_ms(5); // Let multiplexers multiplex (5ms smallest reliable delay)
|
||||||
|
float old_val = input->pots[j + i * 8];
|
||||||
float new_val = (float)adc_read() / 4096.0f;
|
float new_val = (float)adc_read() / 4096.0f;
|
||||||
if (fabs(new_val - old_val) >= 0.01f) input->pots[i + j * 8] = new_val;
|
|
||||||
|
if (!(new_val > 0.99f) && (fabs(new_val - old_val) >= 0.01f)) {
|
||||||
|
|
||||||
|
input->pots[j + i * 8] = new_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
j++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
j = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
i = 0;
|
||||||
|
adc_select_input(i);
|
||||||
|
sleep_ms(5);
|
||||||
|
update_pot(input); // dont skip the tick
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_inputs(input_t *input) {
|
||||||
|
|
||||||
|
// Pots
|
||||||
|
update_pot(input);
|
||||||
|
__asm__("nop");
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
for (uint8_t i = 0; i < BUTTON_COUNT; i++) {
|
for (uint8_t i = 0; i < BUTTON_COUNT; i++) {
|
||||||
bool btn_curr = gpio_get(BUTTON_BASE + i);
|
bool btn_curr = gpio_get(BUTTON_BASE + i);
|
||||||
|
|
||||||
if (btn_curr == true && btn_prev[i] == false) {
|
if (btn_curr == true && btn_prev[i] == false) {
|
||||||
if (is_toggle[i]) input->buttons[i] = !input->buttons[i];
|
if (is_toggle[i])
|
||||||
|
input->buttons[i] = !input->buttons[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_toggle[i]) input->buttons[i] = btn_curr;
|
if (!is_toggle[i])
|
||||||
|
input->buttons[i] = btn_curr;
|
||||||
|
|
||||||
btn_prev[i] = btn_curr;
|
btn_prev[i] = btn_curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ void update_state(state_t* state, input_t* input) {
|
|||||||
else state->vco_freq = quantize(state->vco_freq);
|
else state->vco_freq = quantize(state->vco_freq);
|
||||||
}
|
}
|
||||||
|
|
||||||
// state->amen_enabled = input->buttons[2];
|
state->amen_enabled = input->buttons[2];
|
||||||
state->amen_enabled = true;
|
//state->amen_enabled = true;
|
||||||
|
|
||||||
state->beat_samples = SAMPLE_RATE * 60.0f / state->clock_bpm;
|
state->beat_samples = SAMPLE_RATE * 60.0f / state->clock_bpm;
|
||||||
state->playback_rate = state->clock_bpm / AMEN_BPM;
|
state->playback_rate = state->clock_bpm / AMEN_BPM;
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ float get_sample(void) {
|
|||||||
|
|
||||||
float vco_env_out = vco_env.Process();
|
float vco_env_out = vco_env.Process();
|
||||||
float filter_env_out = filter_env.Process();
|
float filter_env_out = filter_env.Process();
|
||||||
|
// make it emit only continuous tone
|
||||||
|
// float vco_env_out = 1.0f;
|
||||||
|
// float filter_env_out = 0.0f;
|
||||||
|
|
||||||
osc.SetFreq(state->vco_freq);
|
osc.SetFreq(state->vco_freq);
|
||||||
osc.SetWaveform(vco_mode_to_daisy(state->vco_mode));
|
osc.SetWaveform(vco_mode_to_daisy(state->vco_mode));
|
||||||
|
|||||||
Reference in New Issue
Block a user