diff --git a/include/gfx.h b/include/gfx.h index 3a10103f..d261a6ce 100644 --- a/include/gfx.h +++ b/include/gfx.h @@ -204,8 +204,15 @@ extern "C" { */ void gfxInit(void); - /* Compatibility for old programs */ - void DEPRECATED("Use gfxInit() instead") gdispInit(void); + /** + * @brief The one call to end it all + * + * @note This will deinitialise each sub-system that has been turned on. + * @note Do not call this without a previous @p gfxInit(); + * + * @api + */ + void gfxDeinit(void); #ifdef __cplusplus } diff --git a/src/gadc/gadc.c b/src/gadc/gadc.c index e297ef7e..bfa655df 100644 --- a/src/gadc/gadc.c +++ b/src/gadc/gadc.c @@ -236,7 +236,8 @@ void GADC_ISR_ErrorI(ADCDriver *adcp, adcerror_t err) { } /* Our module initialiser */ -void _gadcInit(void) { +void _gadcInit(void) +{ gadc_lld_init(); gfxSemInit(&gadcsem, GADC_MAX_LOWSPEED_DEVICES, GADC_MAX_LOWSPEED_DEVICES); gfxMutexInit(&gadcmutex); @@ -246,6 +247,11 @@ void _gadcInit(void) { #endif } +void _gadcDeinit(void) +{ + /* ToDo */ +} + static inline void StartADC(bool_t onNoHS) { gfxSystemLock(); if (!(gflags & GADC_GFLG_ISACTIVE) || (onNoHS && !curlsdev)) diff --git a/src/gaudin/gaudin.c b/src/gaudin/gaudin.c index a6e173ce..2f0883e7 100644 --- a/src/gaudin/gaudin.c +++ b/src/gaudin/gaudin.c @@ -85,13 +85,18 @@ void GAUDIN_ISR_ErrorI(void) { /* Ignore any errors for now */ } -/* The module initialiser */ -void _gaudinInit(void) { +void _gaudinInit(void) +{ #if GFX_USE_GEVENT gtimerInit(&AudGTimer); #endif } +void _gaudinDeinit(void) +{ + /* ToDo */ +} + bool_t gaudinInit(uint16_t channel, uint32_t frequency, audin_sample_t *buffer, size_t bufcount, size_t samplesPerEvent) { /* Check the channel is valid */ if (channel >= GAUDIN_NUM_CHANNELS || frequency > GAUDIN_MAX_SAMPLE_FREQUENCY) diff --git a/src/gaudout/gaudout.c b/src/gaudout/gaudout.c index e05fc360..56692453 100644 --- a/src/gaudout/gaudout.c +++ b/src/gaudout/gaudout.c @@ -18,6 +18,16 @@ #error "GAUDOUT: Not implemented yet" +void _gaudoutInit(void) +{ + /* ToDo */ +} + +void _gaudoutDeinit(void) +{ + /* ToDo */ +} + #endif /* GFX_USE_GAUDOUT */ /** @} */ diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 13f2eda2..3031c455 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -566,8 +566,8 @@ static void line_clip(GDisplay *g) { /* Driver exported functions. */ /*===========================================================================*/ -/* Our module initialiser */ -void _gdispInit(void) { +void _gdispInit(void) +{ GDisplay *g; uint16_t i; @@ -627,6 +627,11 @@ void _gdispInit(void) { #endif } +void _gdispDeinit(void) +{ + /* ToDo */ +} + GDisplay *gdispGetDisplay(unsigned display) { if (display >= GDISP_TOTAL_DISPLAYS) return 0; diff --git a/src/gevent/gevent.c b/src/gevent/gevent.c index 6681fb53..67b32747 100644 --- a/src/gevent/gevent.c +++ b/src/gevent/gevent.c @@ -46,10 +46,16 @@ static void deleteAssignments(GListener *pl, GSourceHandle gsh) { } } -void _geventInit(void) { +void _geventInit(void) +{ gfxMutexInit(&geventMutex); } +void _geventDeinit(void) +{ + /* ToDo */ +} + void geventListenerInit(GListener *pl) { gfxSemInit(&pl->waitqueue, 0, MAX_SEMAPHORE_COUNT); // Next wait'er will block gfxSemInit(&pl->eventlock, 1, 1); // Only one thread at a time looking at the event buffer diff --git a/src/gfx.c b/src/gfx.c index ff7b29cd..46003f09 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -15,47 +15,50 @@ #include "gfx.h" -void DEPRECATED("Use gfxInit() instead") gdispInit() { gfxInit(); } - /* These init functions are defined by each module but not published */ extern void _gosInit(void); +extern void _gosDeinit(void); #if GFX_USE_GDISP extern void _gdispInit(void); + extern void _gdispDeinit(void); #endif #if GFX_USE_GWIN extern void _gwinInit(void); + extern void _gwinDeinit(void); #endif #if GFX_USE_GEVENT extern void _geventInit(void); + extern void _geventDeinit(void); #endif #if GFX_USE_GTIMER extern void _gtimerInit(void); + extern void _gtimerDeinit(void); #endif #if GFX_USE_GINPUT extern void _ginputInit(void); + extern void _ginputDeinit(void); #endif #if GFX_USE_GADC extern void _gadcInit(void); + extern void _gadcDeinit(void); #endif #if GFX_USE_GAUDIN extern void _gaudinInit(void); + extern void _gaudinDeinit(void); #endif #if GFX_USE_GAUDOUT extern void _gaudoutInit(void); + extern void _gaudoutDeinit(void); #endif #if GFX_USE_GMISC extern void _gmiscInit(void); + extern void _gmiscDeinit(void); #endif -void gfxInit(void) { - static bool_t initDone = FALSE; +void gfxInit(void) +{ + // These must be initialised in the order of their dependancies - /* Ensure we only initialise once */ - if (initDone) - return; - initDone = TRUE; - - /* These must be initialised in the order of their dependancies */ _gosInit(); #if GFX_USE_GMISC _gmiscInit(); @@ -85,3 +88,38 @@ void gfxInit(void) { _gaudoutInit(); #endif } + +void gfxDeinit(void) +{ + // We deinitialise the opposit way as we initialised + + #if GFX_USE_GAUDOUT + _gaudoutDeinit(); + #endif + #if GFX_USE_GAUDIN + _gaoudinDeinit(); + #endif + #if GFX_USE_GADC + _gadcDeinit(); + #endif + #if GFX_USE_GINPUT + _ginputDeinit(); + #endif + #if GFX_USE_GWIN + _gwinDeinit(); + #endif + #if GFX_USE_GDISP + _gdispDeinit(); + #endif + #if GFX_USE_GTIMER + _gtimerDeinit(); + #endif + #if GFX_USE_GEVENT + _geventDeinit(); + #endif + #if GFX_USE_GMISC + _gmiscInit(); + #endif + _gosDeinit(); +} + diff --git a/src/ginput/ginput.c b/src/ginput/ginput.c index 87c4a668..abd16cd8 100644 --- a/src/ginput/ginput.c +++ b/src/ginput/ginput.c @@ -16,11 +16,21 @@ #if GFX_USE_GINPUT -/** - * This should really call an init routine for each ginput sub-system. - * Maybe we'll do this later. - */ -void _ginputInit(void) {} +void _ginputInit(void) +{ + /* ToDo */ + + /** + * This should really call an init routine for each ginput sub-system. + * Maybe we'll do this later. + */ +} + +void _ginputDeinit(void) +{ + +} #endif /* GFX_USE_GINPUT */ /** @} */ + diff --git a/src/gmisc/gmisc.c b/src/gmisc/gmisc.c index 38da6bfa..654dd5e2 100644 --- a/src/gmisc/gmisc.c +++ b/src/gmisc/gmisc.c @@ -14,7 +14,14 @@ #if GFX_USE_GMISC -void _gmiscInit(void) { +void _gmiscInit(void) +{ + +} + +void _gmiscDeinit(void) +{ + } #endif /* GFX_USE_GMISC */ diff --git a/src/gos/chibios.c b/src/gos/chibios.c index 30a2b228..cf02b3e2 100644 --- a/src/gos/chibios.c +++ b/src/gos/chibios.c @@ -22,8 +22,8 @@ #error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h" #endif -/* Our module initialiser */ -void _gosInit(void) { +void _gosInit(void) +{ /* Don't initialise if the user already has */ if (!chThdSelf()) { halInit(); @@ -31,6 +31,11 @@ void _gosInit(void) { } } +void _gosDeinit(void) +{ + /* ToDo */ +} + void *gfxRealloc(void *ptr, size_t oldsz, size_t newsz) { void *np; diff --git a/src/gos/linux.c b/src/gos/linux.c index 97409364..9b4914d5 100644 --- a/src/gos/linux.c +++ b/src/gos/linux.c @@ -20,10 +20,16 @@ static gfxMutex SystemMutex; -void _gosInit(void) { +void _gosInit(void) +{ gfxMutexInit(&SystemMutex); } +void _gosDeinit(void) +{ + /* ToDo */ +} + void gfxSystemLock(void) { gfxMutexEnter(&SystemMutex); } diff --git a/src/gos/osx.c b/src/gos/osx.c index a5560b4e..249147d1 100644 --- a/src/gos/osx.c +++ b/src/gos/osx.c @@ -37,10 +37,16 @@ void get_ticks(mach_timespec_t *mts){ } -void _gosInit(void) { +void _gosInit(void) +{ gfxMutexInit(&SystemMutex); } +void _gosDeinit(void) +{ + /* ToDo */ +} + void gfxSystemLock(void) { gfxMutexEnter(&SystemMutex); } diff --git a/src/gos/raw32.c b/src/gos/raw32.c index 5e11064c..61d09761 100644 --- a/src/gos/raw32.c +++ b/src/gos/raw32.c @@ -26,7 +26,8 @@ static void _gosThreadsInit(void); * Initialise *********************************************************/ -void _gosInit(void) { +void _gosInit(void) +{ // Set up the heap allocator _gosHeapInit(); @@ -34,6 +35,11 @@ void _gosInit(void) { _gosThreadsInit(); } +void _gosDeinit(void) +{ + /* ToDo */ +} + /********************************************************* * For WIn32 emulation - automatically add the tick functions * the user would normally have to provide for bare metal. diff --git a/src/gos/win32.c b/src/gos/win32.c index a05e5c30..3a3f2517 100644 --- a/src/gos/win32.c +++ b/src/gos/win32.c @@ -17,7 +17,13 @@ static HANDLE SystemMutex; -void _gosInit(void) { +void _gosInit(void) +{ + +} + +void _gosDeinit(void) +{ } diff --git a/src/gtimer/gtimer.c b/src/gtimer/gtimer.c index de40e16c..b8f3d4fa 100644 --- a/src/gtimer/gtimer.c +++ b/src/gtimer/gtimer.c @@ -118,11 +118,17 @@ static DECLARE_THREAD_FUNCTION(GTimerThreadHandler, arg) { return 0; } -void _gtimerInit(void) { +void _gtimerInit(void) +{ gfxSemInit(&waitsem, 0, 1); gfxMutexInit(&mutex); } +void _gtimerDeinit(void) +{ + /* ToDo */ +} + void gtimerInit(GTimer *pt) { pt->flags = 0; } diff --git a/src/gwin/gwidget.c b/src/gwin/gwidget.c index 484b8c37..75a69667 100644 --- a/src/gwin/gwidget.c +++ b/src/gwin/gwidget.c @@ -224,11 +224,17 @@ static void gwidgetEvent(void *param, GEvent *pe) { } #endif -void _gwidgetInit(void) { +void _gwidgetInit(void) +{ geventListenerInit(&gl); geventRegisterCallback(&gl, gwidgetEvent, 0); } +void _gwidgetDeinit(void) +{ + /* ToDo */ +} + GHandle _gwidgetCreate(GDisplay *g, GWidgetObject *pgw, const GWidgetInit *pInit, const gwidgetVMT *vmt) { if (!(pgw = (GWidgetObject *)_gwindowCreate(g, &pgw->g, &pInit->g, &vmt->g, GWIN_FLG_WIDGET|GWIN_FLG_ENABLED))) return 0; diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 94799482..485ccaaa 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -84,7 +84,8 @@ static color_t defaultBgColor = Black; * Class Routines *-----------------------------------------------*/ -void _gwinInit(void) { +void _gwinInit(void) +{ #if GWIN_NEED_WIDGET extern void _gwidgetInit(void); @@ -97,6 +98,20 @@ void _gwinInit(void) { #endif } +void _gwinDeinit(void) +{ + #if GWIN_NEED_WIDGET + extern void _gwidgetDeinit(void); + + _gwidgetDeinit(); + #endif + #if GWIN_NEED_WINDOWMANAGER + extern void _gwmDeinit(void); + + _gwmDeinit(); + #endif +} + // Internal routine for use by GWIN components only // Initialise a window creating it dynamically if required. GHandle _gwindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit, const gwinVMT *vmt, uint16_t flags) { diff --git a/src/gwin/gwm.c b/src/gwin/gwm.c index f4dd8090..e7a71737 100644 --- a/src/gwin/gwm.c +++ b/src/gwin/gwm.c @@ -60,7 +60,8 @@ GWindowManager * _GWINwm; * Window Routines *-----------------------------------------------*/ -void _gwmInit(void) { +void _gwmInit(void) +{ gfxQueueASyncInit(&_GWINList); _GWINwm = (GWindowManager *)&GNullWindowManager; _GWINwm->vmt->Init(); @@ -70,6 +71,11 @@ void _gwmInit(void) { #endif } +void _gwmDeinit(void) +{ + /* ToDo */ +} + void gwinSetWindowManager(struct GWindowManager *gwm) { if (!gwm) gwm = (GWindowManager *)&GNullWindowManager;