File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -349,3 +349,47 @@ long random(long max) {
349349}
350350
351351#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 && k_timer_status_get (&timer) == 0 );
372+ if (k_timer_status_get (&timer) > 0 ) {
373+ goto cleanup;
374+ }
375+
376+ while (gpio_pin_get_dt (spec) != state && k_timer_status_get (&timer) == 0 );
377+ if (k_timer_status_get (&timer) > 0 ) {
378+ goto cleanup;
379+ }
380+
381+ start = k_uptime_ticks ();
382+ while (gpio_pin_get_dt (spec) == state && k_timer_status_get (&timer) == 0 );
383+ if (k_timer_status_get (&timer) > 0 ) {
384+ goto cleanup;
385+ }
386+ end = k_uptime_ticks ();
387+
388+ delta = k_ticks_to_us_floor64 (end - start);
389+
390+ cleanup:
391+ k_timer_stop (&timer);
392+ return (unsigned long )delta;
393+ }
394+
395+ #endif // CONFIG_GPIO_GET_DIRECTION
You can’t perform that action at this time.
0 commit comments