add gpio driver for sending CV clock and gate pulses

main
rkcf 2023-01-27 16:35:20 -06:00
parent 805b8cd5c7
commit dc0a9f9308
1 changed files with 22 additions and 2 deletions

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include "driver/gpio.h"
#include "esp_err.h" #include "esp_err.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
@ -16,13 +17,22 @@
// Reset In // Reset In
/* Outputs */ /* Outputs */
// CV Out #define GPIO_CLK_OUT (7) // Clock Out
// Gate Out #define GPIO_GATE_OUT (8) // Gate CV Out
/* LED GPIO Pins */ /* LED GPIO Pins */
#define LEDC_CLK_OUT (5) #define LEDC_CLK_OUT (5)
#define LEDC_GATE_OUT (6) #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) { static void ledc_init(void) {
// Setup LEDC PWM timer configuration // Setup LEDC PWM timer configuration
ledc_timer_config_t ledc_timer = { 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)); 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) { void gen_rand_seq(uint8_t *sequence) {
for (uint8_t i = 0; i < SEQ_MAX_LEN; i++) { for (uint8_t i = 0; i < SEQ_MAX_LEN; i++) {
sequence[i] = esp_random() % 2; sequence[i] = esp_random() % 2;
@ -75,6 +91,8 @@ void gen_rand_seq(uint8_t *sequence) {
void app_main(void) { void app_main(void) {
/* Initialize Peripherals */ /* Initialize Peripherals */
/* Initialize GPIO */
gpio_init();
/* Initialize Monitor LEDs */ /* Initialize Monitor LEDs */
ledc_init(); ledc_init();
/* Initialize sequence */ /* Initialize sequence */
@ -86,10 +104,12 @@ void app_main(void) {
for (uint8_t step = 0; step < seq_len; step++) { for (uint8_t step = 0; step < seq_len; step++) {
blink_led(LEDC_CHANNEL_0); // blink clock led blink_led(LEDC_CHANNEL_0); // blink clock led
pulse_cv(GPIO_CLK_OUT);
// if step has been set for sequence // if step has been set for sequence
if (sequence[step] == 1) { if (sequence[step] == 1) {
blink_led(LEDC_CHANNEL_1); // blink gate triggered led blink_led(LEDC_CHANNEL_1); // blink gate triggered led
pulse_cv(GPIO_GATE_OUT);
} }
printf("%i", sequence[step]); printf("%i", sequence[step]);
vTaskDelay(500 / portTICK_PERIOD_MS); vTaskDelay(500 / portTICK_PERIOD_MS);