Skip to content

Commit de7a38b

Browse files
committed
pulse
1 parent d1185fb commit de7a38b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,36 +470,37 @@ long random(long max) {
470470

471471
#endif
472472

473-
#ifdef CONFIG_GPIO_GET_DIRECTION
474-
475473
unsigned long pulseIn(pin_size_t pinNumber, uint8_t state, unsigned long timeout) {
474+
const struct device* port = local_gpio_port(pinNumber);
475+
const size_t pin = local_gpio_pin(pinNumber);
476476
struct k_timer timer;
477477
int64_t start, end, delta = 0;
478-
const struct gpio_dt_spec *spec = &arduino_pins[pinNumber];
479478

480479
k_timer_init(&timer, NULL, NULL);
481480
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
482481

483-
if (!gpio_is_ready_dt(spec)) {
482+
if (!device_is_ready(local_gpio_port(pinNumber))) {
484483
goto cleanup;
485484
}
486485

487-
if (!gpio_pin_is_input_dt(spec)) {
486+
#ifdef CONFIG_GPIO_GET_DIRECTION
487+
if (!gpio_pin_is_input(port, pin)) {
488488
goto cleanup;
489489
}
490+
#endif // CONFIG_GPIO_GET_DIRECTION
490491

491-
while(gpio_pin_get_dt(spec) == state && k_timer_status_get(&timer) == 0);
492+
while (gpio_pin_get(port, pin) == state && k_timer_status_get(&timer) == 0);
492493
if (k_timer_status_get(&timer) > 0) {
493494
goto cleanup;
494495
}
495496

496-
while(gpio_pin_get_dt(spec) != state && k_timer_status_get(&timer) == 0);
497+
while (gpio_pin_get(port, pin) != state && k_timer_status_get(&timer) == 0);
497498
if (k_timer_status_get(&timer) > 0) {
498499
goto cleanup;
499500
}
500501

501502
start = k_uptime_ticks();
502-
while(gpio_pin_get_dt(spec) == state && k_timer_status_get(&timer) == 0);
503+
while (gpio_pin_get(port, pin) == state && k_timer_status_get(&timer) == 0);
503504
if (k_timer_status_get(&timer) > 0) {
504505
goto cleanup;
505506
}
@@ -512,8 +513,6 @@ unsigned long pulseIn(pin_size_t pinNumber, uint8_t state, unsigned long timeout
512513
return (unsigned long)delta;
513514
}
514515

515-
#endif // CONFIG_GPIO_GET_DIRECTION
516-
517516
void enableInterrupt(pin_size_t pinNumber) {
518517
struct gpio_port_callback *pcb = find_gpio_port_callback(local_gpio_port(pinNumber));
519518

0 commit comments

Comments
 (0)