Added MicroPython implementation.

This commit is contained in:
Jean Schurger 2021-02-23 09:33:41 -05:00
commit da8988237e

View file

@ -145,7 +145,54 @@ class JetsonNano:
self.GPIO.cleanup() self.GPIO.cleanup()
if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'): class MicroPython:
def __init__(self):
# preimport utime
import utime # pylint: disable=C0415, W0611
from machine import Pin # pylint: disable=C0415
self.DC_PIN = self.dc = Pin('P20')
self.dc.mode(Pin.OUT)
self.CS_PIN = self.cs = Pin('P4')
self.cs.mode(Pin.OUT)
self.cs.pull(Pin.PULL_UP)
self.RST_PIN = self.rst = Pin('P19')
self.rst.mode(Pin.OUT)
self.BUSY_PIN = self.busy = Pin('P18')
self.busy.mode(Pin.IN)
def digital_write(self, pin, value):
pin.value(value)
def digital_read(self, pin):
return pin.value()
def spi_writebyte(self, data):
self.spi.write(bytes(c & 0xff for c in data))
def delay_ms(self, delaytime):
import utime # pylint: disable=C0415
utime.sleep_ms(delaytime)
def module_init(self):
from machine import Pin, SPI # pylint: disable=C0415
clk = Pin('P21')
mosi = Pin('P22')
self.spi = SPI(0, mode=SPI.MASTER, baudrate=20000000, polarity=0,
phase=0, pins=(clk, mosi, None))
return 0
def module_exit(self):
self.spi.deinit()
if getattr(getattr(sys, 'implementation', None),
'name', None) == 'micropython':
implementation = MicroPython()
elif os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'):
implementation = RaspberryPi() implementation = RaspberryPi()
else: else:
implementation = JetsonNano() implementation = JetsonNano()