Skip to content

Commit 3c53ce0

Browse files
author
ReclaimerLabs
committed
fixed screen-tearing bug
if the user button was pushed while another thread was trying to update the screen, screen tearing could occur. Now the interrupt only notes that a change is needed, and the change is down in the main loop.
1 parent 247b642 commit 3c53ce0

File tree

1 file changed

+16
-15
lines changed
  • firmware/USB-C Explorer/USB-C Explorer

1 file changed

+16
-15
lines changed

firmware/USB-C Explorer/USB-C Explorer/main.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
7777
};
7878
// USB-C Specific - TCPM end 1
7979

80-
uint8_t display_screen, display_screen_last, display_needs_update;
80+
volatile uint8_t display_screen, display_needs_update, display_change_requested;
8181
uint8_t display_buffer[MAX_SCREENS][DISP_MEM_SIZE];
8282
UG_GUI gui;
8383
timestamp_t last_button_timestamp;
@@ -233,11 +233,20 @@ int main(void)
233233

234234
pd_run_state_machine(0);
235235

236-
if (display_screen != display_screen_last)
236+
if (display_change_requested)
237237
{
238-
ssd1306_write_data_n(display_buffer[display_screen], DISP_MEM_SIZE);
239-
display_screen_last = display_screen;
238+
if (display_screen >= (MAX_SCREENS - 1))
239+
{
240+
display_screen = 0;
241+
}
242+
else
243+
{
244+
display_screen++;
245+
}
246+
display_change_requested = 0;
247+
display_needs_update = 1;
240248
}
249+
241250
if (display_needs_update)
242251
{
243252
ssd1306_write_data_n(display_buffer[display_screen], DISP_MEM_SIZE);
@@ -290,11 +299,10 @@ void display_init(void)
290299
sprintf(str, "No Alt Mode");
291300
UG_PutString(0, 8, str);
292301
display_screen = SCREEN_POWER;
293-
display_needs_update = 1;
294302

303+
display_needs_update = 1;
295304
display_screen = 0;
296-
display_screen_last = 0;
297-
display_needs_update = 0;
305+
display_change_requested = 0;
298306
struct extint_chan_conf config_extint_chan;
299307
extint_chan_get_config_defaults(&config_extint_chan);
300308
config_extint_chan.gpio_pin = SW_USER_EIC_PIN;
@@ -327,14 +335,7 @@ void extint_detection_callback(void)
327335
{
328336
if (port_pin_get_input_level(SW_USER_EIC_PIN) == false)
329337
{
330-
if (display_screen >= (MAX_SCREENS - 1))
331-
{
332-
display_screen = 0;
333-
}
334-
else
335-
{
336-
display_screen++;
337-
}
338+
display_change_requested = 1;
338339
}
339340
}
340341
}

0 commit comments

Comments
 (0)