LCD library for Akizuki AQM1248A graphic LCD module

Dependents:   FRDM_MAG3110 Nucleo_AQM1248A Nucleo_AQM1248A_GT20L16J1Y

Fork of C12832_lcd by Peter Drescher

see http://mbed.org/users/masato/code/Nucleo_AQM1248A/

Committer:
masato
Date:
Tue Jun 02 12:22:56 2015 +0000
Revision:
13:3a94a79194b6
Parent:
12:cecd70424890
add MISO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
masato 11:0145579c487f 1 /*
masato 11:0145579c487f 2 * mbed library for the Akizuki AQM1248A 128*48 pixel LCD
masato 11:0145579c487f 3 * derived from C12832_lcd
masato 11:0145579c487f 4 * Copyright (c) 2014 Masato YAMANISHI
masato 11:0145579c487f 5 * Released under the MIT License: http://mbed.org/license/mit
masato 11:0145579c487f 6 */
masato 11:0145579c487f 7
masato 11:0145579c487f 8 /* mbed library for the mbed Lab Board 128*32 pixel LCD
masato 11:0145579c487f 9 * use C12832 controller
masato 11:0145579c487f 10 * Copyright (c) 2012 Peter Drescher - DC2PD
masato 11:0145579c487f 11 * Released under the MIT License: http://mbed.org/license/mit
masato 11:0145579c487f 12 *
masato 11:0145579c487f 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
masato 11:0145579c487f 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
masato 11:0145579c487f 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
masato 11:0145579c487f 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
masato 11:0145579c487f 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
masato 11:0145579c487f 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
masato 11:0145579c487f 19 * THE SOFTWARE.
masato 11:0145579c487f 20 */
masato 11:0145579c487f 21
masato 11:0145579c487f 22 // 13.10.12 initial design
masato 11:0145579c487f 23 // 25.10.12 add autorefresh of screen
masato 11:0145579c487f 24 // 25.10.12 add standart font
masato 11:0145579c487f 25 // 20.12.12 add bitmap graphics
masato 11:0145579c487f 26
masato 11:0145579c487f 27 // optional defines :
masato 11:0145579c487f 28 // #define debug_lcd 1
masato 11:0145579c487f 29
masato 11:0145579c487f 30 #include "aqm1248a_lcd.h"
masato 11:0145579c487f 31 #include "mbed.h"
masato 11:0145579c487f 32 #include "stdio.h"
masato 11:0145579c487f 33 #include "Small_7.h"
masato 11:0145579c487f 34
masato 11:0145579c487f 35 aqm1248a_lcd::aqm1248a_lcd(const char* name)
masato 12:cecd70424890 36 #if defined(TARGET_LPC1768)
masato 12:cecd70424890 37 : _spi(p5,NC,p7),_reset(p6),_A0(p8),_CS(p11),GraphicsDisplay(name) // for mbed LPC1768
masato 12:cecd70424890 38 #else // defined(TARGET_NUCLEO_L152RE) || defined(TARGET_KL05Z)
masato 13:3a94a79194b6 39 : _spi(D11,D12,D13),_reset(D9),_A0(D8),_CS(D10),GraphicsDisplay(name) // for nucleo L152RE or other
masato 11:0145579c487f 40 #endif
masato 11:0145579c487f 41 {
masato 11:0145579c487f 42 orientation = 1;
masato 11:0145579c487f 43 draw_mode = NORMAL;
masato 11:0145579c487f 44 char_x = 0;
masato 11:0145579c487f 45 lcd_reset();
masato 11:0145579c487f 46 }
masato 11:0145579c487f 47
masato 11:0145579c487f 48 int aqm1248a_lcd::width()
masato 11:0145579c487f 49 {
masato 11:0145579c487f 50 if (orientation == 0 || orientation == 2) return HEIGHT; // 32;
masato 11:0145579c487f 51 else return WIDTH;
masato 11:0145579c487f 52 }
masato 11:0145579c487f 53
masato 11:0145579c487f 54 int aqm1248a_lcd::height()
masato 11:0145579c487f 55 {
masato 11:0145579c487f 56 if (orientation == 0 || orientation == 2) return WIDTH;
masato 11:0145579c487f 57 else return HEIGHT; // 32;
masato 11:0145579c487f 58 }
masato 11:0145579c487f 59
masato 11:0145579c487f 60 /*void aqm1248a_lcd::set_orientation(unsigned int o)
masato 11:0145579c487f 61 {
masato 11:0145579c487f 62 orientation = o;
masato 11:0145579c487f 63 switch (o) {
masato 11:0145579c487f 64 case (0):
masato 11:0145579c487f 65 wr_cmd(0xA0);
masato 11:0145579c487f 66 wr_cmd(0xC0);
masato 11:0145579c487f 67 break;
masato 11:0145579c487f 68 case (1):
masato 11:0145579c487f 69 wr_cmd(0xA0);
masato 11:0145579c487f 70 wr_cmd(0xC8);
masato 11:0145579c487f 71 break;
masato 11:0145579c487f 72 case (2):
masato 11:0145579c487f 73 wr_cmd(0xA1);
masato 11:0145579c487f 74 wr_cmd(0xC8);
masato 11:0145579c487f 75 break;
masato 11:0145579c487f 76 case (3):
masato 11:0145579c487f 77 wr_cmd(0xA1);
masato 11:0145579c487f 78 wr_cmd(0xC0);
masato 11:0145579c487f 79 break;
masato 11:0145579c487f 80 }
masato 11:0145579c487f 81 }
masato 11:0145579c487f 82 */
masato 11:0145579c487f 83
masato 11:0145579c487f 84 void aqm1248a_lcd::invert(unsigned int o)
masato 11:0145579c487f 85 {
masato 11:0145579c487f 86 if(o == 0) wr_cmd(0xA6);
masato 11:0145579c487f 87 else wr_cmd(0xA7);
masato 11:0145579c487f 88 }
masato 11:0145579c487f 89
masato 11:0145579c487f 90
masato 11:0145579c487f 91 void aqm1248a_lcd::set_contrast(unsigned int o)
masato 11:0145579c487f 92 {
masato 11:0145579c487f 93 contrast = o;
masato 11:0145579c487f 94 wr_cmd(0x81); // set volume
masato 11:0145579c487f 95 wr_cmd(o & 0x3F);
masato 11:0145579c487f 96 }
masato 11:0145579c487f 97
masato 11:0145579c487f 98 unsigned int aqm1248a_lcd::get_contrast(void)
masato 11:0145579c487f 99 {
masato 11:0145579c487f 100 return(contrast);
masato 11:0145579c487f 101 }
masato 11:0145579c487f 102
masato 11:0145579c487f 103 // write command to lcd controller
masato 11:0145579c487f 104
masato 11:0145579c487f 105 void aqm1248a_lcd::wr_cmd(unsigned char cmd)
masato 11:0145579c487f 106 {
masato 11:0145579c487f 107 _A0 = 0;
masato 11:0145579c487f 108 _CS = 0;
masato 11:0145579c487f 109 #if defined TARGET_LPC1768 // fast without mbed lib
masato 11:0145579c487f 110 LPC_SSP1->DR = cmd;
masato 11:0145579c487f 111 do {
masato 11:0145579c487f 112 } while ((LPC_SSP1->SR & 0x10) == 0x10); // wait for SPI1 idle
masato 11:0145579c487f 113 #else
masato 11:0145579c487f 114 _spi.write(cmd);
masato 11:0145579c487f 115 #endif
masato 11:0145579c487f 116 _CS = 1;
masato 11:0145579c487f 117 }
masato 11:0145579c487f 118
masato 11:0145579c487f 119 // write data to lcd controller
masato 11:0145579c487f 120
masato 11:0145579c487f 121 void aqm1248a_lcd::wr_dat(unsigned char dat)
masato 11:0145579c487f 122 {
masato 11:0145579c487f 123 _A0 = 1;
masato 11:0145579c487f 124 _CS = 0;
masato 11:0145579c487f 125 #if defined TARGET_LPC1768 // fast without mbed lib
masato 11:0145579c487f 126 LPC_SSP1->DR = dat;
masato 11:0145579c487f 127 do {
masato 11:0145579c487f 128 } while ((LPC_SSP1->SR & 0x10) == 0x10); // wait for SPI1 idle
masato 11:0145579c487f 129 #else
masato 11:0145579c487f 130 _spi.write(dat);
masato 11:0145579c487f 131 #endif
masato 11:0145579c487f 132 _CS = 1;
masato 11:0145579c487f 133 }
masato 11:0145579c487f 134
masato 11:0145579c487f 135 // reset and init the lcd controller
masato 11:0145579c487f 136
masato 11:0145579c487f 137 void aqm1248a_lcd::lcd_reset()
masato 11:0145579c487f 138 {
masato 11:0145579c487f 139 _spi.format(8,3); // 8 bit spi mode 3
masato 11:0145579c487f 140 _spi.frequency(20000000); // 19,2 Mhz SPI clock
masato 11:0145579c487f 141 #if 0
masato 11:0145579c487f 142 #if defined TARGET_LPC1768
masato 11:0145579c487f 143 DigitalOut _reset(p6);
masato 11:0145579c487f 144 #else
masato 11:0145579c487f 145 DigitalOut _reset(D9);
masato 11:0145579c487f 146 #endif
masato 11:0145579c487f 147 #endif
masato 11:0145579c487f 148 _A0 = 0;
masato 11:0145579c487f 149 _CS = 1;
masato 11:0145579c487f 150 _reset = 0; // display reset
masato 11:0145579c487f 151 wait_us(50);
masato 11:0145579c487f 152 _reset = 1; // end reset
masato 11:0145579c487f 153 wait_ms(5);
masato 11:0145579c487f 154
masato 11:0145579c487f 155 /* Start Initial Sequence ----------------------------------------------------*/
masato 11:0145579c487f 156
masato 11:0145579c487f 157 wr_cmd(0xAE); // display off
masato 11:0145579c487f 158 wr_cmd(0xA0);
masato 11:0145579c487f 159 wr_cmd(0xC8); // colum normal
masato 11:0145579c487f 160 wr_cmd(0xA3); // bias voltage
masato 11:0145579c487f 161 wr_cmd(0x2c); wait_ms(2);
masato 11:0145579c487f 162 wr_cmd(0x2e); wait_ms(2);
masato 11:0145579c487f 163 wr_cmd(0x2F); // power on
masato 11:0145579c487f 164 wr_cmd(0x23);
masato 11:0145579c487f 165 wr_cmd(0x81);
masato 11:0145579c487f 166 wr_cmd(0x1c);
masato 11:0145579c487f 167 wr_cmd(0xA4); // LCD display ram
masato 11:0145579c487f 168 wr_cmd(0x40); // start line = 0
masato 11:0145579c487f 169 wr_cmd(0xa6);
masato 11:0145579c487f 170 wr_cmd(0xAF); // display ON
masato 11:0145579c487f 171
masato 11:0145579c487f 172 #if defined TARGET_LPC1768 //setup DMA channel 0
masato 11:0145579c487f 173 LPC_SC->PCONP |= (1UL << 29); // Power up the GPDMA
masato 11:0145579c487f 174 LPC_GPDMA->DMACConfig = 1; // enable DMA controller
masato 11:0145579c487f 175 LPC_GPDMA->DMACIntTCClear = 0x1;
masato 11:0145579c487f 176 LPC_GPDMA->DMACIntErrClr = 0x1;
masato 11:0145579c487f 177 LPC_GPDMACH0->DMACCLLI = 0;
masato 11:0145579c487f 178 #endif
masato 11:0145579c487f 179 // clear and update LCD
masato 11:0145579c487f 180 memset(buffer,0x00,BUFFER_SIZE); // clear display buffer
masato 11:0145579c487f 181 copy_to_lcd();
masato 11:0145579c487f 182 auto_up = 1; // switch on auto update
masato 11:0145579c487f 183 // dont do this by default. Make the user call
masato 11:0145579c487f 184 //claim(stdout); // redirekt printf to lcd
masato 11:0145579c487f 185 locate(0,0);
masato 11:0145579c487f 186 set_font((unsigned char*)Small_7); // standart font
masato 11:0145579c487f 187 }
masato 11:0145579c487f 188
masato 11:0145579c487f 189 // set one pixel in buffer
masato 11:0145579c487f 190
masato 11:0145579c487f 191 void aqm1248a_lcd::pixel(int x, int y, int color)
masato 11:0145579c487f 192 {
masato 11:0145579c487f 193 // first check parameter
masato 11:0145579c487f 194 if(x > WIDTH || y > HEIGHT || x < 0 || y < 0) return;
masato 11:0145579c487f 195
masato 11:0145579c487f 196 if(draw_mode == NORMAL) {
masato 11:0145579c487f 197 if(color == 0)
masato 11:0145579c487f 198 buffer[x + ((y/8) * WIDTH)] &= ~(1 << (y%8)); // erase pixel
masato 11:0145579c487f 199 else
masato 11:0145579c487f 200 buffer[x + ((y/8) * WIDTH)] |= (1 << (y%8)); // set pixel
masato 11:0145579c487f 201 } else { // XOR mode
masato 11:0145579c487f 202 if(color == 1)
masato 11:0145579c487f 203 buffer[x + ((y/8) * WIDTH)] ^= (1 << (y%8)); // xor pixel
masato 11:0145579c487f 204 }
masato 11:0145579c487f 205 }
masato 11:0145579c487f 206
masato 11:0145579c487f 207 // update lcd
masato 11:0145579c487f 208
masato 11:0145579c487f 209 void aqm1248a_lcd::copy_to_lcd(void)
masato 11:0145579c487f 210 {
masato 11:0145579c487f 211 #ifndef TARGET_LPC1768
masato 11:0145579c487f 212 int i;
masato 11:0145579c487f 213 #endif
masato 11:0145579c487f 214
masato 11:0145579c487f 215 for (int page = 0; page < PAGES; page++) {
masato 11:0145579c487f 216 //page 0
masato 11:0145579c487f 217 wr_cmd(0x00); // set column low nibble 0
masato 11:0145579c487f 218 wr_cmd(0x10); // set column hi nibble 0
masato 11:0145579c487f 219 wr_cmd(0xB0 + page); // set page address 0 to PAGES-1
masato 11:0145579c487f 220 _A0 = 1;
masato 11:0145579c487f 221 #if defined TARGET_LPC1768
masato 11:0145579c487f 222 _CS = 0;
masato 11:0145579c487f 223 if (page == 0) {
masato 11:0145579c487f 224 // start 128 byte DMA transfer to SPI1
masato 11:0145579c487f 225 LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1
masato 11:0145579c487f 226 LPC_SSP1->DMACR = 0x2; // Enable SSP1 for DMA.
masato 11:0145579c487f 227 }
masato 11:0145579c487f 228 LPC_GPDMA->DMACIntTCClear = 0x1;
masato 11:0145579c487f 229 LPC_GPDMA->DMACIntErrClr = 0x1;
masato 11:0145579c487f 230 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 128*page);
masato 11:0145579c487f 231 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
masato 11:0145579c487f 232 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
masato 11:0145579c487f 233 LPC_GPDMA->DMACSoftSReq = 0x1;
masato 11:0145579c487f 234 do {
masato 11:0145579c487f 235 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
masato 11:0145579c487f 236 do {
masato 11:0145579c487f 237 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
masato 11:0145579c487f 238 _CS = 1;
masato 11:0145579c487f 239 #else // no DMA
masato 11:0145579c487f 240 for(i=WIDTH*page; i<WIDTH*(page+1); i++) {
masato 11:0145579c487f 241 wr_dat(buffer[i]);
masato 11:0145579c487f 242 }
masato 11:0145579c487f 243 #endif
masato 11:0145579c487f 244 }
masato 11:0145579c487f 245 }
masato 11:0145579c487f 246
masato 11:0145579c487f 247 void aqm1248a_lcd::cls(void)
masato 11:0145579c487f 248 {
masato 11:0145579c487f 249 memset(buffer,0x00,BUFFER_SIZE); // clear display buffer
masato 11:0145579c487f 250 copy_to_lcd();
masato 11:0145579c487f 251 }
masato 11:0145579c487f 252
masato 11:0145579c487f 253
masato 11:0145579c487f 254 void aqm1248a_lcd::line(int x0, int y0, int x1, int y1, int color)
masato 11:0145579c487f 255 {
masato 11:0145579c487f 256 int dx = 0, dy = 0;
masato 11:0145579c487f 257 int dx_sym = 0, dy_sym = 0;
masato 11:0145579c487f 258 int dx_x2 = 0, dy_x2 = 0;
masato 11:0145579c487f 259 int di = 0;
masato 11:0145579c487f 260
masato 11:0145579c487f 261 dx = x1-x0;
masato 11:0145579c487f 262 dy = y1-y0;
masato 11:0145579c487f 263
masato 11:0145579c487f 264 // if (dx == 0) { /* vertical line */
masato 11:0145579c487f 265 // if (y1 > y0) vline(x0,y0,y1,color);
masato 11:0145579c487f 266 // else vline(x0,y1,y0,color);
masato 11:0145579c487f 267 // return;
masato 11:0145579c487f 268 // }
masato 11:0145579c487f 269
masato 11:0145579c487f 270 if (dx > 0) {
masato 11:0145579c487f 271 dx_sym = 1;
masato 11:0145579c487f 272 } else {
masato 11:0145579c487f 273 dx_sym = -1;
masato 11:0145579c487f 274 }
masato 11:0145579c487f 275 // if (dy == 0) { /* horizontal line */
masato 11:0145579c487f 276 // if (x1 > x0) hline(x0,x1,y0,color);
masato 11:0145579c487f 277 // else hline(x1,x0,y0,color);
masato 11:0145579c487f 278 // return;
masato 11:0145579c487f 279 // }
masato 11:0145579c487f 280
masato 11:0145579c487f 281 if (dy > 0) {
masato 11:0145579c487f 282 dy_sym = 1;
masato 11:0145579c487f 283 } else {
masato 11:0145579c487f 284 dy_sym = -1;
masato 11:0145579c487f 285 }
masato 11:0145579c487f 286
masato 11:0145579c487f 287 dx = dx_sym*dx;
masato 11:0145579c487f 288 dy = dy_sym*dy;
masato 11:0145579c487f 289
masato 11:0145579c487f 290 dx_x2 = dx*2;
masato 11:0145579c487f 291 dy_x2 = dy*2;
masato 11:0145579c487f 292
masato 11:0145579c487f 293 if (dx >= dy) {
masato 11:0145579c487f 294 di = dy_x2 - dx;
masato 11:0145579c487f 295 while (x0 != x1) {
masato 11:0145579c487f 296
masato 11:0145579c487f 297 pixel(x0, y0, color);
masato 11:0145579c487f 298 x0 += dx_sym;
masato 11:0145579c487f 299 if (di<0) {
masato 11:0145579c487f 300 di += dy_x2;
masato 11:0145579c487f 301 } else {
masato 11:0145579c487f 302 di += dy_x2 - dx_x2;
masato 11:0145579c487f 303 y0 += dy_sym;
masato 11:0145579c487f 304 }
masato 11:0145579c487f 305 }
masato 11:0145579c487f 306 pixel(x0, y0, color);
masato 11:0145579c487f 307 } else {
masato 11:0145579c487f 308 di = dx_x2 - dy;
masato 11:0145579c487f 309 while (y0 != y1) {
masato 11:0145579c487f 310 pixel(x0, y0, color);
masato 11:0145579c487f 311 y0 += dy_sym;
masato 11:0145579c487f 312 if (di < 0) {
masato 11:0145579c487f 313 di += dx_x2;
masato 11:0145579c487f 314 } else {
masato 11:0145579c487f 315 di += dx_x2 - dy_x2;
masato 11:0145579c487f 316 x0 += dx_sym;
masato 11:0145579c487f 317 }
masato 11:0145579c487f 318 }
masato 11:0145579c487f 319 pixel(x0, y0, color);
masato 11:0145579c487f 320 }
masato 11:0145579c487f 321 if(auto_up) copy_to_lcd();
masato 11:0145579c487f 322 }
masato 11:0145579c487f 323
masato 11:0145579c487f 324 void aqm1248a_lcd::rect(int x0, int y0, int x1, int y1, int color)
masato 11:0145579c487f 325 {
masato 11:0145579c487f 326
masato 11:0145579c487f 327 if (x1 > x0) line(x0,y0,x1,y0,color);
masato 11:0145579c487f 328 else line(x1,y0,x0,y0,color);
masato 11:0145579c487f 329
masato 11:0145579c487f 330 if (y1 > y0) line(x0,y0,x0,y1,color);
masato 11:0145579c487f 331 else line(x0,y1,x0,y0,color);
masato 11:0145579c487f 332
masato 11:0145579c487f 333 if (x1 > x0) line(x0,y1,x1,y1,color);
masato 11:0145579c487f 334 else line(x1,y1,x0,y1,color);
masato 11:0145579c487f 335
masato 11:0145579c487f 336 if (y1 > y0) line(x1,y0,x1,y1,color);
masato 11:0145579c487f 337 else line(x1,y1,x1,y0,color);
masato 11:0145579c487f 338
masato 11:0145579c487f 339 if(auto_up) copy_to_lcd();
masato 11:0145579c487f 340 }
masato 11:0145579c487f 341
masato 11:0145579c487f 342 void aqm1248a_lcd::fillrect(int x0, int y0, int x1, int y1, int color)
masato 11:0145579c487f 343 {
masato 11:0145579c487f 344 int l,c,i;
masato 11:0145579c487f 345 if(x0 > x1) {
masato 11:0145579c487f 346 i = x0;
masato 11:0145579c487f 347 x0 = x1;
masato 11:0145579c487f 348 x1 = i;
masato 11:0145579c487f 349 }
masato 11:0145579c487f 350
masato 11:0145579c487f 351 if(y0 > y1) {
masato 11:0145579c487f 352 i = y0;
masato 11:0145579c487f 353 y0 = y1;
masato 11:0145579c487f 354 y1 = i;
masato 11:0145579c487f 355 }
masato 11:0145579c487f 356
masato 11:0145579c487f 357 for(l = x0; l<= x1; l ++) {
masato 11:0145579c487f 358 for(c = y0; c<= y1; c++) {
masato 11:0145579c487f 359 pixel(l,c,color);
masato 11:0145579c487f 360 }
masato 11:0145579c487f 361 }
masato 11:0145579c487f 362 if(auto_up) copy_to_lcd();
masato 11:0145579c487f 363 }
masato 11:0145579c487f 364
masato 11:0145579c487f 365
masato 11:0145579c487f 366
masato 11:0145579c487f 367 void aqm1248a_lcd::circle(int x0, int y0, int r, int color)
masato 11:0145579c487f 368 {
masato 11:0145579c487f 369
masato 11:0145579c487f 370 int draw_x0, draw_y0;
masato 11:0145579c487f 371 int draw_x1, draw_y1;
masato 11:0145579c487f 372 int draw_x2, draw_y2;
masato 11:0145579c487f 373 int draw_x3, draw_y3;
masato 11:0145579c487f 374 int draw_x4, draw_y4;
masato 11:0145579c487f 375 int draw_x5, draw_y5;
masato 11:0145579c487f 376 int draw_x6, draw_y6;
masato 11:0145579c487f 377 int draw_x7, draw_y7;
masato 11:0145579c487f 378 int xx, yy;
masato 11:0145579c487f 379 int di;
masato 11:0145579c487f 380 //WindowMax();
masato 11:0145579c487f 381 if (r == 0) { /* no radius */
masato 11:0145579c487f 382 return;
masato 11:0145579c487f 383 }
masato 11:0145579c487f 384
masato 11:0145579c487f 385 draw_x0 = draw_x1 = x0;
masato 11:0145579c487f 386 draw_y0 = draw_y1 = y0 + r;
masato 11:0145579c487f 387 if (draw_y0 < height()) {
masato 11:0145579c487f 388 pixel(draw_x0, draw_y0, color); /* 90 degree */
masato 11:0145579c487f 389 }
masato 11:0145579c487f 390
masato 11:0145579c487f 391 draw_x2 = draw_x3 = x0;
masato 11:0145579c487f 392 draw_y2 = draw_y3 = y0 - r;
masato 11:0145579c487f 393 if (draw_y2 >= 0) {
masato 11:0145579c487f 394 pixel(draw_x2, draw_y2, color); /* 270 degree */
masato 11:0145579c487f 395 }
masato 11:0145579c487f 396
masato 11:0145579c487f 397 draw_x4 = draw_x6 = x0 + r;
masato 11:0145579c487f 398 draw_y4 = draw_y6 = y0;
masato 11:0145579c487f 399 if (draw_x4 < width()) {
masato 11:0145579c487f 400 pixel(draw_x4, draw_y4, color); /* 0 degree */
masato 11:0145579c487f 401 }
masato 11:0145579c487f 402
masato 11:0145579c487f 403 draw_x5 = draw_x7 = x0 - r;
masato 11:0145579c487f 404 draw_y5 = draw_y7 = y0;
masato 11:0145579c487f 405 if (draw_x5>=0) {
masato 11:0145579c487f 406 pixel(draw_x5, draw_y5, color); /* 180 degree */
masato 11:0145579c487f 407 }
masato 11:0145579c487f 408
masato 11:0145579c487f 409 if (r == 1) {
masato 11:0145579c487f 410 return;
masato 11:0145579c487f 411 }
masato 11:0145579c487f 412
masato 11:0145579c487f 413 di = 3 - 2*r;
masato 11:0145579c487f 414 xx = 0;
masato 11:0145579c487f 415 yy = r;
masato 11:0145579c487f 416 while (xx < yy) {
masato 11:0145579c487f 417
masato 11:0145579c487f 418 if (di < 0) {
masato 11:0145579c487f 419 di += 4*xx + 6;
masato 11:0145579c487f 420 } else {
masato 11:0145579c487f 421 di += 4*(xx - yy) + 10;
masato 11:0145579c487f 422 yy--;
masato 11:0145579c487f 423 draw_y0--;
masato 11:0145579c487f 424 draw_y1--;
masato 11:0145579c487f 425 draw_y2++;
masato 11:0145579c487f 426 draw_y3++;
masato 11:0145579c487f 427 draw_x4--;
masato 11:0145579c487f 428 draw_x5++;
masato 11:0145579c487f 429 draw_x6--;
masato 11:0145579c487f 430 draw_x7++;
masato 11:0145579c487f 431 }
masato 11:0145579c487f 432 xx++;
masato 11:0145579c487f 433 draw_x0++;
masato 11:0145579c487f 434 draw_x1--;
masato 11:0145579c487f 435 draw_x2++;
masato 11:0145579c487f 436 draw_x3--;
masato 11:0145579c487f 437 draw_y4++;
masato 11:0145579c487f 438 draw_y5++;
masato 11:0145579c487f 439 draw_y6--;
masato 11:0145579c487f 440 draw_y7--;
masato 11:0145579c487f 441
masato 11:0145579c487f 442 if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
masato 11:0145579c487f 443 pixel(draw_x0, draw_y0, color);
masato 11:0145579c487f 444 }
masato 11:0145579c487f 445
masato 11:0145579c487f 446 if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) {
masato 11:0145579c487f 447 pixel(draw_x1, draw_y1, color);
masato 11:0145579c487f 448 }
masato 11:0145579c487f 449
masato 11:0145579c487f 450 if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) {
masato 11:0145579c487f 451 pixel(draw_x2, draw_y2, color);
masato 11:0145579c487f 452 }
masato 11:0145579c487f 453
masato 11:0145579c487f 454 if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
masato 11:0145579c487f 455 pixel(draw_x3, draw_y3, color);
masato 11:0145579c487f 456 }
masato 11:0145579c487f 457
masato 11:0145579c487f 458 if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) {
masato 11:0145579c487f 459 pixel(draw_x4, draw_y4, color);
masato 11:0145579c487f 460 }
masato 11:0145579c487f 461
masato 11:0145579c487f 462 if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
masato 11:0145579c487f 463 pixel(draw_x5, draw_y5, color);
masato 11:0145579c487f 464 }
masato 11:0145579c487f 465 if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
masato 11:0145579c487f 466 pixel(draw_x6, draw_y6, color);
masato 11:0145579c487f 467 }
masato 11:0145579c487f 468 if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
masato 11:0145579c487f 469 pixel(draw_x7, draw_y7, color);
masato 11:0145579c487f 470 }
masato 11:0145579c487f 471 }
masato 11:0145579c487f 472 if(auto_up) copy_to_lcd();
masato 11:0145579c487f 473 }
masato 11:0145579c487f 474
masato 11:0145579c487f 475 void aqm1248a_lcd::fillcircle(int x, int y, int r, int color)
masato 11:0145579c487f 476 {
masato 11:0145579c487f 477 int i,up;
masato 11:0145579c487f 478 up = auto_up;
masato 11:0145579c487f 479 auto_up = 0; // off
masato 11:0145579c487f 480 for (i = 0; i <= r; i++)
masato 11:0145579c487f 481 circle(x,y,i,color);
masato 11:0145579c487f 482 auto_up = up;
masato 11:0145579c487f 483 if(auto_up) copy_to_lcd();
masato 11:0145579c487f 484 }
masato 11:0145579c487f 485
masato 11:0145579c487f 486 void aqm1248a_lcd::setmode(int mode)
masato 11:0145579c487f 487 {
masato 11:0145579c487f 488 draw_mode = mode;
masato 11:0145579c487f 489 }
masato 11:0145579c487f 490
masato 11:0145579c487f 491 void aqm1248a_lcd::locate(int x, int y)
masato 11:0145579c487f 492 {
masato 11:0145579c487f 493 char_x = x;
masato 11:0145579c487f 494 char_y = y;
masato 11:0145579c487f 495 }
masato 11:0145579c487f 496
masato 11:0145579c487f 497
masato 11:0145579c487f 498
masato 11:0145579c487f 499 int aqm1248a_lcd::columns()
masato 11:0145579c487f 500 {
masato 11:0145579c487f 501 return width() / font[1];
masato 11:0145579c487f 502 }
masato 11:0145579c487f 503
masato 11:0145579c487f 504
masato 11:0145579c487f 505
masato 11:0145579c487f 506 int aqm1248a_lcd::rows()
masato 11:0145579c487f 507 {
masato 11:0145579c487f 508 return height() / font[2];
masato 11:0145579c487f 509 }
masato 11:0145579c487f 510
masato 11:0145579c487f 511
masato 11:0145579c487f 512
masato 11:0145579c487f 513 int aqm1248a_lcd::_putc(int value)
masato 11:0145579c487f 514 {
masato 11:0145579c487f 515 if (value == '\n') { // new line
masato 11:0145579c487f 516 char_x = 0;
masato 11:0145579c487f 517 char_y = char_y + font[2];
masato 11:0145579c487f 518 if (char_y >= height() - font[2]) {
masato 11:0145579c487f 519 char_y = 0;
masato 11:0145579c487f 520 }
masato 11:0145579c487f 521 } else {
masato 11:0145579c487f 522 character(char_x, char_y, value);
masato 11:0145579c487f 523 if(auto_up) copy_to_lcd();
masato 11:0145579c487f 524 }
masato 11:0145579c487f 525 return value;
masato 11:0145579c487f 526 }
masato 11:0145579c487f 527
masato 11:0145579c487f 528 void aqm1248a_lcd::character(int x, int y, int c)
masato 11:0145579c487f 529 {
masato 11:0145579c487f 530 unsigned int hor,vert,offset,bpl,j,i,b;
masato 11:0145579c487f 531 unsigned char* zeichen;
masato 11:0145579c487f 532 unsigned char z,w;
masato 11:0145579c487f 533
masato 11:0145579c487f 534 if ((c < 31) || (c > 127)) return; // test char range
masato 11:0145579c487f 535
masato 11:0145579c487f 536 // read font parameter from start of array
masato 11:0145579c487f 537 offset = font[0]; // bytes / char
masato 11:0145579c487f 538 hor = font[1]; // get hor size of font
masato 11:0145579c487f 539 vert = font[2]; // get vert size of font
masato 11:0145579c487f 540 bpl = font[3]; // bytes per line
masato 11:0145579c487f 541
masato 11:0145579c487f 542 if (char_x + hor > width()) {
masato 11:0145579c487f 543 char_x = 0;
masato 11:0145579c487f 544 char_y = char_y + vert;
masato 11:0145579c487f 545 if (char_y >= height() - font[2]) {
masato 11:0145579c487f 546 char_y = 0;
masato 11:0145579c487f 547 }
masato 11:0145579c487f 548 }
masato 11:0145579c487f 549
masato 11:0145579c487f 550 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
masato 11:0145579c487f 551 w = zeichen[0]; // width of actual char
masato 11:0145579c487f 552 // construct the char into the buffer
masato 11:0145579c487f 553 for (j=0; j<vert; j++) { // vert line
masato 11:0145579c487f 554 for (i=0; i<hor; i++) { // horz line
masato 11:0145579c487f 555 z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
masato 11:0145579c487f 556 b = 1 << (j & 0x07);
masato 11:0145579c487f 557 if (( z & b ) == 0x00) {
masato 11:0145579c487f 558 pixel(x+i,y+j,0);
masato 11:0145579c487f 559 } else {
masato 11:0145579c487f 560 pixel(x+i,y+j,1);
masato 11:0145579c487f 561 }
masato 11:0145579c487f 562
masato 11:0145579c487f 563 }
masato 11:0145579c487f 564 }
masato 11:0145579c487f 565
masato 11:0145579c487f 566 char_x += w;
masato 11:0145579c487f 567 }
masato 11:0145579c487f 568
masato 11:0145579c487f 569 void aqm1248a_lcd::set_font(unsigned char* f)
masato 11:0145579c487f 570 {
masato 11:0145579c487f 571 font = f;
masato 11:0145579c487f 572 }
masato 11:0145579c487f 573
masato 11:0145579c487f 574 void aqm1248a_lcd::set_auto_up(unsigned int up)
masato 11:0145579c487f 575 {
masato 11:0145579c487f 576 if(up ) auto_up = 1;
masato 11:0145579c487f 577 else auto_up = 0;
masato 11:0145579c487f 578 }
masato 11:0145579c487f 579
masato 11:0145579c487f 580 unsigned int aqm1248a_lcd::get_auto_up(void)
masato 11:0145579c487f 581 {
masato 11:0145579c487f 582 return (auto_up);
masato 11:0145579c487f 583 }
masato 11:0145579c487f 584
masato 11:0145579c487f 585 void aqm1248a_lcd::print_bm(Bitmap bm, int x, int y)
masato 11:0145579c487f 586 {
masato 11:0145579c487f 587 int h,v,b;
masato 11:0145579c487f 588 char d;
masato 11:0145579c487f 589
masato 11:0145579c487f 590 for(v=0; v < bm.ySize; v++) { // lines
masato 11:0145579c487f 591 for(h=0; h < bm.xSize; h++) { // pixel
masato 11:0145579c487f 592 if(h + x > WIDTH-1) break;
masato 11:0145579c487f 593 if(v + y > HEIGHT-1) break;
masato 11:0145579c487f 594 d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)];
masato 11:0145579c487f 595 b = 0x80 >> (h & 0x07);
masato 11:0145579c487f 596 if((d & b) == 0) {
masato 11:0145579c487f 597 pixel(x+h,y+v,0);
masato 11:0145579c487f 598 } else {
masato 11:0145579c487f 599 pixel(x+h,y+v,1);
masato 11:0145579c487f 600 }
masato 11:0145579c487f 601 }
masato 11:0145579c487f 602 }
masato 11:0145579c487f 603
masato 11:0145579c487f 604 }
masato 11:0145579c487f 605