Skip to content

Commit dba7e47

Browse files
committed
FIX screen corruption #213
1 parent ada9425 commit dba7e47

4 files changed

Lines changed: 38 additions & 78 deletions

File tree

src/components/gfx/Gfx.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ void Gfx::ClearScreen() {
1717
state.busy = true;
1818
state.action = Action::FillRectangle;
1919
state.taskToNotify = xTaskGetCurrentTaskHandle();
20-
21-
lcd.BeginDrawBuffer(0, 0, width, height);
22-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(buffer), width * 2);
20+
21+
lcd.DrawBuffer(0, 0, width, height, reinterpret_cast<const uint8_t *>(buffer), width * 2);
2322
WaitTransferFinished();
2423

2524
}
@@ -34,8 +33,7 @@ void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t col
3433
state.color = color;
3534
state.taskToNotify = xTaskGetCurrentTaskHandle();
3635

37-
lcd.BeginDrawBuffer(x, y, w, h);
38-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(buffer), width * 2);
36+
lcd.DrawBuffer(x, y, w, h, reinterpret_cast<const uint8_t *>(buffer), width * 2);
3937

4038
WaitTransferFinished();
4139
}
@@ -48,8 +46,7 @@ void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t* b)
4846
state.color = 0x00;
4947
state.taskToNotify = xTaskGetCurrentTaskHandle();
5048

51-
lcd.BeginDrawBuffer(x, y, w, h);
52-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(b), width * 2);
49+
lcd.DrawBuffer(x, y, w, h, reinterpret_cast<const uint8_t *>(b), width * 2);
5350

5451
WaitTransferFinished();
5552
}
@@ -120,8 +117,7 @@ void Gfx::DrawChar(const FONT_INFO *font, uint8_t c, uint8_t *x, uint8_t y, uint
120117
state.color = color;
121118
state.taskToNotify = xTaskGetCurrentTaskHandle();
122119

123-
lcd.BeginDrawBuffer(*x, y, bytes_in_line*8, font->height);
124-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(&buffer), bytes_in_line*8*2);
120+
lcd.DrawBuffer(*x, y, bytes_in_line*8, font->height, reinterpret_cast<const uint8_t *>(&buffer), bytes_in_line*8*2);
125121
WaitTransferFinished();
126122

127123
*x += font->charInfo[char_idx].widthBits + font->spacePixels;

src/displayapp/LittleVgl.cpp

Lines changed: 30 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -67,102 +67,75 @@ void LittleVgl::SetFullRefresh(FullRefreshDirections direction) {
6767
}
6868

6969
void LittleVgl::FlushDisplay(const lv_area_t *area, lv_color_t *color_p) {
70+
uint16_t y1, y2, width, height = 0;
71+
7072
ulTaskNotifyTake(pdTRUE, 500);
7173
// Notification is still needed (even if there is a mutex on SPI) because of the DataCommand pin
7274
// which cannot be set/clear during a transfer.
7375

76+
if( (scrollDirection == LittleVgl::FullRefreshDirections::Down) && (area->y2 == visibleNbLines - 1)) {
77+
writeOffset = ((writeOffset + totalNbLines) - visibleNbLines) % totalNbLines;
78+
} else if( (scrollDirection == FullRefreshDirections::Up) && (area->y1 == 0) ) {
79+
writeOffset = (writeOffset + visibleNbLines) % totalNbLines;
80+
}
7481

75-
// TODO refactore and remove duplicated code
76-
77-
uint16_t x, y, y1, y2, width, height = 0;
78-
if(scrollDirection == LittleVgl::FullRefreshDirections::Down) {
79-
if(area->y2 == visibleNbLines-1) {
80-
writeOffset = ((writeOffset + totalNbLines) - visibleNbLines) % totalNbLines;
81-
}
82-
x = area->x1;
83-
width = (area->x2 - area->x1) + 1;
82+
y1 = (area->y1 + writeOffset) % totalNbLines;
83+
y2 = (area->y2 + writeOffset) % totalNbLines;
8484

85-
y1 = (area->y1 + writeOffset) % totalNbLines;
86-
y2 = (area->y2 + writeOffset) % totalNbLines;
87-
y = y1;
88-
height = (y2 - y1) + 1;
85+
width = (area->x2 - area->x1) + 1;
86+
height = (area->y2 - area->y1) + 1;
8987

88+
if(scrollDirection == LittleVgl::FullRefreshDirections::Down) {
9089
if(area->y2 < visibleNbLines - 1) {
9190
uint16_t toScroll = 0;
9291
if(area->y1 == 0) {
93-
toScroll = height*2;
92+
toScroll = height * 2;
9493
scrollDirection = FullRefreshDirections::None;
9594
lv_disp_set_direction(lv_disp_get_default(), 0);
9695
} else {
9796
toScroll = height;
9897
}
99-
10098
if(scrollOffset >= toScroll)
10199
scrollOffset -= toScroll;
102100
else {
103101
toScroll -= scrollOffset;
104-
scrollOffset = (totalNbLines) - toScroll;
102+
scrollOffset = (totalNbLines) - toScroll;
105103
}
106-
107-
lcd.VerticalScrollDefinition(0, 320, 0);
108104
lcd.VerticalScrollStartAddress(scrollOffset);
109105
}
110106

111-
lcd.BeginDrawBuffer(x, y, width, height);
112-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height*2) ;
113-
114107
} else if(scrollDirection == FullRefreshDirections::Up) {
115-
if(area->y1 == 0) {
116-
writeOffset = (writeOffset + visibleNbLines) % totalNbLines;
117-
}
118-
119-
x = area->x1;
120-
width = (area->x2 - area->x1) + 1;
121-
122-
y1 = (area->y1 + writeOffset) % totalNbLines;
123-
y2 = (area->y2 + writeOffset) % totalNbLines;
124-
y = y1;
125-
height = (y2 - y1) + 1;
126108

127109
if(area->y1 > 0) {
128-
if(area->y2 == visibleNbLines -1) {
110+
if(area->y2 == visibleNbLines - 1) {
129111
scrollOffset += (height * 2);
130112
scrollDirection = FullRefreshDirections::None;
131113
lv_disp_set_direction(lv_disp_get_default(), 0);
132114
} else {
133115
scrollOffset += height;
134116
}
135117
scrollOffset = scrollOffset % totalNbLines;
136-
lcd.VerticalScrollDefinition(0, 320, 0);
137118
lcd.VerticalScrollStartAddress(scrollOffset);
138119
}
120+
}
139121

140-
lcd.BeginDrawBuffer(x, y, width, height);
141-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height*2);
142-
} else {
143-
x = area->x1;
144-
width = (area->x2 - area->x1) + 1;
145-
y1 = (area->y1 + writeOffset) % totalNbLines;
146-
y2 = (area->y2 + writeOffset) % totalNbLines;
147-
y = y1;
148-
height = (y2 - y1) + 1;
149-
150-
if (y2 < y1) {
151-
height = (totalNbLines - 1) - y1;
152-
lcd.BeginDrawBuffer(x, y1, width, height);
153-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
154-
ulTaskNotifyTake(pdTRUE, 500);
155-
height = y2;
156-
lcd.BeginDrawBuffer(x, 0, width, height);
157-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
158-
} else {
159-
lcd.BeginDrawBuffer(x, y, width, height);
160-
lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
122+
if (y2 < y1) {
123+
height = totalNbLines - y1;
124+
125+
if ( height > 0 ) {
126+
lcd.DrawBuffer(area->x1, y1, width, height, reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
127+
ulTaskNotifyTake(pdTRUE, 320);
161128
}
129+
uint16_t pixOffset = width * height;
130+
height = y2 + 1;
131+
lcd.DrawBuffer(area->x1, 0, width, height, reinterpret_cast<const uint8_t *>(color_p + pixOffset), width * height * 2);
132+
133+
} else {
134+
lcd.DrawBuffer(area->x1, y1, width, height, reinterpret_cast<const uint8_t *>(color_p), width * height * 2);
162135
}
163136

164-
/* IMPORTANT!!!
165-
* Inform the graphics library that you are ready with the flushing*/
137+
// IMPORTANT!!!
138+
// Inform the graphics library that you are ready with the flushing
166139
lv_disp_flush_ready(&disp_drv);
167140
}
168141

src/drivers/St7789.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,9 @@ void St7789::DrawPixel(uint16_t x, uint16_t y, uint32_t color) {
153153
WriteSpi(reinterpret_cast<const uint8_t *>(&color), 2);
154154
}
155155

156-
void St7789::BeginDrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
157-
if((x >= Width) || (y >= Height)) return;
158-
if((x + width - 1) >= Width) width = Width - x;
159-
if((y + height - 1) >= Height) height = Height - y;
160-
161-
SetAddrWindow(0+x, ST7789_ROW_OFFSET+y, x+width-1, y+height-1);
156+
void St7789::DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *data, size_t size) {
157+
SetAddrWindow(x, y, x + width - 1, y + height - 1);
162158
nrf_gpio_pin_set(pinDataCommand);
163-
}
164-
165-
void St7789::NextDrawBuffer(const uint8_t *data, size_t size) {
166159
WriteSpi(data, size);
167160
}
168161

src/drivers/St7789.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ namespace Pinetime {
2020
void VerticalScrollDefinition(uint16_t topFixedLines, uint16_t scrollLines, uint16_t bottomFixedLines);
2121
void VerticalScrollStartAddress(uint16_t line);
2222

23-
24-
void BeginDrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
25-
void NextDrawBuffer(const uint8_t* data, size_t size);
23+
void DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *data, size_t size);
2624

2725
void DisplayOn();
2826
void DisplayOff();

0 commit comments

Comments
 (0)