Apply better code formatting

- code formatting for ease of reading code structures 
- code formatting for defines
- code formatting for pins arrays
- general code formatting fixes
This commit is contained in:
Nazar 2019-04-12 16:06:05 +03:00
parent 0464ba6da0
commit b140ff3f9d
3 changed files with 640 additions and 673 deletions

1
build
View File

@ -45,7 +45,6 @@ if [ x$1 = "xuninstall" ]; then
exit
fi
echo "wiringPi Build script"
echo "====================="
echo

View File

@ -106,7 +106,10 @@ static int getFieldValueInCpuInfo(char* hardware, int hardwareMaxLen, char* revi
} else {
j = 0;
for (i = 0; i < strlen(lineUntrim); i++) {
if (lineUntrim[i] == ' ' || lineUntrim[i] == '\t' || lineUntrim[i] == '\r' || lineUntrim[i] == '\n') {
if (lineUntrim[i] == ' '
|| lineUntrim[i] == '\t'
|| lineUntrim[i] == '\r'
|| lineUntrim[i] == '\n') {
} else {
line[j++]=lineUntrim[i];
}
@ -162,7 +165,10 @@ static int getAllwinnerBoardID(char* boardId, int boardIdMaxLen )
} else {
j = 0;
for (i = 0; i < strlen(lineUntrim); i++) {
if (lineUntrim[i] == ' ' || lineUntrim[i] == '\t' || lineUntrim[i] == '\r' || lineUntrim[i] == '\n') {
if (lineUntrim[i] == ' '
|| lineUntrim[i] == '\t'
|| lineUntrim[i] == '\r'
|| lineUntrim[i] == '\n') {
} else {
line[j++]=lineUntrim[i];
}
@ -213,9 +219,12 @@ int getBoardType(BoardHardwareInfo** retBoardInfo) {
const char* h5_kernel4 = "Allwinnersun50iw2Family";
//a64 and amlogic, only check hardware
if (strncasecmp(hardware, a64, strlen(a64)) == 0 || strncasecmp(hardware, amlogic, strlen(amlogic)) == 0) {
if (strncasecmp(hardware, a64, strlen(a64)) == 0
|| strncasecmp(hardware, amlogic, strlen(amlogic)) == 0) {
for (i = 0; i < (sizeof(gAllBoardHardwareInfo)/sizeof(BoardHardwareInfo)); i++) {
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware, hardware, strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware,
hardware,
strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
if (retBoardInfo != 0) {
*retBoardInfo = &gAllBoardHardwareInfo[i];
}
@ -233,9 +242,13 @@ int getBoardType(BoardHardwareInfo** retBoardInfo) {
//LOGD("got boardid: %s\n", allwinnerBoardID);
for (i = 0; i < (sizeof(gAllBoardHardwareInfo)/sizeof(BoardHardwareInfo)); i++) {
//LOGD("\t{{ enum, start compare[%d]: %s <--> %s\n", i, gAllBoardHardwareInfo[i].kernelHardware, hardware);
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware, hardware, strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware,
hardware,
strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
//LOGD("\t\tMATCH %s\n", hardware);
if (strncasecmp(gAllBoardHardwareInfo[i].allwinnerBoardID, allwinnerBoardID, strlen(gAllBoardHardwareInfo[i].allwinnerBoardID)) == 0) {
if (strncasecmp(gAllBoardHardwareInfo[i].allwinnerBoardID,
allwinnerBoardID,
strlen(gAllBoardHardwareInfo[i].allwinnerBoardID)) == 0) {
if (retBoardInfo != 0) {
*retBoardInfo = &gAllBoardHardwareInfo[i];
}

View File

@ -217,7 +217,6 @@ static volatile uint32_t *timerIrqRaw;
#define SUNXI_PWM_CH1_MS_MODE (1 << 22) // pulse mode
#define SUNXI_PWM_CH1_PUL_START (1 << 23)
#define PWM_CLK_DIV_120 0
#define PWM_CLK_DIV_180 1
#define PWM_CLK_DIV_240 2
@ -278,7 +277,6 @@ static int sysFds [MAX_PIN_COUNT] ={
//static void (*isrFunctions [64])(void);
static int upDnConvert[3] = {7, 7, 5};
static int *pinToGpio = 0;
@ -310,7 +308,7 @@ static int *syspin = 0;
static int pinToGpio_m1 [MAX_PIN_COUNT] ={
0, 6, // 0, 1
2, 3, // 2, 3
200, 201, // 4 5
200, 201, // 4, 5
1, 203, // 6, 7
12, 11, // 8, 9
67, 17, // 10, 11
@ -324,11 +322,9 @@ static int pinToGpio_m1 [MAX_PIN_COUNT] ={
7, 16, // 26, 27
15, 14, // 28, 29
19, 18, // 30, 31
4, 5, // 32, 33 Debug UART pins
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
@ -349,7 +345,6 @@ static int pinToGpio_neo [MAX_PIN_COUNT] ={
17, -1, // 19, 20
-1, 1, // 21, 22
-1, -1, // 23, 24
/* 12 Pin */
-1, -1, // 25, 26
-1, -1, // 27, 28
@ -357,14 +352,11 @@ static int pinToGpio_neo [MAX_PIN_COUNT] ={
-1, -1, // 31, 32
-1, -1, // 33, 34
-1, -1, // 35, 36
/* UART0 Tx, Rx */
-1, -1, // 37, 38
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
@ -391,17 +383,13 @@ static int pinToGpio_duo [MAX_PIN_COUNT] ={
-1, -1, // 29, 30
-1, -1, // 31, 32
/* ---------nanopi duo end----------- */
-1, -1, // 33, 34
-1, -1, // 35, 36
/* UART0 Tx,Rx */
-1, -1, // 37, 38
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
@ -427,17 +415,13 @@ static int pinToGpio_duo2 [MAX_PIN_COUNT] ={
-1, -1, // 29, 30
-1, -1, // 31, 32
/* ---------nanopi duo end----------- */
-1, -1, // 33, 34
-1, -1, // 35, 36
/* UART0 Tx,Rx */
-1, -1, // 37, 38
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
@ -464,11 +448,9 @@ static int pinToGpio_neocore [MAX_PIN_COUNT] ={
-1, -1, // 33, 34
-1, -1, // 35, 36
-1, -1, // 37, 38
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
@ -818,7 +800,6 @@ static int physToPin_neo [MAX_PIN_COUNT] = //return wiringPI pin
19, -1, // 31, 32
-1, -1, // 33, 34
-1, -1, // 35, 36
17, 18, // 37, 38
/* 39~63 */
@ -901,7 +882,6 @@ static int physToPin_duo [MAX_PIN_COUNT] = //return wiringPI pin //note: same as
/* ---------nanopi duo end----------- */
-1, -1, // 33, 34
-1, -1, // 35, 36
-1, -1, // 37, 38
/* 39~63 */
@ -934,7 +914,6 @@ static int physToPin_duo2 [MAX_PIN_COUNT] = //return wiringPI pin //note: same a
/* ---------nanopi duo end----------- */
-1, -1, // 33, 34
-1, -1, // 35, 36
-1, -1, // 37, 38
/* 39~63 */
@ -1548,7 +1527,6 @@ int getAlt(int pin) {
}
alt = sunxi_get_gpio_mode(pin);
return alt;
}
int getAltSilence(int pin) {
@ -1733,7 +1711,6 @@ void pinModeAlt(int pin, int mode) {
*/
void pinMode(int pin, int mode) {
struct wiringPiNodeStruct *node = wiringPiNodes;
if (wiringPiDebug)
@ -1757,13 +1734,10 @@ void pinMode(int pin, int mode) {
printf(">>> physToGpio[pin] ret %d\n", pin);
}
} else if (wiringPiMode == WPI_MODE_GPIO) { // pin = pinTobcm[pin];
pin = pin;
// pin = pin;
if (wiringPiDebug) {
printf(">>> pinTobcm[pin] ret %d\n", pin);
}
} else {
if (wiringPiDebug) {
printf(">>> unknow wiringPiMode\n");
@ -1798,13 +1772,11 @@ void pinMode(int pin, int mode) {
} else {
return;
}
} else {
if ((node = wiringPiFindNode(pin)) != NULL)
node->pinMode(node, pin, mode);
return;
}
}
/*
@ -1842,17 +1814,14 @@ void pullUpDnControl(int pin, int pud) {
printf("[%s:L%d] the pin:%d is invaild,please check it over!\n", __func__, __LINE__, pin);
return;
}
pud &= 3;
sunxi_pullUpDnControl(pin, pud);
return;
} else // Extension module
{
} else { // Extension module
if ((node = wiringPiFindNode(pin)) != NULL)
node->pullUpDnControl(node, pin, pud);
return;
}
}
/*
@ -1864,23 +1833,18 @@ void pullUpDnControl(int pin, int pud) {
int digitalRead(int pin) {
char c;
struct wiringPiNodeStruct *node = wiringPiNodes;
int oldPin = pin;
if (wiringPiDebug)
printf("Func: %s, Line: %d,pin:%d\n", __func__, __LINE__, pin);
if (pinToGpio == 0 || physToGpio == 0) {
printf("please call wiringPiSetup first.\n");
return 0;
}
if (pin > 0 && pin < MAX_PIN_COUNT) {
if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
{
if (wiringPiMode == WPI_MODE_GPIO_SYS) { // Sys mode
if (wiringPiDebug) {
printf("in digitalRead, wiringPiMode == WPI_MODE_GPIO_SYS\n");
}
if (pin == 0) {
//printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__);
return 0;
@ -1893,7 +1857,6 @@ int digitalRead(int pin) {
return 0;
}
*/
if (sysFds [pin] == -1) {
if (wiringPiDebug)
printf("pin %d sysFds -1.%s,%d\n", pin, __func__, __LINE__);
@ -1921,12 +1884,11 @@ int digitalRead(int pin) {
if (wiringPiDebug) {
printf(">>> pinTobcm[pin] ret %d\n", pin);
}
} else {
return LOW;
}
if (-1 == pin) {
printf("[%s:L%d] the pin:%d is invaild,please check it over!\n", __func__, __LINE__, oldPin);
printf("[%s:L%d] the pin:%d is invaild,please check it over!\n", __func__, __LINE__, pin);
return LOW;
}
return sunxi_digitalRead(pin);
@ -1947,12 +1909,10 @@ int digitalReadSilence(int pin) {
}
if (pin > 0 && pin < MAX_PIN_COUNT) {
if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
{
if (wiringPiMode == WPI_MODE_GPIO_SYS) { // Sys mode
if (pin == 0) {
return 0;
}
if (sysFds [pin] == -1) {
return LOW;
}
@ -1966,6 +1926,7 @@ int digitalReadSilence(int pin) {
} else if (wiringPiMode == WPI_MODE_GPIO) {
// pin = pinTobcm[pin];
pin = pin;
// Nothing
} else {
return LOW;
}
@ -2029,9 +1990,10 @@ void digitalWrite(int pin, int value) {
pin = pinToGpio [pin];
else if (wiringPiMode == WPI_MODE_PHYS)
pin = physToGpio[pin];
else if (wiringPiMode == WPI_MODE_GPIO)
else if (wiringPiMode == WPI_MODE_GPIO) {
// pin = pinTobcm[pin];
pin = pin;
}
else return;
if (-1 == pin) {
//printf("[%s:L%d] the pin:%d is invaild,please check it over!\n", __func__, __LINE__, pin);
@ -2050,7 +2012,6 @@ void digitalWrite(int pin, int value) {
* Set an output PWM value
*********************************************************************************
*/
void pwmWrite(int pin, int value) {
struct wiringPiNodeStruct *node = wiringPiNodes;
@ -2059,16 +2020,13 @@ void pwmWrite(int pin, int value) {
return;
}
uint32_t a_val = 0;
if (pwmmode == 1)//sycle
{
if (pwmmode == 1) { // cycle
sunxi_pwm_set_mode(1);
} else {
// sunxi_pwm_set_mode(0);
}
if (pin < MAX_PIN_NUM) // On-Board Pin needto fix me Jim
{
if (pin < MAX_PIN_NUM) { // On-Board Pin needto fix me Jim
if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio [pin];
else if (wiringPiMode == WPI_MODE_PHYS) {
@ -2190,19 +2148,14 @@ void digitalWriteByte(int value) {
}
if (wiringPiMode == WPI_MODE_GPIO_SYS || wiringPiMode == WPI_MODE_GPIO) {
for (pin = 0; pin < 8; ++pin) {
pinMode(pin, OUTPUT);
delay(1);
digitalWrite(pinToGpio [pin], value & mask);
mask <<= 1;
}
} else if (wiringPiMode == WPI_MODE_PINS) {
for (pin = 0; pin < 8; ++pin) {
pinMode(pin, OUTPUT);
delay(1);
digitalWrite(pin, value & mask);
@ -2217,7 +2170,6 @@ void digitalWriteByte(int value) {
}
}
return;
}
/*
@ -2240,10 +2192,11 @@ int waitForInterrupt(int pin, int mS) {
return;
}
/**/ if (wiringPiMode == WPI_MODE_PINS)
if (wiringPiMode == WPI_MODE_PINS) {
pin = pinToGpio [pin];
else if (wiringPiMode == WPI_MODE_PHYS)
} else if (wiringPiMode == WPI_MODE_PHYS) {
pin = physToGpio [pin];
}
if ((fd = sysFds [pin]) == -1)
return -2;
@ -2320,7 +2273,6 @@ int wiringPiISR(int pin, int mode, void (*function)(void)) {
else
bcmGpioPin = pin;
if (-1 == bcmGpioPin) /**/ {
printf("[%s:L%d] the pin:%d is invaild,please check it over!\n", __func__, __LINE__, pin);
return -1;
@ -2328,7 +2280,6 @@ int wiringPiISR(int pin, int mode, void (*function)(void)) {
//if (edge[bcmGpioPin] == -1)
return wiringPiFailure(WPI_FATAL, "wiringPiISR: pin not sunpprt on Nano PI M1 (%d,%d)\n", pin, bcmGpioPin);
}
/*
@ -2470,11 +2421,9 @@ int wiringPiSetup(void) {
// boardRev = piBoardRev();
// Open the master /dev/memory device
if ((fd = open("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC)) < 0)
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror(errno));
// GPIO:
// BLOCK SIZE * 2 increases range to include pwm addresses
gpio = (uint32_t *) mmap(0, BLOCK_SIZE*10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE_BP);
@ -2482,39 +2431,39 @@ int wiringPiSetup(void) {
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno));
// PWM
pwm = (uint32_t *) mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_PWM_BP);
if ((int32_t) pwm == -1)
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror(errno));
// Clock control (needed for PWM)
clk = (uint32_t *) mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE_BP);
if ((int32_t) clk == -1)
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror(errno));
// The drive pads
pads = (uint32_t *) mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_PADS_BP);
if ((int32_t) pads == -1)
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror(errno));
initialiseEpoch();
// If we're running on a compute module, then wiringPi pin numbers don't really many anything...
piBoardId(&model, &rev, &mem, &maker, &overVolted);
wiringPiMode = WPI_MODE_PINS;
int faBoardId = model;
if (faBoardId == NanoPi_M1 || faBoardId == NanoPi_M1_Plus || faBoardId == NanoPi_M1_Plus2 || faBoardId == NanoPi_K1_Plus) {
if (faBoardId == NanoPi_M1
|| faBoardId == NanoPi_M1_Plus
|| faBoardId == NanoPi_M1_Plus2
|| faBoardId == NanoPi_K1_Plus) {
pinToGpio = pinToGpio_m1;
physToGpio = physToGpio_m1;
physToPin = physToPin_m1;
syspin = syspin_m1;
} else if (faBoardId == NanoPi_NEO || faBoardId == NanoPi_NEO_Air || faBoardId == NanoPi_NEO2 || faBoardId == NanoPi_NEO_Plus2) {
} else if (faBoardId == NanoPi_NEO
|| faBoardId == NanoPi_NEO_Air
|| faBoardId == NanoPi_NEO2
|| faBoardId == NanoPi_NEO_Plus2) {
pinToGpio = pinToGpio_neo;
physToGpio = physToGpio_neo;
physToPin = physToPin_neo;
@ -2607,11 +2556,17 @@ int wiringPiSetupSys(void) {
piBoardId(&model, &rev, &mem, &maker, &overVolted);
int faBoardId = model;
if (faBoardId == NanoPi_M1 || faBoardId == NanoPi_M1_Plus || faBoardId == NanoPi_M1_Plus2 || faBoardId == NanoPi_K1_Plus) {
if (faBoardId == NanoPi_M1
|| faBoardId == NanoPi_M1_Plus
|| faBoardId == NanoPi_M1_Plus2
|| faBoardId == NanoPi_K1_Plus) {
pinToGpio = pinToGpio_m1;
physToGpio = physToGpio_m1;
physToPin = physToPin_m1;
} else if (faBoardId == NanoPi_NEO || faBoardId == NanoPi_NEO_Air || faBoardId == NanoPi_NEO2 || faBoardId == NanoPi_NEO_Plus2) {
} else if (faBoardId == NanoPi_NEO
|| faBoardId == NanoPi_NEO_Air
|| faBoardId == NanoPi_NEO2
|| faBoardId == NanoPi_NEO_Plus2) {
pinToGpio = pinToGpio_neo;
physToGpio = physToGpio_neo;
physToPin = physToPin_neo;