From 6f6181ce96b81ee8caba585d6ba0903994f3a42a Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sat, 23 Aug 2025 08:52:06 +0900 Subject: [PATCH] zephyrCommon: Immediately terminate pulseIn if gpio not ready If gpio is not initialized, the pulseIn function will terminate without running the timer. Signed-off-by: TOKITA Hiroshi --- cores/arduino/zephyrCommon.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 901457d1..49ee10ad 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -418,13 +418,13 @@ unsigned long pulseIn(pin_size_t pinNumber, uint8_t state, unsigned long timeout int64_t start, end, delta = 0; const struct gpio_dt_spec *spec = &arduino_pins[pinNumber]; - k_timer_init(&timer, NULL, NULL); - k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT); - if (!gpio_is_ready_dt(spec)) { - goto cleanup; + return 0; } + k_timer_init(&timer, NULL, NULL); + k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT); + while(gpio_pin_get_dt(spec) == state && k_timer_status_get(&timer) == 0); if (k_timer_status_get(&timer) > 0) { goto cleanup;