]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/ft232h/pin.py
Merge pull request #449 from caternuson/pico_u2if
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / ft232h / pin.py
index c768ffdc98c6aa353dbfd48b208f80713a9f3a41..42ae5abd70e1176e7f6faaf23c3e53a4d5fd98ad 100644 (file)
@@ -1,3 +1,6 @@
+"""FT232H pin names"""
+
+
 class Pin:
     """A basic Pin class for use with FT232H."""
 
 class Pin:
     """A basic Pin class for use with FT232H."""
 
@@ -5,6 +8,9 @@ class Pin:
     OUT = 1
     LOW = 0
     HIGH = 1
     OUT = 1
     LOW = 0
     HIGH = 1
+    PULL_NONE = 0
+    PULL_UP = 1
+    PULL_DOWN = 2
 
     ft232h_gpio = None
 
 
     ft232h_gpio = None
 
@@ -12,7 +18,11 @@ class Pin:
         # setup GPIO controller if not done yet
         # use one provided by I2C as default
         if not Pin.ft232h_gpio:
         # setup GPIO controller if not done yet
         # use one provided by I2C as default
         if not Pin.ft232h_gpio:
+            # pylint: disable=import-outside-toplevel
             from pyftdi.i2c import I2cController
             from pyftdi.i2c import I2cController
+
+            # pylint: enable=import-outside-toplevel
+
             i2c = I2cController()
             i2c.configure("ftdi://ftdi:ft232h/1")
             Pin.ft232h_gpio = i2c.get_gpio()
             i2c = I2cController()
             i2c.configure("ftdi://ftdi:ft232h/1")
             Pin.ft232h_gpio = i2c.get_gpio()
@@ -24,11 +34,12 @@ class Pin:
         self.id = pin_id
 
     def init(self, mode=IN, pull=None):
         self.id = pin_id
 
     def init(self, mode=IN, pull=None):
+        """Initialize the Pin"""
         if not self.id:
             raise RuntimeError("Can not init a None type pin.")
         # FT232H does't have configurable internal pulls?
         if pull:
         if not self.id:
             raise RuntimeError("Can not init a None type pin.")
         # FT232H 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.ft232h_gpio.pins | 1 << self.id
         current = Pin.ft232h_gpio.direction
         if mode == self.OUT:
         pin_mask = Pin.ft232h_gpio.pins | 1 << self.id
         current = Pin.ft232h_gpio.direction
         if mode == self.OUT:
@@ -38,6 +49,7 @@ class Pin:
         Pin.ft232h_gpio.set_direction(pin_mask, current)
 
     def value(self, val=None):
         Pin.ft232h_gpio.set_direction(pin_mask, current)
 
     def value(self, val=None):
+        """Set or return the Pin Value"""
         if not self.id:
             raise RuntimeError("Can not access a None type pin.")
         current = Pin.ft232h_gpio.read(with_output=True)
         if not self.id:
             raise RuntimeError("Can not access a None type pin.")
         current = Pin.ft232h_gpio.read(with_output=True)
@@ -45,16 +57,17 @@ class Pin:
         if val is None:
             return 1 if current & 1 << self.id != 0 else 0
         # write
         if val is None:
             return 1 if current & 1 << self.id != 0 else 0
         # write
-        elif val in (self.LOW, self.HIGH):
+        if val in (self.LOW, self.HIGH):
             if val == self.HIGH:
                 current |= 1 << self.id
             else:
                 current &= ~(1 << self.id)
             # must mask out any input pins
             Pin.ft232h_gpio.write(current & Pin.ft232h_gpio.direction)
             if val == self.HIGH:
                 current |= 1 << self.id
             else:
                 current &= ~(1 << self.id)
             # must mask out any input pins
             Pin.ft232h_gpio.write(current & Pin.ft232h_gpio.direction)
+            return None
         # release the kraken
         # release the kraken
-        else:
-            raise RuntimeError("Invalid value for pin")
+        raise RuntimeError("Invalid value for pin")
+
 
 # create pin instances for each pin
 # D0 to D3 are used by I2C/SPI
 
 # create pin instances for each pin
 # D0 to D3 are used by I2C/SPI