minor refactor and code cleanup

main
rkcf 2023-01-28 11:26:00 -06:00
parent 0ba47039f8
commit f52697412c
1 changed files with 11 additions and 18 deletions

View File

@ -3,25 +3,21 @@
#include "driver/gpio.h"
#include "driver/gptimer.h"
#include "driver/ledc.h"
#include "esp_attr.h"
#include "esp_err.h"
#include "esp_random.h"
#include "esp_log.h"
#include "esp_random.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/ledc.h"
#include "freertos/task.h"
#include "hal/gpio_types.h"
#include "hal/ledc_types.h"
#include "hal/timer_types.h"
#include "soc/clk_tree_defs.h"
#define SEQ_MAX_LEN 8
/* Inputs */
// Clock In
// Reset In
/* Controls */
#define GPIO_MUTATE_BTN (9) // Mutate Button In
@ -45,13 +41,15 @@ gptimer_handle_t gate_cv_timer = NULL;
gptimer_handle_t clk_blink_timer = NULL;
gptimer_handle_t gate_blink_timer = NULL;
static const uint32_t DEFAULT_BPM = 120;
static const uint8_t SEQ_MAX_LEN = 8;
uint8_t sequence[SEQ_MAX_LEN] = {0};
uint8_t seq_len = SEQ_MAX_LEN;
static const uint32_t DEFAULT_BPM = 120;
static const char *TAG = "sequencer";
uint32_t bpm_to_ms(uint32_t bpm) {
return 60000 / bpm;
}
@ -163,14 +161,12 @@ static void gpio_init(void) {
//register clk callback
gptimer_event_callbacks_t clk_cbs = {.on_alarm = clk_cv_off_alarm_cb};
ESP_ERROR_CHECK(
gptimer_register_event_callbacks(clk_cv_timer, &clk_cbs, NULL));
ESP_ERROR_CHECK(gptimer_register_event_callbacks(clk_cv_timer, &clk_cbs, NULL));
ESP_ERROR_CHECK(gptimer_enable(clk_cv_timer));
// register gate callback
gptimer_event_callbacks_t gate_cbs = {.on_alarm = gate_cv_off_alarm_cb};
ESP_ERROR_CHECK(
gptimer_register_event_callbacks(gate_cv_timer, &gate_cbs, NULL));
ESP_ERROR_CHECK(gptimer_register_event_callbacks(gate_cv_timer, &gate_cbs, NULL));
ESP_ERROR_CHECK(gptimer_enable(gate_cv_timer));
}
@ -241,14 +237,12 @@ static void ledc_init(void) {
//register clk callback
gptimer_event_callbacks_t clk_cbs = {.on_alarm = clk_led_off_alarm_cb};
ESP_ERROR_CHECK(
gptimer_register_event_callbacks(clk_blink_timer, &clk_cbs, NULL));
ESP_ERROR_CHECK(gptimer_register_event_callbacks(clk_blink_timer, &clk_cbs, NULL));
ESP_ERROR_CHECK(gptimer_enable(clk_blink_timer));
// register gate callback
gptimer_event_callbacks_t gate_cbs = {.on_alarm = gate_led_off_alarm_cb};
ESP_ERROR_CHECK(
gptimer_register_event_callbacks(gate_blink_timer, &gate_cbs, NULL));
ESP_ERROR_CHECK(gptimer_register_event_callbacks(gate_blink_timer, &gate_cbs, NULL));
ESP_ERROR_CHECK(gptimer_enable(gate_blink_timer));
}
@ -293,7 +287,6 @@ void app_main(void) {
/* Initialize sequence */
randomize_seq(sequence);
/* Main Loop */
while (1) {
for (uint8_t step = 0; step < seq_len; step++) {