add ledc driver and blink control for gate and clock LEDs
parent
c562d43cec
commit
805b8cd5c7
|
|
@ -1,8 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <esp_random.h>
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_random.h"
|
||||
|
||||
#include "driver/ledc.h"
|
||||
#include "hal/ledc_types.h"
|
||||
|
||||
#define SEQ_MAX_LEN 8
|
||||
|
||||
|
|
@ -14,14 +19,64 @@
|
|||
// CV Out
|
||||
// Gate Out
|
||||
|
||||
/* LED GPIO Pins */
|
||||
#define LEDC_CLK_OUT (5)
|
||||
#define LEDC_GATE_OUT (6)
|
||||
|
||||
static void ledc_init(void) {
|
||||
// Setup LEDC PWM timer configuration
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.timer_num = LEDC_TIMER_0,
|
||||
.duty_resolution = LEDC_TIMER_13_BIT,
|
||||
.freq_hz = 5000,
|
||||
.clk_cfg = LEDC_AUTO_CLK
|
||||
};
|
||||
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
|
||||
|
||||
// Setup Clock LED
|
||||
ledc_channel_config_t ledc_clk_channel = {
|
||||
.channel = LEDC_CHANNEL_0,
|
||||
.gpio_num = LEDC_CLK_OUT,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.duty = 0,
|
||||
.hpoint = 0
|
||||
};
|
||||
ESP_ERROR_CHECK(ledc_channel_config(&ledc_clk_channel));
|
||||
|
||||
// Setup Gate LED
|
||||
ledc_channel_config_t ledc_gate_channel = {
|
||||
.channel = LEDC_CHANNEL_1,
|
||||
.gpio_num = LEDC_GATE_OUT,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.duty = 0,
|
||||
.hpoint = 0
|
||||
};
|
||||
ESP_ERROR_CHECK(ledc_channel_config(&ledc_gate_channel));
|
||||
}
|
||||
|
||||
void blink_led(ledc_channel_t channel) {
|
||||
ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, channel, 4095));
|
||||
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, channel));
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, channel, 0));
|
||||
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, channel));
|
||||
}
|
||||
|
||||
void gen_rand_seq(uint8_t *sequence) {
|
||||
for (uint8_t i = 0; i < SEQ_MAX_LEN; i++) {
|
||||
sequence[i] = esp_random() % 2;
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
void app_main(void) {
|
||||
/* Initialize Peripherals */
|
||||
/* Initialize Monitor LEDs */
|
||||
ledc_init();
|
||||
/* Initialize sequence */
|
||||
uint8_t sequence[SEQ_MAX_LEN] = {0};
|
||||
uint8_t seq_len = SEQ_MAX_LEN;
|
||||
|
|
@ -29,7 +84,15 @@ void app_main(void)
|
|||
/* Main Loop */
|
||||
while (1) {
|
||||
for (uint8_t step = 0; step < seq_len; step++) {
|
||||
|
||||
blink_led(LEDC_CHANNEL_0); // blink clock led
|
||||
|
||||
// if step has been set for sequence
|
||||
if (sequence[step] == 1) {
|
||||
blink_led(LEDC_CHANNEL_1); // blink gate triggered led
|
||||
}
|
||||
printf("%i", sequence[step]);
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
}
|
||||
gen_rand_seq(sequence);
|
||||
printf("\n");
|
||||
|
|
|
|||
Reference in New Issue