Library for Mini-DK board
Dependents: LPC1768_Mini-DK_EasyWeb_DM9161 LPC1768_Mini-DK LPC1768_Mini-DK
Fork of Mini-DK by
Mini-DK board overview (Micro SD connector is at the bottom side)
One serial interface , uses CP2102 (USB to RS232 interface, support ISP download )
RJ45-10/100M Ethernet network interface (Ethernet PHY: DM9161)
2.8 inch TFT color LCD interface (SPI interface or 16Bit parallel interface)
Touch panel controller XPT2046 (ADS7843 compatible)
USB 2.0 interface, USB host and USB Device interface.
TF SD / MMC card (SPI) interface.
Two user buttons, One Reset button and ISP button , One INT0 button, two user-programmable LED lights
Serial ISP download, Standard 20-pin JTAG download simulation debugging interface.
Selection between external 5V power supply or USB 5V supply.
Board size: 95mm * 78mm
All IO available on extension connectors
04/01/13
Erik Olieman (http://mbed.org/users/Sissors/) joined the code development for the Mini-DK board.
Thanks to his input, we were able to obtain a tremendous speed gain, remove warnings, ...
An overview of all modifications is stored in modifs.h
The old page (http://mbed.org/users/frankvnk/code/LPC1768_Mini-DK/) contains the demo code.
IMPORTANT : Due to a change in the mbed libraries (Stream()), we cannot use the printf instruction - we need to use <SPI_TFT>.printf (example - see main.cpp in http://mbed.org/users/frankvnk/code/LPC1768_Mini-DK/)
WARNING: filetoflash (SD to CPU flash)
The SPI_TFT library contains an option to copy an image from the SD card to the CPU flash memory. This allows you to use an image as background without speed loss when writing other text and graphics.
By default, this option is enabled.
It can be disabled by uncommenting the #define mentioned below in Mini_DK.h:
#define NO_FLASH_BUFFER
Since the flash memory has limited write endurance, DO NOT use this feature when you intend to read multiple images from the SD card (eg: when used as a photo frame).
14/01/13
A newer version of the Mini-DK has been released by the manufacturer: Mini-DK2. They replaced the DM9161 PHY with a LAN8720A PHY and better buttons are fitted on the board. All other hardware remains the same. Code for this PHY is available from the NXP MCU SW application team. This allows us to use the mbed 'EthernetInterface' library with little modifications. Further info - see http://mbed.org/forum/mbed/topic/3684/?page=1#comment-18473.
Notes:
The code in 'lpc_phy_lan8720.c' uses 'msDelay' - needs to be replaced with 'osDelay'.
A custom MAC address can be defined using following code:
extern "C" void mbed_mac_address(char * mac) { // define your own MAC Address mac[0] = 0x00; mac[1] = 0x01; mac[2] = 0x02; mac[3] = 0x03; mac[4] = 0x04; mac[5] = 0x05; };
SPI_TFT/SPI_TFT.h@16:be1a10246234, 2013-01-08 (annotated)
- Committer:
- Sissors
- Date:
- Tue Jan 08 17:39:50 2013 +0000
- Revision:
- 16:be1a10246234
- Parent:
- 13:5f332321a40c
- Child:
- 17:66c4e84d8571
Added option to define NO_FLASH_BUFFER to disable flash buffer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frankvnk | 7:ffdd4e75b366 | 1 | /************************************************************************************************** |
frankvnk | 7:ffdd4e75b366 | 2 | ***** ***** |
frankvnk | 7:ffdd4e75b366 | 3 | ***** Name: SPI_TFT.h ***** |
frankvnk | 7:ffdd4e75b366 | 4 | ***** Ver.: 1.0 ***** |
frankvnk | 7:ffdd4e75b366 | 5 | ***** Date: 04/01/2013 ***** |
frankvnk | 7:ffdd4e75b366 | 6 | ***** Auth: Frank Vannieuwkerke ***** |
frankvnk | 7:ffdd4e75b366 | 7 | ***** Erik Olieman ***** |
frankvnk | 7:ffdd4e75b366 | 8 | ***** Func: library for 240*320 pixel TFT with ILI9320 LCD Controller ***** |
frankvnk | 7:ffdd4e75b366 | 9 | ***** ***** |
frankvnk | 7:ffdd4e75b366 | 10 | ***** Rewrite from Peter Drescher code - http://mbed.org/cookbook/SPI-driven-QVGA-TFT ***** |
frankvnk | 7:ffdd4e75b366 | 11 | ***** ***** |
frankvnk | 7:ffdd4e75b366 | 12 | **************************************************************************************************/ |
frankvnk | 2:d0acbd263ec7 | 13 | |
frankvnk | 2:d0acbd263ec7 | 14 | #ifndef MBED_SPI_TFT_H |
frankvnk | 2:d0acbd263ec7 | 15 | #define MBED_SPI_TFT_H |
frankvnk | 2:d0acbd263ec7 | 16 | |
Sissors | 16:be1a10246234 | 17 | /* This library allows you to store a background image on the local flash memory of the microcontroller, |
Sissors | 16:be1a10246234 | 18 | from any filesystem (such as SD cards). This allows very fast writing of this specific image, and it allows |
Sissors | 16:be1a10246234 | 19 | you to write text in a nice way over the image. However it does cost the last 5 flash sectors of the LPC1768. |
Sissors | 16:be1a10246234 | 20 | Generally that won't be a problem, if it is a problem, add #define NO_FLASH_BUFFER before including this file. |
Sissors | 16:be1a10246234 | 21 | */ |
Sissors | 11:31a09b75ea23 | 22 | |
frankvnk | 2:d0acbd263ec7 | 23 | |
frankvnk | 2:d0acbd263ec7 | 24 | #include "GraphicsDisplay.h" |
Sissors | 6:b547fb6c1095 | 25 | #include "BurstSPI.h" |
frankvnk | 2:d0acbd263ec7 | 26 | #include "mbed.h" |
frankvnk | 2:d0acbd263ec7 | 27 | |
Sissors | 16:be1a10246234 | 28 | #ifndef NO_FLASH_BUFFER |
Sissors | 11:31a09b75ea23 | 29 | #include "IAP.h" |
Sissors | 11:31a09b75ea23 | 30 | #endif |
Sissors | 11:31a09b75ea23 | 31 | |
Sissors | 6:b547fb6c1095 | 32 | |
frankvnk | 2:d0acbd263ec7 | 33 | #define incx() x++, dxt += d2xt, t += dxt |
frankvnk | 2:d0acbd263ec7 | 34 | #define incy() y--, dyt += d2yt, t += dyt |
frankvnk | 2:d0acbd263ec7 | 35 | |
frankvnk | 2:d0acbd263ec7 | 36 | #define SPI_F_LO 10000000 |
frankvnk | 2:d0acbd263ec7 | 37 | #define SPI_F_HI 48000000 |
frankvnk | 2:d0acbd263ec7 | 38 | |
frankvnk | 2:d0acbd263ec7 | 39 | /* some RGB565 color definitions */ |
frankvnk | 2:d0acbd263ec7 | 40 | #define Black 0x0000 /* 0, 0, 0 */ |
frankvnk | 2:d0acbd263ec7 | 41 | #define Navy 0x000F /* 0, 0, 128 */ |
frankvnk | 2:d0acbd263ec7 | 42 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ |
frankvnk | 2:d0acbd263ec7 | 43 | #define DarkCyan 0x03EF /* 0, 128, 128 */ |
frankvnk | 2:d0acbd263ec7 | 44 | #define Maroon 0x7800 /* 128, 0, 0 */ |
frankvnk | 2:d0acbd263ec7 | 45 | #define Purple 0x780F /* 128, 0, 128 */ |
frankvnk | 2:d0acbd263ec7 | 46 | #define Olive 0x7BE0 /* 128, 128, 0 */ |
frankvnk | 2:d0acbd263ec7 | 47 | #define LightGrey 0xC618 /* 192, 192, 192 */ |
frankvnk | 2:d0acbd263ec7 | 48 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ |
frankvnk | 2:d0acbd263ec7 | 49 | #define Blue 0x001F /* 0, 0, 255 */ |
frankvnk | 2:d0acbd263ec7 | 50 | #define Green 0x07E0 /* 0, 255, 0 */ |
frankvnk | 2:d0acbd263ec7 | 51 | #define Cyan 0x07FF /* 0, 255, 255 */ |
frankvnk | 2:d0acbd263ec7 | 52 | #define Red 0xF800 /* 255, 0, 0 */ |
frankvnk | 2:d0acbd263ec7 | 53 | #define Magenta 0xF81F /* 255, 0, 255 */ |
frankvnk | 2:d0acbd263ec7 | 54 | #define Yellow 0xFFE0 /* 255, 255, 0 */ |
frankvnk | 2:d0acbd263ec7 | 55 | #define White 0xFFFF /* 255, 255, 255 */ |
frankvnk | 2:d0acbd263ec7 | 56 | #define Orange 0xFD20 /* 255, 165, 0 */ |
frankvnk | 2:d0acbd263ec7 | 57 | #define GreenYellow 0xAFE5 /* 173, 255, 47 */ |
frankvnk | 2:d0acbd263ec7 | 58 | |
frankvnk | 2:d0acbd263ec7 | 59 | class SPI_TFT : public GraphicsDisplay { |
frankvnk | 2:d0acbd263ec7 | 60 | public: |
frankvnk | 2:d0acbd263ec7 | 61 | |
frankvnk | 2:d0acbd263ec7 | 62 | /** Create a SPI_TFT object connected to SPI and two pins |
frankvnk | 2:d0acbd263ec7 | 63 | * |
frankvnk | 2:d0acbd263ec7 | 64 | * @param mosi,miso,sclk SPI |
frankvnk | 2:d0acbd263ec7 | 65 | * @param cs pin connected to CS of display |
frankvnk | 2:d0acbd263ec7 | 66 | * @param reset pin connected to RESET of display |
frankvnk | 2:d0acbd263ec7 | 67 | * |
frankvnk | 2:d0acbd263ec7 | 68 | */ |
frankvnk | 2:d0acbd263ec7 | 69 | SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name ="TFT"); |
frankvnk | 2:d0acbd263ec7 | 70 | |
frankvnk | 2:d0acbd263ec7 | 71 | /** Write a value to the to a LCD register |
frankvnk | 2:d0acbd263ec7 | 72 | * |
frankvnk | 2:d0acbd263ec7 | 73 | * @param reg register to be written |
frankvnk | 2:d0acbd263ec7 | 74 | * @param val data to be written |
frankvnk | 2:d0acbd263ec7 | 75 | */ |
frankvnk | 2:d0acbd263ec7 | 76 | void wr_reg (unsigned char reg, unsigned short val); |
frankvnk | 2:d0acbd263ec7 | 77 | |
frankvnk | 7:ffdd4e75b366 | 78 | /** Get the width of the screen in pixels |
frankvnk | 2:d0acbd263ec7 | 79 | * |
frankvnk | 2:d0acbd263ec7 | 80 | * @param |
frankvnk | 7:ffdd4e75b366 | 81 | * @returns width of screen in pixels |
frankvnk | 2:d0acbd263ec7 | 82 | * |
frankvnk | 2:d0acbd263ec7 | 83 | */ |
frankvnk | 2:d0acbd263ec7 | 84 | virtual int width(); |
frankvnk | 2:d0acbd263ec7 | 85 | |
frankvnk | 7:ffdd4e75b366 | 86 | /** Get the height of the screen in pixels |
frankvnk | 2:d0acbd263ec7 | 87 | * |
frankvnk | 7:ffdd4e75b366 | 88 | * @returns height of screen in pixels |
frankvnk | 2:d0acbd263ec7 | 89 | * |
frankvnk | 2:d0acbd263ec7 | 90 | */ |
frankvnk | 2:d0acbd263ec7 | 91 | virtual int height(); |
frankvnk | 2:d0acbd263ec7 | 92 | |
frankvnk | 2:d0acbd263ec7 | 93 | /** Draw a pixel at x,y with color |
frankvnk | 2:d0acbd263ec7 | 94 | * |
frankvnk | 7:ffdd4e75b366 | 95 | * @param x (horizontal position) |
frankvnk | 7:ffdd4e75b366 | 96 | * @param y (vertical position) |
frankvnk | 7:ffdd4e75b366 | 97 | * @param color (16 bit pixel color) |
frankvnk | 2:d0acbd263ec7 | 98 | */ |
frankvnk | 2:d0acbd263ec7 | 99 | virtual void pixel(int x, int y,int colour); |
frankvnk | 2:d0acbd263ec7 | 100 | |
frankvnk | 2:d0acbd263ec7 | 101 | /** Set draw window region to whole screen |
frankvnk | 2:d0acbd263ec7 | 102 | * |
frankvnk | 2:d0acbd263ec7 | 103 | */ |
frankvnk | 2:d0acbd263ec7 | 104 | void WindowMax (void); |
frankvnk | 2:d0acbd263ec7 | 105 | |
frankvnk | 2:d0acbd263ec7 | 106 | /** draw a 1 pixel line |
frankvnk | 2:d0acbd263ec7 | 107 | * |
frankvnk | 2:d0acbd263ec7 | 108 | * @param x0,y0 start point |
frankvnk | 2:d0acbd263ec7 | 109 | * @param x1,y1 stop point |
frankvnk | 2:d0acbd263ec7 | 110 | * @param color 16 bit color |
frankvnk | 2:d0acbd263ec7 | 111 | * |
frankvnk | 2:d0acbd263ec7 | 112 | */ |
frankvnk | 2:d0acbd263ec7 | 113 | void line(int x0, int y0, int x1, int y1, int colour); |
frankvnk | 2:d0acbd263ec7 | 114 | |
frankvnk | 2:d0acbd263ec7 | 115 | /** draw a rect |
frankvnk | 2:d0acbd263ec7 | 116 | * |
frankvnk | 2:d0acbd263ec7 | 117 | * @param x0,y0 top left corner |
frankvnk | 2:d0acbd263ec7 | 118 | * @param w,h width and height |
frankvnk | 2:d0acbd263ec7 | 119 | * @param color 16 bit color |
frankvnk | 2:d0acbd263ec7 | 120 | * * |
frankvnk | 2:d0acbd263ec7 | 121 | */ |
frankvnk | 2:d0acbd263ec7 | 122 | void rect(int x0, int y0, int w, int h, int colour); |
frankvnk | 2:d0acbd263ec7 | 123 | |
frankvnk | 2:d0acbd263ec7 | 124 | /** draw a filled rect |
frankvnk | 2:d0acbd263ec7 | 125 | * |
frankvnk | 2:d0acbd263ec7 | 126 | * @param x0,y0 top left corner |
frankvnk | 2:d0acbd263ec7 | 127 | * @param w,h width and height |
frankvnk | 2:d0acbd263ec7 | 128 | * @param color 16 bit color |
frankvnk | 2:d0acbd263ec7 | 129 | * |
frankvnk | 2:d0acbd263ec7 | 130 | */ |
frankvnk | 2:d0acbd263ec7 | 131 | void fillrect(int x0, int y0, int w, int h, int colour); |
frankvnk | 2:d0acbd263ec7 | 132 | |
frankvnk | 2:d0acbd263ec7 | 133 | /** draw an ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html |
frankvnk | 2:d0acbd263ec7 | 134 | * |
frankvnk | 2:d0acbd263ec7 | 135 | * @param xc,yc center point |
frankvnk | 2:d0acbd263ec7 | 136 | * @param a,b semi-major axis and semi-minor axis |
frankvnk | 2:d0acbd263ec7 | 137 | * @param color 16 bit color |
frankvnk | 2:d0acbd263ec7 | 138 | * |
frankvnk | 2:d0acbd263ec7 | 139 | */ |
frankvnk | 2:d0acbd263ec7 | 140 | void draw_ellipse(int xc, int yc, int a, int b, unsigned int color); |
frankvnk | 2:d0acbd263ec7 | 141 | |
frankvnk | 2:d0acbd263ec7 | 142 | /** draw a filled ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html |
frankvnk | 2:d0acbd263ec7 | 143 | * |
frankvnk | 2:d0acbd263ec7 | 144 | * @param xc,yc center point |
frankvnk | 2:d0acbd263ec7 | 145 | * @param a,b semi-major axis and semi-minor axis |
frankvnk | 2:d0acbd263ec7 | 146 | * @param color 16 bit color |
frankvnk | 2:d0acbd263ec7 | 147 | * |
frankvnk | 2:d0acbd263ec7 | 148 | */ |
frankvnk | 2:d0acbd263ec7 | 149 | void fill_ellipse(int xc, int yc, int a, int b, unsigned int color); |
frankvnk | 2:d0acbd263ec7 | 150 | |
frankvnk | 2:d0acbd263ec7 | 151 | /** setup cursor position |
frankvnk | 2:d0acbd263ec7 | 152 | * |
frankvnk | 2:d0acbd263ec7 | 153 | * @param x x-position (top left) |
frankvnk | 2:d0acbd263ec7 | 154 | * @param y y-position |
frankvnk | 2:d0acbd263ec7 | 155 | */ |
frankvnk | 2:d0acbd263ec7 | 156 | virtual void locate(int x, int y); |
frankvnk | 2:d0acbd263ec7 | 157 | |
frankvnk | 7:ffdd4e75b366 | 158 | /** Fill the screen with _background color |
frankvnk | 2:d0acbd263ec7 | 159 | * |
frankvnk | 2:d0acbd263ec7 | 160 | */ |
frankvnk | 2:d0acbd263ec7 | 161 | virtual void cls (void); |
frankvnk | 2:d0acbd263ec7 | 162 | |
frankvnk | 2:d0acbd263ec7 | 163 | /** Read ILI9320 ID |
frankvnk | 2:d0acbd263ec7 | 164 | * |
frankvnk | 2:d0acbd263ec7 | 165 | * @returns LCD ID code |
frankvnk | 2:d0acbd263ec7 | 166 | * |
frankvnk | 2:d0acbd263ec7 | 167 | */ |
frankvnk | 2:d0acbd263ec7 | 168 | unsigned short Read_ID(void); |
frankvnk | 2:d0acbd263ec7 | 169 | |
frankvnk | 2:d0acbd263ec7 | 170 | /** calculate the max number of char in a line |
frankvnk | 2:d0acbd263ec7 | 171 | * |
frankvnk | 2:d0acbd263ec7 | 172 | * @returns max columns |
frankvnk | 2:d0acbd263ec7 | 173 | * depends on actual font size |
frankvnk | 2:d0acbd263ec7 | 174 | * |
frankvnk | 2:d0acbd263ec7 | 175 | */ |
frankvnk | 2:d0acbd263ec7 | 176 | virtual int columns(void); |
frankvnk | 2:d0acbd263ec7 | 177 | |
frankvnk | 7:ffdd4e75b366 | 178 | /** calculate the max number of rows |
frankvnk | 2:d0acbd263ec7 | 179 | * |
frankvnk | 7:ffdd4e75b366 | 180 | * @returns max rows |
frankvnk | 2:d0acbd263ec7 | 181 | * depends on actual font size |
frankvnk | 2:d0acbd263ec7 | 182 | * |
frankvnk | 2:d0acbd263ec7 | 183 | */ |
frankvnk | 2:d0acbd263ec7 | 184 | virtual int rows(void); |
frankvnk | 2:d0acbd263ec7 | 185 | |
frankvnk | 2:d0acbd263ec7 | 186 | /** put a char on the screen |
frankvnk | 2:d0acbd263ec7 | 187 | * |
frankvnk | 2:d0acbd263ec7 | 188 | * @param value char to print |
frankvnk | 2:d0acbd263ec7 | 189 | * @returns printed char |
frankvnk | 2:d0acbd263ec7 | 190 | * |
frankvnk | 2:d0acbd263ec7 | 191 | */ |
frankvnk | 2:d0acbd263ec7 | 192 | virtual int _putc(int value); |
frankvnk | 2:d0acbd263ec7 | 193 | |
frankvnk | 2:d0acbd263ec7 | 194 | /** draw a character on given position out of the active font to the TFT |
frankvnk | 2:d0acbd263ec7 | 195 | * |
frankvnk | 2:d0acbd263ec7 | 196 | * @param x x-position of char (top left) |
frankvnk | 2:d0acbd263ec7 | 197 | * @param y y-position |
frankvnk | 2:d0acbd263ec7 | 198 | * @param c char to print |
frankvnk | 2:d0acbd263ec7 | 199 | * |
frankvnk | 2:d0acbd263ec7 | 200 | */ |
frankvnk | 2:d0acbd263ec7 | 201 | virtual void character(int x, int y, int c); |
frankvnk | 2:d0acbd263ec7 | 202 | |
frankvnk | 2:d0acbd263ec7 | 203 | /** paint a bitmap on the TFT |
frankvnk | 2:d0acbd263ec7 | 204 | * |
frankvnk | 2:d0acbd263ec7 | 205 | * @param x,y : upper left corner |
frankvnk | 2:d0acbd263ec7 | 206 | * @param w width of bitmap |
frankvnk | 2:d0acbd263ec7 | 207 | * @param h high of bitmap |
frankvnk | 2:d0acbd263ec7 | 208 | * @param *bitmap pointer to the bitmap data |
frankvnk | 2:d0acbd263ec7 | 209 | * |
frankvnk | 2:d0acbd263ec7 | 210 | * bitmap format: 16 bit R5 G6 B5 |
frankvnk | 2:d0acbd263ec7 | 211 | * |
frankvnk | 2:d0acbd263ec7 | 212 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
frankvnk | 2:d0acbd263ec7 | 213 | * use winhex to load this file and mark data stating at offset 0x46 to end |
frankvnk | 2:d0acbd263ec7 | 214 | * use edit -> copy block -> C Source to export C array |
frankvnk | 2:d0acbd263ec7 | 215 | * paste this array into your program |
frankvnk | 2:d0acbd263ec7 | 216 | * |
frankvnk | 2:d0acbd263ec7 | 217 | * define the array as static const unsigned char to put it into flash memory |
frankvnk | 2:d0acbd263ec7 | 218 | * cast the pointer to (unsigned char *) : |
frankvnk | 2:d0acbd263ec7 | 219 | * tft.Bitmap(10,40,309,50,(unsigned char *)scala); |
frankvnk | 2:d0acbd263ec7 | 220 | */ |
Sissors | 11:31a09b75ea23 | 221 | void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *Name_BMP); |
frankvnk | 2:d0acbd263ec7 | 222 | |
frankvnk | 2:d0acbd263ec7 | 223 | |
Sissors | 9:742d15898b2b | 224 | /** paint a BMP (16/24 bit) from filesytem on the TFT (slow) |
Sissors | 9:742d15898b2b | 225 | * |
Sissors | 9:742d15898b2b | 226 | * The 16-bit format is RGB-565. Using 16-bit is faster than 24-bit, however every program can |
Sissors | 9:742d15898b2b | 227 | * output 24 bit BMPs (including MS paint), while it is hard to get them in the correct 16-bit format. |
frankvnk | 2:d0acbd263ec7 | 228 | * |
frankvnk | 2:d0acbd263ec7 | 229 | * @param x,y : upper left corner |
Sissors | 9:742d15898b2b | 230 | * @param *Name_BMP location of the BMP file (for example "/sd/test.bmp") |
Sissors | 12:7213a0dded52 | 231 | * @returns 1 if bmp file was found and stored |
Sissors | 12:7213a0dded52 | 232 | * @returns 0 if file was not found |
Sissors | 12:7213a0dded52 | 233 | * @returns -1 if file was not a bmp |
Sissors | 9:742d15898b2b | 234 | * @returns -2 if bmp file is not 16/24bit |
Sissors | 12:7213a0dded52 | 235 | * @returns -3 if bmp file is wrong for screen |
frankvnk | 7:ffdd4e75b366 | 236 | * @returns -4 if buffer malloc goes wrong |
frankvnk | 2:d0acbd263ec7 | 237 | * |
frankvnk | 2:d0acbd263ec7 | 238 | */ |
frankvnk | 2:d0acbd263ec7 | 239 | |
Sissors | 9:742d15898b2b | 240 | int Bitmap(unsigned int x, unsigned int y, const char *Name_BMP); |
frankvnk | 2:d0acbd263ec7 | 241 | |
frankvnk | 2:d0acbd263ec7 | 242 | |
frankvnk | 2:d0acbd263ec7 | 243 | |
frankvnk | 2:d0acbd263ec7 | 244 | /** select the font to use |
frankvnk | 2:d0acbd263ec7 | 245 | * |
frankvnk | 2:d0acbd263ec7 | 246 | * @param f pointer to font array |
frankvnk | 2:d0acbd263ec7 | 247 | * |
frankvnk | 7:ffdd4e75b366 | 248 | * font array can be created with GLCD Font Creator from http://www.mikroe.com |
frankvnk | 2:d0acbd263ec7 | 249 | * you have to add 4 parameter at the beginning of the font array to use: |
frankvnk | 7:ffdd4e75b366 | 250 | * - the number of bytes / char |
frankvnk | 7:ffdd4e75b366 | 251 | * - the vertial size in pixels |
frankvnk | 7:ffdd4e75b366 | 252 | * - the horizontal size in pixels |
frankvnk | 7:ffdd4e75b366 | 253 | * - the number of bytes per vertical line |
frankvnk | 2:d0acbd263ec7 | 254 | * you also have to change the array to char[] |
frankvnk | 2:d0acbd263ec7 | 255 | * |
frankvnk | 2:d0acbd263ec7 | 256 | */ |
frankvnk | 2:d0acbd263ec7 | 257 | void set_font(unsigned char* f); |
frankvnk | 2:d0acbd263ec7 | 258 | |
frankvnk | 2:d0acbd263ec7 | 259 | /** Set the orientation of the screen |
frankvnk | 2:d0acbd263ec7 | 260 | * x,y: 0,0 is always top left |
frankvnk | 2:d0acbd263ec7 | 261 | * |
frankvnk | 2:d0acbd263ec7 | 262 | * @param o direction to use the screen (0-3) 90� Steps |
frankvnk | 2:d0acbd263ec7 | 263 | * |
frankvnk | 2:d0acbd263ec7 | 264 | */ |
frankvnk | 2:d0acbd263ec7 | 265 | void set_orientation(unsigned int o); |
frankvnk | 7:ffdd4e75b366 | 266 | |
frankvnk | 7:ffdd4e75b366 | 267 | |
frankvnk | 7:ffdd4e75b366 | 268 | /** Modify the orientation of the screen |
frankvnk | 7:ffdd4e75b366 | 269 | * x,y: 0,0 is always top left |
frankvnk | 7:ffdd4e75b366 | 270 | * |
frankvnk | 7:ffdd4e75b366 | 271 | * @param none |
frankvnk | 7:ffdd4e75b366 | 272 | * |
frankvnk | 7:ffdd4e75b366 | 273 | * ILI9320 limitation: The orientation can only be used with a window command (registers 0x50..0x53) |
frankvnk | 7:ffdd4e75b366 | 274 | * |
frankvnk | 7:ffdd4e75b366 | 275 | * reg 03h (Entry Mode) : BGR = 1 - ORG = 1 - ID0, ID1 and AM are set according to the orientation variable. |
frankvnk | 7:ffdd4e75b366 | 276 | * IMPORTANT : when ORG = 1, the GRAM writing direction follows the orientation (ID0, ID1, AM bits) |
frankvnk | 7:ffdd4e75b366 | 277 | * AND we need to use the window command (reg 50h..53h) to write to an area on the display |
frankvnk | 7:ffdd4e75b366 | 278 | * because we cannot change reg 20h and 21h to set the GRAM address (they both remain at 00h). |
frankvnk | 7:ffdd4e75b366 | 279 | * This means that the pixel routine does not work when ORG = 1. |
frankvnk | 7:ffdd4e75b366 | 280 | * Routines relying on the pixel routine first need to set reg 03h = 0x1030 |
frankvnk | 7:ffdd4e75b366 | 281 | * (cls, circle and line do so) AND need to write the data according to the orientation variable. |
frankvnk | 7:ffdd4e75b366 | 282 | */ |
frankvnk | 2:d0acbd263ec7 | 283 | void mod_orientation(void); |
Sissors | 11:31a09b75ea23 | 284 | |
Sissors | 16:be1a10246234 | 285 | #ifndef NO_FLASH_BUFFER |
Sissors | 11:31a09b75ea23 | 286 | /** Move an image to the background buffer |
Sissors | 11:31a09b75ea23 | 287 | * |
Sissors | 11:31a09b75ea23 | 288 | * The image must fit exactly on the screen (240x320). This function takes quite some time, depending on source filesystem. |
Sissors | 11:31a09b75ea23 | 289 | * |
Sissors | 11:31a09b75ea23 | 290 | * @param *Name_BMP location of the BMP file (for example "/sd/test.bmp") |
Sissors | 11:31a09b75ea23 | 291 | * @returns 1 if bmp file was found and stored |
Sissors | 12:7213a0dded52 | 292 | * @returns 0 if file was not found |
Sissors | 12:7213a0dded52 | 293 | * @returns -1 if file was not a bmp |
Sissors | 11:31a09b75ea23 | 294 | * @returns -2 if bmp file is not 16/24bit |
Sissors | 11:31a09b75ea23 | 295 | * @returns -3 if bmp file is wrong for screen |
Sissors | 11:31a09b75ea23 | 296 | * @returns -4 if buffer malloc goes wrong |
Sissors | 11:31a09b75ea23 | 297 | */ |
Sissors | 11:31a09b75ea23 | 298 | int fileToFlash(const char *Name_BMP); |
Sissors | 11:31a09b75ea23 | 299 | |
Sissors | 11:31a09b75ea23 | 300 | /** Use the image on the flash memory as background |
Sissors | 11:31a09b75ea23 | 301 | * |
Sissors | 11:31a09b75ea23 | 302 | * @param active - true to use the image, false to use static color |
Sissors | 11:31a09b75ea23 | 303 | */ |
Sissors | 11:31a09b75ea23 | 304 | void backgroundImage(bool active); |
Sissors | 11:31a09b75ea23 | 305 | #endif |
frankvnk | 7:ffdd4e75b366 | 306 | |
Sissors | 11:31a09b75ea23 | 307 | |
frankvnk | 2:d0acbd263ec7 | 308 | |
frankvnk | 2:d0acbd263ec7 | 309 | |
frankvnk | 2:d0acbd263ec7 | 310 | |
frankvnk | 2:d0acbd263ec7 | 311 | // ------------------ PROTECTED PART ------------------ |
frankvnk | 2:d0acbd263ec7 | 312 | protected: |
frankvnk | 2:d0acbd263ec7 | 313 | |
frankvnk | 2:d0acbd263ec7 | 314 | /** draw a horizontal line |
frankvnk | 2:d0acbd263ec7 | 315 | * |
frankvnk | 2:d0acbd263ec7 | 316 | * @param x0 horizontal start |
frankvnk | 2:d0acbd263ec7 | 317 | * @param x1 horizontal stop |
frankvnk | 2:d0acbd263ec7 | 318 | * @param y vertical position |
frankvnk | 2:d0acbd263ec7 | 319 | * @param color 16 bit color |
frankvnk | 2:d0acbd263ec7 | 320 | * |
frankvnk | 2:d0acbd263ec7 | 321 | */ |
frankvnk | 2:d0acbd263ec7 | 322 | void hline(int x0, int x1, int y, int colour); |
frankvnk | 2:d0acbd263ec7 | 323 | |
frankvnk | 2:d0acbd263ec7 | 324 | /** draw a vertical line |
frankvnk | 2:d0acbd263ec7 | 325 | * |
frankvnk | 2:d0acbd263ec7 | 326 | * @param x horizontal position |
frankvnk | 2:d0acbd263ec7 | 327 | * @param y0 vertical start |
frankvnk | 2:d0acbd263ec7 | 328 | * @param y1 vertical stop |
frankvnk | 2:d0acbd263ec7 | 329 | * @param color 16 bit color |
frankvnk | 2:d0acbd263ec7 | 330 | */ |
frankvnk | 2:d0acbd263ec7 | 331 | void vline(int y0, int y1, int x, int colour); |
frankvnk | 2:d0acbd263ec7 | 332 | |
frankvnk | 2:d0acbd263ec7 | 333 | /** Set draw window region |
frankvnk | 2:d0acbd263ec7 | 334 | * |
frankvnk | 2:d0acbd263ec7 | 335 | * @param x horizontal position |
frankvnk | 2:d0acbd263ec7 | 336 | * @param y vertical position |
frankvnk | 2:d0acbd263ec7 | 337 | * @param w window width in pixel |
frankvnk | 2:d0acbd263ec7 | 338 | * @param h window height in pixels |
frankvnk | 2:d0acbd263ec7 | 339 | */ |
Sissors | 5:781a72d380a1 | 340 | virtual void window (int x, int y, int w, int h); |
frankvnk | 2:d0acbd263ec7 | 341 | |
frankvnk | 2:d0acbd263ec7 | 342 | /** Init the ILI9320 controller |
frankvnk | 2:d0acbd263ec7 | 343 | * |
frankvnk | 2:d0acbd263ec7 | 344 | */ |
frankvnk | 2:d0acbd263ec7 | 345 | void tft_reset(); |
frankvnk | 2:d0acbd263ec7 | 346 | |
frankvnk | 2:d0acbd263ec7 | 347 | /** Write data to the LCD controller |
frankvnk | 2:d0acbd263ec7 | 348 | * |
frankvnk | 2:d0acbd263ec7 | 349 | * @param dat data written to LCD controller |
frankvnk | 2:d0acbd263ec7 | 350 | * |
frankvnk | 2:d0acbd263ec7 | 351 | */ |
frankvnk | 2:d0acbd263ec7 | 352 | void wr_dat(unsigned short value); |
frankvnk | 2:d0acbd263ec7 | 353 | |
frankvnk | 2:d0acbd263ec7 | 354 | /** Start data sequence to the LCD controller |
frankvnk | 2:d0acbd263ec7 | 355 | * |
frankvnk | 2:d0acbd263ec7 | 356 | */ |
frankvnk | 2:d0acbd263ec7 | 357 | void wr_dat_start(void); |
frankvnk | 2:d0acbd263ec7 | 358 | |
frankvnk | 2:d0acbd263ec7 | 359 | /** Write a command the LCD controller |
frankvnk | 2:d0acbd263ec7 | 360 | * |
frankvnk | 2:d0acbd263ec7 | 361 | * @param cmd: command to be written |
frankvnk | 2:d0acbd263ec7 | 362 | * |
frankvnk | 2:d0acbd263ec7 | 363 | */ |
frankvnk | 2:d0acbd263ec7 | 364 | void wr_cmd(unsigned char value); |
frankvnk | 2:d0acbd263ec7 | 365 | |
frankvnk | 2:d0acbd263ec7 | 366 | /** Read data from the LCD controller |
frankvnk | 2:d0acbd263ec7 | 367 | * |
frankvnk | 2:d0acbd263ec7 | 368 | * @returns data from LCD controller |
frankvnk | 2:d0acbd263ec7 | 369 | * |
frankvnk | 2:d0acbd263ec7 | 370 | */ |
frankvnk | 2:d0acbd263ec7 | 371 | unsigned short rd_dat(void); |
frankvnk | 2:d0acbd263ec7 | 372 | |
frankvnk | 2:d0acbd263ec7 | 373 | /** Read a LCD register |
frankvnk | 2:d0acbd263ec7 | 374 | * |
frankvnk | 2:d0acbd263ec7 | 375 | * @param reg register to be read |
frankvnk | 2:d0acbd263ec7 | 376 | * @returns value of the register |
frankvnk | 2:d0acbd263ec7 | 377 | */ |
frankvnk | 2:d0acbd263ec7 | 378 | unsigned short rd_reg (unsigned char reg); |
frankvnk | 2:d0acbd263ec7 | 379 | |
frankvnk | 7:ffdd4e75b366 | 380 | /** Set the cursor position |
frankvnk | 7:ffdd4e75b366 | 381 | * |
frankvnk | 7:ffdd4e75b366 | 382 | * @param x (horizontal position) |
frankvnk | 7:ffdd4e75b366 | 383 | * @param y (vertical position) |
frankvnk | 7:ffdd4e75b366 | 384 | * |
frankvnk | 7:ffdd4e75b366 | 385 | * Can only be used when reg 03h = 0x1030 (see note in mod_orientation). |
frankvnk | 7:ffdd4e75b366 | 386 | * |
frankvnk | 7:ffdd4e75b366 | 387 | */ |
frankvnk | 2:d0acbd263ec7 | 388 | void SetCursor( unsigned short Xpos, unsigned short Ypos ); |
Sissors | 11:31a09b75ea23 | 389 | |
Sissors | 11:31a09b75ea23 | 390 | struct bitmapData { |
Sissors | 11:31a09b75ea23 | 391 | int return_code; |
Sissors | 11:31a09b75ea23 | 392 | int width, height; |
Sissors | 11:31a09b75ea23 | 393 | int bits, pad; |
Sissors | 11:31a09b75ea23 | 394 | int start_data; |
Sissors | 11:31a09b75ea23 | 395 | FILE *file; |
Sissors | 11:31a09b75ea23 | 396 | }; |
Sissors | 11:31a09b75ea23 | 397 | |
Sissors | 11:31a09b75ea23 | 398 | bitmapData getBitmapData(const char *Name_BMP); |
frankvnk | 2:d0acbd263ec7 | 399 | |
frankvnk | 2:d0acbd263ec7 | 400 | unsigned int orientation; |
frankvnk | 2:d0acbd263ec7 | 401 | unsigned int char_x; |
frankvnk | 2:d0acbd263ec7 | 402 | unsigned int char_y; |
Sissors | 11:31a09b75ea23 | 403 | bool backgroundimage; |
Sissors | 11:31a09b75ea23 | 404 | BurstSPI _spi; |
Sissors | 11:31a09b75ea23 | 405 | DigitalOut _cs; |
Sissors | 11:31a09b75ea23 | 406 | unsigned char* font; |
Sissors | 16:be1a10246234 | 407 | #ifndef NO_FLASH_BUFFER |
Sissors | 11:31a09b75ea23 | 408 | IAP iap; |
Sissors | 13:5f332321a40c | 409 | int backgroundOrientation; |
Sissors | 11:31a09b75ea23 | 410 | #endif |
frankvnk | 2:d0acbd263ec7 | 411 | |
frankvnk | 2:d0acbd263ec7 | 412 | }; |
frankvnk | 2:d0acbd263ec7 | 413 | |
frankvnk | 2:d0acbd263ec7 | 414 | #endif |