@@ -170,12 +170,17 @@ int add_fd_list(unsigned int gpio, int fd)
170170int open_value_file (unsigned int gpio )
171171{
172172 int fd ;
173- char filename [40 ];
173+ char filename [MAX_FILENAME ];
174174
175175 // create file descriptor of value file
176- snprintf (filename , sizeof (filename ), "/sys/class/gpio/gpio%d/value" , gpio );
176+ if ((gpio >= USR_LED_GPIO_MIN ) && (gpio <= USR_LED_GPIO_MAX )) {
177+ snprintf (filename , sizeof (filename ), "/sys/class/leds/beaglebone:green:usr%d/brightness" , gpio - USR_LED_GPIO_MIN );
178+ } else {
179+ snprintf (filename , sizeof (filename ), "/sys/class/gpio/gpio%d/value" , gpio );
180+ }
181+
177182 if ((fd = open (filename , O_RDONLY | O_NONBLOCK )) < 0 )
178- return -1 ;
183+ return -1 ;
179184 add_fd_list (gpio , fd );
180185 return fd ;
181186}
@@ -262,10 +267,14 @@ int gpio_get_direction(unsigned int gpio, unsigned int *value)
262267int gpio_set_value (unsigned int gpio , unsigned int value )
263268{
264269 int fd ;
265- char filename [40 ];
270+ char filename [MAX_FILENAME ];
266271 char vstr [10 ];
267272
268- snprintf (filename , sizeof (filename ), "/sys/class/gpio/gpio%d/value" , gpio );
273+ if ((gpio >= USR_LED_GPIO_MIN ) && (gpio <= USR_LED_GPIO_MAX )) {
274+ snprintf (filename , sizeof (filename ), "/sys/class/leds/beaglebone:green:usr%d/brightness" , gpio - USR_LED_GPIO_MIN );
275+ } else {
276+ snprintf (filename , sizeof (filename ), "/sys/class/gpio/gpio%d/value" , gpio );
277+ }
269278
270279 if ((fd = open (filename , O_WRONLY )) < 0 )
271280 return -1 ;
0 commit comments