A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.
Dependencies: FATFileSystem
Fork of EALib by
GFXFb.cpp@6:405c6e5a4eaf, 2013-10-31 (annotated)
- Committer:
- embeddedartists
- Date:
- Thu Oct 31 13:23:11 2013 +0000
- Revision:
- 6:405c6e5a4eaf
- Parent:
- 4:b32cf4ef45c5
- Child:
- 12:15597e45eea0
Updated SPI clock frequency for TSC2046
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 4:b32cf4ef45c5 | 1 | |
embeddedartists | 4:b32cf4ef45c5 | 2 | /****************************************************************************** |
embeddedartists | 4:b32cf4ef45c5 | 3 | * Includes |
embeddedartists | 4:b32cf4ef45c5 | 4 | *****************************************************************************/ |
embeddedartists | 4:b32cf4ef45c5 | 5 | |
embeddedartists | 0:0fdadbc3d852 | 6 | #include "mbed.h" |
embeddedartists | 0:0fdadbc3d852 | 7 | #include "GFXFb.h" |
embeddedartists | 0:0fdadbc3d852 | 8 | |
embeddedartists | 0:0fdadbc3d852 | 9 | |
embeddedartists | 0:0fdadbc3d852 | 10 | GFXFb::GFXFb(uint16_t w, uint16_t h, uint16_t* fb) : Adafruit_GFX(w, h) { |
embeddedartists | 0:0fdadbc3d852 | 11 | _fb = fb; |
embeddedartists | 0:0fdadbc3d852 | 12 | } |
embeddedartists | 0:0fdadbc3d852 | 13 | |
embeddedartists | 0:0fdadbc3d852 | 14 | |
embeddedartists | 0:0fdadbc3d852 | 15 | void GFXFb::drawPixel(int16_t x, int16_t y, uint16_t color) { |
embeddedartists | 0:0fdadbc3d852 | 16 | if (_fb == 0) return; |
embeddedartists | 0:0fdadbc3d852 | 17 | |
embeddedartists | 0:0fdadbc3d852 | 18 | if (x < 0 || x >= width() || y < 0 || y >= height()) return; |
embeddedartists | 0:0fdadbc3d852 | 19 | |
embeddedartists | 0:0fdadbc3d852 | 20 | *(_fb + x + y*_width ) = color; |
embeddedartists | 0:0fdadbc3d852 | 21 | } |
embeddedartists | 0:0fdadbc3d852 | 22 | |
embeddedartists | 0:0fdadbc3d852 | 23 | void GFXFb::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { |
embeddedartists | 0:0fdadbc3d852 | 24 | int16_t y2 = y + h - 1; |
embeddedartists | 0:0fdadbc3d852 | 25 | |
embeddedartists | 0:0fdadbc3d852 | 26 | if (y < 0) y = 0; |
embeddedartists | 0:0fdadbc3d852 | 27 | if (y2 >= _height) y2 = _height-1; |
embeddedartists | 0:0fdadbc3d852 | 28 | |
embeddedartists | 0:0fdadbc3d852 | 29 | if (_fb == 0) return; |
embeddedartists | 0:0fdadbc3d852 | 30 | if (x < 0 || x >= _width || y >= _height || y2 < y) return; |
embeddedartists | 0:0fdadbc3d852 | 31 | |
embeddedartists | 0:0fdadbc3d852 | 32 | uint16_t* f = (_fb + x + y*_width); |
embeddedartists | 0:0fdadbc3d852 | 33 | while(y <= y2) { |
embeddedartists | 0:0fdadbc3d852 | 34 | |
embeddedartists | 0:0fdadbc3d852 | 35 | *f = color; |
embeddedartists | 0:0fdadbc3d852 | 36 | f += _width; |
embeddedartists | 0:0fdadbc3d852 | 37 | y++; |
embeddedartists | 0:0fdadbc3d852 | 38 | } |
embeddedartists | 0:0fdadbc3d852 | 39 | |
embeddedartists | 0:0fdadbc3d852 | 40 | } |
embeddedartists | 0:0fdadbc3d852 | 41 | |
embeddedartists | 0:0fdadbc3d852 | 42 | void GFXFb::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { |
embeddedartists | 0:0fdadbc3d852 | 43 | int16_t x2 = x + w - 1; |
embeddedartists | 0:0fdadbc3d852 | 44 | |
embeddedartists | 0:0fdadbc3d852 | 45 | if (x < 0) x = 0; |
embeddedartists | 0:0fdadbc3d852 | 46 | if (x2 >= _width) x2 = _width-1; |
embeddedartists | 0:0fdadbc3d852 | 47 | |
embeddedartists | 0:0fdadbc3d852 | 48 | if (_fb == 0) return; |
embeddedartists | 0:0fdadbc3d852 | 49 | if (x >= _width || x2 < x || y < 0 || y >= _height) return; |
embeddedartists | 0:0fdadbc3d852 | 50 | |
embeddedartists | 0:0fdadbc3d852 | 51 | uint16_t* f = (_fb + x + y*_width); |
embeddedartists | 0:0fdadbc3d852 | 52 | while(x <= x2) { |
embeddedartists | 0:0fdadbc3d852 | 53 | |
embeddedartists | 0:0fdadbc3d852 | 54 | *f++ = color; |
embeddedartists | 0:0fdadbc3d852 | 55 | x++; |
embeddedartists | 0:0fdadbc3d852 | 56 | } |
embeddedartists | 0:0fdadbc3d852 | 57 | |
embeddedartists | 0:0fdadbc3d852 | 58 | } |
embeddedartists | 0:0fdadbc3d852 | 59 | |
embeddedartists | 0:0fdadbc3d852 | 60 | |
embeddedartists | 0:0fdadbc3d852 | 61 | void GFXFb::fillScreen(uint16_t color) { |
embeddedartists | 0:0fdadbc3d852 | 62 | |
embeddedartists | 0:0fdadbc3d852 | 63 | if (_fb == 0) return; |
embeddedartists | 0:0fdadbc3d852 | 64 | |
embeddedartists | 0:0fdadbc3d852 | 65 | int len = _width*_height; |
embeddedartists | 0:0fdadbc3d852 | 66 | for (int i = 0; i < len; i++) { |
embeddedartists | 0:0fdadbc3d852 | 67 | *(_fb+i) = color; |
embeddedartists | 0:0fdadbc3d852 | 68 | } |
embeddedartists | 0:0fdadbc3d852 | 69 | } |
embeddedartists | 0:0fdadbc3d852 | 70 | |
embeddedartists | 0:0fdadbc3d852 | 71 | void GFXFb::writeString(const char* s) { |
embeddedartists | 0:0fdadbc3d852 | 72 | if (s == NULL) return; |
embeddedartists | 0:0fdadbc3d852 | 73 | |
embeddedartists | 0:0fdadbc3d852 | 74 | while(*s != 0) { |
embeddedartists | 0:0fdadbc3d852 | 75 | write(*s); |
embeddedartists | 0:0fdadbc3d852 | 76 | s++; |
embeddedartists | 0:0fdadbc3d852 | 77 | } |
embeddedartists | 0:0fdadbc3d852 | 78 | } |
embeddedartists | 0:0fdadbc3d852 | 79 | |
embeddedartists | 0:0fdadbc3d852 | 80 | int16_t GFXFb::getStringWidth(const char* s) { |
embeddedartists | 0:0fdadbc3d852 | 81 | // the default font in GFX is 6 pixels in width |
embeddedartists | 0:0fdadbc3d852 | 82 | int chWidth = 6*textsize; |
embeddedartists | 0:0fdadbc3d852 | 83 | int sz = 0; |
embeddedartists | 0:0fdadbc3d852 | 84 | |
embeddedartists | 0:0fdadbc3d852 | 85 | while(*s != 0) { |
embeddedartists | 0:0fdadbc3d852 | 86 | sz += chWidth; |
embeddedartists | 0:0fdadbc3d852 | 87 | s++; |
embeddedartists | 0:0fdadbc3d852 | 88 | } |
embeddedartists | 0:0fdadbc3d852 | 89 | |
embeddedartists | 0:0fdadbc3d852 | 90 | return sz; |
embeddedartists | 0:0fdadbc3d852 | 91 | } |
embeddedartists | 0:0fdadbc3d852 | 92 | |
embeddedartists | 0:0fdadbc3d852 | 93 | int16_t GFXFb::getStringHeight(const char* s) { |
embeddedartists | 0:0fdadbc3d852 | 94 | (void)s; |
embeddedartists | 0:0fdadbc3d852 | 95 | // the default font in GFX is 8 pixels in height |
embeddedartists | 0:0fdadbc3d852 | 96 | return 8; |
embeddedartists | 0:0fdadbc3d852 | 97 | } |
embeddedartists | 0:0fdadbc3d852 | 98 | |
embeddedartists | 0:0fdadbc3d852 | 99 |