|
|
@@ -28,6 +28,14 @@ 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 lcd_t *activeDisplay; |
|
|
|
|
|
|
|
/* |
|
|
@@ -54,6 +62,10 @@ static inline void *safeMalloc(size_t size) |
|
|
|
} /* safeMalloc */ |
|
|
|
|
|
|
|
|
|
|
|
uint8 lcdhw_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 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_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b); |
|
|
@@ -158,28 +170,28 @@ void lcd_setOrientation(lcd_t* lcd, uint8 orientation) |
|
|
|
writeData(0x60); /* MX + MV */ |
|
|
|
activeDisplay->width = 160; |
|
|
|
activeDisplay->height = 128; |
|
|
|
lcd_setWindow(lcd, 0, 0, 159, 127); |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 159, 127); |
|
|
|
break; |
|
|
|
|
|
|
|
case 2: |
|
|
|
writeData(0xC0); /* MY + MX */ |
|
|
|
activeDisplay->width = 128; |
|
|
|
activeDisplay->height = 160; |
|
|
|
lcd_setWindow(lcd, 0, 0, 127, 159); |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 127, 159); |
|
|
|
break; |
|
|
|
|
|
|
|
case 3: |
|
|
|
writeData(0xA0); /* MY + MV */ |
|
|
|
activeDisplay->width = 160; |
|
|
|
activeDisplay->height = 128; |
|
|
|
lcd_setWindow(lcd, 0, 0, 159, 127); |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 159, 127); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
writeData(0x00); /* None */ |
|
|
|
activeDisplay->width = 128; |
|
|
|
activeDisplay->height = 160; |
|
|
|
lcd_setWindow(lcd, 0, 0, 127, 159); |
|
|
|
lcdhw_setWindow(lcd, 0, 0, 127, 159); |
|
|
|
break; |
|
|
|
} |
|
|
|
} /* lcdst_setOrientation */ |
|
|
@@ -206,7 +218,7 @@ void lcd_setInversion(lcd_t* lcd, uint8 state) |
|
|
|
writeCommand(state ? 0x21 : 0x20); |
|
|
|
} /* lcdst_setInversion */ |
|
|
|
|
|
|
|
uint8 lcd_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2) |
|
|
|
uint8 lcdhw_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2) |
|
|
|
{ |
|
|
|
/* Accept: 0 <= x1 <= x2 < activeDisplay->width */ |
|
|
|
if(x2 < x1) return 1; |
|
|
@@ -241,18 +253,69 @@ void lcd_activateRamWrite(void) |
|
|
|
|
|
|
|
uint8 pixel[3]; |
|
|
|
|
|
|
|
inline void lcd_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b) |
|
|
|
inline void lcdhw_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b) |
|
|
|
{ |
|
|
|
gpio.digitalWrite(activeDisplay->a0, HIGH); |
|
|
|
pixel[0] = r; |
|
|
|
pixel[1] = g; |
|
|
|
pixel[2] = b; |
|
|
|
gpio.spiDataRW(activeDisplay->channel, pixel, 3); |
|
|
|
} /* lcdst_pushPx */ |
|
|
|
} |
|
|
|
|
|
|
|
void lcd_pushPixels(lcd_t* lcd, uint8* pixels, size_t count) |
|
|
|
void lcdhw_pushPixels(lcd_t* lcd, uint8* pixels, size_t count) |
|
|
|
{ |
|
|
|
gpio.digitalWrite(activeDisplay->a0, HIGH); |
|
|
|
gpio.spiDataRW(activeDisplay->channel, pixels, count * 3); |
|
|
|
} |
|
|
|
|
|
|
|
uint8 line_buffer[160*3]; // lcd->width or lcd->height |
|
|
|
|
|
|
|
void lcd_redrawBuffer(lcd_t* lcd) |
|
|
|
{ |
|
|
|
for (int i = 0; i < lcd->height; i++) { |
|
|
|
memcpy(line_buffer, &screen_buffer[i*lcd->width*3], lcd->width*3); |
|
|
|
lcdhw_setWindow(lcd, 0, i, lcd->width - 1, i); |
|
|
|
lcdhw_pushPixels(lcd, line_buffer, lcd->width); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
uint8 lcd_setWindow(lcd_t* lcd, uint8 x1, uint8 y1, uint8 x2, uint8 y2) |
|
|
|
{ |
|
|
|
screen_window_x1 = x1; |
|
|
|
screen_window_x2 = x2; |
|
|
|
screen_window_y1 = y1; |
|
|
|
screen_window_y2 = y2; |
|
|
|
screen_cursor_x = x1; |
|
|
|
screen_cursor_y = y1; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
void lcd_pushPixel(lcd_t* lcd, uint8 r, uint8 g, uint8 b) |
|
|
|
{ |
|
|
|
int i = screen_cursor_x |
|
|
|
+ screen_cursor_y * lcd->width; |
|
|
|
screen_buffer[i * 3 + 0] = r; |
|
|
|
screen_buffer[i * 3 + 1] = g; |
|
|
|
screen_buffer[i * 3 + 2] = b; |
|
|
|
|
|
|
|
screen_cursor_x++; |
|
|
|
if (screen_cursor_x > screen_window_x2) { |
|
|
|
screen_cursor_x = screen_window_x1; |
|
|
|
screen_cursor_y++; |
|
|
|
if (screen_cursor_y > screen_window_y2) { |
|
|
|
screen_cursor_y = screen_window_y1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void lcd_pushPixels(lcd_t* lcd, uint8* pixels, size_t count) |
|
|
|
{ |
|
|
|
for (int i = 0; i < count; i++) { |
|
|
|
lcd_pushPixel(lcd, |
|
|
|
pixels[i * 3 + 0], |
|
|
|
pixels[i * 3 + 1], |
|
|
|
pixels[i * 3 + 2]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|