diff --git a/gui/primitives/pushbutton.py b/gui/primitives/pushbutton.py index 4859f33..008a0c4 100644 --- a/gui/primitives/pushbutton.py +++ b/gui/primitives/pushbutton.py @@ -115,6 +115,8 @@ class ESP32Touch(Pushbutton): thresh = (80 << 8) // 100 @classmethod def threshold(cls, val): + if not (isinstance(val, int) and 0 < val < 100): + raise ValueError("Threshold must be in range 1-99") cls.thresh = (val << 8) // 100 def __init__(self, pin, suppress=False): diff --git a/setup_examples/ssd1351_pyb.py b/setup_examples/ssd1351_pyb.py new file mode 100644 index 0000000..58d1240 --- /dev/null +++ b/setup_examples/ssd1351_pyb.py @@ -0,0 +1,42 @@ +# ssd1351_setup.py + + +# WIRING (Adafruit pin nos and names). +# Pyb SSD +# Gnd Gnd +# 3V3 Vcc +# Y11 RESET +# Y12 D/C +# W32 TFT_CS +# Y8 MOSI +# Y6 SCK +# Vin LITE (10) Backlight + +from machine import Pin, SPI +import gc +import time + +from drivers.ssd1351.ssd1351 import SSD1351 as SSD +pp = Pin('EN_3V3') +pp(1) +time.sleep(1) + +# height = 96 # 1.27 inch 96*128 (rows*cols) display +height = 128 # 1.5 inch 128*128 display + +pdc = Pin('X1', Pin.OUT_PP, value=0) +pcs = Pin('X2', Pin.OUT_PP, value=1) +prst = Pin('X3', Pin.OUT_PP, value=1) +spi = SPI(2, baudrate=20_000_000) +gc.collect() # Precaution before instantiating framebuf +ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance +from gui.core.ugui import Display + +# Create and export a Display instance +# Define control buttons +nxt = Pin(Pin.board.Y11, Pin.IN, Pin.PULL_UP) # Move to next control +sel = Pin(Pin.board.Y10, Pin.IN, Pin.PULL_UP) # Operate current control +prev = Pin(Pin.board.Y12, Pin.IN, Pin.PULL_UP) # Move to previous control +increase = Pin(Pin.board.W32, Pin.IN, Pin.PULL_UP) # Increase control's value +decrease = Pin(Pin.board.Y9, Pin.IN, Pin.PULL_UP) # Decrease control's value +display = Display(ssd, nxt, sel, prev, increase, decrease, 4) diff --git a/setup_examples/st7789_pico_lcd_114_rgb565.py b/setup_examples/st7789_pico_lcd_114_rgb565.py new file mode 100644 index 0000000..2d55ca2 --- /dev/null +++ b/setup_examples/st7789_pico_lcd_114_rgb565.py @@ -0,0 +1,56 @@ +# hardware_setup.py Customise for your hardware config + +# Released under the MIT License (MIT). See LICENSE. +# Copyright (c) 2021 Peter Hinch + +# Supports: +# Waveshare Pico LCD 1.14" 135*240(Pixel) based on ST7789V + + +# Demo of initialisation procedure designed to minimise risk of memory fail +# when instantiating the frame buffer. The aim is to do this as early as +# possible before importing other modules. + +from machine import Pin, SPI +import gc + +from drivers.st7789.pico import * +SSD = LCD_1inch14 + +pcs = Pin(9, Pin.OUT, value=1) +prst = Pin(12, Pin.OUT, value=1) +pbl = Pin(13, Pin.OUT, value=1) + +gc.collect() # Precaution before instantiating framebuf +# Conservative low baudrate. Can go to 62.5MHz. +spi = SPI(1, 10_000_000, sck=Pin(10), mosi=Pin(11), miso=None) # miso on pin 8 seems to cattle it +pdc = Pin(8, Pin.OUT, value=0) # Bloody Waveshare use the MISO pin for d/c + +''' TTGO + v +----------------+ + 40 | | | + ^ | +------+ | pin 36 + | | | | | + | | | | | +240 | | | | | + | | | | | + | | | | | + v | +------+ | + 40 | | | Reset button + ^ +----------------+ + >----<------>----< + 52 135 xx + BUTTON2 BUTTON1 +''' + +ssd = SSD(spi, dc=pdc, spics=pcs, rst=prst) + +from gui.core.ugui import Display +# Create and export a Display instance +# Define control buttons +nxt = Pin(20, Pin.IN, Pin.PULL_UP) # Move to next control +sel = Pin(3, Pin.IN, Pin.PULL_UP) # Operate current control +prev = Pin(16, Pin.IN, Pin.PULL_UP) # Move to previous control +increase = Pin(2, Pin.IN, Pin.PULL_UP) # Increase control's value +decrease = Pin(18, Pin.IN, Pin.PULL_UP) # Decrease control's value +display = Display(ssd, nxt, sel, prev, increase, decrease) diff --git a/setup_examples/st7789_ttgo_touch.py b/setup_examples/st7789_ttgo_touch.py new file mode 100644 index 0000000..c5ad366 --- /dev/null +++ b/setup_examples/st7789_ttgo_touch.py @@ -0,0 +1,35 @@ +# color_setup.py Customise for your hardware config + +# Released under the MIT License (MIT). See LICENSE. +# Copyright (c) 2021 Peter Hinch, Ihor Nehrutsa + +from machine import Pin, SPI, ADC, freq +import gc + +from drivers.st7789.st7789_4bit import * +SSD = ST7789 + +pdc = Pin(16, Pin.OUT, value=0) # Arbitrary pins +pcs = Pin(5, Pin.OUT, value=1) +prst = Pin(23, Pin.OUT, value=1) +pbl = Pin(4, Pin.OUT, value=1) # Backlight +gc.collect() # Precaution before instantiating framebuf +# Conservative low baudrate. Can go to 62.5MHz. +spi = SPI(1, 30_000_000, sck=Pin(18), mosi=Pin(19)) +freq(160_000_000) + +# Right way up landscape: defined as top left adjacent to pin 36 +ssd = SSD(spi, height=135, width=240, dc=pdc, cs=pcs, rst=prst, disp_mode=LANDSCAPE, display=TDISPLAY) +# Normal portrait display: consistent with TTGO logo at top +# ssd = SSD(spi, height=240, width=135, dc=pdc, cs=pcs, rst=prst, disp_mode=PORTRAIT, display=TDISPLAY) + +from gui.core.ugui import Display +# Create and export a Display instance +# Define control buttons +nxt = Pin(13) # Move to next control +sel = Pin(15) # Operate current control +prev = Pin(33) # Move to previous control +increase = Pin(32) # Increase control's value +decrease = Pin(27) # Decrease control's value +display = Display(ssd, nxt, sel, prev, increase, decrease, False, 85) +