Port of the LPC4088 QSB EA LCD Sphere Demo to the LPC4088 DM using the DMSupport lib. Dropping the QSB EALib
Dependencies: DMBasicGUI DMSupport
Fork of lpc4088_displaymodule_hello_world by
Just a quick hack to get something good looking on the LPC4088DM
/media/uploads/tecnosys/lpc4088dm.jpg
Graphics.cpp@5:d2f1c9185c5b, 2015-04-29 (annotated)
- Committer:
- tecnosys
- Date:
- Wed Apr 29 05:34:03 2015 +0000
- Revision:
- 5:d2f1c9185c5b
initial port of EA LCD Demo to DMSupport libs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tecnosys | 5:d2f1c9185c5b | 1 | |
tecnosys | 5:d2f1c9185c5b | 2 | #include "mbed.h" |
tecnosys | 5:d2f1c9185c5b | 3 | #include "Graphics.h" |
tecnosys | 5:d2f1c9185c5b | 4 | |
tecnosys | 5:d2f1c9185c5b | 5 | |
tecnosys | 5:d2f1c9185c5b | 6 | Graphics::Graphics(uint16_t *pFrmBuf, uint16_t dispWidth, uint16_t dispHeight) |
tecnosys | 5:d2f1c9185c5b | 7 | { |
tecnosys | 5:d2f1c9185c5b | 8 | this->windowX = dispWidth; |
tecnosys | 5:d2f1c9185c5b | 9 | this->windowY = dispHeight; |
tecnosys | 5:d2f1c9185c5b | 10 | this->pFrmBuf = pFrmBuf; |
tecnosys | 5:d2f1c9185c5b | 11 | } |
tecnosys | 5:d2f1c9185c5b | 12 | |
tecnosys | 5:d2f1c9185c5b | 13 | void Graphics::setFrameBuffer( uint16_t *pFrmBuf ) |
tecnosys | 5:d2f1c9185c5b | 14 | { |
tecnosys | 5:d2f1c9185c5b | 15 | this->pFrmBuf = pFrmBuf; |
tecnosys | 5:d2f1c9185c5b | 16 | } |
tecnosys | 5:d2f1c9185c5b | 17 | |
tecnosys | 5:d2f1c9185c5b | 18 | int32_t Graphics::abs(int32_t v1) const |
tecnosys | 5:d2f1c9185c5b | 19 | { |
tecnosys | 5:d2f1c9185c5b | 20 | if (v1 > 0) |
tecnosys | 5:d2f1c9185c5b | 21 | return v1; |
tecnosys | 5:d2f1c9185c5b | 22 | |
tecnosys | 5:d2f1c9185c5b | 23 | return -v1; |
tecnosys | 5:d2f1c9185c5b | 24 | } |
tecnosys | 5:d2f1c9185c5b | 25 | |
tecnosys | 5:d2f1c9185c5b | 26 | /*********************************************************************** |
tecnosys | 5:d2f1c9185c5b | 27 | * |
tecnosys | 5:d2f1c9185c5b | 28 | * Function: swim_put_line_raw |
tecnosys | 5:d2f1c9185c5b | 29 | * |
tecnosys | 5:d2f1c9185c5b | 30 | * Purpose: Draw a line on the physical display |
tecnosys | 5:d2f1c9185c5b | 31 | * |
tecnosys | 5:d2f1c9185c5b | 32 | * Processing: |
tecnosys | 5:d2f1c9185c5b | 33 | * See function. |
tecnosys | 5:d2f1c9185c5b | 34 | * |
tecnosys | 5:d2f1c9185c5b | 35 | * Parameters: |
tecnosys | 5:d2f1c9185c5b | 36 | * win : Window identifier |
tecnosys | 5:d2f1c9185c5b | 37 | * x1 : Physical X position of X line start |
tecnosys | 5:d2f1c9185c5b | 38 | * y1 : Physical Y position of Y line start |
tecnosys | 5:d2f1c9185c5b | 39 | * x2 : Physical X position of X line end |
tecnosys | 5:d2f1c9185c5b | 40 | * y2 : Physical Y position of Y line end |
tecnosys | 5:d2f1c9185c5b | 41 | * |
tecnosys | 5:d2f1c9185c5b | 42 | * Outputs: None |
tecnosys | 5:d2f1c9185c5b | 43 | * |
tecnosys | 5:d2f1c9185c5b | 44 | * Returns: Nothing |
tecnosys | 5:d2f1c9185c5b | 45 | * |
tecnosys | 5:d2f1c9185c5b | 46 | * Notes: None |
tecnosys | 5:d2f1c9185c5b | 47 | * |
tecnosys | 5:d2f1c9185c5b | 48 | **********************************************************************/ |
tecnosys | 5:d2f1c9185c5b | 49 | void Graphics::put_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int16_t color) |
tecnosys | 5:d2f1c9185c5b | 50 | { |
tecnosys | 5:d2f1c9185c5b | 51 | int32_t e2, sx, sy, dx, dy, err; |
tecnosys | 5:d2f1c9185c5b | 52 | |
tecnosys | 5:d2f1c9185c5b | 53 | /* calculate delta_x and delta_y */ |
tecnosys | 5:d2f1c9185c5b | 54 | dx = abs(x2 - x1); |
tecnosys | 5:d2f1c9185c5b | 55 | dy = abs(y2 - y1); |
tecnosys | 5:d2f1c9185c5b | 56 | |
tecnosys | 5:d2f1c9185c5b | 57 | /* set the direction for the step for both x and y, and |
tecnosys | 5:d2f1c9185c5b | 58 | initialize the error */ |
tecnosys | 5:d2f1c9185c5b | 59 | if (x1 < x2) |
tecnosys | 5:d2f1c9185c5b | 60 | sx = 1; |
tecnosys | 5:d2f1c9185c5b | 61 | else |
tecnosys | 5:d2f1c9185c5b | 62 | sx = -1; |
tecnosys | 5:d2f1c9185c5b | 63 | |
tecnosys | 5:d2f1c9185c5b | 64 | if (y1 < y2) |
tecnosys | 5:d2f1c9185c5b | 65 | sy = 1; |
tecnosys | 5:d2f1c9185c5b | 66 | else |
tecnosys | 5:d2f1c9185c5b | 67 | sy = -1; |
tecnosys | 5:d2f1c9185c5b | 68 | |
tecnosys | 5:d2f1c9185c5b | 69 | err = dx - dy; |
tecnosys | 5:d2f1c9185c5b | 70 | |
tecnosys | 5:d2f1c9185c5b | 71 | while (1) |
tecnosys | 5:d2f1c9185c5b | 72 | { |
tecnosys | 5:d2f1c9185c5b | 73 | if ((x1 >= 0) && (x1 < this->windowX) && |
tecnosys | 5:d2f1c9185c5b | 74 | (y1 >= 0) && (y1 < this->windowY)) |
tecnosys | 5:d2f1c9185c5b | 75 | this->pFrmBuf[x1 + (this->windowX*y1)] = color; |
tecnosys | 5:d2f1c9185c5b | 76 | |
tecnosys | 5:d2f1c9185c5b | 77 | if ((x1 == x2) && (y1 == y2)) |
tecnosys | 5:d2f1c9185c5b | 78 | return; |
tecnosys | 5:d2f1c9185c5b | 79 | |
tecnosys | 5:d2f1c9185c5b | 80 | e2 = 2 * err; |
tecnosys | 5:d2f1c9185c5b | 81 | if (e2 > -dy) |
tecnosys | 5:d2f1c9185c5b | 82 | { |
tecnosys | 5:d2f1c9185c5b | 83 | err -= dy; |
tecnosys | 5:d2f1c9185c5b | 84 | x1 += sx; |
tecnosys | 5:d2f1c9185c5b | 85 | } |
tecnosys | 5:d2f1c9185c5b | 86 | if (e2 < dx) |
tecnosys | 5:d2f1c9185c5b | 87 | { |
tecnosys | 5:d2f1c9185c5b | 88 | err += dx; |
tecnosys | 5:d2f1c9185c5b | 89 | y1 += sy; |
tecnosys | 5:d2f1c9185c5b | 90 | } |
tecnosys | 5:d2f1c9185c5b | 91 | } |
tecnosys | 5:d2f1c9185c5b | 92 | } |
tecnosys | 5:d2f1c9185c5b | 93 | |
tecnosys | 5:d2f1c9185c5b | 94 | /*********************************************************************** |
tecnosys | 5:d2f1c9185c5b | 95 | * |
tecnosys | 5:d2f1c9185c5b | 96 | * Function: plot4points |
tecnosys | 5:d2f1c9185c5b | 97 | * |
tecnosys | 5:d2f1c9185c5b | 98 | * Purpose: |
tecnosys | 5:d2f1c9185c5b | 99 | * |
tecnosys | 5:d2f1c9185c5b | 100 | * Processing: |
tecnosys | 5:d2f1c9185c5b | 101 | * See function. |
tecnosys | 5:d2f1c9185c5b | 102 | * |
tecnosys | 5:d2f1c9185c5b | 103 | * Parameters: |
tecnosys | 5:d2f1c9185c5b | 104 | * win : Window identifier |
tecnosys | 5:d2f1c9185c5b | 105 | * cx : |
tecnosys | 5:d2f1c9185c5b | 106 | * cy : |
tecnosys | 5:d2f1c9185c5b | 107 | * x : |
tecnosys | 5:d2f1c9185c5b | 108 | * y : |
tecnosys | 5:d2f1c9185c5b | 109 | * Filled : |
tecnosys | 5:d2f1c9185c5b | 110 | * |
tecnosys | 5:d2f1c9185c5b | 111 | * Outputs: None |
tecnosys | 5:d2f1c9185c5b | 112 | * |
tecnosys | 5:d2f1c9185c5b | 113 | * Returns: Nothing |
tecnosys | 5:d2f1c9185c5b | 114 | * |
tecnosys | 5:d2f1c9185c5b | 115 | * Notes: None |
tecnosys | 5:d2f1c9185c5b | 116 | * |
tecnosys | 5:d2f1c9185c5b | 117 | **********************************************************************/ |
tecnosys | 5:d2f1c9185c5b | 118 | void Graphics::plot4points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled ) |
tecnosys | 5:d2f1c9185c5b | 119 | { |
tecnosys | 5:d2f1c9185c5b | 120 | int16_t x0, x1, y0, y1; |
tecnosys | 5:d2f1c9185c5b | 121 | |
tecnosys | 5:d2f1c9185c5b | 122 | y0 = cy + y; |
tecnosys | 5:d2f1c9185c5b | 123 | y1 = cy - y; |
tecnosys | 5:d2f1c9185c5b | 124 | if( Filled ) |
tecnosys | 5:d2f1c9185c5b | 125 | { |
tecnosys | 5:d2f1c9185c5b | 126 | for( x0=cx - x; x0<=cx + x; x0++ ) |
tecnosys | 5:d2f1c9185c5b | 127 | { |
tecnosys | 5:d2f1c9185c5b | 128 | if ((x0>=0) && (x0<this->windowX) && (y0>=0) && (y0<this->windowY)) |
tecnosys | 5:d2f1c9185c5b | 129 | this->pFrmBuf[x0 + (this->windowX*y0)] = color; |
tecnosys | 5:d2f1c9185c5b | 130 | if ((x0>=0) && (x0<this->windowX) && (y1>=0) && (y1<this->windowY)) |
tecnosys | 5:d2f1c9185c5b | 131 | this->pFrmBuf[x0 + (this->windowX*y1)] = color; |
tecnosys | 5:d2f1c9185c5b | 132 | } |
tecnosys | 5:d2f1c9185c5b | 133 | } |
tecnosys | 5:d2f1c9185c5b | 134 | else |
tecnosys | 5:d2f1c9185c5b | 135 | { |
tecnosys | 5:d2f1c9185c5b | 136 | x0 = cx + x; |
tecnosys | 5:d2f1c9185c5b | 137 | x1 = cx - x; |
tecnosys | 5:d2f1c9185c5b | 138 | if ((x0>=0) && (x0<this->windowX) && (y0>=0) && (y0<this->windowY)) |
tecnosys | 5:d2f1c9185c5b | 139 | this->pFrmBuf[x0 + (this->windowX*y0)] = color; |
tecnosys | 5:d2f1c9185c5b | 140 | if ((x != 0) && |
tecnosys | 5:d2f1c9185c5b | 141 | (x1>=0) && (x1<this->windowX) && (y0>=0) && (y0<this->windowY)) |
tecnosys | 5:d2f1c9185c5b | 142 | this->pFrmBuf[x1 + (this->windowX*y0)] = color; |
tecnosys | 5:d2f1c9185c5b | 143 | if ((y != 0) && |
tecnosys | 5:d2f1c9185c5b | 144 | (x0>=0) && (x0<this->windowX) && (y1>=0) && (y1<this->windowY)) |
tecnosys | 5:d2f1c9185c5b | 145 | this->pFrmBuf[x0 + (this->windowX*y1)] = color; |
tecnosys | 5:d2f1c9185c5b | 146 | if ((x != 0 && y != 0) && |
tecnosys | 5:d2f1c9185c5b | 147 | (x1>=0) && (x1<this->windowX) && (y1>=0) && (y1<this->windowY)) |
tecnosys | 5:d2f1c9185c5b | 148 | this->pFrmBuf[x1 + (this->windowX*y1)] = color; |
tecnosys | 5:d2f1c9185c5b | 149 | } |
tecnosys | 5:d2f1c9185c5b | 150 | } |
tecnosys | 5:d2f1c9185c5b | 151 | |
tecnosys | 5:d2f1c9185c5b | 152 | /*********************************************************************** |
tecnosys | 5:d2f1c9185c5b | 153 | * |
tecnosys | 5:d2f1c9185c5b | 154 | * Function: plot8points |
tecnosys | 5:d2f1c9185c5b | 155 | * |
tecnosys | 5:d2f1c9185c5b | 156 | * Purpose: |
tecnosys | 5:d2f1c9185c5b | 157 | * |
tecnosys | 5:d2f1c9185c5b | 158 | * Processing: |
tecnosys | 5:d2f1c9185c5b | 159 | * See function. |
tecnosys | 5:d2f1c9185c5b | 160 | * |
tecnosys | 5:d2f1c9185c5b | 161 | * Parameters: |
tecnosys | 5:d2f1c9185c5b | 162 | * win : Window identifier |
tecnosys | 5:d2f1c9185c5b | 163 | * cx : |
tecnosys | 5:d2f1c9185c5b | 164 | * cy : |
tecnosys | 5:d2f1c9185c5b | 165 | * x : |
tecnosys | 5:d2f1c9185c5b | 166 | * y : |
tecnosys | 5:d2f1c9185c5b | 167 | * Filled : |
tecnosys | 5:d2f1c9185c5b | 168 | * |
tecnosys | 5:d2f1c9185c5b | 169 | * Outputs: None |
tecnosys | 5:d2f1c9185c5b | 170 | * |
tecnosys | 5:d2f1c9185c5b | 171 | * Returns: Nothing |
tecnosys | 5:d2f1c9185c5b | 172 | * |
tecnosys | 5:d2f1c9185c5b | 173 | * Notes: None |
tecnosys | 5:d2f1c9185c5b | 174 | * |
tecnosys | 5:d2f1c9185c5b | 175 | **********************************************************************/ |
tecnosys | 5:d2f1c9185c5b | 176 | void Graphics::plot8points( int32_t cx, int32_t cy, int32_t x, int32_t y, int16_t color, int32_t Filled ) |
tecnosys | 5:d2f1c9185c5b | 177 | { |
tecnosys | 5:d2f1c9185c5b | 178 | plot4points( cx, cy, x, y, color, Filled ); |
tecnosys | 5:d2f1c9185c5b | 179 | if (x != y) |
tecnosys | 5:d2f1c9185c5b | 180 | plot4points( cx, cy, y, x, color, Filled ); |
tecnosys | 5:d2f1c9185c5b | 181 | } |
tecnosys | 5:d2f1c9185c5b | 182 | |
tecnosys | 5:d2f1c9185c5b | 183 | /*********************************************************************** |
tecnosys | 5:d2f1c9185c5b | 184 | * |
tecnosys | 5:d2f1c9185c5b | 185 | * Function: swim_put_circle |
tecnosys | 5:d2f1c9185c5b | 186 | * |
tecnosys | 5:d2f1c9185c5b | 187 | * Purpose: |
tecnosys | 5:d2f1c9185c5b | 188 | * |
tecnosys | 5:d2f1c9185c5b | 189 | * Processing: |
tecnosys | 5:d2f1c9185c5b | 190 | * See function. |
tecnosys | 5:d2f1c9185c5b | 191 | * |
tecnosys | 5:d2f1c9185c5b | 192 | * Parameters: |
tecnosys | 5:d2f1c9185c5b | 193 | * win : Window identifier |
tecnosys | 5:d2f1c9185c5b | 194 | * cx : |
tecnosys | 5:d2f1c9185c5b | 195 | * cy : |
tecnosys | 5:d2f1c9185c5b | 196 | * radius : |
tecnosys | 5:d2f1c9185c5b | 197 | * Filled : |
tecnosys | 5:d2f1c9185c5b | 198 | * |
tecnosys | 5:d2f1c9185c5b | 199 | * Outputs: None |
tecnosys | 5:d2f1c9185c5b | 200 | * |
tecnosys | 5:d2f1c9185c5b | 201 | * Returns: Nothing |
tecnosys | 5:d2f1c9185c5b | 202 | * |
tecnosys | 5:d2f1c9185c5b | 203 | * Notes: None |
tecnosys | 5:d2f1c9185c5b | 204 | * |
tecnosys | 5:d2f1c9185c5b | 205 | **********************************************************************/ |
tecnosys | 5:d2f1c9185c5b | 206 | void Graphics::put_circle( int32_t cx, int32_t cy, int16_t color, int32_t radius, int32_t Filled ) |
tecnosys | 5:d2f1c9185c5b | 207 | { |
tecnosys | 5:d2f1c9185c5b | 208 | int32_t Error = -radius; |
tecnosys | 5:d2f1c9185c5b | 209 | int16_t x = radius; |
tecnosys | 5:d2f1c9185c5b | 210 | int16_t y = 0; |
tecnosys | 5:d2f1c9185c5b | 211 | |
tecnosys | 5:d2f1c9185c5b | 212 | while( x >= y ) |
tecnosys | 5:d2f1c9185c5b | 213 | { |
tecnosys | 5:d2f1c9185c5b | 214 | plot8points( cx, cy, x, y, color, Filled ); |
tecnosys | 5:d2f1c9185c5b | 215 | |
tecnosys | 5:d2f1c9185c5b | 216 | Error += y; |
tecnosys | 5:d2f1c9185c5b | 217 | ++y; |
tecnosys | 5:d2f1c9185c5b | 218 | Error += y; |
tecnosys | 5:d2f1c9185c5b | 219 | |
tecnosys | 5:d2f1c9185c5b | 220 | if( Error >= 0 ) |
tecnosys | 5:d2f1c9185c5b | 221 | { |
tecnosys | 5:d2f1c9185c5b | 222 | --x; |
tecnosys | 5:d2f1c9185c5b | 223 | Error -= x; |
tecnosys | 5:d2f1c9185c5b | 224 | Error -= x; |
tecnosys | 5:d2f1c9185c5b | 225 | } |
tecnosys | 5:d2f1c9185c5b | 226 | } |
tecnosys | 5:d2f1c9185c5b | 227 | } |
tecnosys | 5:d2f1c9185c5b | 228 | |
tecnosys | 5:d2f1c9185c5b | 229 | |
tecnosys | 5:d2f1c9185c5b | 230 |