Skip to content

Commit 023ae75

Browse files
committed
Rework pulseIn to work on ESP32-C3
Fixes: espressif#5488
1 parent c5a1f3e commit 023ae75

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Diff for: cores/esp32/wiring_pulse.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
//#include <limits.h>
1818
#include "wiring_private.h"
1919
#include "pins_arduino.h"
20-
21-
22-
extern uint32_t xthal_get_ccount();
20+
#include <hal/cpu_hal.h>
2321

2422
#define WAIT_FOR_PIN_STATE(state) \
2523
while (digitalRead(pin) != (state)) { \
26-
if (xthal_get_ccount() - start_cycle_count > timeout_cycles) { \
24+
if (cpu_hal_get_cycle_count() - start_cycle_count > timeout_cycles) { \
2725
return 0; \
2826
} \
2927
}
@@ -36,12 +34,12 @@ unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
3634
timeout = max_timeout_us;
3735
}
3836
const uint32_t timeout_cycles = microsecondsToClockCycles(timeout);
39-
const uint32_t start_cycle_count = xthal_get_ccount();
37+
const uint32_t start_cycle_count = cpu_hal_get_cycle_count();
4038
WAIT_FOR_PIN_STATE(!state);
4139
WAIT_FOR_PIN_STATE(state);
42-
const uint32_t pulse_start_cycle_count = xthal_get_ccount();
40+
const uint32_t pulse_start_cycle_count = cpu_hal_get_cycle_count();
4341
WAIT_FOR_PIN_STATE(!state);
44-
return clockCyclesToMicroseconds(xthal_get_ccount() - pulse_start_cycle_count);
42+
return clockCyclesToMicroseconds(cpu_hal_get_cycle_count() - pulse_start_cycle_count);
4543
}
4644

4745
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)

0 commit comments

Comments
 (0)