Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LCD contrast support (90% accurately) #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions src/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ static uint8_t LCD_CG[64];

static uint8_t lcd_enable = 1;
static bool lcd_quit_requested = false;
static uint8_t lcd_contrast = 0;

void LCD_SetContrast(uint8_t contrast)
{
if (mcu_jv880)
{
if (contrast > 10)
contrast = 10;
lcd_contrast = contrast; // FIXME
}
else
{
if (contrast > 16)
contrast = 16;
if (contrast < 1)
contrast = 1;
lcd_contrast = contrast;
}
}

void LCD_Enable(uint32_t enable)
{
Expand Down Expand Up @@ -298,7 +317,10 @@ void LCD_FontRenderStandard(int32_t x, int32_t y, uint8_t ch, bool overlay = fal
for (int jj = 0; jj < 5; jj++)
{
if (overlay)
lcd_buffer[xx+ii][yy+jj] &= col;
{
if (lcd_buffer[xx+ii][yy+jj] != col && col == lcd_col1)
lcd_buffer[xx+ii][yy+jj] = col;
}
else
lcd_buffer[xx+ii][yy+jj] = col;
}
Expand Down Expand Up @@ -407,6 +429,19 @@ void LCD_FontRenderLR(uint8_t ch)
}
}

static uint32_t inline LCD_MixColor(uint32_t color, uint8_t contrast)
{
uint8_t b = (color >> 16) & 0xFF;
uint8_t g = (color >> 8) & 0xFF;
uint8_t r = color & 0xFF;

b = (b * contrast) >> 8;
g = (g * contrast) >> 8;
r = (r * contrast) >> 8;

return (color & 0xFF000000) | ((b & 0xFF) << 16) | ((g & 0xFF) << 8) | (r & 0xFF);
}

void LCD_Update(void)
{
if (!lcd_init)
Expand Down Expand Up @@ -439,13 +474,19 @@ void LCD_Update(void)
}
}

uint32_t con = 0x11 * (lcd_contrast - 1);
con = (con * con) >> 8;
lcd_col2 = LCD_MixColor(lcd_buffer[0][0], 0xFF - (con / 4 + 4));
lcd_col1 = LCD_MixColor(lcd_col2, 0x11 * (16 - (((lcd_contrast + 1) >> 1) + 4)));

if (mcu_jv880)
{
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 24; j++)
{
uint8_t ch = LCD_Data[i * 40 + j];
LCD_FontRenderStandard(10 + i * 50, 4 + j * 34, ' ');
LCD_FontRenderStandard(4 + i * 50, 4 + j * 34, ch);
}
}
Expand All @@ -454,7 +495,7 @@ void LCD_Update(void)
int j = LCD_DD_RAM % 0x40;
int i = LCD_DD_RAM / 0x40;
if (i < 2 && j < 24 && LCD_C)
LCD_FontRenderStandard(4 + i * 50, 4 + j * 34, '_', true);
LCD_FontRenderStandard(10 + i * 50, 4 + j * 34, '_', true);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ void LCD_Enable(uint32_t enable);
bool LCD_QuitRequested();
void LCD_Sync(void);
void LCD_Update(void);
void LCD_SetContrast(uint8_t contrast);
4 changes: 4 additions & 0 deletions src/mcu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ void MCU_DeviceWrite(uint32_t address, uint8_t data)
case DEV_IPRD:
break;
case DEV_PWM1_DTR:
if (mcu_jv880)
LCD_SetContrast(10 - (data / 11));
else
LCD_SetContrast(16 - (data >> 4));
break;
case DEV_PWM1_TCR:
break;
Expand Down