@@ -85,11 +85,16 @@ void displayio_display_bus_construct(displayio_display_bus_t *self,
8585 self -> bus = bus ;
8686}
8787
88+ // This is just a hint, and is not a reliable result, since the bus could be grabbed in between this called
89+ // and the attempt to use the bus. Use displayio_display_bus_begin_transaction(), which is atomic.
8890bool displayio_display_bus_is_free (displayio_display_bus_t * self ) {
8991 return !self -> bus || self -> bus_free (self -> bus );
9092}
9193
92- bool displayio_display_bus_begin_transaction (displayio_display_bus_t * self ) {
94+ MP_WARN_UNUSED_RESULT bool displayio_display_bus_begin_transaction (displayio_display_bus_t * self ) {
95+ if (!self -> bus ) {
96+ return false;
97+ }
9398 mp_obj_base_t * bus_base = MP_OBJ_TO_PTR (self -> bus );
9499 if (bus_base -> type == & mp_type_NoneType ) {
95100 return false;
@@ -128,7 +133,9 @@ void displayio_display_bus_set_region_to_update(displayio_display_bus_t *self, d
128133 }
129134
130135 // Set column.
131- displayio_display_bus_begin_transaction (self );
136+ if (!displayio_display_bus_begin_transaction (self )) {
137+ return ;
138+ }
132139 uint8_t data [5 ];
133140 data [0 ] = self -> column_command ;
134141 uint8_t data_length = 1 ;
@@ -167,7 +174,9 @@ void displayio_display_bus_set_region_to_update(displayio_display_bus_t *self, d
167174
168175 if (self -> set_current_column_command != NO_COMMAND ) {
169176 uint8_t command = self -> set_current_column_command ;
170- displayio_display_bus_begin_transaction (self );
177+ if (!displayio_display_bus_begin_transaction (self )) {
178+ return ;
179+ }
171180 self -> send (self -> bus , DISPLAY_COMMAND , chip_select , & command , 1 );
172181 // Only send the first half of data because it is the first coordinate.
173182 self -> send (self -> bus , DISPLAY_DATA , chip_select , data , data_length / 2 );
@@ -176,7 +185,9 @@ void displayio_display_bus_set_region_to_update(displayio_display_bus_t *self, d
176185
177186
178187 // Set row.
179- displayio_display_bus_begin_transaction (self );
188+ if (!displayio_display_bus_begin_transaction (self )) {
189+ return ;
190+ }
180191 data [0 ] = self -> row_command ;
181192 data_length = 1 ;
182193 if (!self -> data_as_commands ) {
@@ -211,7 +222,9 @@ void displayio_display_bus_set_region_to_update(displayio_display_bus_t *self, d
211222
212223 if (self -> set_current_row_command != NO_COMMAND ) {
213224 uint8_t command = self -> set_current_row_command ;
214- displayio_display_bus_begin_transaction (self );
225+ if (!displayio_display_bus_begin_transaction (self )) {
226+ return ;
227+ }
215228 self -> send (self -> bus , DISPLAY_COMMAND , chip_select , & command , 1 );
216229 // Only send the first half of data because it is the first coordinate.
217230 self -> send (self -> bus , DISPLAY_DATA , chip_select , data , data_length / 2 );
0 commit comments