@@ -216,10 +216,11 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
216216 uint8_t row_command , uint16_t set_current_column_command , uint16_t set_current_row_command ,
217217 bool data_as_commands , bool always_toggle_chip_select ,
218218 displayio_area_t * area , bool SH1107_addressing ) {
219- uint16_t x1 = area -> x1 ;
220- uint16_t x2 = area -> x2 ;
221- uint16_t y1 = area -> y1 ;
222- uint16_t y2 = area -> y2 ;
219+ uint16_t x1 = area -> x1 + self -> colstart ;
220+ uint16_t x2 = area -> x2 + self -> colstart ;
221+ uint16_t y1 = area -> y1 + self -> rowstart ;
222+ uint16_t y2 = area -> y2 + self -> rowstart ;
223+
223224 // Collapse down the dimension where multiple pixels are in a byte.
224225 if (self -> colorspace .depth < 8 ) {
225226 uint8_t pixels_per_byte = 8 / self -> colorspace .depth ;
@@ -232,6 +233,9 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
232233 }
233234 }
234235
236+ x2 -= 1 ;
237+ y2 -= 1 ;
238+
235239 display_chip_select_behavior_t chip_select = CHIP_SELECT_UNTOUCHED ;
236240 if (always_toggle_chip_select || data_as_commands ) {
237241 chip_select = CHIP_SELECT_TOGGLE_EVERY_BYTE ;
@@ -249,25 +253,25 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
249253 } else {
250254 data_type = DISPLAY_COMMAND ;
251255 }
256+
252257 if (self -> ram_width < 0x100 ) {
253- data [data_length ++ ] = x1 + self -> colstart ;
254- data [data_length ++ ] = x2 - 1 + self -> colstart ;
258+ data [data_length ++ ] = x1 ;
259+ data [data_length ++ ] = x2 ;
255260 } else {
256- x1 += self -> colstart ;
257- x2 += self -> colstart - 1 ;
258261 data [data_length ++ ] = x1 >> 8 ;
259262 data [data_length ++ ] = x1 & 0xff ;
260263 data [data_length ++ ] = x2 >> 8 ;
261264 data [data_length ++ ] = x2 & 0xff ;
262265 }
266+
263267 // Quirk for SH1107 "SH1107_addressing"
264- // Note... column is y! page is x!
265- // Page address command = 0xB0
268+ // Column lower command = 0x00, Column upper command = 0x10
266269 if (SH1107_addressing ) {
267- // set the page to our x value
268- data [0 ] = 0xB0 | ( x1 & 0x0F );
269- data_length = 1 ;
270+ data [ 0 ] = (( x1 >> 4 ) & 0x0F ) | 0x10 ; // 0x10 to 0x17
271+ data [1 ] = x1 & 0x0F ; // 0x00 to 0x0F
272+ data_length = 2 ;
270273 }
274+
271275 self -> send (self -> bus , data_type , chip_select , data , data_length );
272276 displayio_display_core_end_transaction (self );
273277
@@ -288,27 +292,26 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self,
288292 self -> send (self -> bus , DISPLAY_COMMAND , CHIP_SELECT_UNTOUCHED , data , 1 );
289293 data_length = 0 ;
290294 }
295+
291296 if (self -> ram_height < 0x100 ) {
292- data [data_length ++ ] = y1 + self -> rowstart ;
293- data [data_length ++ ] = y2 - 1 + self -> rowstart ;
297+ data [data_length ++ ] = y1 ;
298+ data [data_length ++ ] = y2 ;
294299 } else {
295- y1 += self -> rowstart ;
296- y2 += self -> rowstart - 1 ;
297300 data [data_length ++ ] = y1 >> 8 ;
298301 data [data_length ++ ] = y1 & 0xff ;
299302 data [data_length ++ ] = y2 >> 8 ;
300303 data [data_length ++ ] = y2 & 0xff ;
301304 }
305+
302306 // Quirk for SH1107 "SH1107_addressing"
303- // Note... column is y! page is x!
304- // Column lower command = 0x00, Column upper command = 0x10
307+ // Page address command = 0xB0
305308 if (SH1107_addressing ) {
306- data [ 0 ] = y1 & 0x0F ; // 0x00 to 0x0F
307- data [1 ] = ( y1 >> 4 & 0x0F ) | 0x10 ; // 0x10 to 0x17
308- data_length = 2 ;
309+ // set the page to our y value
310+ data [0 ] = 0xB0 | y1 ;
311+ data_length = 1 ;
309312 }
310- self -> send (self -> bus , data_type , chip_select , data , data_length );
311313
314+ self -> send (self -> bus , data_type , chip_select , data , data_length );
312315 displayio_display_core_end_transaction (self );
313316
314317 if (set_current_row_command != NO_COMMAND ) {
0 commit comments