Compare commits

...

2 Commits

Author SHA1 Message Date
rkcf 7da7389f18 Fix: add missing led.h
Refs: #14
2023-02-25 04:32:05 -06:00
rkcf 12aa3a714a Feat: add ledc driver initialization
Refs: #14
2023-02-25 04:31:21 -06:00
4 changed files with 66 additions and 2 deletions

View File

@ -1,2 +1,2 @@
idf_component_register(SRCS "esp32_eurorack_generic.c" idf_component_register(SRCS "esp32_eurorack_generic.c" "led.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")

View File

@ -1,6 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include "led.h"
void app_main(void) void app_main(void)
{ {
/* Initialize LEDC driver */
ledc_init();
} }

54
src/main/led.c Normal file
View File

@ -0,0 +1,54 @@
#include <stdio.h>
#include "esp_log.h"
#include "esp_err.h"
#include "driver/ledc.h"
#include "hal/ledc_types.h"
/* Rotary Encoder LED Pins */
#define R1B_PIN 18 /* Rotary Encoder 1 Blue Pin */
#define R1G_PIN 8 /* Rotary Encoder 1 Green Pin */
#define R2B_PIN 45 /* Rotary Encoder 2 Blue Pin */
#define R2G_PIN 0 /* Rotary Encoder 2 Green Pin */
static const char *TAG = "ledc";
void ledc_init(void)
{
ESP_LOGI(TAG, "Initializing LEDC driver");
/* Configure and initialize ledc PWM timer */
ledc_timer_config_t timer_config = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.timer_num = LEDC_TIMER_0,
.duty_resolution = LEDC_TIMER_12_BIT,
.clk_cfg = LEDC_AUTO_CLK,
.freq_hz = 5000
};
ESP_ERROR_CHECK(ledc_timer_config(&timer_config));
/* Configure Rotary Encoder 1 B chan */
ledc_channel_config_t R1B_config = {
.channel = LEDC_CHANNEL_0,
.gpio_num = R1B_PIN,
.speed_mode = LEDC_LOW_SPEED_MODE,
.timer_sel = LEDC_TIMER_0,
.intr_type = LEDC_INTR_DISABLE,
.duty = 2048,
.hpoint = 0
};
ESP_ERROR_CHECK(ledc_channel_config(&R1B_config));
/* Configure Rotary Encoder 1 G chan */
ledc_channel_config_t R1G_config = {
.channel = LEDC_CHANNEL_1,
.gpio_num = R1G_PIN,
.speed_mode = LEDC_LOW_SPEED_MODE,
.timer_sel = LEDC_TIMER_0,
.intr_type = LEDC_INTR_DISABLE,
.duty = 2048,
.hpoint = 0
};
ESP_ERROR_CHECK(ledc_channel_config(&R1G_config));
}

7
src/main/led.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef LED_H_
#define LED_H_
/* Configuration and initialization of ledc driver */
void ledc_init(void);
#endif