Browse Source

YAPF PEP8 auto-reformat layout and whitespace (no code changes)

master^2
Cefn Hoile 3 years ago
parent
commit
5da8051ef5
12 changed files with 219 additions and 171 deletions
  1. +3
    -1
      src/adafruit_blinka/__init__.py
  2. +2
    -2
      src/adafruit_blinka/agnostic.py
  3. +23
    -20
      src/adafruit_blinka/board/feather_huzzah.py
  4. +49
    -49
      src/adafruit_blinka/board/pyboard.py
  5. +2
    -5
      src/adafruit_blinka/microcontroller/esp8266/__init__.py
  6. +12
    -14
      src/adafruit_blinka/microcontroller/esp8266/pin.py
  7. +2
    -5
      src/adafruit_blinka/microcontroller/stm32/__init__.py
  8. +47
    -47
      src/adafruit_blinka/microcontroller/stm32/pin.py
  9. +12
    -3
      src/bitbangio.py
  10. +1
    -2
      src/board.py
  11. +49
    -15
      src/busio.py
  12. +17
    -8
      src/digitalio.py

+ 3
- 1
src/adafruit_blinka/__init__.py View File

@ -1,5 +1,6 @@
"""Module providing runtime utility objects to support the Micro/CircuitPython api"""
class Enum(object):
"""
Object supporting CircuitPython-style of static symbols
@ -37,6 +38,7 @@ class ContextManaged:
def __exit__(self, exc_type, exc_value, traceback):
self.deinit()
class Lockable(ContextManaged):
_locked = False
@ -44,7 +46,7 @@ class Lockable(ContextManaged):
if self._locked:
return False
else:
self._locked=True
self._locked = True
return True
def unlock(self):


+ 2
- 2
src/adafruit_blinka/agnostic.py View File

@ -15,7 +15,7 @@ except:
board = None
if microcontroller is not None:
if microcontroller == "esp8266": # TODO more conservative board-guessing
if microcontroller == "esp8266": # TODO more conservative board-guessing
board = "feather_huzzah"
elif microcontroller == "samd21":
board = "feather_m0_express"
@ -28,4 +28,4 @@ if implementation == "micropython":
from utime import sleep
elif implementation == "circuitpython":
from time import sleep
gc.collect()
gc.collect()

+ 23
- 20
src/adafruit_blinka/board/feather_huzzah.py View File

@ -2,28 +2,31 @@ from adafruit_blinka.microcontroller.esp8266 import pin
# TODO need equiv of INPUT_PULL_DOWN_16 ? see https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html
GPIO0= pin.GPIO0
GPIO1= pin.GPIO1
GPIO2= pin.GPIO2
GPIO3= pin.GPIO3
GPIO4= pin.GPIO4
GPIO5= pin.GPIO5
GPIO12= pin.GPIO12
GPIO13= pin.GPIO13
GPIO14= pin.GPIO14
GPIO15= pin.GPIO15
GPIO16= pin.GPIO16
GPIO0 = pin.GPIO0
GPIO1 = pin.GPIO1
GPIO2 = pin.GPIO2
GPIO3 = pin.GPIO3
GPIO4 = pin.GPIO4
GPIO5 = pin.GPIO5
GPIO12 = pin.GPIO12
GPIO13 = pin.GPIO13
GPIO14 = pin.GPIO14
GPIO15 = pin.GPIO15
GPIO16 = pin.GPIO16
ADC= pin.TOUT
ADC = pin.TOUT
MISO=GPIO12
MOSI=GPIO13
SCK=GPIO14
MISO = GPIO12
MOSI = GPIO13
SCK = GPIO14
RX=GPIO3
TX=GPIO1
RX = GPIO3
TX = GPIO1
SDA=GPIO4
SCL=GPIO5
SDA = GPIO4
SCL = GPIO5
['ADC', 'GPIO16', 'GPIO14', 'SCK', 'GPIO12', 'MISO', 'GPIO13', 'MOSI', 'GPIO15', 'GPIO2', 'GPIO0', 'GPIO4', 'SDA', 'RX', 'TX', 'GPIO5', 'SCL']
[
'ADC', 'GPIO16', 'GPIO14', 'SCK', 'GPIO12', 'MISO', 'GPIO13', 'MOSI',
'GPIO15', 'GPIO2', 'GPIO0', 'GPIO4', 'SDA', 'RX', 'TX', 'GPIO5', 'SCL'
]

+ 49
- 49
src/adafruit_blinka/board/pyboard.py View File

@ -1,51 +1,51 @@
from adafruit_blinka.microcontroller.stm32 import pin
X1=pin.A0
X2=pin.A1
X3=pin.A2
X4=pin.A3
X5=pin.A4
X6=pin.A5
X7=pin.A6
X8=pin.A7
X9=pin.B6
X10=pin.B7
X11=pin.C4
X12=pin.C5
X17=pin.B3
X18=pin.C13
X19=pin.C0
X20=pin.C1
X21=pin.C2
X22=pin.C3
Y1=pin.C6
Y2=pin.C7
Y3=pin.B8
Y4=pin.B9
Y5=pin.B12
Y6=pin.B13
Y7=pin.B14
Y8=pin.B15
Y9=pin.B10
Y10=pin.B11
Y11=pin.B0
Y12=pin.B1
SW=pin.B3
LED_RED=pin.A13
LED_GREEN=pin.A14
LED_YELLOW=pin.A15
LED_BLUE=pin.B4
MMA_INT=pin.B2
MMA_AVDD=pin.B5
SD_D0=pin.C8
SD_D1=pin.C9
SD_D2=pin.C10
SD_D3=pin.C11
SD_CMD=pin.D2
SD_CK=pin.C12
SD=pin.A8
SD_SW=pin.A8
USB_VBUS=pin.A9
USB_ID=pin.A10
USB_DM=pin.A11
USB_DP=pin.A12
X1 = pin.A0
X2 = pin.A1
X3 = pin.A2
X4 = pin.A3
X5 = pin.A4
X6 = pin.A5
X7 = pin.A6
X8 = pin.A7
X9 = pin.B6
X10 = pin.B7
X11 = pin.C4
X12 = pin.C5
X17 = pin.B3
X18 = pin.C13
X19 = pin.C0
X20 = pin.C1
X21 = pin.C2
X22 = pin.C3
Y1 = pin.C6
Y2 = pin.C7
Y3 = pin.B8
Y4 = pin.B9
Y5 = pin.B12
Y6 = pin.B13
Y7 = pin.B14
Y8 = pin.B15
Y9 = pin.B10
Y10 = pin.B11
Y11 = pin.B0
Y12 = pin.B1
SW = pin.B3
LED_RED = pin.A13
LED_GREEN = pin.A14
LED_YELLOW = pin.A15
LED_BLUE = pin.B4
MMA_INT = pin.B2
MMA_AVDD = pin.B5
SD_D0 = pin.C8
SD_D1 = pin.C9
SD_D2 = pin.C10
SD_D3 = pin.C11
SD_CMD = pin.D2
SD_CK = pin.C12
SD = pin.A8
SD_SW = pin.A8
USB_VBUS = pin.A9
USB_ID = pin.A10
USB_DM = pin.A11
USB_DP = pin.A12

+ 2
- 5
src/adafruit_blinka/microcontroller/esp8266/__init__.py View File

@ -1,11 +1,8 @@
# ordered as spiId, sckId, mosiId, misoId
spiPorts = (
(1, 14, 13, 12)
)
spiPorts = ((1, 14, 13, 12))
# ordered as uartId, txId, rxId
uartPorts = (
(0, 1, 3),
# (0, 15, 13) # TODO secondary pins for UART0 configurable from Micropython?
(1, 2, None)
)
(1, 2, None))

+ 12
- 14
src/adafruit_blinka/microcontroller/esp8266/pin.py View File

@ -1,18 +1,17 @@
from microcontroller import Pin
GPIO0=Pin(0)
GPIO1=Pin(1)
GPIO2=Pin(2)
GPIO3=Pin(3)
GPIO4=Pin(4)
GPIO5=Pin(5)
GPIO12=Pin(12)
GPIO13=Pin(13)
GPIO14=Pin(14)
GPIO15=Pin(15)
GPIO16=Pin(16)
TOUT=Pin("TOUT")
GPIO0 = Pin(0)
GPIO1 = Pin(1)
GPIO2 = Pin(2)
GPIO3 = Pin(3)
GPIO4 = Pin(4)
GPIO5 = Pin(5)
GPIO12 = Pin(12)
GPIO13 = Pin(13)
GPIO14 = Pin(14)
GPIO15 = Pin(15)
GPIO16 = Pin(16)
TOUT = Pin("TOUT")
"""
From introspection of microcontroller.pin on Feather Huzzah running CircuitPython
>>> dir(microcontroller.pin)
@ -20,7 +19,6 @@ From introspection of microcontroller.pin on Feather Huzzah running CircuitPytho
>>> dir(board)
['ADC', 'GPIO16', 'GPIO14', 'SCK', 'GPIO12', 'MISO', 'GPIO13', 'MOSI', 'GPIO15', 'GPIO2', 'GPIO0', 'GPIO4', 'SDA', 'RX', 'TX', 'GPIO5', 'SCL']
"""
"""
class cpu():
def frequency(self):


+ 2
- 5
src/adafruit_blinka/microcontroller/stm32/__init__.py View File

@ -1,10 +1,7 @@
from microcontroller import pin
# ordered as spiId, sckId, mosiId, misoId
spiPorts = (
(1, "B13", "B15", "B14"),
(2, "A5", "A6", "A7")
)
spiPorts = ((1, "B13", "B15", "B14"), (2, "A5", "A6", "A7"))
# ordered as uartId, txId, rxId
uartPorts = (
@ -13,4 +10,4 @@ uartPorts = (
(3, "B10", "B11"),
(4, "A0", "A1"),
(6, "C6", "C7"),
)
)

+ 47
- 47
src/adafruit_blinka/microcontroller/stm32/pin.py View File

@ -1,49 +1,49 @@
from microcontroller import Pin
A0=Pin('A0')
A1=Pin('A1')
A2=Pin('A2')
A3=Pin('A3')
A4=Pin('A4')
A5=Pin('A5')
A6=Pin('A6')
A7=Pin('A7')
A8=Pin('A8')
A9=Pin('A9')
A10=Pin('A10')
A11=Pin('A11')
A12=Pin('A12')
A13=Pin('A13')
A14=Pin('A14')
A15=Pin('A15')
B0=Pin('B0')
B1=Pin('B1')
B2=Pin('B2')
B3=Pin('B3')
B4=Pin('B4')
B5=Pin('B5')
B6=Pin('B6')
B7=Pin('B7')
B8=Pin('B8')
B9=Pin('B9')
B10=Pin('B10')
B11=Pin('B11')
B12=Pin('B12')
B13=Pin('B13')
B14=Pin('B14')
B15=Pin('B15')
C0=Pin('C0')
C1=Pin('C1')
C2=Pin('C2')
C3=Pin('C3')
C4=Pin('C4')
C5=Pin('C5')
C6=Pin('C6')
C7=Pin('C7')
C8=Pin('C8')
C9=Pin('C9')
C10=Pin('C10')
C11=Pin('C11')
C12=Pin('C12')
C13=Pin('C13')
D2=Pin('D2')
A0 = Pin('A0')
A1 = Pin('A1')
A2 = Pin('A2')
A3 = Pin('A3')
A4 = Pin('A4')
A5 = Pin('A5')
A6 = Pin('A6')
A7 = Pin('A7')
A8 = Pin('A8')
A9 = Pin('A9')
A10 = Pin('A10')
A11 = Pin('A11')
A12 = Pin('A12')
A13 = Pin('A13')
A14 = Pin('A14')
A15 = Pin('A15')
B0 = Pin('B0')
B1 = Pin('B1')
B2 = Pin('B2')
B3 = Pin('B3')
B4 = Pin('B4')
B5 = Pin('B5')
B6 = Pin('B6')
B7 = Pin('B7')
B8 = Pin('B8')
B9 = Pin('B9')
B10 = Pin('B10')
B11 = Pin('B11')
B12 = Pin('B12')
B13 = Pin('B13')
B14 = Pin('B14')
B15 = Pin('B15')
C0 = Pin('C0')
C1 = Pin('C1')
C2 = Pin('C2')
C3 = Pin('C3')
C4 = Pin('C4')
C5 = Pin('C5')
C6 = Pin('C6')
C7 = Pin('C7')
C8 = Pin('C8')
C9 = Pin('C9')
C10 = Pin('C10')
C11 = Pin('C11')
C12 = Pin('C12')
C13 = Pin('C13')
D2 = Pin('D2')

+ 12
- 3
src/bitbangio.py View File

@ -9,7 +9,7 @@ class I2C(Lockable):
def init(self, scl, sda, frequency):
self.deinit()
id = -1 # force bitbanging implementation - in future introspect platform if SDA/SCL matches hardware I2C
id = -1 # 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):
@ -32,7 +32,7 @@ class I2C(Lockable):
if end is None:
end = len(buffer)
buffer = memoryview(buffer)[start:end]
stop = True # remove for efficiency later
stop = True # remove for efficiency later
return self._i2c.readfrom_into(address, buffer, stop)
def writeto(self, address, buffer, start=0, end=None, stop=True, *a, **k):
@ -42,6 +42,7 @@ class I2C(Lockable):
buffer = memoryview(buffer)[start:end]
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 :(
class SPI(Lockable):
def __init__(self, clock, MOSI=None, MISO=None):
@ -52,7 +53,15 @@ class SPI(Lockable):
if self._locked:
# 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, sck = Pin(self._pins[0]), mosi=Pin(self._pins[1]), miso=Pin(self._pins[2]))
self._spi.init(
baudrate=baudrate,
polarity=polarity,
phase=phase,
bits=bits,
firstbit=SPI.MSB,
sck=Pin(self._pins[0]),
mosi=Pin(self._pins[1]),
miso=Pin(self._pins[2]))
else:
raise RuntimeError("First call try_lock()")


+ 1
- 2
src/board.py View File

@ -37,7 +37,6 @@ gc.collect()
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_Micropython_Blinka.git"
if board == "feather_huzzah":
from adafruit_blinka.board.feather_huzzah import *
elif board == "nodemcu":
@ -46,4 +45,4 @@ elif board == "pyboard":
from adafruit_blinka.board.pyboard import *
else:
raise NotImplementedError("Board not supported")
gc.collect()
gc.collect()

+ 49
- 15
src/busio.py View File

@ -10,14 +10,24 @@ class SPI(Lockable):
self._pinIds = (sck, mosi, miso)
break
else:
raise NotImplementedError("No Hardware SPI on (clock, MOSI, MISO)={}\nValid SPI ports:{}".format((clock, MOSI, MISO), spiPorts))
raise NotImplementedError(
"No Hardware SPI on (clock, MOSI, MISO)={}\nValid SPI ports:{}".
format((clock, MOSI, MISO), spiPorts))
def configure(self, baudrate=100000, polarity=0, phase=0, bits=8):
if self._locked:
from machine import Pin
from microcontroller import spiPorts
# TODO check if #init ignores MOSI=None rather than unsetting, to save _pinIds attribute
self._spi.init(baudrate=baudrate, polarity=polarity, phase=phase, bits = bits, firstbit = SPI.MSB, sck = Pin(self._pinIds[0]), mosi=Pin(self._pinIds[1]), miso=Pin(self._pinIds[2]))
self._spi.init(
baudrate=baudrate,
polarity=polarity,
phase=phase,
bits=bits,
firstbit=SPI.MSB,
sck=Pin(self._pinIds[0]),
mosi=Pin(self._pinIds[1]),
miso=Pin(self._pinIds[2]))
else:
raise RuntimeError("First call try_lock()")
@ -34,26 +44,42 @@ class SPI(Lockable):
def write_readinto(self, buffer_out, buffer_in):
return self.write_readinto(buffer_out, buffer_in)
class UART(Lockable):
class UART(Lockable):
class Parity(Enum):
pass
Parity.ODD=Parity()
Parity.EVEN=Parity()
Parity.ODD = Parity()
Parity.EVEN = Parity()
# TODO investigate UART receiver_buffer_size as e.g. read_buf_len in https://github.com/micropython/micropython/blob/3eb0694b97c6a8f0e93b874549aac40d8b78b0e5/ports/stm32/uart.c
def __init__(self, tx, rx, baudrate=9600, bits=8, parity=None, stop=1, timeout=None, receiver_buffer_size=None, flow=None):
def __init__(self,
tx,
rx,
baudrate=9600,
bits=8,
parity=None,
stop=1,
timeout=None,
receiver_buffer_size=None,
flow=None):
from microcontroller import uartPorts
from machine import UART
self.baudrate = baudrate
if timeout is not None: # default 1000
raise NotImplementedError("Parameter '{}' unsupported on {}".format("timeout", agnostic.board))
if receiver_buffer_size is not None: # default 64
raise NotImplementedError("Parameter '{}' unsupported on {}".format("receiver_buffer_size", agnostic.board))
if flow is not None: # default 0
raise NotImplementedError("Parameter '{}' unsupported on {}".format("flow", agnostic.board))
if timeout is not None: # default 1000
raise NotImplementedError(
"Parameter '{}' unsupported on {}".format(
"timeout", agnostic.board))
if receiver_buffer_size is not None: # default 64
raise NotImplementedError(
"Parameter '{}' unsupported on {}".format(
"receiver_buffer_size", agnostic.board))
if flow is not None: # default 0
raise NotImplementedError(
"Parameter '{}' unsupported on {}".format(
"flow", agnostic.board))
# translate parity flag for Micropython
if parity is UART.Parity.ODD:
@ -66,12 +92,20 @@ class UART(Lockable):
raise ValueError("Invalid parity")
# check tx and rx have hardware support
for portId, portTx, portRx in uartPorts:#
for portId, portTx, portRx in uartPorts: #
if portTx == tx.id and portRx == rx.id:
self._uart = UART(portId, baudrate, bits=bits, parity=parity, stop=stop, timeout=timeout)
self._uart = UART(
portId,
baudrate,
bits=bits,
parity=parity,
stop=stop,
timeout=timeout)
break
else:
raise NotImplementedError("No Hardware UART on (tx,rx)={}\nValid UART ports".format((tx, rx), uartPorts))
raise NotImplementedError(
"No Hardware UART on (tx,rx)={}\nValid UART ports".format(
(tx, rx), uartPorts))
def deinit(self):
self._uart = None


+ 17
- 8
src/digitalio.py View File

@ -1,28 +1,35 @@
from machine import Pin
from adafruit_blinka.agnostic import board as boardId
from adafruit_blinka import Enum,ContextManaged
from adafruit_blinka import Enum, ContextManaged
class DriveMode(Enum):
PUSH_PULL=None
OPEN_DRAIN=None
PUSH_PULL = None
OPEN_DRAIN = None
DriveMode.PUSH_PULL = DriveMode()
DriveMode.OPEN_DRAIN = DriveMode()
class Direction(Enum):
INPUT=None
OUTPUT=None
INPUT = None
OUTPUT = None
Direction.INPUT = Direction()
Direction.OUTPUT = Direction()
class Pull(Enum):
UP=None
DOWN=None
UP = None
DOWN = None
#NONE=None
Pull.UP = Pull()
Pull.DOWN = Pull()
#Pull.NONE = Pull()
@ -90,7 +97,8 @@ class DigitalInOut(ContextManaged):
if hasattr(Pin, "PULL_DOWN"):
self._pin.init(mode=Pin.IN, pull=Pin.PULL_DOWN)
else:
raise NotImplementedError("{} unsupported on {}".format(Pull.DOWN, boardId))
raise NotImplementedError("{} unsupported on {}".format(
Pull.DOWN, boardId))
elif pul is None:
self._pin.init(mode=Pin.IN, pull=None)
else:
@ -113,4 +121,5 @@ class DigitalInOut(ContextManaged):
elif mod is DriveMode.PUSH_PULL:
self._pin.init(mode=Pin.OUT)
# __all__ = ['DigitalInOut', 'DriveMode', 'Direction','Pull']

Loading…
Cancel
Save