File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -328,3 +328,28 @@ void detachInterrupt(pin_size_t pinNumber)
328
328
{
329
329
setInterruptHandler (pinNumber, nullptr );
330
330
}
331
+
332
+ unsigned long pulseIn (pin_size_t pinNumber, uint8_t state, unsigned long timeout) {
333
+ const struct gpio_dt_spec *spec = &arduino_pins[pinNumber];
334
+ int64_t start, end, delta;
335
+
336
+ if (!gpio_is_ready_dt (spec)) {
337
+ return 0 ;
338
+ }
339
+
340
+ if (!gpio_pin_is_input_dt (spec)) {
341
+ return 0 ;
342
+ }
343
+
344
+
345
+ while (gpio_pin_get_dt (spec) == state);
346
+ while (gpio_pin_get_dt (spec) != state);
347
+
348
+ start = k_uptime_ticks ();
349
+ while (gpio_pin_get_dt (spec) == state);
350
+ end = k_uptime_ticks ();
351
+
352
+ delta = k_ticks_to_us_floor64 (end) - k_ticks_to_us_floor64 (start);
353
+
354
+ return (unsigned long )delta;
355
+ }
You can’t perform that action at this time.
0 commit comments