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
+"""Return the current version"""
VERSION = (1, 0, 0)
__version__ = ".".join(map(str, VERSION))
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)
)
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
# 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,
_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!")
"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"""
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)
)
"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"
# 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
"""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)
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)
"Received error response from Binho Nova, result = " + result
)
- # pylint: disable=unused-argument
def writeto_then_readfrom(
self,
address,
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
ESCAPE_SEQUENCE = "+++UART0"
- # pylint: disable=too-many-arguments
+ # pylint: disable=too-many-arguments,unused-argument
def __init__(
self,
portid,
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"""
class I2C:
"""Custom I2C Class for NXP LPC4330"""
+ # pylint: disable=unused-argument
def __init__(self, *, frequency=100000):
self._gf = GreatFET()
"""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:
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
"""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")
# 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()
"""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."""
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):
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.
# 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)
self._gf = GreatFET()
self._frequency = None
self.buffer_size = 255
+ self._mode = 0
+ self._spi = None
self._presets = {
204000: (100, 9),
408000: (100, 4),
102000000: (2, 0),
}
- # pylint: disable=too-many-arguments
+ # pylint: disable=too-many-arguments,unused-argument
def init(
self,
baudrate=100000,
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
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,
"Parameter '{}' unsupported on GreatFET One".format("flow")
)
- # pylint: enable=too-many-arguments
+ # pylint: enable=too-many-arguments,unused-argument
def deinit(self):
"""Deinitialize"""
* 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
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"
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:
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]
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),
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)
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 *
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
self._lock = threading.RLock()
def deinit(self):
+ """Deinitialization"""
try:
del self._i2c
except AttributeError:
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)
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(
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,
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:
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
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)
)
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
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:
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:
)
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()
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
)
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)
class DriveMode(Enum):
+ """Drive Mode Enumeration"""
+
PUSH_PULL = None
OPEN_DRAIN = None
class Direction(Enum):
+ """Direction Enumeration"""
+
INPUT = None
OUTPUT = None
class Pull(Enum):
+ """PullUp/PullDown Enumeration"""
+
UP = None
DOWN = None
# NONE=None
class DigitalInOut(ContextManaged):
+ """DigitalInOut CircuitPython compatibility implementation"""
+
_pin = None
def __init__(self, pin):
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:
@property
def value(self):
+ """Get or Set the Digital Pin Value"""
return self._pin.value() == 1
@value.setter
@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):
@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):
+"""
+`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")
+"""
+`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: