@@ -101,7 +101,8 @@ void displayio_display_bus_end_transaction(displayio_display_bus_t *self) {
101101 self -> end_transaction (self -> bus );
102102}
103103
104- void displayio_display_bus_set_region_to_update (displayio_display_bus_t * self , displayio_display_core_t * display , displayio_area_t * area ) {
104+ // Determine if this is run from a background task or not. Should we skip sending the data or wait for the bus?
105+ bool displayio_display_bus_set_region_to_update (displayio_display_bus_t * self , displayio_display_core_t * display , displayio_area_t * area ) {
105106 uint16_t x1 = area -> x1 + self -> colstart ;
106107 uint16_t x2 = area -> x2 + self -> colstart ;
107108 uint16_t y1 = area -> y1 + self -> rowstart ;
@@ -127,8 +128,12 @@ void displayio_display_bus_set_region_to_update(displayio_display_bus_t *self, d
127128 chip_select = CHIP_SELECT_TOGGLE_EVERY_BYTE ;
128129 }
129130
131+ if (!displayio_display_bus_begin_transaction (self )) {
132+ // Can't acquire display bus; skip and report failure.
133+ return false;
134+ }
135+
130136 // Set column.
131- displayio_display_bus_begin_transaction (self );
132137 uint8_t data [5 ];
133138 data [0 ] = self -> column_command ;
134139 uint8_t data_length = 1 ;
@@ -163,20 +168,16 @@ void displayio_display_bus_set_region_to_update(displayio_display_bus_t *self, d
163168 }
164169
165170 self -> send (self -> bus , data_type , chip_select , data , data_length );
166- displayio_display_bus_end_transaction (self );
167171
168172 if (self -> set_current_column_command != NO_COMMAND ) {
169173 uint8_t command = self -> set_current_column_command ;
170- displayio_display_bus_begin_transaction (self );
171174 self -> send (self -> bus , DISPLAY_COMMAND , chip_select , & command , 1 );
172175 // Only send the first half of data because it is the first coordinate.
173176 self -> send (self -> bus , DISPLAY_DATA , chip_select , data , data_length / 2 );
174- displayio_display_bus_end_transaction (self );
175177 }
176178
177179
178180 // Set row.
179- displayio_display_bus_begin_transaction (self );
180181 data [0 ] = self -> row_command ;
181182 data_length = 1 ;
182183 if (!self -> data_as_commands ) {
@@ -207,16 +208,15 @@ void displayio_display_bus_set_region_to_update(displayio_display_bus_t *self, d
207208 }
208209
209210 self -> send (self -> bus , data_type , chip_select , data , data_length );
210- displayio_display_bus_end_transaction (self );
211211
212212 if (self -> set_current_row_command != NO_COMMAND ) {
213213 uint8_t command = self -> set_current_row_command ;
214- displayio_display_bus_begin_transaction (self );
215214 self -> send (self -> bus , DISPLAY_COMMAND , chip_select , & command , 1 );
216215 // Only send the first half of data because it is the first coordinate.
217216 self -> send (self -> bus , DISPLAY_DATA , chip_select , data , data_length / 2 );
218- displayio_display_bus_end_transaction (self );
219217 }
218+ displayio_display_bus_end_transaction (self );
219+ return true;
220220}
221221
222222void displayio_display_bus_collect_ptrs (displayio_display_bus_t * self ) {
0 commit comments