Skip to content

Commit c1f8948

Browse files
Raffael Rostagnonashif
authored andcommitted
drivers: counter: esp32c2: Add support
Add counter support to ESP32C2 and ESP8684 Signed-off-by: Raffael Rostagno <[email protected]>
1 parent cc2e0f2 commit c1f8948

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

drivers/counter/counter_esp32_rtc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <zephyr/drivers/clock_control.h>
2323
#include <zephyr/drivers/clock_control/esp32_clock_control.h>
2424

25-
#if defined(CONFIG_SOC_SERIES_ESP32C3)
25+
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3)
2626
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
2727
#else
2828
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
@@ -31,7 +31,7 @@
3131
#include <zephyr/logging/log.h>
3232
LOG_MODULE_REGISTER(esp32_counter_rtc, CONFIG_COUNTER_LOG_LEVEL);
3333

34-
#if defined(CONFIG_SOC_SERIES_ESP32C3)
34+
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3)
3535
#define ESP32_COUNTER_RTC_ISR_HANDLER isr_handler_t
3636
#else
3737
#define ESP32_COUNTER_RTC_ISR_HANDLER intr_handler_t
@@ -108,7 +108,8 @@ static int counter_esp32_set_alarm(const struct device *dev, uint8_t chan_id,
108108
uint32_t now;
109109
uint32_t ticks = 0;
110110

111-
#if defined(CONFIG_SOC_SERIES_ESP32) || defined(CONFIG_SOC_SERIES_ESP32C3)
111+
#if defined(CONFIG_SOC_SERIES_ESP32) || defined(CONFIG_SOC_SERIES_ESP32C2) || \
112+
defined(CONFIG_SOC_SERIES_ESP32C3)
112113
/* In ESP32/C3 Series the min possible value is 30 us*/
113114
if (counter_ticks_to_us(dev, alarm_cfg->ticks) < 30) {
114115
return -EINVAL;

drivers/counter/counter_esp32_tmr.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
#include <zephyr/drivers/counter.h>
1919
#include <zephyr/spinlock.h>
2020
#include <zephyr/kernel.h>
21-
#ifndef CONFIG_SOC_SERIES_ESP32C3
22-
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
23-
#else
21+
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3)
2422
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
23+
#else
24+
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
2525
#endif
2626
#include <zephyr/device.h>
2727
#include <zephyr/logging/log.h>
2828
LOG_MODULE_REGISTER(esp32_counter, CONFIG_COUNTER_LOG_LEVEL);
2929

30-
#ifdef CONFIG_SOC_SERIES_ESP32C3
30+
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3)
3131
#define ISR_HANDLER isr_handler_t
3232
#else
3333
#define ISR_HANDLER intr_handler_t
@@ -70,9 +70,11 @@ static int counter_esp32_init(const struct device *dev)
7070
case TIMER_GROUP_0:
7171
periph_module_enable(PERIPH_TIMG0_MODULE);
7272
break;
73+
#if !defined(CONFIG_SOC_SERIES_ESP32C2)
7374
case TIMER_GROUP_1:
7475
periph_module_enable(PERIPH_TIMG1_MODULE);
7576
break;
77+
#endif
7678
default:
7779
return -ENOTSUP;
7880
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
&timer0 {
2+
status = "okay";
3+
};
4+
5+
&rtc_timer {
6+
status = "okay";
7+
};

0 commit comments

Comments
 (0)