Wrote Basic construct
This commit is contained in:
		
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | *.user | ||||||
|  | *.user* | ||||||
|  | Makefile | ||||||
|  | *~ | ||||||
							
								
								
									
										15
									
								
								CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -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) | ||||||
							
								
								
									
										164
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								main.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,164 @@ | |||||||
|  | /* | ||||||
|  |  * Description:     STM32 Microcontroller flashing utility | ||||||
|  |  * Author:          Mario Hüttel | ||||||
|  |  * | ||||||
|  |  * Version:         0.1 | ||||||
|  |  * License:         -- | ||||||
|  |  * | ||||||
|  |  * | ||||||
|  |  */ | ||||||
|  | #include <stdio.h> | ||||||
|  | #include <gtk/gtk.h> | ||||||
|  | #include <string.h> | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <pthread.h> | ||||||
|  |  | ||||||
|  | #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)); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										140
									
								
								window.glade
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								window.glade
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,140 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <!-- Generated with glade 3.20.0 --> | ||||||
|  | <interface> | ||||||
|  |   <requires lib="gtk+" version="3.20"/> | ||||||
|  |   <object class="GtkFileChooserDialog" id="Dialog"> | ||||||
|  |     <property name="can_focus">False</property> | ||||||
|  |     <property name="type_hint">dialog</property> | ||||||
|  |     <child internal-child="vbox"> | ||||||
|  |       <object class="GtkBox" id="fileDialog"> | ||||||
|  |         <property name="can_focus">False</property> | ||||||
|  |         <property name="orientation">vertical</property> | ||||||
|  |         <property name="spacing">2</property> | ||||||
|  |         <child internal-child="action_area"> | ||||||
|  |           <object class="GtkButtonBox"> | ||||||
|  |             <property name="can_focus">False</property> | ||||||
|  |             <property name="layout_style">end</property> | ||||||
|  |             <child> | ||||||
|  |               <placeholder/> | ||||||
|  |             </child> | ||||||
|  |             <child> | ||||||
|  |               <placeholder/> | ||||||
|  |             </child> | ||||||
|  |           </object> | ||||||
|  |           <packing> | ||||||
|  |             <property name="expand">False</property> | ||||||
|  |             <property name="fill">False</property> | ||||||
|  |             <property name="position">0</property> | ||||||
|  |           </packing> | ||||||
|  |         </child> | ||||||
|  |         <child> | ||||||
|  |           <placeholder/> | ||||||
|  |         </child> | ||||||
|  |       </object> | ||||||
|  |     </child> | ||||||
|  |   </object> | ||||||
|  |   <object class="GtkWindow" id="mainWindow"> | ||||||
|  |     <property name="can_focus">False</property> | ||||||
|  |     <child> | ||||||
|  |       <object class="GtkBox"> | ||||||
|  |         <property name="visible">True</property> | ||||||
|  |         <property name="can_focus">False</property> | ||||||
|  |         <property name="orientation">vertical</property> | ||||||
|  |         <child> | ||||||
|  |           <object class="GtkBox"> | ||||||
|  |             <property name="visible">True</property> | ||||||
|  |             <property name="can_focus">False</property> | ||||||
|  |             <child> | ||||||
|  |               <object class="GtkEntry" id="fileEntry"> | ||||||
|  |                 <property name="visible">True</property> | ||||||
|  |                 <property name="can_focus">True</property> | ||||||
|  |               </object> | ||||||
|  |               <packing> | ||||||
|  |                 <property name="expand">True</property> | ||||||
|  |                 <property name="fill">True</property> | ||||||
|  |                 <property name="position">0</property> | ||||||
|  |               </packing> | ||||||
|  |             </child> | ||||||
|  |             <child> | ||||||
|  |               <object class="GtkButton" id="fileDialogButton"> | ||||||
|  |                 <property name="label" translatable="yes">...</property> | ||||||
|  |                 <property name="visible">True</property> | ||||||
|  |                 <property name="can_focus">True</property> | ||||||
|  |                 <property name="receives_default">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="position">0</property> | ||||||
|  |           </packing> | ||||||
|  |         </child> | ||||||
|  |         <child> | ||||||
|  |           <object class="GtkBox"> | ||||||
|  |             <property name="visible">True</property> | ||||||
|  |             <property name="can_focus">False</property> | ||||||
|  |             <child> | ||||||
|  |               <object class="GtkLabel"> | ||||||
|  |                 <property name="visible">True</property> | ||||||
|  |                 <property name="can_focus">False</property> | ||||||
|  |                 <property name="label" translatable="yes">  Serial Port  </property> | ||||||
|  |               </object> | ||||||
|  |               <packing> | ||||||
|  |                 <property name="expand">False</property> | ||||||
|  |                 <property name="fill">True</property> | ||||||
|  |                 <property name="position">0</property> | ||||||
|  |               </packing> | ||||||
|  |             </child> | ||||||
|  |             <child> | ||||||
|  |               <object class="GtkEntry" id="portEntry"> | ||||||
|  |                 <property name="visible">True</property> | ||||||
|  |                 <property name="can_focus">True</property> | ||||||
|  |                 <property name="margin_left">1</property> | ||||||
|  |               </object> | ||||||
|  |               <packing> | ||||||
|  |                 <property name="expand">True</property> | ||||||
|  |                 <property name="fill">True</property> | ||||||
|  |                 <property name="position">1</property> | ||||||
|  |               </packing> | ||||||
|  |             </child> | ||||||
|  |           </object> | ||||||
|  |           <packing> | ||||||
|  |             <property name="expand">False</property> | ||||||
|  |             <property name="fill">False</property> | ||||||
|  |             <property name="position">1</property> | ||||||
|  |           </packing> | ||||||
|  |         </child> | ||||||
|  |         <child> | ||||||
|  |           <object class="GtkButton" id="startButton"> | ||||||
|  |             <property name="label" translatable="yes">Start Flashing</property> | ||||||
|  |             <property name="visible">True</property> | ||||||
|  |             <property name="can_focus">True</property> | ||||||
|  |             <property name="receives_default">True</property> | ||||||
|  |           </object> | ||||||
|  |           <packing> | ||||||
|  |             <property name="expand">True</property> | ||||||
|  |             <property name="fill">True</property> | ||||||
|  |             <property name="position">2</property> | ||||||
|  |           </packing> | ||||||
|  |         </child> | ||||||
|  |         <child> | ||||||
|  |           <object class="GtkLevelBar" id="progressBar"> | ||||||
|  |             <property name="visible">True</property> | ||||||
|  |             <property name="can_focus">False</property> | ||||||
|  |           </object> | ||||||
|  |           <packing> | ||||||
|  |             <property name="expand">False</property> | ||||||
|  |             <property name="fill">True</property> | ||||||
|  |             <property name="position">3</property> | ||||||
|  |           </packing> | ||||||
|  |         </child> | ||||||
|  |       </object> | ||||||
|  |     </child> | ||||||
|  |   </object> | ||||||
|  | </interface> | ||||||
		Reference in New Issue
	
	Block a user