Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 54 additions & 6 deletions src/stlink-gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ static void stlink_gui_set_sensitivity(STlinkGUI *gui, gboolean sensitivity) {
gtk_widget_set_sensitive(GTK_WIDGET(gui->reset_button), sensitivity && (gui->sl != NULL));

gtk_widget_set_sensitive(GTK_WIDGET(gui->export_button), sensitivity && (gui->sl != NULL));

gtk_widget_set_sensitive(GTK_WIDGET(gui->erase_button), sensitivity && (gui->sl != NULL));
}

static void mem_view_init_headers(GtkTreeView *view) {
Expand Down Expand Up @@ -531,11 +533,12 @@ static void stlink_gui_set_disconnected(STlinkGUI *gui) {
gtk_statusbar_push(gui->statusbar, gtk_statusbar_get_context_id(gui->statusbar, "conn"), "Disconnected");

gtk_widget_set_sensitive(GTK_WIDGET(gui->device_frame), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->flash_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->export_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->disconnect_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->connect_button), TRUE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->disconnect_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->flash_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->reset_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->export_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(gui->erase_button), FALSE);
}

static void disconnect_button_cb(GtkWidget *widget, gpointer data) {
Expand Down Expand Up @@ -614,7 +617,7 @@ static void open_button_cb(GtkWidget *widget, gpointer data) {
stlink_gui_open_file(gui);
}

static gboolean stlink_gui_write_flash_update(STlinkGUI *gui) {
static gboolean stlink_gui_restore_after_background_thread(STlinkGUI *gui) {
stlink_gui_set_sensitivity(gui, TRUE);
gui->progress.activity_mode = FALSE;
gtk_widget_hide(GTK_WIDGET(gui->progress.bar));
Expand All @@ -634,7 +637,7 @@ static gpointer stlink_gui_write_flash(gpointer data) {
stlink_gui_set_info_error_message(gui, "Failed to write to flash");
}

g_idle_add((GSourceFunc)stlink_gui_write_flash_update, gui);
g_idle_add((GSourceFunc)stlink_gui_restore_after_background_thread, gui);
return (NULL);
}

Expand Down Expand Up @@ -738,6 +741,42 @@ static void export_button_cb(GtkWidget *widget, gpointer data) {
gtk_widget_destroy(dialog);
}

static gpointer stlink_gui_erase_flash(gpointer data) {
g_return_val_if_fail(STLINK_IS_GUI(data), NULL);
STlinkGUI *gui = STLINK_GUI(data);

g_return_val_if_fail((gui->sl != NULL), NULL);

if(stlink_erase_flash_mass(gui->sl) < 0) {
stlink_gui_set_info_error_message(gui, "Failed to mass erase flash");
} else {
stlink_gui_set_info_error_message(gui, "Mass erased flash");
}

g_idle_add((GSourceFunc)stlink_gui_restore_after_background_thread, gui);
return (NULL);
}

static void erase_button_cb(GtkWidget *widget, gpointer data) {
(void)widget;
STlinkGUI *gui;
gint result;

gui = STLINK_GUI(data);
g_return_if_fail(gui->sl != NULL);

result = gtk_dialog_run(gui->erase_dialog);

if(result == GTK_RESPONSE_OK) {
stlink_gui_set_sensitivity(gui, FALSE);
gtk_progress_bar_set_text(gui->progress.bar, "Mass erasing flash");
gui->progress.activity_mode = TRUE;
gtk_widget_show(GTK_WIDGET(gui->progress.bar));

g_thread_new("erase_flash", (GThreadFunc)stlink_gui_erase_flash, gui);
}
}

static gboolean progress_pulse_timeout(STlinkGUI *gui) {
if(gui->progress.activity_mode) {
gtk_progress_bar_pulse(gui->progress.bar);
Expand Down Expand Up @@ -872,6 +911,9 @@ static void stlink_gui_build_ui(STlinkGUI *gui) {
gui->export_button = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "export_button"));
g_signal_connect(G_OBJECT(gui->export_button), "clicked", G_CALLBACK(export_button_cb), gui);

gui->erase_button = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "erase_button"));
g_signal_connect(G_OBJECT(gui->erase_button), "clicked", G_CALLBACK(erase_button_cb), gui);

gui->devmem_treeview = GTK_TREE_VIEW(gtk_builder_get_object(builder, "devmem_treeview"));
mem_view_init_headers(gui->devmem_treeview);
devmem_store = gtk_list_store_new(5,
Expand Down Expand Up @@ -932,6 +974,12 @@ static void stlink_gui_build_ui(STlinkGUI *gui) {
gui->flash_dialog_cancel = GTK_BUTTON(gtk_builder_get_object(builder, "flash_dialog_cancel_button"));
gui->flash_dialog_entry = GTK_ENTRY(gtk_builder_get_object(builder, "flash_dialog_entry"));

/* Erase dialog */
gui->erase_dialog = GTK_DIALOG(gtk_builder_get_object(builder, "erase_dialog"));
g_signal_connect_swapped(gui->erase_dialog, "response", G_CALLBACK(gtk_widget_hide), gui->erase_dialog);
gui->erase_dialog_ok = GTK_BUTTON(gtk_builder_get_object(builder, "erase_dialog_ok_button"));
gui->erase_dialog_cancel = GTK_BUTTON(gtk_builder_get_object(builder, "erase_dialog_cancel_button"));

// make it so
gtk_widget_show_all(GTK_WIDGET(gui->window));
gtk_widget_hide(GTK_WIDGET(gui->infobar));
Expand Down Expand Up @@ -964,7 +1012,7 @@ int32_t main(int32_t argc, char **argv) {
}
if(argc == 1 && g_file_test(*argv, G_FILE_TEST_IS_REGULAR)){
/* Open hex file at app startup */
gui->filename = g_strdup(*argv);
gui->filename = g_strdup(*argv);
g_idle_add((GSourceFunc)open_file_from_args, gui);
}
argc--;
Expand Down
12 changes: 9 additions & 3 deletions src/stlink-gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,25 @@ struct _STlinkGUI {
GtkEntry *devmem_jmp_entry;
GtkBox *filemem_box;
GtkEntry *filemem_jmp_entry;
GtkToolButton *open_button;
GtkToolButton *connect_button;
GtkToolButton *disconnect_button;
GtkToolButton *flash_button;
GtkToolButton *export_button;
GtkToolButton *open_button;
GtkToolButton *reset_button;
GtkToolButton *export_button;
GtkToolButton *erase_button;

/* flash dialog */
/* Flash dialog */
GtkDialog *flash_dialog;
GtkButton *flash_dialog_ok;
GtkButton *flash_dialog_cancel;
GtkEntry *flash_dialog_entry;

/* Erase dialog */
GtkDialog *erase_dialog;
GtkButton *erase_dialog_ok;
GtkButton *erase_dialog_cancel;

struct progress_t progress;
struct mem_t flash_mem;
struct mem_t file_mem;
Expand Down
102 changes: 102 additions & 0 deletions src/stlink-gui/stlink-gui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,94 @@
<action-widget response="-5">flash_dialog_ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="erase_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Mass erase flash</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="erase_dialog-vbox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="erase_dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="erase_dialog_cancel_button">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="erase_dialog_ok_button">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="erase_dialog_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="column_spacing">5</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkLabel" id="erase_dialog_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">This will permanently delete all code and data on the chip. This action cannot be undone.</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">erase_dialog_cancel_button</action-widget>
<action-widget response="-5">erase_dialog_ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="title" translatable="yes">STlink GUI</property>
Expand Down Expand Up @@ -203,6 +291,20 @@
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="erase_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Erase device memory</property>
<property name="label" translatable="yes">Erase device memory</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-delete</property>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolItem" id="toolProgressbar">
<property name="visible">True</property>
Expand Down
Loading