Skip to content

Commit 32ddcf0

Browse files
committed
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 <[email protected]>
1 parent 627e00f commit 32ddcf0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,13 @@ unsigned long pulseIn(pin_size_t pinNumber, uint8_t state, unsigned long timeout
433433
int64_t start, end, delta = 0;
434434
const struct gpio_dt_spec *spec = &arduino_pins[pinNumber];
435435

436-
k_timer_init(&timer, NULL, NULL);
437-
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
438-
439436
if (!gpio_is_ready_dt(spec)) {
440-
goto cleanup;
437+
return 0;
441438
}
442439

440+
k_timer_init(&timer, NULL, NULL);
441+
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
442+
443443
while(gpio_pin_get_dt(spec) == state && k_timer_status_get(&timer) == 0);
444444
if (k_timer_status_get(&timer) > 0) {
445445
goto cleanup;

0 commit comments

Comments
 (0)