LPC1768 Mini-DK EasyWeb application with SPI TFT output. Started from EasyWebCR and modified for DM9161 PHY support.

Dependencies:   Mini-DK mbed

This is a very basic EasyWeb application.

No error checking is performed during initialisation.

Information

If the webpage is not reachable or the 'Webserver running' message does not appear, press the reset button on the Mini-DK and wait until the message 'Webserver running' appears.
This happens sometimes when powering up the Mini-DK because the DM9161 reset pin is NOT controlled by the LPC1768, it is directly connected to the reset button.

IP adress/mask/gateway in tcpip.h : 192.168.0.200 / 255.255.255.0 / 192.168.0.1

MAC address in ethmac.h : 6-5-4-3-2-1

Committer:
frankvnk
Date:
Fri Dec 21 15:41:54 2012 +0000
Revision:
0:636056c0b5e1
First version - rewrite from EasyWebCR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 0:636056c0b5e1 1 // mbed library for 240*320 pixel display TFT
frankvnk 0:636056c0b5e1 2
frankvnk 0:636056c0b5e1 3 #ifndef MBED_SPI_TFT_H
frankvnk 0:636056c0b5e1 4 #define MBED_SPI_TFT_H
frankvnk 0:636056c0b5e1 5
frankvnk 0:636056c0b5e1 6
frankvnk 0:636056c0b5e1 7 #include "GraphicsDisplay.h"
frankvnk 0:636056c0b5e1 8 #include "mbed.h"
frankvnk 0:636056c0b5e1 9
frankvnk 0:636056c0b5e1 10 #define incx() x++, dxt += d2xt, t += dxt
frankvnk 0:636056c0b5e1 11 #define incy() y--, dyt += d2yt, t += dyt
frankvnk 0:636056c0b5e1 12
frankvnk 0:636056c0b5e1 13 #define SPI_F_LO 10000000
frankvnk 0:636056c0b5e1 14 #define SPI_F_HI 48000000
frankvnk 0:636056c0b5e1 15
frankvnk 0:636056c0b5e1 16 /* some RGB565 color definitions */
frankvnk 0:636056c0b5e1 17 #define Black 0x0000 /* 0, 0, 0 */
frankvnk 0:636056c0b5e1 18 #define Navy 0x000F /* 0, 0, 128 */
frankvnk 0:636056c0b5e1 19 #define DarkGreen 0x03E0 /* 0, 128, 0 */
frankvnk 0:636056c0b5e1 20 #define DarkCyan 0x03EF /* 0, 128, 128 */
frankvnk 0:636056c0b5e1 21 #define Maroon 0x7800 /* 128, 0, 0 */
frankvnk 0:636056c0b5e1 22 #define Purple 0x780F /* 128, 0, 128 */
frankvnk 0:636056c0b5e1 23 #define Olive 0x7BE0 /* 128, 128, 0 */
frankvnk 0:636056c0b5e1 24 #define LightGrey 0xC618 /* 192, 192, 192 */
frankvnk 0:636056c0b5e1 25 #define DarkGrey 0x7BEF /* 128, 128, 128 */
frankvnk 0:636056c0b5e1 26 #define Blue 0x001F /* 0, 0, 255 */
frankvnk 0:636056c0b5e1 27 #define Green 0x07E0 /* 0, 255, 0 */
frankvnk 0:636056c0b5e1 28 #define Cyan 0x07FF /* 0, 255, 255 */
frankvnk 0:636056c0b5e1 29 #define Red 0xF800 /* 255, 0, 0 */
frankvnk 0:636056c0b5e1 30 #define Magenta 0xF81F /* 255, 0, 255 */
frankvnk 0:636056c0b5e1 31 #define Yellow 0xFFE0 /* 255, 255, 0 */
frankvnk 0:636056c0b5e1 32 #define White 0xFFFF /* 255, 255, 255 */
frankvnk 0:636056c0b5e1 33 #define Orange 0xFD20 /* 255, 165, 0 */
frankvnk 0:636056c0b5e1 34 #define GreenYellow 0xAFE5 /* 173, 255, 47 */
frankvnk 0:636056c0b5e1 35
frankvnk 0:636056c0b5e1 36 class SPI_TFT : public GraphicsDisplay {
frankvnk 0:636056c0b5e1 37 public:
frankvnk 0:636056c0b5e1 38
frankvnk 0:636056c0b5e1 39 /** Create a SPI_TFT object connected to SPI and two pins
frankvnk 0:636056c0b5e1 40 *
frankvnk 0:636056c0b5e1 41 * @param mosi,miso,sclk SPI
frankvnk 0:636056c0b5e1 42 * @param cs pin connected to CS of display
frankvnk 0:636056c0b5e1 43 * @param reset pin connected to RESET of display
frankvnk 0:636056c0b5e1 44 *
frankvnk 0:636056c0b5e1 45 */
frankvnk 0:636056c0b5e1 46 SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT");
frankvnk 0:636056c0b5e1 47
frankvnk 0:636056c0b5e1 48 /** Get the width of the screen in pixel
frankvnk 0:636056c0b5e1 49 *
frankvnk 0:636056c0b5e1 50 * @param
frankvnk 0:636056c0b5e1 51 * @returns width of screen in pixel
frankvnk 0:636056c0b5e1 52 *
frankvnk 0:636056c0b5e1 53 */
frankvnk 0:636056c0b5e1 54 virtual int width();
frankvnk 0:636056c0b5e1 55
frankvnk 0:636056c0b5e1 56 /** Get the height of the screen in pixel
frankvnk 0:636056c0b5e1 57 *
frankvnk 0:636056c0b5e1 58 * @returns height of screen in pixel
frankvnk 0:636056c0b5e1 59 *
frankvnk 0:636056c0b5e1 60 */
frankvnk 0:636056c0b5e1 61 virtual int height();
frankvnk 0:636056c0b5e1 62
frankvnk 0:636056c0b5e1 63 /** Draw a pixel at x,y with color
frankvnk 0:636056c0b5e1 64 *
frankvnk 0:636056c0b5e1 65 * @param x horizontal position
frankvnk 0:636056c0b5e1 66 * @param y vertical position
frankvnk 0:636056c0b5e1 67 * @param color 16 bit pixel color
frankvnk 0:636056c0b5e1 68 */
frankvnk 0:636056c0b5e1 69 virtual void pixel(int x, int y,int colour);
frankvnk 0:636056c0b5e1 70
frankvnk 0:636056c0b5e1 71 /** draw a 1 pixel line
frankvnk 0:636056c0b5e1 72 *
frankvnk 0:636056c0b5e1 73 * @param x0,y0 start point
frankvnk 0:636056c0b5e1 74 * @param x1,y1 stop point
frankvnk 0:636056c0b5e1 75 * @param color 16 bit color
frankvnk 0:636056c0b5e1 76 *
frankvnk 0:636056c0b5e1 77 */
frankvnk 0:636056c0b5e1 78 void line(int x0, int y0, int x1, int y1, int colour);
frankvnk 0:636056c0b5e1 79
frankvnk 0:636056c0b5e1 80 /** draw a rect
frankvnk 0:636056c0b5e1 81 *
frankvnk 0:636056c0b5e1 82 * @param x0,y0 top left corner
frankvnk 0:636056c0b5e1 83 * @param w,h width and height
frankvnk 0:636056c0b5e1 84 * @param color 16 bit color
frankvnk 0:636056c0b5e1 85 * *
frankvnk 0:636056c0b5e1 86 */
frankvnk 0:636056c0b5e1 87 void rect(int x0, int y0, int w, int h, int colour);
frankvnk 0:636056c0b5e1 88
frankvnk 0:636056c0b5e1 89 /** draw a filled rect
frankvnk 0:636056c0b5e1 90 *
frankvnk 0:636056c0b5e1 91 * @param x0,y0 top left corner
frankvnk 0:636056c0b5e1 92 * @param w,h width and height
frankvnk 0:636056c0b5e1 93 * @param color 16 bit color
frankvnk 0:636056c0b5e1 94 *
frankvnk 0:636056c0b5e1 95 */
frankvnk 0:636056c0b5e1 96 void fillrect(int x0, int y0, int w, int h, int colour);
frankvnk 0:636056c0b5e1 97
frankvnk 0:636056c0b5e1 98 /** draw an ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
frankvnk 0:636056c0b5e1 99 *
frankvnk 0:636056c0b5e1 100 * @param xc,yc center point
frankvnk 0:636056c0b5e1 101 * @param a,b semi-major axis and semi-minor axis
frankvnk 0:636056c0b5e1 102 * @param color 16 bit color
frankvnk 0:636056c0b5e1 103 *
frankvnk 0:636056c0b5e1 104 */
frankvnk 0:636056c0b5e1 105 void draw_ellipse(int xc, int yc, int a, int b, unsigned int color);
frankvnk 0:636056c0b5e1 106
frankvnk 0:636056c0b5e1 107 /** draw a filled ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
frankvnk 0:636056c0b5e1 108 *
frankvnk 0:636056c0b5e1 109 * @param xc,yc center point
frankvnk 0:636056c0b5e1 110 * @param a,b semi-major axis and semi-minor axis
frankvnk 0:636056c0b5e1 111 * @param color 16 bit color
frankvnk 0:636056c0b5e1 112 *
frankvnk 0:636056c0b5e1 113 */
frankvnk 0:636056c0b5e1 114 void fill_ellipse(int xc, int yc, int a, int b, unsigned int color);
frankvnk 0:636056c0b5e1 115
frankvnk 0:636056c0b5e1 116 /** setup cursor position
frankvnk 0:636056c0b5e1 117 *
frankvnk 0:636056c0b5e1 118 * @param x x-position (top left)
frankvnk 0:636056c0b5e1 119 * @param y y-position
frankvnk 0:636056c0b5e1 120 */
frankvnk 0:636056c0b5e1 121 virtual void locate(int x, int y);
frankvnk 0:636056c0b5e1 122
frankvnk 0:636056c0b5e1 123 /** Fill the screen with _backgroun color
frankvnk 0:636056c0b5e1 124 *
frankvnk 0:636056c0b5e1 125 */
frankvnk 0:636056c0b5e1 126 virtual void cls (void);
frankvnk 0:636056c0b5e1 127
frankvnk 0:636056c0b5e1 128 /** Read ILI9320 ID
frankvnk 0:636056c0b5e1 129 *
frankvnk 0:636056c0b5e1 130 * @returns LCD ID code
frankvnk 0:636056c0b5e1 131 *
frankvnk 0:636056c0b5e1 132 */
frankvnk 0:636056c0b5e1 133 unsigned short Read_ID(void);
frankvnk 0:636056c0b5e1 134
frankvnk 0:636056c0b5e1 135 /** calculate the max number of char in a line
frankvnk 0:636056c0b5e1 136 *
frankvnk 0:636056c0b5e1 137 * @returns max columns
frankvnk 0:636056c0b5e1 138 * depends on actual font size
frankvnk 0:636056c0b5e1 139 *
frankvnk 0:636056c0b5e1 140 */
frankvnk 0:636056c0b5e1 141 virtual int columns(void);
frankvnk 0:636056c0b5e1 142
frankvnk 0:636056c0b5e1 143 /** calculate the max number of columns
frankvnk 0:636056c0b5e1 144 *
frankvnk 0:636056c0b5e1 145 * @returns max column
frankvnk 0:636056c0b5e1 146 * depends on actual font size
frankvnk 0:636056c0b5e1 147 *
frankvnk 0:636056c0b5e1 148 */
frankvnk 0:636056c0b5e1 149 virtual int rows(void);
frankvnk 0:636056c0b5e1 150
frankvnk 0:636056c0b5e1 151 /** put a char on the screen
frankvnk 0:636056c0b5e1 152 *
frankvnk 0:636056c0b5e1 153 * @param value char to print
frankvnk 0:636056c0b5e1 154 * @returns printed char
frankvnk 0:636056c0b5e1 155 *
frankvnk 0:636056c0b5e1 156 */
frankvnk 0:636056c0b5e1 157 virtual int _putc(int value);
frankvnk 0:636056c0b5e1 158
frankvnk 0:636056c0b5e1 159 /** draw a character on given position out of the active font to the TFT
frankvnk 0:636056c0b5e1 160 *
frankvnk 0:636056c0b5e1 161 * @param x x-position of char (top left)
frankvnk 0:636056c0b5e1 162 * @param y y-position
frankvnk 0:636056c0b5e1 163 * @param c char to print
frankvnk 0:636056c0b5e1 164 *
frankvnk 0:636056c0b5e1 165 */
frankvnk 0:636056c0b5e1 166 virtual void character(int x, int y, int c);
frankvnk 0:636056c0b5e1 167
frankvnk 0:636056c0b5e1 168 /** paint a bitmap on the TFT
frankvnk 0:636056c0b5e1 169 *
frankvnk 0:636056c0b5e1 170 * @param x,y : upper left corner
frankvnk 0:636056c0b5e1 171 * @param w width of bitmap
frankvnk 0:636056c0b5e1 172 * @param h high of bitmap
frankvnk 0:636056c0b5e1 173 * @param *bitmap pointer to the bitmap data
frankvnk 0:636056c0b5e1 174 *
frankvnk 0:636056c0b5e1 175 * bitmap format: 16 bit R5 G6 B5
frankvnk 0:636056c0b5e1 176 *
frankvnk 0:636056c0b5e1 177 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
frankvnk 0:636056c0b5e1 178 * use winhex to load this file and mark data stating at offset 0x46 to end
frankvnk 0:636056c0b5e1 179 * use edit -> copy block -> C Source to export C array
frankvnk 0:636056c0b5e1 180 * paste this array into your program
frankvnk 0:636056c0b5e1 181 *
frankvnk 0:636056c0b5e1 182 * define the array as static const unsigned char to put it into flash memory
frankvnk 0:636056c0b5e1 183 * cast the pointer to (unsigned char *) :
frankvnk 0:636056c0b5e1 184 * tft.Bitmap(10,40,309,50,(unsigned char *)scala);
frankvnk 0:636056c0b5e1 185 */
frankvnk 0:636056c0b5e1 186 void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap);
frankvnk 0:636056c0b5e1 187
frankvnk 0:636056c0b5e1 188
frankvnk 0:636056c0b5e1 189 /** paint a 16 bit BMP from local filesytem on the TFT (slow)
frankvnk 0:636056c0b5e1 190 *
frankvnk 0:636056c0b5e1 191 * @param x,y : upper left corner
frankvnk 0:636056c0b5e1 192 * @param *Name_BMP name of the BMP file
frankvnk 0:636056c0b5e1 193 * @returns 1 if bmp file was found and painted
frankvnk 0:636056c0b5e1 194 * @returns -1 if bmp file was not found
frankvnk 0:636056c0b5e1 195 * @returns -2 if bmp file is not 16bit
frankvnk 0:636056c0b5e1 196 * @returns -3 if bmp file is to big for screen
frankvnk 0:636056c0b5e1 197 * @returns -4 if buffer malloc go wrong
frankvnk 0:636056c0b5e1 198 *
frankvnk 0:636056c0b5e1 199 * bitmap format: 16 bit R5 G6 B5
frankvnk 0:636056c0b5e1 200 *
frankvnk 0:636056c0b5e1 201 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
frankvnk 0:636056c0b5e1 202 * copy to internal file system
frankvnk 0:636056c0b5e1 203 *
frankvnk 0:636056c0b5e1 204 */
frankvnk 0:636056c0b5e1 205
frankvnk 0:636056c0b5e1 206 int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP);
frankvnk 0:636056c0b5e1 207
frankvnk 0:636056c0b5e1 208
frankvnk 0:636056c0b5e1 209
frankvnk 0:636056c0b5e1 210 /** select the font to use
frankvnk 0:636056c0b5e1 211 *
frankvnk 0:636056c0b5e1 212 * @param f pointer to font array
frankvnk 0:636056c0b5e1 213 *
frankvnk 0:636056c0b5e1 214 * font array can created with GLCD Font Creator from http://www.mikroe.com
frankvnk 0:636056c0b5e1 215 * you have to add 4 parameter at the beginning of the font array to use:
frankvnk 0:636056c0b5e1 216 * - the number of byte / char
frankvnk 0:636056c0b5e1 217 * - the vertial size in pixel
frankvnk 0:636056c0b5e1 218 * - the horizontal size in pixel
frankvnk 0:636056c0b5e1 219 * - the number of byte per vertical line
frankvnk 0:636056c0b5e1 220 * you also have to change the array to char[]
frankvnk 0:636056c0b5e1 221 *
frankvnk 0:636056c0b5e1 222 */
frankvnk 0:636056c0b5e1 223 void set_font(unsigned char* f);
frankvnk 0:636056c0b5e1 224
frankvnk 0:636056c0b5e1 225 /** Set the orientation of the screen
frankvnk 0:636056c0b5e1 226 * x,y: 0,0 is always top left
frankvnk 0:636056c0b5e1 227 *
frankvnk 0:636056c0b5e1 228 * @param o direction to use the screen (0-3) 90� Steps
frankvnk 0:636056c0b5e1 229 *
frankvnk 0:636056c0b5e1 230 */
frankvnk 0:636056c0b5e1 231 void set_orientation(unsigned int o);
frankvnk 0:636056c0b5e1 232 void mod_orientation(void);
frankvnk 0:636056c0b5e1 233 SPI _spi;
frankvnk 0:636056c0b5e1 234 DigitalOut _cs;
frankvnk 0:636056c0b5e1 235 DigitalOut _reset;
frankvnk 0:636056c0b5e1 236 unsigned char* font;
frankvnk 0:636056c0b5e1 237
frankvnk 0:636056c0b5e1 238
frankvnk 0:636056c0b5e1 239
frankvnk 0:636056c0b5e1 240 // ------------------ PROTECTED PART ------------------
frankvnk 0:636056c0b5e1 241 protected:
frankvnk 0:636056c0b5e1 242
frankvnk 0:636056c0b5e1 243 /** Set draw window region to whole screen
frankvnk 0:636056c0b5e1 244 *
frankvnk 0:636056c0b5e1 245 */
frankvnk 0:636056c0b5e1 246 void WindowMax (void);
frankvnk 0:636056c0b5e1 247
frankvnk 0:636056c0b5e1 248
frankvnk 0:636056c0b5e1 249 /** draw a horizontal line
frankvnk 0:636056c0b5e1 250 *
frankvnk 0:636056c0b5e1 251 * @param x0 horizontal start
frankvnk 0:636056c0b5e1 252 * @param x1 horizontal stop
frankvnk 0:636056c0b5e1 253 * @param y vertical position
frankvnk 0:636056c0b5e1 254 * @param color 16 bit color
frankvnk 0:636056c0b5e1 255 *
frankvnk 0:636056c0b5e1 256 */
frankvnk 0:636056c0b5e1 257 void hline(int x0, int x1, int y, int colour);
frankvnk 0:636056c0b5e1 258
frankvnk 0:636056c0b5e1 259 /** draw a vertical line
frankvnk 0:636056c0b5e1 260 *
frankvnk 0:636056c0b5e1 261 * @param x horizontal position
frankvnk 0:636056c0b5e1 262 * @param y0 vertical start
frankvnk 0:636056c0b5e1 263 * @param y1 vertical stop
frankvnk 0:636056c0b5e1 264 * @param color 16 bit color
frankvnk 0:636056c0b5e1 265 */
frankvnk 0:636056c0b5e1 266 void vline(int y0, int y1, int x, int colour);
frankvnk 0:636056c0b5e1 267
frankvnk 0:636056c0b5e1 268 /** Set draw window region
frankvnk 0:636056c0b5e1 269 *
frankvnk 0:636056c0b5e1 270 * @param x horizontal position
frankvnk 0:636056c0b5e1 271 * @param y vertical position
frankvnk 0:636056c0b5e1 272 * @param w window width in pixel
frankvnk 0:636056c0b5e1 273 * @param h window height in pixels
frankvnk 0:636056c0b5e1 274 */
frankvnk 0:636056c0b5e1 275 void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h);
frankvnk 0:636056c0b5e1 276
frankvnk 0:636056c0b5e1 277
frankvnk 0:636056c0b5e1 278 /** Init the ILI9320 controller
frankvnk 0:636056c0b5e1 279 *
frankvnk 0:636056c0b5e1 280 */
frankvnk 0:636056c0b5e1 281 void tft_reset();
frankvnk 0:636056c0b5e1 282
frankvnk 0:636056c0b5e1 283 /** Write data to the LCD controller
frankvnk 0:636056c0b5e1 284 *
frankvnk 0:636056c0b5e1 285 * @param dat data written to LCD controller
frankvnk 0:636056c0b5e1 286 *
frankvnk 0:636056c0b5e1 287 */
frankvnk 0:636056c0b5e1 288 void wr_dat(unsigned short value);
frankvnk 0:636056c0b5e1 289
frankvnk 0:636056c0b5e1 290 /** Start data sequence to the LCD controller
frankvnk 0:636056c0b5e1 291 *
frankvnk 0:636056c0b5e1 292 */
frankvnk 0:636056c0b5e1 293 //void wr_dat_start();
frankvnk 0:636056c0b5e1 294 void wr_dat_start(void);
frankvnk 0:636056c0b5e1 295
frankvnk 0:636056c0b5e1 296 /** write data only to the LCD controller
frankvnk 0:636056c0b5e1 297 *
frankvnk 0:636056c0b5e1 298 * @param data to be written
frankvnk 0:636056c0b5e1 299 * *
frankvnk 0:636056c0b5e1 300 */
frankvnk 0:636056c0b5e1 301 void wr_dat_only (unsigned short dat);
frankvnk 0:636056c0b5e1 302
frankvnk 0:636056c0b5e1 303 /** Write a command the LCD controller
frankvnk 0:636056c0b5e1 304 *
frankvnk 0:636056c0b5e1 305 * @param cmd: command to be written
frankvnk 0:636056c0b5e1 306 *
frankvnk 0:636056c0b5e1 307 */
frankvnk 0:636056c0b5e1 308 void wr_cmd(unsigned char value);
frankvnk 0:636056c0b5e1 309
frankvnk 0:636056c0b5e1 310 /** Read data from the LCD controller
frankvnk 0:636056c0b5e1 311 *
frankvnk 0:636056c0b5e1 312 * @returns data from LCD controller
frankvnk 0:636056c0b5e1 313 *
frankvnk 0:636056c0b5e1 314 */
frankvnk 0:636056c0b5e1 315 unsigned short rd_dat(void);
frankvnk 0:636056c0b5e1 316
frankvnk 0:636056c0b5e1 317 /** Write a value to the to a LCD register
frankvnk 0:636056c0b5e1 318 *
frankvnk 0:636056c0b5e1 319 * @param reg register to be written
frankvnk 0:636056c0b5e1 320 * @param val data to be written
frankvnk 0:636056c0b5e1 321 */
frankvnk 0:636056c0b5e1 322 void wr_reg (unsigned char reg, unsigned short val);
frankvnk 0:636056c0b5e1 323
frankvnk 0:636056c0b5e1 324 /** Read a LCD register
frankvnk 0:636056c0b5e1 325 *
frankvnk 0:636056c0b5e1 326 * @param reg register to be read
frankvnk 0:636056c0b5e1 327 * @returns value of the register
frankvnk 0:636056c0b5e1 328 */
frankvnk 0:636056c0b5e1 329 unsigned short rd_reg (unsigned char reg);
frankvnk 0:636056c0b5e1 330
frankvnk 0:636056c0b5e1 331 void SetCursor( unsigned short Xpos, unsigned short Ypos );
frankvnk 0:636056c0b5e1 332
frankvnk 0:636056c0b5e1 333 unsigned int orientation;
frankvnk 0:636056c0b5e1 334 unsigned int char_x;
frankvnk 0:636056c0b5e1 335 unsigned int char_y;
frankvnk 0:636056c0b5e1 336
frankvnk 0:636056c0b5e1 337 };
frankvnk 0:636056c0b5e1 338
frankvnk 0:636056c0b5e1 339 #endif