4D display working with Gecko board STK3600

Dependents:   Genie_mbed_Gecko

Fork of 4dGENIE by christian b

Revision:
7:6edb20845684
Parent:
6:f4d3977b0eae
Child:
8:b5ba0df2d0db
--- a/mbed_genie.h	Fri Jul 04 02:44:49 2014 +0000
+++ b/mbed_genie.h	Sat Jul 05 15:11:57 2014 +0000
@@ -1,3 +1,5 @@
+
+
 // Genie commands & replys:
 
 #define GENIE_ACK       0x06
@@ -83,8 +85,51 @@
 #define        FALSE        (!TRUE)
 #endif
 
+#define NO_RESPONSE     0
+
+#define     GENIE_FRAME_SIZE    6
+// Structure to store replys returned from a display
+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
+struct genieEventQueueStruct {
+    genieFrame  frames[MAX_GENIE_EVENTS];
+    uint8_t     rd_index;
+    uint8_t     wr_index;
+    uint8_t     n_events;
+};
+ 
+typedef void        (*genieUserEventHandlerPtr) (void); 
+
 class Mbed4dGenie{
     public:
+    
+    typedef enum{
+        CommIdle = 0,
+        CommInProgress = 1
+        }CommState;
+    
     /*
         Constructor to initialise the pins used to control the lcd screen
         Note: When the class is first initialised, the lcd screen will be put
@@ -95,23 +140,49 @@
         Deassert the reset pin and give some time to the lcd to 
         initialise itself before sending any commands.
     */
-    void Start();
+    void    Start();
+    void    Reset(void);
     /*
         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); 
+    int8_t  genieWriteObject (uint16_t object, uint16_t index, uint16_t data); 
+    int8_t  genieWriteStr (uint16_t index, char *string);
+    int8_t  genieReadObj (uint16_t object, uint16_t index);
+      
+    bool    genieDequeueEvent(genieFrame * buff);
+    void    genieAttachEventHandler (genieUserEventHandlerPtr handler);
+    bool    PendingFrames(void);
     
-    private:    
+    private:   
+    void    writec(char data); 
+    void    RxIrqHandler(void);
+    void    ManageReceiveData(char data);
+    bool    _genieEnqueueEvent (uint8_t * data);
+    void    _genieFlushEventQueue(void);
     /*
         Wait for the screen to aknowledge the command
         returns the status code of operation
     */
-    int8_t WaitForAnswer();
+    int8_t  WaitForAnswer();
+    bool    WaitForIdle();   
     
-    
+    //////////////////////////////////////////////////////////////
+    // A structure to hold up to MAX_GENIE_EVENTS events receive
+    // from the display
+    //
+    genieEventQueueStruct _genieEventQueue;
+    uint8_t     rxframe_count;
+    uint8_t     rx_data[GENIE_FRAME_SIZE];
+    uint8_t     checksum;
+    //////////////////////////////////////////////////////////////
+    // Pointer to the user's event handler function
+    //
+    genieUserEventHandlerPtr _genieUserHandler;
     
     Serial _screen;
     DigitalOut _reset;
     Timer _t;
+    int             state; 
+    int            LastResponse; 
     };
\ No newline at end of file