File tree 1 file changed +43
-0
lines changed
1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -349,3 +349,46 @@ long random(long max) {
349
349
}
350
350
351
351
#endif
352
+
353
+ unsigned long pulseIn (pin_size_t pinNumber, uint8_t state, unsigned long timeout) {
354
+ struct k_timer timer;
355
+ int64_t start, end, delta = 0 ;
356
+ const struct gpio_dt_spec *spec = &arduino_pins[pinNumber];
357
+
358
+ k_timer_init (&timer, NULL , NULL );
359
+ k_timer_start (&timer, K_MSEC (timeout), K_NO_WAIT);
360
+
361
+ if (!gpio_is_ready_dt (spec)) {
362
+ goto cleanup;
363
+ }
364
+
365
+ if (!gpio_pin_is_input_dt (spec)) {
366
+ goto cleanup;
367
+ }
368
+
369
+ while (gpio_pin_get_dt (spec) == state) {
370
+ if (k_timer_status_get (&timer) > 0 ) {
371
+ goto cleanup;
372
+ }
373
+ }
374
+
375
+ while (gpio_pin_get_dt (spec) != state) {
376
+ if (k_timer_status_get (&timer) > 0 ) {
377
+ goto cleanup;
378
+ }
379
+ }
380
+
381
+ start = k_uptime_ticks ();
382
+ while (gpio_pin_get_dt (spec) == state) {
383
+ if (k_timer_status_get (&timer) > 0 ) {
384
+ goto cleanup;
385
+ }
386
+ }
387
+ end = k_uptime_ticks ();
388
+
389
+ delta = k_ticks_to_us_floor64 (end - start);
390
+
391
+ cleanup:
392
+ k_timer_stop (&timer);
393
+ return (unsigned long )delta;
394
+ }
You can’t perform that action at this time.
0 commit comments