Compare commits
3 Commits
d5933cd060
...
c71a162d86
| Author | SHA1 | Date | |
|---|---|---|---|
| c71a162d86 | |||
| afaa87daec | |||
| e375586804 |
@ -4,8 +4,11 @@
|
||||
#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)) {
|
||||
void handle_vco_change(void) {
|
||||
static bool btn_prev = false;
|
||||
|
||||
bool btn_now = gpio_get(VCO_BUTTON);
|
||||
if (btn_now && !btn_prev) {
|
||||
if (state.vco_mode == VCO_SAW) state.vco_mode = VCO_SINE;
|
||||
otherwise state.vco_mode++;
|
||||
}
|
||||
@ -18,4 +21,5 @@ void update_button(uint pin, bool *button_state) {
|
||||
void update_buttons() {
|
||||
update_button(QUANT_BUTTON, &state.quant_enabled);
|
||||
update_button(AMEN_BUTTON, &state.amen_enabled);
|
||||
handle_vco_change();
|
||||
}
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
#pragma once
|
||||
#include <pico/types.h>
|
||||
|
||||
void handle_vco_change(uint gpio, uint32_t events);
|
||||
void update_button(uint pin, bool *button_state);
|
||||
void update_buttons();
|
||||
|
||||
|
||||
43
main.cc
43
main.cc
@ -1,15 +1,21 @@
|
||||
#include "buttons.h"
|
||||
#include "macro.h"
|
||||
#include "pico/stdlib.h"
|
||||
#include <hardware/gpio.h>
|
||||
#include <math.h>
|
||||
#include <hardware/irq.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "const.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/pwm.h"
|
||||
#include "hardware/adc.h"
|
||||
#include "pico/multicore.h"
|
||||
#include "pico/stdlib.h"
|
||||
|
||||
#include "buttons.h"
|
||||
#include "const.h"
|
||||
#include "macro.h"
|
||||
#include "state.h"
|
||||
#include "pwm.h"
|
||||
|
||||
state_t state;
|
||||
|
||||
@ -20,8 +26,6 @@ void init_all() {
|
||||
const uint8_t in_gpio[] = {VCO_BUTTON,QUANT_BUTTON,AMEN_BUTTON};
|
||||
const uint8_t adc_gpio[] = {MUX0,MUX1};
|
||||
|
||||
gpio_set_function(AUDIO_OUT, GPIO_FUNC_PWM);
|
||||
|
||||
for (uint8_t i=0; i < ARRAY_LENGTH(out_gpio); i++) {
|
||||
gpio_init(out_gpio[i]);
|
||||
gpio_set_dir(out_gpio[i], true);
|
||||
@ -37,14 +41,33 @@ void init_all() {
|
||||
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);
|
||||
// PWM bullshit
|
||||
gpio_set_function(AUDIO_OUT, GPIO_FUNC_PWM);
|
||||
|
||||
uint slice = pwm_gpio_to_slice_num(AUDIO_OUT);
|
||||
pwm_config cfg = pwm_get_default_config();
|
||||
pwm_config_set_wrap(&cfg, 3400);
|
||||
pwm_init(slice, &cfg, true);
|
||||
|
||||
pwm_clear_irq(slice);
|
||||
pwm_set_irq_enabled(slice, true);
|
||||
irq_set_exclusive_handler(PWM_IRQ_WRAP, pwm_isr);
|
||||
irq_set_enabled(PWM_IRQ_WRAP, true);
|
||||
}
|
||||
|
||||
__attribute__((noreturn))
|
||||
void core1_main(void) {
|
||||
while (1) {
|
||||
update_buttons();
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((noreturn))
|
||||
int main() {
|
||||
init_all();
|
||||
|
||||
multicore_launch_core1(core1_main);
|
||||
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
|
||||
21
pwm.c
Normal file
21
pwm.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <hardware/pwm.h>
|
||||
#include <pico/types.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
#include "pwm.h"
|
||||
|
||||
void pwm_isr(void) {
|
||||
static uint slice = -1, chan = -1;
|
||||
if (slice == -1) slice = pwm_gpio_to_slice_num(AUDIO_OUT);
|
||||
if (chan == -1) chan = pwm_gpio_to_channel(AUDIO_OUT);
|
||||
|
||||
pwm_clear_irq(slice);
|
||||
|
||||
// TODO:
|
||||
float sample = 0.0f;
|
||||
|
||||
uint16_t level = (uint16_t)((sample + 1.0f) * 0.5f * 3400.0f);
|
||||
pwm_set_chan_level(slice, chan, level);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user