add button basics

This commit is contained in:
PoliEcho 2026-04-24 16:17:59 +02:00
parent 65516b2bff
commit 061ca37ad7
4 changed files with 36 additions and 0 deletions

28
buttons.c Normal file
View File

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

3
buttons.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#include <pico/types.h>
void handle_vco_change(uint gpio, uint32_t events);

View File

@ -16,3 +16,4 @@
#define SAMPLE_RATE 44100.0f #define SAMPLE_RATE 44100.0f
#define otherwise else

View File

@ -1,3 +1,4 @@
#include "buttons.h"
#include "macro.h" #include "macro.h"
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include <hardware/gpio.h> #include <hardware/gpio.h>
@ -36,6 +37,9 @@ void init_all() {
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_set_irq_enabled_with_callback(VCO_BUTTON, GPIO_IRQ_EDGE_RISE, true, &handle_vco_change);
} }
daisysp::Oscillator osc; daisysp::Oscillator osc;