@@ -100,9 +100,9 @@ static int counter_esp32_init(const struct device *dev)
100100 k_spin_unlock (& lock , key );
101101
102102 int ret = esp_intr_alloc (cfg -> irq_source ,
103- ESP_PRIO_TO_FLAGS (cfg -> irq_priority ) |
104- ESP_INT_FLAGS_CHECK (cfg -> irq_flags ),
105- (ISR_HANDLER )counter_esp32_isr , (void * )dev , NULL );
103+ ESP_PRIO_TO_FLAGS (cfg -> irq_priority ) |
104+ ESP_INT_FLAGS_CHECK (cfg -> irq_flags ),
105+ (ISR_HANDLER )counter_esp32_isr , (void * )dev , NULL );
106106
107107 if (ret != 0 ) {
108108 LOG_ERR ("could not allocate interrupt (err %d)" , ret );
@@ -202,8 +202,7 @@ static int counter_esp32_cancel_alarm(const struct device *dev, uint8_t chan_id)
202202 return 0 ;
203203}
204204
205- static int counter_esp32_set_top_value (const struct device * dev ,
206- const struct counter_top_cfg * cfg )
205+ static int counter_esp32_set_top_value (const struct device * dev , const struct counter_top_cfg * cfg )
207206{
208207 const struct counter_esp32_config * config = dev -> config ;
209208
@@ -263,44 +262,37 @@ static void counter_esp32_isr(void *arg)
263262#define CLOCK_SOURCE_FREQ APB_CLK_FREQ
264263#endif
265264
266- #define ESP32_COUNTER_GET_CLK_DIV (idx ) \
267- (((DT_INST_PROP(idx, prescaler) & UINT16_MAX) < 2) ? \
268- 2 : (DT_INST_PROP(idx, prescaler) & UINT16_MAX))
269-
270- #define ESP32_COUNTER_INIT (idx ) \
271- \
272- static struct counter_esp32_data counter_data_##idx; \
273- \
274- static const struct counter_esp32_config counter_config_##idx = { \
275- .counter_info = { \
276- .max_top_value = UINT32_MAX, \
277- .freq = (CLOCK_SOURCE_FREQ / ESP32_COUNTER_GET_CLK_DIV(idx)), \
278- .flags = COUNTER_CONFIG_INFO_COUNT_UP, \
279- .channels = 1 \
280- }, \
281- .config = { \
282- .alarm_en = TIMER_ALARM_DIS, \
283- .counter_en = TIMER_START, \
284- .intr_type = TIMER_INTR_LEVEL, \
285- .counter_dir = TIMER_COUNT_UP, \
286- .auto_reload = TIMER_AUTORELOAD_DIS, \
287- .divider = ESP32_COUNTER_GET_CLK_DIV(idx), \
288- }, \
289- .group = DT_INST_PROP(idx, group), \
290- .index = DT_INST_PROP(idx, index), \
291- .irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
292- .irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
293- .irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags) \
294- }; \
295- \
296- \
297- DEVICE_DT_INST_DEFINE(idx, \
298- counter_esp32_init, \
299- NULL, \
300- &counter_data_##idx, \
301- &counter_config_##idx, \
302- PRE_KERNEL_1, \
303- CONFIG_COUNTER_INIT_PRIORITY, \
265+ #define ESP32_COUNTER_GET_CLK_DIV (idx ) \
266+ (((DT_INST_PROP(idx, prescaler) & UINT16_MAX) < 2) \
267+ ? 2 \
268+ : (DT_INST_PROP(idx, prescaler) & UINT16_MAX))
269+
270+ #define ESP32_COUNTER_INIT (idx ) \
271+ \
272+ static struct counter_esp32_data counter_data_##idx; \
273+ \
274+ static const struct counter_esp32_config counter_config_##idx = { \
275+ .counter_info = {.max_top_value = UINT32_MAX, \
276+ .freq = (CLOCK_SOURCE_FREQ / ESP32_COUNTER_GET_CLK_DIV(idx)), \
277+ .flags = COUNTER_CONFIG_INFO_COUNT_UP, \
278+ .channels = 1}, \
279+ .config = \
280+ { \
281+ .alarm_en = TIMER_ALARM_DIS, \
282+ .counter_en = TIMER_START, \
283+ .intr_type = TIMER_INTR_LEVEL, \
284+ .counter_dir = TIMER_COUNT_UP, \
285+ .auto_reload = TIMER_AUTORELOAD_DIS, \
286+ .divider = ESP32_COUNTER_GET_CLK_DIV(idx), \
287+ }, \
288+ .group = DT_INST_PROP(idx, group), \
289+ .index = DT_INST_PROP(idx, index), \
290+ .irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
291+ .irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
292+ .irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags)}; \
293+ \
294+ DEVICE_DT_INST_DEFINE(idx, counter_esp32_init, NULL, &counter_data_##idx, \
295+ &counter_config_##idx, PRE_KERNEL_1, CONFIG_COUNTER_INIT_PRIORITY, \
304296 &counter_api);
305297
306298DT_INST_FOREACH_STATUS_OKAY (ESP32_COUNTER_INIT );
0 commit comments