Skip to content

Commit

Permalink
Merge pull request #668 from BlitzCityDIY/main
Browse files Browse the repository at this point in the history
Adding support for Feather ThinkInk
  • Loading branch information
ladyada authored Apr 6, 2023
2 parents a43bcc2 + a13f761 commit fdd6d0b
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 8 deletions.
61 changes: 61 additions & 0 deletions src/adafruit_blinka/board/feather_epd_u2if.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Pin definitions for the Feather RP2040 ThinkInk with u2if firmware.
Adafruit CircuitPython 6.2.0 on 2021-04-05; Adafruit Feather RP2040 ThinkInk with rp2040
>>> import board
>>> board.
A0 A1 A2 A3
D0 D1 D10 D11
D12 D13 D24 D25
D4 D5 D6 D9
I2C LED MISO MOSI
NEOPIXEL EPD_BUSY SCK SCL
SDA SPI TX UART
EPD_CS EPD_RESET EPD_DC EPD_MOSI
EPD_SCK
"""

from adafruit_blinka.microcontroller.rp2040_u2if import pin

D0 = pin.GP1
D1 = pin.GP0
D4 = pin.GP4
D5 = pin.GP5
D6 = pin.GP6
D9 = pin.GP9
D10 = pin.GP10
D11 = pin.GP11
D12 = pin.GP12
D13 = pin.GP13
D24 = pin.GP24
D25 = pin.GP25

A0 = pin.GP26
A1 = pin.GP27
A2 = pin.GP28
A3 = pin.GP29

LED = pin.GP13

NEOPIXEL = pin.GP21

SDA = pin.GP2
SCL = pin.GP3

SCLK = SCK = pin.GP14
MOSI = pin.GP15
MISO = pin.GP8

EPD_BUSY = pin.GP16
EPD_RESET = pin.GP17
EPD_DC = pin.GP18
EPD_CS = pin.GP19
EPD_SCK = pin.GP22
EPD_MOSI = pin.GP23

# access u2if via pin instance to open for specifc VID/PID
# pylint:disable = protected-access
pin.GP0._u2if_open_hid(0x239A, 0x812C)
14 changes: 14 additions & 0 deletions src/adafruit_blinka/microcontroller/rp2040_u2if/i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ def __init__(self, scl, sda, *, frequency=100000):
super().__init__(index, frequency=frequency)


class I2C_Feather_EPD(I2C):
"""I2C Class for Feather EPD u2if"""

def __init__(self, scl, sda, *, frequency=100000):
index = None
if scl.id == 3 and sda.id == 2:
index = 1
if index is None:
raise ValueError("I2C not found on specified pins.")
self._index = index

super().__init__(index, frequency=frequency)


class I2C_QTPY(I2C):
"""I2C Class for QT Py 2if"""

Expand Down
15 changes: 15 additions & 0 deletions src/adafruit_blinka/microcontroller/rp2040_u2if/spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""SPI Classes for RP2040s with u2if firmware"""
from .rp2040_u2if import rp2040_u2if


# pylint: disable=protected-access, no-self-use
class SPI:
"""SPI Base Class for RP2040 u2if"""
Expand Down Expand Up @@ -93,6 +94,20 @@ def __init__(self, clock, *, baudrate=100000):
super().__init__(index, baudrate=baudrate)


class SPI_Feather_EPD(SPI):
"""SPI Class for Feather EPD u2if"""

def __init__(self, clock, *, baudrate=100000):
index = None
if clock.id == 14:
index = 0
if clock.id == 22:
index = 1
if index is None:
raise ValueError("No SPI port on specified pin.")
super().__init__(index, baudrate=baudrate)


class SPI_QTPY(SPI):
"""SPI Class for QT Py u2if"""

Expand Down
16 changes: 10 additions & 6 deletions src/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@
elif board_id == ap_board.FEATHER_U2IF:
from adafruit_blinka.board.feather_u2if import *

elif board_id == ap_board.FEATHER_EPD_U2IF:
from adafruit_blinka.board.feather_epd_u2if import *

elif board_id == ap_board.QTPY_U2IF:
from adafruit_blinka.board.qtpy_u2if import *

Expand Down Expand Up @@ -340,15 +343,16 @@

package = str(pkg_resources.get_distribution("adafruit_platformdetect")).split()
raise NotImplementedError(
"{1} version {2} was unable to identify the board and/or microcontroller running "
"the {0} platform. Please be sure you have the latest packages running: 'pip3 install "
"--upgrade adafruit-blinka adafruit-platformdetect'".format(
platform.system(), package[0], package[1]
)
f"""
{package[0]} version {package[1]} was unable to identify the board and/or
microcontroller running the {platform.system()} platform. Please be sure you
have the latest packages running:
'pip3 install --upgrade adafruit-blinka adafruit-platformdetect'
"""
)

else:
raise NotImplementedError("Board not supported {}".format(board_id))
raise NotImplementedError(f"Board not supported {board_id}.")

if "SCL" in locals() and "SDA" in locals():

Expand Down
19 changes: 19 additions & 0 deletions src/busio.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def init(self, scl, sda, frequency):
I2C_Feather as _I2C,
)

self._i2c = _I2C(scl, sda, frequency=frequency)
return
if detector.board.feather_epd_u2if:
from adafruit_blinka.microcontroller.rp2040_u2if.i2c import (
I2C_Feather_EPD as _I2C,
)

self._i2c = _I2C(scl, sda, frequency=frequency)
return
if detector.board.qtpy_u2if:
Expand Down Expand Up @@ -245,6 +252,14 @@ def __init__(self, clock, MOSI=None, MISO=None):
SPI_Feather as _SPI,
)

self._spi = _SPI(clock) # this is really all that's needed
self._pins = (clock, clock, clock) # will determine MOSI/MISO from clock
return
if detector.board.feather_epd_u2if:
from adafruit_blinka.microcontroller.rp2040_u2if.spi import (
SPI_Feather_EPD as _SPI,
)

self._spi = _SPI(clock) # this is really all that's needed
self._pins = (clock, clock, clock) # will determine MOSI/MISO from clock
return
Expand Down Expand Up @@ -332,6 +347,10 @@ def configure(self, baudrate=100000, polarity=0, phase=0, bits=8):
from adafruit_blinka.microcontroller.rp2040_u2if.spi import (
SPI_Feather as _SPI,
)
elif detector.board.feather_epd_u2if:
from adafruit_blinka.microcontroller.rp2040_u2if.spi import (
SPI_Feather_EPD as _SPI,
)
elif detector.board.itsybitsy_u2if:
from adafruit_blinka.microcontroller.rp2040_u2if.spi import (
SPI_ItsyBitsy as _SPI,
Expand Down
3 changes: 2 additions & 1 deletion src/neopixel_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Author(s): ladyada
"""

# pylint: disable=too-many-boolean-expressions
import sys

from adafruit_blinka.agnostic import detector
Expand All @@ -21,6 +21,7 @@
from adafruit_blinka.microcontroller.rp2040_u2if import neopixel as _neopixel
elif (
detector.board.feather_u2if
or detector.board.feather_epd_u2if
or detector.board.qtpy_u2if
or detector.board.itsybitsy_u2if
or detector.board.macropad_u2if
Expand Down
3 changes: 2 additions & 1 deletion src/pwmio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Author(s): Melissa LeBlanc-Williams
"""

# pylint: disable=too-many-boolean-expressions
import sys

from adafruit_blinka.agnostic import detector
Expand Down Expand Up @@ -38,6 +38,7 @@
from adafruit_blinka.microcontroller.rp2040_u2if.pwmio import PWMOut
elif (
detector.board.feather_u2if
or detector.board.feather_epd_u2if
or detector.board.qtpy_u2if
or detector.board.itsybitsy_u2if
or detector.board.macropad_u2if
Expand Down

0 comments on commit fdd6d0b

Please sign in to comment.