Bladeren bron

Added full revision number to details. Did some code and commentary cleanup.

pull/158/head
Jim Parziale 2 jaren geleden
bovenliggende
commit
b147f74f8e
4 gewijzigde bestanden met toevoegingen van 31 en 35 verwijderingen
  1. +1
    -3
      gpio/gpio.1
  2. +14
    -27
      gpio/gpio.c
  3. +13
    -4
      wiringPi/wiringPi.c
  4. +3
    -1
      wiringPi/wiringPi.h

+ 1
- 3
gpio/gpio.1 Bestand weergeven

@@ -319,9 +319,7 @@ the GPIO from a non-root program, then you need to make sure that the
module \fIbcm2835_gpiomem\fR is loaded at boot time. This should happen module \fIbcm2835_gpiomem\fR is loaded at boot time. This should happen
automatically when you enable the device tree in raspi-config. You may automatically when you enable the device tree in raspi-config. You may
also need some additional information in /etc/udev/rules.d/ to change the also need some additional information in /etc/udev/rules.d/ to change the
mode and ownership of the /dev/gpiomem file. Finally, you need to set
the environment variable \fIWIRINGPI_GPIOMEM\fR. This will go-away
in future releases once the /dev/gpiomem interface is fully operational.
mode and ownership of the /dev/gpiomem file.


.SH "SEE ALSO" .SH "SEE ALSO"




+ 14
- 27
gpio/gpio.c Bestand weergeven

@@ -61,8 +61,8 @@ extern void doQmode (int argc, char *argv[]);
int wpMode; int wpMode;


char *usage = "Usage: gpio -v Show version info\n" char *usage = "Usage: gpio -v Show version info\n"
" gpio -h Show Help\n"
" gpio[-b|-p|-w] ... Use bcm-gpio/physical/WiringPi pin numbering scheme.\n"
" gpio -h|-help|--help|help|h Show Help\n"
" gpio [-b|-p|-w] ... Use bcm-gpio/physical/WiringPi pin numbering scheme.\n"
" If none specified, BCM GPIO numbering is used by default.\n" " If none specified, BCM GPIO numbering is used by default.\n"
" [-x extension:params][[ -x ...]] ...\n" " [-x extension:params][[ -x ...]] ...\n"
" gpio <mode/read/write/aread/awritewb/pwm/pwmTone/clock> ...\n" " gpio <mode/read/write/aread/awritewb/pwm/pwmTone/clock> ...\n"
@@ -82,33 +82,12 @@ char *usage = "Usage: gpio -v Show version info\n"
" gpio wb <value>\n" " gpio wb <value>\n"
" gpio usbp high/low"; // No trailing newline needed here. " gpio usbp high/low"; // No trailing newline needed here.


#ifdef NOT_FOR_NOW
/*
* decodePin:
* Decode a pin "number" which can actually be a pin name to represent
* one of the Pi's on-board pins.
*********************************************************************************
*/

static int decodePin (const char *str)
{

// The first case - see if it's a number:

if (isdigit (str[0]))
return atoi (str);

return 0;
}
#endif


/* /*
* findExecutable: * findExecutable:
* Code to locate the path to the given executable. We have a fixed list * Code to locate the path to the given executable. We have a fixed list
* of locations to try which completely overrides any $PATH environment. * of locations to try which completely overrides any $PATH environment.
* This may be detrimental, however it avoids the reliance on $PATH * This may be detrimental, however it avoids the reliance on $PATH
* which may be a security issue when this program is run a set-uid-root.
* which may be a security issue when this program is run as set-uid-root.
********************************************************************************* *********************************************************************************
*/ */
static const char *searchPath[] = static const char *searchPath[] =
@@ -1146,7 +1125,7 @@ static void doPwmClock (int argc, char *argv[])
/* /*
* doVersion: * doVersion:
* Handle the ever more complicated version command and print out * Handle the ever more complicated version command and print out
* some usefull information.
* some useful information.
********************************************************************************* *********************************************************************************
*/ */


@@ -1167,15 +1146,17 @@ static void doVersion (char *argv[])
printf ("For details type: \"%s -warranty\"\n", basename(argv[0])); printf ("For details type: \"%s -warranty\"\n", basename(argv[0]));
printf ("\n"); printf ("\n");


piBoardId (&model, &proc, &rev, &mem, &maker, &warranty);
uint32_t fullRev = piBoardId (&model, &proc, &rev, &mem, &maker, &warranty);


printf ("Raspberry Pi Details\n" printf ("Raspberry Pi Details\n"
" Revision string: 0x%08X\n"
" Type : %s\n" " Type : %s\n"
" Processor: %s\n" " Processor: %s\n"
" Revision : %s\n" " Revision : %s\n"
" Memory : %s\n" " Memory : %s\n"
" Maker : %s\n" " Maker : %s\n"
" %s\n", " %s\n",
fullRev,
piModelNames[model], piModelNames[model],
piProcessorNames[proc], piProcessorNames[proc],
piRevisionNames[rev], piRevisionNames[rev],
@@ -1238,7 +1219,13 @@ int main (int argc, char *argv[])
} }


// Help // Help
if (strcasecmp (argv[1], "-h") == 0)
if (
(strcasecmp (argv[1], "h") == 0) ||
(strcasecmp (argv[1], "-h") == 0) ||
(strcasecmp (argv[1], "-help") == 0) ||
(strcasecmp (argv[1], "--help") == 0) ||
(strcasecmp (argv[1], "help") == 0)
)
{ {
printf ("%s\n", usage); printf ("%s\n", usage);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);


+ 13
- 4
wiringPi/wiringPi.c Bestand weergeven

@@ -83,7 +83,6 @@
// Environment Variables // Environment Variables
#define ENV_DEBUG "WIRINGPI_DEBUG" #define ENV_DEBUG "WIRINGPI_DEBUG"
#define ENV_CODES "WIRINGPI_CODES" #define ENV_CODES "WIRINGPI_CODES"
#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"




// Extend wiringPi with other pin-based devices and keep track of // Extend wiringPi with other pin-based devices and keep track of
@@ -93,6 +92,8 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL;
// BCM Magic // BCM Magic
#define BCM_PASSWORD 0x5A000000 #define BCM_PASSWORD 0x5A000000


// Full revision string
static uint32_t fullRevision = 0;


// The BCM2835 has 54 GPIO pins. // The BCM2835 has 54 GPIO pins.
// BCM2835 data sheet, Page 90 onwards. // BCM2835 data sheet, Page 90 onwards.
@@ -879,7 +880,7 @@ int piGpioLayout (void)
********************************************************************************* *********************************************************************************
*/ */


void piBoardId (int *model, int *proc, int *rev, int *mem, int *maker, int *warranty)
uint32_t piBoardId (int *model, int *proc, int *rev, int *mem, int *maker, int *warranty)
{ {
FILE *cpuFd; FILE *cpuFd;
char line[120]; char line[120];
@@ -928,12 +929,14 @@ void piBoardId (int *model, int *proc, int *rev, int *mem, int *maker, int *warr
piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)"); piGpioLayoutOops ("Bogus \"Revision\" line (no hex digit at start of revision)");


revision = (unsigned int)strtol (c, NULL, 16); // Hex number with no leading 0x revision = (unsigned int)strtol (c, NULL, 16); // Hex number with no leading 0x
// Save full revision number
fullRevision = revision;


// Check for new way: Bit 23 of the revision number // Check for new way: Bit 23 of the revision number
if ((revision & (1 << 23)) != 0) // New way if ((revision & (1 << 23)) != 0) // New way
{ {
if (wiringPiDebug) if (wiringPiDebug)
printf ("piBoardId: New Way: revision is: %08X\n", revision);
printf ("piBoardId: New Way: revision is: 0x%08X\n", revision);


bRev = (revision & (0x0F << 0)) >> 0; bRev = (revision & (0x0F << 0)) >> 0;
bType = (revision & (0xFF << 4)) >> 4; bType = (revision & (0xFF << 4)) >> 4;
@@ -1007,6 +1010,8 @@ void piBoardId (int *model, int *proc, int *rev, int *mem, int *maker, int *warr


else { *model = 0 ; *rev = 0 ; *mem = 0; *maker = 0; } else { *model = 0 ; *rev = 0 ; *mem = 0; *maker = 0; }
} }

return fullRevision;
} }




@@ -1135,7 +1140,11 @@ void pwmSetClock (int divisor)
{ {
divisor = 540*divisor/192; divisor = 540*divisor/192;
} }
divisor &= 4095; // @XXX @TODO Probably constrain to 0xFFF instead of masking?
// Keep divisor in range.
if (divisor > 4095)
{
divisor = 4095;
}


if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO)) if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO))
{ {


+ 3
- 1
wiringPi/wiringPi.h Bestand weergeven

@@ -24,6 +24,8 @@
#ifndef __WIRING_PI_H__ #ifndef __WIRING_PI_H__
#define __WIRING_PI_H__ #define __WIRING_PI_H__


#include <stdint.h>

#include <stdbool.h> #include <stdbool.h>
#ifndef TRUE #ifndef TRUE
# define TRUE true # define TRUE true
@@ -236,7 +238,7 @@ extern void analogWrite (int pin, int value);


// On-Board Raspberry Pi hardware specific stuff // On-Board Raspberry Pi hardware specific stuff
extern int piGpioLayout (void); extern int piGpioLayout (void);
extern void piBoardId (int *model, int *proc, int *rev, int *mem, int *maker, int *overVolted);
extern uint32_t piBoardId (int *model, int *proc, int *rev, int *mem, int *maker, int *overVolted);
extern int wpiPinToGpio (int wpiPin); extern int wpiPinToGpio (int wpiPin);
extern int physPinToGpio (int physPin); extern int physPinToGpio (int physPin);
extern void setPadDrive (int group, int value); extern void setPadDrive (int group, int value);


Laden…
Annuleren
Opslaan