void gameSetMetaPixel(uint8_t x, uint8_t y, uint8_t status) { //status is ON (non-zero) or OFF (zero) //oled is 128x64, our meta board will be 0-64 (x) and 0-32 (y) //oled is written in 'pages' of 8-bits. This particular screen //cannot be read so the game buffer must be used to ensure writing //a new game pixel doesn't overwrite existing pixels. //make our changes to the buffer uint8_t metaPage = y/8; uint8_t metaPageY = 1<<(y%8); if (status) { buffer[metaPage][x] |= metaPageY; } else { buffer[metaPage][x] &= ~metaPageY; } //write to the screen accounting for 2x pixel sizes meta-v-actual uint8_t subMetaPage = (y%8)/4; uint8_t actualPage = (metaPage*2) + subMetaPage; uint8_t actualX = x*2; uint8_t metaData = buffer[metaPage][x]; if (subMetaPage) { metaData>>=4; } //Shift data to get to upper nibble if necessary uint8_t actualData = 0x00; for (uint8_t i=0; i<4; i++) { if (metaData & (1<<i)) { //Each '1' in the meta data is amplified to two bits in the actual actualData |= (0b11<<(i*2)); } } oledSetCursor(actualX,actualPage); oledWriteData(actualData); oledWriteData(actualData); }
void draw_LCD(unsigned char *buffer) { int16_t x, Y; for (Y=0;Y<8;Y++) { oled_address(0, Y); for (x=0;x<LCD_Xmax;x++) oledWriteData(buffer[x+Y*LCD_Xmax]); } }
void clear_LCD(void) { int16_t x, Y; for (Y=0;Y<LCD_Ymax/8;Y++) { oled_address(0, Y); for (x=0;x<LCD_Xmax;x++) oledWriteData(0x00); } }
void oledClearLind(u8 yStart,u8 yEnd) { u8 i,n; for(i=0;i<(yEnd-yStart+1);i++) { oledSetPosition(0,yStart+i); for(n=0;n<128;n++) oledWriteData(0); } }
void print_C(uint8_t Col, uint8_t Line, char ascii) { uint8_t j, i, tmp; for (j=0;j<2;j++) { oled_address(Col*8, Line*2+j); for (i=0;i<8;i++) { tmp=Font8x16[(ascii-0x20)*16+j*8+i]; oledWriteData(tmp); } } }
/**************************************************************************** * 函数名:oledClear 输 入:void 输 出:void 功 能:清屏函数 备 注:清完屏,整个屏幕是黑色的,和没点亮一样. * 日 期:2015.02.01 ****************************************************************************/ void oledClear(void) { u8 i,n; for(i=0;i<8;i++) { oledWriteCmd (0xb0+i); //设置页地址(0~7) oledWriteCmd (0x02); //设置显示位置—列低地址 oledWriteCmd (0x10); //设置显示位置—列高地址 for(n=0;n<128;n++) oledWriteData(0); } }
void oledSlid(u8 x,u8 y,u8 length,u8 point,u8 colorInverse) { int i; oledSetPosition(x,y); for(i=0;i<length;i++) { if(!colorInverse) oledWriteData(0x18); else oledWriteData(0xe7); } oledSetPosition(x+point,y); if(colorInverse) { oledWriteData(0x81); oledWriteData(0x81); } else { oledWriteData(0xff); oledWriteData(0xff); } }
void oledDisplay(char x, char y, char width, char hight, u8 *data, int xOffset, u8 colorInverse) { int i,j; //左右边界 int leftBound,rightBound; //显示的x轴起点, 显示的宽度, 数组偏移 char startX = x + xOffset, widthShow = width, dataOffset = 0; if(xOffset < -128) xOffset = -128; else if(xOffset > 128) xOffset = 128; //左、右边界 leftBound = (int)x + xOffset; rightBound = (int)x + (int)width + xOffset; if(leftBound > 127) return; if(rightBound < 0) return; //若左边界小于0 if(leftBound < 0) { //起点修正为0 startX = 0; //修正显示数据起始位置 dataOffset = -leftBound; //修正显示的宽度 widthShow = width + leftBound; } else if(rightBound > 127) { widthShow = width - (rightBound - 127); } for(i=0;i<hight;i++) { if(xOffset == 0) { oledSetPosition(startX,y+i); } else if(startX >= 2) { oledSetPosition(startX-2,y+i); if(!colorInverse) { oledWriteData(0x00); oledWriteData(0x00); } else { oledWriteData(0xff); oledWriteData(0xff); } } else if(startX == 1) { oledSetPosition(startX-1,y+i); if(!colorInverse) { oledWriteData(0x00); } else { oledWriteData(0xff); } } else oledSetPosition(startX,y+i); for(j=0;j<widthShow;j++) { if(!colorInverse) { oledWriteData(data[i * width + j + dataOffset]); } else { oledWriteData(~data[i * width + j + dataOffset]); } } if(xOffset == 0); else if((127 - rightBound) >= 2) { if(!colorInverse) { oledWriteData(0x00); oledWriteData(0x00); } else { oledWriteData(0xff); oledWriteData(0xff); } } else if((127 - rightBound) == 1) { if(!colorInverse) { oledWriteData(0x00); } else { oledWriteData(0xff); } } } }