Graphics Drawing Interface EZLCD4 display using serial

Files at this revision

API Documentation at this revision

Comitter:
wbasser
Date:
Mon Mar 14 15:58:13 2011 +0000
Child:
1:683ac9b65344
Commit message:
Version 00_00_01

Changed in this revision

gdiezl4.cpp Show annotated file Show diff for this revision Revisions of this file
gdiezl4.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gdiezl4.cpp	Mon Mar 14 15:58:13 2011 +0000
@@ -0,0 +1,329 @@
+/*****************************************************************************
+//   $Workfile: $
+//    Function: graphics drive - EZLCD04 implementation
+//      Author: Bill Basser
+//   $JustDate: $
+//   $Revision: $
+//
+//    This document contains proprietary data and information of
+//  Cyber Integration LLC.  It is the exclusive property of
+//  Cyber Integration, LLC and will not be disclosed in any form to
+//  any party without prior written permission of Cyber Integration, LLC.
+//  This document may not be reproduced or further used without the
+//  prior written permission of Cyber Integration, LLC.
+//
+//  Copyright (C) 2011 Cyber Integration, LLC. All Rights Reserved
+//
+//  $History: $
+ *
+ *****************************************************************************/
+
+// local includes
+#include "gdiezl4.h"
+
+// define the MSB/LSB extraction utilities
+#define    MSB(w)    (( w >> 8 ) & 0xFF )
+#define    LSB(w)    ( w & 0xFF )
+
+/******************************************************************************
+//    Function Name: GdiEzL4( tTx, tRx )
+//      Description: construction
+//            Entry: tTx = transmit pin
+//                   tRx = receive pin    
+//             Exit: none
+// Globals modified: none
+//  Locals modified: none
+//  Locals modified: none
+******************************************************************************/
+GdiEzL4::GdiEzL4( PinName pinTx, PinName pinRx ) : m_serDisp( pinTx, pinRx )
+{
+    // create the interface
+    m_serDisp.baud( 115200 );
+    m_serDisp.attach( this, &LocalCallback );
+    
+    // initialize
+    m_serDisp.putc( EZ_BTP );
+    m_serDisp.putc( ON );
+
+    // turn the backlight on/clear screen to white
+    BacklightCtl( ON );
+    ClearScreen( RGB( 255, 255, 255 ));
+}
+
+/******************************************************************************
+//    Function Name: GdiEzL4( )
+//      Description: destruction
+//            Entry: none
+//             Exit: none
+// Globals modified: none
+//  Locals modified: none
+//  Locals modified: none
+******************************************************************************/
+GdiEzL4::~GdiEzL4( void )
+{
+}
+
+/******************************************************************************
+//    Function Name: GdiBacklightCtl( bOffOn )
+//      Description: turn backlight off/on
+//            Entry: bOffOn
+//             Exit: none
+// Globals modified: none
+//  Locals modified: anBuffer, nBufLen
+******************************************************************************/
+void GdiEzL4::BacklightCtl( BOOL bOffOn )
+{
+    // set the correct state of the backlight
+    m_serDisp.putc(( bOffOn ) ? EZ_LON : EZ_LOF );
+}
+
+/******************************************************************************
+//    Function Name: GdiClearScreen( wColor )
+//      Description: clear the screen to the color
+//            Entry: wColor = background color
+//             Exit: none
+// Globals modified: none
+//  Locals modified: anBuffer, nBufLen
+******************************************************************************/
+void GdiEzL4::ClearScreen( U16 wColor )
+{
+    // clear the screen
+    m_serDisp.putc( EZ_FGC );
+    m_serDisp.putc( LSB( wColor ));
+    m_serDisp.putc( MSB( wColor ));
+    m_serDisp.putc( EZ_CLS );
+}
+
+/******************************************************************************
+//    Function Name: GdiDrawRect( U16 wColor, U16 wSx, U8 nSy, U16 wWidth, U8 nHeight, BOOL bFill )
+//      Description: draw a rectangle
+//            Entry: wColor = rectangle color
+//                   wSx = starting X
+//                   nSy = starting Y
+//                   wWidth = width of box
+//                   nHeight = height of box
+//                   bFill = fill color
+//             Exit: none
+// Globals modified: none
+//  Locals modified: anBuffer, nBufLen
+******************************************************************************/
+void GdiEzL4::DrawRect( U16 wColor, U16 wSx, U8 nSy, U16 wWidth, U8 nHeight, BOOL bFill )
+{
+    U16 wEx = wSx + wWidth - 1;
+    U8 nEy = nSy + nHeight - 1;
+
+    // draw a rectangle
+    m_serDisp.putc( EZ_FGC );
+    m_serDisp.putc( LSB( wColor ));
+    m_serDisp.putc( MSB( wColor ));
+    m_serDisp.putc( EZ_SXY );
+    m_serDisp.putc( MSB( wSx ));
+    m_serDisp.putc( LSB( wSx ));
+    m_serDisp.putc( nSy );
+    m_serDisp.putc( ( bFill ) ? EZ_BXF : EZ_BOX );
+    m_serDisp.putc( MSB( wEx ));
+    m_serDisp.putc( LSB( wEx ));
+    m_serDisp.putc( nEy );
+}
+
+/******************************************************************************
+//    Function Name: GdiDrawLine( wColor, wSx, nSy, wEx, nEy )
+//      Description: draw line
+//            Entry: wColor = color
+//                   wSx = starting X
+//                   nSy = starting Y
+//                   wEx = ending X
+//                   nEy = ending Y
+//             Exit: none
+// Globals modified: none
+//  Locals modified: anBuffer, nBufLen
+******************************************************************************/
+void GdiEzL4::DrawLine( U16 wColor, U16 wSx, U8 nSy, U16 wEx, U8 nEy )
+{
+    // set the color/set starting x/y
+    m_serDisp.putc( EZ_FGC );
+    m_serDisp.putc( LSB( wColor ));
+    m_serDisp.putc( MSB( wColor ));
+    m_serDisp.putc( EZ_SXY );
+    m_serDisp.putc( MSB( wSx ));
+    m_serDisp.putc( LSB( wSx ));
+    m_serDisp.putc( nSy );
+
+    // determine type of line
+    if ( wSx == wEx )
+    {
+        // vertical line
+        m_serDisp.putc( EZ_VLN );
+        m_serDisp.putc( nEy );
+    }
+    else if ( nSy == nEy )
+    {
+        // horizontal line
+        m_serDisp.putc( EZ_HLN );
+        m_serDisp.putc( MSB( wEx ));
+        m_serDisp.putc( LSB( wEx ));
+    }
+    else
+    {
+        // diagonal line
+        m_serDisp.putc( EZ_LIN );
+        m_serDisp.putc( MSB( wEx ));
+        m_serDisp.putc( LSB( wEx ));
+        m_serDisp.putc( nEy );
+    }
+}
+
+
+/******************************************************************************
+//    Function Name: GdiDrawIcon( wSx, nSy, nIcon )
+//      Description: draw an icon
+//            Entry: wSx = starting X
+//                   nSy = starting Y
+//                   nIcon = icon number
+//             Exit: none
+// Globals modified: none
+//  Locals modified: anBuffer, nBufLen
+******************************************************************************/
+void GdiEzL4::DrawIcon( U16 wSx, U8 nSy, U8 nIcon )
+{
+    // draw a icon
+    m_serDisp.putc( EZ_SXY );
+    m_serDisp.putc( MSB( wSx ));
+    m_serDisp.putc( LSB( wSx ));
+    m_serDisp.putc( nSy );
+    m_serDisp.putc( EZ_ICF );
+    m_serDisp.putc( nIcon );
+}
+
+/******************************************************************************
+//    Function Name: GdiDrawChar( wColor, nFont, wSx, nSy, bBackground, nDir, cChar )
+//      Description: draw a character with the designated font, color
+//            Entry: wColor = color
+//                   nFont = font number
+//                   wSx = starting X
+//                   nSy = starting Y
+//                   bBackground = true if drawn on background
+//                   nDir = text direction
+//                   cChar = color
+//             Exit: none
+// Globals modified: none
+//  Locals modified: anBuffer, nBufLen
+******************************************************************************/
+void GdiEzL4::DrawChar( U16 wColor, U8 nFont, U16 wSx, U8 nSy, BOOL bBackground, GDITXTDIR eDir, C8 cChar )
+{
+    // set the color/set xy/set font/draw character
+    m_serDisp.putc( EZ_FGC );
+    m_serDisp.putc( LSB( wColor ));
+    m_serDisp.putc( MSB( wColor ));
+    m_serDisp.putc( EZ_SXY );
+    m_serDisp.putc( MSB( wSx ));
+    m_serDisp.putc( LSB( wSx ));
+    m_serDisp.putc( nSy );
+    m_serDisp.putc( EZ_FNT );
+    m_serDisp.putc( nFont );
+    m_serDisp.putc( EZ_TXN + ( U8 )eDir );
+    m_serDisp.putc(( bBackground ) ? EZ_CHB : EZ_CHR );
+    m_serDisp.putc( cChar );
+}
+
+/******************************************************************************
+//    Function Name: GdiDrawString( wFgcClr, wBgcClr, nFont, wSx, nSy, bBackground, eDir, szMsg )
+//      Description: draw a string with the desinated font, color
+//            Entry: wFgClr = foreground color
+//                   wBgClr = background color
+//                   nFont = font number
+//                   wSx = starting X
+//                   nSy = starting Y
+//                   bBackground = true if drawn on background
+//                   eDir = text direction
+//                   szMsg -> pointer to zero delimited string
+//             Exit: none
+// Globals modified: none
+//  Locals modified: anBuffer, nBufLen
+******************************************************************************/
+void GdiEzL4::DrawString( U16 wFgClr, U16 wBgClr, U8 nFont, U16 wSx, U8 nSy, BOOL bBackground, GDITXTDIR eDir, PC8 pszMsg )
+{
+    // if backgound
+    if ( bBackground )
+    {
+        // set the background color
+        m_serDisp.putc( EZ_BGC );
+        m_serDisp.putc( LSB( wBgClr ));
+        m_serDisp.putc( MSB( wBgClr ));
+    }
+
+    // set color/set sx/set font/send command
+    m_serDisp.putc( EZ_FGC );
+    m_serDisp.putc( LSB( wFgClr ));
+    m_serDisp.putc( MSB( wFgClr ));
+    m_serDisp.putc( EZ_SXY );
+    m_serDisp.putc( MSB( wSx ));
+    m_serDisp.putc( LSB( wSx ));
+    m_serDisp.putc( nSy );
+    m_serDisp.putc( EZ_FNT );
+    m_serDisp.putc( nFont );
+    m_serDisp.putc( EZ_TXN + ( U8 )eDir );
+    m_serDisp.putc(( bBackground ) ? EZ_STB : EZ_STR );
+
+    // copy the string till buffer size
+    U8    nChar = 0;
+    while (( nChar = *( pszMsg++ )) != '\0' )
+        m_serDisp.putc( nChar );
+
+    // stuff the delimiter
+    m_serDisp.putc( nChar );
+}
+
+/*****************************************************************************
+//    Function Name: GdiDrawButton( nIndex, ptBtnDef )
+//      Description: draws a button
+//            Entry: nIndex = button index
+//                   ptBtnDef -> button definition structure
+//             Exit: none
+// Globals modified: none
+//  Locals modified: none
+******************************************************************************/
+void GdiEzL4::DrawButton( U8 nBtnIdx, GDIBTNDEF* ptBtnDef )
+{
+    // draw a button
+    m_serDisp.putc( EZ_BTD );
+    m_serDisp.putc( nBtnIdx );
+    m_serDisp.putc( ptBtnDef->eInitalState );
+    m_serDisp.putc( ptBtnDef->nUpIcon );
+    m_serDisp.putc( ptBtnDef->nDnIcon );
+    m_serDisp.putc( ptBtnDef->nDsIcon );
+    m_serDisp.putc( MSB( ptBtnDef->wUpLfX ));
+    m_serDisp.putc( LSB( ptBtnDef->wUpLfX ));
+    m_serDisp.putc( ptBtnDef->nUpLfY );
+    m_serDisp.putc( ptBtnDef->nTouchWidth );
+    m_serDisp.putc( ptBtnDef->nTouchHeight );
+}
+
+/*****************************************************************************
+//    Function Name: GdiRemoveAllButton( )
+//      Description: remove all button
+//            Entry: none
+//             Exit: none
+// Globals modified: none
+//  Locals modified: none
+******************************************************************************/
+void GdiEzL4::RemoveAllButtons( void )
+{
+    // send the remove all buttons command
+    m_serDisp.putc( EZ_BDL );
+}
+
+void GdiEzL4::PingDisplay( void )
+{
+    // send a ping
+    m_serDisp.putc( EZ_PNG );
+}
+
+void GdiEzL4::LocalCallback( void )
+{
+	U8	nChar;
+	
+	// call the callback
+	nChar = m_serDisp.getc( );
+	m_pvFuncCallBack.call( nChar );
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gdiezl4.h	Mon Mar 14 15:58:13 2011 +0000
@@ -0,0 +1,257 @@
+/* mbed R/C Servo Library
+ * Copyright (c) 2007-2010 sford, cstyles
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+*/
+
+// ensure only one copy
+#ifndef _GDIEZL4_H
+#define _GDIEZL4_H
+
+// include files
+#include "mbed.h"
+#include "types.h"
+#include "MODSERIAL.h"
+#include "FPointer.h"
+
+// define the RGB macro
+#define    RGB( R, G, B )    (((( R >> 3 ) & 0x1F ) << 11 ) | ((( G >> 2 ) & 0x3F ) << 5 ) | (( B >> 3 ) & 0x1F ))
+
+// define the max X/Y in landscaple mode
+#define    MAX_X_SIZE    319
+#define    MAX_Y_SIZE    233
+
+// define some standard colcors
+#define    GDI_CLR_BLK        RGB(   0,   0,   0 )
+#define    GDI_CLR_WHT        RGB( 255, 255, 255 )
+#define    GDI_CLR_BLU        RGB(   0,   0, 255 )
+#define    GDI_CLR_RED        RGB( 255,   0,   0 )
+#define    GDI_CLR_GRN        RGB(   0, 255,   0 )
+
+// define the no button icon valu
+#define GDI_BTN_NOICON  255
+
+// define the button up/down masks
+#define    GDI_BTN_DNMSK    0x40
+#define    GDI_BTN_UPMSK    0x80
+#define    GDI_BTN_VLMSK    0x3F
+
+// define the pong value
+#define    GDI_PNG_VALUE    0x38
+
+// class definition
+class GdiEzL4 
+{
+public:
+    // construction/destruction
+    /** Graphics Drawing Interface (EZLCD4 ) construction
+     *
+     * @param    pinTx = transmit pin
+     * @param    pinRx = receive pin
+     */
+    GdiEzL4( PinName pinTx, PinName pinRx );
+    ~GdiEzL4(  );
+
+// attributes
+public:
+    // enumerate the text direction-
+    enum     GDITXTDIR {
+        GDI_TXT_NORTH = 0,            // text direction north
+        GDI_TXT_EAST,                // text direction east
+        GDI_TXT_SOUTH,                // text direction south
+        GDI_TXT_WEST                // text direction west
+    };
+
+    // enumerate the button state
+    enum    GDIBTNSTATE {
+        GDI_BTN_UP = 1,                // button up
+        GDI_BTN_DN,                    // button down
+        GDI_BTN_DSB,                // button disabled
+        GDI_BTN_NVS                // button non-visible
+    };
+
+    // define the button parameters
+    struct    GDIBTNDEF {
+        GDIBTNSTATE    eInitalState;    // initial state
+        U8            nUpIcon;        // up icon index
+        U8            nDnIcon;        // down icon index
+        U8            nDsIcon;        // disabled icon index
+        U16            wUpLfX;            // upper left X
+        U8            nUpLfY;            // upper left Y
+        U8            nTouchWidth;    // touch width
+        U8            nTouchHeight;    // touch height
+    };
+
+private:
+    MODSERIAL    m_serDisp;
+    FPointer    m_pvFuncCallBack;    
+    
+// local functions    
+    void        LocalCallback( void );
+
+    // enumerate the LCD commands
+    enum COMMANDS {
+        EZ_CLS = 0x21,        // 0x21 - clear screen
+        EZ_LON,                // 0x22 - backlight on
+        EZ_LOF,                // 0x23 - backlight off
+        EZ_PLT = 0x26,        // 0x26 - plot a pixel
+        EZ_PIC = 0x2A,        // 0x2A - draw a picture
+        EZ_FNT,                // 0x2B - select the font
+        EZ_CHR,                // 0x2C - draw a character
+        EZ_STR,                // 0x2D - draw a string
+        EZ_SPS = 0x35,        // 0x35 - store position
+        EZ_RPS,                // 0x36 - restore position
+        EZ_CHB = 0x3C,        // 0x3C - draw character on the background
+        EZ_STB,                // 0x3D - draw a string on the background
+        EZ_VLN = 0x41,        // 0x41 - draw a vertical line
+        EZ_ICF = 0x58,        // 0x58 - draw an icon from serial flash
+        EZ_STY = 0x5F,        // 0x5F - set y position
+        EZ_TXN = 0x60,        // 0x60 - set text direction to north
+        EZ_TXE,                // 0x61 - set text direction to east
+        EZ_TXS,                // 0x62 - set text direction to south
+        EZ_TXW,                // 0x63 - set text direction to west
+        EZ_STX = 0x6E,        // 0x6E - set X position
+        EZ_BKL = 0x80,        // 0x80 - brightness
+        EZ_PNG = 0x83,        // 0x83 - ping the unit
+        EZ_FGC,                // 0x84 - set foreground color
+        EZ_SXY,                // 0x85 - set X/y position
+        EZ_PXY = 0x87,        // 0x87 - plot a pixel at x,y
+        EZ_LIN,                // 0x88 - draw a line
+        EZ_CIR,                // 0x89 - draw a circle
+        EZ_ARC = 0x8F,        // 0x8F - draw an arc
+        EZ_PIE,                // 0x90 - draw a pie
+        EZ_BGC = 0x94,        // 0x94 - set background color
+        EZ_CRF = 0x99,        // 0x99    - draw a filled circle
+        EZ_BMP = 0x9E,        // 0x9E - draw a bitmap
+        EZ_HLN = 0xA0,        // 0xA0 - draw a horizontal line
+        EZ_BOX = 0xA2,        // 0xA2 - draw a box
+        EZ_BXF,                // 0xA3 - draw a filled box
+        EZ_BTD = 0xB0,        // 0xB0 - define a touch button
+        EZ_BTS,                // 0xB1 - changes a button state
+        EZ_BTP,                // 0xB2 - sets the button protocol
+        EZ_BUP,                // 0xB3 - all buttons up
+        EZ_BDL,                // 0xB4 - delete all buttons
+        EZ_BOF = 0xD0,        // 0xD0 - buzzer off
+        EZ_BON,                // 0xD1 - buzzer on
+        EZ_BEE                 // 0xD2 - beep the buzzer for some time
+    };
+
+public:
+    // implementation
+    /** backlight ontrol
+     *
+     * @param    bOffOn = state of the backlight
+     */
+    void    BacklightCtl( BOOL bOffOn );
+
+    /** clear the screen
+     *
+     * @param    wColor = background color
+     */
+    void    ClearScreen( U16 wColor );
+
+    /** Draw a rectangle
+     *
+     * @param    wColor = color of the rectangle
+     * @param    wSx    = starting X location ( top left )
+     * @param    nSy = starting Y location ( top left )
+     * @param    wWidth = width of the rectangle
+     * @param    nHeight = height of the rectangle
+      * @param    bFill = TRUE if rectangle is filled
+     */
+    void    DrawRect( U16 wColor, U16 wSx, U8 nSy, U16 wWidth, U8 nHeight, BOOL fFill );
+
+    /** Draw a line
+     *
+     * @param    wColor = color of the line
+     * @param    wSx    = starting X location ( top left )
+     * @param    nSy = starting Y location ( top left )
+     * @param    wEx = ending X location ( bottom right )
+     * @param    nEy = ending Y location ( bottom right )
+     */
+    void    DrawLine( U16 wColor, U16 wSx, U8 nSy, U16 wEx, U8 nEy );
+
+    /** Draw an Icon 
+     *
+     * @param    wSx    = starting X location ( top left )
+     * @param    nSy = starting Y location ( top left )
+     * @param    nIcon = icon index
+     */
+    void    DrawIcon( U16 wSx, U8 nSy, U8 nIcon );
+
+    /** Draw a character
+     *
+     * @param    wColor = color of the character
+     * @param    nFont = font index
+     * @param    wSx    = starting X location ( top left )
+     * @param    nSy = starting Y location ( top left )
+     * @param    bBackground = display as inverted background
+     * @param    eDir = text direction
+      * @param    cChar = character to draw
+     */
+    void    DrawChar( U16 wColor, U8 nFont, U16 wSx, U8 nSy, BOOL bBackground, GDITXTDIR eDir, C8 cChar );
+
+    /** draw a string
+     *
+     * @param    wColor = color of the character
+     * @param    nFont = font index
+     * @param    wSx    = starting X location ( top left )
+     * @param    nSy = starting Y location ( top left )
+     * @param    bBackground = display as inverted background
+     * @param    eDir = text direction
+      * @param    pszMsg = pointer to the message
+     */
+    void    DrawString( U16 wFgClr, U16 wBgClr, U8 nFont, U16 wSx, U8 nSy, BOOL bBackground, GDITXTDIR eDir, PC8 pszMsg );
+
+    /** backlight ontrol
+     *
+     * @param    nBtnIdx = button index
+     * @param    ptBugDef -> pointer to the button definition structure
+     */
+    void    DrawButton( U8 nBtnIdx, GDIBTNDEF* ptButDef );
+
+    /** backlight ontrol
+     *
+     * @param    bOffOn = state of the backlight
+     */
+    void    RemoveAllButtons( void );
+
+    /** backlight ontrol
+     *
+     * @param    bOffOn = state of the backlight
+     */
+    void    PingDisplay( void );
+
+    /** backlight ontrol
+     *
+     * @param    bOffOn = state of the backlight
+     */
+    void     attach( uint32_t (*function)(uint32_t) = 0) { m_pvFuncCallBack.attach(function); }
+
+    /** backlight ontrol
+     *
+     * @param    bOffOn = state of the backlight
+     */
+    template<class T> 
+    void     attach(T* item, uint32_t (T::*method)(uint32_t)) { m_pvFuncCallBack.attach(item, method); }    
+};
+
+
+#endif
+