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