@@ -67,102 +67,75 @@ void LittleVgl::SetFullRefresh(FullRefreshDirections direction) {
6767}
6868
6969void 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
0 commit comments