--- /dev/null
+"""Boards definition from Onion"""
--- /dev/null
+"""Pin definitions for the Onion Omega2+ Expansion Dock."""
+
+from adafruit_blinka.microcontroller.mips24kec import pin
+
+D0 = pin.GPIO0
+D1 = pin.GPIO1
+D2 = pin.GPIO2
+D3 = pin.GPIO3
+
+D4 = pin.GPIO4
+D5 = pin.GPIO5
+D6 = pin.GPIO6
+D7 = pin.GPIO7
+D8 = pin.GPIO8
+D9 = pin.GPIO9
+
+D11 = pin.GPIO11
+D15 = pin.GPIO15 #RGB LED Blue
+D16 = pin.GPIO16 #RGB LED Green
+D17 = pin.GPIO17 #RGB LED Red
+D18 = pin.GPIO18
+D19 = pin.GPIO19
+
+SDA = pin.I2C0_SDA
+SCL = pin.I2C0_SCL
+
+SCLK = pin.SPI0_SCLK
+MOSI = pin.SPI0_MOSI
+MISO = pin.SPI0_MISO
+CS = pin.SPI0_CS
+SCK = SCLK
+
+UART_TX = pin.UART1_TX
+UART_RX = pin.UART1_RX
--- /dev/null
+try:
+ from periphery import GPIO
+except ImportError:
+ raise ImportError("Periphery Python bindings not found, please install and try again! Try running 'pip3 install python-periphery'")
+
+# Pins dont exist in CPython so...lets make our own!
+class Pin:
+ IN = "in"
+ OUT = "out"
+ LOW = 0
+ HIGH = 1
+ PULL_NONE = 0
+ PULL_UP = 1
+ PULL_DOWN = 2
+ _CONSUMER = 'adafruit_blinka'
+
+ id = None
+ _value = LOW
+ _mode = IN
+
+ def __init__(self, pin_id):
+ self.id = pin_id
+ if type(pin_id) is tuple:
+ self._num = int(pin_id[1])
+ self._chippath = "/dev/gpiochip{}".format(pin_id[0])
+ else:
+ self._num = int(pin_id)
+ self._chippath = "/dev/gpiochip0"
+ self._line = None
+
+ def __repr__(self):
+ return str(self.id)
+
+ def __eq__(self, other):
+ return self.id == other
+
+ def init(self, mode=IN, pull=None):
+ if mode != None:
+ if mode == self.IN:
+ self._mode = self.IN
+ if self._line is not None:
+ self._line.close()
+ self._line = GPIO(self._chippath, int(self._num), self.IN)
+ elif mode == self.OUT:
+ self._mode = self.OUT
+ if self._line is not None:
+ self._line.close()
+ self._line = GPIO(self._chippath, int(self._num), self.OUT)
+ else:
+ raise RuntimeError("Invalid mode for pin: %s" % self.id)
+
+ if pull != None:
+ if pull == self.PULL_UP:
+ raise NotImplementedError("Internal pullups not supported in periphery, use physical resistor instead!")
+ elif pull == self.PULL_DOWN:
+ raise NotImplementedError("Internal pulldowns not supported in periphery, use physical resistor instead!")
+ else:
+ raise RuntimeError("Invalid pull for pin: %s" % self.id)
+
+ def value(self, val=None):
+ if val != None:
+ if val == self.LOW:
+ self._value = val
+ self._line.write(False)
+ elif val == self.HIGH:
+ self._value = val
+ self._line.write(True)
+ else:
+ raise RuntimeError("Invalid value for pin")
+ else:
+ return self.HIGH if self._line.read() else self.LOW
+
end = len(buf)
try:
#self._spi.open(self._port, 0)
- self.set_no_cs()
+ #self.set_no_cs()
self._spi.max_speed_hz = self.baudrate
self._spi.mode = self.mode
self._spi.bits_per_word = self.bits
raise RuntimeError('Buffer slices must be of equal length.')
try:
#self._spi.open(self._port, 0)
- self.set_no_cs()
+ #self.set_no_cs()
self._spi.max_speed_hz = self.baudrate
self._spi.mode = self.mode
self._spi.bits_per_word = self.bits
--- /dev/null
+from adafruit_blinka.microcontroller.generic_linux.periphery_pin import Pin
+
+GPIO0 = Pin(0)
+GPIO1 = Pin(1)
+GPIO2 = Pin(2)
+GPIO3 = Pin(3)
+GPIO4 = Pin(4) #I2C SDA
+GPIO5 = Pin(5) #I2C SCL
+GPIO6 = Pin(6) #SPI CS
+GPIO7 = Pin(7) #SPI SCLK
+GPIO8 = Pin(8) #SPI MOSI
+GPIO9 = Pin(9) #SPI MISO
+GPIO10 = Pin(10)
+
+GPIO11 = Pin(11)
+GPIO12 = Pin(12)
+GPIO13 = Pin(13)
+GPIO14 = Pin(14)
+GPIO15 = Pin(15)
+GPIO16 = Pin(16)
+GPIO17 = Pin(17)
+
+GPIO18 = Pin(18)
+GPIO19 = Pin(19)
+
+GPIO20 = Pin(20)
+GPIO21 = Pin(21)
+GPIO22 = Pin(22)
+GPIO23 = Pin(23)
+
+GPIO37 = Pin((1, 5))
+GPIO38 = Pin((1, 6))
+GPIO43 = Pin((1, 11))
+GPIO44 = Pin((1, 12))
+GPIO45 = Pin((1, 13))
+GPIO46 = Pin((1, 14))
+
+UART0_TX = GPIO12
+UART0_RX = GPIO13
+
+UART1_TX = GPIO45
+UART1_RX = GPIO46
+
+UART2_TX = GPIO20
+UART2_RX = GPIO21
+
+SPI0_MOSI = GPIO8
+SPI0_MISO = GPIO9
+SPI0_SCLK = GPIO7
+SPI0_CS = GPIO6
+
+I2C0_SDA = GPIO4
+I2C0_SCL = GPIO5
+
+# ordered as i2cId, sclId, sdaId
+i2cPorts = (
+ (0, I2C0_SCL, I2C0_SDA),
+)
+
+# ordered as spiId, sckId, mosiId, misoId
+spiPorts = (
+ ((0, 1), SPI0_SCLK, SPI0_MOSI, SPI0_MISO),
+)
+
+# ordered as uartId, txId, rxId
+uartPorts = (
+ (0, UART0_TX, UART0_RX),
+ (1, UART1_TX, UART1_RX),
+)
elif board_id == ap_board.CLOCKWORK_CPI3:
from adafruit_blinka.board.clockworkcpi3 import *
+elif board_id == ap_board.ONION_OMEGA2:
+ from adafruit_blinka.board.onion.omega2 import *
+
elif "sphinx" in sys.modules:
pass
return self._i2c.scan()
def readfrom_into(self, address, buffer, *, start=0, end=None):
- if start is not 0 or end is not None:
+ if start != 0 or end is not None:
if end is None:
end = len(buffer)
buffer = memoryview(buffer)[start:end]
def writeto(self, address, buffer, *, start=0, end=None, stop=True):
if isinstance(buffer, str):
buffer = bytes([ord(x) for x in buffer])
- if start is not 0 or end is not None:
+ if start != 0 or end is not None:
if end is None:
return self._i2c.writeto(address, memoryview(buffer)[start:], stop=stop)
else:
elif board_id == ap_board.CLOCKWORK_CPI3:
from adafruit_blinka.microcontroller.allwinner.a33.pin import Pin
from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
+ elif board_id == ap_board.ONION_OMEGA2:
+ from adafruit_blinka.microcontroller.mips24kec.pin import Pin
+ from adafruit_blinka.microcontroller.generic_linux.spi import SPI as _SPI
else:
from machine import SPI as _SPI
from machine import Pin
from adafruit_blinka.microcontroller.allwinner.a64.pin import Pin
elif detector.chip.A33:
from adafruit_blinka.microcontroller.allwinner.a33.pin import Pin
+elif detector.chip.MIPS24KEC:
+ from adafruit_blinka.microcontroller.mips24kec.pin import Pin
elif detector.board.ftdi_ft232h:
from adafruit_blinka.microcontroller.ft232h.pin import Pin
elif detector.board.binho_nova:
@property
def value(self):
- return self._pin.value() is 1
+ return self._pin.value() == 1
@value.setter
def value(self, val):
from adafruit_blinka.microcontroller.nova import *
elif chip_id == ap_chip.MIPS24KC:
from adafruit_blinka.microcontroller.atheros.ar9331.pin import *
+elif chip_id == ap_chip.MIPS24KEC:
+ from adafruit_blinka.microcontroller.mips24kec.pin import *
else:
raise NotImplementedError("Microcontroller not supported:", chip_id)
from adafruit_blinka.microcontroller.allwinner.a33.pin import *
elif chip_id == ap_chip.MIPS24KC:
from adafruit_blinka.microcontroller.atheros.ar9331.pin import *
+elif chip_id == ap_chip.MIPS24KEC:
+ from adafruit_blinka.microcontroller.mips24kec.pin import *
else:
raise NotImplementedError("Microcontroller not supported: ", chip_id)