29 #include <sys/types.h> 37 #include "rnr/rnrconfig.h" 70 "Safely probe GPIO settings and state.",
73 "The %P command probes the settings and state of GPIO exported number.",
96 "GPIO access method. One of: sysfs mmap." 103 static int strToInt(
const string &str,
int &val)
107 if( sscanf(str.c_str(),
"%lli", &val1) != 1 )
117 static int strToBits(
const string &str, byte_t *p)
124 if( str.substr(0, 2) ==
"0b" )
126 s = str.substr(2, str.size()-2);
128 for(i=0; i<8 & i<s.size(); ++i)
134 else if( s[i] !=
'0' )
143 if( sscanf(str.c_str(),
"%i", &val) != 1 )
166 Argv0 = basename(argv[0]);
173 fprintf(stderr,
"%s: No exported GPIO/header pin number specified.\n",
175 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
179 else if( strToInt(argv[0],
ArgsGpio) < 0 )
181 fprintf(stderr,
"%s: '%s': Bad GPIO number.\n",
Argv0, argv[0]);
182 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
212 static int sysfsProbeAndPrint()
222 fprintf(stderr,
"Error: sysfs GPIO Probe failed.\n");
226 printf(
"GPIO Info\n");
227 printf(
" exported gpio number: %d\n", info.
gpio);
230 printf(
" external pin number: %d\n", info.
pin);
234 printf(
" external pin number: N/A\n");
249 printf(
" direction: %s\n", s);
269 printf(
" edge: %s\n", s);
271 printf(
" pull: N/A\n");
272 printf(
" value: %d\n", info.
value);
285 static int mmapProbe(mmap_gpio_info_t *pInfo)
289 if( mmapGpioMap() < 0 )
294 if( mmapGpioProbe(
ArgsGpio, pInfo) < 0 )
308 static int mmapProbeAndPrint()
310 mmap_gpio_info_t info;
314 ec = mmapProbe(&info);
318 fprintf(stderr,
"Error: mmapped GPIO Probe failed.\n");
322 printf(
"GPIO Info\n");
323 printf(
" exported gpio number: %d\n", info.gpio);
326 printf(
" external pin number: %d\n", info.pin);
330 printf(
" external pin number: N/A\n");
333 printf(
" mmap base address: 0x%lx\n", info.base);
334 printf(
" mmap channel offset: 0x%x\n", info.channel);
335 printf(
" mmap bit: %d\n", info.bit);
349 printf(
" direction: %s\n", s);
369 printf(
" edge: %s\n", s);
383 printf(
" pull: %s\n", s);
385 printf(
" value: %d\n", info.value);
400 int main(
int argc,
char* argv[])
408 ec = sysfsProbeAndPrint();
413 ec = mmapProbeAndPrint();
418 fprintf(stderr,
"%s: Unknown GPIO access method.",
OptsMethod);
#define GPIO_EDGE_FALLING
falling edge
#define GPIO_PULL_DN_STR
enable pulldown string
static int ArgsGpio
gpio number
int gpio
sysfs exported gpio number
static void mainInit(int argc, char *argv[])
Main initialization.
GPIO interface declarations and defines.
int gpioProbe(int gpio, gpio_info_t *p)
Safely probe GPIO parameters.
#define GPIO_EDGE_BOTH
both edges
#define GPIO_EDGE_FALLING_STR
falling edge string
#define GPIO_PULL_DS_STR
disable pullup/down string
static char * OptsMethod
system file system
#define GPIO_PULL_UP_STR
enable pullup string
#define APP_EC_OK
success exit code
#define GPIO_DIR_OUT_STR
output string
int edge
gpio edge type trigger
static char * Argv0
the command
static OptsPgmInfo_T PgmInfo
Program information.
#define GPIO_EDGE_BOTH_STR
both edges string
#define GPIO_EDGE_NONE_STR
no edge string
#define APP_EC_EXEC
execution exit code
#define GPIO_PULL_DN
enable pulldown
#define GPIO_DIR_OUT
output
static const PkgInfo_T PkgInfo
#define GPIO_DIR_IN_STR
input string
#define GPIO_EDGE_NONE
no edge
static int sysfsProbe(gpio_info_t *pInfo)
Probe GPIO state.
int pin
external header pin number
Package version information.
#define GPIO_EDGE_RISING_STR
rising edge string
#define APP_EC_ARGS
command-line options/arguments error exit code
#define GPIO_EDGE_RISING
rising edge
int main(int argc, char *argv[])
Main.
static OptsInfo_T OptsInfo[]
Command line options information.
#define GPIO_PULL_UP
enable pullup