A demonstration of how to drive the onboard LEDS on the LPC1768 via a 4.3 inch touch-screen display from 4D Systems

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_genie.h Source File

mbed_genie.h

00001 #undef  GENIE_DEBUG
00002 
00003 #define GENIE_VERSION   "GenieMbed 17-Nov-2013"
00004 
00005 // Genie commands & replys:
00006 
00007 #define GENIE_ACK       0x06
00008 #define GENIE_NAK       0x15
00009 
00010 #define TIMEOUT_PERIOD  500
00011 #define RESYNC_PERIOD   100
00012 
00013 #define GENIE_READ_OBJ          0
00014 #define GENIE_WRITE_OBJ         1
00015 #define GENIE_WRITE_STR         2
00016 #define GENIE_WRITE_STRU        3
00017 #define GENIE_WRITE_CONTRAST    4
00018 #define GENIE_REPORT_OBJ        5
00019 #define GENIE_REPORT_EVENT      7
00020 
00021 // Objects
00022 //  the manual says:
00023 //      Note: Object IDs may change with future releases; it is not
00024 //      advisable to code their values as constants.
00025 
00026 #define GENIE_OBJ_DIPSW         0
00027 #define GENIE_OBJ_KNOB          1
00028 #define GENIE_OBJ_ROCKERSW      2
00029 #define GENIE_OBJ_ROTARYSW      3
00030 #define GENIE_OBJ_SLIDER        4
00031 #define GENIE_OBJ_TRACKBAR      5
00032 #define GENIE_OBJ_WINBUTTON     6
00033 #define GENIE_OBJ_ANGULAR_METER 7
00034 #define GENIE_OBJ_COOL_GAUGE    8
00035 #define GENIE_OBJ_CUSTOM_DIGITS 9
00036 #define GENIE_OBJ_FORM          10
00037 #define GENIE_OBJ_GAUGE         11
00038 #define GENIE_OBJ_IMAGE         12
00039 #define GENIE_OBJ_KEYBOARD      13
00040 #define GENIE_OBJ_LED           14
00041 #define GENIE_OBJ_LED_DIGITS    15
00042 #define GENIE_OBJ_METER         16
00043 #define GENIE_OBJ_STRINGS       17
00044 #define GENIE_OBJ_THERMOMETER   18
00045 #define GENIE_OBJ_USER_LED      19
00046 #define GENIE_OBJ_VIDEO         20
00047 #define GENIE_OBJ_STATIC_TEXT   21
00048 #define GENIE_OBJ_SOUND         22
00049 #define GENIE_OBJ_TIMER         23
00050 #define GENIE_OBJ_SPECTRUM      24
00051 #define GENIE_OBJ_SCOPE         25
00052 #define GENIE_OBJ_TANK          26
00053 #define GENIE_OBJ_USERIMAGES    27
00054 #define GENIE_OBJ_PINOUTPUT     28
00055 #define GENIE_OBJ_PININPUT      29
00056 #define GENIE_OBJ_4DBUTTON      30
00057 #define GENIE_OBJ_ANIBUTTON     31
00058 #define GENIE_OBJ_COLORPICKER   32
00059 #define GENIE_OBJ_USERBUTTON    33
00060 
00061 // Structure to store replys returned from a display
00062 
00063 #define     GENIE_FRAME_SIZE    6
00064 struct genieFrameReportObj {
00065     uint8_t     cmd;
00066     uint8_t     object;
00067     uint8_t     index;
00068     uint8_t     data_msb;
00069     uint8_t     data_lsb;
00070 };
00071  
00072 /////////////////////////////////////////////////////////////////////
00073 // The Genie frame definition
00074 //
00075 // The union allows the data to be referenced as an array of uint8_t
00076 // or a structure of type genieFrameReportObj, eg
00077 //
00078 //  genieFrame f;
00079 //  f.bytes[4];
00080 //  f.reportObject.data_lsb
00081 //
00082 //  both methods get the same byte
00083 //
00084 union genieFrame {
00085     uint8_t             bytes[GENIE_FRAME_SIZE];
00086     genieFrameReportObj reportObject;
00087 };
00088 
00089 #define MAX_GENIE_EVENTS    16  // MUST be a power of 2
00090 #define MAX_GENIE_FATALS    10
00091 
00092 struct genieEventQueueStruct {
00093     genieFrame  frames[MAX_GENIE_EVENTS];
00094     uint8_t     rd_index;
00095     uint8_t     wr_index;
00096     uint8_t     n_events;
00097 };
00098 
00099 typedef void        (*geniePutCharFuncPtr)      (uint8_t c, uint32_t baud);
00100 typedef uint16_t    (*genieGetCharFuncPtr)      (void);
00101 typedef void        (*genieUserEventHandlerPtr) (void);
00102 
00103 #define ERROR_NONE          0
00104 #define ERROR_TIMEOUT       -1  // 255  0xFF
00105 #define ERROR_NOHANDLER     -2  // 254  0xFE
00106 #define ERROR_NOCHAR        -3  // 253  0xFD
00107 #define ERROR_NAK           -4  // 252  0xFC
00108 #define ERROR_REPLY_OVR     -5  // 251  0xFB
00109 #define ERROR_RESYNC        -6  // 250  0xFA
00110 #define ERROR_NODISPLAY     -7  // 249  0xF9
00111 #define ERROR_BAD_CS        -8  // 248  0xF8
00112 
00113 #define GENIE_LINK_IDLE         0
00114 #define GENIE_LINK_WFAN         1 // waiting for Ack or Nak
00115 #define GENIE_LINK_WF_RXREPORT  2 // waiting for a report frame
00116 #define GENIE_LINK_RXREPORT     3 // receiving a report frame
00117 #define GENIE_LINK_RXEVENT      4 // receiving an event frame
00118 #define GENIE_LINK_SHDN         5
00119 
00120 #define GENIE_EVENT_NONE    0
00121 #define GENIE_EVENT_RXCHAR  1
00122 
00123 #ifndef        TRUE
00124 #define        TRUE        (1==1)
00125 #define        FALSE        (!TRUE)
00126 #endif
00127 
00128 void            SetupGenie(void);
00129 void            genieAttachEventHandler     (genieUserEventHandlerPtr handler);
00130 extern bool     genieDequeueEvent           (genieFrame * buff);
00131 extern bool     genieEventIs                (genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index);
00132 extern uint16_t genieGetEventData           (genieFrame * e); 
00133 extern uint16_t genieWriteObject            (uint16_t object, uint16_t index, uint16_t data);
00134 extern uint16_t        genieWriteStr                        (uint16_t index, char *string);
00135 extern void                genieWriteContrast                (uint16_t value);
00136