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

Use spidev for Jetson devices #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 11 additions & 19 deletions RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,35 +97,23 @@ class JetsonNano:
BUSY_PIN = 24

def __init__(self):
import ctypes
find_dirs = [
os.path.dirname(os.path.realpath(__file__)),
'/usr/local/lib',
'/usr/lib',
]
self.SPI = None
for find_dir in find_dirs:
so_filename = os.path.join(find_dir, 'sysfs_software_spi.so')
if os.path.exists(so_filename):
self.SPI = ctypes.cdll.LoadLibrary(so_filename)
break
if self.SPI is None:
raise RuntimeError('Cannot find sysfs_software_spi.so')

import spidev
import Jetson.GPIO

self.GPIO = Jetson.GPIO
self.SPI = spidev.SpiDev()

def digital_write(self, pin, value):
self.GPIO.output(pin, value)

def digital_read(self, pin):
return self.GPIO.input(self.BUSY_PIN)
return self.GPIO.input(pin)

def delay_ms(self, delaytime):
time.sleep(delaytime / 1000.0)

def spi_writebyte(self, data):
self.SPI.SYSFS_software_spi_transfer(data[0])
self.SPI.writebytes(data)

def module_init(self):
self.GPIO.setmode(self.GPIO.BCM)
Expand All @@ -134,12 +122,16 @@ def module_init(self):
self.GPIO.setup(self.DC_PIN, self.GPIO.OUT)
self.GPIO.setup(self.CS_PIN, self.GPIO.OUT)
self.GPIO.setup(self.BUSY_PIN, self.GPIO.IN)
self.SPI.SYSFS_software_spi_begin()

# SPI device, bus = 3, device = 0
self.SPI.open(3, 0)
self.SPI.max_speed_hz = 32_000_000
self.SPI.mode = 0b00
return 0

def module_exit(self):
logger.debug("spi end")
self.SPI.SYSFS_software_spi_end()
self.SPI.close()

logger.debug("close 5V, Module enters 0 power consumption ...")
self.GPIO.output(self.RST_PIN, 0)
Expand Down
4 changes: 2 additions & 2 deletions RaspberryPi_JetsonNano/python/setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys, os
from setuptools import setup

dependencies = ['Pillow']
dependencies = ['Pillow', 'spidev']

if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'):
dependencies += ['RPi.GPIO', 'spidev']
dependencies += ['RPi.GPIO']
else:
dependencies += ['Jetson.GPIO']

Expand Down