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