]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Black formatted
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Thu, 14 May 2020 17:03:09 +0000 (10:03 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Thu, 14 May 2020 17:03:09 +0000 (10:03 -0700)
src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py
src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py
src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py
src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py
src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py

index e37fae1692dae629644ccf31adee3ef0a0f7fa33..1eadf688098fc74727f4c614f9b6f60354de50b2 100644 (file)
@@ -17,7 +17,7 @@ class I2C:
         """Write data from the buffer to an address"""
         if end is None:
             end = len(buffer)
-        self._gf.i2c.write(address, buffer[start: end])
+        self._gf.i2c.write(address, buffer[start:end])
 
     def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
         """Read data from an address and into the buffer"""
@@ -26,6 +26,7 @@ class I2C:
         readin = self._gf.i2c.read(address, end - start)
         for i in range(end - start):
             buffer[i + start] = readin[i]
+
     # pylint: enable=unused-argument
 
     def writeto_then_readfrom(
index a67032e65d7181ce96f13ea216549cba91eb18ea..b3767af505cd9461704e39764b8fa9f1c8202cf5 100644 (file)
@@ -5,7 +5,10 @@ try:
 
     gf = GreatFET()
 except:
-    raise RuntimeError("Unable to create GreatFET object. Make sure library is installed and the device is connected.")
+    raise RuntimeError(
+        "Unable to create GreatFET object. Make sure library is installed and the device is connected."
+    )
+
 
 class Pin:
     """A basic Pin class for the NXP LPC4330 that acts as a wrapper for the GreatFET api."""
@@ -83,6 +86,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 +126,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 +161,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")
index 08a31b772f99af2e5322e812ee05526fa4a64e9a..01bdb4298d768ae30dee40d0a17ba8f5596ad722 100644 (file)
@@ -14,6 +14,7 @@ from microcontroller.pin import Pin
 # pylint: disable=unnecessary-pass
 class PWMError(IOError):
     """Base class for PWM errors."""
+
     pass
 
 
@@ -125,7 +126,6 @@ class PWMOut:
 
     period = property(_get_period, _set_period)
 
-
     def _get_duty_cycle(self):
         """Get or set the PWM's output duty cycle as a ratio from 0.0 to 1.0.
 
@@ -146,12 +146,14 @@ class PWMOut:
         if isinstance(duty_cycle, int):
             duty_cycle /= 65535.0
         if not 0.0 <= duty_cycle <= 1.0:
-           raise ValueError("Invalid duty cycle value, should be between 0.0 and 1.0.")
-       
+            raise ValueError("Invalid duty cycle value, should be between 0.0 and 1.0.")
+
         # Generate a pattern for 1024 samples of the duty cycle
         pattern = [(1 << self._channel)] * round(PWMOut.MAX_CYCLE_LEVEL * duty_cycle)
-        pattern += [(0 << self._channel)] * round(PWMOut.MAX_CYCLE_LEVEL * (1.0 - duty_cycle))
-        
+        pattern += [(0 << self._channel)] * round(
+            PWMOut.MAX_CYCLE_LEVEL * (1.0 - duty_cycle)
+        )
+
         self._pattern = pattern
         self._duty_cycle = duty_cycle
         if self._enable:
index 37cc6c4aace1081ca481318b66142e09a3992db1..55a439c9949ade9c18d37a455ac28bd52328f38d 100644 (file)
@@ -1,6 +1,7 @@
 """SPI Class for NXP LPC4330"""
 from greatfet import GreatFET
 
+
 class SPI:
     """Custom I2C Class for NXP LPC4330"""
 
@@ -25,8 +26,8 @@ class SPI:
             34000000: (2, 2),
             51000000: (2, 1),
             102000000: (2, 0),
-       }
-        
+        }
+
     # pylint: disable=too-many-arguments
     def init(
         self,
@@ -44,7 +45,7 @@ class SPI:
         polarity = int(polarity)
         phase = int(phase)
         self._mode = (polarity << 1) | phase
-        
+
         # Using API due to possible interface change
         self._spi = self._gf.apis.spi
         # Check baudrate against presets and adjust to the closest one
@@ -57,6 +58,7 @@ class SPI:
 
         # Set the polarity and phase (the "SPI mode").
         self._spi.set_clock_polarity_and_phase(self._mode)
+
     # pylint: enable=too-many-arguments
 
     def _find_closest_preset(self, target_frequency):
@@ -67,7 +69,9 @@ class SPI:
         closest_preset = None
         for frequency in self._presets:
             preset = self._presets[frequency]
-            if self._frequency is None or abs(frequency - target_frequency) < abs(self._frequency - target_frequency):
+            if self._frequency is None or abs(frequency - target_frequency) < abs(
+                self._frequency - target_frequency
+            ):
                 self._frequency = frequency
                 closest_preset = preset
 
@@ -126,8 +130,8 @@ class SPI:
         # Transmit our data in chunks of the buffer size.
         while data_to_transmit:
             # Extract a single data chunk from the transmit buffer.
-            chunk = data_to_transmit[0:self.buffer_size]
-            del data_to_transmit[0:self.buffer_size]
+            chunk = data_to_transmit[0 : self.buffer_size]
+            del data_to_transmit[0 : self.buffer_size]
 
             # Finally, exchange the data.
             response = self._spi.clock_data(len(chunk), bytes(chunk))
index b791269653b5e8de28fd7aafc55df7b8296d093e..16f18737e83cccd96ede299decbe0b2ba1b69768 100644 (file)
@@ -2,13 +2,14 @@
 from greatfet import GreatFET
 from greatfet.interfaces.uart import UART as _UART
 
+
 class UART:
     """Custom UART Class for NXP LPC4330"""
 
-    PARITY_NONE          = 0
-    PARITY_ODD           = 1
-    PARITY_EVEN          = 2
-    PARITY_STUCK_AT_ONE  = 3
+    PARITY_NONE = 0
+    PARITY_ODD = 1
+    PARITY_EVEN = 2
+    PARITY_STUCK_AT_ONE = 3
     PARITY_STUCK_AT_ZERO = 4
 
     # pylint: disable=too-many-arguments
@@ -24,8 +25,15 @@ class UART:
         flow=None,
     ):
         self._gf = GreatFET()
-        self._uart = _UART(self._gf, baud=baudrate, data_bits=bits, stop_bits=stop, parity=parity, uart_number=portid)
-        
+        self._uart = _UART(
+            self._gf,
+            baud=baudrate,
+            data_bits=bits,
+            stop_bits=stop,
+            parity=parity,
+            uart_number=portid,
+        )
+
         if flow is not None:  # default None
             raise NotImplementedError(
                 "Parameter '{}' unsupported on GreatFET One".format("flow")