4D display working with Gecko board STK3600

Dependents:   Genie_mbed_Gecko

Fork of 4dGENIE by christian b

Committer:
chris215
Date:
Sun Feb 23 01:34:05 2014 +0000
Revision:
2:f283764fe9b7
Parent:
1:95e0e194a412
Child:
3:11c49c49cd1a
Completed conversion to a class (untested)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris215 0:d2ed5a44c802 1 #undef GENIE_DEBUG
chris215 0:d2ed5a44c802 2
chris215 0:d2ed5a44c802 3 #define GENIE_VERSION "GenieMbed 17-Nov-2013"
chris215 0:d2ed5a44c802 4
chris215 0:d2ed5a44c802 5 // Genie commands & replys:
chris215 0:d2ed5a44c802 6
chris215 0:d2ed5a44c802 7 #define GENIE_ACK 0x06
chris215 0:d2ed5a44c802 8 #define GENIE_NAK 0x15
chris215 0:d2ed5a44c802 9
chris215 0:d2ed5a44c802 10 #define TIMEOUT_PERIOD 500
chris215 0:d2ed5a44c802 11 #define RESYNC_PERIOD 100
chris215 0:d2ed5a44c802 12
chris215 0:d2ed5a44c802 13 #define GENIE_READ_OBJ 0
chris215 0:d2ed5a44c802 14 #define GENIE_WRITE_OBJ 1
chris215 0:d2ed5a44c802 15 #define GENIE_WRITE_STR 2
chris215 0:d2ed5a44c802 16 #define GENIE_WRITE_STRU 3
chris215 0:d2ed5a44c802 17 #define GENIE_WRITE_CONTRAST 4
chris215 0:d2ed5a44c802 18 #define GENIE_REPORT_OBJ 5
chris215 0:d2ed5a44c802 19 #define GENIE_REPORT_EVENT 7
chris215 0:d2ed5a44c802 20
chris215 0:d2ed5a44c802 21 // Objects
chris215 0:d2ed5a44c802 22 // the manual says:
chris215 0:d2ed5a44c802 23 // Note: Object IDs may change with future releases; it is not
chris215 0:d2ed5a44c802 24 // advisable to code their values as constants.
chris215 0:d2ed5a44c802 25
chris215 0:d2ed5a44c802 26 #define GENIE_OBJ_DIPSW 0
chris215 0:d2ed5a44c802 27 #define GENIE_OBJ_KNOB 1
chris215 0:d2ed5a44c802 28 #define GENIE_OBJ_ROCKERSW 2
chris215 0:d2ed5a44c802 29 #define GENIE_OBJ_ROTARYSW 3
chris215 0:d2ed5a44c802 30 #define GENIE_OBJ_SLIDER 4
chris215 0:d2ed5a44c802 31 #define GENIE_OBJ_TRACKBAR 5
chris215 0:d2ed5a44c802 32 #define GENIE_OBJ_WINBUTTON 6
chris215 0:d2ed5a44c802 33 #define GENIE_OBJ_ANGULAR_METER 7
chris215 0:d2ed5a44c802 34 #define GENIE_OBJ_COOL_GAUGE 8
chris215 0:d2ed5a44c802 35 #define GENIE_OBJ_CUSTOM_DIGITS 9
chris215 0:d2ed5a44c802 36 #define GENIE_OBJ_FORM 10
chris215 0:d2ed5a44c802 37 #define GENIE_OBJ_GAUGE 11
chris215 0:d2ed5a44c802 38 #define GENIE_OBJ_IMAGE 12
chris215 0:d2ed5a44c802 39 #define GENIE_OBJ_KEYBOARD 13
chris215 0:d2ed5a44c802 40 #define GENIE_OBJ_LED 14
chris215 0:d2ed5a44c802 41 #define GENIE_OBJ_LED_DIGITS 15
chris215 0:d2ed5a44c802 42 #define GENIE_OBJ_METER 16
chris215 0:d2ed5a44c802 43 #define GENIE_OBJ_STRINGS 17
chris215 0:d2ed5a44c802 44 #define GENIE_OBJ_THERMOMETER 18
chris215 0:d2ed5a44c802 45 #define GENIE_OBJ_USER_LED 19
chris215 0:d2ed5a44c802 46 #define GENIE_OBJ_VIDEO 20
chris215 0:d2ed5a44c802 47 #define GENIE_OBJ_STATIC_TEXT 21
chris215 0:d2ed5a44c802 48 #define GENIE_OBJ_SOUND 22
chris215 0:d2ed5a44c802 49 #define GENIE_OBJ_TIMER 23
chris215 0:d2ed5a44c802 50 #define GENIE_OBJ_SPECTRUM 24
chris215 0:d2ed5a44c802 51 #define GENIE_OBJ_SCOPE 25
chris215 0:d2ed5a44c802 52 #define GENIE_OBJ_TANK 26
chris215 0:d2ed5a44c802 53 #define GENIE_OBJ_USERIMAGES 27
chris215 0:d2ed5a44c802 54 #define GENIE_OBJ_PINOUTPUT 28
chris215 0:d2ed5a44c802 55 #define GENIE_OBJ_PININPUT 29
chris215 0:d2ed5a44c802 56 #define GENIE_OBJ_4DBUTTON 30
chris215 0:d2ed5a44c802 57 #define GENIE_OBJ_ANIBUTTON 31
chris215 0:d2ed5a44c802 58 #define GENIE_OBJ_COLORPICKER 32
chris215 0:d2ed5a44c802 59 #define GENIE_OBJ_USERBUTTON 33
chris215 0:d2ed5a44c802 60
chris215 0:d2ed5a44c802 61 // Structure to store replys returned from a display
chris215 0:d2ed5a44c802 62
chris215 0:d2ed5a44c802 63 #define GENIE_FRAME_SIZE 6
chris215 0:d2ed5a44c802 64 struct genieFrameReportObj {
chris215 0:d2ed5a44c802 65 uint8_t cmd;
chris215 0:d2ed5a44c802 66 uint8_t object;
chris215 0:d2ed5a44c802 67 uint8_t index;
chris215 0:d2ed5a44c802 68 uint8_t data_msb;
chris215 0:d2ed5a44c802 69 uint8_t data_lsb;
chris215 0:d2ed5a44c802 70 };
chris215 0:d2ed5a44c802 71
chris215 0:d2ed5a44c802 72 /////////////////////////////////////////////////////////////////////
chris215 0:d2ed5a44c802 73 // The Genie frame definition
chris215 0:d2ed5a44c802 74 //
chris215 0:d2ed5a44c802 75 // The union allows the data to be referenced as an array of uint8_t
chris215 0:d2ed5a44c802 76 // or a structure of type genieFrameReportObj, eg
chris215 0:d2ed5a44c802 77 //
chris215 0:d2ed5a44c802 78 // genieFrame f;
chris215 0:d2ed5a44c802 79 // f.bytes[4];
chris215 0:d2ed5a44c802 80 // f.reportObject.data_lsb
chris215 0:d2ed5a44c802 81 //
chris215 0:d2ed5a44c802 82 // both methods get the same byte
chris215 0:d2ed5a44c802 83 //
chris215 0:d2ed5a44c802 84 union genieFrame {
chris215 0:d2ed5a44c802 85 uint8_t bytes[GENIE_FRAME_SIZE];
chris215 0:d2ed5a44c802 86 genieFrameReportObj reportObject;
chris215 0:d2ed5a44c802 87 };
chris215 0:d2ed5a44c802 88
chris215 0:d2ed5a44c802 89 #define MAX_GENIE_EVENTS 16 // MUST be a power of 2
chris215 0:d2ed5a44c802 90 #define MAX_GENIE_FATALS 10
chris215 0:d2ed5a44c802 91
chris215 0:d2ed5a44c802 92 struct genieEventQueueStruct {
chris215 0:d2ed5a44c802 93 genieFrame frames[MAX_GENIE_EVENTS];
chris215 0:d2ed5a44c802 94 uint8_t rd_index;
chris215 0:d2ed5a44c802 95 uint8_t wr_index;
chris215 0:d2ed5a44c802 96 uint8_t n_events;
chris215 0:d2ed5a44c802 97 };
chris215 0:d2ed5a44c802 98
chris215 0:d2ed5a44c802 99 typedef void (*geniePutCharFuncPtr) (uint8_t c, uint32_t baud);
chris215 0:d2ed5a44c802 100 typedef uint16_t (*genieGetCharFuncPtr) (void);
chris215 0:d2ed5a44c802 101 typedef void (*genieUserEventHandlerPtr) (void);
chris215 0:d2ed5a44c802 102
chris215 0:d2ed5a44c802 103 #define ERROR_NONE 0
chris215 0:d2ed5a44c802 104 #define ERROR_TIMEOUT -1 // 255 0xFF
chris215 0:d2ed5a44c802 105 #define ERROR_NOHANDLER -2 // 254 0xFE
chris215 0:d2ed5a44c802 106 #define ERROR_NOCHAR -3 // 253 0xFD
chris215 0:d2ed5a44c802 107 #define ERROR_NAK -4 // 252 0xFC
chris215 0:d2ed5a44c802 108 #define ERROR_REPLY_OVR -5 // 251 0xFB
chris215 0:d2ed5a44c802 109 #define ERROR_RESYNC -6 // 250 0xFA
chris215 0:d2ed5a44c802 110 #define ERROR_NODISPLAY -7 // 249 0xF9
chris215 0:d2ed5a44c802 111 #define ERROR_BAD_CS -8 // 248 0xF8
chris215 0:d2ed5a44c802 112
chris215 0:d2ed5a44c802 113 #define GENIE_LINK_IDLE 0
chris215 0:d2ed5a44c802 114 #define GENIE_LINK_WFAN 1 // waiting for Ack or Nak
chris215 0:d2ed5a44c802 115 #define GENIE_LINK_WF_RXREPORT 2 // waiting for a report frame
chris215 0:d2ed5a44c802 116 #define GENIE_LINK_RXREPORT 3 // receiving a report frame
chris215 0:d2ed5a44c802 117 #define GENIE_LINK_RXEVENT 4 // receiving an event frame
chris215 0:d2ed5a44c802 118 #define GENIE_LINK_SHDN 5
chris215 0:d2ed5a44c802 119
chris215 0:d2ed5a44c802 120 #define GENIE_EVENT_NONE 0
chris215 0:d2ed5a44c802 121 #define GENIE_EVENT_RXCHAR 1
chris215 0:d2ed5a44c802 122
chris215 0:d2ed5a44c802 123 #ifndef TRUE
chris215 0:d2ed5a44c802 124 #define TRUE (1==1)
chris215 0:d2ed5a44c802 125 #define FALSE (!TRUE)
chris215 0:d2ed5a44c802 126 #endif
chris215 0:d2ed5a44c802 127
chris215 0:d2ed5a44c802 128 void SetupGenie(void);
chris215 0:d2ed5a44c802 129 void genieAttachEventHandler (genieUserEventHandlerPtr handler);
chris215 0:d2ed5a44c802 130 extern bool genieDequeueEvent (genieFrame * buff);
chris215 0:d2ed5a44c802 131 extern bool genieEventIs (genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index);
chris215 0:d2ed5a44c802 132 extern uint16_t genieGetEventData (genieFrame * e);
chris215 0:d2ed5a44c802 133 extern uint16_t genieWriteObject (uint16_t object, uint16_t index, uint16_t data);
chris215 1:95e0e194a412 134 extern uint16_t genieWriteStr (uint16_t index, char *string);
chris215 1:95e0e194a412 135 extern void genieWriteContrast (uint16_t value);
chris215 0:d2ed5a44c802 136
chris215 2:f283764fe9b7 137 class Mbed4dGenie{
chris215 2:f283764fe9b7 138 public:
chris215 2:f283764fe9b7 139 Mbed4dGenie(PinName TxPin,PinName RxPin);
chris215 2:f283764fe9b7 140 void genieAttachEventHandler (genieUserEventHandlerPtr handler);
chris215 2:f283764fe9b7 141
chris215 2:f283764fe9b7 142 uint8_t _genieGetchar(void);
chris215 2:f283764fe9b7 143 void _geniePutchar (uint8_t c);
chris215 2:f283764fe9b7 144 uint16_t _genieGetLinkState (void);
chris215 2:f283764fe9b7 145 void _genieSetLinkState (uint16_t newstate);
chris215 2:f283764fe9b7 146 bool _genieEnqueueEvent (uint8_t * data);
chris215 2:f283764fe9b7 147 uint16_t genieWriteStrU (uint16_t index, char *string);
chris215 2:f283764fe9b7 148 uint16_t genieWriteStr (uint16_t index, char *string);
chris215 2:f283764fe9b7 149 int _genieWriteStrX (uint16_t code, uint16_t index, char *string);
chris215 2:f283764fe9b7 150 void genieWriteContrast (uint16_t value);
chris215 2:f283764fe9b7 151 uint16_t genieWriteObject (uint16_t object, uint16_t index, uint16_t data);
chris215 2:f283764fe9b7 152 void _genieWaitForIdle (void);
chris215 2:f283764fe9b7 153 bool genieDequeueEvent(genieFrame * buff);
chris215 2:f283764fe9b7 154 uint16_t genieGetEventData (genieFrame * e);
chris215 2:f283764fe9b7 155 bool genieEventIs(genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index);
chris215 2:f283764fe9b7 156 void _geniePushLinkState (uint8_t newstate);
chris215 2:f283764fe9b7 157 void _geniePopLinkState (void);
chris215 2:f283764fe9b7 158 void _genieFlushSerialInput(void);
chris215 2:f283764fe9b7 159 void _handleError (void);
chris215 2:f283764fe9b7 160 void _genieFlushEventQueue(void);
chris215 2:f283764fe9b7 161 bool GenieReadable(void);
chris215 2:f283764fe9b7 162 uint16_t genieDoEvents (void);
chris215 2:f283764fe9b7 163
chris215 2:f283764fe9b7 164 private:
chris215 2:f283764fe9b7 165 void RxIrqHandler(void);
chris215 2:f283764fe9b7 166 Serial _screen;
chris215 2:f283764fe9b7 167 Timer _t;
chris215 2:f283764fe9b7 168 //////////////////////////////////////////////////////////////
chris215 2:f283764fe9b7 169 // Pointer to the user's event handler function
chris215 2:f283764fe9b7 170 //
chris215 2:f283764fe9b7 171 genieUserEventHandlerPtr _genieUserHandler;
chris215 2:f283764fe9b7 172 //////////////////////////////////////////////////////////////
chris215 2:f283764fe9b7 173 // A structure to hold up to MAX_GENIE_EVENTS events receive
chris215 2:f283764fe9b7 174 // from the display
chris215 2:f283764fe9b7 175 //
chris215 2:f283764fe9b7 176 genieEventQueueStruct _genieEventQueue;
chris215 2:f283764fe9b7 177 //////////////////////////////////////////////////////////////
chris215 2:f283764fe9b7 178 // Simple 5-deep stack for the link state, this allows
chris215 2:f283764fe9b7 179 // genieDoEvents() to save the current state, receive a frame,
chris215 2:f283764fe9b7 180 // then restore the state
chris215 2:f283764fe9b7 181 //
chris215 2:f283764fe9b7 182 uint8_t _genieLinkStates[5];
chris215 2:f283764fe9b7 183 //
chris215 2:f283764fe9b7 184 // Stack pointer
chris215 2:f283764fe9b7 185 //
chris215 2:f283764fe9b7 186 uint8_t *_genieLinkState;
chris215 2:f283764fe9b7 187 //////////////////////////////////////////////////////////////
chris215 2:f283764fe9b7 188 // Number of mS the genieGetChar() function will wait before
chris215 2:f283764fe9b7 189 // giving up on the display
chris215 2:f283764fe9b7 190 int _genieTimeout;
chris215 2:f283764fe9b7 191 //////////////////////////////////////////////////////////////
chris215 2:f283764fe9b7 192 // Global error variable
chris215 2:f283764fe9b7 193 int _genieError;
chris215 2:f283764fe9b7 194 uint8_t rxframe_count;
chris215 2:f283764fe9b7 195 };