Made buttons work

This commit is contained in:
Tom-on64 2026-04-24 16:30:50 +02:00
parent 061ca37ad7
commit d5933cd060
2 changed files with 12 additions and 25 deletions

View File

@ -4,25 +4,18 @@
#include <pico/types.h> #include <pico/types.h>
#include "hardware/gpio.h" #include "hardware/gpio.h"
void handle_vco_change(uint gpio, uint32_t events) { void handle_vco_change(uint gpio, uint32_t events) {
if (gpio == VCO_BUTTON && (events & GPIO_IRQ_EDGE_RISE)) { if (gpio == VCO_BUTTON && (events & GPIO_IRQ_EDGE_RISE)) {
if (state.vco_mode == VCO_SAW) { if (state.vco_mode == VCO_SAW) state.vco_mode = VCO_SINE;
state.vco_mode = VCO_SINE; otherwise state.vco_mode++;
} otherwise { }
state.vco_mode++;
}
}
} }
void update_button(uint pin, bool *button_state) { void update_button(uint pin, bool *button_state) {
if(gpio_get(pin) != *button_state) { if(gpio_get(pin) != *button_state) *button_state = !*button_state;
*button_state=!*button_state;
}
} }
void update_buttons() { void update_buttons() {
update_button(QUANT_BUTTON,&state.quant_enabled); update_button(QUANT_BUTTON, &state.quant_enabled);
update_button(AMEN_BUTTON, &state.amen_enabled);
} }

14
main.cc
View File

@ -10,7 +10,6 @@
#include "hardware/pwm.h" #include "hardware/pwm.h"
#include "hardware/adc.h" #include "hardware/adc.h"
#include "state.h" #include "state.h"
#include "daisysp.h"
state_t state; state_t state;
@ -34,23 +33,18 @@ void init_all() {
} }
adc_init(); adc_init();
for (uint8_t i=0; i < ARRAY_LENGTH(adc_gpio); i++) { for (uint8_t i=0; i < ARRAY_LENGTH(adc_gpio); i++) {
adc_gpio_init(adc_gpio[i]); adc_gpio_init(adc_gpio[i]);
adc_select_input(i); adc_select_input(i);
} }
gpio_pull_down(VCO_BUTTON); gpio_pull_down(VCO_BUTTON);
gpio_set_irq_enabled_with_callback(VCO_BUTTON, GPIO_IRQ_EDGE_RISE, true, &handle_vco_change); gpio_set_irq_enabled_with_callback(VCO_BUTTON, GPIO_IRQ_EDGE_RISE, true, &handle_vco_change);
} }
daisysp::Oscillator osc;
__attribute__((noreturn)) __attribute__((noreturn))
int main() { int main() {
init_all(); init_all();
osc.Init(SAMPLE_RATE); while (1) {}
while (1) {
osc.SetFreq(state.vco_freq * 1760);
}
} }