From: Melissa LeBlanc-Williams Date: Thu, 14 May 2020 17:03:09 +0000 (-0700) Subject: Black formatted X-Git-Tag: 4.9.0~1^2 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/61d0fc3e10417302119c4ed479b31030dc17a064 Black formatted --- diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py index e37fae1..1eadf68 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py @@ -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( diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py index a67032e..b3767af 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py @@ -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") diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py index 08a31b7..01bdb42 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py @@ -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: diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py index 37cc6c4..55a439c 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py @@ -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)) diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py index b791269..16f1873 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py @@ -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")