Differential pressure meter

Dependencies:   TFT_Touch_WaveShare

Committer:
igbt6
Date:
Tue Apr 03 20:13:35 2018 +0000
Revision:
1:c311d5f59c8b
Parent:
0:619824763516
Differential pressure meter

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igbt6 0:619824763516 1 /* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller
igbt6 0:619824763516 2 * Copyright (c) 2011 Peter Drescher - DC2PD
igbt6 0:619824763516 3 *
igbt6 0:619824763516 4 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
igbt6 0:619824763516 5 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
igbt6 0:619824763516 6 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
igbt6 0:619824763516 7 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
igbt6 0:619824763516 8 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
igbt6 0:619824763516 9 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
igbt6 0:619824763516 10 * THE SOFTWARE.
igbt6 0:619824763516 11 */
igbt6 0:619824763516 12
igbt6 0:619824763516 13 #ifndef MBED_SPI_TFT_H
igbt6 0:619824763516 14 #define MBED_SPI_TFT_H
igbt6 0:619824763516 15
igbt6 0:619824763516 16
igbt6 0:619824763516 17 #include "mbed.h"
igbt6 0:619824763516 18 #include "GraphicsDisplay.h"
igbt6 0:619824763516 19
igbt6 0:619824763516 20 #define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue
igbt6 0:619824763516 21
igbt6 0:619824763516 22 #define SPI_START (0x70) /* Start byte for SPI transfer */
igbt6 0:619824763516 23 #define SPI_RD (0x01) /* WR bit 1 within start */
igbt6 0:619824763516 24 #define SPI_WR (0x00) /* WR bit 0 within start */
igbt6 0:619824763516 25 #define SPI_DATA (0x02) /* RS bit 1 within start byte */
igbt6 0:619824763516 26 #define SPI_INDEX (0x00) /* RS bit 0 within start byte */
igbt6 0:619824763516 27
igbt6 0:619824763516 28
igbt6 0:619824763516 29 /* some RGB color definitions */
igbt6 0:619824763516 30 #define Black 0x0000 /* 0, 0, 0 */
igbt6 0:619824763516 31 #define Navy 0x000F /* 0, 0, 128 */
igbt6 0:619824763516 32 #define DarkGreen 0x03E0 /* 0, 128, 0 */
igbt6 0:619824763516 33 #define DarkCyan 0x03EF /* 0, 128, 128 */
igbt6 0:619824763516 34 #define Maroon 0x7800 /* 128, 0, 0 */
igbt6 0:619824763516 35 #define Purple 0x780F /* 128, 0, 128 */
igbt6 0:619824763516 36 #define Olive 0x7BE0 /* 128, 128, 0 */
igbt6 0:619824763516 37 #define LightGrey 0xC618 /* 192, 192, 192 */
igbt6 0:619824763516 38 #define DarkGrey 0x7BEF /* 128, 128, 128 */
igbt6 0:619824763516 39 #define Blue 0x001F /* 0, 0, 255 */
igbt6 0:619824763516 40 #define Green 0x07E0 /* 0, 255, 0 */
igbt6 0:619824763516 41 #define Cyan 0x07FF /* 0, 255, 255 */
igbt6 0:619824763516 42 #define Red 0xF800 /* 255, 0, 0 */
igbt6 0:619824763516 43 #define Magenta 0xF81F /* 255, 0, 255 */
igbt6 0:619824763516 44 #define Yellow 0xFFE0 /* 255, 255, 0 */
igbt6 0:619824763516 45 #define White 0xFFFF /* 255, 255, 255 */
igbt6 0:619824763516 46
igbt6 0:619824763516 47 /** Display control class, based on GraphicsDisplay and TextDisplay
igbt6 0:619824763516 48 *
igbt6 0:619824763516 49 * Example:
igbt6 0:619824763516 50 * @code
igbt6 0:619824763516 51 * #include "stdio.h"
igbt6 0:619824763516 52 * #include "mbed.h"
igbt6 0:619824763516 53 * #include "SPI_TFT.h"
igbt6 0:619824763516 54 * #include "string"
igbt6 0:619824763516 55 * #include "Arial12x12.h"
igbt6 0:619824763516 56 * #include "Arial24x23.h"
igbt6 0:619824763516 57 *
igbt6 0:619824763516 58 *
igbt6 0:619824763516 59 *
igbt6 0:619824763516 60 * // the TFT is connected to SPI pin 5-7
igbt6 0:619824763516 61 * SPI_TFT TFT(p5, p6, p7, p8, p15,"TFT"); // mosi, miso, sclk, cs, reset
igbt6 0:619824763516 62 *
igbt6 0:619824763516 63 * int main() {
igbt6 0:619824763516 64 * TFT.claim(stdout); // send stdout to the TFT display
igbt6 0:619824763516 65 * //TFT.claim(stderr); // send stderr to the TFT display
igbt6 0:619824763516 66 *
igbt6 0:619824763516 67 * TFT.background(Black); // set background to black
igbt6 0:619824763516 68 * TFT.foreground(White); // set chars to white
igbt6 0:619824763516 69 * TFT.cls(); // clear the screen
igbt6 0:619824763516 70 * TFT.set_font((unsigned char*) Arial12x12); // select the font
igbt6 0:619824763516 71 *
igbt6 0:619824763516 72 * TFT.set_orientation(0);
igbt6 0:619824763516 73 * TFT.locate(0,0);
igbt6 0:619824763516 74 * printf(" Hello Mbed 0");
igbt6 0:619824763516 75 * TFT.set_font((unsigned char*) Arial24x23); // select font 2
igbt6 0:619824763516 76 * TFT.locate(2,5);
igbt6 0:619824763516 77 * TFT.printf("Bigger Font");
igbt6 0:619824763516 78 * }
igbt6 0:619824763516 79 * @endcode
igbt6 0:619824763516 80 */
igbt6 0:619824763516 81 class SPI_TFT : public GraphicsDisplay {
igbt6 0:619824763516 82 public:
igbt6 0:619824763516 83
igbt6 0:619824763516 84 /** Create a SPI_TFT object connected to SPI and two pins
igbt6 0:619824763516 85 *
igbt6 0:619824763516 86 * @param mosi,miso,sclk SPI
igbt6 0:619824763516 87 * @param cs pin connected to CS of display
igbt6 0:619824763516 88 * @param reset pin connected to RESET of display
igbt6 0:619824763516 89 *
igbt6 0:619824763516 90 */
igbt6 0:619824763516 91 SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT");
igbt6 0:619824763516 92
igbt6 0:619824763516 93 /** Get the width of the screen in pixel
igbt6 0:619824763516 94 *
igbt6 0:619824763516 95 * @param
igbt6 0:619824763516 96 * @returns width of screen in pixel
igbt6 0:619824763516 97 *
igbt6 0:619824763516 98 */
igbt6 0:619824763516 99 virtual int width();
igbt6 0:619824763516 100
igbt6 0:619824763516 101 /** Get the height of the screen in pixel
igbt6 0:619824763516 102 *
igbt6 0:619824763516 103 * @returns height of screen in pixel
igbt6 0:619824763516 104 *
igbt6 0:619824763516 105 */
igbt6 0:619824763516 106 virtual int height();
igbt6 0:619824763516 107
igbt6 0:619824763516 108 /** Draw a pixel at x,y with color
igbt6 0:619824763516 109 *
igbt6 0:619824763516 110 * @param x horizontal position
igbt6 0:619824763516 111 * @param y vertical position
igbt6 0:619824763516 112 * @param color 16 bit pixel color
igbt6 0:619824763516 113 */
igbt6 0:619824763516 114 virtual void pixel(int x, int y, int colour);
igbt6 0:619824763516 115
igbt6 0:619824763516 116 /** draw a circle
igbt6 0:619824763516 117 *
igbt6 0:619824763516 118 * @param x0,y0 center
igbt6 0:619824763516 119 * @param r radius
igbt6 0:619824763516 120 * @param color 16 bit color *
igbt6 0:619824763516 121 *
igbt6 0:619824763516 122 */
igbt6 0:619824763516 123 void circle(int x, int y, int r, int colour);
igbt6 0:619824763516 124
igbt6 0:619824763516 125 /** draw a filled circle
igbt6 0:619824763516 126 *
igbt6 0:619824763516 127 * @param x0,y0 center
igbt6 0:619824763516 128 * @param r radius
igbt6 0:619824763516 129 * @param color 16 bit color *
igbt6 0:619824763516 130 *
igbt6 0:619824763516 131 * use circle with different radius,
igbt6 0:619824763516 132 * can miss some pixel
igbt6 0:619824763516 133 */
igbt6 0:619824763516 134 void fillcircle(int x, int y, int r, int colour);
igbt6 0:619824763516 135
igbt6 0:619824763516 136
igbt6 0:619824763516 137
igbt6 0:619824763516 138 /** draw a 1 pixel line
igbt6 0:619824763516 139 *
igbt6 0:619824763516 140 * @param x0,y0 start point
igbt6 0:619824763516 141 * @param x1,y1 stop point
igbt6 0:619824763516 142 * @param color 16 bit color
igbt6 0:619824763516 143 *
igbt6 0:619824763516 144 */
igbt6 0:619824763516 145 void line(int x0, int y0, int x1, int y1, int colour);
igbt6 0:619824763516 146
igbt6 0:619824763516 147 /** draw a rect
igbt6 0:619824763516 148 *
igbt6 0:619824763516 149 * @param x0,y0 top left corner
igbt6 0:619824763516 150 * @param x1,y1 down right corner
igbt6 0:619824763516 151 * @param color 16 bit color
igbt6 0:619824763516 152 * *
igbt6 0:619824763516 153 */
igbt6 0:619824763516 154 void rect(int x0, int y0, int x1, int y1, int colour);
igbt6 0:619824763516 155
igbt6 0:619824763516 156 /** draw a filled rect
igbt6 0:619824763516 157 *
igbt6 0:619824763516 158 * @param x0,y0 top left corner
igbt6 0:619824763516 159 * @param x1,y1 down right corner
igbt6 0:619824763516 160 * @param color 16 bit color
igbt6 0:619824763516 161 *
igbt6 0:619824763516 162 */
igbt6 0:619824763516 163 void fillrect(int x0, int y0, int x1, int y1, int colour);
igbt6 0:619824763516 164
igbt6 0:619824763516 165 /** setup cursor position
igbt6 0:619824763516 166 *
igbt6 0:619824763516 167 * @param column 0 to max
igbt6 0:619824763516 168 * @param row 0 to max
igbt6 0:619824763516 169 * max depend on font size
igbt6 0:619824763516 170 */
igbt6 0:619824763516 171 void locate(int column, int row);
igbt6 0:619824763516 172
igbt6 0:619824763516 173 /** Fill the screen with _backgroun color
igbt6 0:619824763516 174 *
igbt6 0:619824763516 175 */
igbt6 0:619824763516 176 virtual void cls (void);
igbt6 0:619824763516 177
igbt6 0:619824763516 178 /** calculate the max number of char in a line
igbt6 0:619824763516 179 *
igbt6 0:619824763516 180 * @returns max columns
igbt6 0:619824763516 181 * depends on actual font size
igbt6 0:619824763516 182 *
igbt6 0:619824763516 183 */
igbt6 0:619824763516 184 int columns(void);
igbt6 0:619824763516 185
igbt6 0:619824763516 186 /** calculate the max number of columns
igbt6 0:619824763516 187 *
igbt6 0:619824763516 188 * @returns max column
igbt6 0:619824763516 189 * depends on actual font size
igbt6 0:619824763516 190 *
igbt6 0:619824763516 191 */
igbt6 0:619824763516 192 int rows(void);
igbt6 0:619824763516 193
igbt6 0:619824763516 194 /** put a char on the screen
igbt6 0:619824763516 195 *
igbt6 0:619824763516 196 * @param value char to print
igbt6 0:619824763516 197 * @returns printed char
igbt6 0:619824763516 198 *
igbt6 0:619824763516 199 */
igbt6 0:619824763516 200 int _putc(int value);
igbt6 0:619824763516 201
igbt6 0:619824763516 202 /** draw a character on given position out of the active font to the TFT
igbt6 0:619824763516 203 *
igbt6 0:619824763516 204 * @param col column
igbt6 0:619824763516 205 * @param row row
igbt6 0:619824763516 206 * @param c char to print
igbt6 0:619824763516 207 *
igbt6 0:619824763516 208 */
igbt6 0:619824763516 209 virtual void character(int col, int row, int c);
igbt6 0:619824763516 210
igbt6 0:619824763516 211 /** paint a bitmap on the TFT
igbt6 0:619824763516 212 *
igbt6 0:619824763516 213 * @param x,y : upper left corner
igbt6 0:619824763516 214 * @param w width of bitmap
igbt6 0:619824763516 215 * @param h high of bitmap
igbt6 0:619824763516 216 * @param *bitmap pointer to the bitmap data
igbt6 0:619824763516 217 *
igbt6 0:619824763516 218 * bitmap format: 16 bit R5 G6 B5
igbt6 0:619824763516 219 *
igbt6 0:619824763516 220 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
igbt6 0:619824763516 221 * use winhex to load this file and mark data stating at offset 0x46 to end
igbt6 0:619824763516 222 * use edit -> copy block -> C Source to export C array
igbt6 0:619824763516 223 * paste this array into your program
igbt6 0:619824763516 224 *
igbt6 0:619824763516 225 */
igbt6 0:619824763516 226 void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap);
igbt6 0:619824763516 227
igbt6 0:619824763516 228 /** select the font to use
igbt6 0:619824763516 229 *
igbt6 0:619824763516 230 * @param f pointer to font array
igbt6 0:619824763516 231 *
igbt6 0:619824763516 232 * font array can created with GLCD Font Creator from http://www.mikroe.com
igbt6 0:619824763516 233 * you have to add 4 parameter at the beginning of the font array to use:
igbt6 0:619824763516 234 * - the number of byte / char
igbt6 0:619824763516 235 * - the vertial size in pixel
igbt6 0:619824763516 236 * - the horizontal size in pixel
igbt6 0:619824763516 237 * - the number of byte per vertical line
igbt6 0:619824763516 238 * you also have to change the array to char[]
igbt6 0:619824763516 239 *
igbt6 0:619824763516 240 */
igbt6 0:619824763516 241 void set_font(unsigned char* f);
igbt6 0:619824763516 242
igbt6 0:619824763516 243 /** Set the orientation of the screen
igbt6 0:619824763516 244 * x,y: 0,0 is always top left
igbt6 0:619824763516 245 *
igbt6 0:619824763516 246 * @param o direction to use the screen (0-3) 90&#65533; Steps
igbt6 0:619824763516 247 *
igbt6 0:619824763516 248 */
igbt6 0:619824763516 249 void set_orientation(unsigned int o);
igbt6 0:619824763516 250
igbt6 0:619824763516 251 SPI _spi;
igbt6 0:619824763516 252 DigitalOut _cs;
igbt6 0:619824763516 253 DigitalOut _reset;
igbt6 0:619824763516 254 unsigned char* font;
igbt6 0:619824763516 255
igbt6 0:619824763516 256 protected:
igbt6 0:619824763516 257
igbt6 0:619824763516 258 /** draw a horizontal line
igbt6 0:619824763516 259 *
igbt6 0:619824763516 260 * @param x0 horizontal start
igbt6 0:619824763516 261 * @param x1 horizontal stop
igbt6 0:619824763516 262 * @param y vertical position
igbt6 0:619824763516 263 * @param color 16 bit color
igbt6 0:619824763516 264 *
igbt6 0:619824763516 265 */
igbt6 0:619824763516 266 void hline(int x0, int x1, int y, int colour);
igbt6 0:619824763516 267
igbt6 0:619824763516 268 /** draw a vertical line
igbt6 0:619824763516 269 *
igbt6 0:619824763516 270 * @param x horizontal position
igbt6 0:619824763516 271 * @param y0 vertical start
igbt6 0:619824763516 272 * @param y1 vertical stop
igbt6 0:619824763516 273 * @param color 16 bit color
igbt6 0:619824763516 274 */
igbt6 0:619824763516 275 void vline(int y0, int y1, int x, int colour);
igbt6 0:619824763516 276
igbt6 0:619824763516 277 /** Set draw window region
igbt6 0:619824763516 278 *
igbt6 0:619824763516 279 * @param x horizontal position
igbt6 0:619824763516 280 * @param y vertical position
igbt6 0:619824763516 281 * @param w window width in pixel
igbt6 0:619824763516 282 * @param h window height in pixels
igbt6 0:619824763516 283 */
igbt6 0:619824763516 284 void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h);
igbt6 0:619824763516 285
igbt6 0:619824763516 286 /** Set draw window region to whole screen
igbt6 0:619824763516 287 *
igbt6 0:619824763516 288 */
igbt6 0:619824763516 289 void WindowMax (void);
igbt6 0:619824763516 290
igbt6 0:619824763516 291 /** Init the HX8347D controller
igbt6 0:619824763516 292 *
igbt6 0:619824763516 293 */
igbt6 0:619824763516 294 void tft_reset();
igbt6 0:619824763516 295
igbt6 0:619824763516 296 /** Write data to the LCD controller
igbt6 0:619824763516 297 *
igbt6 0:619824763516 298 * @param dat data written to LCD controller
igbt6 0:619824763516 299 *
igbt6 0:619824763516 300 */
igbt6 0:619824763516 301 void wr_dat(int value);
igbt6 0:619824763516 302
igbt6 0:619824763516 303 /** Write a command the LCD controller
igbt6 0:619824763516 304 *
igbt6 0:619824763516 305 * @param cmd: command to be written
igbt6 0:619824763516 306 *
igbt6 0:619824763516 307 */
igbt6 0:619824763516 308 void wr_cmd(int value);
igbt6 0:619824763516 309
igbt6 0:619824763516 310 /** Start data sequence to the LCD controller
igbt6 0:619824763516 311 *
igbt6 0:619824763516 312 */
igbt6 0:619824763516 313 void wr_dat_start();
igbt6 0:619824763516 314
igbt6 0:619824763516 315 /** Stop of data writing to the LCD controller
igbt6 0:619824763516 316 *
igbt6 0:619824763516 317 */
igbt6 0:619824763516 318 void wr_dat_stop();
igbt6 0:619824763516 319
igbt6 0:619824763516 320 /** write data to the LCD controller
igbt6 0:619824763516 321 *
igbt6 0:619824763516 322 * @param data to be written
igbt6 0:619824763516 323 * *
igbt6 0:619824763516 324 */
igbt6 0:619824763516 325 void wr_dat_only(unsigned short dat);
igbt6 0:619824763516 326
igbt6 0:619824763516 327 /** Read data from the LCD controller
igbt6 0:619824763516 328 *
igbt6 0:619824763516 329 * @returns data from LCD controller
igbt6 0:619824763516 330 *
igbt6 0:619824763516 331 */
igbt6 0:619824763516 332 unsigned short rd_dat(void);
igbt6 0:619824763516 333
igbt6 0:619824763516 334 /** Write a value to the to a LCD register
igbt6 0:619824763516 335 *
igbt6 0:619824763516 336 * @param reg register to be written
igbt6 0:619824763516 337 * @param val data to be written
igbt6 0:619824763516 338 */
igbt6 0:619824763516 339 void wr_reg (unsigned char reg, unsigned short val);
igbt6 0:619824763516 340
igbt6 0:619824763516 341 /** Read a LCD register
igbt6 0:619824763516 342 *
igbt6 0:619824763516 343 * @param reg register to be read
igbt6 0:619824763516 344 * @returns value of the register
igbt6 0:619824763516 345 */
igbt6 0:619824763516 346 unsigned short rd_reg (unsigned char reg);
igbt6 0:619824763516 347
igbt6 0:619824763516 348 unsigned int orientation;
igbt6 0:619824763516 349 unsigned int char_x;
igbt6 0:619824763516 350
igbt6 0:619824763516 351 };
igbt6 0:619824763516 352
igbt6 0:619824763516 353 #endif