Page 1 of 1
Some STM32F7DISC board LCD and TS demo
Posted: Wed Feb 19, 2020 12:42 pm
by shaoziyang
I have a STM32F7DISC board, it has a large TFT LCD with touch screen. I complie and download
forester3 mod version micropython, it works fine.
Because the lack of documentation, I wrote several demos.
precompile firmware
basic demo
Code: Select all
import lcdF7D
lcdF7D.init()
for i in range(lcdF7D.get_x_size()):
lcdF7D.set_text_color(255, 0, 0, i*256//lcdF7D.get_x_size())
lcdF7D.draw_Vline(i, 0, lcdF7D.get_y_size())
lcdF7D.set_font(12)
lcdF7D.set_text_color(255,255,255,0)
lcdF7D.display_string_at(0,0,'Hello',0)
lcdF7D.set_font(16)
lcdF7D.set_text_color(255,255,255,255)
lcdF7D.display_string_at(0,20,'Hello',0)
lcdF7D.set_font(24)
lcdF7D.set_text_color(255,255,128,0)
lcdF7D.display_string_at(0,50,'Hello',0)
Re: Some STM32F7DISC board LCD and TS demo
Posted: Wed Feb 19, 2020 1:55 pm
by shaoziyang
Layer
Code: Select all
from time import sleep_ms
import lcdF7D as lcd
import tchF7D as ts
MAX_X = 480
MAX_Y = 272
lcd.init()
lcd.select_layer(0)
lcd.set_text_color(0xFF)
lcd.fill_rect(50, 50, 200, 100)
lcd.set_text_color(0xFF00)
lcd.fill_rect(200, 80, 200, 100)
lcd.set_text_color(0xFF0000)
lcd.fill_rect(100, 100, 200, 100)
lcd.set_text_color(0xFF00)
lcd.set_font(20)
lcd.display_string_at(0, 0, 'rect show on the screen', 0)
lcd.select_layer(1)
lcd.set_text_color(0xFF0000)
lcd.set_font(24)
lcd.display_string_at(0, 60, 'no rect show on the screen', 0)
lcd.set_text_color(0x80, 0)
lcd.fill_rect(180, 90, 30, 30)
sleep_ms(2000)
lcd.set_layer_visible(1, 0)
sleep_ms(2000)
lcd.set_layer_visible(1, 1)
for i in range(255):
lcd.set_transparency(1, 255 - i)
sleep_ms(10)
for i in range(220):
lcd.set_transparency(1, i)
sleep_ms(10)
Re: Some STM32F7DISC board LCD and TS demo
Posted: Wed Feb 19, 2020 1:56 pm
by shaoziyang
Touch
Code: Select all
import lcdF7D as lcd
import tchF7D as ts
from time import sleep_ms
lcd.init()
lcd.set_text_color(0x00FF00)
ts.init(480, 272)
def ts_test():
while 1:
ts.get_state()
if ts.touches() > 0:
lcd.clear(0)
print('\nTouch num: ', str(ts.touches()))
for i in range(ts.touches()):
print(' {} {}'.format(i+1, ts.point_info(i+1)))
p = ts.point_info(i+1)
x1 = max(min(p[0] - p[2]//2, 479), 0)
x2 = max(min(p[0] + p[2]//2, 479), 0)
y1 = max(min(p[1] - p[2]//2, 271), 0)
y2 = max(min(p[1] + p[2]//2, 271), 0)
lcd.set_text_color(0x00FF00)
lcd.draw_rect(x1, y1, x2-x1, y2-y1)
sleep_ms(100)
Re: Some STM32F7DISC board LCD and TS demo
Posted: Wed Feb 19, 2020 2:46 pm
by shaoziyang
print
Code: Select all
import lcdF7D
class LCD_F7D():
def __init__(self):
self.LCD = lcdF7D
self.LCD.init()
self.color = 0xFFFFFF
self.px, self.py = 0, 0
self.Width, self.Height = 480, 272
self.fontsize(12)
return
def fontsize(self, size):
if size > 20: self.w, self.h =17, 24,
elif size > 16: self.w, self.h = 14, 20
elif size > 12: self.w, self.h = 11, 16
elif size > 8: self.w, self.h = 7, 12
else: self.w, self.h = 5, 8
self.LCD.set_font(size)
def newline(self):
self.px = 0
self.py += self.h
if self.py > self.Height - self.h:
self.py -= self.h
self.LCD.scroll(0, -self.h)
bc = self.LCD.get_back_color()
tc = self.LCD.get_text_color()
self.LCD.set_text_color(bc[0], bc[1], bc[2], bc[3])
self.LCD.fill_rect(0, self.py, self.Width-1, self.Height-1)
self.LCD.set_text_color(tc[0], tc[1], tc[2], tc[3])
def color(self, c):
self.color = c
self.LCD.set_text_color(c)
def print(self, s = '', wrap = False):
print(self.px, self.py)
if type(s) is not str:
return
for i in range(len(s)):
if self.px > self.Width - self.w:
if wrap:
self.newline()
else:
return
if s[i] == '\n':
self.newline()
else:
self.LCD.display_char(self.px, self.py, ord(s[i]))
self.px += self.w