.

Committer:
Geremia
Date:
Fri Feb 13 15:25:10 2015 +0000
Revision:
1:ff019d22b275
Parent:
0:75ec1b3cde17
Child:
2:713844a55c4e
Added SPI_16, LCD done

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