Added new SPI driver helpers.
Changed the gertboard code to use it and ran more tests on he Gertboard code.
This commit is contained in:
32
gpio/gpio.1
32
gpio/gpio.1
@@ -36,14 +36,23 @@ range
|
||||
.PP
|
||||
.B gpio
|
||||
.B load \ i2c/spi
|
||||
.PP
|
||||
.B gpio
|
||||
.B gbr
|
||||
channel
|
||||
.PP
|
||||
.B gpio
|
||||
.B gbw
|
||||
channel value
|
||||
|
||||
.SH DESCRIPTION
|
||||
|
||||
.B GPIO
|
||||
is a command line tool to allow the user easy access to the GPIO pins
|
||||
on the Raspberry Pi. It's designed for simple testing and diagnostic
|
||||
purposes, but can be used in shell scripts for general if somewhat slow
|
||||
control of the GPIO pins.
|
||||
is a swiss army knofe of a command line tool to allow the user easy
|
||||
access to the GPIO pins on the Raspberry Pi and the SPI A/D and D/A
|
||||
convertors on the Gertboard. It's designed for simple testing and
|
||||
diagnostic purposes, but can be used in shell scripts for general if
|
||||
somewhat slow control of the GPIO pins.
|
||||
|
||||
Additionally, it can be used to set the exports in the \fI/sys/class/gpio\fR
|
||||
system directory to allow subsequent programs to use the \fR/sys/class/gpio\fR
|
||||
@@ -142,6 +151,21 @@ Change the PWM range register. The default is 1024.
|
||||
This loads the i2c or the spi drivers into the system and changes the permissions on
|
||||
the associated /dev/ entries so that the current user has access to them.
|
||||
|
||||
.TP
|
||||
.B gbr
|
||||
channel
|
||||
|
||||
This reads the analog to digital convertor on the Gertboard on the given
|
||||
channel. The board jumpers need to be in-place to do this operation.
|
||||
|
||||
.TP
|
||||
.B gbw
|
||||
channel value
|
||||
|
||||
This writes the supplied value to the output channel on the Gertboards
|
||||
SPI digital to analogue convertor.
|
||||
The board jumpers need to be in-place to do this operation.
|
||||
|
||||
|
||||
.SH "WiringPi vs. GPIO Pin numbering"
|
||||
|
||||
|
||||
94
gpio/gpio.c
94
gpio/gpio.c
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* gpio.c:
|
||||
* Set-UID command-line interface to the Raspberry Pi's GPIO
|
||||
* Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
|
||||
* Pi's GPIO.
|
||||
* Copyright (c) 2012 Gordon Henderson
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
@@ -21,7 +22,6 @@
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <wiringPi.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -32,12 +32,15 @@
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <gertboard.h>
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (1==1)
|
||||
# define FALSE (1==2)
|
||||
#endif
|
||||
|
||||
#define VERSION "1.1"
|
||||
#define VERSION "1.2"
|
||||
|
||||
static int wpMode ;
|
||||
|
||||
@@ -49,7 +52,9 @@ char *usage = "Usage: gpio -v\n"
|
||||
" gpio drive <group> <value>\n"
|
||||
" gpio pwm-bal/pwm-ms \n"
|
||||
" gpio pwmr <range> \n"
|
||||
" gpio load spi/i2c" ;
|
||||
" gpio load spi/i2c\n"
|
||||
" gpio gbr <channel>\n"
|
||||
" gpio gbw <channel> <value>\n" ;
|
||||
|
||||
|
||||
/*
|
||||
@@ -518,6 +523,82 @@ static void doPadDrive (int argc, char *argv [])
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doGbw:
|
||||
* gpio gbw channel value
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doGbw (int argc, char *argv [])
|
||||
{
|
||||
int channel, value ;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s gbr <channel> <value>\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
channel = atoi (argv [2]) ;
|
||||
value = atoi (argv [3]) ;
|
||||
|
||||
if ((channel < 0) || (channel > 1))
|
||||
{
|
||||
fprintf (stderr, "%s: channel must be 0 or 1\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
if ((value < 0) || (value > 1023))
|
||||
{
|
||||
fprintf (stderr, "%s: value must be from 0 to 255\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
if (gertboardSPISetup () == -1)
|
||||
{
|
||||
fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
gertboardAnalogWrite (channel, value) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* doGbr:
|
||||
* gpio gbr channel
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void doGbr (int argc, char *argv [])
|
||||
{
|
||||
int channel ;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s gbr <channel>\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
channel = atoi (argv [2]) ;
|
||||
|
||||
if ((channel < 0) || (channel > 1))
|
||||
{
|
||||
fprintf (stderr, "%s: channel must be 0 or 1\n", argv [0]) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
if (gertboardSPISetup () == -1)
|
||||
{
|
||||
fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
printf ("%d\n",gertboardAnalogRead (channel)) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* doWrite:
|
||||
* gpio write pin value
|
||||
@@ -709,6 +790,11 @@ int main (int argc, char *argv [])
|
||||
if (strcasecmp (argv [1], "drive") == 0) { doPadDrive (argc, argv) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "load" ) == 0) { doLoad (argc, argv) ; return 0 ; }
|
||||
|
||||
// Gertboard commands
|
||||
|
||||
if (strcasecmp (argv [1], "gbr" ) == 0) { doGbr (argc, argv) ; return 0 ; }
|
||||
if (strcasecmp (argv [1], "gbw" ) == 0) { doGbw (argc, argv) ; return 0 ; }
|
||||
|
||||
// Check for -g argument
|
||||
|
||||
if (strcasecmp (argv [1], "-g") == 0)
|
||||
|
||||
Reference in New Issue
Block a user