![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
mbed I2C LCD draw bitmap
ssd1306.cpp@0:5880b78ceccc, 2016-10-21 (annotated)
- Committer:
- rkuo2000
- Date:
- Fri Oct 21 03:34:21 2016 +0000
- Revision:
- 0:5880b78ceccc
mbed I2C LCD draw bitmap
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 0:5880b78ceccc | 1 | // SSD1306Z LCD Driver: 0.96" lcd LY096BG30 |
rkuo2000 | 0:5880b78ceccc | 2 | #include "mbed.h" |
rkuo2000 | 0:5880b78ceccc | 3 | #include "ssd1306.h" |
rkuo2000 | 0:5880b78ceccc | 4 | #include "Font8x16.h" |
rkuo2000 | 0:5880b78ceccc | 5 | #include "Font5x7.h" |
rkuo2000 | 0:5880b78ceccc | 6 | |
rkuo2000 | 0:5880b78ceccc | 7 | I2C ssd1306_i2c(PD_12, PD_10); // I2C1_SDA, I2C1_SCL |
rkuo2000 | 0:5880b78ceccc | 8 | |
rkuo2000 | 0:5880b78ceccc | 9 | char DisplayBuffer[128*8]; |
rkuo2000 | 0:5880b78ceccc | 10 | |
rkuo2000 | 0:5880b78ceccc | 11 | void lcdWriteCommand(uint8_t lcd_Command) |
rkuo2000 | 0:5880b78ceccc | 12 | { |
rkuo2000 | 0:5880b78ceccc | 13 | char data[2]; |
rkuo2000 | 0:5880b78ceccc | 14 | data[0]=0x00; |
rkuo2000 | 0:5880b78ceccc | 15 | data[1]=lcd_Command; |
rkuo2000 | 0:5880b78ceccc | 16 | ssd1306_i2c.write(SSD1306_slave_addr, data, 2, 0); |
rkuo2000 | 0:5880b78ceccc | 17 | } |
rkuo2000 | 0:5880b78ceccc | 18 | |
rkuo2000 | 0:5880b78ceccc | 19 | void lcdWriteData(uint8_t lcd_Data) |
rkuo2000 | 0:5880b78ceccc | 20 | { |
rkuo2000 | 0:5880b78ceccc | 21 | char data[2]; |
rkuo2000 | 0:5880b78ceccc | 22 | data[0]=0x40; |
rkuo2000 | 0:5880b78ceccc | 23 | data[1]=lcd_Data; |
rkuo2000 | 0:5880b78ceccc | 24 | ssd1306_i2c.write(SSD1306_slave_addr, data, 2, 0); |
rkuo2000 | 0:5880b78ceccc | 25 | } |
rkuo2000 | 0:5880b78ceccc | 26 | |
rkuo2000 | 0:5880b78ceccc | 27 | void lcdSetAddr(uint8_t column, uint8_t page) |
rkuo2000 | 0:5880b78ceccc | 28 | { |
rkuo2000 | 0:5880b78ceccc | 29 | lcdWriteCommand(0xb0+page); // set page address |
rkuo2000 | 0:5880b78ceccc | 30 | lcdWriteCommand(0x10 | ((column & 0xf0) >> 4)); // set column address MSB |
rkuo2000 | 0:5880b78ceccc | 31 | lcdWriteCommand(0x00 | (column & 0x0f) ); // set column address LSB |
rkuo2000 | 0:5880b78ceccc | 32 | } |
rkuo2000 | 0:5880b78ceccc | 33 | |
rkuo2000 | 0:5880b78ceccc | 34 | void SSD1306::initialize(void) |
rkuo2000 | 0:5880b78ceccc | 35 | { |
rkuo2000 | 0:5880b78ceccc | 36 | lcdWriteCommand(0xae); //display off |
rkuo2000 | 0:5880b78ceccc | 37 | lcdWriteCommand(0x20); //Set Memory Addressing Mode |
rkuo2000 | 0:5880b78ceccc | 38 | lcdWriteCommand(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid |
rkuo2000 | 0:5880b78ceccc | 39 | lcdWriteCommand(0xb0); //Set Page Start Address for Page Addressing Mode,0-7 |
rkuo2000 | 0:5880b78ceccc | 40 | lcdWriteCommand(0xc8); //Set COM Output Scan Direction |
rkuo2000 | 0:5880b78ceccc | 41 | lcdWriteCommand(0x00);//---set low column address |
rkuo2000 | 0:5880b78ceccc | 42 | lcdWriteCommand(0x10);//---set high column address |
rkuo2000 | 0:5880b78ceccc | 43 | lcdWriteCommand(0x40);//--set start line address |
rkuo2000 | 0:5880b78ceccc | 44 | lcdWriteCommand(0x81);//--set contrast control register |
rkuo2000 | 0:5880b78ceccc | 45 | lcdWriteCommand(0x7f); |
rkuo2000 | 0:5880b78ceccc | 46 | lcdWriteCommand(0xa1);//--set segment re-map 0 to 127 |
rkuo2000 | 0:5880b78ceccc | 47 | lcdWriteCommand(0xa6);//--set normal display |
rkuo2000 | 0:5880b78ceccc | 48 | lcdWriteCommand(0xa8);//--set multiplex ratio(1 to 64) |
rkuo2000 | 0:5880b78ceccc | 49 | lcdWriteCommand(0x3F);// |
rkuo2000 | 0:5880b78ceccc | 50 | lcdWriteCommand(0xa4);//0xa4,Output follows RAM content;0xa5,Output ignores RAM content |
rkuo2000 | 0:5880b78ceccc | 51 | lcdWriteCommand(0xd3);//-set display offset |
rkuo2000 | 0:5880b78ceccc | 52 | lcdWriteCommand(0x00);//-not offset |
rkuo2000 | 0:5880b78ceccc | 53 | lcdWriteCommand(0xd5);//--set display clock divide ratio/oscillator frequency |
rkuo2000 | 0:5880b78ceccc | 54 | lcdWriteCommand(0xf0);//--set divide ratio |
rkuo2000 | 0:5880b78ceccc | 55 | lcdWriteCommand(0xd9);//--set pre-charge period |
rkuo2000 | 0:5880b78ceccc | 56 | lcdWriteCommand(0x22); // |
rkuo2000 | 0:5880b78ceccc | 57 | lcdWriteCommand(0xda);//--set com pins hardware configuration |
rkuo2000 | 0:5880b78ceccc | 58 | lcdWriteCommand(0x12); |
rkuo2000 | 0:5880b78ceccc | 59 | lcdWriteCommand(0xdb);//--set vcomh |
rkuo2000 | 0:5880b78ceccc | 60 | lcdWriteCommand(0x20);//0x20,0.77xVcc |
rkuo2000 | 0:5880b78ceccc | 61 | lcdWriteCommand(0x8d);//--set DC-DC enable |
rkuo2000 | 0:5880b78ceccc | 62 | lcdWriteCommand(0x14);// |
rkuo2000 | 0:5880b78ceccc | 63 | lcdWriteCommand(0xaf);//--turn on lcd panel |
rkuo2000 | 0:5880b78ceccc | 64 | } |
rkuo2000 | 0:5880b78ceccc | 65 | |
rkuo2000 | 0:5880b78ceccc | 66 | void SSD1306::clearscreen(void) |
rkuo2000 | 0:5880b78ceccc | 67 | { |
rkuo2000 | 0:5880b78ceccc | 68 | int16_t x, Y; |
rkuo2000 | 0:5880b78ceccc | 69 | for (Y=0;Y<LCD_Ymax/8;Y++) |
rkuo2000 | 0:5880b78ceccc | 70 | { |
rkuo2000 | 0:5880b78ceccc | 71 | lcdSetAddr(0, Y); |
rkuo2000 | 0:5880b78ceccc | 72 | for (x=0;x<LCD_Xmax;x++) |
rkuo2000 | 0:5880b78ceccc | 73 | lcdWriteData(0x00); |
rkuo2000 | 0:5880b78ceccc | 74 | } |
rkuo2000 | 0:5880b78ceccc | 75 | } |
rkuo2000 | 0:5880b78ceccc | 76 | |
rkuo2000 | 0:5880b78ceccc | 77 | // print char function using Font5x7 |
rkuo2000 | 0:5880b78ceccc | 78 | void SSD1306::printC_5x7 (int x, int y, unsigned char ascii_code) |
rkuo2000 | 0:5880b78ceccc | 79 | { |
rkuo2000 | 0:5880b78ceccc | 80 | int8_t i; |
rkuo2000 | 0:5880b78ceccc | 81 | if (x<(LCD_Xmax-5) && y<(LCD_Ymax-7)) { |
rkuo2000 | 0:5880b78ceccc | 82 | if (ascii_code<0x20) ascii_code=0x20; |
rkuo2000 | 0:5880b78ceccc | 83 | else if (ascii_code>0x7F) ascii_code=0x20; |
rkuo2000 | 0:5880b78ceccc | 84 | for (i=0;i<5;i++) { |
rkuo2000 | 0:5880b78ceccc | 85 | lcdSetAddr((x+i), (y/8)); |
rkuo2000 | 0:5880b78ceccc | 86 | lcdWriteData(Font5x7[(ascii_code-0x20)*5+i]); |
rkuo2000 | 0:5880b78ceccc | 87 | } |
rkuo2000 | 0:5880b78ceccc | 88 | } |
rkuo2000 | 0:5880b78ceccc | 89 | } |
rkuo2000 | 0:5880b78ceccc | 90 | |
rkuo2000 | 0:5880b78ceccc | 91 | void SSD1306::printC(int Line, int Col, unsigned char ascii_code) |
rkuo2000 | 0:5880b78ceccc | 92 | { |
rkuo2000 | 0:5880b78ceccc | 93 | uint8_t j, i, tmp; |
rkuo2000 | 0:5880b78ceccc | 94 | for (j=0;j<2;j++) { |
rkuo2000 | 0:5880b78ceccc | 95 | lcdSetAddr(Col*8, Line*2+j); |
rkuo2000 | 0:5880b78ceccc | 96 | for (i=0;i<8;i++) { |
rkuo2000 | 0:5880b78ceccc | 97 | tmp=Font8x16[(ascii_code-0x20)*16+j*8+i]; |
rkuo2000 | 0:5880b78ceccc | 98 | lcdWriteData(tmp); |
rkuo2000 | 0:5880b78ceccc | 99 | } |
rkuo2000 | 0:5880b78ceccc | 100 | } |
rkuo2000 | 0:5880b78ceccc | 101 | } |
rkuo2000 | 0:5880b78ceccc | 102 | |
rkuo2000 | 0:5880b78ceccc | 103 | void SSD1306::printLine(int line, char text[]) |
rkuo2000 | 0:5880b78ceccc | 104 | { |
rkuo2000 | 0:5880b78ceccc | 105 | uint8_t Col; |
rkuo2000 | 0:5880b78ceccc | 106 | for (Col=0; Col<strlen(text); Col++) |
rkuo2000 | 0:5880b78ceccc | 107 | printC(line, Col, text[Col]); |
rkuo2000 | 0:5880b78ceccc | 108 | } |
rkuo2000 | 0:5880b78ceccc | 109 | |
rkuo2000 | 0:5880b78ceccc | 110 | void SSD1306::printS(int x, int y, char text[]) |
rkuo2000 | 0:5880b78ceccc | 111 | { |
rkuo2000 | 0:5880b78ceccc | 112 | int8_t i; |
rkuo2000 | 0:5880b78ceccc | 113 | for (i=0;i<strlen(text);i++) |
rkuo2000 | 0:5880b78ceccc | 114 | printC(x+i*8, y,text[i]); |
rkuo2000 | 0:5880b78ceccc | 115 | } |
rkuo2000 | 0:5880b78ceccc | 116 | |
rkuo2000 | 0:5880b78ceccc | 117 | void SSD1306::printS_5x7(int x, int y, char text[]) |
rkuo2000 | 0:5880b78ceccc | 118 | { |
rkuo2000 | 0:5880b78ceccc | 119 | int8_t i; |
rkuo2000 | 0:5880b78ceccc | 120 | for (i=0;i<strlen(text);i++) { |
rkuo2000 | 0:5880b78ceccc | 121 | printC_5x7(x,y,text[i]); |
rkuo2000 | 0:5880b78ceccc | 122 | x=x+5; |
rkuo2000 | 0:5880b78ceccc | 123 | } |
rkuo2000 | 0:5880b78ceccc | 124 | } |
rkuo2000 | 0:5880b78ceccc | 125 | |
rkuo2000 | 0:5880b78ceccc | 126 | void SSD1306::drawPixel(int x, int y, int fgColor, int bgColor) |
rkuo2000 | 0:5880b78ceccc | 127 | { |
rkuo2000 | 0:5880b78ceccc | 128 | if (fgColor!=0) |
rkuo2000 | 0:5880b78ceccc | 129 | DisplayBuffer[x+y/8*LCD_Xmax] |= (0x01<<(y%8)); |
rkuo2000 | 0:5880b78ceccc | 130 | else |
rkuo2000 | 0:5880b78ceccc | 131 | DisplayBuffer[x+y/8*LCD_Xmax] &= (0xFE<<(y%8)); |
rkuo2000 | 0:5880b78ceccc | 132 | |
rkuo2000 | 0:5880b78ceccc | 133 | lcdSetAddr(x, y/8); |
rkuo2000 | 0:5880b78ceccc | 134 | lcdWriteData(DisplayBuffer[x+y/8*LCD_Xmax]); |
rkuo2000 | 0:5880b78ceccc | 135 | } |
rkuo2000 | 0:5880b78ceccc | 136 | |
rkuo2000 | 0:5880b78ceccc | 137 | void SSD1306::drawBmp8x8(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 138 | { |
rkuo2000 | 0:5880b78ceccc | 139 | uint8_t t,i,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 140 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 141 | for (i=0;i<8;i++){ |
rkuo2000 | 0:5880b78ceccc | 142 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 143 | t=bitmap[i]; |
rkuo2000 | 0:5880b78ceccc | 144 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 145 | ky=y+k; |
rkuo2000 | 0:5880b78ceccc | 146 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 147 | } |
rkuo2000 | 0:5880b78ceccc | 148 | } |
rkuo2000 | 0:5880b78ceccc | 149 | } |
rkuo2000 | 0:5880b78ceccc | 150 | |
rkuo2000 | 0:5880b78ceccc | 151 | void SSD1306::drawBmp32x8(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 152 | { |
rkuo2000 | 0:5880b78ceccc | 153 | uint8_t t,i,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 154 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 155 | for (i=0;i<32;i++){ |
rkuo2000 | 0:5880b78ceccc | 156 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 157 | t=bitmap[i]; |
rkuo2000 | 0:5880b78ceccc | 158 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 159 | ky=y+k; |
rkuo2000 | 0:5880b78ceccc | 160 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 161 | } |
rkuo2000 | 0:5880b78ceccc | 162 | } |
rkuo2000 | 0:5880b78ceccc | 163 | } |
rkuo2000 | 0:5880b78ceccc | 164 | |
rkuo2000 | 0:5880b78ceccc | 165 | void SSD1306::drawBmp120x8(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 166 | { |
rkuo2000 | 0:5880b78ceccc | 167 | uint8_t t,i,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 168 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 169 | for (i=0;i<120;i++){ |
rkuo2000 | 0:5880b78ceccc | 170 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 171 | t=bitmap[i]; |
rkuo2000 | 0:5880b78ceccc | 172 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 173 | ky=y+k; |
rkuo2000 | 0:5880b78ceccc | 174 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 175 | } |
rkuo2000 | 0:5880b78ceccc | 176 | } |
rkuo2000 | 0:5880b78ceccc | 177 | } |
rkuo2000 | 0:5880b78ceccc | 178 | |
rkuo2000 | 0:5880b78ceccc | 179 | void SSD1306::drawBmp8x16(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 180 | { |
rkuo2000 | 0:5880b78ceccc | 181 | uint8_t t,i,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 182 | if (x<(LCD_Xmax-7) && y<(LCD_Ymax-7)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 183 | for (i=0;i<8;i++){ |
rkuo2000 | 0:5880b78ceccc | 184 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 185 | t=bitmap[i]; |
rkuo2000 | 0:5880b78ceccc | 186 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 187 | ky=y+k; |
rkuo2000 | 0:5880b78ceccc | 188 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 189 | } |
rkuo2000 | 0:5880b78ceccc | 190 | t=bitmap[i+8]; |
rkuo2000 | 0:5880b78ceccc | 191 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 192 | ky=y+k+8; |
rkuo2000 | 0:5880b78ceccc | 193 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 194 | } |
rkuo2000 | 0:5880b78ceccc | 195 | } |
rkuo2000 | 0:5880b78ceccc | 196 | } |
rkuo2000 | 0:5880b78ceccc | 197 | |
rkuo2000 | 0:5880b78ceccc | 198 | void SSD1306::drawBmp16x8(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 199 | { |
rkuo2000 | 0:5880b78ceccc | 200 | uint8_t t,i,k,kx,ky; |
rkuo2000 | 0:5880b78ceccc | 201 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-7)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 202 | for (i=0;i<16;i++) |
rkuo2000 | 0:5880b78ceccc | 203 | { |
rkuo2000 | 0:5880b78ceccc | 204 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 205 | t=bitmap[i]; |
rkuo2000 | 0:5880b78ceccc | 206 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 207 | ky=y+k; |
rkuo2000 | 0:5880b78ceccc | 208 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 209 | } |
rkuo2000 | 0:5880b78ceccc | 210 | } |
rkuo2000 | 0:5880b78ceccc | 211 | } |
rkuo2000 | 0:5880b78ceccc | 212 | |
rkuo2000 | 0:5880b78ceccc | 213 | void SSD1306::drawBmp16x16(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 214 | { |
rkuo2000 | 0:5880b78ceccc | 215 | uint8_t t,i,j,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 216 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-15)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 217 | for (j=0;j<2; j++){ |
rkuo2000 | 0:5880b78ceccc | 218 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 219 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 220 | t=bitmap[i+j*16]; |
rkuo2000 | 0:5880b78ceccc | 221 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 222 | ky=y+j*8+k; |
rkuo2000 | 0:5880b78ceccc | 223 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 224 | } |
rkuo2000 | 0:5880b78ceccc | 225 | } |
rkuo2000 | 0:5880b78ceccc | 226 | } |
rkuo2000 | 0:5880b78ceccc | 227 | } |
rkuo2000 | 0:5880b78ceccc | 228 | |
rkuo2000 | 0:5880b78ceccc | 229 | void SSD1306::drawBmp16x24(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 230 | { |
rkuo2000 | 0:5880b78ceccc | 231 | uint8_t t,i,j,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 232 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-15)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 233 | for (j=0;j<3; j++){ |
rkuo2000 | 0:5880b78ceccc | 234 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 235 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 236 | t=bitmap[i+j*16]; |
rkuo2000 | 0:5880b78ceccc | 237 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 238 | ky=y+j*8+k; |
rkuo2000 | 0:5880b78ceccc | 239 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 240 | } |
rkuo2000 | 0:5880b78ceccc | 241 | } |
rkuo2000 | 0:5880b78ceccc | 242 | } |
rkuo2000 | 0:5880b78ceccc | 243 | } |
rkuo2000 | 0:5880b78ceccc | 244 | |
rkuo2000 | 0:5880b78ceccc | 245 | void SSD1306::drawBmp16x32(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 246 | { |
rkuo2000 | 0:5880b78ceccc | 247 | uint8_t t, i,j,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 248 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-31)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 249 | for (j=0;j<4; j++) { |
rkuo2000 | 0:5880b78ceccc | 250 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 251 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 252 | t=bitmap[i+j*16]; |
rkuo2000 | 0:5880b78ceccc | 253 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 254 | ky=y+j*8+k; |
rkuo2000 | 0:5880b78ceccc | 255 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 256 | } |
rkuo2000 | 0:5880b78ceccc | 257 | } |
rkuo2000 | 0:5880b78ceccc | 258 | } |
rkuo2000 | 0:5880b78ceccc | 259 | } |
rkuo2000 | 0:5880b78ceccc | 260 | |
rkuo2000 | 0:5880b78ceccc | 261 | void SSD1306::drawBmp16x40(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 262 | { |
rkuo2000 | 0:5880b78ceccc | 263 | uint8_t t, i,j,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 264 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-31)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 265 | for (j=0;j<5; j++) { |
rkuo2000 | 0:5880b78ceccc | 266 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 267 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 268 | t=bitmap[i+j*16]; |
rkuo2000 | 0:5880b78ceccc | 269 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 270 | ky=y+j*8+k; |
rkuo2000 | 0:5880b78ceccc | 271 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 272 | } |
rkuo2000 | 0:5880b78ceccc | 273 | } |
rkuo2000 | 0:5880b78ceccc | 274 | } |
rkuo2000 | 0:5880b78ceccc | 275 | } |
rkuo2000 | 0:5880b78ceccc | 276 | |
rkuo2000 | 0:5880b78ceccc | 277 | void SSD1306::drawBmp16x48(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 278 | { |
rkuo2000 | 0:5880b78ceccc | 279 | uint8_t t,i,j,k,kx,ky; |
rkuo2000 | 0:5880b78ceccc | 280 | if (x<(LCD_Xmax-15) && y<(LCD_Ymax-47)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 281 | for (j=0;j<6; j++) { |
rkuo2000 | 0:5880b78ceccc | 282 | k=x; |
rkuo2000 | 0:5880b78ceccc | 283 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 284 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 285 | t=bitmap[i+j*16]; |
rkuo2000 | 0:5880b78ceccc | 286 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 287 | ky=y+j*8+k; |
rkuo2000 | 0:5880b78ceccc | 288 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 289 | } |
rkuo2000 | 0:5880b78ceccc | 290 | } |
rkuo2000 | 0:5880b78ceccc | 291 | } |
rkuo2000 | 0:5880b78ceccc | 292 | } |
rkuo2000 | 0:5880b78ceccc | 293 | |
rkuo2000 | 0:5880b78ceccc | 294 | void SSD1306::drawBmp16x64(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 295 | { |
rkuo2000 | 0:5880b78ceccc | 296 | uint8_t t,i,j,k,kx,ky; |
rkuo2000 | 0:5880b78ceccc | 297 | if (x<(LCD_Xmax-15) && y==0) // boundary check |
rkuo2000 | 0:5880b78ceccc | 298 | for (j=0;j<8; j++) { |
rkuo2000 | 0:5880b78ceccc | 299 | k=x; |
rkuo2000 | 0:5880b78ceccc | 300 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 301 | kx=x+i; |
rkuo2000 | 0:5880b78ceccc | 302 | t=bitmap[i+j*16]; |
rkuo2000 | 0:5880b78ceccc | 303 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 304 | ky=y+j*8+k; |
rkuo2000 | 0:5880b78ceccc | 305 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 306 | } |
rkuo2000 | 0:5880b78ceccc | 307 | } |
rkuo2000 | 0:5880b78ceccc | 308 | } |
rkuo2000 | 0:5880b78ceccc | 309 | } |
rkuo2000 | 0:5880b78ceccc | 310 | |
rkuo2000 | 0:5880b78ceccc | 311 | void SSD1306::drawBmp32x16(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 312 | { |
rkuo2000 | 0:5880b78ceccc | 313 | uint8_t t,i,jx,jy,k,kx,ky; |
rkuo2000 | 0:5880b78ceccc | 314 | if (x<(LCD_Xmax-31) && y<(LCD_Ymax-15)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 315 | for (jy=0;jy<2;jy++) |
rkuo2000 | 0:5880b78ceccc | 316 | for (jx=0;jx<2;jx++) { |
rkuo2000 | 0:5880b78ceccc | 317 | k=x; |
rkuo2000 | 0:5880b78ceccc | 318 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 319 | kx=x+jx*16+i; |
rkuo2000 | 0:5880b78ceccc | 320 | t=bitmap[i+jx*16+jy*32]; |
rkuo2000 | 0:5880b78ceccc | 321 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 322 | ky=y+jy*8+k; |
rkuo2000 | 0:5880b78ceccc | 323 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 324 | } |
rkuo2000 | 0:5880b78ceccc | 325 | } |
rkuo2000 | 0:5880b78ceccc | 326 | } |
rkuo2000 | 0:5880b78ceccc | 327 | } |
rkuo2000 | 0:5880b78ceccc | 328 | |
rkuo2000 | 0:5880b78ceccc | 329 | void SSD1306::drawBmp32x32(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 330 | { |
rkuo2000 | 0:5880b78ceccc | 331 | uint8_t t,i,jx,jy,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 332 | if (x<(LCD_Xmax-31) && y<(LCD_Ymax-31)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 333 | for (jy=0;jy<4;jy++) |
rkuo2000 | 0:5880b78ceccc | 334 | for (jx=0;jx<2;jx++) { |
rkuo2000 | 0:5880b78ceccc | 335 | k=x; |
rkuo2000 | 0:5880b78ceccc | 336 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 337 | kx=x+jx*16+i; |
rkuo2000 | 0:5880b78ceccc | 338 | t=bitmap[i+jx*16+jy*32]; |
rkuo2000 | 0:5880b78ceccc | 339 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 340 | ky=y+jy*8+k; |
rkuo2000 | 0:5880b78ceccc | 341 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 342 | } |
rkuo2000 | 0:5880b78ceccc | 343 | } |
rkuo2000 | 0:5880b78ceccc | 344 | } |
rkuo2000 | 0:5880b78ceccc | 345 | } |
rkuo2000 | 0:5880b78ceccc | 346 | |
rkuo2000 | 0:5880b78ceccc | 347 | void SSD1306::drawBmp32x48(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 348 | { |
rkuo2000 | 0:5880b78ceccc | 349 | uint8_t t,i,jx,jy,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 350 | if (x<(LCD_Xmax-31) && y<(LCD_Ymax-47)) // boundary check |
rkuo2000 | 0:5880b78ceccc | 351 | for (jy=0;jy<6;jy++) |
rkuo2000 | 0:5880b78ceccc | 352 | for (jx=0;jx<2;jx++) { |
rkuo2000 | 0:5880b78ceccc | 353 | k=x; |
rkuo2000 | 0:5880b78ceccc | 354 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 355 | kx=x+jx*16+i; |
rkuo2000 | 0:5880b78ceccc | 356 | t=bitmap[i+jx*16+jy*32]; |
rkuo2000 | 0:5880b78ceccc | 357 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 358 | ky=y+jy*8+k; |
rkuo2000 | 0:5880b78ceccc | 359 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 360 | } |
rkuo2000 | 0:5880b78ceccc | 361 | } |
rkuo2000 | 0:5880b78ceccc | 362 | } |
rkuo2000 | 0:5880b78ceccc | 363 | } |
rkuo2000 | 0:5880b78ceccc | 364 | |
rkuo2000 | 0:5880b78ceccc | 365 | void SSD1306::drawBmp32x64(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 366 | { |
rkuo2000 | 0:5880b78ceccc | 367 | uint8_t t,i,jx,jy,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 368 | if (x<(LCD_Xmax-31) && y==0) // boundary check |
rkuo2000 | 0:5880b78ceccc | 369 | for (jy=0;jy<8;jy++) |
rkuo2000 | 0:5880b78ceccc | 370 | for (jx=0;jx<2;jx++) { |
rkuo2000 | 0:5880b78ceccc | 371 | k=x; |
rkuo2000 | 0:5880b78ceccc | 372 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 373 | kx=x+jx*16+i; |
rkuo2000 | 0:5880b78ceccc | 374 | t=bitmap[i+jx*16+jy*32]; |
rkuo2000 | 0:5880b78ceccc | 375 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 376 | ky=y+jy*8+k; |
rkuo2000 | 0:5880b78ceccc | 377 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 378 | } |
rkuo2000 | 0:5880b78ceccc | 379 | } |
rkuo2000 | 0:5880b78ceccc | 380 | } |
rkuo2000 | 0:5880b78ceccc | 381 | } |
rkuo2000 | 0:5880b78ceccc | 382 | |
rkuo2000 | 0:5880b78ceccc | 383 | void SSD1306::drawBmp64x64(int x, int y, int fgColor, int bgColor, unsigned char bitmap[]) |
rkuo2000 | 0:5880b78ceccc | 384 | { |
rkuo2000 | 0:5880b78ceccc | 385 | uint8_t t, i,jx,jy,k, kx,ky; |
rkuo2000 | 0:5880b78ceccc | 386 | if (x<(LCD_Xmax-63) && y==0) // boundary check |
rkuo2000 | 0:5880b78ceccc | 387 | for (jy=0;jy<8;jy++) |
rkuo2000 | 0:5880b78ceccc | 388 | for (jx=0;jx<4;jx++) { |
rkuo2000 | 0:5880b78ceccc | 389 | k=x; |
rkuo2000 | 0:5880b78ceccc | 390 | for (i=0;i<16;i++) { |
rkuo2000 | 0:5880b78ceccc | 391 | kx=x+jx*16+i; |
rkuo2000 | 0:5880b78ceccc | 392 | t=bitmap[i+jx*16+jy*64]; |
rkuo2000 | 0:5880b78ceccc | 393 | for (k=0;k<8;k++) { |
rkuo2000 | 0:5880b78ceccc | 394 | ky=y+jy*8+k; |
rkuo2000 | 0:5880b78ceccc | 395 | if (t&(0x01<<k)) drawPixel(kx,ky,fgColor,bgColor); |
rkuo2000 | 0:5880b78ceccc | 396 | } |
rkuo2000 | 0:5880b78ceccc | 397 | } |
rkuo2000 | 0:5880b78ceccc | 398 | } |
rkuo2000 | 0:5880b78ceccc | 399 | } |
rkuo2000 | 0:5880b78ceccc | 400 | |
rkuo2000 | 0:5880b78ceccc | 401 | void SSD1306::drawBMP(unsigned char *buffer) |
rkuo2000 | 0:5880b78ceccc | 402 | { |
rkuo2000 | 0:5880b78ceccc | 403 | uint8_t x,y; |
rkuo2000 | 0:5880b78ceccc | 404 | for (x=0; x<LCD_Xmax; x++) { |
rkuo2000 | 0:5880b78ceccc | 405 | for (y=0; y<(LCD_Ymax/8); y++) { |
rkuo2000 | 0:5880b78ceccc | 406 | lcdSetAddr(x ,y); |
rkuo2000 | 0:5880b78ceccc | 407 | lcdWriteData(buffer[x+y*LCD_Xmax]); |
rkuo2000 | 0:5880b78ceccc | 408 | } |
rkuo2000 | 0:5880b78ceccc | 409 | } |
rkuo2000 | 0:5880b78ceccc | 410 | } |
rkuo2000 | 0:5880b78ceccc | 411 |