MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / wiringPiSetup

Function wiringPiSetup

wiringPi/wiringPi.c:3447–3645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3445 */
3446
3447int wiringPiSetup (void)
3448{
3449 int fd ;
3450 int model, rev, mem, maker, overVolted ;
3451
3452 if (wiringPiSetuped)
3453 return 0 ;
3454
3455 wiringPiSetuped = true ;
3456
3457 if (getenv (ENV_DEBUG) != NULL)
3458 wiringPiDebug = true ;
3459
3460 if (getenv (ENV_CODES) != NULL)
3461 wiringPiReturnCodes = true ;
3462
3463 if (wiringPiDebug)
3464 printf ("wiringPi: wiringPiSetup called\n") ;
3465
3466// Get the board ID information. We're not really using the information here,
3467// but it will give us information like the GPIO layout scheme (2 variants
3468// on the older 26-pin Pi's) and the GPIO peripheral base address.
3469// and if we're running on a compute module, then wiringPi pin numbers
3470// don't really mean anything, so force native BCM mode anyway.
3471
3472 piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
3473
3474 if ((model == PI_MODEL_CM) ||
3475 (model == PI_MODEL_CM3) ||
3476 (model == PI_MODEL_CM3P))
3477 wiringPiMode = WPI_MODE_GPIO ;
3478 else
3479 wiringPiMode = WPI_MODE_PINS ;
3480
3481 if (piGpioLayout () == GPIO_LAYOUT_PI1_REV1) // A, B, Rev 1, 1.1
3482 {
3483 pinToGpio = pinToGpioR1 ;
3484 physToGpio = physToGpioR1 ;
3485 }
3486 else // A2, B2, A+, B+, CM, Pi2, Pi3, Zero, Zero W, Zero 2 W
3487 {
3488 pinToGpio = pinToGpioR2 ;
3489 physToGpio = physToGpioR2 ;
3490 }
3491
3492// Open the master /dev/ memory control device
3493// Device strategy: December 2016:
3494// Try /dev/mem. If that fails, then
3495// try /dev/gpiomem. If that fails then game over.
3496
3497 const char* gpiomemGlobal = gpiomem_global;
3498 const char* gpiomemModule = gpiomem_BCM;
3499
3500 if (piRP1Model()) {
3501 GetRP1Memory();
3502 gpiomemGlobal = pciemem_RP1;
3503 gpiomemModule = gpiomem_RP1;
3504

Callers 15

mainFunction · 0.85
wiringPiSetupGpioFunction · 0.85
wiringPiSetupPhysFunction · 0.85
wiringPiSetupPinTypeFunction · 0.85
SetUpTestSuiteMethod · 0.85
SetUpTestSuiteMethod · 0.85
SetUpTestSuiteMethod · 0.85
SetUpTestSuiteMethod · 0.85
SetUpTestSuiteMethod · 0.85
SetUpTestSuiteMethod · 0.85
mainFunction · 0.85
SetUpTestSuiteMethod · 0.85

Calls 6

piBoardIdFunction · 0.85
piGpioLayoutFunction · 0.85
piRP1ModelFunction · 0.85
GetRP1MemoryFunction · 0.85
wiringPiFailureFunction · 0.85
initialiseEpochFunction · 0.85

Tested by 10

SetUpTestSuiteMethod · 0.68
SetUpTestSuiteMethod · 0.68
SetUpTestSuiteMethod · 0.68
SetUpTestSuiteMethod · 0.68
SetUpTestSuiteMethod · 0.68
SetUpTestSuiteMethod · 0.68
SetUpTestSuiteMethod · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68