diff --git a/buttons.c b/buttons.c new file mode 100644 index 0000000..5215dc0 --- /dev/null +++ b/buttons.c @@ -0,0 +1,28 @@ +#include "const.h" +#include "state.h" +#include "vco.h" +#include +#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); + + +} \ No newline at end of file diff --git a/buttons.h b/buttons.h new file mode 100644 index 0000000..47a4a21 --- /dev/null +++ b/buttons.h @@ -0,0 +1,3 @@ +#pragma once +#include +void handle_vco_change(uint gpio, uint32_t events); \ No newline at end of file diff --git a/const.h b/const.h index 6aac508..a446624 100644 --- a/const.h +++ b/const.h @@ -16,3 +16,4 @@ #define SAMPLE_RATE 44100.0f +#define otherwise else diff --git a/main.cc b/main.cc index 56e473f..3971fa4 100644 --- a/main.cc +++ b/main.cc @@ -1,3 +1,4 @@ +#include "buttons.h" #include "macro.h" #include "pico/stdlib.h" #include @@ -36,6 +37,9 @@ void init_all() { adc_gpio_init(adc_gpio[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;