Mbed 4dGenie class

Dependents:   Genie_Test 039847382-S3_DS1621_and_LCD_V1

This is a work in progress.

4dGenie class to use with 4dLCD screens that are using the genie environment.

There are still some rare occasions where the 4dLCD might crash, for now i have no solution to this except doing a reset of the 4dLCD.

Please make sure to have the most up to date PmmC loaded on the screen.

usage example :

Mbed4dGenie test program

#include "mbed.h"
#include "mbed_genie.h"

DigitalOut myled(LED1);
/*
    The Mbed4dGenie class requires 3 parameters
    1 - Tx pin
    2 - Rx pin
    3 - Reset pin
*/
Mbed4dGenie lcd4d(PTE0,PTE1,PTB9);



int main() {
    int temp = 0;
printf("Mbed Genie demo \n\r");
lcd4d.Start();


 /*
 for example, in this loop we increment the thermometer0 object from 0 to 100
 */
 
    while(1) {
        if(temp >= 100)
        {
            temp = -1;
        }
        else
        {
            temp++;
        }

        lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,1,temp);

        myled = 1;
        wait(0.05);
        myled = 0;
        wait(0.05);
    }
}
Revision:
6:f4d3977b0eae
Parent:
3:11c49c49cd1a
Child:
7:6edb20845684
--- a/mbed_genie.h	Sun Feb 23 17:32:37 2014 +0000
+++ b/mbed_genie.h	Fri Jul 04 02:44:49 2014 +0000
@@ -1,7 +1,3 @@
-#undef  GENIE_DEBUG
-
-#define GENIE_VERSION   "GenieMbed 17-Nov-2013"
-
 // Genie commands & replys:
 
 #define GENIE_ACK       0x06
@@ -61,44 +57,6 @@
 // Structure to store replys returned from a display
 
 #define     GENIE_FRAME_SIZE    6
-struct genieFrameReportObj {
-    uint8_t     cmd;
-    uint8_t     object;
-    uint8_t     index;
-    uint8_t     data_msb;
-    uint8_t     data_lsb;
-};
- 
-/////////////////////////////////////////////////////////////////////
-// The Genie frame definition
-//
-// The union allows the data to be referenced as an array of uint8_t
-// or a structure of type genieFrameReportObj, eg
-//
-//  genieFrame f;
-//  f.bytes[4];
-//  f.reportObject.data_lsb
-//
-//  both methods get the same byte
-//
-union genieFrame {
-    uint8_t             bytes[GENIE_FRAME_SIZE];
-    genieFrameReportObj reportObject;
-};
-
-#define MAX_GENIE_EVENTS    16  // MUST be a power of 2
-#define MAX_GENIE_FATALS    10
-
-struct genieEventQueueStruct {
-    genieFrame  frames[MAX_GENIE_EVENTS];
-    uint8_t     rd_index;
-    uint8_t     wr_index;
-    uint8_t     n_events;
-};
-
-typedef void        (*geniePutCharFuncPtr)      (uint8_t c, uint32_t baud);
-typedef uint16_t    (*genieGetCharFuncPtr)      (void);
-typedef void        (*genieUserEventHandlerPtr) (void);
 
 #define ERROR_NONE          0
 #define ERROR_TIMEOUT       -1  // 255  0xFF
@@ -125,72 +83,35 @@
 #define        FALSE        (!TRUE)
 #endif
 
-void            SetupGenie(void);
-void            genieAttachEventHandler     (genieUserEventHandlerPtr handler);
-extern bool     genieDequeueEvent           (genieFrame * buff);
-extern bool     genieEventIs                (genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index);
-extern uint16_t genieGetEventData           (genieFrame * e); 
-extern uint16_t genieWriteObject            (uint16_t object, uint16_t index, uint16_t data);
-extern uint16_t genieWriteStr               (uint16_t index, char *string);
-extern void     genieWriteContrast          (uint16_t value);
-
 class Mbed4dGenie{
     public:
+    /*
+        Constructor to initialise the pins used to control the lcd screen
+        Note: When the class is first initialised, the lcd screen will be put
+        in reset and kept reset until Start() is called
+    */
     Mbed4dGenie(PinName TxPin,PinName RxPin, PinName resetpin);
-    void genieAttachEventHandler (genieUserEventHandlerPtr handler);   
-    uint16_t genieWriteStrU (uint16_t index, char *string);
-    uint16_t genieWriteStr (uint16_t index, char *string);   
-    void genieWriteContrast (uint16_t value);
-    uint16_t genieWriteObject (uint16_t object, uint16_t index, uint16_t data);   
-    bool genieDequeueEvent(genieFrame * buff);
-    uint16_t genieGetEventData (genieFrame * e);
-    bool genieEventIs(genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index);   
-    bool GenieReadable(void);
-    uint16_t genieDoEvents (void);
+    /*
+        Deassert the reset pin and give some time to the lcd to 
+        initialise itself before sending any commands.
+    */
+    void Start();
+    /*
+        Generic command to write data to a Genie object
+        returns the status code of operation
+    */
+    int8_t genieWriteObject (uint16_t object, uint16_t index, uint16_t data); 
     
-    private:
-    void RxIrqHandler(void);
-    uint8_t _genieGetchar(void);
-    void _geniePutchar (uint8_t c);
-    uint16_t _genieGetLinkState (void);
-    void _genieSetLinkState (uint16_t newstate);
-    bool _genieEnqueueEvent (uint8_t * data);
-    int _genieWriteStrX (uint16_t code, uint16_t index, char *string);
-    void _genieWaitForIdle (void);
-    void _geniePushLinkState (uint8_t newstate);
-    void _geniePopLinkState (void);
-    void _genieFlushSerialInput(void);
-    void _handleError (void);
-    void _genieFlushEventQueue(void);
-       
+    private:    
+    /*
+        Wait for the screen to aknowledge the command
+        returns the status code of operation
+    */
+    int8_t WaitForAnswer();
+    
+    
+    
     Serial _screen;
+    DigitalOut _reset;
     Timer _t;
-    DigitalOut _reset;
-    //////////////////////////////////////////////////////////////
-    // Pointer to the user's event handler function
-    //
-    genieUserEventHandlerPtr _genieUserHandler;
-    //////////////////////////////////////////////////////////////
-    // A structure to hold up to MAX_GENIE_EVENTS events receive
-    // from the display
-    //
-    genieEventQueueStruct _genieEventQueue;
-    //////////////////////////////////////////////////////////////
-    // Simple 5-deep stack for the link state, this allows 
-    // genieDoEvents() to save the current state, receive a frame,
-    // then restore the state
-    //
-    uint8_t _genieLinkStates[5];
-    //
-    // Stack pointer
-    //
-    uint8_t     *_genieLinkState;
-    //////////////////////////////////////////////////////////////
-    // Number of mS the genieGetChar() function will wait before
-    // giving up on the display
-    int _genieTimeout;
-    //////////////////////////////////////////////////////////////
-    // Global error variable
-    int _genieError;
-    uint8_t rxframe_count;
-    };
+    };
\ No newline at end of file