26
26
#include "gpio-utils.h"
27
27
28
28
int monitor_device (const char * device_name ,
29
- unsigned int line ,
29
+ unsigned int * lines ,
30
+ unsigned int num_lines ,
30
31
struct gpio_v2_line_config * config ,
31
32
unsigned int loops )
32
33
{
@@ -47,16 +48,18 @@ int monitor_device(const char *device_name,
47
48
goto exit_free_name ;
48
49
}
49
50
50
- ret = gpiotools_request_line (device_name , & line , 1 , config ,
51
+ ret = gpiotools_request_line (device_name , lines , num_lines , config ,
51
52
"gpio-event-mon" );
52
53
if (ret < 0 )
53
54
goto exit_device_close ;
54
55
else
55
56
lfd = ret ;
56
57
57
58
/* Read initial states */
58
- values .mask = 1 ;
59
+ values .mask = 0 ;
59
60
values .bits = 0 ;
61
+ for (i = 0 ; i < num_lines ; i ++ )
62
+ gpiotools_set_bit (& values .mask , i );
60
63
ret = gpiotools_get_values (lfd , & values );
61
64
if (ret < 0 ) {
62
65
fprintf (stderr ,
@@ -65,9 +68,23 @@ int monitor_device(const char *device_name,
65
68
goto exit_line_close ;
66
69
}
67
70
68
- fprintf (stdout , "Monitoring line %d on %s\n" , line , device_name );
69
- fprintf (stdout , "Initial line value: %d\n" ,
70
- gpiotools_test_bit (values .bits , 0 ));
71
+ if (num_lines == 1 ) {
72
+ fprintf (stdout , "Monitoring line %d on %s\n" , lines [0 ], device_name );
73
+ fprintf (stdout , "Initial line value: %d\n" ,
74
+ gpiotools_test_bit (values .bits , 0 ));
75
+ } else {
76
+ fprintf (stdout , "Monitoring lines %d" , lines [0 ]);
77
+ for (i = 1 ; i < num_lines - 1 ; i ++ )
78
+ fprintf (stdout , ", %d" , lines [i ]);
79
+ fprintf (stdout , " and %d on %s\n" , lines [i ], device_name );
80
+ fprintf (stdout , "Initial line values: %d" ,
81
+ gpiotools_test_bit (values .bits , 0 ));
82
+ for (i = 1 ; i < num_lines - 1 ; i ++ )
83
+ fprintf (stdout , ", %d" ,
84
+ gpiotools_test_bit (values .bits , i ));
85
+ fprintf (stdout , " and %d\n" ,
86
+ gpiotools_test_bit (values .bits , i ));
87
+ }
71
88
72
89
while (1 ) {
73
90
struct gpio_v2_line_event event ;
@@ -126,7 +143,7 @@ void print_usage(void)
126
143
fprintf (stderr , "Usage: gpio-event-mon [options]...\n"
127
144
"Listen to events on GPIO lines, 0->1 1->0\n"
128
145
" -n <name> Listen on GPIOs on a named device (must be stated)\n"
129
- " -o <n> Offset to monitor\n"
146
+ " -o <n> Offset of line to monitor (may be repeated) \n"
130
147
" -d Set line as open drain\n"
131
148
" -s Set line as open source\n"
132
149
" -r Listen for rising edges\n"
@@ -146,7 +163,8 @@ void print_usage(void)
146
163
int main (int argc , char * * argv )
147
164
{
148
165
const char * device_name = NULL ;
149
- unsigned int line = -1 ;
166
+ unsigned int lines [GPIO_V2_LINES_MAX ];
167
+ unsigned int num_lines = 0 ;
150
168
unsigned int loops = 0 ;
151
169
struct gpio_v2_line_config config ;
152
170
int c ;
@@ -162,7 +180,12 @@ int main(int argc, char **argv)
162
180
device_name = optarg ;
163
181
break ;
164
182
case 'o' :
165
- line = strtoul (optarg , NULL , 10 );
183
+ if (num_lines >= GPIO_V2_LINES_MAX ) {
184
+ print_usage ();
185
+ return -1 ;
186
+ }
187
+ lines [num_lines ] = strtoul (optarg , NULL , 10 );
188
+ num_lines ++ ;
166
189
break ;
167
190
case 'd' :
168
191
config .flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN ;
@@ -182,7 +205,7 @@ int main(int argc, char **argv)
182
205
}
183
206
}
184
207
185
- if (!device_name || line == -1 ) {
208
+ if (!device_name || num_lines == 0 ) {
186
209
print_usage ();
187
210
return -1 ;
188
211
}
@@ -191,5 +214,5 @@ int main(int argc, char **argv)
191
214
"falling edges\n" );
192
215
config .flags |= EDGE_FLAGS ;
193
216
}
194
- return monitor_device (device_name , line , & config , loops );
217
+ return monitor_device (device_name , lines , num_lines , & config , loops );
195
218
}
0 commit comments