My Version
C12832_lcd.cpp@8:c9afe58d786a, 2012-12-21 (annotated)
- Committer:
- dreschpe
- Date:
- Fri Dec 21 21:58:19 2012 +0000
- Revision:
- 8:c9afe58d786a
- Parent:
- 7:0f5a3b0f3cab
- Child:
- 10:8f86576007d6
BUGFIX IN AUTOUPDATE
Who changed what in which revision?
User | Revision | Line number | New 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 | 7:0f5a3b0f3cab | 17 | // 25.10.12 add standart font |
dreschpe | 7:0f5a3b0f3cab | 18 | // 20.12.12 add bitmap graphics |
dreschpe | 3:468cdccff7af | 19 | |
dreschpe | 0:4bbc531be6e2 | 20 | // optional defines : |
dreschpe | 3:468cdccff7af | 21 | // #define debug_lcd 1 |
dreschpe | 0:4bbc531be6e2 | 22 | |
dreschpe | 0:4bbc531be6e2 | 23 | #include "C12832_lcd.h" |
dreschpe | 0:4bbc531be6e2 | 24 | #include "mbed.h" |
dreschpe | 0:4bbc531be6e2 | 25 | #include "stdio.h" |
dreschpe | 3:468cdccff7af | 26 | #include "Small_7.h" |
dreschpe | 0:4bbc531be6e2 | 27 | |
dreschpe | 0:4bbc531be6e2 | 28 | #define BPP 1 // Bits per pixel |
dreschpe | 0:4bbc531be6e2 | 29 | |
dreschpe | 0:4bbc531be6e2 | 30 | C12832_LCD::C12832_LCD(const char* name) |
dreschpe | 0:4bbc531be6e2 | 31 | : _spi(p5,NC,p7),_reset(p6),_A0(p8),_CS(p11),GraphicsDisplay(name) |
dreschpe | 0:4bbc531be6e2 | 32 | { |
dreschpe | 0:4bbc531be6e2 | 33 | orientation = 1; |
dreschpe | 0:4bbc531be6e2 | 34 | draw_mode = NORMAL; |
dreschpe | 0:4bbc531be6e2 | 35 | char_x = 0; |
dreschpe | 0:4bbc531be6e2 | 36 | lcd_reset(); |
dreschpe | 0:4bbc531be6e2 | 37 | } |
dreschpe | 0:4bbc531be6e2 | 38 | |
dreschpe | 0:4bbc531be6e2 | 39 | int C12832_LCD::width() |
dreschpe | 0:4bbc531be6e2 | 40 | { |
dreschpe | 0:4bbc531be6e2 | 41 | if (orientation == 0 || orientation == 2) return 32; |
dreschpe | 0:4bbc531be6e2 | 42 | else return 128; |
dreschpe | 0:4bbc531be6e2 | 43 | } |
dreschpe | 0:4bbc531be6e2 | 44 | |
dreschpe | 0:4bbc531be6e2 | 45 | int C12832_LCD::height() |
dreschpe | 0:4bbc531be6e2 | 46 | { |
dreschpe | 0:4bbc531be6e2 | 47 | if (orientation == 0 || orientation == 2) return 128; |
dreschpe | 0:4bbc531be6e2 | 48 | else return 32; |
dreschpe | 0:4bbc531be6e2 | 49 | } |
dreschpe | 0:4bbc531be6e2 | 50 | |
dreschpe | 0:4bbc531be6e2 | 51 | |
dreschpe | 1:66dd8afbfd06 | 52 | /*void C12832_LCD::set_orientation(unsigned int o) |
dreschpe | 0:4bbc531be6e2 | 53 | { |
dreschpe | 0:4bbc531be6e2 | 54 | orientation = o; |
dreschpe | 0:4bbc531be6e2 | 55 | switch (o) { |
dreschpe | 0:4bbc531be6e2 | 56 | case (0): |
dreschpe | 0:4bbc531be6e2 | 57 | wr_cmd(0xA0); |
dreschpe | 0:4bbc531be6e2 | 58 | wr_cmd(0xC0); |
dreschpe | 0:4bbc531be6e2 | 59 | break; |
dreschpe | 0:4bbc531be6e2 | 60 | case (1): |
dreschpe | 0:4bbc531be6e2 | 61 | wr_cmd(0xA0); |
dreschpe | 0:4bbc531be6e2 | 62 | wr_cmd(0xC8); |
dreschpe | 0:4bbc531be6e2 | 63 | break; |
dreschpe | 0:4bbc531be6e2 | 64 | case (2): |
dreschpe | 0:4bbc531be6e2 | 65 | wr_cmd(0xA1); |
dreschpe | 0:4bbc531be6e2 | 66 | wr_cmd(0xC8); |
dreschpe | 0:4bbc531be6e2 | 67 | break; |
dreschpe | 0:4bbc531be6e2 | 68 | case (3): |
dreschpe | 0:4bbc531be6e2 | 69 | wr_cmd(0xA1); |
dreschpe | 0:4bbc531be6e2 | 70 | wr_cmd(0xC0); |
dreschpe | 0:4bbc531be6e2 | 71 | break; |
dreschpe | 0:4bbc531be6e2 | 72 | } |
dreschpe | 0:4bbc531be6e2 | 73 | } |
dreschpe | 0:4bbc531be6e2 | 74 | |
dreschpe | 1:66dd8afbfd06 | 75 | */ |
dreschpe | 1:66dd8afbfd06 | 76 | |
dreschpe | 0:4bbc531be6e2 | 77 | void C12832_LCD::invert(unsigned int o) |
dreschpe | 0:4bbc531be6e2 | 78 | { |
dreschpe | 0:4bbc531be6e2 | 79 | if(o == 0) wr_cmd(0xA6); |
dreschpe | 0:4bbc531be6e2 | 80 | else wr_cmd(0xA7); |
dreschpe | 0:4bbc531be6e2 | 81 | } |
dreschpe | 0:4bbc531be6e2 | 82 | |
dreschpe | 0:4bbc531be6e2 | 83 | |
dreschpe | 0:4bbc531be6e2 | 84 | void C12832_LCD::set_contrast(unsigned int o) |
dreschpe | 0:4bbc531be6e2 | 85 | { |
dreschpe | 1:66dd8afbfd06 | 86 | contrast = o; |
dreschpe | 0:4bbc531be6e2 | 87 | wr_cmd(0x81); // set volume |
dreschpe | 2:bdc53502af17 | 88 | wr_cmd(o & 0x3F); |
dreschpe | 0:4bbc531be6e2 | 89 | } |
dreschpe | 0:4bbc531be6e2 | 90 | |
dreschpe | 1:66dd8afbfd06 | 91 | unsigned int C12832_LCD::get_contrast(void) |
dreschpe | 1:66dd8afbfd06 | 92 | { |
dreschpe | 1:66dd8afbfd06 | 93 | return(contrast); |
dreschpe | 1:66dd8afbfd06 | 94 | } |
dreschpe | 1:66dd8afbfd06 | 95 | |
dreschpe | 0:4bbc531be6e2 | 96 | |
dreschpe | 0:4bbc531be6e2 | 97 | // write command to lcd controller |
dreschpe | 0:4bbc531be6e2 | 98 | |
dreschpe | 0:4bbc531be6e2 | 99 | void C12832_LCD::wr_cmd(unsigned char cmd) |
dreschpe | 0:4bbc531be6e2 | 100 | { |
dreschpe | 0:4bbc531be6e2 | 101 | _A0 = 0; |
dreschpe | 0:4bbc531be6e2 | 102 | _CS = 0; |
dreschpe | 2:bdc53502af17 | 103 | #if defined TARGET_LPC1768 // fast without mbed lib |
dreschpe | 0:4bbc531be6e2 | 104 | LPC_SSP1->DR = cmd; |
dreschpe | 0:4bbc531be6e2 | 105 | do { |
dreschpe | 0:4bbc531be6e2 | 106 | } while ((LPC_SSP1->SR & 0x10) == 0x10); // wait for SPI1 idle |
dreschpe | 2:bdc53502af17 | 107 | #else |
dreschpe | 2:bdc53502af17 | 108 | _spi.write(cmd); |
dreschpe | 2:bdc53502af17 | 109 | #endif |
dreschpe | 7:0f5a3b0f3cab | 110 | _CS = 1; |
dreschpe | 0:4bbc531be6e2 | 111 | } |
dreschpe | 0:4bbc531be6e2 | 112 | |
dreschpe | 0:4bbc531be6e2 | 113 | // write data to lcd controller |
dreschpe | 0:4bbc531be6e2 | 114 | |
dreschpe | 0:4bbc531be6e2 | 115 | void C12832_LCD::wr_dat(unsigned char dat) |
dreschpe | 0:4bbc531be6e2 | 116 | { |
dreschpe | 0:4bbc531be6e2 | 117 | _A0 = 1; |
dreschpe | 0:4bbc531be6e2 | 118 | _CS = 0; |
dreschpe | 2:bdc53502af17 | 119 | #if defined TARGET_LPC1768 // fast without mbed lib |
dreschpe | 0:4bbc531be6e2 | 120 | LPC_SSP1->DR = dat; |
dreschpe | 0:4bbc531be6e2 | 121 | do { |
dreschpe | 0:4bbc531be6e2 | 122 | } while ((LPC_SSP1->SR & 0x10) == 0x10); // wait for SPI1 idle |
dreschpe | 2:bdc53502af17 | 123 | #else |
dreschpe | 2:bdc53502af17 | 124 | _spi.write(dat); |
dreschpe | 2:bdc53502af17 | 125 | #endif |
dreschpe | 0:4bbc531be6e2 | 126 | _CS = 1; |
dreschpe | 0:4bbc531be6e2 | 127 | } |
dreschpe | 0:4bbc531be6e2 | 128 | |
dreschpe | 0:4bbc531be6e2 | 129 | // reset and init the lcd controller |
dreschpe | 0:4bbc531be6e2 | 130 | |
dreschpe | 0:4bbc531be6e2 | 131 | void C12832_LCD::lcd_reset() |
dreschpe | 0:4bbc531be6e2 | 132 | { |
dreschpe | 0:4bbc531be6e2 | 133 | |
dreschpe | 0:4bbc531be6e2 | 134 | _spi.format(8,3); // 8 bit spi mode 3 |
dreschpe | 0:4bbc531be6e2 | 135 | _spi.frequency(20000000); // 19,2 Mhz SPI clock |
dreschpe | 0:4bbc531be6e2 | 136 | DigitalOut _reset(p6); |
dreschpe | 0:4bbc531be6e2 | 137 | _A0 = 0; |
dreschpe | 0:4bbc531be6e2 | 138 | _CS = 1; |
dreschpe | 0:4bbc531be6e2 | 139 | _reset = 0; // display reset |
dreschpe | 0:4bbc531be6e2 | 140 | wait_us(50); |
dreschpe | 0:4bbc531be6e2 | 141 | _reset = 1; // end reset |
dreschpe | 0:4bbc531be6e2 | 142 | wait_ms(5); |
dreschpe | 0:4bbc531be6e2 | 143 | |
dreschpe | 0:4bbc531be6e2 | 144 | /* Start Initial Sequence ----------------------------------------------------*/ |
dreschpe | 0:4bbc531be6e2 | 145 | |
dreschpe | 0:4bbc531be6e2 | 146 | wr_cmd(0xAE); // display off |
dreschpe | 0:4bbc531be6e2 | 147 | wr_cmd(0xA2); // bias voltage |
dreschpe | 0:4bbc531be6e2 | 148 | |
dreschpe | 0:4bbc531be6e2 | 149 | wr_cmd(0xA0); |
dreschpe | 0:4bbc531be6e2 | 150 | wr_cmd(0xC8); // colum normal |
dreschpe | 0:4bbc531be6e2 | 151 | |
dreschpe | 0:4bbc531be6e2 | 152 | wr_cmd(0x22); // voltage resistor ratio |
dreschpe | 0:4bbc531be6e2 | 153 | wr_cmd(0x2F); // power on |
dreschpe | 1:66dd8afbfd06 | 154 | //wr_cmd(0xA4); // LCD display ram |
dreschpe | 0:4bbc531be6e2 | 155 | wr_cmd(0x40); // start line = 0 |
dreschpe | 0:4bbc531be6e2 | 156 | wr_cmd(0xAF); // display ON |
dreschpe | 0:4bbc531be6e2 | 157 | |
dreschpe | 0:4bbc531be6e2 | 158 | wr_cmd(0x81); // set contrast |
dreschpe | 0:4bbc531be6e2 | 159 | wr_cmd(0x17); // set contrast |
dreschpe | 0:4bbc531be6e2 | 160 | |
dreschpe | 0:4bbc531be6e2 | 161 | wr_cmd(0xA6); // display normal |
dreschpe | 0:4bbc531be6e2 | 162 | |
dreschpe | 7:0f5a3b0f3cab | 163 | |
dreschpe | 2:bdc53502af17 | 164 | #if defined TARGET_LPC1768 //setup DMA channel 0 |
dreschpe | 0:4bbc531be6e2 | 165 | LPC_SC->PCONP |= (1UL << 29); // Power up the GPDMA |
dreschpe | 2:bdc53502af17 | 166 | LPC_GPDMA->DMACConfig = 1; // enable DMA controller |
dreschpe | 0:4bbc531be6e2 | 167 | LPC_GPDMA->DMACIntTCClear = 0x1; |
dreschpe | 0:4bbc531be6e2 | 168 | LPC_GPDMA->DMACIntErrClr = 0x1; |
dreschpe | 0:4bbc531be6e2 | 169 | LPC_GPDMACH0->DMACCLLI = 0; |
dreschpe | 2:bdc53502af17 | 170 | #endif |
dreschpe | 0:4bbc531be6e2 | 171 | // clear and update LCD |
dreschpe | 0:4bbc531be6e2 | 172 | memset(buffer,0x00,512); // clear display buffer |
dreschpe | 0:4bbc531be6e2 | 173 | copy_to_lcd(); |
dreschpe | 3:468cdccff7af | 174 | auto_up = 1; // switch on auto update |
dreschpe | 3:468cdccff7af | 175 | claim(stdout); // redirekt printf to lcd |
dreschpe | 3:468cdccff7af | 176 | locate(0,0); |
dreschpe | 7:0f5a3b0f3cab | 177 | set_font((unsigned char*)Small_7); // standart font |
dreschpe | 0:4bbc531be6e2 | 178 | } |
dreschpe | 0:4bbc531be6e2 | 179 | |
dreschpe | 0:4bbc531be6e2 | 180 | // set one pixel in buffer |
dreschpe | 0:4bbc531be6e2 | 181 | |
dreschpe | 0:4bbc531be6e2 | 182 | void C12832_LCD::pixel(int x, int y, int color) |
dreschpe | 0:4bbc531be6e2 | 183 | { |
dreschpe | 0:4bbc531be6e2 | 184 | // first check parameter |
dreschpe | 0:4bbc531be6e2 | 185 | if(x > 128 || y > 32 || x < 0 || y < 0) return; |
dreschpe | 0:4bbc531be6e2 | 186 | |
dreschpe | 0:4bbc531be6e2 | 187 | if(draw_mode == NORMAL) { |
dreschpe | 0:4bbc531be6e2 | 188 | if(color == 0) |
dreschpe | 0:4bbc531be6e2 | 189 | buffer[x + ((y/8) * 128)] &= ~(1 << (y%8)); // erase pixel |
dreschpe | 0:4bbc531be6e2 | 190 | else |
dreschpe | 0:4bbc531be6e2 | 191 | buffer[x + ((y/8) * 128)] |= (1 << (y%8)); // set pixel |
dreschpe | 0:4bbc531be6e2 | 192 | } else { // XOR mode |
dreschpe | 0:4bbc531be6e2 | 193 | if(color == 1) |
dreschpe | 0:4bbc531be6e2 | 194 | buffer[x + ((y/8) * 128)] ^= (1 << (y%8)); // xor pixel |
dreschpe | 0:4bbc531be6e2 | 195 | } |
dreschpe | 0:4bbc531be6e2 | 196 | } |
dreschpe | 0:4bbc531be6e2 | 197 | |
dreschpe | 0:4bbc531be6e2 | 198 | // update lcd |
dreschpe | 0:4bbc531be6e2 | 199 | |
dreschpe | 0:4bbc531be6e2 | 200 | void C12832_LCD::copy_to_lcd(void) |
dreschpe | 0:4bbc531be6e2 | 201 | { |
dreschpe | 7:0f5a3b0f3cab | 202 | #ifndef TARGET_LPC1768 |
dreschpe | 2:bdc53502af17 | 203 | int i; |
dreschpe | 2:bdc53502af17 | 204 | #endif |
dreschpe | 0:4bbc531be6e2 | 205 | //page 0 |
dreschpe | 0:4bbc531be6e2 | 206 | wr_cmd(0x00); // set column low nibble 0 |
dreschpe | 0:4bbc531be6e2 | 207 | wr_cmd(0x10); // set column hi nibble 0 |
dreschpe | 0:4bbc531be6e2 | 208 | wr_cmd(0xB0); // set page address 0 |
dreschpe | 2:bdc53502af17 | 209 | _A0 = 1; |
dreschpe | 7:0f5a3b0f3cab | 210 | #if defined TARGET_LPC1768 |
dreschpe | 0:4bbc531be6e2 | 211 | _CS = 0; |
dreschpe | 0:4bbc531be6e2 | 212 | // start 128 byte DMA transfer to SPI1 |
dreschpe | 0:4bbc531be6e2 | 213 | LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 |
dreschpe | 0:4bbc531be6e2 | 214 | LPC_SSP1->DMACR = 0x2; // Enable SSP1 for DMA. |
dreschpe | 0:4bbc531be6e2 | 215 | LPC_GPDMA->DMACIntTCClear = 0x1; |
dreschpe | 0:4bbc531be6e2 | 216 | LPC_GPDMA->DMACIntErrClr = 0x1; |
dreschpe | 0:4bbc531be6e2 | 217 | LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer); |
dreschpe | 0:4bbc531be6e2 | 218 | LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt |
dreschpe | 0:4bbc531be6e2 | 219 | LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX; |
dreschpe | 0:4bbc531be6e2 | 220 | LPC_GPDMA->DMACSoftSReq = 0x1; |
dreschpe | 0:4bbc531be6e2 | 221 | do { |
dreschpe | 0:4bbc531be6e2 | 222 | } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running |
dreschpe | 0:4bbc531be6e2 | 223 | do { |
dreschpe | 0:4bbc531be6e2 | 224 | } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle |
dreschpe | 0:4bbc531be6e2 | 225 | _CS = 1; |
dreschpe | 2:bdc53502af17 | 226 | #else // no DMA |
dreschpe | 7:0f5a3b0f3cab | 227 | for(i=0; i<128; i++) { |
dreschpe | 2:bdc53502af17 | 228 | wr_dat(buffer[i]); |
dreschpe | 7:0f5a3b0f3cab | 229 | } |
dreschpe | 7:0f5a3b0f3cab | 230 | #endif |
dreschpe | 0:4bbc531be6e2 | 231 | |
dreschpe | 0:4bbc531be6e2 | 232 | // page 1 |
dreschpe | 0:4bbc531be6e2 | 233 | wr_cmd(0x00); // set column low nibble 0 |
dreschpe | 0:4bbc531be6e2 | 234 | wr_cmd(0x10); // set column hi nibble 0 |
dreschpe | 0:4bbc531be6e2 | 235 | wr_cmd(0xB1); // set page address 1 |
dreschpe | 2:bdc53502af17 | 236 | _A0 = 1; |
dreschpe | 7:0f5a3b0f3cab | 237 | #if defined TARGET_LPC1768 |
dreschpe | 0:4bbc531be6e2 | 238 | _CS = 0; |
dreschpe | 0:4bbc531be6e2 | 239 | // start 128 byte DMA transfer to SPI1 |
dreschpe | 0:4bbc531be6e2 | 240 | LPC_GPDMA->DMACIntTCClear = 0x1; |
dreschpe | 0:4bbc531be6e2 | 241 | LPC_GPDMA->DMACIntErrClr = 0x1; |
dreschpe | 0:4bbc531be6e2 | 242 | LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 128); |
dreschpe | 0:4bbc531be6e2 | 243 | LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt |
dreschpe | 0:4bbc531be6e2 | 244 | LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX; |
dreschpe | 0:4bbc531be6e2 | 245 | LPC_GPDMA->DMACSoftSReq = 0x1; |
dreschpe | 0:4bbc531be6e2 | 246 | do { |
dreschpe | 0:4bbc531be6e2 | 247 | } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running |
dreschpe | 0:4bbc531be6e2 | 248 | do { |
dreschpe | 0:4bbc531be6e2 | 249 | } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle |
dreschpe | 0:4bbc531be6e2 | 250 | _CS = 1; |
dreschpe | 2:bdc53502af17 | 251 | #else // no DMA |
dreschpe | 7:0f5a3b0f3cab | 252 | for(i=128; i<256; i++) { |
dreschpe | 2:bdc53502af17 | 253 | wr_dat(buffer[i]); |
dreschpe | 7:0f5a3b0f3cab | 254 | } |
dreschpe | 7:0f5a3b0f3cab | 255 | #endif |
dreschpe | 0:4bbc531be6e2 | 256 | |
dreschpe | 0:4bbc531be6e2 | 257 | //page 2 |
dreschpe | 0:4bbc531be6e2 | 258 | wr_cmd(0x00); // set column low nibble 0 |
dreschpe | 0:4bbc531be6e2 | 259 | wr_cmd(0x10); // set column hi nibble 0 |
dreschpe | 0:4bbc531be6e2 | 260 | wr_cmd(0xB2); // set page address 2 |
dreschpe | 2:bdc53502af17 | 261 | _A0 = 1; |
dreschpe | 7:0f5a3b0f3cab | 262 | #if defined TARGET_LPC1768 |
dreschpe | 0:4bbc531be6e2 | 263 | _CS = 0; |
dreschpe | 0:4bbc531be6e2 | 264 | // start 128 byte DMA transfer to SPI1 |
dreschpe | 0:4bbc531be6e2 | 265 | LPC_GPDMA->DMACIntTCClear = 0x1; |
dreschpe | 0:4bbc531be6e2 | 266 | LPC_GPDMA->DMACIntErrClr = 0x1; |
dreschpe | 0:4bbc531be6e2 | 267 | LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 256); |
dreschpe | 0:4bbc531be6e2 | 268 | LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt |
dreschpe | 0:4bbc531be6e2 | 269 | LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX ; |
dreschpe | 0:4bbc531be6e2 | 270 | LPC_GPDMA->DMACSoftSReq = 0x1; |
dreschpe | 0:4bbc531be6e2 | 271 | do { |
dreschpe | 0:4bbc531be6e2 | 272 | } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running |
dreschpe | 0:4bbc531be6e2 | 273 | do { |
dreschpe | 0:4bbc531be6e2 | 274 | } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle |
dreschpe | 0:4bbc531be6e2 | 275 | _CS = 1; |
dreschpe | 2:bdc53502af17 | 276 | #else // no DMA |
dreschpe | 7:0f5a3b0f3cab | 277 | for(i=256; i<384; i++) { |
dreschpe | 2:bdc53502af17 | 278 | wr_dat(buffer[i]); |
dreschpe | 7:0f5a3b0f3cab | 279 | } |
dreschpe | 7:0f5a3b0f3cab | 280 | #endif |
dreschpe | 2:bdc53502af17 | 281 | |
dreschpe | 0:4bbc531be6e2 | 282 | //page 3 |
dreschpe | 0:4bbc531be6e2 | 283 | wr_cmd(0x00); // set column low nibble 0 |
dreschpe | 0:4bbc531be6e2 | 284 | wr_cmd(0x10); // set column hi nibble 0 |
dreschpe | 0:4bbc531be6e2 | 285 | wr_cmd(0xB3); // set page address 3 |
dreschpe | 0:4bbc531be6e2 | 286 | _A0 = 1; |
dreschpe | 7:0f5a3b0f3cab | 287 | |
dreschpe | 7:0f5a3b0f3cab | 288 | _CS = 0; |
dreschpe | 7:0f5a3b0f3cab | 289 | #if defined TARGET_LPC1768 |
dreschpe | 0:4bbc531be6e2 | 290 | // start 128 byte DMA transfer to SPI1 |
dreschpe | 0:4bbc531be6e2 | 291 | LPC_GPDMA->DMACIntTCClear = 0x1; |
dreschpe | 0:4bbc531be6e2 | 292 | LPC_GPDMA->DMACIntErrClr = 0x1; |
dreschpe | 0:4bbc531be6e2 | 293 | LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + 384); |
dreschpe | 0:4bbc531be6e2 | 294 | LPC_GPDMACH0->DMACCControl = 128 | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 8 bit transfer , address increment, interrupt |
dreschpe | 0:4bbc531be6e2 | 295 | LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | DMA_DEST_SSP1_TX; |
dreschpe | 0:4bbc531be6e2 | 296 | LPC_GPDMA->DMACSoftSReq = 0x1; |
dreschpe | 0:4bbc531be6e2 | 297 | do { |
dreschpe | 0:4bbc531be6e2 | 298 | } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running |
dreschpe | 0:4bbc531be6e2 | 299 | do { |
dreschpe | 0:4bbc531be6e2 | 300 | } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle |
dreschpe | 0:4bbc531be6e2 | 301 | _CS = 1; |
dreschpe | 2:bdc53502af17 | 302 | #else // no DMA |
dreschpe | 7:0f5a3b0f3cab | 303 | for(i=384; i<512; i++) { |
dreschpe | 2:bdc53502af17 | 304 | wr_dat(buffer[i]); |
dreschpe | 7:0f5a3b0f3cab | 305 | } |
dreschpe | 7:0f5a3b0f3cab | 306 | #endif |
dreschpe | 0:4bbc531be6e2 | 307 | } |
dreschpe | 0:4bbc531be6e2 | 308 | |
dreschpe | 0:4bbc531be6e2 | 309 | void C12832_LCD::cls(void) |
dreschpe | 0:4bbc531be6e2 | 310 | { |
dreschpe | 0:4bbc531be6e2 | 311 | memset(buffer,0x00,512); // clear display buffer |
dreschpe | 0:4bbc531be6e2 | 312 | copy_to_lcd(); |
dreschpe | 0:4bbc531be6e2 | 313 | } |
dreschpe | 0:4bbc531be6e2 | 314 | |
dreschpe | 0:4bbc531be6e2 | 315 | |
dreschpe | 0:4bbc531be6e2 | 316 | void C12832_LCD::line(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:4bbc531be6e2 | 317 | { |
dreschpe | 0:4bbc531be6e2 | 318 | int dx = 0, dy = 0; |
dreschpe | 0:4bbc531be6e2 | 319 | int dx_sym = 0, dy_sym = 0; |
dreschpe | 0:4bbc531be6e2 | 320 | int dx_x2 = 0, dy_x2 = 0; |
dreschpe | 0:4bbc531be6e2 | 321 | int di = 0; |
dreschpe | 0:4bbc531be6e2 | 322 | |
dreschpe | 0:4bbc531be6e2 | 323 | dx = x1-x0; |
dreschpe | 0:4bbc531be6e2 | 324 | dy = y1-y0; |
dreschpe | 0:4bbc531be6e2 | 325 | |
dreschpe | 0:4bbc531be6e2 | 326 | // if (dx == 0) { /* vertical line */ |
dreschpe | 0:4bbc531be6e2 | 327 | // if (y1 > y0) vline(x0,y0,y1,color); |
dreschpe | 0:4bbc531be6e2 | 328 | // else vline(x0,y1,y0,color); |
dreschpe | 0:4bbc531be6e2 | 329 | // return; |
dreschpe | 0:4bbc531be6e2 | 330 | // } |
dreschpe | 0:4bbc531be6e2 | 331 | |
dreschpe | 0:4bbc531be6e2 | 332 | if (dx > 0) { |
dreschpe | 0:4bbc531be6e2 | 333 | dx_sym = 1; |
dreschpe | 0:4bbc531be6e2 | 334 | } else { |
dreschpe | 0:4bbc531be6e2 | 335 | dx_sym = -1; |
dreschpe | 0:4bbc531be6e2 | 336 | } |
dreschpe | 0:4bbc531be6e2 | 337 | // if (dy == 0) { /* horizontal line */ |
dreschpe | 0:4bbc531be6e2 | 338 | // if (x1 > x0) hline(x0,x1,y0,color); |
dreschpe | 0:4bbc531be6e2 | 339 | // else hline(x1,x0,y0,color); |
dreschpe | 0:4bbc531be6e2 | 340 | // return; |
dreschpe | 0:4bbc531be6e2 | 341 | // } |
dreschpe | 0:4bbc531be6e2 | 342 | |
dreschpe | 0:4bbc531be6e2 | 343 | if (dy > 0) { |
dreschpe | 0:4bbc531be6e2 | 344 | dy_sym = 1; |
dreschpe | 0:4bbc531be6e2 | 345 | } else { |
dreschpe | 0:4bbc531be6e2 | 346 | dy_sym = -1; |
dreschpe | 0:4bbc531be6e2 | 347 | } |
dreschpe | 0:4bbc531be6e2 | 348 | |
dreschpe | 0:4bbc531be6e2 | 349 | dx = dx_sym*dx; |
dreschpe | 0:4bbc531be6e2 | 350 | dy = dy_sym*dy; |
dreschpe | 0:4bbc531be6e2 | 351 | |
dreschpe | 0:4bbc531be6e2 | 352 | dx_x2 = dx*2; |
dreschpe | 0:4bbc531be6e2 | 353 | dy_x2 = dy*2; |
dreschpe | 0:4bbc531be6e2 | 354 | |
dreschpe | 0:4bbc531be6e2 | 355 | if (dx >= dy) { |
dreschpe | 0:4bbc531be6e2 | 356 | di = dy_x2 - dx; |
dreschpe | 0:4bbc531be6e2 | 357 | while (x0 != x1) { |
dreschpe | 0:4bbc531be6e2 | 358 | |
dreschpe | 0:4bbc531be6e2 | 359 | pixel(x0, y0, color); |
dreschpe | 0:4bbc531be6e2 | 360 | x0 += dx_sym; |
dreschpe | 0:4bbc531be6e2 | 361 | if (di<0) { |
dreschpe | 0:4bbc531be6e2 | 362 | di += dy_x2; |
dreschpe | 0:4bbc531be6e2 | 363 | } else { |
dreschpe | 0:4bbc531be6e2 | 364 | di += dy_x2 - dx_x2; |
dreschpe | 0:4bbc531be6e2 | 365 | y0 += dy_sym; |
dreschpe | 0:4bbc531be6e2 | 366 | } |
dreschpe | 0:4bbc531be6e2 | 367 | } |
dreschpe | 0:4bbc531be6e2 | 368 | pixel(x0, y0, color); |
dreschpe | 0:4bbc531be6e2 | 369 | } else { |
dreschpe | 0:4bbc531be6e2 | 370 | di = dx_x2 - dy; |
dreschpe | 0:4bbc531be6e2 | 371 | while (y0 != y1) { |
dreschpe | 0:4bbc531be6e2 | 372 | pixel(x0, y0, color); |
dreschpe | 0:4bbc531be6e2 | 373 | y0 += dy_sym; |
dreschpe | 0:4bbc531be6e2 | 374 | if (di < 0) { |
dreschpe | 0:4bbc531be6e2 | 375 | di += dx_x2; |
dreschpe | 0:4bbc531be6e2 | 376 | } else { |
dreschpe | 0:4bbc531be6e2 | 377 | di += dx_x2 - dy_x2; |
dreschpe | 0:4bbc531be6e2 | 378 | x0 += dx_sym; |
dreschpe | 0:4bbc531be6e2 | 379 | } |
dreschpe | 0:4bbc531be6e2 | 380 | } |
dreschpe | 0:4bbc531be6e2 | 381 | pixel(x0, y0, color); |
dreschpe | 0:4bbc531be6e2 | 382 | } |
dreschpe | 3:468cdccff7af | 383 | if(auto_up) copy_to_lcd(); |
dreschpe | 0:4bbc531be6e2 | 384 | } |
dreschpe | 0:4bbc531be6e2 | 385 | |
dreschpe | 0:4bbc531be6e2 | 386 | void C12832_LCD::rect(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:4bbc531be6e2 | 387 | { |
dreschpe | 0:4bbc531be6e2 | 388 | |
dreschpe | 0:4bbc531be6e2 | 389 | if (x1 > x0) line(x0,y0,x1,y0,color); |
dreschpe | 0:4bbc531be6e2 | 390 | else line(x1,y0,x0,y0,color); |
dreschpe | 0:4bbc531be6e2 | 391 | |
dreschpe | 0:4bbc531be6e2 | 392 | if (y1 > y0) line(x0,y0,x0,y1,color); |
dreschpe | 0:4bbc531be6e2 | 393 | else line(x0,y1,x0,y0,color); |
dreschpe | 0:4bbc531be6e2 | 394 | |
dreschpe | 0:4bbc531be6e2 | 395 | if (x1 > x0) line(x0,y1,x1,y1,color); |
dreschpe | 0:4bbc531be6e2 | 396 | else line(x1,y1,x0,y1,color); |
dreschpe | 0:4bbc531be6e2 | 397 | |
dreschpe | 0:4bbc531be6e2 | 398 | if (y1 > y0) line(x1,y0,x1,y1,color); |
dreschpe | 0:4bbc531be6e2 | 399 | else line(x1,y1,x1,y0,color); |
dreschpe | 0:4bbc531be6e2 | 400 | |
dreschpe | 3:468cdccff7af | 401 | if(auto_up) copy_to_lcd(); |
dreschpe | 0:4bbc531be6e2 | 402 | } |
dreschpe | 0:4bbc531be6e2 | 403 | |
dreschpe | 0:4bbc531be6e2 | 404 | void C12832_LCD::fillrect(int x0, int y0, int x1, int y1, int color) |
dreschpe | 0:4bbc531be6e2 | 405 | { |
dreschpe | 0:4bbc531be6e2 | 406 | int l,c,i; |
dreschpe | 0:4bbc531be6e2 | 407 | if(x0 > x1) { |
dreschpe | 0:4bbc531be6e2 | 408 | i = x0; |
dreschpe | 0:4bbc531be6e2 | 409 | x0 = x1; |
dreschpe | 0:4bbc531be6e2 | 410 | x1 = i; |
dreschpe | 0:4bbc531be6e2 | 411 | } |
dreschpe | 0:4bbc531be6e2 | 412 | |
dreschpe | 0:4bbc531be6e2 | 413 | if(y0 > y1) { |
dreschpe | 0:4bbc531be6e2 | 414 | i = y0; |
dreschpe | 0:4bbc531be6e2 | 415 | y0 = y1; |
dreschpe | 0:4bbc531be6e2 | 416 | y1 = i; |
dreschpe | 0:4bbc531be6e2 | 417 | } |
dreschpe | 0:4bbc531be6e2 | 418 | |
dreschpe | 0:4bbc531be6e2 | 419 | for(l = x0; l<= x1; l ++) { |
dreschpe | 0:4bbc531be6e2 | 420 | for(c = y0; c<= y1; c++) { |
dreschpe | 0:4bbc531be6e2 | 421 | pixel(l,c,color); |
dreschpe | 0:4bbc531be6e2 | 422 | } |
dreschpe | 0:4bbc531be6e2 | 423 | } |
dreschpe | 3:468cdccff7af | 424 | if(auto_up) copy_to_lcd(); |
dreschpe | 0:4bbc531be6e2 | 425 | } |
dreschpe | 0:4bbc531be6e2 | 426 | |
dreschpe | 0:4bbc531be6e2 | 427 | |
dreschpe | 0:4bbc531be6e2 | 428 | |
dreschpe | 0:4bbc531be6e2 | 429 | void C12832_LCD::circle(int x0, int y0, int r, int color) |
dreschpe | 0:4bbc531be6e2 | 430 | { |
dreschpe | 0:4bbc531be6e2 | 431 | |
dreschpe | 0:4bbc531be6e2 | 432 | int draw_x0, draw_y0; |
dreschpe | 0:4bbc531be6e2 | 433 | int draw_x1, draw_y1; |
dreschpe | 0:4bbc531be6e2 | 434 | int draw_x2, draw_y2; |
dreschpe | 0:4bbc531be6e2 | 435 | int draw_x3, draw_y3; |
dreschpe | 0:4bbc531be6e2 | 436 | int draw_x4, draw_y4; |
dreschpe | 0:4bbc531be6e2 | 437 | int draw_x5, draw_y5; |
dreschpe | 0:4bbc531be6e2 | 438 | int draw_x6, draw_y6; |
dreschpe | 0:4bbc531be6e2 | 439 | int draw_x7, draw_y7; |
dreschpe | 0:4bbc531be6e2 | 440 | int xx, yy; |
dreschpe | 0:4bbc531be6e2 | 441 | int di; |
dreschpe | 0:4bbc531be6e2 | 442 | //WindowMax(); |
dreschpe | 0:4bbc531be6e2 | 443 | if (r == 0) { /* no radius */ |
dreschpe | 0:4bbc531be6e2 | 444 | return; |
dreschpe | 0:4bbc531be6e2 | 445 | } |
dreschpe | 0:4bbc531be6e2 | 446 | |
dreschpe | 0:4bbc531be6e2 | 447 | draw_x0 = draw_x1 = x0; |
dreschpe | 0:4bbc531be6e2 | 448 | draw_y0 = draw_y1 = y0 + r; |
dreschpe | 0:4bbc531be6e2 | 449 | if (draw_y0 < height()) { |
dreschpe | 0:4bbc531be6e2 | 450 | pixel(draw_x0, draw_y0, color); /* 90 degree */ |
dreschpe | 0:4bbc531be6e2 | 451 | } |
dreschpe | 0:4bbc531be6e2 | 452 | |
dreschpe | 0:4bbc531be6e2 | 453 | draw_x2 = draw_x3 = x0; |
dreschpe | 0:4bbc531be6e2 | 454 | draw_y2 = draw_y3 = y0 - r; |
dreschpe | 0:4bbc531be6e2 | 455 | if (draw_y2 >= 0) { |
dreschpe | 0:4bbc531be6e2 | 456 | pixel(draw_x2, draw_y2, color); /* 270 degree */ |
dreschpe | 0:4bbc531be6e2 | 457 | } |
dreschpe | 0:4bbc531be6e2 | 458 | |
dreschpe | 0:4bbc531be6e2 | 459 | draw_x4 = draw_x6 = x0 + r; |
dreschpe | 0:4bbc531be6e2 | 460 | draw_y4 = draw_y6 = y0; |
dreschpe | 0:4bbc531be6e2 | 461 | if (draw_x4 < width()) { |
dreschpe | 0:4bbc531be6e2 | 462 | pixel(draw_x4, draw_y4, color); /* 0 degree */ |
dreschpe | 0:4bbc531be6e2 | 463 | } |
dreschpe | 0:4bbc531be6e2 | 464 | |
dreschpe | 0:4bbc531be6e2 | 465 | draw_x5 = draw_x7 = x0 - r; |
dreschpe | 0:4bbc531be6e2 | 466 | draw_y5 = draw_y7 = y0; |
dreschpe | 0:4bbc531be6e2 | 467 | if (draw_x5>=0) { |
dreschpe | 0:4bbc531be6e2 | 468 | pixel(draw_x5, draw_y5, color); /* 180 degree */ |
dreschpe | 0:4bbc531be6e2 | 469 | } |
dreschpe | 0:4bbc531be6e2 | 470 | |
dreschpe | 0:4bbc531be6e2 | 471 | if (r == 1) { |
dreschpe | 0:4bbc531be6e2 | 472 | return; |
dreschpe | 0:4bbc531be6e2 | 473 | } |
dreschpe | 0:4bbc531be6e2 | 474 | |
dreschpe | 0:4bbc531be6e2 | 475 | di = 3 - 2*r; |
dreschpe | 0:4bbc531be6e2 | 476 | xx = 0; |
dreschpe | 0:4bbc531be6e2 | 477 | yy = r; |
dreschpe | 0:4bbc531be6e2 | 478 | while (xx < yy) { |
dreschpe | 0:4bbc531be6e2 | 479 | |
dreschpe | 0:4bbc531be6e2 | 480 | if (di < 0) { |
dreschpe | 0:4bbc531be6e2 | 481 | di += 4*xx + 6; |
dreschpe | 0:4bbc531be6e2 | 482 | } else { |
dreschpe | 0:4bbc531be6e2 | 483 | di += 4*(xx - yy) + 10; |
dreschpe | 0:4bbc531be6e2 | 484 | yy--; |
dreschpe | 0:4bbc531be6e2 | 485 | draw_y0--; |
dreschpe | 0:4bbc531be6e2 | 486 | draw_y1--; |
dreschpe | 0:4bbc531be6e2 | 487 | draw_y2++; |
dreschpe | 0:4bbc531be6e2 | 488 | draw_y3++; |
dreschpe | 0:4bbc531be6e2 | 489 | draw_x4--; |
dreschpe | 0:4bbc531be6e2 | 490 | draw_x5++; |
dreschpe | 0:4bbc531be6e2 | 491 | draw_x6--; |
dreschpe | 0:4bbc531be6e2 | 492 | draw_x7++; |
dreschpe | 0:4bbc531be6e2 | 493 | } |
dreschpe | 0:4bbc531be6e2 | 494 | xx++; |
dreschpe | 0:4bbc531be6e2 | 495 | draw_x0++; |
dreschpe | 0:4bbc531be6e2 | 496 | draw_x1--; |
dreschpe | 0:4bbc531be6e2 | 497 | draw_x2++; |
dreschpe | 0:4bbc531be6e2 | 498 | draw_x3--; |
dreschpe | 0:4bbc531be6e2 | 499 | draw_y4++; |
dreschpe | 0:4bbc531be6e2 | 500 | draw_y5++; |
dreschpe | 0:4bbc531be6e2 | 501 | draw_y6--; |
dreschpe | 0:4bbc531be6e2 | 502 | draw_y7--; |
dreschpe | 0:4bbc531be6e2 | 503 | |
dreschpe | 0:4bbc531be6e2 | 504 | if ( (draw_x0 <= width()) && (draw_y0>=0) ) { |
dreschpe | 0:4bbc531be6e2 | 505 | pixel(draw_x0, draw_y0, color); |
dreschpe | 0:4bbc531be6e2 | 506 | } |
dreschpe | 0:4bbc531be6e2 | 507 | |
dreschpe | 0:4bbc531be6e2 | 508 | if ( (draw_x1 >= 0) && (draw_y1 >= 0) ) { |
dreschpe | 0:4bbc531be6e2 | 509 | pixel(draw_x1, draw_y1, color); |
dreschpe | 0:4bbc531be6e2 | 510 | } |
dreschpe | 0:4bbc531be6e2 | 511 | |
dreschpe | 0:4bbc531be6e2 | 512 | if ( (draw_x2 <= width()) && (draw_y2 <= height()) ) { |
dreschpe | 0:4bbc531be6e2 | 513 | pixel(draw_x2, draw_y2, color); |
dreschpe | 0:4bbc531be6e2 | 514 | } |
dreschpe | 0:4bbc531be6e2 | 515 | |
dreschpe | 0:4bbc531be6e2 | 516 | if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) { |
dreschpe | 0:4bbc531be6e2 | 517 | pixel(draw_x3, draw_y3, color); |
dreschpe | 0:4bbc531be6e2 | 518 | } |
dreschpe | 0:4bbc531be6e2 | 519 | |
dreschpe | 0:4bbc531be6e2 | 520 | if ( (draw_x4 <= width()) && (draw_y4 >= 0) ) { |
dreschpe | 0:4bbc531be6e2 | 521 | pixel(draw_x4, draw_y4, color); |
dreschpe | 0:4bbc531be6e2 | 522 | } |
dreschpe | 0:4bbc531be6e2 | 523 | |
dreschpe | 0:4bbc531be6e2 | 524 | if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) { |
dreschpe | 0:4bbc531be6e2 | 525 | pixel(draw_x5, draw_y5, color); |
dreschpe | 0:4bbc531be6e2 | 526 | } |
dreschpe | 0:4bbc531be6e2 | 527 | if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) { |
dreschpe | 0:4bbc531be6e2 | 528 | pixel(draw_x6, draw_y6, color); |
dreschpe | 0:4bbc531be6e2 | 529 | } |
dreschpe | 0:4bbc531be6e2 | 530 | if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) { |
dreschpe | 0:4bbc531be6e2 | 531 | pixel(draw_x7, draw_y7, color); |
dreschpe | 0:4bbc531be6e2 | 532 | } |
dreschpe | 0:4bbc531be6e2 | 533 | } |
dreschpe | 3:468cdccff7af | 534 | if(auto_up) copy_to_lcd(); |
dreschpe | 0:4bbc531be6e2 | 535 | } |
dreschpe | 0:4bbc531be6e2 | 536 | |
dreschpe | 0:4bbc531be6e2 | 537 | void C12832_LCD::fillcircle(int x, int y, int r, int color) |
dreschpe | 0:4bbc531be6e2 | 538 | { |
dreschpe | 3:468cdccff7af | 539 | int i,up; |
dreschpe | 3:468cdccff7af | 540 | up = auto_up; |
dreschpe | 3:468cdccff7af | 541 | auto_up = 0; // off |
dreschpe | 0:4bbc531be6e2 | 542 | for (i = 0; i <= r; i++) |
dreschpe | 0:4bbc531be6e2 | 543 | circle(x,y,i,color); |
dreschpe | 3:468cdccff7af | 544 | auto_up = up; |
dreschpe | 7:0f5a3b0f3cab | 545 | if(auto_up) copy_to_lcd(); |
dreschpe | 0:4bbc531be6e2 | 546 | } |
dreschpe | 0:4bbc531be6e2 | 547 | |
dreschpe | 0:4bbc531be6e2 | 548 | void C12832_LCD::setmode(int mode) |
dreschpe | 0:4bbc531be6e2 | 549 | { |
dreschpe | 0:4bbc531be6e2 | 550 | draw_mode = mode; |
dreschpe | 0:4bbc531be6e2 | 551 | } |
dreschpe | 0:4bbc531be6e2 | 552 | |
dreschpe | 0:4bbc531be6e2 | 553 | void C12832_LCD::locate(int x, int y) |
dreschpe | 0:4bbc531be6e2 | 554 | { |
dreschpe | 0:4bbc531be6e2 | 555 | char_x = x; |
dreschpe | 0:4bbc531be6e2 | 556 | char_y = y; |
dreschpe | 0:4bbc531be6e2 | 557 | } |
dreschpe | 0:4bbc531be6e2 | 558 | |
dreschpe | 0:4bbc531be6e2 | 559 | |
dreschpe | 0:4bbc531be6e2 | 560 | |
dreschpe | 0:4bbc531be6e2 | 561 | int C12832_LCD::columns() |
dreschpe | 0:4bbc531be6e2 | 562 | { |
dreschpe | 0:4bbc531be6e2 | 563 | return width() / font[1]; |
dreschpe | 0:4bbc531be6e2 | 564 | } |
dreschpe | 0:4bbc531be6e2 | 565 | |
dreschpe | 0:4bbc531be6e2 | 566 | |
dreschpe | 0:4bbc531be6e2 | 567 | |
dreschpe | 0:4bbc531be6e2 | 568 | int C12832_LCD::rows() |
dreschpe | 0:4bbc531be6e2 | 569 | { |
dreschpe | 0:4bbc531be6e2 | 570 | return height() / font[2]; |
dreschpe | 0:4bbc531be6e2 | 571 | } |
dreschpe | 0:4bbc531be6e2 | 572 | |
dreschpe | 0:4bbc531be6e2 | 573 | |
dreschpe | 0:4bbc531be6e2 | 574 | |
dreschpe | 0:4bbc531be6e2 | 575 | int C12832_LCD::_putc(int value) |
dreschpe | 0:4bbc531be6e2 | 576 | { |
dreschpe | 0:4bbc531be6e2 | 577 | if (value == '\n') { // new line |
dreschpe | 0:4bbc531be6e2 | 578 | char_x = 0; |
dreschpe | 0:4bbc531be6e2 | 579 | char_y = char_y + font[2]; |
dreschpe | 0:4bbc531be6e2 | 580 | if (char_y >= height() - font[2]) { |
dreschpe | 0:4bbc531be6e2 | 581 | char_y = 0; |
dreschpe | 0:4bbc531be6e2 | 582 | } |
dreschpe | 0:4bbc531be6e2 | 583 | } else { |
dreschpe | 0:4bbc531be6e2 | 584 | character(char_x, char_y, value); |
dreschpe | 3:468cdccff7af | 585 | if(auto_up) copy_to_lcd(); |
dreschpe | 0:4bbc531be6e2 | 586 | } |
dreschpe | 0:4bbc531be6e2 | 587 | return value; |
dreschpe | 0:4bbc531be6e2 | 588 | } |
dreschpe | 0:4bbc531be6e2 | 589 | |
dreschpe | 0:4bbc531be6e2 | 590 | void C12832_LCD::character(int x, int y, int c) |
dreschpe | 0:4bbc531be6e2 | 591 | { |
dreschpe | 0:4bbc531be6e2 | 592 | unsigned int hor,vert,offset,bpl,j,i,b; |
dreschpe | 0:4bbc531be6e2 | 593 | unsigned char* zeichen; |
dreschpe | 0:4bbc531be6e2 | 594 | unsigned char z,w; |
dreschpe | 0:4bbc531be6e2 | 595 | |
dreschpe | 0:4bbc531be6e2 | 596 | if ((c < 31) || (c > 127)) return; // test char range |
dreschpe | 0:4bbc531be6e2 | 597 | |
dreschpe | 0:4bbc531be6e2 | 598 | // read font parameter from start of array |
dreschpe | 0:4bbc531be6e2 | 599 | offset = font[0]; // bytes / char |
dreschpe | 0:4bbc531be6e2 | 600 | hor = font[1]; // get hor size of font |
dreschpe | 0:4bbc531be6e2 | 601 | vert = font[2]; // get vert size of font |
dreschpe | 0:4bbc531be6e2 | 602 | bpl = font[3]; // bytes per line |
dreschpe | 0:4bbc531be6e2 | 603 | |
dreschpe | 0:4bbc531be6e2 | 604 | if (char_x + hor > width()) { |
dreschpe | 0:4bbc531be6e2 | 605 | char_x = 0; |
dreschpe | 0:4bbc531be6e2 | 606 | char_y = char_y + vert; |
dreschpe | 0:4bbc531be6e2 | 607 | if (char_y >= height() - font[2]) { |
dreschpe | 0:4bbc531be6e2 | 608 | char_y = 0; |
dreschpe | 0:4bbc531be6e2 | 609 | } |
dreschpe | 0:4bbc531be6e2 | 610 | } |
dreschpe | 0:4bbc531be6e2 | 611 | |
dreschpe | 0:4bbc531be6e2 | 612 | zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap |
dreschpe | 0:4bbc531be6e2 | 613 | w = zeichen[0]; // width of actual char |
dreschpe | 0:4bbc531be6e2 | 614 | // construct the char into the buffer |
dreschpe | 0:4bbc531be6e2 | 615 | for (j=0; j<vert; j++) { // vert line |
dreschpe | 0:4bbc531be6e2 | 616 | for (i=0; i<hor; i++) { // horz line |
dreschpe | 0:4bbc531be6e2 | 617 | z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; |
dreschpe | 0:4bbc531be6e2 | 618 | b = 1 << (j & 0x07); |
dreschpe | 0:4bbc531be6e2 | 619 | if (( z & b ) == 0x00) { |
dreschpe | 0:4bbc531be6e2 | 620 | pixel(x+i,y+j,0); |
dreschpe | 0:4bbc531be6e2 | 621 | } else { |
dreschpe | 0:4bbc531be6e2 | 622 | pixel(x+i,y+j,1); |
dreschpe | 0:4bbc531be6e2 | 623 | } |
dreschpe | 0:4bbc531be6e2 | 624 | |
dreschpe | 0:4bbc531be6e2 | 625 | } |
dreschpe | 0:4bbc531be6e2 | 626 | } |
dreschpe | 0:4bbc531be6e2 | 627 | |
dreschpe | 0:4bbc531be6e2 | 628 | char_x += w; |
dreschpe | 0:4bbc531be6e2 | 629 | } |
dreschpe | 0:4bbc531be6e2 | 630 | |
dreschpe | 0:4bbc531be6e2 | 631 | |
dreschpe | 0:4bbc531be6e2 | 632 | void C12832_LCD::set_font(unsigned char* f) |
dreschpe | 0:4bbc531be6e2 | 633 | { |
dreschpe | 0:4bbc531be6e2 | 634 | font = f; |
dreschpe | 0:4bbc531be6e2 | 635 | } |
dreschpe | 0:4bbc531be6e2 | 636 | |
dreschpe | 3:468cdccff7af | 637 | void C12832_LCD::set_auto_up(unsigned int up) |
dreschpe | 3:468cdccff7af | 638 | { |
dreschpe | 3:468cdccff7af | 639 | if(up ) auto_up = 1; |
dreschpe | 8:c9afe58d786a | 640 | else auto_up = 0; |
dreschpe | 3:468cdccff7af | 641 | } |
dreschpe | 3:468cdccff7af | 642 | |
dreschpe | 7:0f5a3b0f3cab | 643 | unsigned int C12832_LCD::get_auto_up(void) |
dreschpe | 7:0f5a3b0f3cab | 644 | { |
dreschpe | 3:468cdccff7af | 645 | return (auto_up); |
dreschpe | 3:468cdccff7af | 646 | } |
dreschpe | 0:4bbc531be6e2 | 647 | |
dreschpe | 7:0f5a3b0f3cab | 648 | void C12832_LCD::print_bm(Bitmap bm, int x, int y) |
dreschpe | 7:0f5a3b0f3cab | 649 | { |
dreschpe | 7:0f5a3b0f3cab | 650 | int h,v,b; |
dreschpe | 7:0f5a3b0f3cab | 651 | char d; |
dreschpe | 0:4bbc531be6e2 | 652 | |
dreschpe | 7:0f5a3b0f3cab | 653 | for(v=0; v < bm.ySize; v++) { // lines |
dreschpe | 7:0f5a3b0f3cab | 654 | for(h=0; h < bm.xSize; h++) { // pixel |
dreschpe | 7:0f5a3b0f3cab | 655 | if(h + x > 127) break; |
dreschpe | 7:0f5a3b0f3cab | 656 | if(v + y > 31) break; |
dreschpe | 7:0f5a3b0f3cab | 657 | d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)]; |
dreschpe | 7:0f5a3b0f3cab | 658 | b = 0x80 >> (h & 0x07); |
dreschpe | 7:0f5a3b0f3cab | 659 | if((d & b) == 0) { |
dreschpe | 7:0f5a3b0f3cab | 660 | pixel(x+h,y+v,0); |
dreschpe | 7:0f5a3b0f3cab | 661 | } else { |
dreschpe | 7:0f5a3b0f3cab | 662 | pixel(x+h,y+v,1); |
dreschpe | 7:0f5a3b0f3cab | 663 | } |
dreschpe | 7:0f5a3b0f3cab | 664 | } |
dreschpe | 7:0f5a3b0f3cab | 665 | } |
dreschpe | 7:0f5a3b0f3cab | 666 | |
dreschpe | 7:0f5a3b0f3cab | 667 | } |
dreschpe | 7:0f5a3b0f3cab | 668 | |
dreschpe | 7:0f5a3b0f3cab | 669 |