From 4a1a9e8669bf9692ff4b470c6413fca0f8c2f26e Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 8 Aug 2024 23:40:51 +1000 Subject: [PATCH] Add touch-screen rotation support, binary versions for MicroPython 1.24, and recipe to make themImproved clock/time and file date handling --- Makefile | 19 +++++++++++++++++++ ili9341.mpy | Bin 0 -> 8525 bytes ili9341.py | 22 ++++++++++++++++++++++ urequests2.mpy | Bin 0 -> 2100 bytes xglcd_font.mpy | Bin 0 -> 1263 bytes xglcd_font.py | 16 ++++++++++++++++ xpt2046.mpy | Bin 0 -> 1786 bytes xpt2046.py | 42 +++++++++++++++++++++++++++++++++++++++--- 8 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 Makefile create mode 100644 ili9341.mpy create mode 100644 urequests2.mpy create mode 100644 xglcd_font.mpy create mode 100644 xpt2046.mpy diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..bcc45ec --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +# Define variables +MPY_CROSS = ../micropython/mpy-cross/build/mpy-cross + +SRC_DIR = . +OUT_DIR = . +SRC = $(wildcard $(SRC_DIR)/*.py) +OUT = $(patsubst $(SRC_DIR)/%.py, $(OUT_DIR)/%.mpy, $(SRC)) + +# Default target +# all: $(OUT) $(OUT_DIR)/sh.txt +all: $(OUT) + +# Rule to create .mpy from .py +$(OUT_DIR)/%.mpy: $(SRC_DIR)/%.py + $(MPY_CROSS) $< -o $@ + +# Phony targets +.PHONY: all + diff --git a/ili9341.mpy b/ili9341.mpy new file mode 100644 index 0000000000000000000000000000000000000000..d4b4ed3c1df2a7485f7c57e17f174563b07f5408 GIT binary patch literal 8525 zcmb_AX;fS1l}|!|444S<{2?&5m8XXQ31cB-dC3OiiN$6Wn}Nha2pQA>l7$>Y(2%VbRvTis+a%tXoSvD}#9ijJGsV->o}R==lUaVunftvb$s|qF zv}dsOzPo+*-tYVFz2AMWEsNTRTZ(A+g!@RXsixXHOFfh`J>hbBDY@T0>7ufno@pv; z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|B_ZgNm&F6i+hj=F_JBf~vcH5t|BC8$ z`pHwG#~7Nj3u_OWvW|2|Ry**ZAFKVOZmbUyGY&tvG%}$T|45^C^V2q3eL_deMw*_h*J6>x_3(`)?(|~vidae9gw!1BzeQ4R zRjAFYF_^yw`?(t1ypg_qmbu~7oaIC$0Yxz_znqkZkUsIRvWl^7js|xUN6Vn@r5nEo z-bLVc7b;>n0`(qJ9PZX}h)x0Na=zyMPTA+BZqSy#xq^H7eDUULZ)(w(yUVrZWhX1j zo!Z7OwyZ^4-lT2RRyF8Z?Y@Rq`01*&2kwYL(i;4YuGe_XfYtD&W13Rjd!*(keDC{+v4r9n1Q~jb6T2 z=vr6>z!+e?^x{UJr5WS}h*h$MgST#5UV8!N#61L6BV*1lFFKB;(F*0WzA|>NEo3F`Q)sL3Rwg4Bw^C>@QvZ{ zHzeq3aI`-7>TsRrc!+~UfUiLla2=B-6TnH~HGZD@k?d$E2wHFh=CC#Rw|q|7eg^)R zSLlRa2sW{UG$l&f9x}rl#DL8iPSFZ!dpJppz(+nrtJiSl0jM+n==aEDw3>S zw4GpSR;M%I{b$+UDeyo~nz~>VS}=V$09KdtowzY#YD|7Cc%vO=pVgMXp$7OdtcoEx41$Kjm=w)S*tYU%?~ z>bsCR8&nBrBL!Xc!S}YGjqkzPJSLpYi&U8B>q^T(v^n@c!^7p}h9+H*-bI!Xq-kM* zPe#+wA%*mCFd|u47B+=V5_l1Bg|AM)21L;Kc@@#fsENiO>=+)_HZqllibfsm;x5%5 zc+#ppmOAns%5SE)Lj?GccEHcT2P)WS5QG--V~qs7jH&`GJp6;w;kxqjO7NKYwB2Kf hBZ3n$Xvy$haBm0{vWt;Nl5?z literal 0 HcmV?d00001 diff --git a/ili9341.py b/ili9341.py index 86482ae..4fa84d6 100644 --- a/ili9341.py +++ b/ili9341.py @@ -1074,3 +1074,25 @@ class Display(object): self.spi.write(data) self.spi.unlock() self.cs.value = True + + +""" + +from ili9341 import Display, color565 +from machine import Pin, SPI, ADC, PWM, SDCard, SoftSPI +from xpt2046 import Touch +hspi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13)) +display = Display(hspi, dc=Pin(2), cs=Pin(15), rst=Pin(0), width=320, height=240, rotation=270) +tft_bl = Pin(21, Pin.OUT) +tft_bl.value(1) +display.fill_rectangle(0, 0, 320, 240, 1234) +display.draw_circle(120,160,50,0) +display.draw_ellipse(125,165,90,20,9999) +display.draw_hline(20,40,100,8888) +from xglcd_font import XglcdFont +robotron = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24 ) +display.draw_text(100,160,"Hello World",robotron,2016,1234) +display.draw_text8x8(160,100,"Hello World",0,1234) +display.fill_circle(10,10,10,0b0000011111100000) + +""" diff --git a/urequests2.mpy b/urequests2.mpy new file mode 100644 index 0000000000000000000000000000000000000000..fc1b623fcd3cbfea64fbc73663f0539768778256 GIT binary patch literal 2100 zcmY*YOLN=S6}|u;f+$%6K^E1+v0;J_i4rB5qEVZ+6B`7@mu!n7SygsDGzwgcY$T8& zz$R)J0^u}GX1eU6-FDGMXF5YsvPMqjG>P+cl6KKeof$j-A*;-E(*sFKZOj1Y;Je@b z&OP6~_nI4>E)S2jTllp$)(t&A)7(VELv6jGyowD(FJryg&~%K3jv2_}PdGd^!)PYa zpdIuiqT0H?j>sfp*RUb0YOAi@Z6LOEBUPxD%FF4i*U;dx;E>YLG^`kieZ3_&tH~bcR{okd3xpRT?TrgDouE z9IA$86;avrRS9)s?o7IjsHQDKE!`-Uk-OP8kb9|8MxLf@C^h6+x>`mqt zdNEy2Bi`MTUq@Do#u~`iwKWugI+}qs!;X4;1FLALs>n(WlF{+VNZo*?A5)Ospv^^{ z-%tjA1F9c2u-=eW9r+Kr>vau7uGHGvt5v=JYm7Rt(Q8=4Eg2SaDpyV~S5w)_b#O0t zGmU0r=jdju(Znrd6Af-)qt;N7yWLtxlqwrC8nPS5EgeiYz>5vk=v?lsRAtLY-bL0d z?xZ%X%M7$x->}Q00T)|=KAO!&%fKoJ(ndp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dfly{V^ZNz>EKYyTA>?*2*j{`p<)AkUOB!@qLi2kkzYN@=ixU{_T&DZWa zq6d{#tEJ|!niIfKAvV$U-kEjNj!s_wT&`|%czejOADRE-mGBQh!9Df> literal 0 HcmV?d00001 diff --git a/xpt2046.py b/xpt2046.py index 11493a0..1f59e11 100644 --- a/xpt2046.py +++ b/xpt2046.py @@ -17,7 +17,7 @@ class Touch(object): def __init__(self, spi, cs, int_pin=None, int_handler=None, width=240, height=320, - x_min=100, x_max=1962, y_min=100, y_max=1900): + x_min=100, x_max=1962, y_min=100, y_max=1900, rotation=0): """Initialize touch screen controller. Args: @@ -44,6 +44,7 @@ class Touch(object): self.x_max = x_max self.y_min = y_min self.y_max = y_max + self.rotation = rotation self.last_touch=0 self.x_multiplier = width / (x_max - x_min) self.x_add = x_min * -self.x_multiplier @@ -58,6 +59,23 @@ class Touch(object): int_pin.irq(trigger=int_pin.IRQ_FALLING | int_pin.IRQ_RISING, handler=self.int_press) + + def rot(self,x,y,rotation=None): # convert touch locations to possibly-rotated screen locations. + if rotation is None: + rotation=self.rotation + + x,y = self.normalize(x,y) + + if rotation == 0: + return x, self.height - y - 1 + elif rotation == 90: + return self.height - y - 1, self.width - x - 1 + elif rotation == 180: + return self.width - x - 1, y + elif rotation == 270: + return y , x + + def get_touch(self): """Take multiple samples to get accurate touch reading.""" timeout = 2 # set timeout to 2 seconds @@ -107,7 +125,7 @@ class Touch(object): y = int(self.y_multiplier * y + self.y_add) return x, y - def raw_touch(self,xyonly=False): + def raw_touch(self,xyonly=False,nozero=True): """Read raw X,Y touch values. Returns: @@ -128,12 +146,13 @@ class Touch(object): b = self.send_command(self.GET_BATTERY) a = self.send_command(self.GET_AUX) # chip aux ADC input p = x * (z1 - z2) / z1 if z1>0 else None # touch-pressure is a formula based on x + p2 = x/4096 * (z2/z1-1) if z1>0 else None # touch-pressure is a formula based on x d = None if p is not None: now=time.ticks_ms() d = time.ticks_diff(now, self.last_touch) # timediff since last (for debounce) self.last_touch=now - return (p, x, y, z1, z2, t0, t1, b, a, d) + return (p, x, y, z1, z2, t0, t1, b, a, d, p2) + tuple(self.normalize(x,y) + tuple(self.rot(x,y))) # cnd def send_command(self, command): """Write command to XT2046 (MicroPython). @@ -149,3 +168,20 @@ class Touch(object): self.cs(1) return (self.rx_buf[1] << 4) | (self.rx_buf[2] >> 4) + + + +""" Examples + +import time +from xpt2046 import Touch +from machine import Pin, SPI, ADC, PWM, SDCard, SoftSPI +sspi = SoftSPI(baudrate=500000, sck=Pin(25), mosi=Pin(32), miso=Pin(39)) +touch = Touch(sspi, cs=Pin(33)) # a, int_pin=Pin(36), int_handler=self._touch_handler) +while True: +time.sleep(0.1) +t = touch.raw_touch() # (p, x, y, z1, z2, t0, t1, b, a, d) +if t[-1] is not None: +print(t) + +"""