]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Fixed pylint to check all files and linted
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Fri, 29 May 2020 18:04:35 +0000 (11:04 -0700)
committerMelissa LeBlanc-Williams <melissa@adafruit.com>
Fri, 29 May 2020 18:04:35 +0000 (11:04 -0700)
23 files changed:
.github/workflows/build.yml
src/__version__.py
src/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py
src/adafruit_blinka/microcontroller/ft232h/spi.py
src/adafruit_blinka/microcontroller/generic_linux/i2c.py
src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py
src/adafruit_blinka/microcontroller/mcp2221/mcp2221.py
src/adafruit_blinka/microcontroller/mcp2221/pin.py
src/adafruit_blinka/microcontroller/nova/i2c.py
src/adafruit_blinka/microcontroller/nova/pwmout.py
src/adafruit_blinka/microcontroller/nova/uart.py
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
src/analogio.py
src/bitbangio.py
src/board.py
src/busio.py
src/digitalio.py
src/micropython.py
src/pulseio.py

index 83c2a340d6095fe385720c863b2737226099eda5..b0f79c273442b0faf46272c006a7839c073a3e79 100644 (file)
@@ -43,7 +43,7 @@ jobs:
         black --check --target-version=py35 .
     - name: PyLint
       run: |
-        pylint src/**/*.py
+        pylint $( find src -name '*.py' )
         ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
     - name: Build docs
       working-directory: docs
index 4bdba83866aa6bc6a98155d0056206765f193e44..4a384b3bf9af6862c40f1b768690d49c4c008413 100644 (file)
@@ -1,3 +1,4 @@
+"""Return the current version"""
 VERSION = (1, 0, 0)
 
 __version__ = ".".join(map(str, VERSION))
index 84ceaedc0f9cb88fad42ecbbc1eccff0eb3a2aaa..2ba135927da79d86e24ae76fd758e9fed9383c63 100644 (file)
@@ -84,6 +84,9 @@ class PWMOut:
         if self._channel is None:
             raise RuntimeError("No PWM channel found for this Pin")
 
+        if variable_frequency:
+            print("Variable Frequency is not supported, continuing without it...")
+
         channel_path = os.path.join(
             self._sysfs_path, self._channel_path.format(self._channel)
         )
@@ -121,9 +124,6 @@ class PWMOut:
             channel_path = os.path.join(
                 self._sysfs_path, self._channel_path.format(self._channel)
             )
-            pin_path = os.path.join(
-                channel_path, self._pin_path.format(self._channel, self._pwmpin)
-            )
 
             if self._channel is not None:
                 # self.duty_cycle = 0
index bd4a53be1b435e20ab7e0cb9ba72379ee789a5a0..afdf3140c5374933f2d9ab6328228f3e385615e4 100644 (file)
@@ -22,7 +22,7 @@ class SPI:
         # Change GPIO controller to SPI
         Pin.ft232h_gpio = self._spi.get_gpio()
 
-    # pylint: disable=too-many-arguments
+    # pylint: disable=too-many-arguments,unused-argument
     def init(
         self,
         baudrate=100000,
index b151798d90d68e77f25a07b708316e1afb2cdd58..1870dfc802eb28206a1bca6c8f3ddbd0fa10d124 100644 (file)
@@ -11,6 +11,7 @@ class I2C:
     _mode = None
     _i2c_bus = None
 
+    # pylint: disable=unused-argument
     def __init__(self, bus_num, mode=MASTER, baudrate=None):
         if mode != self.MASTER:
             raise NotImplementedError("Only I2C Master supported!")
@@ -26,6 +27,8 @@ class I2C:
                 "I2C Bus #%d not found, check if enabled in config!" % bus_num
             )
 
+    # pylint: enable=unused-argument
+
     def scan(self):
         """Try to read a byte from each address, if you get an OSError
         it means the device isnt there"""
index 5f72e4fd40d9d7cd738a8cebe5c31c7651a8a056..6cf477c15dd63aa1e8422890504d92920d847b6d 100644 (file)
@@ -85,6 +85,9 @@ class PWMOut:
         if self._channel is None:
             raise RuntimeError("No PWM channel found for this Pin")
 
+        if variable_frequency:
+            print("Variable Frequency is not supported, continuing without it...")
+
         channel_path = os.path.join(
             self._sysfs_path, self._channel_path.format(self._channel)
         )
@@ -93,7 +96,6 @@ class PWMOut:
                 "PWM channel does not exist, check that the required modules are loaded."
             )
 
-        pin_path = os.path.join(channel_path, self._pin_path.format(self._pwmpin))
         try:
             with open(
                 os.path.join(channel_path, self._unexport_path), "w"
index 7597ca662e4c5a35fa0a3fe9fa7065d9d4f2e84d..a4a1d990a58ecd8419873c81d2cd4b62403e6a5d 100644 (file)
@@ -268,7 +268,7 @@ class MCP2221:
 
         # and now the read part
         while (end - start) > 0:
-            for retry in range(MCP2221_RETRY_MAX):
+            for _ in range(MCP2221_RETRY_MAX):
                 # the actual read
                 resp = self._hid_xfer(b"\x40")
                 # check for success
index 758a3daa27f94b44f035cffeecf08174a9b1cb28..f5e73bb60534eca7478c2e480ed4280097875763 100644 (file)
@@ -22,6 +22,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):
             # All pins can do GPIO
             mcp2221.gp_set_mode(self.id, mcp2221.GP_GPIO)
index e5f0beb747044b854e9add67efb8d38ee928ff25..75306f8270fe7db68da1f458c400cb904e2d9d3f 100644 (file)
@@ -41,6 +41,7 @@ class I2C:
         else:
             self._nova.endI2C(0, True)
 
+    # pylint: disable=unused-argument
     def readfrom_into(self, address, buffer, *, start=0, end=None, stop=True):
         """Read data from an address and into the buffer"""
         end = end if end else len(buffer)
@@ -57,7 +58,6 @@ class I2C:
                 "Received error response from Binho Nova, result = " + result
             )
 
-    # pylint: disable=unused-argument
     def writeto_then_readfrom(
         self,
         address,
index 478a2bd1b3e6ec427cc27edeba3b32c86f0bb4d8..00beba767064bb64a7c4d8289894aa1e6a02a532 100644 (file)
@@ -78,6 +78,9 @@ class PWMOut:
         if self._channel is None:
             raise RuntimeError("No PWM channel found for this Pin")
 
+        if variable_frequency:
+            print("Variable Frequency is not supported, continuing without it...")
+
         PWMOut._nova.setIOpinMode(self._pwmpin, Pin.PWM)
 
         # set frequency
index 6cf0c589452d7e74ac2390a7cea661f52be01d5c..d84a339178f455eb1364b513e962b7062379982a 100644 (file)
@@ -8,7 +8,7 @@ class UART:
 
     ESCAPE_SEQUENCE = "+++UART0"
 
-    # pylint: disable=too-many-arguments
+    # pylint: disable=too-many-arguments,unused-argument
     def __init__(
         self,
         portid,
@@ -42,7 +42,7 @@ class UART:
         self._nova.setEscapeSequenceUART(self._id, UART.ESCAPE_SEQUENCE)
         self._nova.beginBridgeUART(self._id)
 
-    # pylint: enable=too-many-arguments
+    # pylint: enable=too-many-arguments,unused-argument
 
     def deinit(self):
         """Deinitialize"""
index 1eadf688098fc74727f4c614f9b6f60354de50b2..30a876295754f2f54bfd356f58cfb8a35806833d 100644 (file)
@@ -5,6 +5,7 @@ from greatfet import GreatFET
 class I2C:
     """Custom I2C Class for NXP LPC4330"""
 
+    # pylint: disable=unused-argument
     def __init__(self, *, frequency=100000):
         self._gf = GreatFET()
 
@@ -12,7 +13,6 @@ class I2C:
         """Perform an I2C Device Scan"""
         return [index for index, dev in enumerate(self._gf.i2c.scan()) if dev[0]]
 
-    # pylint: disable=unused-argument
     def writeto(self, address, buffer, *, start=0, end=None, stop=True):
         """Write data from the buffer to an address"""
         if end is None:
index b3767af505cd9461704e39764b8fa9f1c8202cf5..cfa96fe2ccababefb07f1e701a95a584d1842573 100644 (file)
@@ -6,12 +6,15 @@ try:
     gf = GreatFET()
 except:
     raise RuntimeError(
-        "Unable to create GreatFET object. Make sure library is installed and the device is connected."
+        "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."""
+    """A basic Pin class for the NXP LPC4330 that
+    acts as a wrapper for the GreatFET api.
+    """
 
     # pin modes
     OUT = gf.gpio.DIRECTION_OUT
@@ -32,6 +35,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")
@@ -41,12 +46,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()
index 01bdb4298d768ae30dee40d0a17ba8f5596ad722..5bb7889d3430f74aff8f13a37f2a6f6da742898d 100644 (file)
@@ -1,16 +1,12 @@
 """PWMOut Class for NXP LPC4330"""
 
 from greatfet import GreatFET
-from greatfet.interfaces.pattern_generator import PatternGenerator
 
 try:
     from microcontroller.pin import pwmOuts
 except ImportError:
     raise RuntimeError("No PWM outputs defined for this board")
 
-from microcontroller.pin import Pin
-
-
 # pylint: disable=unnecessary-pass
 class PWMError(IOError):
     """Base class for PWM errors."""
@@ -46,11 +42,13 @@ class PWMOut:
         self._gf = GreatFET()
 
         if variable_frequency:
-            raise NotImplemented("Variable Frequency is not currently supported.")
+            raise NotImplementedError("Variable Frequency is not currently supported.")
 
         self._pattern = None
         self._channel = None
         self._enable = False
+        self._frequency = 500
+        self._duty_cycle = 0
         self._open(pin, duty_cycle, frequency)
 
     def __enter__(self):
@@ -162,7 +160,7 @@ class PWMOut:
     duty_cycle = property(_get_duty_cycle, _set_duty_cycle)
 
     def _get_frequency(self):
-        return int(PWMOut._nova.getIOpinPWMFreq(self._pwmpin).split("PWMFREQ ")[1])
+        return self._frequency
 
     def _set_frequency(self, frequency):
         """Get or set the PWM's output frequency in Hertz.
@@ -178,6 +176,7 @@ class PWMOut:
 
         # We are sending 1024 samples per second already
         self._gf.pattern_generator.set_sample_rate(frequency * len(self._pattern))
+        self._frequency = frequency
 
     frequency = property(_get_frequency, _set_frequency)
 
index 55a439c9949ade9c18d37a455ac28bd52328f38d..17859a42d374e19b23f93de123c7ea97172072d7 100644 (file)
@@ -11,6 +11,8 @@ class SPI:
         self._gf = GreatFET()
         self._frequency = None
         self.buffer_size = 255
+        self._mode = 0
+        self._spi = None
         self._presets = {
             204000: (100, 9),
             408000: (100, 4),
@@ -28,7 +30,7 @@ class SPI:
             102000000: (2, 0),
         }
 
-    # pylint: disable=too-many-arguments
+    # pylint: disable=too-many-arguments,unused-argument
     def init(
         self,
         baudrate=100000,
@@ -108,8 +110,6 @@ class SPI:
         in_end = in_end if in_end else len(buffer_in)
 
         result = self._transmit(buffer_out[out_start:out_end], in_end - in_start)
-        for i, b in enumerate(result):
-            buf[start + i] = b
         for i, b in enumerate(result):
             buffer_in[in_start + i] = b
 
index 16f18737e83cccd96ede299decbe0b2ba1b69768..3f077001ce8433a65f84b3a4e1afed563939e046 100644 (file)
@@ -12,7 +12,7 @@ class UART:
     PARITY_STUCK_AT_ONE = 3
     PARITY_STUCK_AT_ZERO = 4
 
-    # pylint: disable=too-many-arguments
+    # pylint: disable=too-many-arguments,unused-argument
     def __init__(
         self,
         portid,
@@ -39,7 +39,7 @@ class UART:
                 "Parameter '{}' unsupported on GreatFET One".format("flow")
             )
 
-    # pylint: enable=too-many-arguments
+    # pylint: enable=too-many-arguments,unused-argument
 
     def deinit(self):
         """Deinitialize"""
index bde4441e783af0d4b8e2502832617d27b6a0c255..f126ef326b9d146d5f5d720a34e26ecca888b8c9 100644 (file)
@@ -5,9 +5,9 @@ See `CircuitPython:analogio` in CircuitPython for more details.
 * Author(s): Carter Nelson, Melissa LeBlanc-Williams
 """
 
-from adafruit_blinka.agnostic import board_id, detector
+from adafruit_blinka.agnostic import detector
 
-# pylint: disable=ungrouped-imports,wrong-import-position
+# pylint: disable=ungrouped-imports,wrong-import-position,unused-import
 
 if detector.board.microchip_mcp2221:
     from adafruit_blinka.microcontroller.mcp2221.analogio import AnalogIn
index 8570620c21b3e92e0e171e2012d62503a1d88ece..e52387157e9acd69f2d4295621be3ee6b244f301 100755 (executable)
@@ -10,13 +10,17 @@ See `CircuitPython:bitbangio` in CircuitPython for more details.
 from adafruit_blinka import Lockable, agnostic
 import adafruit_platformdetect.constants.boards as ap_board
 
+# pylint: disable=import-outside-toplevel,too-many-arguments
+
 
 class I2C(Lockable):
+    """Bitbang/Software I2C implementation"""
+
     def __init__(self, scl, sda, frequency=400000):
         # TODO: This one is a bit questionable:
         if agnostic.board_id == ap_board.PYBOARD:
             raise NotImplementedError("No software I2C on {}".format(agnostic.board_id))
-        elif agnostic.detector.board.any_embedded_linux:
+        if agnostic.detector.board.any_embedded_linux:
             # TODO: Attempt to load this library automatically
             raise NotImplementedError(
                 "For bitbangio on Linux, please use Adafruit_CircuitPython_BitbangIO"
@@ -24,16 +28,19 @@ class I2C(Lockable):
         self.init(scl, sda, frequency)
 
     def init(self, scl, sda, frequency):
+        """Initialization"""
         from machine import Pin
         from machine import I2C as _I2C
 
         self.deinit()
-        id = (
+        id = (  # pylint: disable=redefined-builtin
             -1
-        )  # force bitbanging implementation - in future introspect platform if SDA/SCL matches hardware I2C
+        )  # force bitbanging implementation - in future
+        # introspect platform if SDA/SCL matches hardware I2C
         self._i2c = _I2C(id, Pin(scl.id), Pin(sda.id), freq=frequency)
 
     def deinit(self):
+        """Deinitialization"""
         try:
             del self._i2c
         except AttributeError:
@@ -46,10 +53,12 @@ class I2C(Lockable):
         self.deinit()
 
     def scan(self):
+        """Scan for attached devices"""
         return self._i2c.scan()
 
     def readfrom_into(self, address, buffer, start=0, end=None):
-        if start is not 0 or end is not None:
+        """Read from a device at specified address into a buffer"""
+        if start != 0 or end is not None:
             if end is None:
                 end = len(buffer)
             buffer = memoryview(buffer)[start:end]
@@ -57,39 +66,45 @@ class I2C(Lockable):
         return self._i2c.readfrom_into(address, buffer, stop)
 
     def writeto(self, address, buffer, start=0, end=None, stop=True):
-        if start is not 0 or end is not None:
+        """Write to a device at specified address from a buffer"""
+        if start != 0 or end is not None:
             if end is None:
                 return self._i2c.writeto(address, memoryview(buffer)[start:], stop)
-            else:
-                return self._i2c.writeto(address, memoryview(buffer)[start:end], stop)
+            return self._i2c.writeto(address, memoryview(buffer)[start:end], stop)
         return self._i2c.writeto(address, buffer, stop)
 
 
-# TODO untested, as actually busio.SPI was on tasklist https://github.com/adafruit/Adafruit_Micropython_Blinka/issues/2 :(
+# TODO untested, as actually busio.SPI was on
+# tasklist https://github.com/adafruit/Adafruit_Micropython_Blinka/issues/2 :(
 class SPI(Lockable):
+    """Bitbang/Software SPI implementation"""
+
     def __init__(self, clock, MOSI=None, MISO=None):
         if agnostic.detector.board.any_embedded_linux:
             # TODO: Attempt to load this library automatically
             raise NotImplementedError(
                 "For bitbangio on Linux, please use Adafruit_CircuitPython_BitbangIO"
             )
-        from machine import SPI
+        from machine import SPI as _SPI
 
-        self._spi = SPI(-1)
+        self._spi = _SPI(-1)
         self._pins = (clock, MOSI, MISO)
 
     def configure(self, baudrate=100000, polarity=0, phase=0, bits=8):
-        from machine import SPI, Pin
+        """Update the configuration"""
+        from machine import Pin
+        from machine import SPI as _SPI
 
         if self._locked:
-            # TODO verify if _spi obj 'caches' sck, mosi, miso to avoid storing in _attributeIds (duplicated in busio)
+            # TODO verify if _spi obj 'caches' sck, mosi, miso to
+            # avoid storing in _attributeIds (duplicated in busio)
             # i.e. #init ignores MOSI=None rather than unsetting
             self._spi.init(
                 baudrate=baudrate,
                 polarity=polarity,
                 phase=phase,
                 bits=bits,
-                firstbit=SPI.MSB,
+                firstbit=_SPI.MSB,
                 sck=Pin(self._pins[0].id),
                 mosi=Pin(self._pins[1].id),
                 miso=Pin(self._pins[2].id),
@@ -98,10 +113,13 @@ class SPI(Lockable):
             raise RuntimeError("First call try_lock()")
 
     def write(self, buf):
+        """Write to the SPI device"""
         return self._spi.write(buf)
 
     def readinto(self, buf):
+        """Read from the SPI device into a buffer"""
         return self.readinto(buf)
 
     def write_readinto(self, buffer_out, buffer_in):
+        """Write to the SPI device and read from the SPI device into a buffer"""
         return self.write_readinto(buffer_out, buffer_in)
index 4bf275e051e4abebd131d1c21aa7935412ea91e3..5c83289a51799c063b4d0a481dd7083a1550aaeb 100755 (executable)
@@ -33,6 +33,7 @@ from adafruit_blinka.agnostic import board_id, detector
 import adafruit_platformdetect.constants.boards as ap_board
 
 # pylint: disable=wildcard-import,unused-wildcard-import,ungrouped-imports
+# pylint: disable=import-outside-toplevel
 
 if board_id == ap_board.FEATHER_HUZZAH:
     from adafruit_blinka.board.feather_huzzah import *
index d14dcc5844f7894d7fc2523b45ca2ae08a1a4419..1e636a0724148ce034d0423c521748790fa51a3e 100755 (executable)
@@ -14,34 +14,43 @@ from adafruit_blinka.agnostic import board_id, detector
 import adafruit_platformdetect.constants.boards as ap_board
 import adafruit_platformdetect.constants.chips as ap_chip
 
+# pylint: disable=import-outside-toplevel,too-many-branches,too-many-statements
+# pylint: disable=too-many-arguments,too-many-function-args
+
 
 class I2C(Lockable):
+    """
+    Busio I2C Class for CircuitPython Compatibility. Used
+    for both MicroPython and Linux.
+    """
+
     def __init__(self, scl, sda, frequency=400000):
         self.init(scl, sda, frequency)
 
     def init(self, scl, sda, frequency):
+        """Initialization"""
         self.deinit()
         if detector.board.ftdi_ft232h:
-            from adafruit_blinka.microcontroller.ft232h.i2c import I2C
+            from adafruit_blinka.microcontroller.ft232h.i2c import I2C as _I2C
 
-            self._i2c = I2C(frequency=frequency)
+            self._i2c = _I2C(frequency=frequency)
             return
-        elif detector.board.binho_nova:
-            from adafruit_blinka.microcontroller.nova.i2c import I2C
+        if detector.board.binho_nova:
+            from adafruit_blinka.microcontroller.nova.i2c import I2C as _I2C
 
-            self._i2c = I2C(frequency=frequency)
+            self._i2c = _I2C(frequency=frequency)
             return
-        elif detector.board.microchip_mcp2221:
-            from adafruit_blinka.microcontroller.mcp2221.i2c import I2C
+        if detector.board.microchip_mcp2221:
+            from adafruit_blinka.microcontroller.mcp2221.i2c import I2C as _I2C
 
-            self._i2c = I2C(frequency=frequency)
+            self._i2c = _I2C(frequency=frequency)
             return
-        elif detector.board.greatfet_one:
-            from adafruit_blinka.microcontroller.nxp_lpc4330.i2c import I2C
+        if detector.board.greatfet_one:
+            from adafruit_blinka.microcontroller.nxp_lpc4330.i2c import I2C as _I2C
 
-            self._i2c = I2C(frequency=frequency)
+            self._i2c = _I2C(frequency=frequency)
             return
-        elif detector.board.any_embedded_linux:
+        if detector.board.any_embedded_linux:
             from adafruit_blinka.microcontroller.generic_linux.i2c import I2C as _I2C
         else:
             from machine import I2C as _I2C
@@ -64,6 +73,7 @@ class I2C(Lockable):
         self._lock = threading.RLock()
 
     def deinit(self):
+        """Deinitialization"""
         try:
             del self._i2c
         except AttributeError:
@@ -78,9 +88,11 @@ class I2C(Lockable):
         self.deinit()
 
     def scan(self):
+        """Scan for attached devices"""
         return self._i2c.scan()
 
     def readfrom_into(self, address, buffer, *, start=0, end=None):
+        """Read from a device at specified address into a buffer"""
         if start != 0 or end is not None:
             if end is None:
                 end = len(buffer)
@@ -89,15 +101,13 @@ class I2C(Lockable):
         return self._i2c.readfrom_into(address, buffer, stop=stop)
 
     def writeto(self, address, buffer, *, start=0, end=None, stop=True):
+        """Write to a device at specified address from a buffer"""
         if isinstance(buffer, str):
             buffer = bytes([ord(x) for x in buffer])
         if start != 0 or end is not None:
             if end is None:
                 return self._i2c.writeto(address, memoryview(buffer)[start:], stop=stop)
-            else:
-                return self._i2c.writeto(
-                    address, memoryview(buffer)[start:end], stop=stop
-                )
+            return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
         return self._i2c.writeto(address, buffer, stop=stop)
 
     def writeto_then_readfrom(
@@ -112,6 +122,9 @@ class I2C(Lockable):
         in_end=None,
         stop=False
     ):
+        """"Write to a device at specified address from a buffer then read
+        from a device at specified address into a buffer
+        """
         return self._i2c.writeto_then_readfrom(
             address,
             buffer_out,
@@ -125,6 +138,11 @@ class I2C(Lockable):
 
 
 class SPI(Lockable):
+    """
+    Busio SPI Class for CircuitPython Compatibility. Used
+    for both MicroPython and Linux.
+    """
+
     def __init__(self, clock, MOSI=None, MISO=None):
         self.deinit()
         if detector.board.ftdi_ft232h:
@@ -134,21 +152,21 @@ class SPI(Lockable):
             self._spi = _SPI()
             self._pins = (SCK, MOSI, MISO)
             return
-        elif detector.board.binho_nova:
+        if detector.board.binho_nova:
             from adafruit_blinka.microcontroller.nova.spi import SPI as _SPI
             from adafruit_blinka.microcontroller.nova.pin import SCK, MOSI, MISO
 
             self._spi = _SPI(clock)
             self._pins = (SCK, MOSI, MISO)
             return
-        elif detector.board.greatfet_one:
+        if detector.board.greatfet_one:
             from adafruit_blinka.microcontroller.nxp_lpc4330.spi import SPI as _SPI
             from adafruit_blinka.microcontroller.nxp_lpc4330.pin import SCK, MOSI, MISO
 
             self._spi = _SPI()
             self._pins = (SCK, MOSI, MISO)
             return
-        elif detector.board.any_embedded_linux:
+        if detector.board.any_embedded_linux:
             from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
         else:
             from machine import SPI as _SPI
@@ -157,8 +175,8 @@ class SPI(Lockable):
         for portId, portSck, portMosi, portMiso in spiPorts:
             if (
                 (clock == portSck)
-                and (MOSI == portMosi or MOSI == None)  # Clock is required!
-                and (MISO == portMiso or MISO == None)  # But can do with just output
+                and MOSI in (portMosi, None)  # Clock is required!
+                and MISO in (portMiso, None)  # But can do with just output
             ):  # Or just input
                 self._spi = _SPI(portId)
                 self._pins = (portSck, portMosi, portMiso)
@@ -171,6 +189,7 @@ class SPI(Lockable):
             )
 
     def configure(self, baudrate=100000, polarity=0, phase=0, bits=8):
+        """Update the configuration"""
         if detector.board.any_raspberry_pi or detector.board.any_raspberry_pi_40_pin:
             from adafruit_blinka.microcontroller.bcm283x.pin import Pin
             from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
@@ -228,11 +247,7 @@ class SPI(Lockable):
         elif detector.board.greatfet_one:
             from adafruit_blinka.microcontroller.nxp_lpc4330.spi import SPI as _SPI
             from adafruit_blinka.microcontroller.nxp_lpc4330.pin import Pin
-        elif (
-            board_id == ap_board.PINE64
-            or board_id == ap_board.PINEBOOK
-            or board_id == ap_board.PINEPHONE
-        ):
+        elif board_id in (ap_board.PINE64, ap_board.PINEBOOK, ap_board.PINEPHONE):
             from adafruit_blinka.microcontroller.allwinner.a64.pin import Pin
             from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
         elif board_id == ap_board.CLOCKWORK_CPI3:
@@ -261,11 +276,13 @@ class SPI(Lockable):
             raise RuntimeError("First call try_lock()")
 
     def deinit(self):
+        """Deinitialization"""
         self._spi = None
         self._pinIds = None
 
     @property
     def frequency(self):
+        """Return the baud rate if implemented"""
         try:
             return self._spi.frequency
         except AttributeError:
@@ -274,22 +291,32 @@ class SPI(Lockable):
             )
 
     def write(self, buf, start=0, end=None):
+        """Write to the SPI device"""
         return self._spi.write(buf, start, end)
 
     def readinto(self, buf, start=0, end=None, write_value=0):
+        """Read from the SPI device into a buffer"""
         return self._spi.readinto(buf, start, end, write_value=write_value)
 
     def write_readinto(
         self, buffer_out, buffer_in, out_start=0, out_end=None, in_start=0, in_end=None
     ):
+        """Write to the SPI device and read from the SPI device into a buffer"""
         return self._spi.write_readinto(
             buffer_out, buffer_in, out_start, out_end, in_start, in_end
         )
 
 
 class UART(Lockable):
+    """
+    Busio UART Class for CircuitPython Compatibility. Used
+    for MicroPython and a few other non-Linux boards.
+    """
+
     class Parity(Enum):
-        pass
+        """Parity Enumeration"""
+
+        pass  # pylint: disable=unnecessary-pass
 
     Parity.ODD = Parity()
     Parity.EVEN = Parity()
@@ -310,7 +337,7 @@ class UART(Lockable):
             raise RuntimeError(
                 "busio.UART not supported on this platform. Please use pyserial instead."
             )
-        elif detector.board.binho_nova:
+        if detector.board.binho_nova:
             from adafruit_blinka.microcontroller.nova.uart import UART as _UART
         elif detector.board.greatfet_one:
             from adafruit_blinka.microcontroller.nxp_lpc4330.uart import UART as _UART
@@ -360,18 +387,23 @@ class UART(Lockable):
             )
 
     def deinit(self):
+        """Deinitialization"""
         if detector.board.binho_nova:
             self._uart.deinit()
         self._uart = None
 
     def read(self, nbytes=None):
+        """Read from the UART"""
         return self._uart.read(nbytes)
 
     def readinto(self, buf, nbytes=None):
+        """Read from the UART into a buffer"""
         return self._uart.readinto(buf, nbytes)
 
     def readline(self):
+        """Read a line of characters up to a newline charater from the UART"""
         return self._uart.readline()
 
     def write(self, buf):
+        """Write to the UART from a buffer"""
         return self._uart.write(buf)
index 8634e411649e851252558344441743cb9f888e07..4b0036b6537f835236f5324f8bb45418a03e3ddc 100755 (executable)
@@ -61,6 +61,8 @@ from adafruit_blinka import Enum, ContextManaged
 
 
 class DriveMode(Enum):
+    """Drive Mode Enumeration"""
+
     PUSH_PULL = None
     OPEN_DRAIN = None
 
@@ -70,6 +72,8 @@ DriveMode.OPEN_DRAIN = DriveMode()
 
 
 class Direction(Enum):
+    """Direction Enumeration"""
+
     INPUT = None
     OUTPUT = None
 
@@ -79,6 +83,8 @@ Direction.OUTPUT = Direction()
 
 
 class Pull(Enum):
+    """PullUp/PullDown Enumeration"""
+
     UP = None
     DOWN = None
     # NONE=None
@@ -91,6 +97,8 @@ Pull.DOWN = Pull()
 
 
 class DigitalInOut(ContextManaged):
+    """DigitalInOut CircuitPython compatibility implementation"""
+
     _pin = None
 
     def __init__(self, pin):
@@ -98,29 +106,33 @@ class DigitalInOut(ContextManaged):
         self.direction = Direction.INPUT
 
     def switch_to_output(self, value=False, drive_mode=DriveMode.PUSH_PULL):
+        """Switch the Digital Pin Mode to Output"""
         self.direction = Direction.OUTPUT
         self.value = value
         self.drive_mode = drive_mode
 
     def switch_to_input(self, pull=None):
+        """Switch the Digital Pin Mode to Input"""
         self.direction = Direction.INPUT
         self.pull = pull
 
     def deinit(self):
+        """Deinitialize the Digital Pin"""
         del self._pin
 
     @property
     def direction(self):
+        """Get or Set the Digital Pin Direction"""
         return self.__direction
 
     @direction.setter
-    def direction(self, dir):
-        self.__direction = dir
-        if dir is Direction.OUTPUT:
+    def direction(self, value):
+        self.__direction = value
+        if value is Direction.OUTPUT:
             self._pin.init(mode=Pin.OUT)
             self.value = False
             self.drive_mode = DriveMode.PUSH_PULL
-        elif dir is Direction.INPUT:
+        elif value is Direction.INPUT:
             self._pin.init(mode=Pin.IN)
             self.pull = None
         else:
@@ -128,6 +140,7 @@ class DigitalInOut(ContextManaged):
 
     @property
     def value(self):
+        """Get or Set the Digital Pin Value"""
         return self._pin.value() == 1
 
     @value.setter
@@ -139,10 +152,10 @@ class DigitalInOut(ContextManaged):
 
     @property
     def pull(self):
+        """Get or Set the Digital Pin Direction"""
         if self.direction is Direction.INPUT:
             return self.__pull
-        else:
-            raise AttributeError("Not an input")
+        raise AttributeError("Not an input")
 
     @pull.setter
     def pull(self, pul):
@@ -166,10 +179,10 @@ class DigitalInOut(ContextManaged):
 
     @property
     def drive_mode(self):
+        """Get or Set the Digital Pin Drive Mode"""
         if self.direction is Direction.OUTPUT:
             return self.__drive_mode  #
-        else:
-            raise AttributeError("Not an output")
+        raise AttributeError("Not an output")
 
     @drive_mode.setter
     def drive_mode(self, mod):
index 6d5c4cd182d2ce0e69a06fe9ddb01a921e02cd1d..5f369e3f0df022d3594edd97633e5093ed303266 100755 (executable)
@@ -1,14 +1,26 @@
+"""
+`micropython` - MicroPython Specific Decorator Functions
+=================================================
+
+* Author(s): cefn
+"""
+
+
 def const(x):
+    "Emulate making a constant"
     return x
 
 
 def native(f):
+    "Emulate making a native"
     return f
 
 
 def viper(f):
+    "User is attempting to use a viper code emitter"
     raise SyntaxError("invalid micropython decorator")
 
 
 def asm_thumb(f):
+    "User is attempting to use an inline assembler"
     raise SyntaxError("invalid micropython decorator")
index 7db0b6a36727d49765838d3ed95497ca3a27381d..ab44c69e360723817cf761a94e52f7a6f83f6b4b 100644 (file)
@@ -1,5 +1,14 @@
+"""
+`pulseio` - Pulse Width Modulation Input and Output control
+=================================================
+See `CircuitPython:pulseio` in CircuitPython for more details.
+* Author(s): Melissa LeBlanc-Williams
+"""
+
 from adafruit_blinka.agnostic import detector
 
+# pylint: disable=unused-import
+
 if detector.board.any_raspberry_pi:
     from adafruit_blinka.microcontroller.bcm283x.pulseio.PulseIn import PulseIn
 if detector.board.any_coral_board: