Skip to content

Commit 73999ad

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 20448bb commit 73999ad

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
@@ -412,13 +412,13 @@ unsigned long pulseIn(pin_size_t pinNumber, uint8_t state, unsigned long timeout
412412
int64_t start, end, delta = 0;
413413
const struct gpio_dt_spec *spec = &arduino_pins[pinNumber];
414414

415-
k_timer_init(&timer, NULL, NULL);
416-
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
417-
418415
if (!gpio_is_ready_dt(spec)) {
419-
goto cleanup;
416+
return 0;
420417
}
421418

419+
k_timer_init(&timer, NULL, NULL);
420+
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
421+
422422
while(gpio_pin_get_dt(spec) == state && k_timer_status_get(&timer) == 0);
423423
if (k_timer_status_get(&timer) > 0) {
424424
goto cleanup;

0 commit comments

Comments
 (0)