Ver a proveniência

Added some tweaks to gpio to set alt modes on pins (sssh!)

pull/22/head
Gordon Henderson há 11 anos
ascendente
cometimento
f18c8f7204
3 ficheiros alterados com 56 adições e 2 eliminações
  1. +29
    -1
      gpio/gpio.c
  2. +26
    -1
      wiringPi/wiringPi.c
  3. +1
    -0
      wiringPi/wiringPi.h

+ 29
- 1
gpio/gpio.c Ver ficheiro

@@ -51,7 +51,7 @@ extern void doReadallOld (void) ;
# define FALSE (1==2)
#endif

#define VERSION "2.12"
#define VERSION "2.13"
#define I2CDETECT "/usr/sbin/i2cdetect"

int wpMode ;
@@ -76,6 +76,25 @@ char *usage = "Usage: gpio -v\n"


/*
* 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 ;
}


/*
* changeOwner:
* Change the ownership of the file to the real userId of the calling
* program so we can access it.
@@ -639,6 +658,15 @@ void doMode (int argc, char *argv [])
else if (strcasecmp (mode, "down") == 0) pullUpDnControl (pin, PUD_DOWN) ;
else if (strcasecmp (mode, "tri") == 0) pullUpDnControl (pin, PUD_OFF) ;
else if (strcasecmp (mode, "off") == 0) pullUpDnControl (pin, PUD_OFF) ;

// Undocumented

else if (strcasecmp (mode, "alt0") == 0) pinModeAlt (pin, 0b100) ;
else if (strcasecmp (mode, "alt1") == 0) pinModeAlt (pin, 0b101) ;
else if (strcasecmp (mode, "alt2") == 0) pinModeAlt (pin, 0b110) ;
else if (strcasecmp (mode, "alt3") == 0) pinModeAlt (pin, 0b111) ;
else if (strcasecmp (mode, "alt4") == 0) pinModeAlt (pin, 0b011) ;
else if (strcasecmp (mode, "alt5") == 0) pinModeAlt (pin, 0b010) ;
else
{
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;


+ 26
- 1
wiringPi/wiringPi.c Ver ficheiro

@@ -118,7 +118,6 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ;
#define FSEL_INPT 0b000
#define FSEL_OUTP 0b001
#define FSEL_ALT0 0b100
#define FSEL_ALT0 0b100
#define FSEL_ALT1 0b101
#define FSEL_ALT2 0b110
#define FSEL_ALT3 0b111
@@ -925,6 +924,32 @@ void pinEnableED01Pi (int pin)
*********************************************************************************
*/

/*
* pinModeAlt:
* This is an un-documented special to let you set any pin to any mode
*********************************************************************************
*/

void pinModeAlt (int pin, int mode)
{
int fSel, shift ;

if ((pin & PI_GPIO_MASK) == 0) // On-board pin
{
/**/ if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio [pin] ;
else if (wiringPiMode == WPI_MODE_PHYS)
pin = physToGpio [pin] ;
else if (wiringPiMode != WPI_MODE_GPIO)
return ;

fSel = gpioToGPFSEL [pin] ;
shift = gpioToShift [pin] ;

*(gpio + fSel) = (*(gpio + fSel) & ~(7 << shift)) | ((mode & 0x7) << shift) ;
}
}


/*
* pinMode:


+ 1
- 0
wiringPi/wiringPi.h Ver ficheiro

@@ -129,6 +129,7 @@ extern int wiringPiSetupSys (void) ;
extern int wiringPiSetupGpio (void) ;
extern int wiringPiSetupPhys (void) ;

extern void pinModeAlt (int pin, int mode) ;
extern void pinMode (int pin, int mode) ;
extern void pullUpDnControl (int pin, int pud) ;
extern int digitalRead (int pin) ;


Carregando…
Cancelar
Guardar