commit a32a7e2377b9fb8ac691edd27deb028f528825af Author: Shino Amakusa Date: Tue Jun 7 20:21:28 2016 +0200 Wrote Basic construct diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc7c253 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.user +*.user* +Makefile +*~ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..03055ca --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +project(stm32flash) +cmake_minimum_required(VERSION 2.8) +find_package(PkgConfig REQUIRED) +pkg_check_modules(GTK3 REQUIRED gtk+-3.0) + +aux_source_directory(. SRC_LIST) +# GTK3 Dependencies +include_directories(${GTK3_INCLUDE_DIRS}) +link_directories(${GTK3_LIBRARY_DIRS}) +add_definitions(${GTK3_CFLAGS_OTHER}) + +add_executable(${PROJECT_NAME} ${SRC_LIST}) +# Add GTK Libraries to Linking list +# Add lib pthread +target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} pthread) diff --git a/main.c b/main.c new file mode 100644 index 0000000..e52ae02 --- /dev/null +++ b/main.c @@ -0,0 +1,164 @@ +/* + * Description: STM32 Microcontroller flashing utility + * Author: Mario Hüttel + * + * Version: 0.1 + * License: -- + * + * + */ +#include +#include +#include +#include +#include + +#define ISOPT(var) (!strcmp(argv[i], var)) +#define GETOPT(var) if (++i < argc) strcpy(var, argv[i]) +#define MAXPARAMLENGTH 100 + +enum ValueAvail {hasNoVal, hasVal}; + + +typedef struct _parameter { + char *name; + enum ValueAvail hasValue; + void *value; +} parameter; + +typedef struct _builderWidget { + char *widgetId; + GtkWidget **widget; +}builderWidget; + +typedef struct _flasher { + GtkWidget **progressBar; + GtkWidget **fileEntry; + GtkWidget **portEntry; +}flasher; + +void parseParams(parameter *progParams, int argc, char **argv); +void parseBuilder(GtkBuilder *builder, builderWidget *builderWidgets); +void startFlash(); + +int main(int argc, char *argv[]) { + + static int gui = 0; + static char port[MAXPARAMLENGTH] = {0}; + static char fileName[MAXPARAMLENGTH] = {0}; + static GtkWidget *startButton; + static GtkWidget *fileDialogButton; + static GtkWidget *fileEntry; + static GtkWidget *portEntry; + static GtkWidget *progressBar; + static GtkWidget *fileDialog; + static flasher stmFlasher; + + static parameter progParams[] = { + { + .name = "--gui", + .hasValue = hasNoVal, + .value = (void*)&gui + }, + { + .name = "--port", + .hasValue = hasVal, + .value = (void*)port + }, + { + .name = "--file", + .hasValue = hasVal, + .value = (void*)fileName + }, + {.name = NULL} + }; + static builderWidget builderWidgets[] = { + { + .widgetId = "startButton", + .widget = &startButton + }, + { + .widgetId = "fileDialogButton", + .widget = &fileDialogButton + }, + { + .widgetId = "fileEntry", + .widget = &fileEntry + }, + { + .widgetId = "portEntry", + .widget = &portEntry + }, + { + .widgetId = "progressBar", + .widget = &progressBar + }, + { + .widgetId = "Dialog", + .widget = &fileDialog + }, + { + .widgetId = NULL, + .widget = NULL + } + }; + + GtkBuilder *builder; + + + parseParams(progParams, argc, argv); + // Create flasher and fill elements + stmFlasher.fileEntry = &fileEntry; + stmFlasher.portEntry = &portEntry; + // TODO: above + + if (gui) { + gtk_init(&argc, &argv); + builder = gtk_builder_new(); + gtk_builder_add_from_file(builder, "window.glade", NULL); + + //Get Widgets from Builder + parseBuilder(builder, builderWidgets); + g_signal_connect(startButton, "clicked", G_CALLBACK(startFlash), &stmFlasher); + gtk_main(); + } else { + startFlash(&stmFlasher); + } + + return 0; + +} + + +void startFlash(flasher *flashObj) { + return; +} + + +void parseParams(parameter* progParams, int argc, char **argv) +{ + int i = 0; + parameter* paramptr = NULL; + for (i = 0; i < argc; i++) { + for (paramptr = progParams; paramptr->name; paramptr++) { + if (paramptr->hasValue == hasNoVal) *(int*)paramptr->value = 0; + + if (ISOPT(paramptr->name)) + { + if (paramptr->hasValue == hasNoVal) { + *(int*)paramptr->value = 1; + } else { + printf("setting\n"); + GETOPT((char*)paramptr->value); + } + } + } + } +} + +void parseBuilder(GtkBuilder *builder, builderWidget *builderWidgets) { + builderWidget *ptr = NULL; + for (ptr = builderWidgets; ptr->widgetId;ptr++) { + *(ptr->widget) = GTK_WIDGET(gtk_builder_get_object(builder, (gchar*)ptr->widgetId)); + } +} diff --git a/window.glade b/window.glade new file mode 100644 index 0000000..5139f38 --- /dev/null +++ b/window.glade @@ -0,0 +1,140 @@ + + + + + + False + dialog + + + False + vertical + 2 + + + False + end + + + + + + + + + False + False + 0 + + + + + + + + + + False + + + True + False + vertical + + + True + False + + + True + True + + + True + True + 0 + + + + + ... + True + True + True + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + + + True + False + Serial Port + + + False + True + 0 + + + + + True + True + 1 + + + True + True + 1 + + + + + False + False + 1 + + + + + Start Flashing + True + True + True + + + True + True + 2 + + + + + True + False + + + False + True + 3 + + + + + +