Skip to content

Commit

Permalink
FF OSD: Support Configuration via Gotek
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed Sep 25, 2019
1 parent 9e1c264 commit b58070e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 2 additions & 0 deletions inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ void lcd_write(int col, int row, int min, const char *str);
void lcd_backlight(bool_t on);
void lcd_sync(void);
extern uint8_t lcd_columns, lcd_rows;
extern bool_t ff_osd;
extern uint8_t ff_osd_buttons;

/* USB stack processing */
void usbh_msc_init(void);
Expand Down
6 changes: 5 additions & 1 deletion src/display/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#define OSD_DATA 0x02 /* next columns*rows bytes are text data */
#define OSD_ROWS 0x10 /* [3:0] = #rows */
#define OSD_HEIGHTS 0x20 /* [3:0] = 1 iff row is 2x height */
#define OSD_BUTTONS 0x30 /* [3:0] = button mask */
#define OSD_COLUMNS 0x40 /* [6:0] = #columns */

/* STM32 I2C peripheral. */
Expand All @@ -53,7 +54,9 @@ void IRQ_33(void) __attribute__((alias("IRQ_i2c_event")));
#define DMA1_CH4_IRQ 14
void IRQ_14(void) __attribute__((alias("IRQ_dma1_ch4_tc")));

static bool_t ff_osd, in_osd;
bool_t ff_osd;
uint8_t ff_osd_buttons;
static bool_t in_osd;
#define OSD_I2C_ADDR 0x10

static uint8_t _bl;
Expand Down Expand Up @@ -179,6 +182,7 @@ static unsigned int osd_prep_buffer(void)
*q++ = OSD_COLUMNS | lcd_columns;
*q++ = OSD_ROWS | 3;
*q++ = OSD_HEIGHTS | (menu_mode ? 4 : 2);
*q++ = OSD_BUTTONS | ff_osd_buttons;
*q++ = OSD_DATA;
for (row = 0; row < 3; row++) {
p = text[(order >> (row * DORD_shift)) & DORD_row];
Expand Down
44 changes: 43 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ static bool_t confirm(const char *op)
snprintf(msg, sizeof(msg), "Confirm %s?", op);
lcd_write(0, 1, -1, msg);

while ((b = buttons) == 0)
while ((b = menu_wait_button(TRUE, "")) == 0)
continue;

return (b == B_SELECT);
Expand Down Expand Up @@ -2116,6 +2116,38 @@ static bool_t image_delete(void)
return ok;
}

static void ff_osd_configure(void)
{
if (!ff_osd || !confirm("OSD Cnf"))
return;

lcd_clear();
lcd_write(0, 0, -1, "Exit: Power Off");
lcd_write(0, 1, -1, "or Eject USB/SD");

for (;;) {
time_t t = time_now();
uint8_t b = buttons;
if (b == (B_LEFT|B_RIGHT)) {
ff_osd_buttons = B_SELECT;
/* Wait for two-button release. */
while ((time_diff(t, time_now()) < time_ms(1000)) && buttons)
continue;
} else if (b & (B_LEFT|B_RIGHT)) {
/* Wait 50ms for a two-button press. */
while ((b == buttons) && (time_diff(t, time_now()) < time_ms(50)))
continue;
ff_osd_buttons = (buttons == (B_LEFT|B_RIGHT)) ? B_SELECT : b;
} else {
ff_osd_buttons = b;
}
/* Hold button-held state for a while to make sure it gets
* transferred to the OSD. */
if (ff_osd_buttons)
delay_ms(100);
}
}

static uint8_t noinline eject_menu(uint8_t b)
{
const static char *menu[] = {
Expand All @@ -2125,15 +2157,21 @@ static uint8_t noinline eject_menu(uint8_t b)
"Delete Image",
"Exit to Selector",
"Exit & Re-Insert",
"Configure FF OSD",
};

int nr_opts = ARRAY_SIZE(menu);
char msg[17];
unsigned int wait;
int sel = 0;
bool_t twobutton_eject =
((ff_cfg.twobutton_action & TWOBUTTON_mask) == TWOBUTTON_eject)
|| (display_mode == DM_LCD_OLED); /* or two buttons can't exit menu */

/* Only allow FF OSD configuration if we have OSD attached. */
if (!ff_osd)
nr_opts--;

menu_mode = TRUE;

ima_mark_ejected(TRUE);
Expand Down Expand Up @@ -2231,6 +2269,9 @@ static uint8_t noinline eject_menu(uint8_t b)
case 0: case 5: /* Exit & Re-Insert */
b = 0;
goto out;
case 6:
ff_osd_configure();
break;
}
}

Expand Down Expand Up @@ -2648,6 +2689,7 @@ int main(void)
usbh_msc_buffer_set((void *)0xdeadbeef);

fres = F_call_cancellable(floppy_main, NULL);
ff_osd_buttons = 0;
floppy_cancel();
floppy_arena_teardown();

Expand Down

0 comments on commit b58070e

Please sign in to comment.