Merge pull request #2 from troyane/improvements
Small problem fixes and code formatting improvements
This commit is contained in:
		
							
								
								
									
										11
									
								
								build
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								build
									
									
									
									
									
								
							| @@ -45,7 +45,6 @@ if [ x$1 = "xuninstall" ]; then | ||||
|   exit | ||||
| fi | ||||
|  | ||||
|  | ||||
| echo "wiringPi Build script" | ||||
| echo "=====================" | ||||
| echo | ||||
| @@ -55,11 +54,11 @@ fi | ||||
| cd wiringPi | ||||
| ${PFX}make uninstall | ||||
| if [ x$1 = "xstatic" ]; then | ||||
|     make static | ||||
|   make -j `nproc` static | ||||
|   check_make_ok | ||||
|   ${PFX}make install-static | ||||
| else | ||||
|     make | ||||
|   make -j `nproc` | ||||
|   check_make_ok | ||||
|   ${PFX}make install | ||||
| fi | ||||
| @@ -70,11 +69,11 @@ fi | ||||
| cd ../devLib | ||||
| ${PFX}make uninstall | ||||
| if [ x$1 = "xstatic" ]; then | ||||
|     make static | ||||
|   make -j `nproc` static | ||||
|   check_make_ok | ||||
|   ${PFX}make install-static | ||||
| else | ||||
|     make | ||||
|   make -j `nproc` | ||||
|   check_make_ok | ||||
|   ${PFX}make install | ||||
| fi | ||||
| @@ -83,7 +82,7 @@ fi | ||||
| echo | ||||
| echo "GPIO Utility" | ||||
| cd ../gpio | ||||
|   make | ||||
| make -j `nproc` | ||||
| check_make_ok | ||||
| ${PFX}make install | ||||
| check_make_ok | ||||
|   | ||||
| @@ -90,7 +90,7 @@ BoardHardwareInfo gAllBoardHardwareInfo[] = { | ||||
|  | ||||
| static int getFieldValueInCpuInfo(char* hardware, int hardwareMaxLen, char* revision, int revisionMaxLen) | ||||
| { | ||||
|     int n,i,j; | ||||
|     unsigned long n, i, j; | ||||
|     char lineUntrim[1024], line[1024], line2[1024], *p, *p2; | ||||
|     FILE *f; | ||||
|     int isGotHardware = 0; | ||||
| @@ -109,7 +109,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]; | ||||
|                 } | ||||
| @@ -148,7 +151,7 @@ static int getFieldValueInCpuInfo(char* hardware, int hardwareMaxLen, char* revi | ||||
|  | ||||
| static int getAllwinnerBoardID(char* boardId, int boardIdMaxLen ) | ||||
| { | ||||
|     int n,i,j; | ||||
|     unsigned long n, i, j; | ||||
|     char lineUntrim[1024], line[1024], *p; | ||||
|     const char* sunxi_board_id_fieldname = "sunxi_board_id"; | ||||
|     FILE *f; | ||||
| @@ -165,7 +168,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]; | ||||
|                 } | ||||
| @@ -216,9 +222,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]; | ||||
|                 } | ||||
| @@ -236,9 +245,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]; | ||||
|                         } | ||||
| @@ -263,7 +276,7 @@ int getBoardType(BoardHardwareInfo** retBoardInfo) { | ||||
|  | ||||
|     char revision2[255]; | ||||
|     sprintf(revision2, "0x%s", revision); | ||||
|     int iRev; | ||||
|     long iRev; | ||||
|     iRev = strtol(revision2, NULL, 16); | ||||
|  | ||||
|     // other, check hardware and revision | ||||
|   | ||||
| @@ -134,6 +134,10 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL; | ||||
| #define GPIO_PWM          (BCM2708_PERI_BASE + 0x0020C000) | ||||
|  | ||||
| #define PAGE_SIZE  (4*1024) | ||||
| // Since BLOCK_SIZE is defined in /usr/include/linux/fs.h: | ||||
| #ifdef BLOCK_SIZE | ||||
| #undef BLOCK_SIZE | ||||
| #endif | ||||
| #define BLOCK_SIZE (4*1024) | ||||
|  | ||||
| // PWM | ||||
| @@ -217,7 +221,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 +281,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 +312,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 +326,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 +349,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 +356,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 +387,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 +419,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 +452,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 +804,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 +886,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 +918,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 */ | ||||
| @@ -1538,17 +1521,19 @@ int getAlt(int pin) { | ||||
|         pin = pinToGpio [pin]; | ||||
|     else if (wiringPiMode == WPI_MODE_PHYS) | ||||
|         pin = physToGpio[pin]; | ||||
|     else if (wiringPiMode == WPI_MODE_GPIO)    //pin = pinTobcm[pin];  | ||||
|         pin = pin; | ||||
|     else return 0; | ||||
|  | ||||
|     else if (wiringPiMode == WPI_MODE_GPIO) { | ||||
|         //pin = pinTobcm[pin]; | ||||
|         // pin = pin; | ||||
|         // Nothing | ||||
|     } else { | ||||
|         return 0; | ||||
|     } | ||||
|     if (-1 == pin) { | ||||
|         printf("[%s:L%d] the pin:%d  mode: %d is invaild,please check it over!\n", __func__, __LINE__, pin, wiringPiMode); | ||||
|         return -1; | ||||
|     } | ||||
|     alt = sunxi_get_gpio_mode(pin); | ||||
|     return alt; | ||||
|  | ||||
| } | ||||
|  | ||||
| int getAltSilence(int pin) { | ||||
| @@ -1567,9 +1552,13 @@ int getAltSilence(int pin) { | ||||
|         pin = pinToGpio [pin]; | ||||
|     else if (wiringPiMode == WPI_MODE_PHYS) | ||||
|         pin = physToGpio[pin]; | ||||
|     else if (wiringPiMode == WPI_MODE_GPIO)    //pin = pinTobcm[pin];  | ||||
|         pin = pin; | ||||
|     else return 0; | ||||
|     else if (wiringPiMode == WPI_MODE_GPIO) { | ||||
|         // pin = pinTobcm[pin]; | ||||
|         // pin = pin; | ||||
|         // Nothing | ||||
|     } else { | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     if (-1 == pin) { | ||||
|         return -1; | ||||
| @@ -1691,9 +1680,9 @@ struct wiringPiNodeStruct *wiringPiNewNode(int pinBase, int numPins) { | ||||
|             (void)wiringPiFailure(WPI_FATAL, "wiringPiNewNode: Pin %d overlaps with existing definition\n", pin); | ||||
|  | ||||
|     node = (struct wiringPiNodeStruct *) calloc(sizeof (struct wiringPiNodeStruct), 1); // calloc zeros | ||||
|     if (node == NULL) | ||||
|     if (node == NULL) { | ||||
|         (void)wiringPiFailure(WPI_FATAL, "wiringPiNewNode: Unable to allocate memory: %s\n", strerror(errno)); | ||||
|  | ||||
|     } else { | ||||
|         node->pinBase = pinBase; | ||||
|         node->pinMax = pinBase + numPins - 1; | ||||
|         node->pinMode = pinModeDummy; | ||||
| @@ -1705,7 +1694,7 @@ struct wiringPiNodeStruct *wiringPiNewNode(int pinBase, int numPins) { | ||||
|         node->analogWrite = analogWriteDummy; | ||||
|         node->next = wiringPiNodes; | ||||
|         wiringPiNodes = node; | ||||
|  | ||||
|     } | ||||
|     return node; | ||||
| } | ||||
|  | ||||
| @@ -1733,7 +1722,6 @@ void pinModeAlt(int pin, int mode) { | ||||
|  */ | ||||
|  | ||||
| void pinMode(int pin, int mode) { | ||||
|  | ||||
|     struct wiringPiNodeStruct *node = wiringPiNodes; | ||||
|  | ||||
|     if (wiringPiDebug) | ||||
| @@ -1757,13 +1745,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 +1783,11 @@ void pinMode(int pin, int mode) { | ||||
|         } else { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|     } else { | ||||
|         if ((node = wiringPiFindNode(pin)) != NULL) | ||||
|             node->pinMode(node, pin, mode); | ||||
|         return; | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| /* | ||||
| @@ -1831,10 +1814,13 @@ void pullUpDnControl(int pin, int pud) { | ||||
|             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; | ||||
|             // pin = pin; | ||||
|             // Nothing | ||||
|         } else { | ||||
|             return; | ||||
|         } | ||||
|         if (wiringPiDebug) | ||||
|             printf("%s,%d,pin:%d\n", __func__, __LINE__, pin); | ||||
|  | ||||
| @@ -1842,17 +1828,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,28 +1847,22 @@ 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 (wiringPiDebug) { | ||||
| 			    printf("in digitalRead, wiringPiMode == WPI_MODE_GPIO_SYS\n"); | ||||
| 		    } | ||||
|  | ||||
| 		    if (pin == 0) { | ||||
|     if (pin == 0 && wiringPiMode == WPI_MODE_GPIO_SYS) { | ||||
|         //printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__); | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     if (pin > 0 && pin < MAX_PIN_COUNT) { | ||||
|         if (wiringPiMode == WPI_MODE_GPIO_SYS) { // Sys mode | ||||
| 		    if (wiringPiDebug) { | ||||
| 			    printf("in digitalRead, wiringPiMode == WPI_MODE_GPIO_SYS\n"); | ||||
| 		    } | ||||
|             //TODO: fix me | ||||
|             /* | ||||
|             if (syspin[pin] == -1) { | ||||
| @@ -1893,7 +1870,6 @@ int digitalRead(int pin) { | ||||
|                 return 0; | ||||
|             } | ||||
|             */ | ||||
|  | ||||
|             if (sysFds [pin] == -1) { | ||||
| 			    if (wiringPiDebug) | ||||
| 				    printf("pin %d sysFds -1.%s,%d\n", pin, __func__, __LINE__); | ||||
| @@ -1916,17 +1892,16 @@ int digitalRead(int pin) { | ||||
| 		    } | ||||
| 	    } else if (wiringPiMode == WPI_MODE_GPIO) { | ||||
| 		    // pin = pinTobcm[pin];  | ||||
|         pin = pin; | ||||
|             // pin = 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); | ||||
| @@ -1940,19 +1915,17 @@ int digitalRead(int pin) { | ||||
| int digitalReadSilence(int pin) { | ||||
|     char c; | ||||
|     struct wiringPiNodeStruct *node = wiringPiNodes; | ||||
|     int oldPin = pin; | ||||
|  | ||||
|     if (pinToGpio == 0 || physToGpio == 0) { | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     if (pin > 0 && pin < MAX_PIN_COUNT) { | ||||
|       if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode | ||||
|       { | ||||
|         if (pin == 0) { | ||||
|     if (pin == 0 && wiringPiMode == WPI_MODE_GPIO_SYS) { | ||||
|         return 0; | ||||
|     } | ||||
|  | ||||
|     if (pin > 0 && pin < MAX_PIN_COUNT) { | ||||
|         if (wiringPiMode == WPI_MODE_GPIO_SYS) { // Sys mode | ||||
|             if (sysFds [pin] == -1) { | ||||
|                 return LOW; | ||||
|             } | ||||
| @@ -1965,7 +1938,8 @@ int digitalReadSilence(int pin) { | ||||
|             pin = physToGpio[pin]; | ||||
|         } else if (wiringPiMode == WPI_MODE_GPIO) { | ||||
|             // pin = pinTobcm[pin]; | ||||
|         pin = pin; | ||||
|             // pin = pin; | ||||
|             // Nothing | ||||
|         } else { | ||||
|             return LOW; | ||||
|         } | ||||
| @@ -2029,9 +2003,11 @@ 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; | ||||
|             // pin = pin; | ||||
|             // Nothing | ||||
|         } | ||||
|         else return; | ||||
|         if (-1 == pin) { | ||||
|             //printf("[%s:L%d] the pin:%d is invaild,please check it over!\n", __func__,  __LINE__, pin); | ||||
| @@ -2050,7 +2026,6 @@ void digitalWrite(int pin, int value) { | ||||
|  *	Set an output PWM value | ||||
|  ********************************************************************************* | ||||
|  */ | ||||
|  | ||||
| void pwmWrite(int pin, int value) { | ||||
|     struct wiringPiNodeStruct *node = wiringPiNodes; | ||||
|  | ||||
| @@ -2059,16 +2034,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 +2162,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 +2184,6 @@ void digitalWriteByte(int value) { | ||||
|         } | ||||
|     } | ||||
|     return; | ||||
|  | ||||
| } | ||||
|  | ||||
| /* | ||||
| @@ -2240,10 +2206,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 +2287,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 +2294,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 +2435,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 +2445,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 +2570,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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user