Browse Source

Added command to set GPIO multiplexing function for allwinner soc

"gpio mode 1 alt7" command sets gpio to io_disable
pull/39/head
leeboby 4 years ago
parent
commit
081073390a
  1. 12
      gpio/gpio.c
  2. 28
      wiringPi/OrangePi.c
  3. 1
      wiringPi/OrangePi.h
  4. 34
      wiringPi/wiringPi.c

12
gpio/gpio.c

@ -889,12 +889,12 @@ 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) ;
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 if (strcasecmp (mode, "alt2") == 0) pinModeAlt (pin, 0b010) ;
else if (strcasecmp (mode, "alt3") == 0) pinModeAlt (pin, 0b011) ;
else if (strcasecmp (mode, "alt4") == 0) pinModeAlt (pin, 0b100) ;
else if (strcasecmp (mode, "alt5") == 0) pinModeAlt (pin, 0b101) ;
else if (strcasecmp (mode, "alt6") == 0) pinModeAlt (pin, 0b110) ;
else if (strcasecmp (mode, "alt7") == 0) pinModeAlt (pin, 0b111) ;
else
{
fprintf (stderr, "%s: Invalid mode: %s. Should be in/out/pwm/clock/up/down/tri\n", argv [1], mode) ;

28
wiringPi/OrangePi.c

@ -1996,6 +1996,34 @@ int OrangePi_set_gpio_mode(int pin, int mode)
return 0;
}
int OrangePi_set_gpio_alt(int pin, int mode)
{
unsigned int regval = 0;
unsigned int bank = pin >> 5;
unsigned int index = pin - (bank << 5);
unsigned int phyaddr = 0;
int offset = ((index - ((index >> 3) << 3)) << 2);
if (bank == 11) {
phyaddr = GPIOL_BASE + ((index >> 3) << 2);
}else
phyaddr = GPIO_BASE_MAP + (bank * 36) + ((index >> 3) << 2);
/* Ignore unused gpio */
if (ORANGEPI_PIN_MASK[bank][index] != -1) {
if (wiringPiDebug)
printf("Register[%#x]: %#x index:%d\n", phyaddr, regval, index);
regval = readR(phyaddr);
regval &= ~(7 << offset);
regval |= (mode << offset);
writeR(regval, phyaddr);
} else
printf("Pin alt mode failed!\n");
return 0;
}
/*
* OrangePi Digital write
*/

1
wiringPi/OrangePi.h

@ -233,6 +233,7 @@ extern int pwmmode;
extern unsigned int readR(unsigned int addr);
extern void writeR(unsigned int val, unsigned int addr);
extern int OrangePi_set_gpio_mode(int pin, int mode);
extern int OrangePi_set_gpio_alt(int pin, int mode);
extern int OrangePi_get_gpio_mode(int pin);
extern int isOrangePi_2G_IOT(void);
extern int isOrangePi(void);

34
wiringPi/wiringPi.c

@ -1338,6 +1338,40 @@ void pinModeAlt (int pin, int mode)
setupCheck ("pinModeAlt") ;
#ifdef CONFIG_ORANGEPI
if(version == ORANGEPI) {
if (wiringPiDebug)
printf("PinModeAlt: pin:%d,mode:%d\n", pin, mode);
if ((pin & PI_GPIO_MASK) == 0) {
if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio[pin];
else if (wiringPiMode == WPI_MODE_PHYS)
pin = physToGpio[pin];
else if (wiringPiMode != WPI_MODE_GPIO)
return;
if (-1 == pin) {
printf("[%s:L%d] the pin:%d is invaild,please check it over!\n",
__func__, __LINE__, pin);
return;
}
if ( mode <= 1 || mode >= 8){
printf("[%s:L%d] the mode:%d is invaild,please check it over!\n",
__func__, __LINE__, mode);
return;
}
OrangePi_set_gpio_alt(pin, mode);
return;
} else {
return ;
}
}
#endif
if ((pin & PI_GPIO_MASK) == 0) // On-board pin
{
/**/ if (wiringPiMode == WPI_MODE_PINS)

Loading…
Cancel
Save