mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-15 15:00:02 +01:00
Update LEDC, PCNT,Timer_Group driver for esp32s2beta.
This commit is contained in:
@@ -33,15 +33,22 @@
|
||||
* GPIO4/5 are from low speed channel group.
|
||||
*
|
||||
*/
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#define LEDC_HS_TIMER LEDC_TIMER_0
|
||||
#define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE
|
||||
#define LEDC_HS_CH0_GPIO (18)
|
||||
#define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0
|
||||
#define LEDC_HS_CH1_GPIO (19)
|
||||
#define LEDC_HS_CH1_CHANNEL LEDC_CHANNEL_1
|
||||
|
||||
#endif
|
||||
#define LEDC_LS_TIMER LEDC_TIMER_1
|
||||
#define LEDC_LS_MODE LEDC_LOW_SPEED_MODE
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
#define LEDC_LS_CH0_GPIO (18)
|
||||
#define LEDC_LS_CH0_CHANNEL LEDC_CHANNEL_0
|
||||
#define LEDC_LS_CH1_GPIO (19)
|
||||
#define LEDC_LS_CH1_CHANNEL LEDC_CHANNEL_1
|
||||
#endif
|
||||
#define LEDC_LS_CH2_GPIO (4)
|
||||
#define LEDC_LS_CH2_CHANNEL LEDC_CHANNEL_2
|
||||
#define LEDC_LS_CH3_GPIO (5)
|
||||
@@ -62,17 +69,17 @@ void app_main()
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.duty_resolution = LEDC_TIMER_13_BIT, // resolution of PWM duty
|
||||
.freq_hz = 5000, // frequency of PWM signal
|
||||
.speed_mode = LEDC_HS_MODE, // timer mode
|
||||
.timer_num = LEDC_HS_TIMER // timer index
|
||||
.speed_mode = LEDC_LS_MODE, // timer mode
|
||||
.timer_num = LEDC_LS_TIMER // timer index
|
||||
};
|
||||
// Set configuration of timer0 for high speed channels
|
||||
ledc_timer_config(&ledc_timer);
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
// Prepare and set configuration of timer1 for low speed channels
|
||||
ledc_timer.speed_mode = LEDC_LS_MODE;
|
||||
ledc_timer.timer_num = LEDC_LS_TIMER;
|
||||
ledc_timer.speed_mode = LEDC_HS_MODE;
|
||||
ledc_timer.timer_num = LEDC_HS_TIMER;
|
||||
ledc_timer_config(&ledc_timer);
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Prepare individual configuration
|
||||
* for each channel of LED Controller
|
||||
@@ -87,6 +94,7 @@ void app_main()
|
||||
* will be the same
|
||||
*/
|
||||
ledc_channel_config_t ledc_channel[LEDC_TEST_CH_NUM] = {
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
{
|
||||
.channel = LEDC_HS_CH0_CHANNEL,
|
||||
.duty = 0,
|
||||
@@ -103,6 +111,24 @@ void app_main()
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_HS_TIMER
|
||||
},
|
||||
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
{
|
||||
.channel = LEDC_LS_CH0_CHANNEL,
|
||||
.duty = 0,
|
||||
.gpio_num = LEDC_LS_CH0_GPIO,
|
||||
.speed_mode = LEDC_LS_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_LS_TIMER
|
||||
},
|
||||
{
|
||||
.channel = LEDC_LS_CH1_CHANNEL,
|
||||
.duty = 0,
|
||||
.gpio_num = LEDC_LS_CH1_GPIO,
|
||||
.speed_mode = LEDC_LS_MODE,
|
||||
.hpoint = 0,
|
||||
.timer_sel = LEDC_LS_TIMER
|
||||
},
|
||||
#endif
|
||||
{
|
||||
.channel = LEDC_LS_CH2_CHANNEL,
|
||||
.duty = 0,
|
||||
|
||||
@@ -96,7 +96,7 @@ static void ledc_init(void)
|
||||
{
|
||||
// Prepare and then apply the LEDC PWM timer configuration
|
||||
ledc_timer_config_t ledc_timer;
|
||||
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;
|
||||
ledc_timer.speed_mode = LEDC_LOW_SPEED_MODE;
|
||||
ledc_timer.timer_num = LEDC_TIMER_1;
|
||||
ledc_timer.duty_resolution = LEDC_TIMER_10_BIT;
|
||||
ledc_timer.freq_hz = 1; // set output frequency at 1 Hz
|
||||
@@ -104,7 +104,7 @@ static void ledc_init(void)
|
||||
|
||||
// Prepare and then apply the LEDC PWM channel configuration
|
||||
ledc_channel_config_t ledc_channel;
|
||||
ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
|
||||
ledc_channel.speed_mode = LEDC_LOW_SPEED_MODE;
|
||||
ledc_channel.channel = LEDC_CHANNEL_1;
|
||||
ledc_channel.timer_sel = LEDC_TIMER_1;
|
||||
ledc_channel.intr_type = LEDC_INTR_DISABLE;
|
||||
@@ -187,19 +187,19 @@ void app_main()
|
||||
if (res == pdTRUE) {
|
||||
pcnt_get_counter_value(PCNT_TEST_UNIT, &count);
|
||||
printf("Event PCNT unit[%d]; cnt: %d\n", evt.unit, count);
|
||||
if (evt.status & PCNT_STATUS_THRES1_M) {
|
||||
if (evt.status & PCNT_EVT_THRES_1) {
|
||||
printf("THRES1 EVT\n");
|
||||
}
|
||||
if (evt.status & PCNT_STATUS_THRES0_M) {
|
||||
if (evt.status & PCNT_EVT_THRES_0) {
|
||||
printf("THRES0 EVT\n");
|
||||
}
|
||||
if (evt.status & PCNT_STATUS_L_LIM_M) {
|
||||
if (evt.status & PCNT_EVT_L_LIM) {
|
||||
printf("L_LIM EVT\n");
|
||||
}
|
||||
if (evt.status & PCNT_STATUS_H_LIM_M) {
|
||||
if (evt.status & PCNT_EVT_H_LIM) {
|
||||
printf("H_LIM EVT\n");
|
||||
}
|
||||
if (evt.status & PCNT_STATUS_ZERO_M) {
|
||||
if (evt.status & PCNT_EVT_ZERO) {
|
||||
printf("ZERO EVT\n");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "esp_types.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@@ -60,8 +59,13 @@ void IRAM_ATTR timer_group0_isr(void *para)
|
||||
|
||||
/* Retrieve the interrupt status and the counter value
|
||||
from the timer that reported the interrupt */
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
uint32_t intr_status = TIMERG0.int_st_timers.val;
|
||||
TIMERG0.hw_timer[timer_idx].update = 1;
|
||||
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
uint32_t intr_status = TIMERG0.int_st.val;
|
||||
TIMERG0.hw_timer[timer_idx].update.update = 1;
|
||||
#endif
|
||||
uint64_t timer_counter_value =
|
||||
((uint64_t) TIMERG0.hw_timer[timer_idx].cnt_high) << 32
|
||||
| TIMERG0.hw_timer[timer_idx].cnt_low;
|
||||
@@ -77,13 +81,21 @@ void IRAM_ATTR timer_group0_isr(void *para)
|
||||
and update the alarm time for the timer with without reload */
|
||||
if ((intr_status & BIT(timer_idx)) && timer_idx == TIMER_0) {
|
||||
evt.type = TEST_WITHOUT_RELOAD;
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
TIMERG0.int_clr_timers.t0 = 1;
|
||||
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
TIMERG0.int_clr.t0 = 1;
|
||||
#endif
|
||||
timer_counter_value += (uint64_t) (TIMER_INTERVAL0_SEC * TIMER_SCALE);
|
||||
TIMERG0.hw_timer[timer_idx].alarm_high = (uint32_t) (timer_counter_value >> 32);
|
||||
TIMERG0.hw_timer[timer_idx].alarm_low = (uint32_t) timer_counter_value;
|
||||
} else if ((intr_status & BIT(timer_idx)) && timer_idx == TIMER_1) {
|
||||
evt.type = TEST_WITH_RELOAD;
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
TIMERG0.int_clr_timers.t1 = 1;
|
||||
#elif defined CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
TIMERG0.int_clr.t1 = 1;
|
||||
#endif
|
||||
} else {
|
||||
evt.type = -1; // not supported even type
|
||||
}
|
||||
@@ -114,6 +126,9 @@ static void example_tg0_timer_init(int timer_idx,
|
||||
config.alarm_en = TIMER_ALARM_EN;
|
||||
config.intr_type = TIMER_INTR_LEVEL;
|
||||
config.auto_reload = auto_reload;
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
config.clk_sel = TIMER_SRC_CLK_APB;
|
||||
#endif
|
||||
timer_init(TIMER_GROUP_0, timer_idx, &config);
|
||||
|
||||
/* Timer's counter will initially start from value below.
|
||||
|
||||
Reference in New Issue
Block a user