| 2877 | */ |
| 2878 | |
| 2879 | static int interruptHandlerInit(int pin, int EdgeMode, unsigned long debounce_period_us) |
| 2880 | { |
| 2881 | const char* strmode = ""; |
| 2882 | int ret, attr; |
| 2883 | struct gpio_v2_line_config config; |
| 2884 | struct gpio_v2_line_request req; |
| 2885 | |
| 2886 | if (wiringPiGpioDeviceGetFd() < 0) { |
| 2887 | return -1; |
| 2888 | } |
| 2889 | |
| 2890 | if (wiringPiDebug) { |
| 2891 | printf ("interruptHandlerV2: GPIO line %d, edge mode %d, debounce_period_us %lu \n", pin, EdgeMode, debounce_period_us) ; |
| 2892 | } |
| 2893 | |
| 2894 | memset(&req, 0, sizeof(req)); |
| 2895 | memset(&config, 0, sizeof(config)); |
| 2896 | |
| 2897 | /* setup config */ |
| 2898 | config.flags = GPIO_V2_LINE_FLAG_INPUT; |
| 2899 | switch(EdgeMode) { |
| 2900 | default: |
| 2901 | case INT_EDGE_SETUP: |
| 2902 | if (wiringPiDebug) { |
| 2903 | printf ("interruptHandlerV2: waitForInterruptMode edge mode INT_EDGE_SETUP - exiting\n") ; |
| 2904 | } |
| 2905 | return 0; |
| 2906 | case INT_EDGE_FALLING: |
| 2907 | config.flags |= GPIO_V2_LINE_FLAG_EDGE_FALLING; |
| 2908 | strmode = "falling"; |
| 2909 | break; |
| 2910 | case INT_EDGE_RISING: |
| 2911 | config.flags |= GPIO_V2_LINE_FLAG_EDGE_RISING; |
| 2912 | strmode = "rising"; |
| 2913 | break; |
| 2914 | case INT_EDGE_BOTH: |
| 2915 | config.flags |= (GPIO_V2_LINE_FLAG_EDGE_FALLING | GPIO_V2_LINE_FLAG_EDGE_RISING); |
| 2916 | strmode = "both"; |
| 2917 | break; |
| 2918 | } |
| 2919 | strcpy(req.consumer, "wiringpi_gpio_irq"); |
| 2920 | |
| 2921 | if (debounce_period_us) { |
| 2922 | attr = config.num_attrs; |
| 2923 | config.num_attrs++; |
| 2924 | gpiotools_set_bit(&config.attrs[attr].mask, 0); |
| 2925 | config.attrs[attr].attr.id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE; |
| 2926 | config.attrs[attr].attr.debounce_period_us = debounce_period_us; |
| 2927 | } |
| 2928 | |
| 2929 | req.num_lines = 1; |
| 2930 | req.event_buffer_size = 45; |
| 2931 | req.offsets[0] = pin; |
| 2932 | req.config = config; |
| 2933 | |
| 2934 | ret = ioctl(chipFd, GPIO_V2_GET_LINE_IOCTL, &req); |
| 2935 | if (ret == -1) { |
| 2936 | ReportDeviceError("interruptHandlerV2: get line event", pin , strmode, ret); |
no test coverage detected