Skip to content

Commit

Permalink
Config: Quiesce display before Flash update. Avoids corruption.
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Oct 9, 2019
1 parent d91fbf9 commit e93f91b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 3 additions & 0 deletions inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ int printk(const char *format, ...)
#define htobe16(x) _rev16(x)
#define htobe32(x) _rev32(x)

/* Display control */
void display_off(void);

/* Amiga keyboard */
#define AMI_RETURN 0x44
#define AMI_F(x) (0x4f+(x))
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void config_process(uint8_t b)
if (b & B_SELECT) {
if (++config_state >= C_max) {
config_state = C_idle;
display_off();
switch (new_config) {
case C_SAVE:
config_write_flash(&config);
Expand Down
12 changes: 8 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ static void IRQ_csync(void)

/* Short sync: We are outside the vblank period. Start frame (we
* were previously in vblank). */
if (display_height == 0)
goto eof;
hline = HLINE_SOF;
slave_arr_update();
set_polarity();
Expand All @@ -257,7 +255,6 @@ static void IRQ_csync(void)

} else if (hline >= (config.v_off + display_height)) {

eof:
/* Vertical end of OSD: Disable TIM1 trigger and signal main loop. */
tim1->smcr = 0;
hline = HLINE_EOF;
Expand Down Expand Up @@ -521,10 +518,17 @@ static void emulate_gotek_buttons(void)
*(volatile uint8_t *)&i2c_osd_info.buttons = b;
}

static struct display no_display;
/* Called before erasing Flash, to temporarily disable the display.
* Flash updates can stall instruction fetch and mess up the OSD. */
void display_off(void)
{
display_height = 0; /* Display off */
delay_us(500); /* Wait for a few hlines (we only really need one) */
}

int main(void)
{
static struct display no_display;
int i;
time_t frame_time;
bool_t lost_sync, _keyboard_held;
Expand Down

0 comments on commit e93f91b

Please sign in to comment.