Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MicroPython implementation. #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# *----------------
# * | This version: V1.0
# * | Date : 2019-06-21
# * | Info :
# * | Info :
# ******************************************************************************
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
Expand Down Expand Up @@ -145,7 +145,54 @@ def module_exit(self):
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()
else:
implementation = JetsonNano()
Expand Down