]> Repositories - Adafruit_Blinka-hackapet.git/blobdiff - src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py
Untangle code and remove pylint disables
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / nxp_lpc4330 / pin.py
index a67032e65d7181ce96f13ea216549cba91eb18ea..187a4d35aaa1d90ac7bc0a5d454409ba3fcd5c15 100644 (file)
@@ -1,14 +1,23 @@
+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """NXP LPC4330 pin names"""
 try:
     from greatfet import GreatFET
     from greatfet.interfaces.adc import ADC
 
     gf = GreatFET()
-except:
-    raise RuntimeError("Unable to create GreatFET object. Make sure library is installed and the device is connected.")
+except ModuleNotFoundError:
+    raise RuntimeError(
+        "Unable to create GreatFET object. Make sure library is "
+        "installed and the device is connected."
+    ) from ModuleNotFoundError
+
 
 class Pin:
-    """A basic Pin class for the NXP LPC4330 that acts as a wrapper for the GreatFET api."""
+    """A basic Pin class for the NXP LPC4330 that
+    acts as a wrapper for the GreatFET api.
+    """
 
     # pin modes
     OUT = gf.gpio.DIRECTION_OUT
@@ -29,6 +38,8 @@ class Pin:
         """Initialize the Pin"""
         if self.id is None:
             raise RuntimeError("Can not init a None type pin.")
+        if pull is not None:
+            raise NotImplementedError("Internal pullups and pulldowns not supported")
         if mode in (Pin.IN, Pin.OUT):
             if self.id not in gf.GPIO_MAPPINGS:
                 raise ValueError("Pin does not have GPIO capabilities")
@@ -38,12 +49,10 @@ class Pin:
             # ADC only available on these pins
             if self.id not in gf.ADC_MAPPINGS:
                 raise ValueError("Pin does not have ADC capabilities")
-            gf.ADC_MAPPINGS[self.id]
-            # TODO: figure out a way to pass the ADC number without breaking the interface
             self._pin = ADC(gf, self.id)
         elif mode == Pin.DAC:
             # DAC only available on these pins
-            if self.id not in ("J2_P5"):
+            if self.id != "J2_P5":
                 raise ValueError("Pin does not have DAC capabilities")
             self._pin = gf.apis.dac
             self._pin.initialize()
@@ -83,6 +92,7 @@ class Pin:
             "No action for mode {} with value {}".format(self._mode, val)
         )
 
+
 # create pin instances for each pin
 # J1 Header Pins
 J1_P3 = Pin("J1_P3")
@@ -122,15 +132,14 @@ J1_P39 = Pin("J1_P39")  # MOSI
 J1_P40 = Pin("J1_P40")  # MISO
 
 
-
 # J2 Header Pins
 J2_P3 = Pin("J2_P3")
 J2_P4 = Pin("J2_P4")
-J2_P5 = Pin("J2_P5")    # ADC, ADC, DAC
+J2_P5 = Pin("J2_P5")  # ADC, ADC, DAC
 J2_P6 = Pin("J2_P6")
 J2_P7 = Pin("J2_P7")
 J2_P8 = Pin("J2_P8")
-J2_P9 = Pin("J2_P9")    # ADC, GPIO
+J2_P9 = Pin("J2_P9")  # ADC, GPIO
 J2_P10 = Pin("J2_P10")
 J2_P13 = Pin("J2_P13")
 J2_P14 = Pin("J2_P14")
@@ -158,8 +167,8 @@ J2_P38 = Pin("J2_P38")
 # Bonus Row Pins
 J7_P2 = Pin("J7_P2")
 J7_P3 = Pin("J7_P3")
-J7_P4 = Pin("J7_P4")    # ADC, ADC
-J7_P5 = Pin("J7_P5")    # ADC, ADC
+J7_P4 = Pin("J7_P4")  # ADC, ADC
+J7_P5 = Pin("J7_P5")  # ADC, ADC
 J7_P6 = Pin("J7_P6")
 J7_P7 = Pin("J7_P7")
 J7_P8 = Pin("J7_P8")