From 32550da9db7202e6fbfa651fb703040b799a4726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 16 May 2017 17:54:48 +0200 Subject: [PATCH 01/10] move _set_area to chip class add CS and LED pins --- gfxlcd/drawing/area.py | 16 ---------------- gfxlcd/driver/ili9325/gpio.py | 3 +++ gfxlcd/driver/ili9325/ili9325.py | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gfxlcd/drawing/area.py b/gfxlcd/drawing/area.py index 48bd8eb..418a84b 100644 --- a/gfxlcd/drawing/area.py +++ b/gfxlcd/drawing/area.py @@ -18,22 +18,6 @@ class Area(Pixel): self._set_area(pos_x, pos_y, pos_x, pos_y) self.driver.data(self._converted_color(), None) - def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): - """select area to work with""" - self.driver.cmd(0x0020, None) - self.driver.data(pos_x1, None) - self.driver.cmd(0x0021, None) - self.driver.data(pos_y1, None) - self.driver.cmd(0x0050, None) - self.driver.data(pos_x1, None) - self.driver.cmd(0x0052, None) - self.driver.data(pos_y1, None) - self.driver.cmd(0x0051, None) - self.driver.data(pos_x2, None) - self.driver.cmd(0x0053, None) - self.driver.data(pos_y2, None) - self.driver.cmd(0x0022, None) - def _draw_vertical_line(self, pos_x, pos_y, length): """draw vertical line""" self._set_area(pos_x, pos_y, pos_x, pos_y + length) diff --git a/gfxlcd/driver/ili9325/gpio.py b/gfxlcd/driver/ili9325/gpio.py index 9d06f5d..1bdd433 100644 --- a/gfxlcd/driver/ili9325/gpio.py +++ b/gfxlcd/driver/ili9325/gpio.py @@ -34,6 +34,9 @@ class GPIO(Driver): RPi.GPIO.setup(self.pins[pin], RPi.GPIO.OUT) RPi.GPIO.output(self.pins[pin], 0) + if self.pins['LED']: + RPi.GPIO.output(self.pins['LED'], 1) + def reset(self): """reset a display""" if self.pins['LED']: diff --git a/gfxlcd/driver/ili9325/ili9325.py b/gfxlcd/driver/ili9325/ili9325.py index b260f01..7e4330a 100644 --- a/gfxlcd/driver/ili9325/ili9325.py +++ b/gfxlcd/driver/ili9325/ili9325.py @@ -175,3 +175,19 @@ class ILI9325(Area, Chip): # 262K color and display ON self.driver.cmd(0x0007, None) self.driver.data(0x0133, None) + + def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): + """select area to work with""" + self.driver.cmd(0x0020, None) + self.driver.data(pos_x1, None) + self.driver.cmd(0x0021, None) + self.driver.data(pos_y1, None) + self.driver.cmd(0x0050, None) + self.driver.data(pos_x1, None) + self.driver.cmd(0x0052, None) + self.driver.data(pos_y1, None) + self.driver.cmd(0x0051, None) + self.driver.data(pos_x2, None) + self.driver.cmd(0x0053, None) + self.driver.data(pos_y2, None) + self.driver.cmd(0x0022, None) From 7d568251e9265fb90557e2fb5a89b7e5659075b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 16 May 2017 17:57:55 +0200 Subject: [PATCH 02/10] pin CS to AD7843 --- gfxlcd/driver/ad7843/ad7843.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gfxlcd/driver/ad7843/ad7843.py b/gfxlcd/driver/ad7843/ad7843.py index 7e9e56b..6e107fe 100644 --- a/gfxlcd/driver/ad7843/ad7843.py +++ b/gfxlcd/driver/ad7843/ad7843.py @@ -4,7 +4,7 @@ import RPi.GPIO class AD7843(object): """AD7843 class""" - def __init__(self, width, height, int_pin=None, callback=None, spi=0, speed=2000000): + def __init__(self, width, height, int_pin=None, callback=None, cs_pin=None, spi=0, speed=2000000): self.width = width self.height = height self.spi = spidev.SpiDev() @@ -17,6 +17,7 @@ class AD7843(object): 'ratio_x': 14.35, 'ratio_y': 10.59 } + self.cs_pin = cs_pin self.int_pin = int_pin self.callback = callback self.bouncetime = 500 @@ -28,6 +29,9 @@ class AD7843(object): RPi.GPIO.add_event_detect( self.int_pin, RPi.GPIO.BOTH, callback=self._interrupt, bouncetime=self.bouncetime ) + if self.cs_pin: + RPi.GPIO.setup(self.cs_pin, RPi.GPIO.OUT) + RPi.GPIO.output(self.cs_pin, 1) def get_x(self, value): """correct value to x""" @@ -39,7 +43,11 @@ class AD7843(object): def _interrupt(self, channel): """call users callback""" + if self.cs_pin: + RPi.GPIO.output(self.cs_pin, 0) self.callback(self.get_position()) + if self.cs_pin: + RPi.GPIO.output(self.cs_pin, 1) def get_position(self): """get touch coords""" From 5a87c44afe759e87024dbedc79006a9bfd9cf523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 16 May 2017 18:23:25 +0200 Subject: [PATCH 03/10] SPI ILI9486 rename ili demos to ili9325 --- gfxlcd/demos/ili.py | 65 ------------------- gfxlcd/demos/{ili_2.py => ili9325_2.py} | 0 .../demos/{ili_image.py => ili9325_image.py} | 0 gfxlcd/driver/ili9325/gpio.py | 3 + gfxlcd/driver/ili9486/__init__.py | 2 + gfxlcd/driver/ili9486/spi.py | 65 +++++++++++++++++++ 6 files changed, 70 insertions(+), 65 deletions(-) delete mode 100644 gfxlcd/demos/ili.py rename gfxlcd/demos/{ili_2.py => ili9325_2.py} (100%) rename gfxlcd/demos/{ili_image.py => ili9325_image.py} (100%) create mode 100644 gfxlcd/driver/ili9486/__init__.py create mode 100644 gfxlcd/driver/ili9486/spi.py diff --git a/gfxlcd/demos/ili.py b/gfxlcd/demos/ili.py deleted file mode 100644 index 23ee492..0000000 --- a/gfxlcd/demos/ili.py +++ /dev/null @@ -1,65 +0,0 @@ -import sys -sys.path.append("../../") -from gfxlcd.driver.ili9325.gpio import GPIO -from gfxlcd.driver.ili9325.ili9325 import ILI9325 - - -def hole(x, y): - o.draw_pixel(x+1, y) - o.draw_pixel(x+2, y) - o.draw_pixel(x+3, y) - o.draw_pixel(x+1, y + 4) - o.draw_pixel(x+2, y + 4) - o.draw_pixel(x+3, y + 4) - o.draw_pixel(x, y + 1) - o.draw_pixel(x+4, y + 1) - o.draw_pixel(x, y + 2) - o.draw_pixel(x+4, y + 2) - o.draw_pixel(x, y + 3) - o.draw_pixel(x+4, y + 3) - - -def draw_net(o): - s = 0 - while s < o.width-1: - o.draw_line(s, 0, s, o.height-1) - s += 10 - s = 0 - while s < o.height-1: - o.draw_line(0, s, o.width-1, s) - s += 10 - - -drv = GPIO() -drv.pins['LED'] = 6 -drv.pins['CS'] = 18 -o = ILI9325(240, 320, drv) - -o.init() -# for _ in range(0, 50): -# hole(random.randint(2,o.width-3), random.randint(2,o.height-3)) -# -# draw_net(o) - -o.color = (10, 230, 200) -o.draw_circle(60, 15, 15) -o.color = (0, 250, 20) -o.draw_circle(53, 10, 3) -o.draw_circle(67, 10, 3) -o.color = (250, 150, 20) -o.draw_arc(60, 15, 10, 45, 135) -o.color = (10, 230, 200) -o.draw_line(60, 12, 57, 17) -o.draw_line(60, 12, 63, 17) -o.draw_arc(60, 15, 3, 45, 135) - -o.background_color = (200, 0, 120) -o.fill_rect(2, 2, 42, 29) -o.background_color = (20, 200, 120) -o.fill_rect(119, 2, 109, 12) -o.fill_rect(119, 17, 109, 19) - -o.background_color = (255, 255, 255) -o.fill_rect(77, 6, 105, 16) -o.background_color = (255, 0, 0) -o.fill_rect(77, 16, 105, 25) diff --git a/gfxlcd/demos/ili_2.py b/gfxlcd/demos/ili9325_2.py similarity index 100% rename from gfxlcd/demos/ili_2.py rename to gfxlcd/demos/ili9325_2.py diff --git a/gfxlcd/demos/ili_image.py b/gfxlcd/demos/ili9325_image.py similarity index 100% rename from gfxlcd/demos/ili_image.py rename to gfxlcd/demos/ili9325_image.py diff --git a/gfxlcd/driver/ili9325/gpio.py b/gfxlcd/driver/ili9325/gpio.py index 1bdd433..4d26d80 100644 --- a/gfxlcd/driver/ili9325/gpio.py +++ b/gfxlcd/driver/ili9325/gpio.py @@ -37,6 +37,9 @@ class GPIO(Driver): if self.pins['LED']: RPi.GPIO.output(self.pins['LED'], 1) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS'], 1) + def reset(self): """reset a display""" if self.pins['LED']: diff --git a/gfxlcd/driver/ili9486/__init__.py b/gfxlcd/driver/ili9486/__init__.py new file mode 100644 index 0000000..7a53ea9 --- /dev/null +++ b/gfxlcd/driver/ili9486/__init__.py @@ -0,0 +1,2 @@ +"""driver/ili9486 module""" +__author__ = 'Bartosz Kosciow' diff --git a/gfxlcd/driver/ili9486/spi.py b/gfxlcd/driver/ili9486/spi.py new file mode 100644 index 0000000..6a51e68 --- /dev/null +++ b/gfxlcd/driver/ili9486/spi.py @@ -0,0 +1,65 @@ +"""SPI communication driver""" +import time +import spidev +import RPi.GPIO # pylint: disable=I0011,F0401 +from gfxlcd.abstract.driver import Driver +RPi.GPIO.setmode(RPi.GPIO.BCM) + + +class SPI(Driver): + """SPI communication driver""" + def __init__(self, spi=0, speed=2000000): + self.pins = { + 'CS_LCD': 8, + 'RST': 25, + 'RS': 24, + 'LED': None + } + self.spi = spidev.SpiDev() + self.spi.open(spi, 0) + self.spi.max_speed_hz = speed + self.spi.mode = 0 + + def init(self): + """initialize pins""" + for pin in self.pins: + if self.pins[pin] is not None: + RPi.GPIO.setup(self.pins[pin], RPi.GPIO.OUT) + RPi.GPIO.output(self.pins[pin], 0) + + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS_LCD'], 1) + + if self.pins['LED']: + RPi.GPIO.output(self.pins['LED'], 1) + + def reset(self): + """reset a display""" + if self.pins['LED']: + RPi.GPIO.output(self.pins['LED'], 1) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS'], 1) + RPi.GPIO.output(self.pins['RST'], 1) + time.sleep(0.005) + RPi.GPIO.output(self.pins['RST'], 0) + time.sleep(0.005) + RPi.GPIO.output(self.pins['RST'], 1) + time.sleep(0.005) + + def cmd(self, data, enable): + """send command to display""" + RPi.GPIO.output(self.pins['RS'], 0) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS_LCD'], 0) + self.spi.xfer2(data) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS_LCD'], 1) + + def data(self, data, enable): + """send data to display""" + RPi.GPIO.output(self.pins['RS'], 1) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS_LCD'], 0) + self.spi.xfer2(data) + if self.pins['CS']: + RPi.GPIO.output(self.pins['CS_LCD'], 1) From 626d012021afb164b3bb80b43a5831393de2e8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 16 May 2017 21:16:30 +0200 Subject: [PATCH 04/10] ILI9486 --- gfxlcd/demos/ili9325.py | 65 ++++++++++++++++ gfxlcd/demos/ili9486.py | 73 ++++++++++++++++++ gfxlcd/driver/ili9486/ili9486.py | 122 +++++++++++++++++++++++++++++++ gfxlcd/driver/ili9486/spi.py | 16 ++-- 4 files changed, 268 insertions(+), 8 deletions(-) create mode 100644 gfxlcd/demos/ili9325.py create mode 100644 gfxlcd/demos/ili9486.py create mode 100644 gfxlcd/driver/ili9486/ili9486.py diff --git a/gfxlcd/demos/ili9325.py b/gfxlcd/demos/ili9325.py new file mode 100644 index 0000000..23ee492 --- /dev/null +++ b/gfxlcd/demos/ili9325.py @@ -0,0 +1,65 @@ +import sys +sys.path.append("../../") +from gfxlcd.driver.ili9325.gpio import GPIO +from gfxlcd.driver.ili9325.ili9325 import ILI9325 + + +def hole(x, y): + o.draw_pixel(x+1, y) + o.draw_pixel(x+2, y) + o.draw_pixel(x+3, y) + o.draw_pixel(x+1, y + 4) + o.draw_pixel(x+2, y + 4) + o.draw_pixel(x+3, y + 4) + o.draw_pixel(x, y + 1) + o.draw_pixel(x+4, y + 1) + o.draw_pixel(x, y + 2) + o.draw_pixel(x+4, y + 2) + o.draw_pixel(x, y + 3) + o.draw_pixel(x+4, y + 3) + + +def draw_net(o): + s = 0 + while s < o.width-1: + o.draw_line(s, 0, s, o.height-1) + s += 10 + s = 0 + while s < o.height-1: + o.draw_line(0, s, o.width-1, s) + s += 10 + + +drv = GPIO() +drv.pins['LED'] = 6 +drv.pins['CS'] = 18 +o = ILI9325(240, 320, drv) + +o.init() +# for _ in range(0, 50): +# hole(random.randint(2,o.width-3), random.randint(2,o.height-3)) +# +# draw_net(o) + +o.color = (10, 230, 200) +o.draw_circle(60, 15, 15) +o.color = (0, 250, 20) +o.draw_circle(53, 10, 3) +o.draw_circle(67, 10, 3) +o.color = (250, 150, 20) +o.draw_arc(60, 15, 10, 45, 135) +o.color = (10, 230, 200) +o.draw_line(60, 12, 57, 17) +o.draw_line(60, 12, 63, 17) +o.draw_arc(60, 15, 3, 45, 135) + +o.background_color = (200, 0, 120) +o.fill_rect(2, 2, 42, 29) +o.background_color = (20, 200, 120) +o.fill_rect(119, 2, 109, 12) +o.fill_rect(119, 17, 109, 19) + +o.background_color = (255, 255, 255) +o.fill_rect(77, 6, 105, 16) +o.background_color = (255, 0, 0) +o.fill_rect(77, 16, 105, 25) diff --git a/gfxlcd/demos/ili9486.py b/gfxlcd/demos/ili9486.py new file mode 100644 index 0000000..30ed6fa --- /dev/null +++ b/gfxlcd/demos/ili9486.py @@ -0,0 +1,73 @@ +import sys +sys.path.append("../../") +from gfxlcd.driver.ili9486.spi import SPI +from gfxlcd.driver.ili9486.ili9486 import ILI9486 +import RPi.GPIO +RPi.GPIO.setmode(RPi.GPIO.BCM) +import random + +def hole(x, y): + o.draw_pixel(x+1, y) + o.draw_pixel(x+2, y) + o.draw_pixel(x+3, y) + o.draw_pixel(x+1, y + 4) + o.draw_pixel(x+2, y + 4) + o.draw_pixel(x+3, y + 4) + o.draw_pixel(x, y + 1) + o.draw_pixel(x+4, y + 1) + o.draw_pixel(x, y + 2) + o.draw_pixel(x+4, y + 2) + o.draw_pixel(x, y + 3) + o.draw_pixel(x+4, y + 3) + + +def draw_net(o): + s = 0 + while s < o.width-1: + o.draw_line(s, 0, s, o.height-1) + s += 10 + s = 0 + while s < o.height-1: + o.draw_line(0, s, o.width-1, s) + s += 10 + + +drv = SPI() +o = ILI9486(320, 480, drv) + +print("init") +o.init() + +o.color = (255, 120, 0) +o.background_color = (255, 120,0) +o.fill_rect(50, 150, 205, 205) + +for _ in range(0, 50): + hole(random.randint(2,o.width-3), random.randint(2,o.height-3)) + +draw_net(o) +print("draw") +o.color = (10, 230, 200) +o.draw_circle(60, 15, 15) +o.color = (0, 250, 20) +o.draw_circle(53, 10, 3) +o.draw_circle(67, 10, 3) +o.color = (250, 150, 20) +o.draw_arc(60, 15, 10, 45, 135) +o.color = (10, 230, 200) +o.draw_line(60, 12, 57, 17) +o.draw_line(60, 12, 63, 17) +o.draw_arc(60, 15, 3, 45, 135) + +o.background_color = (200, 0, 120) +o.fill_rect(2, 2, 42, 29) +o.background_color = (20, 200, 120) +o.fill_rect(119, 2, 109, 12) +o.fill_rect(119, 17, 109, 19) + +o.background_color = (255, 255, 255) +o.fill_rect(77, 6, 105, 16) +o.background_color = (255, 0, 0) +o.fill_rect(77, 16, 105, 25) +print("end") +# o.driver.reset() diff --git a/gfxlcd/driver/ili9486/ili9486.py b/gfxlcd/driver/ili9486/ili9486.py new file mode 100644 index 0000000..376bc47 --- /dev/null +++ b/gfxlcd/driver/ili9486/ili9486.py @@ -0,0 +1,122 @@ +"""ILI9486 chip driver""" +import time +from gfxlcd.drawing.area import Area +from gfxlcd.abstract.chip import Chip + + +class ILI9486(Area, Chip): + """Class for ILI9486 based LCD""" + def __init__(self, width, height, driver): + Chip.__init__(self, width, height, driver, True) + Area.__init__(self, driver) + + def _converted_background_color(self): + """color from 8-8-8 to 5-6-5""" + rgb = self.options['background_color']['R'] << 16 | \ + self.options['background_color']['G'] << 8 | \ + self.options['background_color']['B'] + return ((rgb & 0x00f80000) >> 8) |\ + ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) + + def _converted_color(self): + """color from 8-8-8 to 5-6-5""" + rgb = self.options['color']['R'] << 16 | \ + self.options['color']['G'] << 8 | \ + self.options['color']['B'] + return ((rgb & 0x00f80000) >> 8) |\ + ((rgb & 0x0000fc00) >> 5) | ((rgb & 0x000000f8) >> 3) + + def init(self): + """init display""" + self.driver.init() + Area.init(self) + Chip.init(self) + self.driver.reset() + + self.driver.cmd(0x0b, None) + self.driver.data(0x00, None) + + self.driver.cmd(0x11, None) + # self.driver.cmd(250, None) + self.driver.cmd(0x3a, None) + self.driver.data(0x55, None) + + self.driver.cmd(0xc2, None) + self.driver.data(0x44, None) + + self.driver.cmd(0xc5, None) + self.driver.data(0x00, None) + self.driver.data(0x00, None) + self.driver.data(0x00, None) + self.driver.data(0x00, None) + + self.driver.cmd(0xe0, None) + self.driver.data(0x0F, None) + self.driver.data(0x1F, None) + self.driver.data(0x1C, None) + self.driver.data(0x0C, None) + self.driver.data(0x0F, None) + self.driver.data(0x08, None) + self.driver.data(0x48, None) + self.driver.data(0x98, None) + self.driver.data(0x37, None) + self.driver.data(0x0A, None) + self.driver.data(0x13, None) + self.driver.data(0x04, None) + self.driver.data(0x11, None) + self.driver.data(0x0D, None) + self.driver.data(0x00, None) + + self.driver.cmd(0x10000e1, None) + self.driver.data(0x0F, None) + self.driver.data(0x32, None) + self.driver.data(0x2E, None) + self.driver.data(0x0B, None) + self.driver.data(0x0D, None) + self.driver.data(0x05, None) + self.driver.data(0x47, None) + self.driver.data(0x75, None) + self.driver.data(0x37, None) + self.driver.data(0x06, None) + self.driver.data(0x10, None) + self.driver.data(0x03, None) + self.driver.data(0x24, None) + self.driver.data(0x20, None) + self.driver.data(0x00, None) + + self.driver.cmd(0x10000e2, None) + self.driver.data(0x0F, None) + self.driver.data(0x32, None) + self.driver.data(0x2E, None) + self.driver.data(0x0B, None) + self.driver.data(0x0D, None) + self.driver.data(0x05, None) + self.driver.data(0x47, None) + self.driver.data(0x75, None) + self.driver.data(0x37, None) + self.driver.data(0x06, None) + self.driver.data(0x10, None) + self.driver.data(0x03, None) + self.driver.data(0x24, None) + self.driver.data(0x20, None) + self.driver.data(0x00, None) + + self.driver.cmd(0x11, None) + self.driver.cmd(0x29, None) + + def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): + """select area to work with""" + self.driver.cmd(0x2a, None) + self.driver.data(pos_x1>>8, None) + self.driver.data(pos_x1&0xff, None) + self.driver.data(pos_x2>>8, None) + self.driver.data(pos_x2&0xff, None) + self.driver.cmd(0x2b, None) + self.driver.data(pos_y1>>8, None) + self.driver.data(pos_y1&0xff, None) + self.driver.data(pos_y2>>8, None) + self.driver.data(pos_y2&0xff, None) + self.driver.cmd(0x2c, None) + + # for _ in range(0, pos_x1*pos_y1): + # self.driver.data(0xf00ff, None) diff --git a/gfxlcd/driver/ili9486/spi.py b/gfxlcd/driver/ili9486/spi.py index 6a51e68..fab722c 100644 --- a/gfxlcd/driver/ili9486/spi.py +++ b/gfxlcd/driver/ili9486/spi.py @@ -10,7 +10,7 @@ class SPI(Driver): """SPI communication driver""" def __init__(self, spi=0, speed=2000000): self.pins = { - 'CS_LCD': 8, + 'CS': 8, 'RST': 25, 'RS': 24, 'LED': None @@ -28,7 +28,7 @@ class SPI(Driver): RPi.GPIO.output(self.pins[pin], 0) if self.pins['CS']: - RPi.GPIO.output(self.pins['CS_LCD'], 1) + RPi.GPIO.output(self.pins['CS'], 1) if self.pins['LED']: RPi.GPIO.output(self.pins['LED'], 1) @@ -50,16 +50,16 @@ class SPI(Driver): """send command to display""" RPi.GPIO.output(self.pins['RS'], 0) if self.pins['CS']: - RPi.GPIO.output(self.pins['CS_LCD'], 0) - self.spi.xfer2(data) + RPi.GPIO.output(self.pins['CS'], 0) + self.spi.xfer2([data]) if self.pins['CS']: - RPi.GPIO.output(self.pins['CS_LCD'], 1) + RPi.GPIO.output(self.pins['CS'], 1) def data(self, data, enable): """send data to display""" RPi.GPIO.output(self.pins['RS'], 1) if self.pins['CS']: - RPi.GPIO.output(self.pins['CS_LCD'], 0) - self.spi.xfer2(data) + RPi.GPIO.output(self.pins['CS'], 0) + self.spi.xfer2([data]) if self.pins['CS']: - RPi.GPIO.output(self.pins['CS_LCD'], 1) + RPi.GPIO.output(self.pins['CS'], 1) From 26178fba205b7e61c4cd2d0ed4e84eae557db397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Tue, 16 May 2017 23:04:56 +0200 Subject: [PATCH 05/10] ILI9486 --- gfxlcd/demos/ili9486.py | 15 +++++++++------ gfxlcd/demos/ili9486_image.py | 19 +++++++++++++++++++ gfxlcd/driver/ili9486/ili9486.py | 29 +++++++++++++++-------------- 3 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 gfxlcd/demos/ili9486_image.py diff --git a/gfxlcd/demos/ili9486.py b/gfxlcd/demos/ili9486.py index 30ed6fa..58a531e 100644 --- a/gfxlcd/demos/ili9486.py +++ b/gfxlcd/demos/ili9486.py @@ -37,15 +37,18 @@ o = ILI9486(320, 480, drv) print("init") o.init() +# o.driver.reset() -o.color = (255, 120, 0) -o.background_color = (255, 120,0) -o.fill_rect(50, 150, 205, 205) +# exit() +o.color = (255, 255, 255) +o.background_color = (0, 0, 0) +o.fill_rect(10, 150, 205, 205) -for _ in range(0, 50): - hole(random.randint(2,o.width-3), random.randint(2,o.height-3)) +# exit() +# for _ in range(0, 50): +# hole(random.randint(2,o.width-3), random.randint(2,o.height-3)) -draw_net(o) +# draw_net(o) print("draw") o.color = (10, 230, 200) o.draw_circle(60, 15, 15) diff --git a/gfxlcd/demos/ili9486_image.py b/gfxlcd/demos/ili9486_image.py new file mode 100644 index 0000000..5c957fd --- /dev/null +++ b/gfxlcd/demos/ili9486_image.py @@ -0,0 +1,19 @@ +import RPi.GPIO +import sys +from PIL import Image +sys.path.append("../../") +from gfxlcd.driver.ili9486.spi import SPI +from gfxlcd.driver.ili9486.ili9486 import ILI9486 +RPi.GPIO.setmode(RPi.GPIO.BCM) + + +drv = SPI() +lcd_tft = ILI9486(320, 480, drv) +lcd_tft.init() + +image_file = Image.open("assets/japan_temple_240x320.jpg") +lcd_tft.draw_image(0, 0, image_file) + +numbers_image = Image.open("assets/dsp2017_101_64.png") +lcd_tft.transparency_color = (0, 0, 0) +lcd_tft.draw_image(10, 10, numbers_image) diff --git a/gfxlcd/driver/ili9486/ili9486.py b/gfxlcd/driver/ili9486/ili9486.py index 376bc47..f7bc62c 100644 --- a/gfxlcd/driver/ili9486/ili9486.py +++ b/gfxlcd/driver/ili9486/ili9486.py @@ -37,10 +37,14 @@ class ILI9486(Area, Chip): self.driver.data(0x00, None) self.driver.cmd(0x11, None) - # self.driver.cmd(250, None) + #self.driver.cmd(250, None) + self.driver.cmd(0x3a, None) self.driver.data(0x55, None) + self.driver.cmd(0x36, None) + self.driver.data(0x28, None) + self.driver.cmd(0xc2, None) self.driver.data(0x44, None) @@ -67,7 +71,7 @@ class ILI9486(Area, Chip): self.driver.data(0x0D, None) self.driver.data(0x00, None) - self.driver.cmd(0x10000e1, None) + self.driver.cmd(0xe1, None) self.driver.data(0x0F, None) self.driver.data(0x32, None) self.driver.data(0x2E, None) @@ -84,7 +88,7 @@ class ILI9486(Area, Chip): self.driver.data(0x20, None) self.driver.data(0x00, None) - self.driver.cmd(0x10000e2, None) + self.driver.cmd(0xe2, None) self.driver.data(0x0F, None) self.driver.data(0x32, None) self.driver.data(0x2E, None) @@ -107,16 +111,13 @@ class ILI9486(Area, Chip): def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): """select area to work with""" self.driver.cmd(0x2a, None) - self.driver.data(pos_x1>>8, None) - self.driver.data(pos_x1&0xff, None) - self.driver.data(pos_x2>>8, None) - self.driver.data(pos_x2&0xff, None) + self.driver.data(pos_x1 >> 8, None) + self.driver.data(pos_x1 & 0xff, None) + self.driver.data(pos_x2 >> 8, None) + self.driver.data(pos_x2 & 0xff, None) self.driver.cmd(0x2b, None) - self.driver.data(pos_y1>>8, None) - self.driver.data(pos_y1&0xff, None) - self.driver.data(pos_y2>>8, None) - self.driver.data(pos_y2&0xff, None) + self.driver.data(pos_y1 >> 8, None) + self.driver.data(pos_y1 & 0xff, None) + self.driver.data(pos_y2 >> 8, None) + self.driver.data(pos_y2 & 0xff, None) self.driver.cmd(0x2c, None) - - # for _ in range(0, pos_x1*pos_y1): - # self.driver.data(0xf00ff, None) From fbb69d2db99dcad0efa15379deb1b7aabfe9d10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Wed, 17 May 2017 21:59:04 +0200 Subject: [PATCH 06/10] ILI9486 orientation --- gfxlcd/driver/ili9486/ili9486.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gfxlcd/driver/ili9486/ili9486.py b/gfxlcd/driver/ili9486/ili9486.py index f7bc62c..58ed1c3 100644 --- a/gfxlcd/driver/ili9486/ili9486.py +++ b/gfxlcd/driver/ili9486/ili9486.py @@ -6,9 +6,12 @@ from gfxlcd.abstract.chip import Chip class ILI9486(Area, Chip): """Class for ILI9486 based LCD""" + rotations = {0: 0x80, 90: 0xf0, 180: 0x40, 270: 0x20} + def __init__(self, width, height, driver): Chip.__init__(self, width, height, driver, True) Area.__init__(self, driver) + self.rotation = 0 def _converted_background_color(self): """color from 8-8-8 to 5-6-5""" @@ -35,15 +38,15 @@ class ILI9486(Area, Chip): self.driver.cmd(0x0b, None) self.driver.data(0x00, None) + self.driver.data(0x00, None) self.driver.cmd(0x11, None) - #self.driver.cmd(250, None) self.driver.cmd(0x3a, None) - self.driver.data(0x55, None) + self.driver.data(0x55, None) #0x66 self.driver.cmd(0x36, None) - self.driver.data(0x28, None) + self.driver.data(self.rotations[self.rotation], None) self.driver.cmd(0xc2, None) self.driver.data(0x44, None) From 221ee59f794e556881ef52b215e87596b8835eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Thu, 18 May 2017 18:28:14 +0200 Subject: [PATCH 07/10] rotaion for ili9325 --- gfxlcd/driver/ili9325/ili9325.py | 36 +++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/gfxlcd/driver/ili9325/ili9325.py b/gfxlcd/driver/ili9325/ili9325.py index 7e4330a..7182881 100644 --- a/gfxlcd/driver/ili9325/ili9325.py +++ b/gfxlcd/driver/ili9325/ili9325.py @@ -6,9 +6,33 @@ from gfxlcd.abstract.chip import Chip class ILI9325(Area, Chip): """Class for ILI9325 based LCD""" + rotations = { + 0: { + 'output': 0x0100, + 'mode': 0x1038, + 'output2': 0xa700 + }, + 90: { + 'output': 0x0000, + 'mode': 0x1038, + 'output2': 0xa700 + }, + 180: { + 'output': 0x0000, + 'mode': 0x1038, + 'output2': 0x2700 + }, + 270: { + 'output': 0x0100, + 'mode': 0x1038, + 'output2': 0x2700 + } + } + def __init__(self, width, height, driver): Chip.__init__(self, width, height, driver, True) Area.__init__(self, driver) + self.rotation = 270 def _converted_background_color(self): """color from 8-8-8 to 5-6-5""" @@ -36,13 +60,16 @@ class ILI9325(Area, Chip): # ************* ILI9325C/D ********** # set SS and SM bit self.driver.cmd(0x0001, None) - self.driver.data(0x0100, None) + self.driver.data(self.rotations[self.rotation]['output'], None) + # set 1 line inversion self.driver.cmd(0x0002, None) self.driver.data(0x0200, None) + # set GRAM write direction and BGR=1 self.driver.cmd(0x0003, None) - self.driver.data(0x1030, None) + self.driver.data(self.rotations[self.rotation]['mode'], None) + # Resize register self.driver.cmd(0x0004, None) self.driver.data(0x0000, None) @@ -145,7 +172,8 @@ class ILI9325(Area, Chip): self.driver.data(0x013F, None) # Gate Scan Line self.driver.cmd(0x0060, None) - self.driver.data(0xA700, None) + self.driver.data(self.rotations[self.rotation]['output2'], None) + # NDL, VLE, REV self.driver.cmd(0x0061, None) self.driver.data(0x0001, None) @@ -178,6 +206,8 @@ class ILI9325(Area, Chip): def _set_area(self, pos_x1, pos_y1, pos_x2, pos_y2): """select area to work with""" + if self.rotation == 90 or self.rotation == 270: + pos_x1, pos_y1, pos_x2, pos_y2 = pos_y1, pos_x1, pos_y2, pos_x2 self.driver.cmd(0x0020, None) self.driver.data(pos_x1, None) self.driver.cmd(0x0021, None) From 3b8d87772b9b38fcf04016f784861152717bab59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Thu, 18 May 2017 18:30:47 +0200 Subject: [PATCH 08/10] fake rotaion for ssd and nju --- gfxlcd/driver/ili9325/ili9325.py | 2 +- gfxlcd/driver/nju6450/nju6450.py | 1 + gfxlcd/driver/ssd1306/ssd1306.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gfxlcd/driver/ili9325/ili9325.py b/gfxlcd/driver/ili9325/ili9325.py index 7182881..fc84b9f 100644 --- a/gfxlcd/driver/ili9325/ili9325.py +++ b/gfxlcd/driver/ili9325/ili9325.py @@ -32,7 +32,7 @@ class ILI9325(Area, Chip): def __init__(self, width, height, driver): Chip.__init__(self, width, height, driver, True) Area.__init__(self, driver) - self.rotation = 270 + self.rotation = 0 def _converted_background_color(self): """color from 8-8-8 to 5-6-5""" diff --git a/gfxlcd/driver/nju6450/nju6450.py b/gfxlcd/driver/nju6450/nju6450.py index 200ed15..a99c77e 100644 --- a/gfxlcd/driver/nju6450/nju6450.py +++ b/gfxlcd/driver/nju6450/nju6450.py @@ -8,6 +8,7 @@ class NJU6450(Page, Chip): def __init__(self, width, height, driver, auto_flush=True): Chip.__init__(self, width, height, driver, auto_flush) Page.__init__(self, driver) + self.rotation = 0 def init(self): """initialize display""" diff --git a/gfxlcd/driver/ssd1306/ssd1306.py b/gfxlcd/driver/ssd1306/ssd1306.py index 4b595a1..dfe6078 100644 --- a/gfxlcd/driver/ssd1306/ssd1306.py +++ b/gfxlcd/driver/ssd1306/ssd1306.py @@ -8,6 +8,7 @@ class SSD1306(Page, Chip): def __init__(self, width, height, driver, auto_flush=True): Chip.__init__(self, width, height, driver, auto_flush) Page.__init__(self, driver) + self.rotation = 0 def init(self): """inits a device""" From 01aa9f2bddc226a5578d406d23c2ca4f476f1014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Thu, 18 May 2017 18:35:04 +0200 Subject: [PATCH 09/10] tweaks --- gfxlcd/driver/ili9325/ili9325.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gfxlcd/driver/ili9325/ili9325.py b/gfxlcd/driver/ili9325/ili9325.py index fc84b9f..c16d47d 100644 --- a/gfxlcd/driver/ili9325/ili9325.py +++ b/gfxlcd/driver/ili9325/ili9325.py @@ -9,7 +9,7 @@ class ILI9325(Area, Chip): rotations = { 0: { 'output': 0x0100, - 'mode': 0x1038, + 'mode': 0x1030, 'output2': 0xa700 }, 90: { @@ -18,9 +18,9 @@ class ILI9325(Area, Chip): 'output2': 0xa700 }, 180: { - 'output': 0x0000, - 'mode': 0x1038, - 'output2': 0x2700 + 'output': 0x0000, + 'mode': 0x1030, + 'output2': 0x2700 }, 270: { 'output': 0x0100, @@ -32,7 +32,7 @@ class ILI9325(Area, Chip): def __init__(self, width, height, driver): Chip.__init__(self, width, height, driver, True) Area.__init__(self, driver) - self.rotation = 0 + self.rotation = 270 def _converted_background_color(self): """color from 8-8-8 to 5-6-5""" From ab3d62c5a1f08ad755e499b6e2d1970a032094c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Ko=C5=9Bci=C3=B3w?= Date: Thu, 18 May 2017 19:41:12 +0200 Subject: [PATCH 10/10] default rotation 0 --- gfxlcd/driver/ili9325/ili9325.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfxlcd/driver/ili9325/ili9325.py b/gfxlcd/driver/ili9325/ili9325.py index c16d47d..27562b5 100644 --- a/gfxlcd/driver/ili9325/ili9325.py +++ b/gfxlcd/driver/ili9325/ili9325.py @@ -32,7 +32,7 @@ class ILI9325(Area, Chip): def __init__(self, width, height, driver): Chip.__init__(self, width, height, driver, True) Area.__init__(self, driver) - self.rotation = 270 + self.rotation = 0 def _converted_background_color(self): """color from 8-8-8 to 5-6-5"""