29 #include <sys/types.h> 36 #include "rnr/rnrconfig.h" 71 "Set GPIO pin direction.",
74 "The %P command sets the direction for the GPIO associated with the given " 75 "<gpio> exported number." 76 "An input (in) direction allows for the value of the GPIO to be read. " 77 "An output (out) direction allows for writing of values to the GPIO.",
100 "GPIO access method. One of: sysfs mmap." 107 static int strToInt(
const string &str,
int &val)
111 if( sscanf(str.c_str(),
"%lli", &val1) != 1 )
133 Argv0 = basename(argv[0]);
140 fprintf(stderr,
"%s: No GPIO pin number <gpio> specified.\n",
Argv0);
141 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
145 else if( strToInt(argv[0],
ArgsGpio) < 0 )
147 fprintf(stderr,
"%s: '%s': Bad GPIO number.\n",
Argv0, argv[0]);
148 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
154 fprintf(stderr,
"%s: No GPIO direction specified.\n",
Argv0);
155 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
168 fprintf(stderr,
"%s: '%s': Bad direction.\n",
Argv0, argv[1]);
169 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
205 static int mmapSetDirection()
209 if( mmapGpioMap() < 0 )
237 int main(
int argc,
char* argv[])
250 ec = mmapSetDirection();
255 fprintf(stderr,
"%s: Unknown GPIO access method.",
OptsMethod);
static int ArgsDirection
gpio direction
#define APP_EC_ARGS
command-line options/arguments error exit code
GPIO interface declarations and defines.
#define APP_EC_EXEC
execution exit code
#define GPIO_DIR_OUT_STR
output string
static char * OptsMethod
system file system
static OptsPgmInfo_T PgmInfo
Program information.
static char * Argv0
the command
static void mainInit(int argc, char *argv[])
Main initialization.
int main(int argc, char *argv[])
Main.
#define GPIO_DIR_OUT
output
static const PkgInfo_T PkgInfo
#define GPIO_DIR_IN_STR
input string
static OptsInfo_T OptsInfo[]
Command line options information.
Package version information.
static int ArgsGpio
gpio number
int gpioSetDirection(int gpio, int dir)
Set GPIO signal direction.
#define APP_EC_OK
success exit code
static int sysfsSetDirection()
Set GPIO directiion.