]> Repositories - hackapet/Adafruit_Blinka.git/blobdiff - src/adafruit_blinka/microcontroller/ftdi_mpsse/mpsse/pin.py
Merge branch 'master' of https://github.com/adafruit/Adafruit_Blinka
[hackapet/Adafruit_Blinka.git] / src / adafruit_blinka / microcontroller / ftdi_mpsse / mpsse / pin.py
index 6a0ea938ffe3db0a79f5ff664bdc1c857c51a9a7..5dc171ea16485524a4b8d4f877fc31a1f04ea051 100644 (file)
@@ -1,5 +1,7 @@
 """MPSSE pin names"""
 
+from adafruit_blinka.microcontroller.ftdi_mpsse.mpsse.url import get_ft232h_url, get_ft2232h_url
+
 
 class Pin:
     """A basic Pin class for use with FTDI MPSSEs."""
@@ -8,10 +10,13 @@ class Pin:
     OUT = 1
     LOW = 0
     HIGH = 1
+    PULL_NONE = 0
+    PULL_UP = 1
+    PULL_DOWN = 2
 
     mpsse_gpio = None
 
-    def __init__(self, pin_id=None, url="ftdi://ftdi:ft232h/1"):
+    def __init__(self, pin_id=None, interface_id=None):
         # setup GPIO controller if not done yet
         # use one provided by I2C as default
         if not Pin.mpsse_gpio:
@@ -21,7 +26,10 @@ class Pin:
             # pylint: enable=import-outside-toplevel
 
             i2c = I2cController()
-            i2c.configure(url)
+            if interface_id is None:
+                i2c.configure(get_ft232h_url())
+            else:
+                i2c.configure(get_ft2232h_url(interface_id))
             Pin.mpsse_gpio = i2c.get_gpio()
         # check if pin is valid
         if pin_id:
@@ -36,7 +44,7 @@ class Pin:
             raise RuntimeError("Can not init a None type pin.")
         # MPSSE does't have configurable internal pulls?
         if pull:
-            raise ValueError("Internal pull up/down not currently supported.")
+            raise NotImplementedError("Internal pull up/down not currently supported.")
         pin_mask = Pin.mpsse_gpio.pins | 1 << self.id
         current = Pin.mpsse_gpio.direction
         if mode == self.OUT:
@@ -63,4 +71,4 @@ class Pin:
             Pin.mpsse_gpio.write(current & Pin.mpsse_gpio.direction)
             return None
         # release the kraken
-        raise RuntimeError("Invalid value for pin")
\ No newline at end of file
+        raise RuntimeError("Invalid value for pin")