.

Committer:
Geremia
Date:
Thu Feb 12 22:22:47 2015 +0000
Revision:
0:75ec1b3cde17
Child:
1:ff019d22b275
Initial tests, LCD par and spi ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 0:75ec1b3cde17 1
Geremia 0:75ec1b3cde17 2 #ifndef MBED_LCD_H
Geremia 0:75ec1b3cde17 3 #define MBED_LCD_H
Geremia 0:75ec1b3cde17 4
Geremia 0:75ec1b3cde17 5 #include "GraphicsDisplay.h"
Geremia 0:75ec1b3cde17 6 #include "PAR8.h"
Geremia 0:75ec1b3cde17 7 #include "SPI8.h"
Geremia 0:75ec1b3cde17 8 #include "Protocols.h"
Geremia 0:75ec1b3cde17 9
Geremia 0:75ec1b3cde17 10 #define Black 1
Geremia 0:75ec1b3cde17 11 #define White 0
Geremia 0:75ec1b3cde17 12
Geremia 0:75ec1b3cde17 13 /** Draw mode
Geremia 0:75ec1b3cde17 14 * NORMAl
Geremia 0:75ec1b3cde17 15 * XOR set pixel by xor the screen
Geremia 0:75ec1b3cde17 16 */
Geremia 0:75ec1b3cde17 17 enum {NORMAL,XOR};
Geremia 0:75ec1b3cde17 18
Geremia 0:75ec1b3cde17 19 /** Mirror mode */
Geremia 0:75ec1b3cde17 20 enum mirror_t {X,Y,XY,NONE};
Geremia 0:75ec1b3cde17 21
Geremia 0:75ec1b3cde17 22
Geremia 0:75ec1b3cde17 23 /** A common base class for monochrome Display
Geremia 0:75ec1b3cde17 24 */
Geremia 0:75ec1b3cde17 25 class LCD : public GraphicsDisplay
Geremia 0:75ec1b3cde17 26 {
Geremia 0:75ec1b3cde17 27
Geremia 0:75ec1b3cde17 28 public:
Geremia 0:75ec1b3cde17 29
Geremia 0:75ec1b3cde17 30 /** Create a monochrome LCD Parallel interface
Geremia 0:75ec1b3cde17 31 * @param name The name used by the parent class to access the interface
Geremia 0:75ec1b3cde17 32 */
Geremia 0:75ec1b3cde17 33 LCD(proto_t displayproto,PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
Geremia 0:75ec1b3cde17 34
Geremia 0:75ec1b3cde17 35 /** Create a monochrome LCD SPI interface
Geremia 0:75ec1b3cde17 36 * @param name The name used by the parent class to access the interface
Geremia 0:75ec1b3cde17 37 */
Geremia 0:75ec1b3cde17 38 LCD(proto_t displayproto,PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const int lcdsize_x, const int lcdsize_y, const int ic_x_segs, const int ic_y_coms, const char* name);
Geremia 0:75ec1b3cde17 39
Geremia 0:75ec1b3cde17 40 /** Destructor
Geremia 0:75ec1b3cde17 41 * will free framebuffer
Geremia 0:75ec1b3cde17 42 */
Geremia 0:75ec1b3cde17 43 virtual ~LCD();
Geremia 0:75ec1b3cde17 44
Geremia 0:75ec1b3cde17 45
Geremia 0:75ec1b3cde17 46
Geremia 0:75ec1b3cde17 47 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 48 /////// ----------------------------------------------------///////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 49
Geremia 0:75ec1b3cde17 50 /** Draw a pixel in the specified color.
Geremia 0:75ec1b3cde17 51 * @param x is the horizontal offset to this pixel.
Geremia 0:75ec1b3cde17 52 * @param y is the vertical offset to this pixel.
Geremia 0:75ec1b3cde17 53 * @param color defines the color for the pixel.
Geremia 0:75ec1b3cde17 54 */
Geremia 0:75ec1b3cde17 55 virtual void pixel(int x, int y, unsigned short color);
Geremia 0:75ec1b3cde17 56
Geremia 0:75ec1b3cde17 57
Geremia 0:75ec1b3cde17 58
Geremia 0:75ec1b3cde17 59
Geremia 0:75ec1b3cde17 60 /** Set the window, which controls where items are written to the screen.
Geremia 0:75ec1b3cde17 61 * When something hits the window width, it wraps back to the left side
Geremia 0:75ec1b3cde17 62 * and down a row. If the initial write is outside the window, it will
Geremia 0:75ec1b3cde17 63 * be captured into the window when it crosses a boundary.
Geremia 0:75ec1b3cde17 64 * @param x is the left edge in pixels.
Geremia 0:75ec1b3cde17 65 * @param y is the top edge in pixels.
Geremia 0:75ec1b3cde17 66 * @param w is the window width in pixels.
Geremia 0:75ec1b3cde17 67 * @param h is the window height in pixels.
Geremia 0:75ec1b3cde17 68 */
Geremia 0:75ec1b3cde17 69 virtual void window(int x, int y, int w, int h);
Geremia 0:75ec1b3cde17 70
Geremia 0:75ec1b3cde17 71 /** Push a single pixel into the window and increment position.
Geremia 0:75ec1b3cde17 72 * You must first call window() then push pixels in loop.
Geremia 0:75ec1b3cde17 73 * @param color is the pixel color.
Geremia 0:75ec1b3cde17 74 */
Geremia 0:75ec1b3cde17 75 virtual void window_pushpixel(unsigned short color);
Geremia 0:75ec1b3cde17 76
Geremia 0:75ec1b3cde17 77 /** Framebuffer is used, it needs to be sent to LCD from time to time
Geremia 0:75ec1b3cde17 78 */
Geremia 0:75ec1b3cde17 79 virtual void copy_to_lcd();
Geremia 0:75ec1b3cde17 80
Geremia 0:75ec1b3cde17 81 /** set the contrast of the screen
Geremia 0:75ec1b3cde17 82 *
Geremia 0:75ec1b3cde17 83 * @param o contrast 0-63
Geremia 0:75ec1b3cde17 84 * @note may be overrided in case of not standard command
Geremia 0:75ec1b3cde17 85 */
Geremia 0:75ec1b3cde17 86 virtual void set_contrast(int o);
Geremia 0:75ec1b3cde17 87
Geremia 0:75ec1b3cde17 88 /** read the contrast level
Geremia 0:75ec1b3cde17 89 *
Geremia 0:75ec1b3cde17 90 */
Geremia 0:75ec1b3cde17 91 int get_contrast(void);
Geremia 0:75ec1b3cde17 92
Geremia 0:75ec1b3cde17 93 /** invert the screen
Geremia 0:75ec1b3cde17 94 *
Geremia 0:75ec1b3cde17 95 * @param o = 0 normal, 1 invert
Geremia 0:75ec1b3cde17 96 */
Geremia 0:75ec1b3cde17 97 void invert(unsigned char o);
Geremia 0:75ec1b3cde17 98
Geremia 0:75ec1b3cde17 99 /** clear the entire screen
Geremia 0:75ec1b3cde17 100 * The inherited one sets windomax then fill with background color
Geremia 0:75ec1b3cde17 101 * We override it to speedup
Geremia 0:75ec1b3cde17 102 */
Geremia 0:75ec1b3cde17 103 virtual void cls();
Geremia 0:75ec1b3cde17 104
Geremia 0:75ec1b3cde17 105 /** setup auto update of screen
Geremia 0:75ec1b3cde17 106 *
Geremia 0:75ec1b3cde17 107 * @param up 1 = on , 0 = off
Geremia 0:75ec1b3cde17 108 * if switched off the program has to call copy_to_lcd()
Geremia 0:75ec1b3cde17 109 * to update screen from framebuffer
Geremia 0:75ec1b3cde17 110 */
Geremia 0:75ec1b3cde17 111 void set_auto_up(bool up);
Geremia 0:75ec1b3cde17 112
Geremia 0:75ec1b3cde17 113 /** get status of the auto update function
Geremia 0:75ec1b3cde17 114 *
Geremia 0:75ec1b3cde17 115 * @returns if auto update is on
Geremia 0:75ec1b3cde17 116 */
Geremia 0:75ec1b3cde17 117 bool get_auto_up(void);
Geremia 0:75ec1b3cde17 118
Geremia 0:75ec1b3cde17 119
Geremia 0:75ec1b3cde17 120
Geremia 0:75ec1b3cde17 121 /** Set the orientation of the screen
Geremia 0:75ec1b3cde17 122 * x,y: 0,0 is always top left
Geremia 0:75ec1b3cde17 123 *
Geremia 0:75ec1b3cde17 124 * @param o direction to use the screen (0-3)
Geremia 0:75ec1b3cde17 125 * 0 = -90°
Geremia 0:75ec1b3cde17 126 * 1 = default 0°
Geremia 0:75ec1b3cde17 127 * 2 = +90°
Geremia 0:75ec1b3cde17 128 * 3 = +180°
Geremia 0:75ec1b3cde17 129 *
Geremia 0:75ec1b3cde17 130 */
Geremia 0:75ec1b3cde17 131 void set_orientation(int o);
Geremia 0:75ec1b3cde17 132
Geremia 0:75ec1b3cde17 133 /** Set ChipSelect high or low
Geremia 0:75ec1b3cde17 134 * @param enable 0/1
Geremia 0:75ec1b3cde17 135 */
Geremia 0:75ec1b3cde17 136 virtual void BusEnable(bool enable);
Geremia 0:75ec1b3cde17 137
Geremia 0:75ec1b3cde17 138
Geremia 0:75ec1b3cde17 139 protected:
Geremia 0:75ec1b3cde17 140
Geremia 0:75ec1b3cde17 141 /** set mirror mode
Geremia 0:75ec1b3cde17 142 * @note may be overridden by specific display init class in case of not standard cmds or inverted wiring
Geremia 0:75ec1b3cde17 143 * @param mode NONE, X, Y, XY
Geremia 0:75ec1b3cde17 144 */
Geremia 0:75ec1b3cde17 145 virtual void mirrorXY(mirror_t mode);
Geremia 0:75ec1b3cde17 146
Geremia 0:75ec1b3cde17 147 ////// functions needed by parent class ///////////////////////////////////////
Geremia 0:75ec1b3cde17 148 ////// -------------------------------- ///////////////////////////////////////
Geremia 0:75ec1b3cde17 149
Geremia 0:75ec1b3cde17 150 /** Send command byte to display
Geremia 0:75ec1b3cde17 151 * @param cmd is the command
Geremia 0:75ec1b3cde17 152 */
Geremia 0:75ec1b3cde17 153 void wr_cmd(unsigned char cmd);
Geremia 0:75ec1b3cde17 154
Geremia 0:75ec1b3cde17 155 /** Send data byte to display
Geremia 0:75ec1b3cde17 156 * @param data8 is the byte
Geremia 0:75ec1b3cde17 157 */
Geremia 0:75ec1b3cde17 158 void wr_data8(unsigned char data8);
Geremia 0:75ec1b3cde17 159
Geremia 0:75ec1b3cde17 160 /** Send same data byte to display controller multiple times
Geremia 0:75ec1b3cde17 161 *
Geremia 0:75ec1b3cde17 162 * @param data8: byte to send
Geremia 0:75ec1b3cde17 163 * @param count: how many
Geremia 0:75ec1b3cde17 164 *
Geremia 0:75ec1b3cde17 165 */
Geremia 0:75ec1b3cde17 166 virtual void wr_data8(unsigned char data8, unsigned int count);
Geremia 0:75ec1b3cde17 167
Geremia 0:75ec1b3cde17 168 /** Send array of data bytes to display controller
Geremia 0:75ec1b3cde17 169 *
Geremia 0:75ec1b3cde17 170 * @param data8: unsigned char data array
Geremia 0:75ec1b3cde17 171 * @param lenght: lenght of array
Geremia 0:75ec1b3cde17 172 *
Geremia 0:75ec1b3cde17 173 */
Geremia 0:75ec1b3cde17 174 virtual void wr_data8buf(unsigned char* data8, unsigned int lenght);
Geremia 0:75ec1b3cde17 175
Geremia 0:75ec1b3cde17 176 /** HW reset sequence (without display init commands)
Geremia 0:75ec1b3cde17 177 */
Geremia 0:75ec1b3cde17 178 void hw_reset();
Geremia 0:75ec1b3cde17 179
Geremia 0:75ec1b3cde17 180 int draw_mode;
Geremia 0:75ec1b3cde17 181 int contrast;
Geremia 0:75ec1b3cde17 182
Geremia 0:75ec1b3cde17 183 private:
Geremia 0:75ec1b3cde17 184
Geremia 0:75ec1b3cde17 185
Geremia 0:75ec1b3cde17 186 unsigned char *buffer;
Geremia 0:75ec1b3cde17 187 const int LCDSIZE_X;
Geremia 0:75ec1b3cde17 188 const int LCDSIZE_Y;
Geremia 0:75ec1b3cde17 189 const int LCDPAGES;
Geremia 0:75ec1b3cde17 190 const int IC_X_SEGS;
Geremia 0:75ec1b3cde17 191 const int IC_Y_COMS;
Geremia 0:75ec1b3cde17 192 const int IC_PAGES;
Geremia 0:75ec1b3cde17 193
Geremia 0:75ec1b3cde17 194 int page_offset;
Geremia 0:75ec1b3cde17 195 int col_offset;
Geremia 0:75ec1b3cde17 196 // pixel location
Geremia 0:75ec1b3cde17 197 int cur_x;
Geremia 0:75ec1b3cde17 198 int cur_y;
Geremia 0:75ec1b3cde17 199 // window location
Geremia 0:75ec1b3cde17 200 int win_x1;
Geremia 0:75ec1b3cde17 201 int win_x2;
Geremia 0:75ec1b3cde17 202 int win_y1;
Geremia 0:75ec1b3cde17 203 int win_y2;
Geremia 0:75ec1b3cde17 204 int orientation;
Geremia 0:75ec1b3cde17 205 // bool portrait;
Geremia 0:75ec1b3cde17 206 };
Geremia 0:75ec1b3cde17 207
Geremia 0:75ec1b3cde17 208 #endif