-
Notifications
You must be signed in to change notification settings - Fork 0
/
epdif.py
81 lines (73 loc) · 2.76 KB
/
epdif.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# ported to CircuitPython 3.0.0-beta0 by Gregory P. Smith
##
# @filename : epdif.py
# @brief : EPD hardware interface implements (GPIO, SPI)
# @author : Yehui from Waveshare
#
# Copyright (C) Waveshare July 4 2017
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
import adafruit_bus_device.spi_device
import board
import digitalio
# Pin definition as hooked up on my Metro M4 (reassigned to instances in init)
# These pins are also present on the ItsyBitsy M4
RST_PIN = board.GP12
DC_PIN = board.GP8
CS_PIN = board.GP9
BUSY_PIN = board.GP13
#_SPI_MOSI = board.MOSI
#_SPI_CLK = board.SCK
_SPI_MOSI = board.GP11
_SPI_CLK = board.GP10
_SPI_BUS = None
_init = False
def spi_transfer(data):
with _SPI_BUS as device:
device.write(data)
def epd_io_bus_init():
global _init
if _init:
raise RuntimeError("epd_io_bus_init() called twice")
_init = True
global RST_PIN, DC_PIN, CS_PIN, BUSY_PIN
DInOut = digitalio.DigitalInOut
OUTPUT = digitalio.Direction.OUTPUT
INPUT = digitalio.Direction.INPUT
RST_PIN = DInOut(RST_PIN)
RST_PIN.direction = OUTPUT
DC_PIN = DInOut(DC_PIN)
DC_PIN.direction = OUTPUT
CS_PIN = DInOut(CS_PIN)
CS_PIN.direction = OUTPUT
BUSY_PIN = DInOut(BUSY_PIN)
BUSY_PIN.direction = INPUT
global _SPI_BUS
# bus vs bitbang isn't really important for slow displays, detecting
# when to use one vs the other is overkill...
if (_SPI_CLK == getattr(board, 'SCK', None) and
_SPI_MOSI == getattr(board, 'MOSI', None)):
import busio as io_module
else:
import bitbangio as io_module
_SPI_BUS = adafruit_bus_device.spi_device.SPIDevice(
io_module.SPI(_SPI_CLK, _SPI_MOSI), CS_PIN,
baudrate=2000000)
### END OF FILE ###