From Swordfish Wiki

SwordfishUser: FT800

This library, obtained by porting from Firewing source written by David Barker, lets you use the display module FT800 / Gameduino2 from Swordifsh.

Changed on Feb 2017:

Compared to the original version to be able to properly display many objects and be able to use the tracking properly, you must change the following routines :

rows added are indicated by // <----------------

'********************************************************************************
'* Name    : CMD_PROGRESS                                                       *
'* Purpose : Draw a progress bar                                                *
'******************************************************************************** 
Public Sub CMD_PROGRESS(x As Integer, 
                        y As Integer, 
                        w As Integer, 
                        h As Integer, 
                        options As Word, 
                        val As Word, 
                        range As Word) 
   cmd(FT_CMD_PROGRESS) 
   wr16(RAM_CMD+cmd_offset, x) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, y) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, w) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, h) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, options) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, val) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, range) 
   cmd_increment2()    
   wr16(RAM_CMD+cmd_offset, 0)       // <----------------
   cmd_increment2()                  // <----------------
End Sub

'********************************************************************************
'* Name    : CMD_SLIDER                                                         *
'* Purpose : draw a slider                                                      *
'******************************************************************************** 
Public Sub CMD_SLIDER(x As Integer, 
                      y As Integer, 
                      w As Word, 
                      h As Word, 
                      options As Word, 
                      val As Word, 
                      range As Word) 
   cmd(FT_CMD_SLIDER) 
   wr16(RAM_CMD+cmd_offset, x) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, y) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, w) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, h) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, options) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, val) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, range) 
   cmd_increment2()
   wr16(RAM_CMD+cmd_offset, 0)       // <----------------
   cmd_increment2()                  // <----------------
End Sub

'********************************************************************************
'* Name    : CMD_DIAL                                                           *
'* Purpose : Draw a rotary dial control                                         *
'******************************************************************************** 
Public Sub CMD_DIAL(x As Integer, 
                    y As Integer, 
                    r As Integer, 
                    options As Word, 
                    val As Word) 
   cmd(FT_CMD_DIAL) 
   wr16(RAM_CMD+cmd_offset, x) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, y) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, r) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, options) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, val) 
   cmd_increment2()                // <----------------
   wr16(RAM_CMD+cmd_offset, 0)     // <----------------
   cmd_increment2()                // <----------------
End Sub

'********************************************************************************
'* Name    : CMD_TOGGLE                                                         *
'* Purpose : draw a toggle switch                                               *
'******************************************************************************** 
Public Sub CMD_TOGGLE(x As Integer, 
                      y As Integer, 
                      w As Integer, 
                      font As Byte, 
                      options As Word, 
                      state As Word, 
                      s As String) 
   cmd(FT_CMD_TOGGLE) 
   wr16(RAM_CMD+cmd_offset, x) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, y) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, w) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, font) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, options) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, state) 
   cmd_increment2()                          // <----------------
   cmd_incrementn(wr8s(RAM_CMD+cmd_offset, s))
End Sub

'********************************************************************************
'* Name    : CMD_TRACK                                                          *
'* Purpose : enable co-processor engine to track the touch on the particular    *
'*           graphics object with one valid tag value assigned                  *
'******************************************************************************** 
Public Sub CMD_TRACK(x As Integer, y As Integer, w As Integer, h As Integer, TAG As Integer) 
   cmd(FT_CMD_TRACK) 
   wr16(RAM_CMD+cmd_offset, x) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, y) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, w) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset, h) 
   cmd_increment2() 
   wr16(RAM_CMD+cmd_offset,TAG ) 
   cmd_increment2()     
   wr16(RAM_CMD+cmd_offset,0 )    // <----------------
   cmd_increment2()               // <----------------
End Sub

You can download Swordfish FT800 Library here

You can download Diagram and PCB here

I used a Gameduino 2 display module and recommend using a MPU with a speed higher or equal to 32MHz, I used a xtal of 10MHz with a 4xPLL device.

Respect from original of David I added:

 - Storing the calibration in EEPROM 

(at address 0 by default but can be selected differently) if the device has an EEPROM that stored parameters on the first run of SelfCalibrate().

 - The ability to adjust the intensity of the backlight

via software through procedures TurnOff (), which turns it off completely, and TurnOn () where you can pass as a parameter the duty cycle with a byte value between 0 and 128.

 - The ability to use the SDCard module completely or a subset of it 

with only necessary routines for use with the FT800 module maked via option. Default value is False, only a subset is included.

#option FT800_FULL_SD_LIB = false
 - FT.Clear became FT.Cls since Clear is a keyword in Swordfish.
{
*****************************************************************************
*  Name    : Ballons.BAS                                                    *
*****************************************************************************
}

Device = 18F2682
Clock = 40

#option FT800_MODEL = GAMEDUINO
#option FT800_SDCS  = PORTC.1
#option FT800_CS    = PORTC.0
#option FT800_CLK   = PORTC.3
#option FT800_DI    = PORTC.4
#option FT800_DO    = PORTC.5
Include "FT800"

Dim i As Word
While true
    FT.Cls()
    FT.Begin(POINTS)
    For i = 0 To 100
        FT.PointSize(FT.Random(16 * 50))
        FT.ColorRGB(FT.Random(256), FT.Random(256), FT.Random(256))
        FT.ColorA(FT.Random(256))
        FT.VERTEX2II(FT.Random(480), FT.Random(272))
    Next 
    FT.Swap()
End While

In the second example "Numpad.BAS" found how to switch off the display after a period of time without use until they touch the screen.

{
*****************************************************************************
*  Name    : Numpad.BAS                                                     *
*****************************************************************************
}

Device = 18F2682
Clock = 40

#option FT800_MODEL = GAMEDUINO
#option FT800_SDCS  = PORTC.1
#option FT800_CS    = PORTC.0
#option FT800_CLK   = PORTC.3
#option FT800_DI    = PORTC.4
#option FT800_DO    = PORTC.5
Include "FT800"
Include "convert"

Private Sub Paint_Alpha()
    FT.BlendFunc(ONE, ONE_MINUS_SRC_ALPHA)
End Sub

Private Sub Clear_Alpha()
    FT.BlendFunc(ZERO, ONE_MINUS_SRC_ALPHA)
End Sub

Private Sub button(x As Integer, y As Integer, size As Byte, label As Byte)
    Paint_Alpha()
    FT.TagMask(1)
    FT.Tag(label)
    FT.Begin(RECTS)
    FT.LineWidth(16 * 20)
    FT.VERTEX2II(x - size, y - size)
    FT.VERTEX2II(x + size, y + size)
    Clear_Alpha()
    FT.ColorA(200)
    FT.ColorA(200)
    FT.LineWidth(16 * 15)
    FT.VERTEX2II(x - size, y - size)
    FT.VERTEX2II(x + size, y + size)
    FT.ColorA($ff)
    Paint_Alpha()
    FT.Begin(POINTS)
    FT.cmd_number(x, y, 31, OPT_CENTER, label)
    FT.TagMask(0)
End Sub

Dim x0, x1, x2,
    y0, y1, y2  As Integer
Dim selectedTag,
    lastselected As Byte
Dim loops As Word, 
    on As Boolean

x0 = 40  ' 160
x1 = 110 ' 240
x2 = 180 ' 320

y0 = 50  ' 56
y1 = 120 ' 136
y2 = 190 ' 216

lastselected = 0
loops = 0
on = true 

FT.SelfCalibrate()
FT.cmd_loadimage(0,0) 

If Not FT.Load("chipmunk.jpg") Then 
    FT.Cls()
    FT.cmd_text(240, 136, 29, OPT_CENTER, "Unable to load file")  
    FT.Swap()          
Else 

    While true
        FT.Cls()
        FT.ColorMask(1, 1, 1, 0)
        FT.TagMask(0)
        FT.Begin(BITMAPS)
        FT.VERTEX2II(0, 0)
        FT.ColorMask(0, 0, 0, 1)

        button(x0, y0, 14 ,1)
        button(x1, y0, 14 ,2)
        button(x2, y0, 14 ,3)
        button(x0, y1, 14 ,4)
        button(x1, y1, 14 ,5)
        button(x2, y1, 14 ,6)
        button(x0, y2, 14 ,7)
        button(x1, y2, 14 ,8)
        button(x2, y2, 14 ,9)

        If on Then    
            If loops > 1000 Then
                TurnOn(5)             ' <-- Backlight set to 5 duty
                loops = 0
                on = false
            Else
                Inc(loops)
            End If 
        End If

        If on Then
            FT.TagMask(0)
        Else
            FT.TagMask(1)        
        End If
        FT.ColorMask(1, 1, 1, 1)
        FT.ColorRGB($ffffff)
        FT.BlendFunc(DST_ALPHA, ONE_MINUS_DST_ALPHA)
        FT.Begin(RECTS)
        If Not on Then
            FT.Tag(128)                ' Display is OFF then 
                                       ' the rectangle on all display area 
                                       ' become active when touch with a tag
                                       ' value of 128
        End If
        FT.VERTEX2II(0, 0)
        FT.VERTEX2II(480, 272)         ' Draw a rectangle on all display area 
                                       ' active with a tag only when display is
                                       ' off 

        FT.RestoreContext()

        selectedTag = FT.GetTag()
        If selectedTag<>0 Then
            lastselected = selectedTag
            TurnOn()                     ' <-- Backlight set to 128 duty 
            loops = 0
            on = true              
        End If

        If selectedTag<>128 Then
            ' Touch on all display area when display is off then
            ' pressed message is not display
            FT.cmd_text(15, 240, 27, 0, "Pressed : " + DecToStr(selectedTag))
        End If

        If lastselected <>0 And lastselected<>128 Then
            ' Touch on an element and not when display is off 
            FT.cmd_text(200, 240, 27, 0, "Last Selected : " + DecToStr(lastselected))
        End If

        FT.Swap()     
    End While
End If
Retrieved from http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.FT800
Page last modified on February 03, 2017, at 08:51 AM