implement height and width
This commit is contained in:
parent
78e20ae4bb
commit
f0ee85d022
4 changed files with 32 additions and 21 deletions
|
@ -27,12 +27,14 @@ extern "C"
|
||||||
|
|
||||||
unsigned char frame[SSD1306_128x64_BYTES];
|
unsigned char frame[SSD1306_128x64_BYTES];
|
||||||
|
|
||||||
SSD1306::SSD1306(int BSCMaster, u8 address, int flip, LCD_MODEL type)
|
SSD1306::SSD1306(int BSCMaster, u8 address, int width, int height, int flip, LCD_MODEL type)
|
||||||
: BSCMaster(BSCMaster)
|
: BSCMaster(BSCMaster)
|
||||||
, address(address)
|
, address(address)
|
||||||
, type(type)
|
, type(type)
|
||||||
, flip(flip)
|
, flip(flip)
|
||||||
, contrast(127)
|
, contrast(127)
|
||||||
|
, width(width)
|
||||||
|
, height(height)
|
||||||
{
|
{
|
||||||
RPI_I2CInit(BSCMaster, 1);
|
RPI_I2CInit(BSCMaster, 1);
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ void SSD1306::InitHardware()
|
||||||
SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE
|
SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8
|
SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8
|
||||||
SendCommand(0x3F); // SSD1306_LCDHEIGHT - 1
|
SendCommand(height-1); // SSD1306_LCDHEIGHT - 1
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_SET_DISPLAY_OFFSET); // 0xD3 Vertical scroll position
|
SendCommand(SSD1306_CMD_SET_DISPLAY_OFFSET); // 0xD3 Vertical scroll position
|
||||||
SendCommand(0x00); // no Offset
|
SendCommand(0x00); // no Offset
|
||||||
|
@ -118,15 +120,15 @@ void SSD1306::Home()
|
||||||
MoveCursorByte(0, 0);
|
MoveCursorByte(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSD1306::MoveCursorByte(u8 row, u8 col)
|
void SSD1306::MoveCursorByte(u8 page, u8 col)
|
||||||
{
|
{
|
||||||
if (col > 127) { col = 127; }
|
if (col > width-1) { col = width-1; }
|
||||||
if (row > 7) { row = 7; }
|
if (page > height/8-1) { page = height/8-1; }
|
||||||
|
|
||||||
if (type == LCD_1106_128x64)
|
if (type == LCD_1106_128x64)
|
||||||
col += 2; // sh1106 uses columns 2..129
|
col += 2; // sh1106 uses columns 2..129
|
||||||
|
|
||||||
SendCommand(SSD1306_CMD_SET_PAGE | row); // 0xB0 page address
|
SendCommand(SSD1306_CMD_SET_PAGE | page); // 0xB0 page address
|
||||||
SendCommand(SSD1306_CMD_SET_COLUMN_LOW | (col & 0xf)); // 0x00 column address lower bits
|
SendCommand(SSD1306_CMD_SET_COLUMN_LOW | (col & 0xf)); // 0x00 column address lower bits
|
||||||
SendCommand(SSD1306_CMD_SET_COLUMN_HIGH | (col >> 4)); // 0x10 column address upper bits
|
SendCommand(SSD1306_CMD_SET_COLUMN_HIGH | (col >> 4)); // 0x10 column address upper bits
|
||||||
}
|
}
|
||||||
|
@ -134,7 +136,7 @@ void SSD1306::MoveCursorByte(u8 row, u8 col)
|
||||||
void SSD1306::RefreshScreen()
|
void SSD1306::RefreshScreen()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < height/8; i++)
|
||||||
{
|
{
|
||||||
RefreshPage(i);
|
RefreshPage(i);
|
||||||
}
|
}
|
||||||
|
@ -154,16 +156,19 @@ void SSD1306::RefreshRows(u32 start, u32 amountOfRows)
|
||||||
|
|
||||||
void SSD1306::RefreshPage(u32 page)
|
void SSD1306::RefreshPage(u32 page)
|
||||||
{
|
{
|
||||||
|
if (page >= height/8)
|
||||||
|
return;
|
||||||
|
|
||||||
// x32 displays use lower half (pages 2 and 3)
|
// x32 displays use lower half (pages 2 and 3)
|
||||||
if (type == LCD_1306_128x32)
|
if (type == LCD_1306_128x32)
|
||||||
{
|
{
|
||||||
page = page+2; // 0,1 -> 2,3
|
page = page+4; // 0,1,2,3 -> 4,5,6,7
|
||||||
page = page%4; // and wrap it so 2,3 -> 0,1
|
page = page%4; // and wrap it so 4,5 -> 0,1
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int start = page*128;
|
int start = page*width;
|
||||||
int end = page*128 + 128;
|
int end = start + width;
|
||||||
|
|
||||||
MoveCursorByte(page, 0);
|
MoveCursorByte(page, 0);
|
||||||
for (i = start; i < end; i++)
|
for (i = start; i < end; i++)
|
||||||
|
|
|
@ -76,7 +76,7 @@ class SSD1306
|
||||||
public:
|
public:
|
||||||
// 128x32 0x3C
|
// 128x32 0x3C
|
||||||
// 128x64 0x3D or 0x3C (if SA0 is grounded)
|
// 128x64 0x3D or 0x3C (if SA0 is grounded)
|
||||||
SSD1306(int BSCMaster = 1, u8 address = 0x3C, int flip = 0, LCD_MODEL type=LCD_UNKNOWN);
|
SSD1306(int BSCMaster = 1, u8 address = 0x3C, int width = 128, int height = 64, int flip = 0, LCD_MODEL type=LCD_UNKNOWN);
|
||||||
|
|
||||||
void PlotCharacter(int x, int y, char ascii, bool inverse);
|
void PlotCharacter(int x, int y, char ascii, bool inverse);
|
||||||
void PlotText(int x, int y, char* str, bool inverse);
|
void PlotText(int x, int y, char* str, bool inverse);
|
||||||
|
@ -110,6 +110,8 @@ protected:
|
||||||
int type;
|
int type;
|
||||||
int flip;
|
int flip;
|
||||||
int contrast;
|
int contrast;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int B
|
||||||
|
|
||||||
if (widthDesired < 128)
|
if (widthDesired < 128)
|
||||||
widthDesired = 128;
|
widthDesired = 128;
|
||||||
if (heightDesired < 64)
|
if (heightDesired < 32)
|
||||||
heightDesired = 64;
|
heightDesired = 32;
|
||||||
if (widthDesired > 128)
|
if (widthDesired > 128)
|
||||||
widthDesired = 128;
|
widthDesired = 128;
|
||||||
if (heightDesired > 64)
|
if (heightDesired > 64)
|
||||||
|
@ -39,7 +39,7 @@ void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int B
|
||||||
width = widthDesired;
|
width = widthDesired;
|
||||||
height = heightDesired;
|
height = heightDesired;
|
||||||
|
|
||||||
ssd1306 = new SSD1306(BSCMaster, LCDAddress, LCDFlip, LCDType);
|
ssd1306 = new SSD1306(BSCMaster, LCDAddress, width, height, LCDFlip, LCDType);
|
||||||
ssd1306->ClearScreen();
|
ssd1306->ClearScreen();
|
||||||
ssd1306->RefreshScreen();
|
ssd1306->RefreshScreen();
|
||||||
ssd1306->DisplayOn();
|
ssd1306->DisplayOn();
|
||||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -369,20 +369,24 @@ void InitialiseLCD()
|
||||||
|
|
||||||
if (i2cLcdModel)
|
if (i2cLcdModel)
|
||||||
{
|
{
|
||||||
|
int width = 128;
|
||||||
|
int height = 64;
|
||||||
|
if (i2cLcdModel == LCD_1306_128x32)
|
||||||
|
height = 32;
|
||||||
screenLCD = new ScreenLCD();
|
screenLCD = new ScreenLCD();
|
||||||
screenLCD->Open(128, 64, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip, i2cLcdModel);
|
screenLCD->Open(width, height, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip, i2cLcdModel);
|
||||||
screenLCD->SetContrast(i2cLcdOnContrast);
|
screenLCD->SetContrast(i2cLcdOnContrast);
|
||||||
screenLCD->ClearInit(0); // sh1106 needs this
|
screenLCD->ClearInit(0); // sh1106 needs this
|
||||||
|
|
||||||
bool logo_done = false;
|
bool logo_done = false;
|
||||||
if (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0)
|
if ( (height == 64) && (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0) )
|
||||||
{
|
{
|
||||||
screenLCD->PlotRawImage(logo_ssd_1541ii, 0, 0, 128, 64);
|
screenLCD->PlotRawImage(logo_ssd_1541ii, 0, 0, 128, 64);
|
||||||
snprintf(tempBuffer, tempBufferSize, "Pi1541 V%d.%02d", versionMajor, versionMinor);
|
snprintf(tempBuffer, tempBufferSize, "Pi1541 V%d.%02d", versionMajor, versionMinor);
|
||||||
screenLCD->PrintText(0, 16, 0, tempBuffer, 0xffffffff);
|
screenLCD->PrintText(0, 16, 0, tempBuffer, 0xffffffff);
|
||||||
logo_done = true;
|
logo_done = true;
|
||||||
}
|
}
|
||||||
else if (strcasecmp(options.GetLcdLogoName(), "1541classic") == 0)
|
else if (( height == 64) && (strcasecmp(options.GetLcdLogoName(), "1541classic") == 0) )
|
||||||
{
|
{
|
||||||
screenLCD->PlotRawImage(logo_ssd_1541classic, 0, 0, 128, 64);
|
screenLCD->PlotRawImage(logo_ssd_1541classic, 0, 0, 128, 64);
|
||||||
logo_done = true;
|
logo_done = true;
|
||||||
|
@ -398,7 +402,7 @@ void InitialiseLCD()
|
||||||
u32 bytesRead;
|
u32 bytesRead;
|
||||||
f_read(&fp, LcdLogoFile, LCD_LOGO_MAX_SIZE, &bytesRead);
|
f_read(&fp, LcdLogoFile, LCD_LOGO_MAX_SIZE, &bytesRead);
|
||||||
f_close(&fp);
|
f_close(&fp);
|
||||||
screenLCD->PlotRawImage(LcdLogoFile, 0, 0, 128, 64);
|
screenLCD->PlotRawImage(LcdLogoFile, 0, 0, 128, height);
|
||||||
logo_done = true;
|
logo_done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,8 +410,8 @@ void InitialiseLCD()
|
||||||
if (!logo_done)
|
if (!logo_done)
|
||||||
{
|
{
|
||||||
snprintf(tempBuffer, tempBufferSize, "Pi1541 V%d.%02d", versionMajor, versionMinor);
|
snprintf(tempBuffer, tempBufferSize, "Pi1541 V%d.%02d", versionMajor, versionMinor);
|
||||||
int x = (128 - 8*strlen(tempBuffer) ) /2;
|
int x = (width - 8*strlen(tempBuffer) ) /2;
|
||||||
int y = (64-16)/2;
|
int y = (height-16)/2;
|
||||||
screenLCD->PrintText(0, x, y, tempBuffer, 0x0);
|
screenLCD->PrintText(0, x, y, tempBuffer, 0x0);
|
||||||
}
|
}
|
||||||
screenLCD->RefreshScreen();
|
screenLCD->RefreshScreen();
|
||||||
|
|
Loading…
Reference in a new issue