瀏覽代碼

#225

pull/228/head
mstroh76 6 月之前
父節點
當前提交
f3415b593c
共有 2 個檔案被更改,包括 71 行新增20 行删除
  1. +54
    -12
      wiringPi/wiringPi.c
  2. +17
    -8
      wiringPi/wiringPi.h

+ 54
- 12
wiringPi/wiringPi.c 查看文件

@@ -1689,9 +1689,15 @@ void pinMode (int pin, int mode)
case WPI_MODE_PHYS:
pin = physToGpio [pin];
break;
case WPI_MODE_GPIO_DEVICE:
case WPI_MODE_GPIO_DEVICE_BCM:
pinModeDevice(pin, mode);
return;
case WPI_MODE_GPIO_DEVICE_WPI:
pinModeDevice(pinToGpio[pin], mode);
return;
case WPI_MODE_GPIO_DEVICE_PHYS:
pinModeDevice(physToGpio[pin], mode);
return;
case WPI_MODE_GPIO:
break;
}
@@ -1817,8 +1823,12 @@ void pullUpDnControl (int pin, int pud)
case WPI_MODE_PHYS:
pin = physToGpio [pin];
break;
case WPI_MODE_GPIO_DEVICE:
case WPI_MODE_GPIO_DEVICE_BCM:
return pullUpDnControlDevice(pin, pud);
case WPI_MODE_GPIO_DEVICE_WPI:
return pullUpDnControlDevice(pinToGpio[pin], pud);
case WPI_MODE_GPIO_DEVICE_PHYS:
return pullUpDnControlDevice(physToGpio[pin], pud);
case WPI_MODE_GPIO:
break;
}
@@ -1915,8 +1925,12 @@ int digitalRead (int pin)
case WPI_MODE_PHYS:
pin = physToGpio [pin];
break;
case WPI_MODE_GPIO_DEVICE:
case WPI_MODE_GPIO_DEVICE_BCM:
return digitalReadDevice(pin);
case WPI_MODE_GPIO_DEVICE_WPI:
return digitalReadDevice(pinToGpio[pin]);
case WPI_MODE_GPIO_DEVICE_PHYS:
return digitalReadDevice(physToGpio[pin]);
case WPI_MODE_GPIO:
break;
}
@@ -2011,9 +2025,15 @@ void digitalWrite (int pin, int value)
case WPI_MODE_PHYS:
pin = physToGpio [pin];
break;
case WPI_MODE_GPIO_DEVICE:
case WPI_MODE_GPIO_DEVICE_BCM:
digitalWriteDevice(pin, value);
return;
case WPI_MODE_GPIO_DEVICE_WPI:
digitalWriteDevice(pinToGpio[pin], value);
return;
case WPI_MODE_GPIO_DEVICE_PHYS:
digitalWriteDevice(physToGpio[pin], value);
return;
case WPI_MODE_GPIO:
break;
}
@@ -2933,7 +2953,6 @@ int wiringPiSetup (void)
_wiringPiPads = pads ;
_wiringPiTimer = timer ;
_wiringPiRio = NULL ;
} else {
unsigned int MMAP_size = (usingGpioMem) ? gpiomem_RP1_Size : pciemem_RP1_Size;

GPIO_PADS = (RP1_PADS0_Addr-RP1_IO0_Addr) ;
@@ -3024,13 +3043,24 @@ int wiringPiSetupPhys (void)
return 0 ;
}

int wiringPiSetupPinType (enum WPIPinType pinType) {
if (wiringPiDebug)
printf ("wiringPi: wiringPiSetupPinType(%d) called\n", (int) pinType) ;
switch (pinType) {
case WPI_PIN_BCM: return wiringPiSetupGpio();
case WPI_PIN_WPI: return wiringPiSetup();
case WPI_PIN_PHYS: return wiringPiSetupPhys();
default: return -1;
}
}

int wiringPiSetupGpioDevice (void) {

int wiringPiSetupGpioDevice (enum WPIPinType pinType) {
if (wiringPiSetuped)
return 0 ;
if (wiringPiDebug)
printf ("wiringPi: wiringPiSetupGpioDevice called\n") ;

if (wiringPiDebug) {
printf ("wiringPi: wiringPiSetupGpioDevice(%d) called\n", (int)pinType) ;
}
if (getenv (ENV_DEBUG) != NULL)
wiringPiDebug = TRUE ;

@@ -3042,7 +3072,6 @@ int wiringPiSetupGpioDevice (void) {
}
wiringPiSetuped = TRUE ;

// not used or needed but still assigned
if (piGpioLayout () == GPIO_LAYOUT_PI1_REV1){
pinToGpio = pinToGpioR1 ;
physToGpio = physToGpioR1 ;
@@ -3053,7 +3082,20 @@ int wiringPiSetupGpioDevice (void) {

initialiseEpoch () ;

wiringPiMode = WPI_MODE_GPIO_DEVICE ;
switch (pinType) {
case WPI_PIN_BCM:
wiringPiMode = WPI_MODE_GPIO_DEVICE_BCM;
break;
case WPI_PIN_WPI:
wiringPiMode = WPI_MODE_GPIO_DEVICE_WPI;
break;
case WPI_PIN_PHYS:
wiringPiMode = WPI_MODE_GPIO_DEVICE_PHYS;
break;
default:
wiringPiSetuped = FALSE;
return -1;
}

return 0 ;
}
@@ -3072,5 +3114,5 @@ int wiringPiSetupSys (void)
return 0 ;
if (wiringPiDebug)
printf ("wiringPi: wiringPiSetupSys called\n") ;
return wiringPiSetupGpioDevice();
return wiringPiSetupGpioDevice(WPI_PIN_BCM);
}

+ 17
- 8
wiringPi/wiringPi.h 查看文件

@@ -46,12 +46,14 @@

// wiringPi modes

#define WPI_MODE_PINS 0
#define WPI_MODE_GPIO 1
#define WPI_MODE_GPIO_SYS 2 // deprecated since 3.2
#define WPI_MODE_PHYS 3
#define WPI_MODE_PIFACE 4
#define WPI_MODE_GPIO_DEVICE 5 // BCM numbers like WPI_MODE_GPIO
#define WPI_MODE_PINS 0
#define WPI_MODE_GPIO 1
#define WPI_MODE_GPIO_SYS 2 // deprecated since 3.2
#define WPI_MODE_PHYS 3
#define WPI_MODE_PIFACE 4
#define WPI_MODE_GPIO_DEVICE_BCM 5 // BCM pin numbers like WPI_MODE_GPIO
#define WPI_MODE_GPIO_DEVICE_WPI 6 // WiringPi pin numbers like WPI_MODE_PINS
#define WPI_MODE_GPIO_DEVICE_PHYS 7 // Physic pin numbers like WPI_MODE_PHYS
#define WPI_MODE_UNINITIALISED -1

// Pin modes
@@ -207,14 +209,21 @@ extern int wiringPiFailure (int fatal, const char *message, ...) ;
extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;

enum WPIPinType {
WPI_PIN_BCM = 1,
WPI_PIN_WPI,
WPI_PIN_PHYS,
};

extern void wiringPiVersion (int *major, int *minor) ;
extern int wiringPiGlobalMemoryAccess(void); //Interface 3.3
extern int wiringPiGlobalMemoryAccess(void); //Interface V3.3
extern int wiringPiUserLevelAccess (void) ;
extern int wiringPiSetup (void) ;
extern int wiringPiSetupSys (void) ;
extern int wiringPiSetupGpio (void) ;
extern int wiringPiSetupPhys (void) ;
extern int wiringPiSetupGpioDevice(void) ; //Interface 3.3
extern int wiringPiSetupPinType (enum WPIPinType pinType); //Interface V3.3
extern int wiringPiSetupGpioDevice(enum WPIPinType pinType); //Interface V3.3

extern int GetChipFd ();
extern void pinModeAlt (int pin, int mode) ;


Loading…
取消
儲存