Skip to content

Commit 646897d

Browse files
committed
add lilygo t-deck support + cp 9.x libraries
1 parent 73c93b2 commit 646897d

24 files changed

+623
-21
lines changed

PyBasic/interpreter.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,6 @@ def main(passedIn=""):
6565
tmpfile = open('_pybTmp.tmp','w+')
6666
infile = tmpfile
6767

68-
#Attempting memory pre-allocation to prepare for large Basic programs
69-
if implementation.name.upper() in ['MICROPYTHON','CIRCUITPYTHON']:
70-
gc.collect()
71-
for i in range(1600):
72-
if i % 100 == 0:
73-
print(".",end="")
74-
try:
75-
program.__program[i] = i
76-
except:
77-
print("\nMemory pre-allocation limit reached at ",i)
78-
break
79-
print()
80-
program.__program.clear()
81-
8268
if passedIn != "":
8369
infile = program.load(passedIn,tmpfile)
8470
program.execute(infile,tmpfile)

PyDOS.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def PyDOS():
6767
global envVars
6868
if "envVars" not in globals().keys():
6969
envVars = {}
70-
_VER = "1.26"
70+
_VER = "1.27"
7171
prmpVals = ['>','(',')','&','|','\x1b','\b','<','=',' ',_VER,'\n','$','']
7272

7373
print("Starting Py-DOS...")
@@ -440,7 +440,7 @@ def readBATFile(BATfile):
440440
if batLine.strip()[:1] == ":" and len(batLine.strip().split(" ")[0]) > 1:
441441
batLabels[batLine.strip().split(" ")[0][1:]] = [batLineNo,batIndex[batLineNo]]
442442
BATfile.seek(0)
443-
del batIndex,batLineNo,batLine
443+
del batIndex,batLineNo
444444

445445
return batLabels
446446

cpython/ESP32/lib/adafruit_ntp.mpy

63 Bytes
Binary file not shown.
-1022 Bytes
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# PyDOS Board Configuration for 'lilygo_tdeck'
2+
3+
import board
4+
5+
Pydos_pins = {
6+
'SCL' : (board.SCL,"SCL IO8"),
7+
'SDA' : (board.SDA,"SDA IO18"),
8+
'SCK' : [(board.SCK,"SCK IO40")],
9+
'MOSI' : [(board.MOSI,"MOSI IO41")],
10+
'MISO' : [(board.MISO,"MISO IO38")],
11+
'CS' : [(board.SDCARD_CS,"SDCARD_CS IO39")]
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# PyDOS Board Configuration for 'raspberry_pi_pico'
2+
3+
import board
4+
5+
Pydos_pins = {
6+
'sndPin' : (board.GP12,"GP12"),
7+
'led' : (board.LED,"LED, GP25"),
8+
'neoPixel' : (board.NEOPIXEL,"NEOPIXEL"),
9+
'SCL' : (board.GP9,"GP9"),
10+
'SDA' : (board.GP8,"GP8"),
11+
'SCK' : [(board.GP18,"GP18")],
12+
'MOSI' : [(board.GP19,"GP19")],
13+
'MISO' : [(board.GP16,"GP16")],
14+
'CS' : [(board.GP6,"GP6")]
15+
}
14 Bytes
Binary file not shown.
-10 Bytes
Binary file not shown.
-165 Bytes
Binary file not shown.

cpython/lib/adafruit_dotstar.mpy

7 Bytes
Binary file not shown.

cpython/lib/circuitpython_i2c_lcd.mpy

-1.16 KB
Binary file not shown.

cpython/lib/circuitpython_i2c_lcd.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""Implements a HD44780 character LCD connected via PCF8574 on I2C.
2+
This was tested with: https://www.wemos.cc/product/d1-mini.html"""
3+
4+
from lcd_api import LcdApi
5+
import busio
6+
from time import sleep
7+
8+
# The PCF8574 has a jumper selectable address: 0x20 - 0x27
9+
DEFAULT_I2C_ADDR = 0x27
10+
11+
# Defines shifts or masks for the various LCD line attached to the PCF8574
12+
13+
MASK_RS = 0x01
14+
MASK_RW = 0x02
15+
MASK_E = 0x04
16+
SHIFT_BACKLIGHT = 3
17+
SHIFT_DATA = 4
18+
19+
20+
class I2cLcd(LcdApi):
21+
"""Implements a HD44780 character LCD connected via PCF8574 on I2C."""
22+
def __init__(self, i2c, i2c_addr, num_lines, num_columns):
23+
self.i2c = i2c
24+
self.i2c_addr = i2c_addr
25+
self.i2c.writeto(self.i2c_addr, bytearray([0]))
26+
sleep(0.02) # Allow LCD time to powerup
27+
# Send reset 3 times
28+
self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
29+
sleep(0.005) # need to delay at least 4.1 msec
30+
self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
31+
sleep(0.001)
32+
self.hal_write_init_nibble(self.LCD_FUNCTION_RESET)
33+
sleep(0.001)
34+
# Put LCD into 4 bit mode
35+
self.hal_write_init_nibble(self.LCD_FUNCTION)
36+
sleep(0.001)
37+
LcdApi.__init__(self, num_lines, num_columns)
38+
cmd = self.LCD_FUNCTION
39+
if num_lines > 1:
40+
cmd |= self.LCD_FUNCTION_2LINES
41+
self.hal_write_command(cmd)
42+
43+
def hal_write_init_nibble(self, nibble):
44+
"""Writes an initialization nibble to the LCD.
45+
46+
This particular function is only used during initialization.
47+
"""
48+
byte = ((nibble >> 4) & 0x0f) << SHIFT_DATA
49+
self.i2c.writeto(self.i2c_addr, bytearray([byte | MASK_E]))
50+
self.i2c.writeto(self.i2c_addr, bytearray([byte]))
51+
52+
def hal_backlight_on(self):
53+
"""Allows the hal layer to turn the backlight on."""
54+
self.i2c.writeto(self.i2c_addr, bytearray([1 << SHIFT_BACKLIGHT]))
55+
56+
def hal_backlight_off(self):
57+
"""Allows the hal layer to turn the backlight off."""
58+
self.i2c.writeto(self.i2c_addr, bytearray([0]))
59+
60+
def hal_write_command(self, cmd):
61+
"""Writes a command to the LCD.
62+
63+
Data is latched on the falling edge of E.
64+
"""
65+
byte = ((self.backlight << SHIFT_BACKLIGHT) | (((cmd >> 4) & 0x0f) << SHIFT_DATA))
66+
self.i2c.writeto(self.i2c_addr, bytearray([byte | MASK_E]))
67+
self.i2c.writeto(self.i2c_addr, bytearray([byte]))
68+
byte = ((self.backlight << SHIFT_BACKLIGHT) | ((cmd & 0x0f) << SHIFT_DATA))
69+
self.i2c.writeto(self.i2c_addr, bytearray([byte | MASK_E]))
70+
self.i2c.writeto(self.i2c_addr, bytearray([byte]))
71+
if cmd <= 3:
72+
# The home and clear commands require a worst case delay of 4.1 msec
73+
sleep(0.005)
74+
75+
def hal_write_data(self, data):
76+
"""Write data to the LCD."""
77+
byte = (MASK_RS | (self.backlight << SHIFT_BACKLIGHT) | (((data >> 4) & 0x0f) << SHIFT_DATA))
78+
self.i2c.writeto(self.i2c_addr, bytearray([byte | MASK_E]))
79+
self.i2c.writeto(self.i2c_addr, bytearray([byte]))
80+
byte = (MASK_RS | (self.backlight << SHIFT_BACKLIGHT) | ((data & 0x0f) << SHIFT_DATA))
81+
self.i2c.writeto(self.i2c_addr, bytearray([byte | MASK_E]))
82+
self.i2c.writeto(self.i2c_addr, bytearray([byte]))
83+
84+
def hal_sleep_us(self, usecs):
85+
"""Sleep for some time (given in microseconds)."""
86+
sleep(float(usecs)/1e6)

cpython/lib/lcd_api.mpy

-1.88 KB
Binary file not shown.

cpython/lib/lcd_api.py

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
"""Provides an API for talking to HD44780 compatible character LCDs."""
2+
3+
import time
4+
5+
class LcdApi:
6+
"""Implements the API for talking with HD44780 compatible character LCDs.
7+
This class only knows what commands to send to the LCD, and not how to get
8+
them to the LCD.
9+
10+
It is expected that a derived class will implement the hal_xxx functions.
11+
"""
12+
13+
# The following constant names were lifted from the avrlib lcd.h
14+
# header file, however, I changed the definitions from bit numbers
15+
# to bit masks.
16+
#
17+
# HD44780 LCD controller command set
18+
19+
LCD_CLR = 0x01 # DB0: clear display
20+
LCD_HOME = 0x02 # DB1: return to home position
21+
22+
LCD_ENTRY_MODE = 0x04 # DB2: set entry mode
23+
LCD_ENTRY_INC = 0x02 # --DB1: increment
24+
LCD_ENTRY_SHIFT = 0x01 # --DB0: shift
25+
26+
LCD_ON_CTRL = 0x08 # DB3: turn lcd/cursor on
27+
LCD_ON_DISPLAY = 0x04 # --DB2: turn display on
28+
LCD_ON_CURSOR = 0x02 # --DB1: turn cursor on
29+
LCD_ON_BLINK = 0x01 # --DB0: blinking cursor
30+
31+
LCD_MOVE = 0x10 # DB4: move cursor/display
32+
LCD_MOVE_DISP = 0x08 # --DB3: move display (0-> move cursor)
33+
LCD_MOVE_RIGHT = 0x04 # --DB2: move right (0-> left)
34+
35+
LCD_FUNCTION = 0x20 # DB5: function set
36+
LCD_FUNCTION_8BIT = 0x10 # --DB4: set 8BIT mode (0->4BIT mode)
37+
LCD_FUNCTION_2LINES = 0x08 # --DB3: two lines (0->one line)
38+
LCD_FUNCTION_10DOTS = 0x04 # --DB2: 5x10 font (0->5x7 font)
39+
LCD_FUNCTION_RESET = 0x30 # See "Initializing by Instruction" section
40+
41+
LCD_CGRAM = 0x40 # DB6: set CG RAM address
42+
LCD_DDRAM = 0x80 # DB7: set DD RAM address
43+
44+
LCD_RS_CMD = 0
45+
LCD_RS_DATA = 1
46+
47+
LCD_RW_WRITE = 0
48+
LCD_RW_READ = 1
49+
50+
def __init__(self, num_lines, num_columns):
51+
self.num_lines = num_lines
52+
if self.num_lines > 4:
53+
self.num_lines = 4
54+
self.num_columns = num_columns
55+
if self.num_columns > 40:
56+
self.num_columns = 40
57+
self.cursor_x = 0
58+
self.cursor_y = 0
59+
self.implied_newline = False
60+
self.backlight = True
61+
self.display_off()
62+
self.backlight_on()
63+
self.clear()
64+
self.hal_write_command(self.LCD_ENTRY_MODE | self.LCD_ENTRY_INC)
65+
self.hide_cursor()
66+
self.display_on()
67+
68+
def clear(self):
69+
"""Clears the LCD display and moves the cursor to the top left
70+
corner.
71+
"""
72+
self.hal_write_command(self.LCD_CLR)
73+
self.hal_write_command(self.LCD_HOME)
74+
self.cursor_x = 0
75+
self.cursor_y = 0
76+
77+
def show_cursor(self):
78+
"""Causes the cursor to be made visible."""
79+
self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY |
80+
self.LCD_ON_CURSOR)
81+
82+
def hide_cursor(self):
83+
"""Causes the cursor to be hidden."""
84+
self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY)
85+
86+
def blink_cursor_on(self):
87+
"""Turns on the cursor, and makes it blink."""
88+
self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY |
89+
self.LCD_ON_CURSOR | self.LCD_ON_BLINK)
90+
91+
def blink_cursor_off(self):
92+
"""Turns on the cursor, and makes it no blink (i.e. be solid)."""
93+
self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY |
94+
self.LCD_ON_CURSOR)
95+
96+
def display_on(self):
97+
"""Turns on (i.e. unblanks) the LCD."""
98+
self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY)
99+
100+
def display_off(self):
101+
"""Turns off (i.e. blanks) the LCD."""
102+
self.hal_write_command(self.LCD_ON_CTRL)
103+
104+
def backlight_on(self):
105+
"""Turns the backlight on.
106+
107+
This isn't really an LCD command, but some modules have backlight
108+
controls, so this allows the hal to pass through the command.
109+
"""
110+
self.backlight = True
111+
self.hal_backlight_on()
112+
113+
def backlight_off(self):
114+
"""Turns the backlight off.
115+
116+
This isn't really an LCD command, but some modules have backlight
117+
controls, so this allows the hal to pass through the command.
118+
"""
119+
self.backlight = False
120+
self.hal_backlight_off()
121+
122+
def move_to(self, cursor_x, cursor_y):
123+
"""Moves the cursor position to the indicated position. The cursor
124+
position is zero based (i.e. cursor_x == 0 indicates first column).
125+
"""
126+
self.cursor_x = cursor_x
127+
self.cursor_y = cursor_y
128+
addr = cursor_x & 0x3f
129+
if cursor_y & 1:
130+
addr += 0x40 # Lines 1 & 3 add 0x40
131+
if cursor_y & 2: # Lines 2 & 3 add number of columns
132+
addr += self.num_columns
133+
self.hal_write_command(self.LCD_DDRAM | addr)
134+
135+
def putchar(self, char):
136+
"""Writes the indicated character to the LCD at the current cursor
137+
position, and advances the cursor by one position.
138+
"""
139+
if char == '\n':
140+
if self.implied_newline:
141+
# self.implied_newline means we advanced due to a wraparound,
142+
# so if we get a newline right after that we ignore it.
143+
self.implied_newline = False
144+
else:
145+
self.cursor_x = self.num_columns
146+
else:
147+
self.hal_write_data(ord(char))
148+
self.cursor_x += 1
149+
if self.cursor_x >= self.num_columns:
150+
self.cursor_x = 0
151+
self.cursor_y += 1
152+
self.implied_newline = (char != '\n')
153+
if self.cursor_y >= self.num_lines:
154+
self.cursor_y = 0
155+
self.move_to(self.cursor_x, self.cursor_y)
156+
157+
def putstr(self, string):
158+
"""Write the indicated string to the LCD at the current cursor
159+
position and advances the cursor position appropriately.
160+
"""
161+
for char in string:
162+
self.putchar(char)
163+
164+
def custom_char(self, location, charmap):
165+
"""Write a character to one of the 8 CGRAM locations, available
166+
as chr(0) through chr(7).
167+
"""
168+
location &= 0x7
169+
self.hal_write_command(self.LCD_CGRAM | (location << 3))
170+
self.hal_sleep_us(40)
171+
for i in range(8):
172+
self.hal_write_data(charmap[i])
173+
self.hal_sleep_us(40)
174+
self.move_to(self.cursor_x, self.cursor_y)
175+
176+
def hal_backlight_on(self):
177+
"""Allows the hal layer to turn the backlight on.
178+
179+
If desired, a derived HAL class will implement this function.
180+
"""
181+
pass
182+
183+
def hal_backlight_off(self):
184+
"""Allows the hal layer to turn the backlight off.
185+
186+
If desired, a derived HAL class will implement this function.
187+
"""
188+
pass
189+
190+
def hal_write_command(self, cmd):
191+
"""Write a command to the LCD.
192+
193+
It is expected that a derived HAL class will implement this
194+
function.
195+
"""
196+
raise NotImplementedError
197+
198+
def hal_write_data(self, data):
199+
"""Write data to the LCD.
200+
201+
It is expected that a derived HAL class will implement this
202+
function.
203+
"""
204+
raise NotImplementedError
205+
206+
# This is a default implementation of hal_sleep_us which is suitable
207+
# for most micropython implementations. For platforms which don't
208+
# support `time.sleep_us()` they should provide their own implementation
209+
# of hal_sleep_us in their hal layer and it will be used instead.
210+
def hal_sleep_us(self, usecs):
211+
"""Sleep for some time (given in microseconds)."""
212+
time.sleep_us(usecs) # NOTE this is not part of Standard Python library, specific hal layers will need to override this
Binary file not shown.
Binary file not shown.
-229 Bytes
Binary file not shown.

cpython/lib/optional/neopixel.mpy

5 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)