add gpio driver for sending CV clock and gate pulses
parent
805b8cd5c7
commit
dc0a9f9308
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
|
@ -16,13 +17,22 @@
|
|||
// Reset In
|
||||
|
||||
/* Outputs */
|
||||
// CV Out
|
||||
// Gate Out
|
||||
#define GPIO_CLK_OUT (7) // Clock Out
|
||||
#define GPIO_GATE_OUT (8) // Gate CV Out
|
||||
|
||||
/* LED GPIO Pins */
|
||||
#define LEDC_CLK_OUT (5)
|
||||
#define LEDC_GATE_OUT (6)
|
||||
|
||||
static void gpio_init(void) {
|
||||
// Setup Clock CV Output
|
||||
gpio_reset_pin(GPIO_CLK_OUT);
|
||||
gpio_set_direction(GPIO_CLK_OUT, GPIO_MODE_OUTPUT);
|
||||
// Setup Gate CV Output
|
||||
gpio_reset_pin(GPIO_GATE_OUT);
|
||||
gpio_set_direction(GPIO_GATE_OUT, GPIO_MODE_OUTPUT);
|
||||
}
|
||||
|
||||
static void ledc_init(void) {
|
||||
// Setup LEDC PWM timer configuration
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
|
|
@ -67,6 +77,12 @@ void blink_led(ledc_channel_t channel) {
|
|||
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, channel));
|
||||
}
|
||||
|
||||
void pulse_cv(uint8_t gpio_num) {
|
||||
gpio_set_level(gpio_num, 1);
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
gpio_set_level(gpio_num, 0);
|
||||
}
|
||||
|
||||
void gen_rand_seq(uint8_t *sequence) {
|
||||
for (uint8_t i = 0; i < SEQ_MAX_LEN; i++) {
|
||||
sequence[i] = esp_random() % 2;
|
||||
|
|
@ -75,6 +91,8 @@ void gen_rand_seq(uint8_t *sequence) {
|
|||
|
||||
void app_main(void) {
|
||||
/* Initialize Peripherals */
|
||||
/* Initialize GPIO */
|
||||
gpio_init();
|
||||
/* Initialize Monitor LEDs */
|
||||
ledc_init();
|
||||
/* Initialize sequence */
|
||||
|
|
@ -86,10 +104,12 @@ void app_main(void) {
|
|||
for (uint8_t step = 0; step < seq_len; step++) {
|
||||
|
||||
blink_led(LEDC_CHANNEL_0); // blink clock led
|
||||
pulse_cv(GPIO_CLK_OUT);
|
||||
|
||||
// if step has been set for sequence
|
||||
if (sequence[step] == 1) {
|
||||
blink_led(LEDC_CHANNEL_1); // blink gate triggered led
|
||||
pulse_cv(GPIO_GATE_OUT);
|
||||
}
|
||||
printf("%i", sequence[step]);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
|
|
|
|||
Reference in New Issue