| 2634 | */ |
| 2635 | |
| 2636 | struct WPIWfiStatus waitForInterrupt2(int pin, int edgeMode, int ms, unsigned long debounce_period_us) // ms < 0 wait infinite, = 0 return immediately, > 0 wait timeout |
| 2637 | { |
| 2638 | int ret; |
| 2639 | int fd, attr, status, readret; |
| 2640 | struct pollfd polls ; |
| 2641 | struct gpio_v2_line_event evdata; |
| 2642 | struct gpio_v2_line_config config; |
| 2643 | struct gpio_v2_line_request req; |
| 2644 | const char* strmode = ""; |
| 2645 | struct WPIWfiStatus wfiStatus; |
| 2646 | |
| 2647 | memset(&wfiStatus, 0, sizeof(wfiStatus)); |
| 2648 | /* open gpio */ |
| 2649 | if (wiringPiGpioDeviceGetFd()<0 || !ToBCMPin(&pin)) { |
| 2650 | wfiStatus.statusOK = -1; |
| 2651 | return wfiStatus; |
| 2652 | } |
| 2653 | |
| 2654 | memset(&req, 0, sizeof(req)); |
| 2655 | memset(&config, 0, sizeof(config)); |
| 2656 | |
| 2657 | /* setup config */ |
| 2658 | config.flags = GPIO_V2_LINE_FLAG_INPUT; |
| 2659 | |
| 2660 | switch(edgeMode) { |
| 2661 | default: |
| 2662 | case INT_EDGE_SETUP: |
| 2663 | if (wiringPiDebug) { |
| 2664 | printf ("waitForInterrupt2: edgeMode INT_EDGE_SETUP - exiting\n") ; |
| 2665 | } |
| 2666 | wfiStatus.statusOK = -1; |
| 2667 | return wfiStatus; |
| 2668 | case INT_EDGE_FALLING: |
| 2669 | config.flags |= GPIO_V2_LINE_FLAG_EDGE_FALLING; |
| 2670 | strmode = "falling"; |
| 2671 | break; |
| 2672 | case INT_EDGE_RISING: |
| 2673 | config.flags |= GPIO_V2_LINE_FLAG_EDGE_RISING; |
| 2674 | strmode = "rising"; |
| 2675 | break; |
| 2676 | case INT_EDGE_BOTH: |
| 2677 | config.flags |= (GPIO_V2_LINE_FLAG_EDGE_FALLING | GPIO_V2_LINE_FLAG_EDGE_RISING); |
| 2678 | strmode = "both"; |
| 2679 | break; |
| 2680 | } |
| 2681 | strcpy(req.consumer, "wiringpi_gpio_irq"); |
| 2682 | |
| 2683 | if (debounce_period_us) { |
| 2684 | attr = config.num_attrs; |
| 2685 | config.num_attrs++; |
| 2686 | gpiotools_set_bit(&config.attrs[attr].mask, 0); |
| 2687 | config.attrs[attr].attr.id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE; |
| 2688 | config.attrs[attr].attr.debounce_period_us = debounce_period_us; |
| 2689 | } |
| 2690 | |
| 2691 | req.num_lines = 1; |
| 2692 | req.offsets[0] = pin; |
| 2693 | req.event_buffer_size = 32; |
no test coverage detected