Shop OBEX P1 Docs P2 Docs Learn Events
Driver code for 4D SGE (serial) mode displays — Parallax Forums

Driver code for 4D SGE (serial) mode displays

Don MDon M Posts: 1,652
edited 2013-02-25 16:29 in Propeller 1
I recently purchased several of the 4.3" cap touch displays for a project. I thought I'd try my hand at writing a driver for the commands. It's far from finished but would like some critique from the crowd here before I get too far. In the zip file I also included a demo program I'm working with as I go along.
'' =================================================================================================
''
''   File....... 4D_SPE_Driver_V0_1.spin
''   Purpose.... Serial commands for 4D Systems SPE
''   Author..... Don Merchant
''   Licensing.. MIT License - see end of file for terms of use.   
''              
''              
''   E-mail..... donmerch@yahoo.com
''   Started.... FEB 15 2013
''   Updated.... 
''
'' =================================================================================================

con

var

obj

  ser   : "FullDuplexSerial"
  
pub Start(RX, TX, RST, Baud)

{{
  Start FullDuplexSerial driver
}}  

  ser.Start(RX, TX, 0, Baud)
  
  outa[RST]~~
  dira[RST]~~                                           ' Set RST pin as output

pub Move_Cursor(Line, Col) : result
{{
  The Move Cursor command moves the text cursor to a screen position set by line and
  column parameters in HEX. The line and column position is calculated, based on the size and
  scaling factor for the currently selected font. When text is outputted to screen it
  will be displayed from this position. The text position could also be set with Move Origin
  command if required to set the text position to an exact pixel location.  Note that
  lines and columns start from 0, so line 0, column 0 is the top left corner of the display.

  Response: 0x06 ACK (byte) if successful
  Anything else implies mismatch between command and response.
}}

  ser.tx($FF)
  ser.tx($E9)
  ser.tx(Line >> 8)
  ser.tx(Line & $FF)
  ser.tx(Col >> 8)
  ser.tx(Col & $FF)

  result := ser.rxtime(20)

pub Put_Char(Char) : result
{{
  The Put Character command prints a single character to the display.

  Response: 0x06 ACK (byte) if successful
  Anything else implies mismatch between command and response.
 
}}

  ser.tx($FF)
  ser.tx($E9)
  ser.tx(Char >> 8)
  ser.tx(Char & $FF)
  
  result := ser.rxtime(20)

pub Put_String(Strng) : result | d, r1, r2
{{
  The Put String command prints a string to the display. The argument can be a string
  constant or a pointer to a string.

  A string needs to be terminated with a NULL (00).

  Response: 0x06 ACK (byte), StringLength (word) if successful
  Anything else implies mismatch between command and response.
}}
 
  ser.tx($00)
  ser.tx($18)
  ser.str(Strng)
  ser.tx($00)
  
  d := ser.rx                   'time(200)
  if d == $06
    r1 := d << 16
    d := ser.rxtime(2)
    r2 := d << 8
    r1 := r1 | r2
    d := ser.rxtime(2)
    r1 := r1 | d
     
  result := r1

pub Text_FG_Color(Color) : result | d, r1, r2 
{{
  The Text Foreground Color command sets the text foreground color, and reports
  back the previous foreground color.

  Response: 0x06 ACK (byte) and Previous Text Foreground Color (word) if successful
  Anything else implies mismatch between command and response.
}}

  ser.tx($FF)
  ser.tx($E7)
  ser.tx(Color >> 8)
  ser.tx(Color & $FF)

  d := ser.rx                   'time(200)
  if d == $06
    r1 := d << 16
    d := ser.rxtime(2)
    r2 := d << 8
    r1 := r1 | r2
    d := ser.rxtime(2)
    r1 := r1 | d
     
  result := r1

pub Draw_Rect(x1, y1, x2, y2, color) : result
{{
  The Draw Rectangle command draws a rectangle from x1, y1 to x2, y2 using the
  specified color. The line may be tessellated with the Line Pattern command.

  Response: 0x06: ACK (byte) if successful
  Anything else implies mismatch between command and response.
}}

  ser.tx($FF)
  ser.tx($C5)
  ser.tx(x1 >> 8)
  ser.tx(x1 & $FF)
  ser.tx(y1 >> 8)
  ser.tx(y1 & $FF)
  ser.tx(x2 >> 8)
  ser.tx(x2 & $FF)
  ser.tx(y2 >> 8)
  ser.tx(y2 & $FF)
  ser.tx(color >> 8)
  ser.tx(color & $FF)
  
  result := ser.rxtime(20)
  
pub Clear_Scrn : result
{{
  The Clear Screen command clears the screen using the current background colour.
  This command brings some of the settings back to default; such as
    * Transparency turned OFF
    * Outline colour set to BLACK
    * Opacity set to OPAQUE
    * Pen set to OUTLINE
    * Line patterns set to OFF
    * Right text margin set to full width
    * Text magnifications set to 1
    * All origins set to 0:0

  The alternative to maintain settings and clear screen is to draw a filled rectangle with the required background colour.

  Response: 0x06: ACK (byte) if successful
  Anything else implies mismatch between command and response.
 
}}

  ser.tx($FF)
  ser.tx($CD)

  result := ser.rxtime(40) 
  
dat
{{
  Colors
}}

RED     word  $F800
GREEN   word  $0400
LIME    word  $07E0
WHITE   word  $FFFF
BLACK   word  $0000
BLUE    word  $001F

{{
&#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
&#9474;                                                   TERMS OF USE: MIT License                                                  &#9474;                                                            
&#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
&#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    &#9474; 
&#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    &#9474;
&#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software&#9474;
&#9474;is furnished to do so, subject to the following conditions:                                                                   &#9474;
&#9474;                                                                                                                              &#9474;
&#9474;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#9474;
&#9474;                                                                                                                              &#9474;
&#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          &#9474;
&#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         &#9474;
&#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   &#9474;
&#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         &#9474;
&#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
}}                 


Here's my setup using a Quickstart board:

4D Display Quickstart.jpg


Edit: This will work with the new 3.2" displays that Parallax is now selling too.

Edit: Attached latest driver.

Comments

  • ratronicratronic Posts: 1,451
    edited 2013-02-15 16:24
    Hi Don can you list the model # of your module? I have a 4.3" uLCD-43P (non touch version) 4DGL/serial which I have replaced the firmware with the discontinued G1 series.
  • ratronicratronic Posts: 1,451
    edited 2013-02-15 19:04
    Ok Don I have finally figured it out. The module needs to have the serial slave enviroment loaded with WorkShop 4 IDE under serial. When I first talked with 4D they pointed me to old firmware to use the SGC serial commands instead of pointing me to the new SPE serial command set. When I get back home I will put the newer firmware back in. The new SPE enviroment has different commands than the older SGC. That is why I couldn't get your program to work.
  • Don MDon M Posts: 1,652
    edited 2013-02-16 06:21
    ratronic wrote: »
    Ok Don I have finally figured it out. The module needs to have the serial slave enviroment loaded with WorkShop 4 IDE under serial. When I first talked with 4D they pointed me to old firmware to use the SGC serial commands instead of pointing me to the new SPE serial command set. When I get back home I will put the newer firmware back in. The new SPE enviroment has different commands than the older SGC. That is why I couldn't get your program to work.

    I'm using the uLCD-43PCT with PMMC Ver 3.3 and SGE Ver 1.0 @ 115_200 Baud.

    I've added some more functions to the driver and will continue to as time goes on. So far this display has been pretty good to work with.
  • Don MDon M Posts: 1,652
    edited 2013-02-25 16:29
    Attached the latest version of my driver to the top post if anyone is interested.
Sign In or Register to comment.