Library for 4D systems touchscreen

Committer:
ashleymills
Date:
Tue Aug 21 14:40:18 2012 +0000
Revision:
0:edf5f3d8645e
4D systems touchscreen lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:edf5f3d8645e 1 /***************************
ashleymills 0:edf5f3d8645e 2 * Created by Ashley Mills *
ashleymills 0:edf5f3d8645e 3 ***************************/
ashleymills 0:edf5f3d8645e 4 #pragma once
ashleymills 0:edf5f3d8645e 5 #include "mbed.h"
ashleymills 0:edf5f3d8645e 6 #include "rtos.h"
ashleymills 0:edf5f3d8645e 7
ashleymills 0:edf5f3d8645e 8 #define lowByte(w) ((uint8_t) ((w) & 0xff))
ashleymills 0:edf5f3d8645e 9 #define highByte(w) ((uint8_t) ((w) >> 8))
ashleymills 0:edf5f3d8645e 10
ashleymills 0:edf5f3d8645e 11 typedef enum {
ashleymills 0:edf5f3d8645e 12 NO_TOUCH_ACTIVITY=0,
ashleymills 0:edf5f3d8645e 13 TOUCH_PRESS,
ashleymills 0:edf5f3d8645e 14 TOUCH_RELEASE,
ashleymills 0:edf5f3d8645e 15 TOUCH_MOVING
ashleymills 0:edf5f3d8645e 16 } eTouchStatus;
ashleymills 0:edf5f3d8645e 17
ashleymills 0:edf5f3d8645e 18 typedef enum {
ashleymills 0:edf5f3d8645e 19 LANDSCAPE=0,
ashleymills 0:edf5f3d8645e 20 LANDSCAPE_R,
ashleymills 0:edf5f3d8645e 21 NATIVE,
ashleymills 0:edf5f3d8645e 22 PORTRAIT_R
ashleymills 0:edf5f3d8645e 23 } eScreenOrientation;
ashleymills 0:edf5f3d8645e 24
ashleymills 0:edf5f3d8645e 25 typedef enum {
ashleymills 0:edf5f3d8645e 26 BAUD_9600,
ashleymills 0:edf5f3d8645e 27 BAUD_14400,
ashleymills 0:edf5f3d8645e 28 BAUD_19200,
ashleymills 0:edf5f3d8645e 29 BAUD_57600,
ashleymills 0:edf5f3d8645e 30 BAUD_115200,
ashleymills 0:edf5f3d8645e 31 BAUD_256000
ashleymills 0:edf5f3d8645e 32 } eBaudRate;
ashleymills 0:edf5f3d8645e 33
ashleymills 0:edf5f3d8645e 34 typedef struct {
ashleymills 0:edf5f3d8645e 35 uint16_t x;
ashleymills 0:edf5f3d8645e 36 uint16_t y;
ashleymills 0:edf5f3d8645e 37 } TouchPoint;
ashleymills 0:edf5f3d8645e 38
ashleymills 0:edf5f3d8645e 39 typedef enum {
ashleymills 0:edf5f3d8645e 40 INTERNAL_FONT_5x7,
ashleymills 0:edf5f3d8645e 41 INTERNAL_FONT_8x8,
ashleymills 0:edf5f3d8645e 42 INTERNAL_FONT_8x12,
ashleymills 0:edf5f3d8645e 43 INTERNAL_FONT_12x16
ashleymills 0:edf5f3d8645e 44 } eInternalFont;
ashleymills 0:edf5f3d8645e 45
ashleymills 0:edf5f3d8645e 46 class TouchScreen : Serial {
ashleymills 0:edf5f3d8645e 47 public:
ashleymills 0:edf5f3d8645e 48 static const int WIDTH = 320;
ashleymills 0:edf5f3d8645e 49 static const int HEIGHT = 240;
ashleymills 0:edf5f3d8645e 50
ashleymills 0:edf5f3d8645e 51 // constructors
ashleymills 0:edf5f3d8645e 52 TouchScreen(PinName tx, PinName rx, PinName resetPin, const char *name = NULL);
ashleymills 0:edf5f3d8645e 53 TouchScreen(PinName tx, PinName rx, PinName resetPin, eBaudRate baud, const char *name = NULL);
ashleymills 0:edf5f3d8645e 54 bool begin();
ashleymills 0:edf5f3d8645e 55
ashleymills 0:edf5f3d8645e 56 // drawing commands
ashleymills 0:edf5f3d8645e 57 void drawCircle(uint16_t xPos, uint16_t yPos, uint16_t radius, uint16_t color);
ashleymills 0:edf5f3d8645e 58 void drawPixel(uint16_t xPos, uint16_t yPos, uint16_t color);
ashleymills 0:edf5f3d8645e 59 void clearScreen();
ashleymills 0:edf5f3d8645e 60 void setBackgroundColor(uint16_t color);
ashleymills 0:edf5f3d8645e 61 void setPenSolid();
ashleymills 0:edf5f3d8645e 62 void setPenWireframe();
ashleymills 0:edf5f3d8645e 63 void drawImage(char *name, uint16_t x, uint16_t y);
ashleymills 0:edf5f3d8645e 64 void drawGraphicsFormatString(uint16_t x, uint16_t y, eInternalFont font, uint16_t textColor, uint8_t charWidth, uint8_t charHeight, char* text);
ashleymills 0:edf5f3d8645e 65
ashleymills 0:edf5f3d8645e 66 void drawRectangle(uint16_t topLeftX, uint16_t topLeftY, uint16_t botRightX, uint16_t botRightY, uint16_t color);
ashleymills 0:edf5f3d8645e 67 void drawRectangleWH(uint16_t topLeftX, uint16_t topLeftY, uint16_t width, uint16_t height, uint16_t color);
ashleymills 0:edf5f3d8645e 68 void drawRectangleWH(uint16_t topLeftX, uint16_t topLeftY, uint16_t width, uint16_t height);
ashleymills 0:edf5f3d8645e 69 void drawLine(uint16_t topLeftX, uint16_t topLeftY, uint16_t botRightX, uint16_t botRightY, uint16_t color);
ashleymills 0:edf5f3d8645e 70
ashleymills 0:edf5f3d8645e 71 // drawing text
ashleymills 0:edf5f3d8645e 72 void drawTextFormatString(uint8_t row, uint8_t column, eInternalFont font, uint16_t textColor, char* text);
ashleymills 0:edf5f3d8645e 73 void drawChar(char c, uint16_t x, uint16_t y, uint16_t color, uint8_t width, uint8_t height);
ashleymills 0:edf5f3d8645e 74 void drawText(char *s, uint16_t x, uint16_t y);
ashleymills 0:edf5f3d8645e 75 void setFont(uint8_t fontIndex);
ashleymills 0:edf5f3d8645e 76
ashleymills 0:edf5f3d8645e 77 // color creation
ashleymills 0:edf5f3d8645e 78 uint16_t createRGB(uint8_t r, uint8_t g, uint8_t b);
ashleymills 0:edf5f3d8645e 79 uint16_t createRGBClassic(int r, int g, int b);
ashleymills 0:edf5f3d8645e 80 uint16_t createRGBF(float r, float g, float b);
ashleymills 0:edf5f3d8645e 81
ashleymills 0:edf5f3d8645e 82 // touch commands
ashleymills 0:edf5f3d8645e 83 void enableTouch();
ashleymills 0:edf5f3d8645e 84 void disableTouch();
ashleymills 0:edf5f3d8645e 85 eTouchStatus getTouchStatus();
ashleymills 0:edf5f3d8645e 86 TouchPoint getLastTouch();
ashleymills 0:edf5f3d8645e 87 void reset();
ashleymills 0:edf5f3d8645e 88
ashleymills 0:edf5f3d8645e 89 // misc commands
ashleymills 0:edf5f3d8645e 90 void getVersion();
ashleymills 0:edf5f3d8645e 91 void setOrientation(eScreenOrientation o);
ashleymills 0:edf5f3d8645e 92 bool setBaudRate(eBaudRate baud);
ashleymills 0:edf5f3d8645e 93 void setBacklight(bool state);
ashleymills 0:edf5f3d8645e 94 void setContrast(uint8_t value);
ashleymills 0:edf5f3d8645e 95
ashleymills 0:edf5f3d8645e 96 void setFillColor(uint16_t c);
ashleymills 0:edf5f3d8645e 97 void setStrokeColor(uint16_t c);
ashleymills 0:edf5f3d8645e 98
ashleymills 0:edf5f3d8645e 99 private:
ashleymills 0:edf5f3d8645e 100 void dropByte();
ashleymills 0:edf5f3d8645e 101 void dropBytes(uint16_t numBytes);
ashleymills 0:edf5f3d8645e 102 void dropByteAndWaitUntilReadable();
ashleymills 0:edf5f3d8645e 103 bool gack();
ashleymills 0:edf5f3d8645e 104 bool waitUntilReadable();
ashleymills 0:edf5f3d8645e 105
ashleymills 0:edf5f3d8645e 106 DigitalOut *_resetPin;
ashleymills 0:edf5f3d8645e 107 uint16_t _fillColor;
ashleymills 0:edf5f3d8645e 108 uint16_t _strokeColor;
ashleymills 0:edf5f3d8645e 109 bool _initOK;
ashleymills 0:edf5f3d8645e 110 };
ashleymills 0:edf5f3d8645e 111
ashleymills 0:edf5f3d8645e 112
ashleymills 0:edf5f3d8645e 113 /*
ashleymills 0:edf5f3d8645e 114 Header (6 bytes as 3 words)
ashleymills 0:edf5f3d8645e 115 word1 (Hi:Lo) = width : horizontal size of the image
ashleymills 0:edf5f3d8645e 116 word2 (Hi:Lo) = height : vertical size of the image
ashleymills 0:edf5f3d8645e 117 Word3 = colour_mode : 16dec = 65K colour mode, 16bits/2bytes per pixel (msb, lsb)
ashleymills 0:edf5f3d8645e 118
ashleymills 0:edf5f3d8645e 119 The header is then followed by the pixel data
ashleymills 0:edf5f3d8645e 120 Pixel1�PixelN: Image pixel data and N is the total number of pixels
ashleymills 0:edf5f3d8645e 121 N = height x width when colour_mode = 0
ashleymills 0:edf5f3d8645e 122 N = height x width x 2 when colour_mode = 1
ashleymills 0:edf5f3d8645e 123 */