NuMaker-PFM-NUC472: I2C1 LCD draw a moving circle

Committer:
ccli8
Date:
Tue Jul 11 13:41:06 2017 +0800
Revision:
1:219b99b987f0
Parent:
0:72afeb131817
Update mbed-os to mbed-os-5.5.2

Who changed what in which revision?

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