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)