From b43948ded3edca656fc8283a841fcf38e4b5fcd7 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 24 Apr 2020 23:50:43 +0200 Subject: [PATCH] Update drone mute function + mosfet --- drone.c | 29 ++++++++++++++++++++++++++--- main.c | 1 + pot.c | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/drone.c b/drone.c index 6638977..7579e49 100644 --- a/drone.c +++ b/drone.c @@ -7,6 +7,8 @@ #include #include #include +#include "unicore-mx/stm32/gpio.h" +#include "unicore-mx/stm32/rcc.h" #include "ui.h" #include "timer.h" #include "led.h" @@ -42,7 +44,9 @@ static struct drone_slot drone_pattern[MAX_PATTERN_LEN] = { void drone_mute(void) { pot_set(0, 0); - pot_set(1, 99); + pot_set(1, 0); + gpio_clear(GPIOE, GPIO2); + gpio_clear(GPIOE, GPIO3); } void drone_beat(int pattern_pos) @@ -54,10 +58,18 @@ void drone_beat(int pattern_pos) int lfo_rate = 7; int lfo_step = 2; int tgt_env; + 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); - if ((key->pitch == 0) && (key->env == 0)) - return; + gpio_set(GPIOE, GPIO2); + gpio_set(GPIOE, GPIO3); + if ((pattern_pos % lfo_step) == 0) { if (test_lfo_step == 0) { @@ -85,3 +97,14 @@ void drone_beat(int pattern_pos) 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); +} + diff --git a/main.c b/main.c index 6f98906..de2434e 100644 --- a/main.c +++ b/main.c @@ -71,6 +71,7 @@ static void bootlevel_1(void) printf("UI initialized.\r\n"); timer_init(); drums_init(); + drone_init(); drums_start(); printf("System up and running.\r\n\n\n"); diff --git a/pot.c b/pot.c index 57f7767..11febfe 100644 --- a/pot.c +++ b/pot.c @@ -59,7 +59,7 @@ static void p_offset(int p, int offset) /* /CS off first (no store) */ gpio_set(GPIOC,cs); //WFI(); - for (int j = 0; j < 4000; j++) + for (int j = 0; j < 1000; j++) ;; }