29 #include <sys/types.h> 36 #include "rnr/rnrconfig.h" 72 "<gpio> byte [byte...]",
75 "Bit-bang bit pattern out GPIO pin.",
78 "The %P command writes the specified bit pattern to the GPIO at the given " 80 "A bit value of 0 sets the pin low. " 81 "A bit value of 1 set the pin high." 82 "The byte pattern is specified as a series of byte arguments of any of the " 84 " 0xH[H] hexidecimal examples: 0x5 0x3C 0xff\n" 85 " 0bB[B...] binary examples: 0b00000101 0b001111 0b11111111\n" 86 " D[D...] unsigned integer examples: 5 60 255",
108 "Inter-bit delay in microseconds. A 0 value means no delay." 123 "GPIO access method. One of: sysfs mmap." 130 static int strToInt(
const string &str,
int &val)
134 if( sscanf(str.c_str(),
"%lli", &val1) != 1 )
144 static int strToBits(
const string &str, byte_t *p)
151 if( str.substr(0, 2) ==
"0b" )
153 s = str.substr(2, str.size()-2);
155 for(i=0; i<8 & i<s.size(); ++i)
161 else if( s[i] !=
'0' )
170 if( sscanf(str.c_str(),
"%i", &val) != 1 )
196 Argv0 = basename(argv[0]);
203 fprintf(stderr,
"%s: No GPIO pin number <gpio> specified.\n",
Argv0);
204 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
208 else if( strToInt(argv[0],
ArgsGpio) < 0 )
210 fprintf(stderr,
"%s: '%s': Bad GPIO number.\n",
Argv0, argv[0]);
211 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
217 fprintf(stderr,
"%s: No bit pattern specified.\n",
Argv0);
218 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
228 if( strToBits(argv[i], p) < 0 )
230 fprintf(stderr,
"%s: '%s': Bad bit pattern %d.\n",
Argv0, argv[i], i);
231 fprintf(stderr,
"Try '%s --help' for more information.\n",
Argv0);
276 static int mmapBitBang()
280 if( mmapGpioMap() < 0 )
308 int main(
int argc,
char* argv[])
316 printf(
"Bit banging pattern to GPIO %d.\n",
ArgsGpio);
317 printf(
" Pattern: ");
323 printf(
" Ibd: %u usec\n",
OptsIbd);
337 fprintf(stderr,
"%s: Unknown GPIO access method.",
OptsMethod);
#define APP_EC_EXEC
execution exit code
static void mainInit(int argc, char *argv[])
Main initialization.
int main(int argc, char *argv[])
Main.
int gpioOpen(int gpio)
Open GPIO pin.
#define APP_EC_OK
success exit code
GPIO interface declarations and defines.
static OptsInfo_T OptsInfo[]
Command line options information.
#define APP_EC_ARGS
command-line options/arguments error exit code
static int sysfsBitBang()
Bit bang bit pattern.
static char * OptsMethod
system file system
int gpioBitBang(int fd, byte_t pattern[], size_t bitCount, unsigned int usecIbd)
Bit-bang bits out a GPIO pin.
static byte_t * ArgsPattern
bit pattern to write
static size_t PatByteCount
pattern byte count
int gpioClose(int fd)
Close GPIO pin.
static int ArgsGpio
gpio number
static size_t PatBitCount
pattern bit count
static const PkgInfo_T PkgInfo
static char * Argv0
the command
Package version information.
static int OptsIbd
inter-bit delay
static OptsPgmInfo_T PgmInfo
Program information.