64x128 Graphic LCD Library

Dependencies:   LCD_fonts

Fork of C12832_lcd by Peter Drescher

Committer:
tonydbeck
Date:
Tue Jan 21 22:53:24 2014 +0000
Revision:
12:66b988c1b143
Parent:
10:269eddb2b7c5
Removed gLCD:: from set_auto_up and get_auto_up in gLCD.h as this is not required and can cause errors in offline compliers

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:4bbc531be6e2 1 /* mbed library for the mbed Lab Board 128*32 pixel LCD
dreschpe 0:4bbc531be6e2 2 * use C12832 controller
dreschpe 0:4bbc531be6e2 3 * Copyright (c) 2012 Peter Drescher - DC2PD
dreschpe 0:4bbc531be6e2 4 * Released under the MIT License: http://mbed.org/license/mit
dreschpe 0:4bbc531be6e2 5 *
dreschpe 0:4bbc531be6e2 6 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dreschpe 0:4bbc531be6e2 7 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dreschpe 0:4bbc531be6e2 8 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
dreschpe 0:4bbc531be6e2 9 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dreschpe 0:4bbc531be6e2 10 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
dreschpe 0:4bbc531be6e2 11 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
dreschpe 0:4bbc531be6e2 12 * THE SOFTWARE.
dreschpe 0:4bbc531be6e2 13 */
dreschpe 0:4bbc531be6e2 14
dreschpe 0:4bbc531be6e2 15 // 13.10.12 initial design
dreschpe 3:468cdccff7af 16 // 25.10.12 add autorefresh of screen
dreschpe 3:468cdccff7af 17 // 25.10.12 add standart font
dreschpe 3:468cdccff7af 18
dreschpe 0:4bbc531be6e2 19 // optional defines :
dreschpe 3:468cdccff7af 20 // #define debug_lcd 1
dreschpe 0:4bbc531be6e2 21
tonydbeck 9:4b0d5aee5371 22 #include "gLCD.h"
dreschpe 0:4bbc531be6e2 23 #include "mbed.h"
dreschpe 0:4bbc531be6e2 24 #include "stdio.h"
tonydbeck 10:269eddb2b7c5 25
dreschpe 0:4bbc531be6e2 26
dreschpe 0:4bbc531be6e2 27 #define BPP 1 // Bits per pixel
dreschpe 0:4bbc531be6e2 28
tonydbeck 10:269eddb2b7c5 29 gLCD::gLCD(PinName cs,
tonydbeck 10:269eddb2b7c5 30 PinName res,
tonydbeck 10:269eddb2b7c5 31 PinName rs,
tonydbeck 10:269eddb2b7c5 32 PinName sdo, PinName sdi, PinName scl,
tonydbeck 10:269eddb2b7c5 33 PinName bcl,
tonydbeck 10:269eddb2b7c5 34 const char* name)
tonydbeck 10:269eddb2b7c5 35 : _spi(sdo,sdi,scl),_reset(res),_A0(rs),_CS(cs),backLight(bcl),GraphicsDisplay(name)
dreschpe 0:4bbc531be6e2 36 {
dreschpe 0:4bbc531be6e2 37 orientation = 1;
dreschpe 0:4bbc531be6e2 38 draw_mode = NORMAL;
dreschpe 0:4bbc531be6e2 39 char_x = 0;
dreschpe 0:4bbc531be6e2 40 lcd_reset();
dreschpe 0:4bbc531be6e2 41 }
dreschpe 0:4bbc531be6e2 42
tonydbeck 9:4b0d5aee5371 43 int gLCD::width()
dreschpe 0:4bbc531be6e2 44 {
tonydbeck 10:269eddb2b7c5 45 if (orientation == 0 || orientation == 2) return 64;
dreschpe 0:4bbc531be6e2 46 else return 128;
dreschpe 0:4bbc531be6e2 47 }
dreschpe 0:4bbc531be6e2 48
tonydbeck 9:4b0d5aee5371 49 int gLCD::height()
dreschpe 0:4bbc531be6e2 50 {
dreschpe 0:4bbc531be6e2 51 if (orientation == 0 || orientation == 2) return 128;
tonydbeck 10:269eddb2b7c5 52 else return 64;
dreschpe 0:4bbc531be6e2 53 }
tonydbeck 10:269eddb2b7c5 54 float bclValue = 1;
dreschpe 0:4bbc531be6e2 55
tonydbeck 10:269eddb2b7c5 56 void gLCD::bclIncrease()
tonydbeck 10:269eddb2b7c5 57 {
tonydbeck 10:269eddb2b7c5 58 bclValue+=0.1;
tonydbeck 10:269eddb2b7c5 59 if(bclValue > 1) bclValue = 1;
tonydbeck 10:269eddb2b7c5 60 backLight = bclValue;
tonydbeck 10:269eddb2b7c5 61 }
tonydbeck 10:269eddb2b7c5 62 void gLCD::bclDecrease()
tonydbeck 10:269eddb2b7c5 63 {
tonydbeck 10:269eddb2b7c5 64 bclValue-=0.1;
tonydbeck 10:269eddb2b7c5 65 if(bclValue < 0) bclValue = 0;
tonydbeck 10:269eddb2b7c5 66 backLight = bclValue;
tonydbeck 10:269eddb2b7c5 67 }
tonydbeck 10:269eddb2b7c5 68
dreschpe 0:4bbc531be6e2 69
tonydbeck 10:269eddb2b7c5 70 void gLCD::set_orientation(unsigned int o)
dreschpe 0:4bbc531be6e2 71 {
dreschpe 0:4bbc531be6e2 72 orientation = o;
dreschpe 0:4bbc531be6e2 73 switch (o) {
dreschpe 0:4bbc531be6e2 74 case (0):
dreschpe 0:4bbc531be6e2 75 wr_cmd(0xA0);
dreschpe 0:4bbc531be6e2 76 wr_cmd(0xC0);
dreschpe 0:4bbc531be6e2 77 break;
dreschpe 0:4bbc531be6e2 78 case (1):
dreschpe 0:4bbc531be6e2 79 wr_cmd(0xA0);
dreschpe 0:4bbc531be6e2 80 wr_cmd(0xC8);
dreschpe 0:4bbc531be6e2 81 break;
dreschpe 0:4bbc531be6e2 82 case (2):
dreschpe 0:4bbc531be6e2 83 wr_cmd(0xA1);
dreschpe 0:4bbc531be6e2 84 wr_cmd(0xC8);
dreschpe 0:4bbc531be6e2 85 break;
dreschpe 0:4bbc531be6e2 86 case (3):
dreschpe 0:4bbc531be6e2 87 wr_cmd(0xA1);
dreschpe 0:4bbc531be6e2 88 wr_cmd(0xC0);
dreschpe 0:4bbc531be6e2 89 break;
dreschpe 0:4bbc531be6e2 90 }
dreschpe 0:4bbc531be6e2 91 }
dreschpe 0:4bbc531be6e2 92
tonydbeck 10:269eddb2b7c5 93
dreschpe 1:66dd8afbfd06 94
tonydbeck 9:4b0d5aee5371 95 void gLCD::invert(unsigned int o)
dreschpe 0:4bbc531be6e2 96 {
dreschpe 0:4bbc531be6e2 97 if(o == 0) wr_cmd(0xA6);
dreschpe 0:4bbc531be6e2 98 else wr_cmd(0xA7);
dreschpe 0:4bbc531be6e2 99 }
dreschpe 0:4bbc531be6e2 100
dreschpe 0:4bbc531be6e2 101
tonydbeck 9:4b0d5aee5371 102 void gLCD::set_contrast(unsigned int o)
dreschpe 0:4bbc531be6e2 103 {
dreschpe 1:66dd8afbfd06 104 contrast = o;
dreschpe 0:4bbc531be6e2 105 wr_cmd(0x81); // set volume
dreschpe 2:bdc53502af17 106 wr_cmd(o & 0x3F);
dreschpe 0:4bbc531be6e2 107 }
dreschpe 0:4bbc531be6e2 108
tonydbeck 9:4b0d5aee5371 109 unsigned int gLCD::get_contrast(void)
dreschpe 1:66dd8afbfd06 110 {
dreschpe 1:66dd8afbfd06 111 return(contrast);
dreschpe 1:66dd8afbfd06 112 }
dreschpe 1:66dd8afbfd06 113
dreschpe 0:4bbc531be6e2 114
dreschpe 0:4bbc531be6e2 115 // write command to lcd controller
dreschpe 0:4bbc531be6e2 116
tonydbeck 9:4b0d5aee5371 117 void gLCD::wr_cmd(unsigned char cmd)
dreschpe 0:4bbc531be6e2 118 {
dreschpe 0:4bbc531be6e2 119 _A0 = 0;
dreschpe 0:4bbc531be6e2 120 _CS = 0;
dreschpe 2:bdc53502af17 121 #if defined TARGET_LPC1768 // fast without mbed lib
dreschpe 0:4bbc531be6e2 122 LPC_SSP1->DR = cmd;
dreschpe 0:4bbc531be6e2 123 do {
dreschpe 0:4bbc531be6e2 124 } while ((LPC_SSP1->SR & 0x10) == 0x10); // wait for SPI1 idle
dreschpe 2:bdc53502af17 125 #else
dreschpe 2:bdc53502af17 126 _spi.write(cmd);
dreschpe 2:bdc53502af17 127 #endif
tonydbeck 10:269eddb2b7c5 128 _A0 = 1;
tonydbeck 10:269eddb2b7c5 129 wait(0.000040f);
tonydbeck 10:269eddb2b7c5 130 _A0 = 0;
tonydbeck 10:269eddb2b7c5 131 _CS = 1;
dreschpe 0:4bbc531be6e2 132 }
dreschpe 0:4bbc531be6e2 133
dreschpe 0:4bbc531be6e2 134 // write data to lcd controller
dreschpe 0:4bbc531be6e2 135
tonydbeck 9:4b0d5aee5371 136 void gLCD::wr_dat(unsigned char dat)
dreschpe 0:4bbc531be6e2 137 {
dreschpe 0:4bbc531be6e2 138 _A0 = 1;
dreschpe 0:4bbc531be6e2 139 _CS = 0;
dreschpe 2:bdc53502af17 140 #if defined TARGET_LPC1768 // fast without mbed lib
dreschpe 0:4bbc531be6e2 141 LPC_SSP1->DR = dat;
dreschpe 0:4bbc531be6e2 142 do {
dreschpe 0:4bbc531be6e2 143 } while ((LPC_SSP1->SR & 0x10) == 0x10); // wait for SPI1 idle
dreschpe 2:bdc53502af17 144 #else
dreschpe 2:bdc53502af17 145 _spi.write(dat);
dreschpe 2:bdc53502af17 146 #endif
tonydbeck 10:269eddb2b7c5 147 _A0 = 0;
tonydbeck 10:269eddb2b7c5 148 wait(0.000040f);
tonydbeck 10:269eddb2b7c5 149 _A0 = 1;
dreschpe 0:4bbc531be6e2 150 _CS = 1;
dreschpe 0:4bbc531be6e2 151 }
dreschpe 0:4bbc531be6e2 152
dreschpe 0:4bbc531be6e2 153 // reset and init the lcd controller
dreschpe 0:4bbc531be6e2 154
tonydbeck 9:4b0d5aee5371 155 void gLCD::lcd_reset()
dreschpe 0:4bbc531be6e2 156 {
dreschpe 0:4bbc531be6e2 157
tonydbeck 10:269eddb2b7c5 158 _spi.format(8,0); // 8 bit spi mode 0
dreschpe 0:4bbc531be6e2 159 _spi.frequency(20000000); // 19,2 Mhz SPI clock
dreschpe 0:4bbc531be6e2 160 _A0 = 0;
dreschpe 0:4bbc531be6e2 161 _CS = 1;
dreschpe 0:4bbc531be6e2 162 _reset = 0; // display reset
tonydbeck 10:269eddb2b7c5 163 wait(0.015); //Give display 15ms to reset
dreschpe 0:4bbc531be6e2 164 _reset = 1; // end reset
dreschpe 0:4bbc531be6e2 165 wait_ms(5);
tonydbeck 10:269eddb2b7c5 166 backLight.period_ms(1);
tonydbeck 10:269eddb2b7c5 167 backLight.pulsewidth_ms(1);
tonydbeck 10:269eddb2b7c5 168 backLight = 1;
dreschpe 0:4bbc531be6e2 169 /* Start Initial Sequence ----------------------------------------------------*/
dreschpe 0:4bbc531be6e2 170
tonydbeck 10:269eddb2b7c5 171 /* wr_cmd(0xAE); // display off
dreschpe 0:4bbc531be6e2 172 wr_cmd(0xA2); // bias voltage
dreschpe 0:4bbc531be6e2 173
tonydbeck 10:269eddb2b7c5 174
dreschpe 0:4bbc531be6e2 175
dreschpe 0:4bbc531be6e2 176 wr_cmd(0x22); // voltage resistor ratio
dreschpe 0:4bbc531be6e2 177 wr_cmd(0x2F); // power on
dreschpe 1:66dd8afbfd06 178 //wr_cmd(0xA4); // LCD display ram
dreschpe 0:4bbc531be6e2 179 wr_cmd(0x40); // start line = 0
dreschpe 0:4bbc531be6e2 180 wr_cmd(0xAF); // display ON
dreschpe 0:4bbc531be6e2 181
dreschpe 0:4bbc531be6e2 182 wr_cmd(0x81); // set contrast
dreschpe 0:4bbc531be6e2 183 wr_cmd(0x17); // set contrast
dreschpe 0:4bbc531be6e2 184
dreschpe 0:4bbc531be6e2 185 wr_cmd(0xA6); // display normal
tonydbeck 10:269eddb2b7c5 186 */
tonydbeck 10:269eddb2b7c5 187 wr_cmd(0xA0); //SEG1->SEG132 x direction
tonydbeck 10:269eddb2b7c5 188 wr_cmd(0xC8); //COM1->COM64 y direction
tonydbeck 10:269eddb2b7c5 189 wr_cmd(0xA3); // 1/9 bias
tonydbeck 10:269eddb2b7c5 190 wr_cmd(0x2C); //Voltage converter on
tonydbeck 10:269eddb2b7c5 191 wait(0.001);
tonydbeck 10:269eddb2b7c5 192 wr_cmd(0x2E); //Voltage regulator on
tonydbeck 10:269eddb2b7c5 193 wait(0.001);
tonydbeck 10:269eddb2b7c5 194 wr_cmd(0x2F); //Voltage follower on
tonydbeck 10:269eddb2b7c5 195 wr_cmd(0x26); //voltage reg ratio = 5.29
tonydbeck 10:269eddb2b7c5 196 wr_cmd(0x81); //Enter voltage resistor set mode
tonydbeck 10:269eddb2b7c5 197 wr_cmd(0x8); //Set volt res (contrast)
tonydbeck 10:269eddb2b7c5 198 wr_cmd(0x40); //initial display line = 0
tonydbeck 10:269eddb2b7c5 199 wr_cmd(0xB0); //initial page address = 0
tonydbeck 10:269eddb2b7c5 200 wr_cmd(0x00);
tonydbeck 10:269eddb2b7c5 201 wr_cmd(0x10); //Sets first col
tonydbeck 10:269eddb2b7c5 202 wr_cmd(0xA6); //not inverse display
tonydbeck 10:269eddb2b7c5 203 wr_cmd(0xAD); //Static indicator off
tonydbeck 10:269eddb2b7c5 204 wr_cmd(0x00); //no blinking
tonydbeck 10:269eddb2b7c5 205 wr_cmd(0xAF); //display on
dreschpe 2:bdc53502af17 206 #if defined TARGET_LPC1768 //setup DMA channel 0
dreschpe 0:4bbc531be6e2 207 LPC_SC->PCONP |= (1UL << 29); // Power up the GPDMA
dreschpe 2:bdc53502af17 208 LPC_GPDMA->DMACConfig = 1; // enable DMA controller
dreschpe 0:4bbc531be6e2 209 LPC_GPDMA->DMACIntTCClear = 0x1;
dreschpe 0:4bbc531be6e2 210 LPC_GPDMA->DMACIntErrClr = 0x1;
dreschpe 0:4bbc531be6e2 211 LPC_GPDMACH0->DMACCLLI = 0;
dreschpe 2:bdc53502af17 212 #endif
dreschpe 0:4bbc531be6e2 213 // clear and update LCD
dreschpe 0:4bbc531be6e2 214 memset(buffer,0x00,512); // clear display buffer
dreschpe 0:4bbc531be6e2 215 copy_to_lcd();
dreschpe 3:468cdccff7af 216 auto_up = 1; // switch on auto update
tonydbeck 10:269eddb2b7c5 217 claim(stdout); // redirect printf to lcd
dreschpe 3:468cdccff7af 218 locate(0,0);
tonydbeck 10:269eddb2b7c5 219 set_font((unsigned char*)Small_7); // standard font
dreschpe 0:4bbc531be6e2 220 }
dreschpe 0:4bbc531be6e2 221
dreschpe 0:4bbc531be6e2 222 // set one pixel in buffer
dreschpe 0:4bbc531be6e2 223
tonydbeck 9:4b0d5aee5371 224 void gLCD::pixel(int x, int y, int color)
dreschpe 0:4bbc531be6e2 225 {
dreschpe 0:4bbc531be6e2 226 // first check parameter
tonydbeck 10:269eddb2b7c5 227 if(x > 128 || y > 64 || x < 0 || y < 0) return;
dreschpe 0:4bbc531be6e2 228
dreschpe 0:4bbc531be6e2 229 if(draw_mode == NORMAL) {
dreschpe 0:4bbc531be6e2 230 if(color == 0)
dreschpe 0:4bbc531be6e2 231 buffer[x + ((y/8) * 128)] &= ~(1 << (y%8)); // erase pixel
dreschpe 0:4bbc531be6e2 232 else
dreschpe 0:4bbc531be6e2 233 buffer[x + ((y/8) * 128)] |= (1 << (y%8)); // set pixel
dreschpe 0:4bbc531be6e2 234 } else { // XOR mode
dreschpe 0:4bbc531be6e2 235 if(color == 1)
dreschpe 0:4bbc531be6e2 236 buffer[x + ((y/8) * 128)] ^= (1 << (y%8)); // xor pixel
dreschpe 0:4bbc531be6e2 237 }
dreschpe 0:4bbc531be6e2 238 }
dreschpe 0:4bbc531be6e2 239
dreschpe 0:4bbc531be6e2 240 // update lcd
dreschpe 0:4bbc531be6e2 241
tonydbeck 9:4b0d5aee5371 242 void gLCD::copy_to_lcd(void)
dreschpe 0:4bbc531be6e2 243 {
dreschpe 2:bdc53502af17 244 #ifndef TARGET_LPC1768
dreschpe 2:bdc53502af17 245 int i;
dreschpe 2:bdc53502af17 246 #endif
dreschpe 0:4bbc531be6e2 247 //page 0
dreschpe 0:4bbc531be6e2 248 wr_cmd(0x00); // set column low nibble 0
dreschpe 0:4bbc531be6e2 249 wr_cmd(0x10); // set column hi nibble 0
dreschpe 0:4bbc531be6e2 250 wr_cmd(0xB0); // set page address 0
dreschpe 2:bdc53502af17 251 _A0 = 1;
dreschpe 2:bdc53502af17 252 #if defined TARGET_LPC1768
dreschpe 0:4bbc531be6e2 253 _CS = 0;
dreschpe 0:4bbc531be6e2 254 // start 128 byte DMA transfer to SPI1
dreschpe 0:4bbc531be6e2 255 LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1
dreschpe 0:4bbc531be6e2 256 LPC_SSP1->DMACR = 0x2; // Enable SSP1 for DMA.
dreschpe 0:4bbc531be6e2 257 LPC_GPDMA->DMACIntTCClear = 0x1;
dreschpe 0:4bbc531be6e2 258 LPC_GPDMA->DMACIntErrClr = 0x1;
dreschpe 0:4bbc531be6e2 259 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer);
dreschpe 0:4bbc531be6e2 260 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
dreschpe 0:4bbc531be6e2 261 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
dreschpe 0:4bbc531be6e2 262 LPC_GPDMA->DMACSoftSReq = 0x1;
dreschpe 0:4bbc531be6e2 263 do {
dreschpe 0:4bbc531be6e2 264 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
dreschpe 0:4bbc531be6e2 265 do {
dreschpe 0:4bbc531be6e2 266 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
dreschpe 0:4bbc531be6e2 267 _CS = 1;
dreschpe 2:bdc53502af17 268 #else // no DMA
dreschpe 2:bdc53502af17 269 for(i=0;i<128;i++){
dreschpe 2:bdc53502af17 270 wr_dat(buffer[i]);
dreschpe 2:bdc53502af17 271 }
dreschpe 2:bdc53502af17 272 #endif
dreschpe 0:4bbc531be6e2 273
dreschpe 0:4bbc531be6e2 274 // page 1
dreschpe 0:4bbc531be6e2 275 wr_cmd(0x00); // set column low nibble 0
dreschpe 0:4bbc531be6e2 276 wr_cmd(0x10); // set column hi nibble 0
dreschpe 0:4bbc531be6e2 277 wr_cmd(0xB1); // set page address 1
dreschpe 2:bdc53502af17 278 _A0 = 1;
dreschpe 2:bdc53502af17 279 #if defined TARGET_LPC1768
dreschpe 0:4bbc531be6e2 280 _CS = 0;
dreschpe 0:4bbc531be6e2 281 // start 128 byte DMA transfer to SPI1
dreschpe 0:4bbc531be6e2 282 LPC_GPDMA->DMACIntTCClear = 0x1;
dreschpe 0:4bbc531be6e2 283 LPC_GPDMA->DMACIntErrClr = 0x1;
dreschpe 0:4bbc531be6e2 284 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 128);
dreschpe 0:4bbc531be6e2 285 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
dreschpe 0:4bbc531be6e2 286 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
dreschpe 0:4bbc531be6e2 287 LPC_GPDMA->DMACSoftSReq = 0x1;
dreschpe 0:4bbc531be6e2 288 do {
dreschpe 0:4bbc531be6e2 289 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
dreschpe 0:4bbc531be6e2 290 do {
dreschpe 0:4bbc531be6e2 291 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
dreschpe 0:4bbc531be6e2 292 _CS = 1;
dreschpe 2:bdc53502af17 293 #else // no DMA
dreschpe 2:bdc53502af17 294 for(i=128;i<256;i++){
dreschpe 2:bdc53502af17 295 wr_dat(buffer[i]);
dreschpe 2:bdc53502af17 296 }
dreschpe 2:bdc53502af17 297 #endif
dreschpe 0:4bbc531be6e2 298
dreschpe 0:4bbc531be6e2 299 //page 2
dreschpe 0:4bbc531be6e2 300 wr_cmd(0x00); // set column low nibble 0
dreschpe 0:4bbc531be6e2 301 wr_cmd(0x10); // set column hi nibble 0
dreschpe 0:4bbc531be6e2 302 wr_cmd(0xB2); // set page address 2
dreschpe 2:bdc53502af17 303 _A0 = 1;
dreschpe 2:bdc53502af17 304 #if defined TARGET_LPC1768
dreschpe 0:4bbc531be6e2 305 _CS = 0;
dreschpe 0:4bbc531be6e2 306 // start 128 byte DMA transfer to SPI1
dreschpe 0:4bbc531be6e2 307 LPC_GPDMA->DMACIntTCClear = 0x1;
dreschpe 0:4bbc531be6e2 308 LPC_GPDMA->DMACIntErrClr = 0x1;
dreschpe 0:4bbc531be6e2 309 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 256);
dreschpe 0:4bbc531be6e2 310 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
dreschpe 0:4bbc531be6e2 311 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX ;
dreschpe 0:4bbc531be6e2 312 LPC_GPDMA->DMACSoftSReq = 0x1;
dreschpe 0:4bbc531be6e2 313 do {
dreschpe 0:4bbc531be6e2 314 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
dreschpe 0:4bbc531be6e2 315 do {
dreschpe 0:4bbc531be6e2 316 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
dreschpe 0:4bbc531be6e2 317 _CS = 1;
dreschpe 2:bdc53502af17 318 #else // no DMA
dreschpe 2:bdc53502af17 319 for(i=256;i<384;i++){
dreschpe 2:bdc53502af17 320 wr_dat(buffer[i]);
dreschpe 2:bdc53502af17 321 }
dreschpe 2:bdc53502af17 322 #endif
dreschpe 2:bdc53502af17 323
dreschpe 0:4bbc531be6e2 324 //page 3
dreschpe 0:4bbc531be6e2 325 wr_cmd(0x00); // set column low nibble 0
dreschpe 0:4bbc531be6e2 326 wr_cmd(0x10); // set column hi nibble 0
dreschpe 0:4bbc531be6e2 327 wr_cmd(0xB3); // set page address 3
dreschpe 0:4bbc531be6e2 328 _A0 = 1;
dreschpe 2:bdc53502af17 329
dreschpe 2:bdc53502af17 330 _CS = 0;
dreschpe 2:bdc53502af17 331 #if defined TARGET_LPC1768
dreschpe 0:4bbc531be6e2 332 // start 128 byte DMA transfer to SPI1
dreschpe 0:4bbc531be6e2 333 LPC_GPDMA->DMACIntTCClear = 0x1;
dreschpe 0:4bbc531be6e2 334 LPC_GPDMA->DMACIntErrClr = 0x1;
dreschpe 0:4bbc531be6e2 335 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 384);
dreschpe 0:4bbc531be6e2 336 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
dreschpe 0:4bbc531be6e2 337 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
dreschpe 0:4bbc531be6e2 338 LPC_GPDMA->DMACSoftSReq = 0x1;
dreschpe 0:4bbc531be6e2 339 do {
dreschpe 0:4bbc531be6e2 340 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
dreschpe 0:4bbc531be6e2 341 do {
dreschpe 0:4bbc531be6e2 342 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
dreschpe 0:4bbc531be6e2 343 _CS = 1;
dreschpe 2:bdc53502af17 344 #else // no DMA
dreschpe 2:bdc53502af17 345 for(i=384;i<512;i++){
dreschpe 2:bdc53502af17 346 wr_dat(buffer[i]);
dreschpe 2:bdc53502af17 347 }
tonydbeck 10:269eddb2b7c5 348 #endif
tonydbeck 10:269eddb2b7c5 349
tonydbeck 10:269eddb2b7c5 350 //page 4
tonydbeck 10:269eddb2b7c5 351 wr_cmd(0x00); // set column low nibble 0
tonydbeck 10:269eddb2b7c5 352 wr_cmd(0x10); // set column hi nibble 0
tonydbeck 10:269eddb2b7c5 353 wr_cmd(0xB4); // set page address 4
tonydbeck 10:269eddb2b7c5 354 _A0 = 1;
tonydbeck 10:269eddb2b7c5 355
tonydbeck 10:269eddb2b7c5 356 _CS = 0;
tonydbeck 10:269eddb2b7c5 357 #if defined TARGET_LPC1768
tonydbeck 10:269eddb2b7c5 358 // start 128 byte DMA transfer to SPI1
tonydbeck 10:269eddb2b7c5 359 LPC_GPDMA->DMACIntTCClear = 0x1;
tonydbeck 10:269eddb2b7c5 360 LPC_GPDMA->DMACIntErrClr = 0x1;
tonydbeck 10:269eddb2b7c5 361 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 512);
tonydbeck 10:269eddb2b7c5 362 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
tonydbeck 10:269eddb2b7c5 363 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
tonydbeck 10:269eddb2b7c5 364 LPC_GPDMA->DMACSoftSReq = 0x1;
tonydbeck 10:269eddb2b7c5 365 do {
tonydbeck 10:269eddb2b7c5 366 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
tonydbeck 10:269eddb2b7c5 367 do {
tonydbeck 10:269eddb2b7c5 368 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
tonydbeck 10:269eddb2b7c5 369 _CS = 1;
tonydbeck 10:269eddb2b7c5 370 #else // no DMA
tonydbeck 10:269eddb2b7c5 371 for(i=512;i<640;i++){
tonydbeck 10:269eddb2b7c5 372 wr_dat(buffer[i]);
tonydbeck 10:269eddb2b7c5 373 }
tonydbeck 10:269eddb2b7c5 374 #endif
tonydbeck 10:269eddb2b7c5 375
tonydbeck 10:269eddb2b7c5 376 //page 5
tonydbeck 10:269eddb2b7c5 377 wr_cmd(0x00); // set column low nibble 0
tonydbeck 10:269eddb2b7c5 378 wr_cmd(0x10); // set column hi nibble 0
tonydbeck 10:269eddb2b7c5 379 wr_cmd(0xB5); // set page address 5
tonydbeck 10:269eddb2b7c5 380 _A0 = 1;
tonydbeck 10:269eddb2b7c5 381
tonydbeck 10:269eddb2b7c5 382 _CS = 0;
tonydbeck 10:269eddb2b7c5 383 #if defined TARGET_LPC1768
tonydbeck 10:269eddb2b7c5 384 // start 128 byte DMA transfer to SPI1
tonydbeck 10:269eddb2b7c5 385 LPC_GPDMA->DMACIntTCClear = 0x1;
tonydbeck 10:269eddb2b7c5 386 LPC_GPDMA->DMACIntErrClr = 0x1;
tonydbeck 10:269eddb2b7c5 387 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 640);
tonydbeck 10:269eddb2b7c5 388 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
tonydbeck 10:269eddb2b7c5 389 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
tonydbeck 10:269eddb2b7c5 390 LPC_GPDMA->DMACSoftSReq = 0x1;
tonydbeck 10:269eddb2b7c5 391 do {
tonydbeck 10:269eddb2b7c5 392 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
tonydbeck 10:269eddb2b7c5 393 do {
tonydbeck 10:269eddb2b7c5 394 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
tonydbeck 10:269eddb2b7c5 395 _CS = 1;
tonydbeck 10:269eddb2b7c5 396 #else // no DMA
tonydbeck 10:269eddb2b7c5 397 for(i=640;i<768;i++){
tonydbeck 10:269eddb2b7c5 398 wr_dat(buffer[i]);
tonydbeck 10:269eddb2b7c5 399 }
tonydbeck 10:269eddb2b7c5 400 #endif
tonydbeck 10:269eddb2b7c5 401
tonydbeck 10:269eddb2b7c5 402 //page 6
tonydbeck 10:269eddb2b7c5 403 wr_cmd(0x00); // set column low nibble 0
tonydbeck 10:269eddb2b7c5 404 wr_cmd(0x10); // set column hi nibble 0
tonydbeck 10:269eddb2b7c5 405 wr_cmd(0xB6); // set page address 6
tonydbeck 10:269eddb2b7c5 406 _A0 = 1;
tonydbeck 10:269eddb2b7c5 407
tonydbeck 10:269eddb2b7c5 408 _CS = 0;
tonydbeck 10:269eddb2b7c5 409 #if defined TARGET_LPC1768
tonydbeck 10:269eddb2b7c5 410 // start 128 byte DMA transfer to SPI1
tonydbeck 10:269eddb2b7c5 411 LPC_GPDMA->DMACIntTCClear = 0x1;
tonydbeck 10:269eddb2b7c5 412 LPC_GPDMA->DMACIntErrClr = 0x1;
tonydbeck 10:269eddb2b7c5 413 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 768);
tonydbeck 10:269eddb2b7c5 414 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
tonydbeck 10:269eddb2b7c5 415 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
tonydbeck 10:269eddb2b7c5 416 LPC_GPDMA->DMACSoftSReq = 0x1;
tonydbeck 10:269eddb2b7c5 417 do {
tonydbeck 10:269eddb2b7c5 418 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
tonydbeck 10:269eddb2b7c5 419 do {
tonydbeck 10:269eddb2b7c5 420 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
tonydbeck 10:269eddb2b7c5 421 _CS = 1;
tonydbeck 10:269eddb2b7c5 422 #else // no DMA
tonydbeck 10:269eddb2b7c5 423 for(i=768;i<896;i++){
tonydbeck 10:269eddb2b7c5 424 wr_dat(buffer[i]);
tonydbeck 10:269eddb2b7c5 425 }
tonydbeck 10:269eddb2b7c5 426 #endif
tonydbeck 10:269eddb2b7c5 427
tonydbeck 10:269eddb2b7c5 428 //page 7
tonydbeck 10:269eddb2b7c5 429 wr_cmd(0x00); // set column low nibble 0
tonydbeck 10:269eddb2b7c5 430 wr_cmd(0x10); // set column hi nibble 0
tonydbeck 10:269eddb2b7c5 431 wr_cmd(0xB7); // set page address 7
tonydbeck 10:269eddb2b7c5 432 _A0 = 1;
tonydbeck 10:269eddb2b7c5 433
tonydbeck 10:269eddb2b7c5 434 _CS = 0;
tonydbeck 10:269eddb2b7c5 435 #if defined TARGET_LPC1768
tonydbeck 10:269eddb2b7c5 436 // start 128 byte DMA transfer to SPI1
tonydbeck 10:269eddb2b7c5 437 LPC_GPDMA->DMACIntTCClear = 0x1;
tonydbeck 10:269eddb2b7c5 438 LPC_GPDMA->DMACIntErrClr = 0x1;
tonydbeck 10:269eddb2b7c5 439 LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 896);
tonydbeck 10:269eddb2b7c5 440 LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt
tonydbeck 10:269eddb2b7c5 441 LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX;
tonydbeck 10:269eddb2b7c5 442 LPC_GPDMA->DMACSoftSReq = 0x1;
tonydbeck 10:269eddb2b7c5 443 do {
tonydbeck 10:269eddb2b7c5 444 } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running
tonydbeck 10:269eddb2b7c5 445 do {
tonydbeck 10:269eddb2b7c5 446 } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle
tonydbeck 10:269eddb2b7c5 447 _CS = 1;
tonydbeck 10:269eddb2b7c5 448 #else // no DMA
tonydbeck 10:269eddb2b7c5 449 for(i=896;i<1024;i++){
tonydbeck 10:269eddb2b7c5 450 wr_dat(buffer[i]);
tonydbeck 10:269eddb2b7c5 451 }
dreschpe 2:bdc53502af17 452 #endif
dreschpe 0:4bbc531be6e2 453 }
dreschpe 0:4bbc531be6e2 454
tonydbeck 9:4b0d5aee5371 455 void gLCD::cls(void)
dreschpe 0:4bbc531be6e2 456 {
tonydbeck 10:269eddb2b7c5 457 memset(buffer,0x00,1024); // clear display buffer
dreschpe 0:4bbc531be6e2 458 copy_to_lcd();
dreschpe 0:4bbc531be6e2 459 }
dreschpe 0:4bbc531be6e2 460
dreschpe 0:4bbc531be6e2 461
tonydbeck 9:4b0d5aee5371 462 void gLCD::line(int x0, int y0, int x1, int y1, int color)
dreschpe 0:4bbc531be6e2 463 {
dreschpe 0:4bbc531be6e2 464 int dx = 0, dy = 0;
dreschpe 0:4bbc531be6e2 465 int dx_sym = 0, dy_sym = 0;
dreschpe 0:4bbc531be6e2 466 int dx_x2 = 0, dy_x2 = 0;
dreschpe 0:4bbc531be6e2 467 int di = 0;
dreschpe 0:4bbc531be6e2 468
dreschpe 0:4bbc531be6e2 469 dx = x1-x0;
dreschpe 0:4bbc531be6e2 470 dy = y1-y0;
dreschpe 0:4bbc531be6e2 471
dreschpe 0:4bbc531be6e2 472 // if (dx == 0) { /* vertical line */
dreschpe 0:4bbc531be6e2 473 // if (y1 > y0) vline(x0,y0,y1,color);
dreschpe 0:4bbc531be6e2 474 // else vline(x0,y1,y0,color);
dreschpe 0:4bbc531be6e2 475 // return;
dreschpe 0:4bbc531be6e2 476 // }
dreschpe 0:4bbc531be6e2 477
dreschpe 0:4bbc531be6e2 478 if (dx > 0) {
dreschpe 0:4bbc531be6e2 479 dx_sym = 1;
dreschpe 0:4bbc531be6e2 480 } else {
dreschpe 0:4bbc531be6e2 481 dx_sym = -1;
dreschpe 0:4bbc531be6e2 482 }
dreschpe 0:4bbc531be6e2 483 // if (dy == 0) { /* horizontal line */
dreschpe 0:4bbc531be6e2 484 // if (x1 > x0) hline(x0,x1,y0,color);
dreschpe 0:4bbc531be6e2 485 // else hline(x1,x0,y0,color);
dreschpe 0:4bbc531be6e2 486 // return;
dreschpe 0:4bbc531be6e2 487 // }
dreschpe 0:4bbc531be6e2 488
dreschpe 0:4bbc531be6e2 489 if (dy > 0) {
dreschpe 0:4bbc531be6e2 490 dy_sym = 1;
dreschpe 0:4bbc531be6e2 491 } else {
dreschpe 0:4bbc531be6e2 492 dy_sym = -1;
dreschpe 0:4bbc531be6e2 493 }
dreschpe 0:4bbc531be6e2 494
dreschpe 0:4bbc531be6e2 495 dx = dx_sym*dx;
dreschpe 0:4bbc531be6e2 496 dy = dy_sym*dy;
dreschpe 0:4bbc531be6e2 497
dreschpe 0:4bbc531be6e2 498 dx_x2 = dx*2;
dreschpe 0:4bbc531be6e2 499 dy_x2 = dy*2;
dreschpe 0:4bbc531be6e2 500
dreschpe 0:4bbc531be6e2 501 if (dx >= dy) {
dreschpe 0:4bbc531be6e2 502 di = dy_x2 - dx;
dreschpe 0:4bbc531be6e2 503 while (x0 != x1) {
dreschpe 0:4bbc531be6e2 504
dreschpe 0:4bbc531be6e2 505 pixel(x0, y0, color);
dreschpe 0:4bbc531be6e2 506 x0 += dx_sym;
dreschpe 0:4bbc531be6e2 507 if (di<0) {
dreschpe 0:4bbc531be6e2 508 di += dy_x2;
dreschpe 0:4bbc531be6e2 509 } else {
dreschpe 0:4bbc531be6e2 510 di += dy_x2 - dx_x2;
dreschpe 0:4bbc531be6e2 511 y0 += dy_sym;
dreschpe 0:4bbc531be6e2 512 }
dreschpe 0:4bbc531be6e2 513 }
dreschpe 0:4bbc531be6e2 514 pixel(x0, y0, color);
dreschpe 0:4bbc531be6e2 515 } else {
dreschpe 0:4bbc531be6e2 516 di = dx_x2 - dy;
dreschpe 0:4bbc531be6e2 517 while (y0 != y1) {
dreschpe 0:4bbc531be6e2 518 pixel(x0, y0, color);
dreschpe 0:4bbc531be6e2 519 y0 += dy_sym;
dreschpe 0:4bbc531be6e2 520 if (di < 0) {
dreschpe 0:4bbc531be6e2 521 di += dx_x2;
dreschpe 0:4bbc531be6e2 522 } else {
dreschpe 0:4bbc531be6e2 523 di += dx_x2 - dy_x2;
dreschpe 0:4bbc531be6e2 524 x0 += dx_sym;
dreschpe 0:4bbc531be6e2 525 }
dreschpe 0:4bbc531be6e2 526 }
dreschpe 0:4bbc531be6e2 527 pixel(x0, y0, color);
dreschpe 0:4bbc531be6e2 528 }
dreschpe 3:468cdccff7af 529 if(auto_up) copy_to_lcd();
dreschpe 0:4bbc531be6e2 530 }
dreschpe 0:4bbc531be6e2 531
tonydbeck 9:4b0d5aee5371 532 void gLCD::rect(int x0, int y0, int x1, int y1, int color)
dreschpe 0:4bbc531be6e2 533 {
dreschpe 0:4bbc531be6e2 534
dreschpe 0:4bbc531be6e2 535 if (x1 > x0) line(x0,y0,x1,y0,color);
dreschpe 0:4bbc531be6e2 536 else line(x1,y0,x0,y0,color);
dreschpe 0:4bbc531be6e2 537
dreschpe 0:4bbc531be6e2 538 if (y1 > y0) line(x0,y0,x0,y1,color);
dreschpe 0:4bbc531be6e2 539 else line(x0,y1,x0,y0,color);
dreschpe 0:4bbc531be6e2 540
dreschpe 0:4bbc531be6e2 541 if (x1 > x0) line(x0,y1,x1,y1,color);
dreschpe 0:4bbc531be6e2 542 else line(x1,y1,x0,y1,color);
dreschpe 0:4bbc531be6e2 543
dreschpe 0:4bbc531be6e2 544 if (y1 > y0) line(x1,y0,x1,y1,color);
dreschpe 0:4bbc531be6e2 545 else line(x1,y1,x1,y0,color);
dreschpe 0:4bbc531be6e2 546
dreschpe 3:468cdccff7af 547 if(auto_up) copy_to_lcd();
dreschpe 0:4bbc531be6e2 548 }
dreschpe 0:4bbc531be6e2 549
tonydbeck 9:4b0d5aee5371 550 void gLCD::fillrect(int x0, int y0, int x1, int y1, int color)
dreschpe 0:4bbc531be6e2 551 {
dreschpe 0:4bbc531be6e2 552 int l,c,i;
dreschpe 0:4bbc531be6e2 553 if(x0 > x1) {
dreschpe 0:4bbc531be6e2 554 i = x0;
dreschpe 0:4bbc531be6e2 555 x0 = x1;
dreschpe 0:4bbc531be6e2 556 x1 = i;
dreschpe 0:4bbc531be6e2 557 }
dreschpe 0:4bbc531be6e2 558
dreschpe 0:4bbc531be6e2 559 if(y0 > y1) {
dreschpe 0:4bbc531be6e2 560 i = y0;
dreschpe 0:4bbc531be6e2 561 y0 = y1;
dreschpe 0:4bbc531be6e2 562 y1 = i;
dreschpe 0:4bbc531be6e2 563 }
dreschpe 0:4bbc531be6e2 564
dreschpe 0:4bbc531be6e2 565 for(l = x0; l<= x1; l ++) {
dreschpe 0:4bbc531be6e2 566 for(c = y0; c<= y1; c++) {
dreschpe 0:4bbc531be6e2 567 pixel(l,c,color);
dreschpe 0:4bbc531be6e2 568 }
dreschpe 0:4bbc531be6e2 569 }
dreschpe 3:468cdccff7af 570 if(auto_up) copy_to_lcd();
dreschpe 0:4bbc531be6e2 571 }
dreschpe 0:4bbc531be6e2 572
dreschpe 0:4bbc531be6e2 573
dreschpe 0:4bbc531be6e2 574
tonydbeck 9:4b0d5aee5371 575 void gLCD::circle(int x0, int y0, int r, int color)
dreschpe 0:4bbc531be6e2 576 {
dreschpe 0:4bbc531be6e2 577
dreschpe 0:4bbc531be6e2 578 int draw_x0, draw_y0;
dreschpe 0:4bbc531be6e2 579 int draw_x1, draw_y1;
dreschpe 0:4bbc531be6e2 580 int draw_x2, draw_y2;
dreschpe 0:4bbc531be6e2 581 int draw_x3, draw_y3;
dreschpe 0:4bbc531be6e2 582 int draw_x4, draw_y4;
dreschpe 0:4bbc531be6e2 583 int draw_x5, draw_y5;
dreschpe 0:4bbc531be6e2 584 int draw_x6, draw_y6;
dreschpe 0:4bbc531be6e2 585 int draw_x7, draw_y7;
dreschpe 0:4bbc531be6e2 586 int xx, yy;
dreschpe 0:4bbc531be6e2 587 int di;
dreschpe 0:4bbc531be6e2 588 //WindowMax();
dreschpe 0:4bbc531be6e2 589 if (r == 0) { /* no radius */
dreschpe 0:4bbc531be6e2 590 return;
dreschpe 0:4bbc531be6e2 591 }
dreschpe 0:4bbc531be6e2 592
dreschpe 0:4bbc531be6e2 593 draw_x0 = draw_x1 = x0;
dreschpe 0:4bbc531be6e2 594 draw_y0 = draw_y1 = y0 + r;
dreschpe 0:4bbc531be6e2 595 if (draw_y0 < height()) {
dreschpe 0:4bbc531be6e2 596 pixel(draw_x0, draw_y0, color); /* 90 degree */
dreschpe 0:4bbc531be6e2 597 }
dreschpe 0:4bbc531be6e2 598
dreschpe 0:4bbc531be6e2 599 draw_x2 = draw_x3 = x0;
dreschpe 0:4bbc531be6e2 600 draw_y2 = draw_y3 = y0 - r;
dreschpe 0:4bbc531be6e2 601 if (draw_y2 >= 0) {
dreschpe 0:4bbc531be6e2 602 pixel(draw_x2, draw_y2, color); /* 270 degree */
dreschpe 0:4bbc531be6e2 603 }
dreschpe 0:4bbc531be6e2 604
dreschpe 0:4bbc531be6e2 605 draw_x4 = draw_x6 = x0 + r;
dreschpe 0:4bbc531be6e2 606 draw_y4 = draw_y6 = y0;
dreschpe 0:4bbc531be6e2 607 if (draw_x4 < width()) {
dreschpe 0:4bbc531be6e2 608 pixel(draw_x4, draw_y4, color); /* 0 degree */
dreschpe 0:4bbc531be6e2 609 }
dreschpe 0:4bbc531be6e2 610
dreschpe 0:4bbc531be6e2 611 draw_x5 = draw_x7 = x0 - r;
dreschpe 0:4bbc531be6e2 612 draw_y5 = draw_y7 = y0;
dreschpe 0:4bbc531be6e2 613 if (draw_x5>=0) {
dreschpe 0:4bbc531be6e2 614 pixel(draw_x5, draw_y5, color); /* 180 degree */
dreschpe 0:4bbc531be6e2 615 }
dreschpe 0:4bbc531be6e2 616
dreschpe 0:4bbc531be6e2 617 if (r == 1) {
dreschpe 0:4bbc531be6e2 618 return;
dreschpe 0:4bbc531be6e2 619 }
dreschpe 0:4bbc531be6e2 620
dreschpe 0:4bbc531be6e2 621 di = 3 - 2*r;
dreschpe 0:4bbc531be6e2 622 xx = 0;
dreschpe 0:4bbc531be6e2 623 yy = r;
dreschpe 0:4bbc531be6e2 624 while (xx < yy) {
dreschpe 0:4bbc531be6e2 625
dreschpe 0:4bbc531be6e2 626 if (di < 0) {
dreschpe 0:4bbc531be6e2 627 di += 4*xx + 6;
dreschpe 0:4bbc531be6e2 628 } else {
dreschpe 0:4bbc531be6e2 629 di += 4*(xx - yy) + 10;
dreschpe 0:4bbc531be6e2 630 yy--;
dreschpe 0:4bbc531be6e2 631 draw_y0--;
dreschpe 0:4bbc531be6e2 632 draw_y1--;
dreschpe 0:4bbc531be6e2 633 draw_y2++;
dreschpe 0:4bbc531be6e2 634 draw_y3++;
dreschpe 0:4bbc531be6e2 635 draw_x4--;
dreschpe 0:4bbc531be6e2 636 draw_x5++;
dreschpe 0:4bbc531be6e2 637 draw_x6--;
dreschpe 0:4bbc531be6e2 638 draw_x7++;
dreschpe 0:4bbc531be6e2 639 }
dreschpe 0:4bbc531be6e2 640 xx++;
dreschpe 0:4bbc531be6e2 641 draw_x0++;
dreschpe 0:4bbc531be6e2 642 draw_x1--;
dreschpe 0:4bbc531be6e2 643 draw_x2++;
dreschpe 0:4bbc531be6e2 644 draw_x3--;
dreschpe 0:4bbc531be6e2 645 draw_y4++;
dreschpe 0:4bbc531be6e2 646 draw_y5++;
dreschpe 0:4bbc531be6e2 647 draw_y6--;
dreschpe 0:4bbc531be6e2 648 draw_y7--;
dreschpe 0:4bbc531be6e2 649
dreschpe 0:4bbc531be6e2 650 if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
dreschpe 0:4bbc531be6e2 651 pixel(draw_x0, draw_y0, color);
dreschpe 0:4bbc531be6e2 652 }
dreschpe 0:4bbc531be6e2 653
dreschpe 0:4bbc531be6e2 654 if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) {
dreschpe 0:4bbc531be6e2 655 pixel(draw_x1, draw_y1, color);
dreschpe 0:4bbc531be6e2 656 }
dreschpe 0:4bbc531be6e2 657
dreschpe 0:4bbc531be6e2 658 if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) {
dreschpe 0:4bbc531be6e2 659 pixel(draw_x2, draw_y2, color);
dreschpe 0:4bbc531be6e2 660 }
dreschpe 0:4bbc531be6e2 661
dreschpe 0:4bbc531be6e2 662 if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
dreschpe 0:4bbc531be6e2 663 pixel(draw_x3, draw_y3, color);
dreschpe 0:4bbc531be6e2 664 }
dreschpe 0:4bbc531be6e2 665
dreschpe 0:4bbc531be6e2 666 if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) {
dreschpe 0:4bbc531be6e2 667 pixel(draw_x4, draw_y4, color);
dreschpe 0:4bbc531be6e2 668 }
dreschpe 0:4bbc531be6e2 669
dreschpe 0:4bbc531be6e2 670 if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
dreschpe 0:4bbc531be6e2 671 pixel(draw_x5, draw_y5, color);
dreschpe 0:4bbc531be6e2 672 }
dreschpe 0:4bbc531be6e2 673 if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
dreschpe 0:4bbc531be6e2 674 pixel(draw_x6, draw_y6, color);
dreschpe 0:4bbc531be6e2 675 }
dreschpe 0:4bbc531be6e2 676 if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
dreschpe 0:4bbc531be6e2 677 pixel(draw_x7, draw_y7, color);
dreschpe 0:4bbc531be6e2 678 }
dreschpe 0:4bbc531be6e2 679 }
dreschpe 3:468cdccff7af 680 if(auto_up) copy_to_lcd();
dreschpe 0:4bbc531be6e2 681 }
dreschpe 0:4bbc531be6e2 682
tonydbeck 9:4b0d5aee5371 683 void gLCD::fillcircle(int x, int y, int r, int color)
dreschpe 0:4bbc531be6e2 684 {
dreschpe 3:468cdccff7af 685 int i,up;
dreschpe 3:468cdccff7af 686 up = auto_up;
dreschpe 3:468cdccff7af 687 auto_up = 0; // off
dreschpe 0:4bbc531be6e2 688 for (i = 0; i <= r; i++)
dreschpe 0:4bbc531be6e2 689 circle(x,y,i,color);
dreschpe 3:468cdccff7af 690 auto_up = up;
dreschpe 3:468cdccff7af 691 if(auto_up) copy_to_lcd();
dreschpe 0:4bbc531be6e2 692 }
dreschpe 0:4bbc531be6e2 693
tonydbeck 9:4b0d5aee5371 694 void gLCD::setmode(int mode)
dreschpe 0:4bbc531be6e2 695 {
dreschpe 0:4bbc531be6e2 696 draw_mode = mode;
dreschpe 0:4bbc531be6e2 697 }
dreschpe 0:4bbc531be6e2 698
tonydbeck 9:4b0d5aee5371 699 void gLCD::locate(int x, int y)
dreschpe 0:4bbc531be6e2 700 {
dreschpe 0:4bbc531be6e2 701 char_x = x;
dreschpe 0:4bbc531be6e2 702 char_y = y;
tonydbeck 10:269eddb2b7c5 703 oldchar_x = x;
dreschpe 0:4bbc531be6e2 704 }
dreschpe 0:4bbc531be6e2 705
dreschpe 0:4bbc531be6e2 706
dreschpe 0:4bbc531be6e2 707
tonydbeck 9:4b0d5aee5371 708 int gLCD::columns()
dreschpe 0:4bbc531be6e2 709 {
dreschpe 0:4bbc531be6e2 710 return width() / font[1];
dreschpe 0:4bbc531be6e2 711 }
dreschpe 0:4bbc531be6e2 712
dreschpe 0:4bbc531be6e2 713
dreschpe 0:4bbc531be6e2 714
tonydbeck 9:4b0d5aee5371 715 int gLCD::rows()
dreschpe 0:4bbc531be6e2 716 {
dreschpe 0:4bbc531be6e2 717 return height() / font[2];
dreschpe 0:4bbc531be6e2 718 }
dreschpe 0:4bbc531be6e2 719
dreschpe 0:4bbc531be6e2 720
dreschpe 0:4bbc531be6e2 721
tonydbeck 9:4b0d5aee5371 722 int gLCD::_putc(int value)
dreschpe 0:4bbc531be6e2 723 {
dreschpe 0:4bbc531be6e2 724 if (value == '\n') { // new line
tonydbeck 10:269eddb2b7c5 725 char_x = oldchar_x;
dreschpe 0:4bbc531be6e2 726 char_y = char_y + font[2];
dreschpe 0:4bbc531be6e2 727 if (char_y >= height() - font[2]) {
dreschpe 0:4bbc531be6e2 728 char_y = 0;
dreschpe 0:4bbc531be6e2 729 }
dreschpe 0:4bbc531be6e2 730 } else {
dreschpe 0:4bbc531be6e2 731 character(char_x, char_y, value);
dreschpe 3:468cdccff7af 732 if(auto_up) copy_to_lcd();
dreschpe 0:4bbc531be6e2 733 }
dreschpe 0:4bbc531be6e2 734 return value;
dreschpe 0:4bbc531be6e2 735 }
dreschpe 0:4bbc531be6e2 736
tonydbeck 9:4b0d5aee5371 737 void gLCD::character(int x, int y, int c)
dreschpe 0:4bbc531be6e2 738 {
dreschpe 0:4bbc531be6e2 739 unsigned int hor,vert,offset,bpl,j,i,b;
dreschpe 0:4bbc531be6e2 740 unsigned char* zeichen;
dreschpe 0:4bbc531be6e2 741 unsigned char z,w;
dreschpe 0:4bbc531be6e2 742
dreschpe 0:4bbc531be6e2 743 if ((c < 31) || (c > 127)) return; // test char range
dreschpe 0:4bbc531be6e2 744
dreschpe 0:4bbc531be6e2 745 // read font parameter from start of array
dreschpe 0:4bbc531be6e2 746 offset = font[0]; // bytes / char
dreschpe 0:4bbc531be6e2 747 hor = font[1]; // get hor size of font
dreschpe 0:4bbc531be6e2 748 vert = font[2]; // get vert size of font
dreschpe 0:4bbc531be6e2 749 bpl = font[3]; // bytes per line
dreschpe 0:4bbc531be6e2 750
dreschpe 0:4bbc531be6e2 751 if (char_x + hor > width()) {
dreschpe 0:4bbc531be6e2 752 char_x = 0;
dreschpe 0:4bbc531be6e2 753 char_y = char_y + vert;
dreschpe 0:4bbc531be6e2 754 if (char_y >= height() - font[2]) {
dreschpe 0:4bbc531be6e2 755 char_y = 0;
dreschpe 0:4bbc531be6e2 756 }
dreschpe 0:4bbc531be6e2 757 }
dreschpe 0:4bbc531be6e2 758
dreschpe 0:4bbc531be6e2 759 zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
dreschpe 0:4bbc531be6e2 760 w = zeichen[0]; // width of actual char
dreschpe 0:4bbc531be6e2 761 // construct the char into the buffer
dreschpe 0:4bbc531be6e2 762 for (j=0; j<vert; j++) { // vert line
dreschpe 0:4bbc531be6e2 763 for (i=0; i<hor; i++) { // horz line
dreschpe 0:4bbc531be6e2 764 z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
dreschpe 0:4bbc531be6e2 765 b = 1 << (j & 0x07);
dreschpe 0:4bbc531be6e2 766 if (( z & b ) == 0x00) {
dreschpe 0:4bbc531be6e2 767 pixel(x+i,y+j,0);
dreschpe 0:4bbc531be6e2 768 } else {
dreschpe 0:4bbc531be6e2 769 pixel(x+i,y+j,1);
dreschpe 0:4bbc531be6e2 770 }
dreschpe 0:4bbc531be6e2 771
dreschpe 0:4bbc531be6e2 772 }
dreschpe 0:4bbc531be6e2 773 }
dreschpe 0:4bbc531be6e2 774
dreschpe 0:4bbc531be6e2 775 char_x += w;
dreschpe 0:4bbc531be6e2 776 }
dreschpe 0:4bbc531be6e2 777
dreschpe 0:4bbc531be6e2 778
tonydbeck 9:4b0d5aee5371 779 void gLCD::set_font(unsigned char* f)
dreschpe 0:4bbc531be6e2 780 {
dreschpe 0:4bbc531be6e2 781 font = f;
dreschpe 0:4bbc531be6e2 782 }
dreschpe 0:4bbc531be6e2 783
tonydbeck 9:4b0d5aee5371 784 void gLCD::set_auto_up(unsigned int up)
dreschpe 3:468cdccff7af 785 {
tonydbeck 10:269eddb2b7c5 786 if(up )
tonydbeck 10:269eddb2b7c5 787 {
tonydbeck 10:269eddb2b7c5 788 auto_up = 1;
tonydbeck 10:269eddb2b7c5 789 }else
tonydbeck 10:269eddb2b7c5 790 {
tonydbeck 10:269eddb2b7c5 791 auto_up = 0;
tonydbeck 10:269eddb2b7c5 792 }
dreschpe 3:468cdccff7af 793 }
dreschpe 3:468cdccff7af 794
tonydbeck 9:4b0d5aee5371 795 unsigned int gLCD::get_auto_up(void){
dreschpe 3:468cdccff7af 796 return (auto_up);
dreschpe 3:468cdccff7af 797 }
dreschpe 0:4bbc531be6e2 798
dreschpe 0:4bbc531be6e2 799
tonydbeck 9:4b0d5aee5371 800
tonydbeck 10:269eddb2b7c5 801