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

Add preliminary SPI support for BeagleBone Black #46

Merged
merged 3 commits into from
Nov 22, 2018
Merged
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
22 changes: 22 additions & 0 deletions src/adafruit_blinka/board/beaglebone_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,25 @@

SDA = pin.SDA
SCL = pin.SCL

# Refer to header default pin modes
# http://beagleboard.org/static/images/cape-headers.png
# P9_17 (SPI0_CSO => CE0) enables peripheral device
# P9_18 (SPI0_D1 => MOSI) outputs data to peripheral device
# P9_21 (SPIO_DO => MISO) receives data from peripheral device
# P9_22 (SPI0_SCLK => SCLK) outputs clock signal
CE0 = pin.CE0
MOSI = pin.MOSI
MISO = pin.MISO
SCLK = pin.SCLK
#CircuitPython naming convention for SPI Clock
SCK = pin.SCK

# SPI1 pins
# http://beagleboard.org/static/images/cape-headers-spi.png
CE1 = pin.CE1
MOSI_1 = pin.MOSI_1
MISO_1 = pin.MISO_1
SCLK_1 = pin.SCLK_1
#CircuitPython naming convention for SPI Clock
SCK_1 = pin.SCK_1
54 changes: 53 additions & 1 deletion src/adafruit_blinka/microcontroller/beaglebone_black/pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,60 @@ def value(self, val=None):
SCL = Pin('P9_19')
SDA = Pin('P9_20')

# Refer to header default pin modes
# http://beagleboard.org/static/images/cape-headers.png
#
# P9_17 (SPI0_CSO => CE0) enables peripheral device
# P9_18 (SPI0_D1 => MOSI) outputs data to peripheral device
# P9_21 (SPIO_DO => MISO) receives data from peripheral device
# P9_22 (SPI0_SCLK => SCLK) outputs clock signal
#
# Use config-pin to set pin mode for SPI pins
# https://github.com/beagleboard/bb.org-overlays/tree/master/tools/beaglebone-universal-io
# config-pin p9.17 spi_cs
# config-pin p9.18 spi
# config-pin p9.21 spi
# config-pin p9.22 spi_sclk
#
CE0 = Pin('P9_17')
MOSI = Pin('P9_18')
MISO = Pin('P9_21')
SCLK = Pin('P9_22')
#CircuitPython naming convention for SPI Clock
SCK = Pin('P9_22')

# Pins for SPI1
# refer to:
# http://beagleboard.org/static/images/cape-headers-spi.png
#
# CE1 P9.28 SPI1_CS0
# MISO_1 P9.29 SPI1_D0
# MOSI_1 P9.30 SPI1_D1
# SCLK_1 P9.31 SPI_SCLK
#
# SPI1 conflicts with HDMI Audio (McASP)
#
# Refer to:
# https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays
#
# To Disable HDMI AUDIO, uncomment this line in /boot/uEnv.txt:
# disable_uboot_overlay_audio=1
#
# Set pin modes for SPI1 with:
#
# config-pin p9.28 spi1_cs
# config-pin p9.29 spi1
# config-pin p9.30 spi1
# config-pin p9.31 spi_sclk
CE1 = Pin('P9_28')
MOSI_1 = Pin('P9_29')
MISO_1 = Pin('P9_30')
SCLK_1 = Pin('P9_31')
#CircuitPython naming convention for SPI Clock
SCK_1 = Pin('P9_31')

# ordered as spiId, sckId, mosiId, misoId
spiPorts = ()
spiPorts = ((0, SCLK, MOSI, MISO), (1, SCLK_1, MOSI_1, MISO_1))

# ordered as uartId, txId, rxId
uartPorts = (
Expand Down
13 changes: 11 additions & 2 deletions src/busio.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,26 @@ def writeto_then_readfrom(self, address, buffer_out, buffer_in, *, out_start=0,

class SPI(Lockable):
def __init__(self, clock, MOSI=None, MISO=None):
print("SPI(): __init()")
self.deinit()
if board_id == "raspi_3" or board_id == "raspi_2":
from adafruit_blinka.microcontroller.raspi_23.spi import SPI as _SPI
elif board_id == "beaglebone_black":
from adafruit_blinka.microcontroller.beaglebone_black.spi import SPI as _SPI
print("SPI(): beaglebone_black: from adafruit_blinka.microcontroller.raspi_23.spi import SPI as _SPI")
from adafruit_blinka.microcontroller.raspi_23.spi import SPI as _SPI
else:
from machine import SPI as _SPI
from microcontroller.pin import spiPorts
print("spiPorts: {0}".format(spiPorts))
print("for:")
for portId, portSck, portMosi, portMiso in spiPorts:
print(portId, portSck, portMosi, portMiso)
if ((clock == portSck) and # Clock is required!
(MOSI == portMosi or MOSI == None) and # But can do with just output
(MISO == portMiso or MISO == None)): # Or just input
print("Line 91")
print(_SPI)
print(_SPI(portId))
self._spi = _SPI(portId)
self._pins = (portSck, portMosi, portMiso)
break
Expand All @@ -96,7 +104,8 @@ def configure(self, baudrate=100000, polarity=0, phase=0, bits=8):
from adafruit_blinka.microcontroller.raspi_23.spi import SPI as _SPI
from adafruit_blinka.microcontroller.raspi_23.pin import Pin
elif board_id == "beaglebone_black":
from adafruit_blinka.microcontroller.beaglebone_black.spi import SPI as _SPI
# reuse the raspberry pi class as both boards use Linux spidev
from adafruit_blinka.microcontroller.raspi_23.spi import SPI as _SPI
from adafruit_blinka.microcontroller.beaglebone_black.pin import Pin
else:
from machine import SPI as _SPI
Expand Down