TFT Image converter

Discuss the Firewing development environment

TFT Image converter

Postby skartalov » Mon Jan 13, 2014 9:50 am

Hi,
as I succeed to run a 5 inch TFT display with resolution 800x480, featuring SSD1963 controller, I need the TFT Image converter plug-in to process images with the same resolution (800x480), but I found out, that the size is restricted to 320x240.

What we can do about that?

P.S. Once the driver is ready and tested, I will publish it on this forum as well.\
Meanwhile I have another driver almost ready! It's for 3.2' TFT's featuring SSD1289 controller.

RDS
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Re: TFT Image converter

Postby David John Barker » Mon Jan 13, 2014 9:57 am

> that the size is restricted to 320x240.

The latest version is 640x480. At that resolution, you will need to read the images of SD Card or some other external storage device. If you want higher, may I suggest you just split your image? That is, use the image converter to generate 2 x 400 x 480?

I look forward to seeing your driver code! Thanks for offering to share...
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: TFT Image converter

Postby David John Barker » Sat Feb 08, 2014 12:11 pm

Hi skartalov

> Meanwhile I have another driver almost ready! It's for 3.2' TFT's featuring SSD1289 controller.

Did you ever finish the driver? I would be very interested in taking a look...
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: TFT Image converter

Postby skartalov » Sat Feb 08, 2014 1:50 pm

Yeah Sure!
This one was the easiest to implement. It uses the complete PORTB for data (16bit). I am using another board, not FIREWING. MCU is 24HJ128GP504.
This driver runs pretty fast!
Any suggestion to make it even faster are welcomed, and will be used for another driver SSD1963, which you can find on 4,3' (480x272) and 5' (800x480) TFT's.

So here it is:

Code: Select all
'*****************************************************************************
'*  Name    : SSD1289.bas                                                    *
'*  Author  : Simeon Kartalov                                                *
'*  Version : 1.0                                                            *
'*  Notes   :                                                                *
'*          :                                                                *
'*****************************************************************************
Module SSD1289

imports TftGraphic

' Option section - if no values are given in the main program, this section
' will initialise them - all values are verified and if any errors are found,
' a custom message will be displayed in the main user program...

' Delay (US) of Shift clock...
#option SHIFT_CLK_TFT = 0 
#if IsOption(SHIFT_CLK_TFT) And Not (SHIFT_CLK_TFT in (0, 1, 2, 4, 8))
   #error SHIFT_CLK_TFT, "Invalid option. _data delay must be 0, 1, 2, 4 or 8 us."
#endif

' RS pin
' Low: indicates that data is commands,
' High: indicates that data is display data.
#option TFT_RS = PORTA.7
#if IsOption(TFT_RS) And Not IsValidPortPin(TFT_RS)
   #error TFT_RS, "Invalid option. TFT_RS must be a valid pin."
#endif

' RW pin (write strobe signal - active low)...
#option TFT_WR = PORTA.8
#if IsOption(TFT_WR) And Not IsValidPortPin(TFT_WR)
   #error TFT_WR, "Invalid option. TFT_RW must be a valid pin."
#endif

' CS pin (chip selection pin - active low)...
#option TFT_CS = PORTA.2
#if IsOption(TFT_CS) And Not IsValidPortPin(TFT_CS)
   #error TFT_CS, "Invalid option. TFT_CS must be a valid pin."
#endif

' RD pin
#option TFT_RD = PORTA.1
#if IsOption(TFT_RD) And Not IsValidPortPin(TFT_RD)
   #error TFT_RD, "Invalid option. TFT_RD must be a valid pin."
#endif

' RESET pin
#option TFT_RESET = PORTA.3
#if IsOption(TFT_RESET) And Not IsValidPortPin(TFT_RESET)
   #error TFT_RESET, "Invalid option. TFT_RESET must be a valid pin."
#endif

' data pins for 16 bit interface...
#option TFT_DATA = PORTB

' validate data pins...
#if IsOption(TFT_DATA) And Not IsValidPort(TFT_DATA)
   #error TFT_DATA, "Invalid option. TFT_DATA must be a valid port."
#endif

' bring delay option into the module...
private Const _delayUS As Byte = SHIFT_CLK_TFT

' width and height constants...
public const Width = 320   
public const Height = 240

' bring pin options into the program...
'private _data as TFT_DATA.TFT_DATA@
private _rs As TFT_RS.TFT_RS@     
private _wr As TFT_WR.TFT_WR@       
private _cs As TFT_CS.TFT_CS@
private _rd As TFT_RD.TFT_RD@
private _reset As TFT_RESET.TFT_RESET@     

' variables...
private _orientation as Orientation

'****************************************************************************
'* Name    : MakeOutput                                                     *
'* Purpose : Make data pins output                                          *
'****************************************************************************
private Inline Sub MakeOutput()
  TRISB=0
  output(_cs)
  output(_wr)
  output(_rs)
  output(_rd)
End Sub

'****************************************************************************
'* Name    : SetData                                                        *
'* Purpose : Sets DATA port value                                           *
'****************************************************************************
private Sub SetData(data As ushort)     
   PORTB=data 
End Sub

'****************************************************************************
'* Name    : Delay                                                          *
'* Purpose : Variable delay command                                         *
'****************************************************************************
inline sub Delay()
   asm
      nop
   end asm
 
   'delayus(1)
end sub

'****************************************************************************
'* Name    : WriteCommand                                                   *
'* Purpose : Write UShort command to TFT                                    *
'****************************************************************************
private sub WriteCommand(command as byte)
   _rs = 0         
   _cs = 0                   
   PORTB=command                   
   'Delay()
   _wr = 0
   Delay()       
   _wr = 1         
   _cs = 1   
   'Delay()     
end sub

'****************************************************************************
'* Name    : WriteData                                                      *
'* Purpose : Write UShort data to TFT                                       *
'****************************************************************************
public sub WriteData(data as ushort)
   _rs = 1       
   _cs = 0       
   PORTB=data           
   'Delay()
   _wr = 0
   Delay()           
   _wr = 1       
   _cs = 1 
     
   'Delay()     
end sub

'****************************************************************************
'* Name    : WriteCommandData                                               *
'* Purpose : Write Command and Data to TFT                                  *
'****************************************************************************
private sub WriteCommandData(command as ushort, data as ushort)
   WriteCommand(command)
   WriteData(data)
end sub

'****************************************************************************
'* Name    : SetOrientation                                                 *
'* Purpose : Set orientation to either portrait or landscape                *
'****************************************************************************
public sub SetOrientation(orient as Orientation)
   _orientation = orient
end sub

'****************************************************************************
'* Name    : SetPenColor                                                    *
'* Purpose : Set RGB pen color                                              *
'****************************************************************************
public sub SetPenColor(r as byte, g as byte, b as byte)
   Pen.Color.Value.Byte1 = ((r and 248) or g >> 5)
   Pen.Color.Value.Byte0 = ((g and 28) << 3 or b >> 3)
end sub

'****************************************************************************
'* Name    : SetPenColor                                                    *
'* Purpose : Set packed RGB pen color                                       *
'****************************************************************************
public sub SetPenColor(colour as ushort)
   Pen.Color.Value = colour
end sub

'****************************************************************************
'* Name    : SetBrushColor                                                  *
'* Purpose : Set RGB brush color                                            *
'****************************************************************************
public sub SetBrushColor(r as byte, g as byte, b as byte)
   Brush.Color.Value.Byte1 = ((r and 248) or g >> 5)
   Brush.Color.Value.Byte0 = ((g and 28) << 3 or b >> 3)
end sub

'****************************************************************************
'* Name    : SetBrushColor                                                  *
'* Purpose : Set packed RGB brush color                                     *
'****************************************************************************
public sub SetBrushColor(color as integer)
   Brush.Color.Value = color
end sub

'****************************************************************************
'* Name    : SetBounds                                                      *
'* Purpose : Set TFT update region                                          *
'****************************************************************************
public sub SetBounds(x1 as ushort, y1 as ushort, x2 as ushort, y2 as ushort)
   if (_orientation = Orientation.IsLandscape) then 
      dim tmp as ushort
     
      ' swap(x1, y1)
      tmp = x1
      x1 = y1
      y1 = tmp
         
      ' swap(x2, y2)
      tmp = x2
      x2 = y2
      y2 = tmp     
     
      y1 = (Width - 1) - y1
      y2 = (Width - 1) - y2
     
      ' swap(y1, y2)
      tmp = y1
      y1 = y2
      y2 = tmp
   end if

   WriteCommand($44)
   writedata((x2<<8)+x1)
   writecommand($45)
   writedata(y1)
   writecommand($46)
   writedata(y2)   
   writecommand($4e)
   writedata(x1)
   writecommand($4f)
   writedata(y1)
   
   WriteCommand($22)
   
end sub

'****************************************************************************
'* Name    : ClearXY                                                        *
'* Purpose : Set TFT update region to whole of screen                       *
'****************************************************************************
private sub ClearXY()
   if (_orientation = Orientation.IsPortrait) then
      SetBounds(0,0,Height - 1,Width - 1)
   else
      SetBounds(0,0,Width - 1,Height - 1)
   end if
end sub

'****************************************************************************
'* Name    : SetPixel                                                       *
'* Purpose : Set a single pixel value                                       *
'****************************************************************************
public sub SetPixel(x as integer, y as integer)
   _cs=0   
   SetBounds(x, y, x, y)
   WriteData(Pen.Color.Value)
   _cs=1
end sub

'****************************************************************************
'* Name    : Fill                                                           *
'* Purpose : Fill the whole of the screen in a given color                  *
'****************************************************************************
private sub Fill(data as ushort)
   ClearXY()
   for i as ushort = 0 to Width - 1         
      for j as ushort = 0 to Height - 1       
         WriteData(data)
      next
   next
end sub

'****************************************************************************
'* Name    : Clear                                                          *
'* Purpose : Clear screen with optional packed RGB color value              *
'****************************************************************************
public sub Clear(optional color as ushort = 0)
   _cs=0
   high(_rs)
   Fill(color)
   _cs=1
end sub

'****************************************************************************
'* Name    : Clear                                                          *
'* Purpose : Clear the screen using RGB color values                        *
'****************************************************************************
public sub Clear(r as byte, g as byte, b as byte)
   dim color as ushort
   Color.Byte1 = ((r and 248) or g >> 5)
   Color.Byte0 = ((g and 28) << 3 or b >> 3)
   _cs=0
   high(_rs)
   Fill(color)
   _cs=1
end sub

'****************************************************************************
'* Name    : HLine                                                          *
'* Purpose : Optimised horizontal line drawing                              *
'****************************************************************************
public sub HLine(x1 as ushort, x2 as ushort, y1 as ushort)
   _cs=0 
   dim len as ushort = x2 - x1 + 1
   SetBounds(x1, y1, x1 + len - 1, y1)
   while len > 0 
      WriteData(Pen.Color.Value)
      len = len - 1
   end while
   _cs=1
end sub

'****************************************************************************
'* Name    : VLine                                                          *
'* Purpose : Optimised vertical line drawing                                *
'****************************************************************************
public sub VLine(x1 as UShort, y1 as UShort, y2 as UShort)
   _cs=0
   dim len as ushort = y2 - y1 + 1
   SetBounds(x1, y1, x1, y1 + len - 1)
   while len > 0 
      WriteData(Pen.Color.Value)
      len = len - 1
   end while
   _cs=1
end sub

'****************************************************************************
'* Name    : SetBitmap                                                      *
'* Purpose : Draw a ROM bitmap at position x,y                              *
'****************************************************************************
public sub SetBitmap(x as ushort, y as ushort, byrefConst data() as ushort)
   dim width as ushort = data(0)
   dim height as ushort = data(1)
   dim index as ushort = 2
     
   low(_cs)   
   if (_orientation = Orientation.IsPortrait) then
      SetBounds(x, y, x + width - 1, y + height - 1)
      while index < ubound(data) 
         WriteData(data(index))
         index += 1
      end while 
   else 
      dim ty as ushort = 0
      while ty < height
         SetBounds(x, y + ty, x + width - 1, y + ty)
         dim tx as ushort = width - 1
         while true   
            dim index as ushort = (ty * width) + tx + 2
            WriteData(data(index))
            if tx = 0 then exit while 
            tx = tx - 1
         end while
         ty += 1
      end while
   end if
   high(_cs)
end sub

'****************************************************************************
'* Name    : Main                                                           *
'* Purpose : Module entry point                                             *
'****************************************************************************
sub Main()
   _orientation = Orientation.IsLandscape
   MakeOutput()
   low(_rs):high(_cs):high(_wr):high(_rd):high(_reset)
   delayms(5)     
   low(_reset)
   delayms(10)
   high(_reset)
   delayms(10)
   high(_wr):high(_rd)
   low(_cs)

   writecommanddata($00,$0001)
   writecommanddata($03,$A8A4)
   writecommanddata($0C,$0000)
   writecommanddata($0D,$080C)
   writecommanddata($0E,$2B00)
   writecommanddata($1E,$00B7)
   writecommanddata($01,$2B3F)
   writecommanddata($02,$0600)
   writecommanddata($10,$0000)
   writecommanddata($11,$6070)
   writecommanddata($05,$0000)
   writecommanddata($06,$0000)
   writecommanddata($16,$EF1C)
   writecommanddata($17,$0003)
   writecommanddata($07,$0233)
   writecommanddata($0B,$0000)
   writecommanddata($0F,$0000)
   writecommanddata($41,$0000)
   writecommanddata($42,$0000)
   writecommanddata($48,$0000)
   writecommanddata($49,$013F)
   writecommanddata($4A,$0000)
   writecommanddata($4B,$0000)
   writecommanddata($44,$EF00)
   writecommanddata($45,$0000)
   writecommanddata($46,$013F)
   writecommanddata($30,$0707)
   writecommanddata($31,$0204)
   writecommanddata($32,$0204)
   writecommanddata($33,$0502)
   writecommanddata($34,$0507)
   writecommanddata($35,$0204)
   writecommanddata($36,$0204)
   writecommanddata($37,$0502)
   writecommanddata($3A,$0302)
   writecommanddata($3B,$0302)
   writecommanddata($23,$0000)
   writecommanddata($24,$0000)
   writecommanddata($25,$8000)
   writecommanddata($4f,$0000)
   writecommanddata($4e,$0000)
   writecommand($22)   

   SetPenColor(255, 255, 255)
   SetBrushColor(0, 0, 0)
end sub

End Module


Also you have to replace TFT.bas with mine:

Code: Select all
'*****************************************************************************
'*  Name    : Tft.BAS                                                        *
'*  Author  : David John Barker                                              *
'*          : Steven Wright                                                  *
'*  Notice  : Copyright (c) 2012 Mecanique                                   *
'*          : All Rights Reserved                                            *
'*  Date    : 26/10/2012                                                     *
'*  Version : 1.0                                                            *
'*  Notes   : ST7735,ILI9225B,SSD1963,SSD1289 addition by Simeon Kartalov    *
'*****************************************************************************
module Tft

' validate model...
#option TFT_MODEL = S6D1121
#if not (TFT_MODEL in (S6D1121,ST7735,ILI9225B,SSD1963,SSD1963L,SSD1289))
   #error TFT_MODEL, "Invalid option. TFT model not recognized."
#endif



imports TFT_MODEL
imports TftGraphic
imports Math

' import driver...
#if TFT_MODEL = S6D1121
public const Width = S6D1121.Width
public const Height = S6D1121.Height
public Clear as S6D1121.Clear
public SetOrientation as S6D1121.SetOrientation
public SetPixel as S6D1121.SetPixel
public SetPenColor as S6D1121.SetPenColor
public SetBrushColor as S6D1121.SetBrushColor
public SetBitmap as S6D1121.SetBitmap
#define IMPLEMENTS_HLINE
#define IMPLEMENTS_VLINE
private SetHLine as S6D1121.HLine
private SetVLine as S6D1121.VLine
#endif

'800x600 5' TFT MODEL
#if TFT_MODEL = SSD1963
public const Width = SSD1963.Width
public const Height = SSD1963.Height
public Clear as SSD1963.Clear
public SetOrientation as SSD1963.SetOrientation
public SetPixel as SSD1963.SetPixel
public SetPenColor as SSD1963.SetPenColor
public SetBrushColor as SSD1963.SetBrushColor
public SetBitmap as SSD1963.SetBitmap
Public SetBounds as SSD1963.SetBounds
public WriteData as SSD1963.WriteData
'#define IMPLEMENTS_HLINE
'#define IMPLEMENTS_VLINE
private SetHLine as SSD1963.HLine
private SetVLine as SSD1963.VLine
#endif

'480x272 4.3' TFT MODEL
#if TFT_MODEL = SSD1963L
public const Width = SSD1963L.Width
public const Height = SSD1963L.Height
public Clear as SSD1963L.Clear
public SetOrientation as SSD1963L.SetOrientation
public SetPixel as SSD1963L.SetPixel
public SetPenColor as SSD1963L.SetPenColor
public SetBrushColor as SSD1963L.SetBrushColor
public SetBitmap as SSD1963L.SetBitmap
Public SetBounds as SSD1963L.SetBounds
public WriteData as SSD1963L.WriteData
'#define IMPLEMENTS_HLINE
'#define IMPLEMENTS_VLINE
private SetHLine as SSD1963L.HLine
private SetVLine as SSD1963L.VLine
#endif

#if TFT_MODEL = SSD1289
public const Width = SSD1289.Width
public const Height = SSD1289.Height
public Clear as SSD1289.Clear
public SetOrientation as SSD1289.SetOrientation
public SetPixel as SSD1289.SetPixel
public SetPenColor as SSD1289.SetPenColor
public SetBrushColor as SSD1289.SetBrushColor
public SetBitmap as SSD1289.SetBitmap
Public SetBounds as SSD1289.SetBounds
public WriteData as SSD1289.WriteData
'#define IMPLEMENTS_HLINE
'#define IMPLEMENTS_VLINE
private SetHLine as SSD1289.HLine
private SetVLine as SSD1289.VLine
#endif

#if TFT_MODEL = ST7735
public const Width = ST7735.Width
public const Height = ST7735.Height
public Clear as ST7735.Clear
public SetOrientation as ST7735.SetOrientation
public SetPixel as ST7735.SetPixel
public SetPenColor as ST7735.SetPenColor
public SetBrushColor as ST7735.SetBrushColor
public SetBitmap as ST7735.SetBitmap
Public SetBounds as ST7735.SetBounds
public WriteData as ST7735.WriteWordData
public StandBy as ST7735.StandBy
public WakeUp as ST7735.WakeUp
'#define IMPLEMENTS_HLINE
'#define IMPLEMENTS_VLINE
'private SetHLine as ST7735.HLine
'private SetVLine as ST7735.VLine
#endif

#if TFT_MODEL = ILI9225B
public const Width = ILI9225B.Width
public const Height = ILI9225B.Height
public Clear as ILI9225B.Clear
public SetOrientation as ILI9225B.SetOrientation
public SetPixel as ILI9225B.SetPixel
public SetPenColor as ILI9225B.SetPenColor
public SetBrushColor as ILI9225B.SetBrushColor
public SetBitmap as ILI9225B.SetBitmap
Public SetBounds as ILI9225B.SetBounds
public WriteData as ILI9225B.WriteWordData
'#define IMPLEMENTS_HLINE
'#define IMPLEMENTS_VLINE
'private SetHLine as ILI9225B.HLine
'private SetVLine as ILI9225B.VLine
#endif

' make graphics variables available for this module interface
public SetFont as Graphic.SetFont
public TextWidth as Graphic.TextWidth
public Pen as Graphic.Pen
public Brush as Graphic.Brush
public Font as Graphic.Font
public Align as Graphic.Align
public Pos as GraphicPosition

' default is equal apect ratio, change in GLCD model core...
#option GLCD_ASPECT_RATIO = 100
private const _aspectRatio = GLCD_ASPECT_RATIO

'****************************************************************************
'* Name    : line                                                           *
'* Purpose : Draws a line using a Bresenham line drawing algorithm          *
'****************************************************************************
public sub line(x1 as UShort, y1 as UShort, x2 as UShort, y2 as UShort) 
   dim p, diff as integer
   dim incx, incy  as integer
   dim dx_ge_dy as boolean
   dim dy, dx, delta as uShort
   dim penPosition as byte
   dim length as byte
   
   ' x direction...
   incx = 1
   if x1 > x2 then
      incx = -1
   end if   
 
   ' y direction
   incy = 1
   if y1 > y2 then
      incy = -1
   end if   

   dx = abs(x2 - x1)
   dy = abs(y2 - y1)

   if dx >= dy then
      dx_ge_dy = true
      dy = dy * 2
      p = dy - dx
      delta = dx
   else
      dx_ge_dy = false
      dx = dx * 2
      p = dx - dy
      delta = dy
   end if   
   diff = p - delta

   delta += 1
   penPosition = 0
   length = cbyte(Pen.Style)
   
   do                 
      if Pen.Style <> PenStyle.IsNormal then
         if penPosition < length then
            SetPixel(x1, y1)
         end if
         penPosition += 1
         if penPosition > length then
            penPosition = 0
         end if
      else
         SetPixel(x1, y1)
      end if
      if P < 0 then
         if dx_ge_dy then
            p += dy
            x1 += incx
         else
            p += dx
            y1 += incy
         end if   
      else
         p += diff
         x1 += incx
         y1 += incy
     end if
     delta -= 1
   loop until delta = 0
end sub

'****************************************************************************
'* Name    : Plot (PRIVATE)                                                 *
'* Purpose : Plots a set of ellipse quadrant points                         *
'****************************************************************************
sub Plot(pCX as UShort, pCY as UShort, posX as UShort, posY as UShort)
   SetPixel(pCX + posX, pCY + posY)
   SetPixel(pCX - posX, pCY + posY)
   SetPixel(pCX - posX, pCY - posY)
   SetPixel(pCX + posX, pCY - posY) 
end sub

'****************************************************************************
'* Name    : Ellipse                                                        *
'* Purpose : Draws an ellipse                                               *
'*         : A Fast Bresenham Type Algorithm For Drawing Ellipses           *
'*         : John Kennedy                                                   *
'*         : Mathematics Department, Santa Monica College                   *
'*         : Santa Monica, CA 90405 - http:'homepage.smc.edu/kennedy_john  *
'****************************************************************************
public sub Ellipse(pCX as UShort, pCY as UShort, pXRadius as UShort, pYRadius as UShort)
  dim x, y as UShort
  dim xChange, yChange as integer
  dim ellipseError as integer
  dim twoASquare, twoBSquare as integer
  dim stoppingX, stoppingY as integer
  dim penPosition as byte
  dim length as byte

  length = cbyte(Pen.Style)

  twoASquare = 2 * pXRadius * pXRadius
  twoBSquare = 2 * pYRadius * pYRadius
  x = pXRadius
  y = 0
  xChange = pYRadius * pYRadius * (1 - cint(2 * pXRadius))

  yChange = pXRadius * pXRadius
  ellipseError = 0
  stoppingX = twoBSquare * pXRadius
  stoppingY = 0
  penPosition = 0
  while stoppingX >= stoppingY 
      if Pen.Style <> PenStyle.IsNormal then
         if penPosition < length then
            Plot(pCX, pCY, x, y)
         end if
         penPosition += 1
         if penPosition > length then
            penPosition = 0
         end if
      else
         Plot(pCX, pCY, x, y)
      end if
      y += 1
      stoppingY += twoASquare
      ellipseError +=  yChange
      yChange += twoASquare
      if (2 * ellipseError + xChange) > 0  then
          x -= 1
          stoppingX -= twoBSquare
          ellipseError += xChange
          xChange += twoBSquare
      end if
  end while

  x = 0
  y = pYRadius
  xChange = pYRadius * pYRadius
  yChange = pXRadius * pXRadius * (1 - cint(2 * pYRadius))

  ellipseError = 0
  stoppingX = 0
  stoppingY = twoASquare * pYRadius
  penPosition = 0
  while stoppingX <= stoppingY
      if Pen.Style <> PenStyle.IsNormal then
         if penPosition < length then
            Plot(pCX, pCY, x, y)
         end if
         penPosition += 1
         if penPosition > length then
            penPosition = 0
         end if
      else
         Plot(pCX, pCY, x, y)
      end if
      x += 1
      stoppingX += twoBSquare
      ellipseError += xChange
      xChange += twoBSquare
      if (2 * ellipseError + yChange) > 0  then
          y -= 1
          stoppingY -= twoASquare
          ellipseError += yChange
          yChange += twoASquare
      end if
  end while
end sub

'****************************************************************************
'* Name    : Circle                                                         *
'* Purpose : Draws a circle, Y is scaled to compensate for aspect ratio     *
'****************************************************************************
public sub Circle(centerX as UShort, centerY as UShort, radius as UShort)   
   #if GLCD_ASPECT_RATIO <> 100
   Ellipse(centerX, centerY, radius, radius * _aspectRatio / 100)
   #else
   Ellipse(centerX, centerY, radius, radius)
   #endif
end sub

'****************************************************************************
'* Name    :                                                                *
'* Purpose :                                                                *
'****************************************************************************
public sub FillCircle(x as ushort, y as ushort, radius as ushort)
   dim lastPen as GraphicPen = Pen
   Pen.Color.Value = Brush.Color.Value
   Pen.Style = PenStyle.IsNormal
   for y1 as short = -radius to 0
      for x1 as short = -radius to 0
         if (x1 * x1 + y1 * y1 <= radius * radius) then
            HLine(x + x1, x + abs(x1), y + y1) 
            HLine(x + x1, x + abs(x1), y - y1)
            exit for
         end if
      next
   next
   Pen = lastPen
end sub

'****************************************************************************
'* Name    : HLine (PRIVATE)                                                *
'* Purpose : Draws a horizontal line                                        *
'****************************************************************************
sub HLine(x1 as UShort, x2 as UShort, y as UShort)
   #ifdef IMPLEMENTS_HLINE
   if Pen.Style = PenStyle.IsNormal then
      SetHLine(x1,x2,y)
      exit sub
   end if
   #endif

   dim penPosition as byte
   dim length as byte
   penPosition = 0
   length = cbyte(Pen.Style)
   while x1 <= x2
      if Pen.Style <> PenStyle.IsNormal then
         if penPosition < length then
            SetPixel(x1,y)
         end if
         penPosition += 1
         if penPosition > length then
            penPosition = 0
         end if
      else
         SetPixel(x1,y)
      end if
      x1 += 1
   end while   
end sub

'****************************************************************************
'* Name    : VLine (PRIVATE)                                                *
'* Purpose : Draw a vertical line                                           *
'****************************************************************************
sub VLine(x as UShort, y1 as UShort, y2 as UShort)
   #ifdef IMPLEMENTS_VLINE
   if Pen.Style = PenStyle.IsNormal then
      SetVLine(x,y1,y2)
      exit sub   
   end if
   #endif
   
   dim penPosition as byte
   dim length as byte
   penPosition = 0
   length = cbyte(Pen.Style)
   while y1 <= y2
      if Pen.Style <> PenStyle.IsNormal then
         if penPosition < length then
            SetPixel(x,y1)
         end if
         penPosition += 1
         if penPosition > length then
            penPosition = 0
         end if
      else
         SetPixel(x,y1)
      end if
      y1 += 1
   end while   
end sub

'****************************************************************************
'* Name    : Rectangle                                                      *
'* Purpose : Draws a rectangle                                              *
'****************************************************************************
public sub Rect(x1 as UShort, y1 as UShort, x2 as UShort, y2 as UShort)
   dim Swap as UShort
   
   if x2 < x1 then
      Swap = x1
      x1 = x2
      x2 = Swap
   end if

   if y2 < y1 then
      Swap = y1
      y1 = y2
      y2 = Swap
   end if
   
   HLine(x1, x2, y1)
   VLine(x2, y1, y2)
   HLine(x1, x2, y2)
   VLine(x1, y1, y2)
end sub

'****************************************************************************
'* Name    : Rectangle                                                      *
'* Purpose : Draws a rectangle                                              *
'****************************************************************************
public sub FillRect(x1 as UShort, y1 as UShort, x2 as UShort, y2 as UShort)
   dim Swap as UShort
   
   if x2 < x1 then
      Swap = x1
      x1 = x2
      x2 = Swap
   end if

   if y2 < y1 then
      Swap = y1
      y1 = y2
      y2 = Swap
   end if
   
   dim lastPen as GraphicPen = Pen
   Pen.Color.Value = Brush.Color.Value
   Pen.Style = PenStyle.IsNormal
   for y as ushort = y1 to y2
      HLine(x1, x2, y)
   next
   Pen = lastPen
end sub

'****************************************************************************
'* Name    : RoundRect                                                      *
'* Purpose : Draws a rectangle with rounded edges                           *
'****************************************************************************
public sub RoundRect(x1 as ushort, y1 as ushort, x2 as ushort, y2 as ushort)
   dim Swap as UShort
   if x2 < x1 then
      Swap = x1
      x1 = x2
      x2 = Swap
   end if

   if y2 < y1 then
      Swap = y1
      y1 = y2
      y2 = Swap
   end if
   
   if (x2 - x1 > 4) and (y2 - y1 > 4) then
      SetPixel(x1+1,y1+1)
      SetPixel(x2-1,y1+1)
      SetPixel(x1+1,y2-1)
      SetPixel(x2-1,y2-1)
      HLine(x1 + 2, x2 - 2, y1)
      HLine(x1 + 2, x2 - 2, y2)
      VLine(x1, y1 + 2, y2 - 2)
      VLine(x2, y1 + 2, y2 - 2)
   end if
end sub

'****************************************************************************
'* Name    : FillRoundRect                                                  *
'* Purpose : Draws a filled rectangle with rounded edges                    *
'****************************************************************************
public sub FillRoundRect(x1 as ushort, y1 as ushort, x2 as ushort, y2 as ushort)
   dim Swap as UShort
   if x2 < x1 then
      Swap = x1
      x1 = x2
      x2 = Swap
   end if

   if y2 < y1 then
      Swap = y1
      y1 = y2
      y2 = Swap
   end if
   
   if (x2 - x1 > 4) and (y2 - y1 > 4) then 
      dim lastPen as GraphicPen = Pen
      Pen.Color.Value = Brush.Color.Value
      Pen.Style = PenStyle.IsNormal
      for i as ushort = 0 to (y2 - y1) / 2
         select i
            case 0:
               HLine(x1 + 2, x2 - 2, y1 + i)
               HLine(x1 + 2, x2 - 2, y2 - i)
            case 1:
               HLine(x1 + 1, x2 - 1, y1 + i)
               HLine(x1 + 1, x2 - 1, y2 - i)
            case else
               HLine(x1, x2, y1 + i)
               HLine(x1, x2, y2 - i)
         end select
      next
      Pen = lastPen
   end if
end sub

'****************************************************************************
'* Name    : Square                                                         *
'* Purpose : Draws a square, Y is scaled to compensate for aspect ratio     *
'****************************************************************************
public sub Square(posX as UShort, posY as UShort, size as UShort)
   #if GLCD_ASPECT_RATIO <> 100
   Rect(posX, posY, posX + size, posY + size * _aspectRatio / 100)
   #else
   Rect(posX, posY, posX + size, posY + size)
   #endif
end sub

'****************************************************************************
'* Name    : MoveTo                                                         *
'* Purpose : Moves graphics cursor to given point before calling LineTo()   *
'****************************************************************************
public sub MoveTo(posX as UShort, posY as UShort)
   Pos.x = posX
   Pos.y = posY
end sub

'****************************************************************************
'* Name    : LineTo                                                         *
'* Purpose : Draws a line from the current graphics cursor position         *
'****************************************************************************
public sub LineTo(posX as UShort, posY as UShort)
   line(Pos.x, Pos.y, posX, posY)
   Pos.x = posX
   Pos.y = posY
end sub

'****************************************************************************
'* Name    : WriteChar(PRIVATE)                                             *
'* Purpose : Write a single character to GLCD                               *
'*         : This routine only supports fonts with a y scan line (&H8x xx)  *
'*         : It's device independent, which makes it pretty slow - look at  *
'*         : implementing a device specific routine in the GLCD driver      *
'****************************************************************************
private sub WriteChar()
   dim x, y as ushort

   dim fontByte as byte
   dim lastPosY as ushort = Pos.y
   dim penColor as GraphicColor = Pen.Color
     
   dim posx as ushort = pos.x
   dim posy as ushort = pos.y
   
   if Font.IsScanY then
      if Brush.Style <> BrushStyle.IsClear then
         FillRect(Pos.x, Pos.y, Pos.x + Font.Width, Pos.y + Font.Height)
      end if
      x = 0
      do
         Posy = lastPosY         
         y = 0
         do
            if y mod 8 = 0 then
               fontByte = ReadFontByte
            end if   
           
            if fontByte.0 = 1 then
               SetPixel(Posx,Posy)
            end if
                         
            fontByte = fontByte >> 1
            Posy = posy + 1
            y = y + 1
         loop until y = Font.Height
         Posx = posx + 1
         x = x + 1
      loop until x = Font.Width 
   end if     

   Pen.Color = penColor 
   pos.x = posx
   pos.y = lastPosY 
end sub

'****************************************************************************
'* Name    : WriteFontChar                                                  *
'* Purpose : Write a font character to the GLCD                             *
'****************************************************************************
sub WriteFontChar(character as char)
   LoadCharAddress(character)
   if Font.IsVariable then
      Font.Width = ReadFontByte
   end if
   WriteChar 
end sub

'****************************************************************************
'* Name    : WriteLetterSpacing                                             *
'* Purpose :                                                                *
'****************************************************************************
sub WriteFontSpace()
   dim index as byte
   index = Font.LetterSpacing     
   while index > 0
      LoadLetterSpacing
      WriteChar
      index -= 1
   end while
end sub

'****************************************************************************
'* Name    : WriteItem (OVERLOAD)                                           *
'* Purpose : Writes a character to GLCD                                     *
'****************************************************************************
sub WriteItem(character as char)
   WriteFontChar(character)
end sub

'****************************************************************************
'* Name    : WriteItem (OVERLOAD)                                           *
'* Purpose : Writes a string to GLCD                                        *
'****************************************************************************
sub WriteItem(text as string)
   dim index as byte = 0
   dim ch as char = text(index)
   while ch <> nothing
      WriteFontChar(ch)
      index += 1
      ch = text(index)
      if Font.IsVariable and ch <> nothing then
         WriteFontSpace
      end if   
   end while
end sub

'****************************************************************************
'* Name    : SetLocationX (PRIVATE)                                         *
'* Purpose : Set cursor x                                                   *
'****************************************************************************
sub SetLocationX(posX as UShort)
   Pos.x = posX
end sub

'****************************************************************************
'* Name    : SetLocationY (PRIVATE)                                         *
'* Purpose : Set cursor y                                                   *
'****************************************************************************
sub SetLocationY(posY as UShort)
   Pos.y = posY
end sub

'****************************************************************************
'* Name    : Write (COMPOUND)                                               *
'* Purpose : Write one or more items to GLCD                                *
'****************************************************************************
public compound sub Write(WriteItem)

'****************************************************************************
'* Name    : WriteAt (COMPOUND)                                             *
'* Purpose : Write one or more items at position x, y                       *
'****************************************************************************
public compound sub WriteAt(SetLocationX, SetLocationY, WriteItem)

'****************************************************************************
'* Name    : WriteStr                                                       *
'* Purpose : Write one item centred in x At position x, y                   *
'****************************************************************************
public sub WriteStr(posX as UShort, posY as UShort, text as string)
   Pos.x = posX
   Pos.y = posY
   if Align = TextAlign.Center then
      Pos.x  -= TextWidth(text) / 2
   elseif Align = TextAlign.Right then
      Pos.x -= TextWidth(text)
   end if     
   WriteItem(text)
end sub


end module
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Re: TFT Image converter

Postby David John Barker » Sat Feb 08, 2014 9:05 pm

That's great work! Have you any pictures? Would you mind if I upload to the wiki?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: TFT Image converter

Postby David John Barker » Sun Feb 09, 2014 11:32 am

I've noticed you have done many more drivers for the Tft module? Would you be prepared to share them with the Firewing community? I would like to try some of these drivers myself!!
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: TFT Image converter

Postby skartalov » Sun Feb 09, 2014 12:29 pm

Yes, I will share all of them.

ST7735 for 1.8' (128x160) TFT SPI -> Already Shared
http://www.ebay.co.uk/itm/1-8-Serial-SP ... 3cd595cf9b

ILI9225B for 2.2' (176x220) TFT SPI ->Already Shared
http://www.aliexpress.com/item/2-2-SPI- ... 55135.html

SSD1289 for 3.2' (320x240) TFT 16bit -> Already Shared
http://www.aliexpress.com/item/3-2-TFT- ... 80146.html

SSD1963 for 5' (800x480) TFT 16 bit -> Work in progress
http://www.ebay.co.uk/itm/5-TFT-LCD-SSD ... =undefined

SSD1963L for 4.3' (480x272) TFT 16 bit -> Work in progress
http://www.ebay.co.uk/itm/130981185941? ... 1439.l2649

Feel free to publish them on WiKi on my behalf.

3.2TFT_1.JPG
3.2TFT_1.JPG (182.97 KiB) Viewed 11024 times

3.2TFT_2.JPG
3.2TFT_2.JPG (148.64 KiB) Viewed 11024 times
Last edited by skartalov on Sun Feb 09, 2014 12:48 pm, edited 1 time in total.
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Re: TFT Image converter

Postby David John Barker » Sun Feb 09, 2014 12:32 pm

That would be great, that you. I will wait to see what you come up with. Pictures of the TFT running would be nice so I can post on the wiki. Also, where you obtained the TFT would also be useful so we know where to buy from. Thanks again for your input...
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: TFT Image converter

Postby David John Barker » Sun Feb 09, 2014 12:39 pm

I see you uploaded some pictures - awesome! Have you implemented any code for touch?
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: TFT Image converter

Postby skartalov » Sun Feb 09, 2014 12:51 pm

David John Barker wrote:I see you uploaded some pictures - awesome! Have you implemented any code for touch?


OK, I also added links in EBAY and ALIEXPRESS to buy some TFT's.

I am using succesfuly bitfogav's code for touch screen, however it needs modification, because the display orientation is different.
I will let you know, when I am ready with the touch screen functions.
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Next

Return to Development Environment

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x