-
Notifications
You must be signed in to change notification settings - Fork 50
/
pye_lcd.py
108 lines (82 loc) · 2.63 KB
/
pye_lcd.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
# Wrapper for Micropython standard console IO
#
import sys
class IO_DEVICE:
def __init__(self, Editor):
self.init_display()
self.init_terminal()
Editor.KEYMAP["\x08"] = 0x08
import busio, board
self.uart = busio.UART(
board.TX, board.RX, baudrate=115200, timeout=0.1, receiver_buffer_size=64
)
try:
from micropython import kbd_intr
kbd_intr(-1)
except ImportError:
pass
def init_display(self):
import fontio, displayio, terminalio, board
from adafruit_st7789 import ST7789
displayio.release_displays()
spi = board.SPI()
tft_cs = board.D12 # arbitrary, pin not used for my display
tft_dc = board.D2
tft_backlight = board.D4
tft_reset = board.D3
while not spi.try_lock():
pass
spi.unlock()
display_bus = displayio.FourWire(
spi,
command=tft_dc,
chip_select=tft_cs,
reset=tft_reset,
baudrate=24000000,
polarity=1,
phase=1,
)
self.xPixels = 240 # number of xPixels for the display
self.yPixels = 240 # number of yPixels for the display
self.display = ST7789(
display_bus,
width=self.xPixels,
height=self.yPixels,
rotation=0,
rowstart=80,
colstart=0,
)
self.display.show(None)
def init_terminal(self):
from simpleTerminal import editorTerminal
self.terminal = editorTerminal(
self.display, displayXPixels=self.xPixels, displayYPixels=self.yPixels
)
def wr(self, s):
self.terminal.write(s)
def rd(self):
while True:
myInput = self.uart.read(1) # for using uart
if myInput:
return myInput.decode("utf-8")
def rd_raw(self): ## just to have it implemented
return self.rd()
def deinit_tty(self):
self.uart.deinit() # clear out the UART
self.display.show(None) # remove the groups from the display
try:
from micropython import kbd_intr
kbd_intr(3)
except ImportError:
pass
def get_screen_size(self):
return self.terminal.getScreenSize()
## test, if the Editor class is already present
if "pye_edit" not in globals().keys():
from pye import pye_edit, Editor
def pye(*args, tab_size=4, undo=50):
io_device = IO_DEVICE(Editor)
ret = pye_edit(args, tab_size=tab_size, undo=undo, io_device=io_device)
io_device.deinit_tty()
return ret