Skip to content

Commit

Permalink
Merge pull request #5 from PelicanHu/master
Browse files Browse the repository at this point in the history
make ALT functions work, fix broken lines in readall
  • Loading branch information
xpertsavenue authored May 18, 2017
2 parents bc5e7e3 + fca0fed commit 7072222
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 61 deletions.
38 changes: 22 additions & 16 deletions gpio/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static int moduleLoaded (char *modName)
modName="i2c_sunxi";
}
/*end 2014.08.19*/

while (fgets (line, 80, fd) != NULL)
{
if (strncmp (line, modName, len) != 0)
Expand Down Expand Up @@ -182,12 +182,12 @@ static void doLoad (int argc, char *argv [])
char cmd [80] ;
char *file1, *file2 ;
char args1 [32], args2 [32] ;

if (argc < 3)
_doLoadUsage (argv) ;

args1 [0] = args2 [0] = 0 ;

/*add for BananaPro by LeMaker team*/
if(BPRVER == piBoardRev())
{
Expand Down Expand Up @@ -302,7 +302,7 @@ static void doI2Cdetect (int argc, char *argv [])
struct stat statBuf ;

/*add for BananaPro by LeMaker team*/
if(BPRVER == piBoardRev())
if(BPRVER == piBoardRev())
{
if (stat (I2CDETECT, &statBuf) < 0)
{
Expand Down Expand Up @@ -377,7 +377,7 @@ static void doExports (int argc, char *argv [])

if ((l = read (fd, buf, 16)) == 0)
sprintf (buf, "%s", "?") ;

buf [l] = 0 ;
if ((buf [strlen (buf) - 1]) == '\n')
buf [strlen (buf) - 1] = 0 ;
Expand Down Expand Up @@ -448,15 +448,15 @@ void doExport (int argc, char *argv [])
}

pin = atoi (argv [2]) ;

/*add for BananaPro by LeMaker team*/
if (pin == 0)
{
printf("%d is invalid pin,please check it over.\n",pin);
return ;
}
/*end 2014.08.19*/

mode = argv [3] ;

if ((fd = fopen ("/sys/class/gpio/export", "w")) == NULL)
Expand Down Expand Up @@ -567,14 +567,14 @@ void doEdge (int argc, char *argv [])

pin = atoi (argv [2]) ;
mode = argv [3] ;

/*add for BananaPro by LeMaker team*/
if (pin==0)
{
printf("%d is invalid pin,please check it over.\n",pin);
return ;
}
/*end 2014.08.19*/
/*end 2014.08.19*/

// Export the pin and set direction to input

Expand Down Expand Up @@ -652,15 +652,15 @@ void doUnexport (int argc, char *argv [])
}

pin = atoi (argv [2]) ;

/*add for BananaPro by LeMaker team*/
if (pin==0)
{
printf("%d is invalid pin,please check it over.\n",pin);
return ;
}
/*end 2014.08.19*/

if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL)
{
fprintf (stderr, "%s: Unable to open GPIO export interface\n", argv [0]) ;
Expand Down Expand Up @@ -776,6 +776,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
Expand Down Expand Up @@ -847,7 +853,7 @@ static void doUsbP (int argc, char *argv [])
fprintf (stderr, "USB power contol is applicable to B+ boards only.\n") ;
exit (1) ;
}

// Need to force BCM_GPIO mode:

wiringPiSetupGpio () ;
Expand Down Expand Up @@ -1034,7 +1040,7 @@ static void doWriteByte (int argc, char *argv [])
*********************************************************************************
*/

void doRead (int argc, char *argv [])
void doRead (int argc, char *argv [])
{
int pin, val ;

Expand All @@ -1057,7 +1063,7 @@ void doRead (int argc, char *argv [])
*********************************************************************************
*/

void doAread (int argc, char *argv [])
void doAread (int argc, char *argv [])
{
if (argc != 3)
{
Expand Down Expand Up @@ -1279,8 +1285,8 @@ int main (int argc, char *argv [])
}
else
{
printf ("Banana Pro Details:\n") ;
printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n",
printf ("Board details:\n") ;
printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n",
piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ;
}
return 0 ;
Expand Down
60 changes: 30 additions & 30 deletions gpio/readall.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ static void readallPhys (int physPin)
int pin ;

if (physPinToGpio (physPin) == -1)
printf (" | | ") ;
printf ("| | ") ;
else
printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;
printf ("| %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;

printf (" | %s", physNames [physPin]) ;

Expand Down Expand Up @@ -270,22 +270,22 @@ void abReadall (int model, int rev)
else
type = "B1" ;

printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf ("+-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
printf ("| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf ("+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 1 ; pin <= 26 ; pin += 2)
readallPhys (pin) ;

if (rev == PI_VERSION_2) // B version 2
{
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf ("+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 51 ; pin <= 54 ; pin += 2)
readallPhys (pin) ;
}

printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
printf ("+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf ("| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf ("+-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
}


Expand All @@ -299,29 +299,29 @@ void bPlusReadall (void)
{
int pin ;

printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf ("+-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
printf ("| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf ("+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 1 ; pin <= 40 ; pin += 2)
readallPhys (pin) ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
printf ("+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf ("| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf ("+-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
}

//add for BananaPro by lemaker team
void BPReadAll(void)
{
int pin ;

printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf ("+-----+-----+---------+------+---+--Banana Pro--+------+---------+-----+-----+\n") ;
printf ("| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf ("+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
for (pin = 1 ; pin <= 40 ; pin += 2)
readallPhys (pin) ;
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+---------+------+---+--Banana Pro--+---+------+---------+-----+-----+\n") ;
printf ("+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
printf ("| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf ("+-----+-----+---------+------+---+--Banana Pro--+------+---------+-----+-----+\n") ;
}
//end 2014.09.26

Expand All @@ -330,16 +330,16 @@ void OrangePiReadAll(void)
{
int pin ;

printf (" +-----+-----+----------+------+--Orange Pi Zero--+---+------+---------+-----+--+\n") ;
printf (" | H2+ | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | H2+ |\n") ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
printf ("+-----+-----+----------+------+--Orange Pi Zero--+------+----------+-----+-----+\n") ;
printf ("| H2+ | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | H2+ |\n") ;
printf ("+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
for (pin = 1 ; pin <= 26 ; pin += 2)
readallPhys (pin) ;
printf (" +-----+-----+----------+------+---+---LEDs---+---+------+----------+-----+-----+\n") ;
printf ("+-----+-----+----------+------+---+---LEDs---+---+------+----------+-----+-----+\n") ;
readallPhys (27) ;
printf (" +-----+-----+----------+------+---+-----+----+---+------+----------+-----+-----+\n") ;
printf (" | H2+ | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | H2+ |\n") ;
printf (" +-----+-----+----------+------+--Orange Pi Zero--+---+------+---------+-----+--+\n") ;
printf ("+-----+-----+----------+------+---+-----+----+---+------+----------+-----+-----+\n") ;
printf ("| H2+ | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | H2+ |\n") ;
printf ("+-----+-----+----------+------+--Orange Pi Zero--+---+------+---------+-----+--+\n") ;
}
// changed by Christian Beckert

Expand All @@ -361,8 +361,8 @@ void doReadall (void)
bPlusReadall () ;
else if (model == PI_MODEL_CM)
cmReadall () ;
else if (model == PI_MODEL_BPR) //add for BananaPro by lemaker team
OrangePiReadAll(); //guenter / // changed by Christian Beckert
else if (model == PI_MODEL_OPZ) //add for BananaPro by lemaker team
OrangePiReadAll(); //guenter / // changed by Christian Beckert
else
printf ("Oops - unable to determine board type... model: %d\n", model) ;
}
41 changes: 29 additions & 12 deletions wiringPi/wiringPi.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const char *piModelNames [6] =
"Model B",
"Model B+",
"Compute Module",
"Banana Pro", //add for BananaPro by LeMaker team
"Orange Pi Zero",
} ;

const char *piRevisionNames [5] =
Expand All @@ -269,13 +269,12 @@ const char *piRevisionNames [5] =
"2",
} ;

const char *piMakerNames [5] =
const char *piMakerNames [4] =
{
"Unknown",
"Egoman",
"Sony",
"Qusda",
"LeMaker", //add for BananaPro by LeMaker team
} ;


Expand Down Expand Up @@ -1062,6 +1061,15 @@ void sunxi_set_gpio_mode(int pin,int mode)
pwmSetMode(PWM_MODE_MS);
sunxi_pwm_set_clk(PWM_CLK_DIV_120);//default clk:24M/120
delayMicroseconds (200);
} else {
regval &= ~(7 << offset);
regval |= (mode << offset);
if (wiringPiDebug)
printf("ready set val: 0x%x\n", regval);
writel(regval, phyaddr);
regval = readl(phyaddr);
if (wiringPiDebug)
printf("set over reg val: 0x%x\n", regval);
}
}
else
Expand Down Expand Up @@ -1468,9 +1476,9 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 512 ; *maker = PI_MAKER_EGOMAN ; }
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
//add for BananaPro by LeMaker team
else if (strcmp (c, "0000") == 0) { *model = PI_MODEL_BPR; *rev = PI_VERSION_1_2; *mem = 1024; *maker = PI_MAKER_LEMAKER;}
//end 2014.09.30
//add for Orange Pi Zero by pel
else if (strcmp (c, "0000") == 0) { *model = PI_MODEL_OPZ; *rev = PI_VERSION_UNKNOWN; *mem = 512; *maker = PI_MAKER_UNKNOWN;}
//end
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
}

Expand Down Expand Up @@ -1841,12 +1849,21 @@ void pinEnableED01Pi (int pin)
void pinModeAlt (int pin, int mode)
{
int fSel, shift ;
/*add for BananaPro by LeMaker team*/
if (BPRVER == version)
{
return;
}
/*end 2014.08.19*/
if (BPRVER == version) { // fix for Banana and Orange Pi
if ((pin & PI_GPIO_MASK) == 0) { // On-board pin
if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio_BP[pin];
else if (wiringPiMode == WPI_MODE_PHYS)
pin = physToGpio_BP[pin];
else if (wiringPiMode == WPI_MODE_GPIO)
pin = pinTobcm_BP[pin];//need map A20 to bcm
else return;

if (-1 == pin) /*VCC or GND return directly*/
return;
sunxi_set_gpio_mode(pin, mode);
}
}

if ((pin & PI_GPIO_MASK) == 0) // On-board pin
{
Expand Down
5 changes: 2 additions & 3 deletions wiringPi/wiringPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#define PI_MODEL_B 2
#define PI_MODEL_BP 3
#define PI_MODEL_CM 4
#define PI_MODEL_BPR 5 //add for BananaPro by LeMaker team
#define PI_MODEL_OPZ 5

#define PI_VERSION_UNKNOWN 0
#define PI_VERSION_1 1
Expand All @@ -88,13 +88,12 @@
#define PI_MAKER_EGOMAN 1
#define PI_MAKER_SONY 2
#define PI_MAKER_QISDA 3
#define PI_MAKER_LEMAKER 4 //add for BananaPro by LeMaker team

#define BPRVER 3 //add for BananaPro by lemaker team

extern const char *piModelNames [6] ;
extern const char *piRevisionNames [5] ;
extern const char *piMakerNames [5] ;
extern const char *piMakerNames [4] ;


// Intended for the GPIO program Use at your own risk.
Expand Down

0 comments on commit 7072222

Please sign in to comment.