From: Melissa LeBlanc-Williams Date: Fri, 29 May 2020 18:04:35 +0000 (-0700) Subject: Fixed pylint to check all files and linted X-Git-Tag: 5.0.1^2~1 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/18bc57adc610625742d7be9bc3422d02615d6d4f Fixed pylint to check all files and linted --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83c2a34..b0f79c2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/src/__version__.py b/src/__version__.py index 4bdba83..4a384b3 100644 --- a/src/__version__.py +++ b/src/__version__.py @@ -1,3 +1,4 @@ +"""Return the current version""" VERSION = (1, 0, 0) __version__ = ".".join(map(str, VERSION)) diff --git a/src/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py b/src/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py index 84ceaed..2ba1359 100644 --- a/src/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py +++ b/src/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py @@ -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 diff --git a/src/adafruit_blinka/microcontroller/ft232h/spi.py b/src/adafruit_blinka/microcontroller/ft232h/spi.py index bd4a53b..afdf314 100644 --- a/src/adafruit_blinka/microcontroller/ft232h/spi.py +++ b/src/adafruit_blinka/microcontroller/ft232h/spi.py @@ -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, diff --git a/src/adafruit_blinka/microcontroller/generic_linux/i2c.py b/src/adafruit_blinka/microcontroller/generic_linux/i2c.py index b151798..1870dfc 100644 --- a/src/adafruit_blinka/microcontroller/generic_linux/i2c.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/i2c.py @@ -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""" diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py index 5f72e4f..6cf477c 100644 --- a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pwmout.py @@ -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" diff --git a/src/adafruit_blinka/microcontroller/mcp2221/mcp2221.py b/src/adafruit_blinka/microcontroller/mcp2221/mcp2221.py index 7597ca6..a4a1d99 100644 --- a/src/adafruit_blinka/microcontroller/mcp2221/mcp2221.py +++ b/src/adafruit_blinka/microcontroller/mcp2221/mcp2221.py @@ -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 diff --git a/src/adafruit_blinka/microcontroller/mcp2221/pin.py b/src/adafruit_blinka/microcontroller/mcp2221/pin.py index 758a3da..f5e73bb 100644 --- a/src/adafruit_blinka/microcontroller/mcp2221/pin.py +++ b/src/adafruit_blinka/microcontroller/mcp2221/pin.py @@ -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) diff --git a/src/adafruit_blinka/microcontroller/nova/i2c.py b/src/adafruit_blinka/microcontroller/nova/i2c.py index e5f0beb..75306f8 100644 --- a/src/adafruit_blinka/microcontroller/nova/i2c.py +++ b/src/adafruit_blinka/microcontroller/nova/i2c.py @@ -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, diff --git a/src/adafruit_blinka/microcontroller/nova/pwmout.py b/src/adafruit_blinka/microcontroller/nova/pwmout.py index 478a2bd..00beba7 100644 --- a/src/adafruit_blinka/microcontroller/nova/pwmout.py +++ b/src/adafruit_blinka/microcontroller/nova/pwmout.py @@ -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 diff --git a/src/adafruit_blinka/microcontroller/nova/uart.py b/src/adafruit_blinka/microcontroller/nova/uart.py index 6cf0c58..d84a339 100644 --- a/src/adafruit_blinka/microcontroller/nova/uart.py +++ b/src/adafruit_blinka/microcontroller/nova/uart.py @@ -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""" diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py index 1eadf68..30a8762 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/i2c.py @@ -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: diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py index b3767af..cfa96fe 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pin.py @@ -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() diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py index 01bdb42..5bb7889 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/pwmout.py @@ -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) diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py index 55a439c..17859a4 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/spi.py @@ -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 diff --git a/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py b/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py index 16f1873..3f07700 100644 --- a/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py +++ b/src/adafruit_blinka/microcontroller/nxp_lpc4330/uart.py @@ -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""" diff --git a/src/analogio.py b/src/analogio.py index bde4441..f126ef3 100644 --- a/src/analogio.py +++ b/src/analogio.py @@ -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 diff --git a/src/bitbangio.py b/src/bitbangio.py index 8570620..e523871 100755 --- a/src/bitbangio.py +++ b/src/bitbangio.py @@ -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) diff --git a/src/board.py b/src/board.py index 4bf275e..5c83289 100755 --- a/src/board.py +++ b/src/board.py @@ -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 * diff --git a/src/busio.py b/src/busio.py index d14dcc5..1e636a0 100755 --- a/src/busio.py +++ b/src/busio.py @@ -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) diff --git a/src/digitalio.py b/src/digitalio.py index 8634e41..4b0036b 100755 --- a/src/digitalio.py +++ b/src/digitalio.py @@ -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): diff --git a/src/micropython.py b/src/micropython.py index 6d5c4cd..5f369e3 100755 --- a/src/micropython.py +++ b/src/micropython.py @@ -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") diff --git a/src/pulseio.py b/src/pulseio.py index 7db0b6a..ab44c69 100644 --- a/src/pulseio.py +++ b/src/pulseio.py @@ -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: