![](/media/cache/profiles/06833b73c7b85d172f55b6f38a40b094.jpg.50x50_q85.jpg)
A demonstration of how to drive the onboard LEDS on the LPC1768 via a 4.3 inch touch-screen display from 4D Systems
A quick example program to show how to use the mbed LPC1768 with the 4D systems 4.3 inch capacitive touch screen.
The display has four vitual winButton objects which when touched change the state of four virtual led (userLed) objects. The winButton objects on change of state send a serial message out to the Mbed serial port on pins 9 and 10.
This message tells the mbed to drive actual corresponding virtual and actual LEDS 1 to 4 appropriately.
for more information people can check out my blog post on the subject here:
http://langster1980.blogspot.co.uk/2014/01/mbed-controlling-4d-systems-ulcd-43pct.html
mbed_genie.h@0:e1ef1c6666f3, 2014-01-29 (annotated)
- Committer:
- langster1980
- Date:
- Wed Jan 29 23:04:22 2014 +0000
- Revision:
- 0:e1ef1c6666f3
1st Version of a tutorial on how to drive the onboard LEDS on an LPC1768 via a 4D systems 4.3 inch touch screen display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
langster1980 | 0:e1ef1c6666f3 | 1 | #undef GENIE_DEBUG |
langster1980 | 0:e1ef1c6666f3 | 2 | |
langster1980 | 0:e1ef1c6666f3 | 3 | #define GENIE_VERSION "GenieMbed 17-Nov-2013" |
langster1980 | 0:e1ef1c6666f3 | 4 | |
langster1980 | 0:e1ef1c6666f3 | 5 | // Genie commands & replys: |
langster1980 | 0:e1ef1c6666f3 | 6 | |
langster1980 | 0:e1ef1c6666f3 | 7 | #define GENIE_ACK 0x06 |
langster1980 | 0:e1ef1c6666f3 | 8 | #define GENIE_NAK 0x15 |
langster1980 | 0:e1ef1c6666f3 | 9 | |
langster1980 | 0:e1ef1c6666f3 | 10 | #define TIMEOUT_PERIOD 500 |
langster1980 | 0:e1ef1c6666f3 | 11 | #define RESYNC_PERIOD 100 |
langster1980 | 0:e1ef1c6666f3 | 12 | |
langster1980 | 0:e1ef1c6666f3 | 13 | #define GENIE_READ_OBJ 0 |
langster1980 | 0:e1ef1c6666f3 | 14 | #define GENIE_WRITE_OBJ 1 |
langster1980 | 0:e1ef1c6666f3 | 15 | #define GENIE_WRITE_STR 2 |
langster1980 | 0:e1ef1c6666f3 | 16 | #define GENIE_WRITE_STRU 3 |
langster1980 | 0:e1ef1c6666f3 | 17 | #define GENIE_WRITE_CONTRAST 4 |
langster1980 | 0:e1ef1c6666f3 | 18 | #define GENIE_REPORT_OBJ 5 |
langster1980 | 0:e1ef1c6666f3 | 19 | #define GENIE_REPORT_EVENT 7 |
langster1980 | 0:e1ef1c6666f3 | 20 | |
langster1980 | 0:e1ef1c6666f3 | 21 | // Objects |
langster1980 | 0:e1ef1c6666f3 | 22 | // the manual says: |
langster1980 | 0:e1ef1c6666f3 | 23 | // Note: Object IDs may change with future releases; it is not |
langster1980 | 0:e1ef1c6666f3 | 24 | // advisable to code their values as constants. |
langster1980 | 0:e1ef1c6666f3 | 25 | |
langster1980 | 0:e1ef1c6666f3 | 26 | #define GENIE_OBJ_DIPSW 0 |
langster1980 | 0:e1ef1c6666f3 | 27 | #define GENIE_OBJ_KNOB 1 |
langster1980 | 0:e1ef1c6666f3 | 28 | #define GENIE_OBJ_ROCKERSW 2 |
langster1980 | 0:e1ef1c6666f3 | 29 | #define GENIE_OBJ_ROTARYSW 3 |
langster1980 | 0:e1ef1c6666f3 | 30 | #define GENIE_OBJ_SLIDER 4 |
langster1980 | 0:e1ef1c6666f3 | 31 | #define GENIE_OBJ_TRACKBAR 5 |
langster1980 | 0:e1ef1c6666f3 | 32 | #define GENIE_OBJ_WINBUTTON 6 |
langster1980 | 0:e1ef1c6666f3 | 33 | #define GENIE_OBJ_ANGULAR_METER 7 |
langster1980 | 0:e1ef1c6666f3 | 34 | #define GENIE_OBJ_COOL_GAUGE 8 |
langster1980 | 0:e1ef1c6666f3 | 35 | #define GENIE_OBJ_CUSTOM_DIGITS 9 |
langster1980 | 0:e1ef1c6666f3 | 36 | #define GENIE_OBJ_FORM 10 |
langster1980 | 0:e1ef1c6666f3 | 37 | #define GENIE_OBJ_GAUGE 11 |
langster1980 | 0:e1ef1c6666f3 | 38 | #define GENIE_OBJ_IMAGE 12 |
langster1980 | 0:e1ef1c6666f3 | 39 | #define GENIE_OBJ_KEYBOARD 13 |
langster1980 | 0:e1ef1c6666f3 | 40 | #define GENIE_OBJ_LED 14 |
langster1980 | 0:e1ef1c6666f3 | 41 | #define GENIE_OBJ_LED_DIGITS 15 |
langster1980 | 0:e1ef1c6666f3 | 42 | #define GENIE_OBJ_METER 16 |
langster1980 | 0:e1ef1c6666f3 | 43 | #define GENIE_OBJ_STRINGS 17 |
langster1980 | 0:e1ef1c6666f3 | 44 | #define GENIE_OBJ_THERMOMETER 18 |
langster1980 | 0:e1ef1c6666f3 | 45 | #define GENIE_OBJ_USER_LED 19 |
langster1980 | 0:e1ef1c6666f3 | 46 | #define GENIE_OBJ_VIDEO 20 |
langster1980 | 0:e1ef1c6666f3 | 47 | #define GENIE_OBJ_STATIC_TEXT 21 |
langster1980 | 0:e1ef1c6666f3 | 48 | #define GENIE_OBJ_SOUND 22 |
langster1980 | 0:e1ef1c6666f3 | 49 | #define GENIE_OBJ_TIMER 23 |
langster1980 | 0:e1ef1c6666f3 | 50 | #define GENIE_OBJ_SPECTRUM 24 |
langster1980 | 0:e1ef1c6666f3 | 51 | #define GENIE_OBJ_SCOPE 25 |
langster1980 | 0:e1ef1c6666f3 | 52 | #define GENIE_OBJ_TANK 26 |
langster1980 | 0:e1ef1c6666f3 | 53 | #define GENIE_OBJ_USERIMAGES 27 |
langster1980 | 0:e1ef1c6666f3 | 54 | #define GENIE_OBJ_PINOUTPUT 28 |
langster1980 | 0:e1ef1c6666f3 | 55 | #define GENIE_OBJ_PININPUT 29 |
langster1980 | 0:e1ef1c6666f3 | 56 | #define GENIE_OBJ_4DBUTTON 30 |
langster1980 | 0:e1ef1c6666f3 | 57 | #define GENIE_OBJ_ANIBUTTON 31 |
langster1980 | 0:e1ef1c6666f3 | 58 | #define GENIE_OBJ_COLORPICKER 32 |
langster1980 | 0:e1ef1c6666f3 | 59 | #define GENIE_OBJ_USERBUTTON 33 |
langster1980 | 0:e1ef1c6666f3 | 60 | |
langster1980 | 0:e1ef1c6666f3 | 61 | // Structure to store replys returned from a display |
langster1980 | 0:e1ef1c6666f3 | 62 | |
langster1980 | 0:e1ef1c6666f3 | 63 | #define GENIE_FRAME_SIZE 6 |
langster1980 | 0:e1ef1c6666f3 | 64 | struct genieFrameReportObj { |
langster1980 | 0:e1ef1c6666f3 | 65 | uint8_t cmd; |
langster1980 | 0:e1ef1c6666f3 | 66 | uint8_t object; |
langster1980 | 0:e1ef1c6666f3 | 67 | uint8_t index; |
langster1980 | 0:e1ef1c6666f3 | 68 | uint8_t data_msb; |
langster1980 | 0:e1ef1c6666f3 | 69 | uint8_t data_lsb; |
langster1980 | 0:e1ef1c6666f3 | 70 | }; |
langster1980 | 0:e1ef1c6666f3 | 71 | |
langster1980 | 0:e1ef1c6666f3 | 72 | ///////////////////////////////////////////////////////////////////// |
langster1980 | 0:e1ef1c6666f3 | 73 | // The Genie frame definition |
langster1980 | 0:e1ef1c6666f3 | 74 | // |
langster1980 | 0:e1ef1c6666f3 | 75 | // The union allows the data to be referenced as an array of uint8_t |
langster1980 | 0:e1ef1c6666f3 | 76 | // or a structure of type genieFrameReportObj, eg |
langster1980 | 0:e1ef1c6666f3 | 77 | // |
langster1980 | 0:e1ef1c6666f3 | 78 | // genieFrame f; |
langster1980 | 0:e1ef1c6666f3 | 79 | // f.bytes[4]; |
langster1980 | 0:e1ef1c6666f3 | 80 | // f.reportObject.data_lsb |
langster1980 | 0:e1ef1c6666f3 | 81 | // |
langster1980 | 0:e1ef1c6666f3 | 82 | // both methods get the same byte |
langster1980 | 0:e1ef1c6666f3 | 83 | // |
langster1980 | 0:e1ef1c6666f3 | 84 | union genieFrame { |
langster1980 | 0:e1ef1c6666f3 | 85 | uint8_t bytes[GENIE_FRAME_SIZE]; |
langster1980 | 0:e1ef1c6666f3 | 86 | genieFrameReportObj reportObject; |
langster1980 | 0:e1ef1c6666f3 | 87 | }; |
langster1980 | 0:e1ef1c6666f3 | 88 | |
langster1980 | 0:e1ef1c6666f3 | 89 | #define MAX_GENIE_EVENTS 16 // MUST be a power of 2 |
langster1980 | 0:e1ef1c6666f3 | 90 | #define MAX_GENIE_FATALS 10 |
langster1980 | 0:e1ef1c6666f3 | 91 | |
langster1980 | 0:e1ef1c6666f3 | 92 | struct genieEventQueueStruct { |
langster1980 | 0:e1ef1c6666f3 | 93 | genieFrame frames[MAX_GENIE_EVENTS]; |
langster1980 | 0:e1ef1c6666f3 | 94 | uint8_t rd_index; |
langster1980 | 0:e1ef1c6666f3 | 95 | uint8_t wr_index; |
langster1980 | 0:e1ef1c6666f3 | 96 | uint8_t n_events; |
langster1980 | 0:e1ef1c6666f3 | 97 | }; |
langster1980 | 0:e1ef1c6666f3 | 98 | |
langster1980 | 0:e1ef1c6666f3 | 99 | typedef void (*geniePutCharFuncPtr) (uint8_t c, uint32_t baud); |
langster1980 | 0:e1ef1c6666f3 | 100 | typedef uint16_t (*genieGetCharFuncPtr) (void); |
langster1980 | 0:e1ef1c6666f3 | 101 | typedef void (*genieUserEventHandlerPtr) (void); |
langster1980 | 0:e1ef1c6666f3 | 102 | |
langster1980 | 0:e1ef1c6666f3 | 103 | #define ERROR_NONE 0 |
langster1980 | 0:e1ef1c6666f3 | 104 | #define ERROR_TIMEOUT -1 // 255 0xFF |
langster1980 | 0:e1ef1c6666f3 | 105 | #define ERROR_NOHANDLER -2 // 254 0xFE |
langster1980 | 0:e1ef1c6666f3 | 106 | #define ERROR_NOCHAR -3 // 253 0xFD |
langster1980 | 0:e1ef1c6666f3 | 107 | #define ERROR_NAK -4 // 252 0xFC |
langster1980 | 0:e1ef1c6666f3 | 108 | #define ERROR_REPLY_OVR -5 // 251 0xFB |
langster1980 | 0:e1ef1c6666f3 | 109 | #define ERROR_RESYNC -6 // 250 0xFA |
langster1980 | 0:e1ef1c6666f3 | 110 | #define ERROR_NODISPLAY -7 // 249 0xF9 |
langster1980 | 0:e1ef1c6666f3 | 111 | #define ERROR_BAD_CS -8 // 248 0xF8 |
langster1980 | 0:e1ef1c6666f3 | 112 | |
langster1980 | 0:e1ef1c6666f3 | 113 | #define GENIE_LINK_IDLE 0 |
langster1980 | 0:e1ef1c6666f3 | 114 | #define GENIE_LINK_WFAN 1 // waiting for Ack or Nak |
langster1980 | 0:e1ef1c6666f3 | 115 | #define GENIE_LINK_WF_RXREPORT 2 // waiting for a report frame |
langster1980 | 0:e1ef1c6666f3 | 116 | #define GENIE_LINK_RXREPORT 3 // receiving a report frame |
langster1980 | 0:e1ef1c6666f3 | 117 | #define GENIE_LINK_RXEVENT 4 // receiving an event frame |
langster1980 | 0:e1ef1c6666f3 | 118 | #define GENIE_LINK_SHDN 5 |
langster1980 | 0:e1ef1c6666f3 | 119 | |
langster1980 | 0:e1ef1c6666f3 | 120 | #define GENIE_EVENT_NONE 0 |
langster1980 | 0:e1ef1c6666f3 | 121 | #define GENIE_EVENT_RXCHAR 1 |
langster1980 | 0:e1ef1c6666f3 | 122 | |
langster1980 | 0:e1ef1c6666f3 | 123 | #ifndef TRUE |
langster1980 | 0:e1ef1c6666f3 | 124 | #define TRUE (1==1) |
langster1980 | 0:e1ef1c6666f3 | 125 | #define FALSE (!TRUE) |
langster1980 | 0:e1ef1c6666f3 | 126 | #endif |
langster1980 | 0:e1ef1c6666f3 | 127 | |
langster1980 | 0:e1ef1c6666f3 | 128 | void SetupGenie(void); |
langster1980 | 0:e1ef1c6666f3 | 129 | void genieAttachEventHandler (genieUserEventHandlerPtr handler); |
langster1980 | 0:e1ef1c6666f3 | 130 | extern bool genieDequeueEvent (genieFrame * buff); |
langster1980 | 0:e1ef1c6666f3 | 131 | extern bool genieEventIs (genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index); |
langster1980 | 0:e1ef1c6666f3 | 132 | extern uint16_t genieGetEventData (genieFrame * e); |
langster1980 | 0:e1ef1c6666f3 | 133 | extern uint16_t genieWriteObject (uint16_t object, uint16_t index, uint16_t data); |
langster1980 | 0:e1ef1c6666f3 | 134 | extern uint16_t genieWriteStr (uint16_t index, char *string); |
langster1980 | 0:e1ef1c6666f3 | 135 | extern void genieWriteContrast (uint16_t value); |
langster1980 | 0:e1ef1c6666f3 | 136 |