#include #include "system.h" #include "display.h" #include "systick.h" #include "button.h" #include #include #include #include "unicore-mx/stm32/gpio.h" #include "unicore-mx/stm32/rcc.h" #include "ui.h" #include "timer.h" #include "led.h" #include "drone.h" #include "drums.h" #include "pot.h" #include "settings.h" #define MUTE { 0 , 0 } void drone_mute(void) { pot_set(0, 0); pot_set(1, 0); gpio_clear(GPIOE, GPIO2); gpio_clear(GPIOE, GPIO3); } void drone_beat(int pattern_pos) { static int test_lfo_step = 0; static int test_lfo = 0; int lfo_depth = 80; int lfo_rate = 7; int lfo_step = 2; int tgt_env; static struct drone_slot *pattern; struct drone_slot *key; pattern = Settings->drone[Settings->current_pattern].data; key = &pattern[pattern_pos]; if ((key->pitch == 0) && (key->env == 0)) { pot_set(0, 99); pot_set(1, 0); gpio_clear(GPIOE, GPIO2); gpio_clear(GPIOE, GPIO3); return; } pot_set(0, 0); pot_set(1, 99); gpio_set(GPIOE, GPIO2); gpio_set(GPIOE, GPIO3); if ((pattern_pos % lfo_step) == 0) { if (test_lfo_step == 0) { test_lfo+=lfo_rate; if (test_lfo > lfo_depth) test_lfo_step = 1; } else { test_lfo-=lfo_rate; if (test_lfo < (0 - lfo_depth)) test_lfo_step = 0; } } tgt_env = key->env + test_lfo; if (tgt_env < 0) { tgt_env = 0; test_lfo_step = 0; } if (tgt_env > 99) { tgt_env = 99; test_lfo_step = 1; } pot_set(0, key->pitch); pot_set(1, tgt_env); } #define TRIG_PIN (GPIO2 | GPIO3) void drone_init(void) { rcc_periph_clock_enable(RCC_GPIOE); gpio_mode_setup(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, TRIG_PIN); gpio_set_output_options(GPIOE, GPIO_OTYPE_OD, GPIO_OSPEED_100MHZ, TRIG_PIN); gpio_clear(GPIOE, TRIG_PIN); }