|
|
@@ -28,13 +28,13 @@ struct |
|
|
|
}; |
|
|
|
/****************************** END EASY PORT END *****************************/ |
|
|
|
|
|
|
|
static uint8 screen_buffer[128 * 160 * 3]; // TODO: make dynamic |
|
|
|
static uint8 screen_window_x1; |
|
|
|
static uint8 screen_window_x2; |
|
|
|
static uint8 screen_window_y1; |
|
|
|
static uint8 screen_window_y2; |
|
|
|
static uint8 screen_cursor_x; |
|
|
|
static uint8 screen_cursor_y; |
|
|
|
static uint8 screen_buffer[SCREEN_HEIGHT * SCREEN_WIDTH * 3]; // TODO: make dynamic |
|
|
|
static uint16 screen_window_x1; |
|
|
|
static uint16 screen_window_x2; |
|
|
|
static uint16 screen_window_y1; |
|
|
|
static uint16 screen_window_y2; |
|
|
|
static uint16 screen_cursor_x; |
|
|
|
static uint16 screen_cursor_y; |
|
|
|
|
|
|
|
void advance_screen_cursor() |
|
|
|
{ |
|
|
@@ -74,12 +74,12 @@ static inline void *safeMalloc(size_t size) |
|
|
|
} /* safeMalloc */ |
|
|
|
|
|
|
|
|
|
|
|
uint8 lcdhw_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2); |
|
|
|
uint16 lcdhw_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2); |
|
|
|
void lcdhw_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b); |
|
|
|
void lcdhw_pushPixels(lcd_t* lcd, uint8* pixels, size_t count); |
|
|
|
|
|
|
|
void lcd_setOrientation(lcd_t* lcd, uint8 orientation); |
|
|
|
void lcd_setGamma(lcd_t* lcd, uint8 state); |
|
|
|
void lcd_setOrientation(lcd_t* lcd, uint16 orientation); |
|
|
|
void lcd_setGamma(lcd_t* lcd, uint16 state); |
|
|
|
void lcd_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b); |
|
|
|
void lcd_pushPixels(lcd_t* lcd, uint8* pixels, size_t count); |
|
|
|
|
|
|
@@ -174,43 +174,53 @@ void lcd_deinit(lcd_t *display) |
|
|
|
free(display); |
|
|
|
} /* lcdst_uninit */ |
|
|
|
|
|
|
|
void lcd_setOrientation(lcd_t* lcd, uint8 orientation) |
|
|
|
void lcd_setOrientation(lcd_t* lcd, uint16 orientation) |
|
|
|
{ |
|
|
|
writeCommand(0x36); /* Memory Data Access Control */ |
|
|
|
|
|
|
|
int sw = SCREEN_WIDTH; |
|
|
|
int sh = SCREEN_HEIGHT; |
|
|
|
|
|
|
|
uint8 my = 1 << 7; // row address order bit |
|
|
|
uint8 mx = 1 << 6; // column address order bit |
|
|
|
uint8 mv = 1 << 5; // row/column exchange bit |
|
|
|
switch(orientation) |
|
|
|
{ |
|
|
|
case 1: |
|
|
|
writeData(0x60); /* MX + MV */ |
|
|
|
activeDisplay->width = 160; |
|
|
|
activeDisplay->height = 128; |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 159, 127); |
|
|
|
writeData(mx & mv); |
|
|
|
activeDisplay->width = sw; |
|
|
|
activeDisplay->height = sh; |
|
|
|
break; |
|
|
|
|
|
|
|
case 2: |
|
|
|
writeData(0xC0); /* MY + MX */ |
|
|
|
activeDisplay->width = 128; |
|
|
|
activeDisplay->height = 160; |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 127, 159); |
|
|
|
writeData(my & mx); |
|
|
|
activeDisplay->width = sh; |
|
|
|
activeDisplay->height = sw; |
|
|
|
break; |
|
|
|
|
|
|
|
case 3: |
|
|
|
writeData(0xA0); /* MY + MV */ |
|
|
|
activeDisplay->width = 160; |
|
|
|
activeDisplay->height = 128; |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 159, 127); |
|
|
|
writeData(my & mv); |
|
|
|
activeDisplay->width = sw; |
|
|
|
activeDisplay->height = sh; |
|
|
|
break; |
|
|
|
|
|
|
|
case 4: |
|
|
|
writeData(mx); |
|
|
|
activeDisplay->width = sh; |
|
|
|
activeDisplay->height = sw; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
writeData(0x00); /* None */ |
|
|
|
activeDisplay->width = 128; |
|
|
|
activeDisplay->height = 160; |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 127, 159); |
|
|
|
writeData(0); /* None */ |
|
|
|
activeDisplay->width = sh; |
|
|
|
activeDisplay->height = sw; |
|
|
|
break; |
|
|
|
} |
|
|
|
lcdhw_setWindow(lcd, 0, 0, activeDisplay->width - 1, activeDisplay->height - 1); |
|
|
|
} /* lcdst_setOrientation */ |
|
|
|
|
|
|
|
void lcd_setGamma(lcd_t* lcd, uint8 state) |
|
|
|
void lcd_setGamma(lcd_t* lcd, uint16 state) |
|
|
|
{ |
|
|
|
/* The status (0 or 1) of the GS pin can only be empirically tested */ |
|
|
|
switch(state) |
|
|
@@ -226,13 +236,13 @@ void lcd_setGamma(lcd_t* lcd, uint8 state) |
|
|
|
writeData(state); |
|
|
|
} /* lcdst_setGamma */ |
|
|
|
|
|
|
|
void lcd_setInversion(lcd_t* lcd, uint8 state) |
|
|
|
void lcd_setInversion(lcd_t* lcd, uint16 state) |
|
|
|
{ |
|
|
|
/* Display inversion ON/OFF */ |
|
|
|
writeCommand(state ? 0x21 : 0x20); |
|
|
|
} /* lcdst_setInversion */ |
|
|
|
|
|
|
|
uint8 lcdhw_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2) |
|
|
|
uint16 lcdhw_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2) |
|
|
|
{ |
|
|
|
/* Accept: 0 <= x1 <= x2 < activeDisplay->width */ |
|
|
|
if(x2 < x1) return 1; |
|
|
@@ -244,13 +254,13 @@ uint8 lcdhw_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2) |
|
|
|
|
|
|
|
/* Set column address */ |
|
|
|
writeCommand(0x2A); |
|
|
|
writeData(0); writeData(x1); |
|
|
|
writeData(0); writeData(x2); |
|
|
|
writeData(x1 >> 8); writeData(x1 & 0xFF); |
|
|
|
writeData(x2 >> 8); writeData(x2 & 0XFF); |
|
|
|
|
|
|
|
/* Set row address */ |
|
|
|
writeCommand(0x2B); |
|
|
|
writeData(0); writeData(y1); |
|
|
|
writeData(0); writeData(y2); |
|
|
|
writeData(y1 >> 8); writeData(y1 & 0xFF); |
|
|
|
writeData(y2 >> 8); writeData(y2 & 0xFF); |
|
|
|
|
|
|
|
/* Activate RAW write */ |
|
|
|
writeCommand(0x2C); |
|
|
@@ -282,7 +292,7 @@ void lcdhw_pushPixels(lcd_t* lcd, uint8* pixels, size_t count) |
|
|
|
gpio.spiDataRW(activeDisplay->channel, pixels, count * 3); |
|
|
|
} |
|
|
|
|
|
|
|
uint8 line_buffer[160*3]; // lcd->width or lcd->height |
|
|
|
uint8 line_buffer[SCREEN_WIDTH*3]; // lcd->width or lcd->height |
|
|
|
|
|
|
|
void lcd_redrawBuffer(lcd_t* lcd) |
|
|
|
{ |
|
|
@@ -293,7 +303,7 @@ void lcd_redrawBuffer(lcd_t* lcd) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
uint8 lcd_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2) |
|
|
|
uint16 lcd_setWindow(lcd_t* lcd, uint16 x1, uint16 y1, uint16 x2, uint16 y2) |
|
|
|
{ |
|
|
|
screen_window_x1 = x1; |
|
|
|
screen_window_x2 = x2; |
|
|
|