diff options
Diffstat (limited to 'src')
40 files changed, 617 insertions, 222 deletions
diff --git a/src/gadc/gadc_rules.h b/src/gadc/gadc_rules.h index d6c6e5ee..af863765 100644 --- a/src/gadc/gadc_rules.h +++ b/src/gadc/gadc_rules.h @@ -19,14 +19,22 @@ #if GFX_USE_GADC #if !GFX_USE_GTIMER #if GFX_DISPLAY_RULE_WARNINGS - #warning "GADC: GFX_USE_GTIMER is required if GFX_USE_GADC is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GADC: GFX_USE_GTIMER is required if GFX_USE_GADC is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GADC: GFX_USE_GTIMER is required if GFX_USE_GADC is TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GTIMER #define GFX_USE_GTIMER TRUE #endif #if !GFX_USE_GQUEUE || !GQUEUE_NEED_GSYNC || !GQUEUE_NEED_BUFFERS #if GFX_DISPLAY_RULE_WARNINGS - #warning "GADC: GFX_USE_GQUEUE, GQUEUE_NEED_BUFFERS and GQUEUE_NEED_GSYNC are required if GFX_USE_GADC is TRUE. They have been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GADC: GFX_USE_GQUEUE, GQUEUE_NEED_BUFFERS and GQUEUE_NEED_GSYNC are required if GFX_USE_GADC is TRUE. They have been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GADC: GFX_USE_GQUEUE, GQUEUE_NEED_BUFFERS and GQUEUE_NEED_GSYNC are required if GFX_USE_GADC is TRUE. They have been turned on for you.") + #endif #endif #undef GFX_USE_GQUEUE #define GFX_USE_GQUEUE TRUE diff --git a/src/gaudio/gaudio_rules.h b/src/gaudio/gaudio_rules.h index 2dbad17d..7ab587da 100644 --- a/src/gaudio/gaudio_rules.h +++ b/src/gaudio/gaudio_rules.h @@ -22,21 +22,33 @@ #endif #if !GFX_USE_GQUEUE #if GFX_DISPLAY_RULE_WARNINGS - #warning "GAUDIO: GFX_USE_GQUEUE is required if GFX_USE_GAUDIO is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GAUDIO: GFX_USE_GQUEUE is required if GFX_USE_GAUDIO is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GAUDIO: GFX_USE_GQUEUE is required if GFX_USE_GAUDIO is TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GQUEUE #define GFX_USE_GQUEUE TRUE #endif #if GAUDIO_NEED_PLAY && !GQUEUE_NEED_ASYNC #if GFX_DISPLAY_RULE_WARNINGS - #warning "GAUDIO: GQUEUE_NEED_ASYNC is required if GAUDIO_NEED_PLAY is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GAUDIO: GQUEUE_NEED_ASYNC is required if GAUDIO_NEED_PLAY is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GAUDIO: GQUEUE_NEED_ASYNC is required if GAUDIO_NEED_PLAY is TRUE. It has been turned on for you.") + #endif #endif #undef GQUEUE_NEED_ASYNC #define GQUEUE_NEED_ASYNC TRUE #endif #if !GQUEUE_NEED_GSYNC || !GQUEUE_NEED_BUFFERS #if GFX_DISPLAY_RULE_WARNINGS - #warning "GAUDIO: GQUEUE_NEED_BUFFERS and GQUEUE_NEED_GSYNC are required if GFX_USE_GAUDIO is TRUE. They have been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GAUDIO: GQUEUE_NEED_BUFFERS and GQUEUE_NEED_GSYNC are required if GFX_USE_GAUDIO is TRUE. They have been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GAUDIO: GQUEUE_NEED_BUFFERS and GQUEUE_NEED_GSYNC are required if GFX_USE_GAUDIO is TRUE. They have been turned on for you.") + #endif #endif #undef GQUEUE_NEED_BUFFERS #define GQUEUE_NEED_BUFFERS TRUE @@ -45,7 +57,11 @@ #endif #if GFX_USE_GEVENT && !GFX_USE_GTIMER #if GFX_DISPLAY_RULE_WARNINGS - #warning "GAUDIO: GFX_USE_GTIMER is required if GFX_USE_GAUDIO and GFX_USE_GEVENT are TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GAUDIO: GFX_USE_GTIMER is required if GFX_USE_GAUDIO and GFX_USE_GEVENT are TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GAUDIO: GFX_USE_GTIMER is required if GFX_USE_GAUDIO and GFX_USE_GEVENT are TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GTIMER #define GFX_USE_GTIMER TRUE diff --git a/src/gdisp/gdisp_image_png.c b/src/gdisp/gdisp_image_png.c index f7389a29..822c7002 100644 --- a/src/gdisp/gdisp_image_png.c +++ b/src/gdisp/gdisp_image_png.c @@ -267,7 +267,11 @@ static void PNG_oColor(PNG_output *o, color_t c) { #if (GDISP_IMAGE_PNG_Z_BUFFER_SIZE & ~(GDISP_IMAGE_PNG_Z_BUFFER_SIZE-1)) == GDISP_IMAGE_PNG_Z_BUFFER_SIZE #define WRAP_ZBUF(x) { x &= GDISP_IMAGE_PNG_Z_BUFFER_SIZE-1; } #else - #warning "PNG: GDISP_IMAGE_PNG_Z_BUFFER_SIZE is more efficient as a power of 2" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "PNG: GDISP_IMAGE_PNG_Z_BUFFER_SIZE is more efficient as a power of 2" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("PNG: GDISP_IMAGE_PNG_Z_BUFFER_SIZE is more efficient as a power of 2") + #endif #define WRAP_ZBUF(x) { if (x >= GDISP_IMAGE_PNG_Z_BUFFER_SIZE) x = 0; } #endif diff --git a/src/gdisp/gdisp_rules.h b/src/gdisp/gdisp_rules.h index 2c14b4cb..d9fb86bb 100644 --- a/src/gdisp/gdisp_rules.h +++ b/src/gdisp/gdisp_rules.h @@ -19,7 +19,11 @@ #if GFX_USE_GDISP #if !GFX_USE_GDRIVER #if GFX_DISPLAY_RULE_WARNINGS - #warning "GDISP: GFX_USE_GDRIVER is required. GFX_USE_GDRIVER has turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GDISP: GFX_USE_GDRIVER is required. GFX_USE_GDRIVER has turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GDISP: GFX_USE_GDRIVER is required. GFX_USE_GDRIVER has turned on for you.") + #endif #endif #undef GFX_USE_GDRIVER #define GFX_USE_GDRIVER TRUE @@ -34,7 +38,11 @@ #endif #if GDISP_NEED_AUTOFLUSH && GDISP_NEED_TIMERFLUSH #if GFX_DISPLAY_RULE_WARNINGS - #warning "GDISP: Both GDISP_NEED_AUTOFLUSH and GDISP_NEED_TIMERFLUSH has been set. GDISP_NEED_TIMERFLUSH has been disabled for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GDISP: Both GDISP_NEED_AUTOFLUSH and GDISP_NEED_TIMERFLUSH has been set. GDISP_NEED_TIMERFLUSH has been disabled for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GDISP: Both GDISP_NEED_AUTOFLUSH and GDISP_NEED_TIMERFLUSH has been set. GDISP_NEED_TIMERFLUSH has been disabled for you.") + #endif #endif #undef GDISP_NEED_TIMERFLUSH #define GDISP_NEED_TIMERFLUSH FALSE @@ -45,7 +53,11 @@ #endif #if !GFX_USE_GTIMER #if GFX_DISPLAY_RULE_WARNINGS - #warning "GDISP: GDISP_NEED_TIMERFLUSH has been set but GFX_USE_GTIMER has not been set. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GDISP: GDISP_NEED_TIMERFLUSH has been set but GFX_USE_GTIMER has not been set. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GDISP: GDISP_NEED_TIMERFLUSH has been set but GFX_USE_GTIMER has not been set. It has been turned on for you.") + #endif #endif #undef GFX_USE_GTIMER #define GFX_USE_GTIMER TRUE @@ -56,20 +68,33 @@ #if GDISP_NEED_ANTIALIAS && !GDISP_NEED_PIXELREAD #if GDISP_HARDWARE_PIXELREAD #if GFX_DISPLAY_RULE_WARNINGS - #warning "GDISP: GDISP_NEED_ANTIALIAS has been set but GDISP_NEED_PIXELREAD has not. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GDISP: GDISP_NEED_ANTIALIAS has been set but GDISP_NEED_PIXELREAD has not. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GDISP: GDISP_NEED_ANTIALIAS has been set but GDISP_NEED_PIXELREAD has not. It has been turned on for you.") + #endif #endif #undef GDISP_NEED_PIXELREAD #define GDISP_NEED_PIXELREAD TRUE #else #if GFX_DISPLAY_RULE_WARNINGS - #warning "GDISP: GDISP_NEED_ANTIALIAS has been set but your hardware does not support reading back pixels. Anti-aliasing will only occur for filled characters." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GDISP: GDISP_NEED_ANTIALIAS has been set but your hardware does not support reading back pixels. Anti-aliasing will only occur for filled characters." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GDISP: GDISP_NEED_ANTIALIAS has been set but your hardware does not support reading back pixels. Anti-aliasing will only occur for filled characters.") + #endif #endif #endif #endif #if (defined(GDISP_INCLUDE_FONT_SMALL) && GDISP_INCLUDE_FONT_SMALL) || (defined(GDISP_INCLUDE_FONT_LARGER) && GDISP_INCLUDE_FONT_LARGER) #if GFX_DISPLAY_RULE_WARNINGS - #warning "GDISP: An old font (Small or Larger) has been defined. A single default font of UI2 has been added instead." - #warning "GDISP: Please see <$(GFXLIB)/include/gdisp/fonts/fonts.h> for a list of available font names." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GDISP: An old font (Small or Larger) has been defined. A single default font of UI2 has been added instead." + #warning "GDISP: Please see <$(GFXLIB)/include/gdisp/fonts/fonts.h> for a list of available font names." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GDISP: An old font (Small or Larger) has been defined. A single default font of UI2 has been added instead.") + COMPILER_WARNING("GDISP: Please see <$(GFXLIB)/include/gdisp/fonts/fonts.h> for a list of available font names.") + #endif #endif #undef GDISP_INCLUDE_FONT_UI2 #define GDISP_INCLUDE_FONT_UI2 TRUE @@ -77,7 +102,11 @@ #if GDISP_NEED_IMAGE #if !GFX_USE_GFILE #if GFX_DISPLAY_RULE_WARNINGS - #warning "GDISP: GFX_USE_GFILE is required when GDISP_NEED_IMAGE is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GDISP: GFX_USE_GFILE is required when GDISP_NEED_IMAGE is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GDISP: GFX_USE_GFILE is required when GDISP_NEED_IMAGE is TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GFILE #define GFX_USE_GFILE TRUE diff --git a/src/gfx_compilers.h b/src/gfx_compilers.h index 46d6c8b1..6d1dae1e 100644 --- a/src/gfx_compilers.h +++ b/src/gfx_compilers.h @@ -285,12 +285,19 @@ * * Please keep this list in alphabetical order to keep it easier to maintain */ + #undef GFX_COMPILER_NAME #undef GFX_COMPILER_TESTED #undef GFX_COMPILER_VERSION_MAJOR #undef GFX_COMPILER_VERSION_MINOR #undef GFX_COMPILER_VERSION_PATCH #undef GFX_COMPILER_VERSION_BUILD + #undef GFX_COMPILER_WARNING_TYPE + #define GFX_COMPILER_WARNING_NONE 0 /* Don't display warnings */ + #define GFX_COMPILER_WARNING_DIRECT 1 /* Use #warning text, no macro expansion possible */ + #define GFX_COMPILER_WARNING_MACRO 2 /* Use COMPILER_WARNING(text), macro expansion possible */ + #define GFX_COMPILER_WARNING_GCC 3 /* Use GCC style warnings - converted to GFX_COMPILER_WARNING_MACRO */ + #if GFX_COMPILER == GFX_COMPILER_ACC #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS #warning "Compiler: ACC" @@ -338,6 +345,7 @@ #define GFX_COMPILER_VERSION_MINOR (((__ARMCC_VERSION)/10000)%10) #define GFX_COMPILER_VERSION_PATCH (((__ARMCC_VERSION)/1000)%10) #define GFX_COMPILER_VERSION_BUILD ((__ARMCC_VERSION)%1000) + #pragma anon_unions // Allow anonymous unions #define __LITTLE_IF_NOT_BIG__ // Oops - Defines __BIG_ENDIAN but not __LITTLE_ENDIAN #elif GFX_COMPILER == GFX_COMPILER_AZTEC #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS @@ -362,11 +370,9 @@ #define GFX_COMPILER_VERSION_MINOR (((__CC65__)/0x10)%0x10) #define GFX_COMPILER_VERSION_PATCH ((__CC65__)%0x10) #elif GFX_COMPILER == GFX_COMPILER_CLANG - #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS - #warning "Compiler: CLANG" - #endif #define GFX_COMPILER_NAME "CLang (LLVM)" #define GFX_COMPILER_TESTED TRUE + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_GCC #define GFX_COMPILER_VERSION_MAJOR (__clang_major__) #define GFX_COMPILER_VERSION_MINOR (__clang_minor__) #define GFX_COMPILER_VERSION_PATCH (__clang_patchlevel__) @@ -404,11 +410,9 @@ #define GFX_COMPILER_VERSION_MAJOR (_RELEASE) #define GFX_COMPILER_VERSION_MINOR (_RELEASE_MINOR) #elif GFX_COMPILER == GFX_COMPILER_CYGWIN - #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS - #warning "Compiler: CYGWIN" - #endif #define GFX_COMPILER_NAME "Cygwin" #define GFX_COMPILER_TESTED TRUE + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_GCC #define GFX_COMPILER_VERSION_MAJOR (__GNUC__) #define GFX_COMPILER_VERSION_MINOR (__GNUC_MINOR__) #ifdef __GNUC_PATCHLEVEL__ @@ -489,11 +493,9 @@ #endif #define GFX_COMPILER_NAME "Fujitsu C++" #elif GFX_COMPILER == GFX_COMPILER_GCC - #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS - #warning "Compiler: GCC" - #endif #define GFX_COMPILER_NAME "GCC" #define GFX_COMPILER_TESTED TRUE + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_GCC #define GFX_COMPILER_VERSION_MAJOR (__GNUC__) #define GFX_COMPILER_VERSION_MINOR (__GNUC_MINOR__) #ifdef __GNUC_PATCHLEVEL__ @@ -654,11 +656,9 @@ #endif #define GFX_COMPILER_NAME "Microway NDP C" #elif GFX_COMPILER == GFX_COMPILER_MINGW32 - #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS - #warning "Compiler: MINGW32" - #endif #define GFX_COMPILER_NAME "MingW32" #define GFX_COMPILER_TESTED TRUE + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_GCC #define GFX_COMPILER_VERSION_MAJOR (__GNUC__) #define GFX_COMPILER_VERSION_MINOR (__GNUC_MINOR__) #ifdef __GNUC_PATCHLEVEL__ @@ -666,10 +666,8 @@ #endif #define DEPRECATED(msg) __attribute__((deprecated(msg))) #elif GFX_COMPILER == GFX_COMPILER_MINGW64 - #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS - #warning "Compiler: MINGW64" - #endif #define GFX_COMPILER_NAME "MingW64" + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_GCC #define GFX_COMPILER_VERSION_MAJOR (__GNUC__) #define GFX_COMPILER_VERSION_MINOR (__GNUC_MINOR__) #ifdef __GNUC_PATCHLEVEL__ @@ -890,9 +888,6 @@ #endif #define GFX_COMPILER_NAME "VBCC" #elif GFX_COMPILER == GFX_COMPILER_VS - #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS - #warning "Compiler: VS" - #endif #define GFX_COMPILER_NAME "Microsoft Visual Studio" #ifdef _MSC_FULL_VER #if _MSC_FULL_VER < 100000000 @@ -912,6 +907,9 @@ #define GFX_COMPILER_VERSION_BUILD (_MSC_BUILD) #endif #define DEPRECATED(msg) __declspec(deprecated(msg)) + + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_MACRO + #define COMPILER_WARNING(desc) __pragma(message(__FILE__ "(" GFXSTRX(__LINE__) "): warning uGFX: " desc)) #elif GFX_COMPILER == GFX_COMPILER_WATCOM #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS #warning "Compiler: WATCOM" @@ -928,8 +926,17 @@ #define GFX_COMPILER_VERSION_MINOR (((__ZTC__)/0x10)%0x10) #define GFX_COMPILER_VERSION_PATCH ((__ZTC__)%0x10) #endif + #ifndef GFX_COMPILER_TESTED - #define GFX_COMPILER_TESTED FALSE + #define GFX_COMPILER_TESTED FALSE + #endif + #ifndef GFX_COMPILER_WARNING_TYPE + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_DIRECT + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_GCC + #undef GFX_COMPILER_WARNING_TYPE + #define GFX_COMPILER_WARNING_TYPE GFX_COMPILER_WARNING_MACRO + #define COMPILER_PRAGMA(x) _Pragma(#x) + #define COMPILER_WARNING(desc) COMPILER_PRAGMA(GCC warning desc) #endif /************************************ End Compiler Settings *************************/ @@ -944,6 +951,11 @@ #define GFX_COMPILER_NAME "Unknown" #warning "You are using an unknown compiler. Please report this on the ugfx forum" #endif + #if GFX_SHOW_COMPILER && GFX_DISPLAY_RULE_WARNINGS + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING(GFXSTRX(Compiler: GFX_COMPILER_NAME)) + #endif + #endif /** * @brief This compiler is tested with ugfx @@ -955,8 +967,12 @@ * tested with a different compiler version. Please report any problems * on the ugfx forum. */ - #if !GFX_COMPILER_TESTED - #warning "You are using an un-tested compiler. Please report any compile errors or warnings on the ugfx forum" + #if !GFX_COMPILER_TESTED && GFX_DISPLAY_RULE_WARNINGS + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "You are using an un-tested compiler. Please report any compile errors or warnings on the ugfx forum" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING(GFXSTRX(You are using the un-tested GFX_COMPILER_NAME compiler. Please report any compile errors or warnings on the ugfx forum)) + #endif #endif /** diff --git a/src/ginput/ginput_keyboard.c b/src/ginput/ginput_keyboard.c index 0018dafb..141bdd2b 100644 --- a/src/ginput/ginput_keyboard.c +++ b/src/ginput/ginput_keyboard.c @@ -471,7 +471,7 @@ void _gkeyboardInit(void) { static const GKeyboardVMT * const dclist[] = {GINPUT_KEYBOARD_DRIVER_LIST}; for(i = 0; i < sizeof(dclist)/sizeof(dclist[0]); i++) { - if (!(dclist[i]->d.flags & GKEYBOARD_VFLG_DYNAMICONLY)) + if (!(dclist[i]->d.flags & GKEYBOARD_VFLG_DYNAMICONLY)) gdriverRegister(&dclist[i]->d, 0); } } @@ -481,8 +481,8 @@ void _gkeyboardInit(void) { { extern const GKeyboardVMT const GKEYBOARDVMT_OnlyOne[1]; - if (!(GKEYBOARDVMT_OnlyOne->d.flags & GKEYBOARD_VFLG_DYNAMICONLY)) - gdriverRegister(&GKEYBOARDVMT_OnlyOne->d, 0); + if (!(GKEYBOARDVMT_OnlyOne->d.flags & GKEYBOARD_VFLG_DYNAMICONLY)) + gdriverRegister(&GKEYBOARDVMT_OnlyOne->d, 0); } #endif @@ -493,43 +493,43 @@ void _gkeyboardDeinit(void) { } bool_t _gkeyboardInitDriver(GDriver *g, void *param, unsigned driverinstance, unsigned systeminstance) { - #define k ((GKeyboard *)g) + #define k ((GKeyboard *)g) (void) param; - (void) systeminstance; + (void) systeminstance; // The initial keyboard layout comes from the VMT k->pLayout = gkvmt(k)->defLayout; // Init the mouse - if (!gkvmt(k)->init((GKeyboard *)g, driverinstance)) - return FALSE; + if (!gkvmt(k)->init((GKeyboard *)g, driverinstance)) + return FALSE; // Ensure the Poll timer is started if (!gtimerIsActive(&KeyboardTimer)) gtimerStart(&KeyboardTimer, KeyboardPoll, 0, TRUE, GINPUT_KEYBOARD_POLL_PERIOD); - return TRUE; + return TRUE; - #undef k + #undef k } void _gkeyboardPostInitDriver(GDriver *g) { - #define k ((GKeyboard *)g) + #define k ((GKeyboard *)g) // Run the init sequence from the layout microcode. microengine(k, 0, FLAG_INIT); - #undef k + #undef k } void _gkeyboardDeInitDriver(GDriver *g) { - (void) g; + (void) g; } GSourceHandle ginputGetKeyboard(unsigned instance) { if (instance == GKEYBOARD_ALL_INSTANCES) return (GSourceHandle)&KeyboardTimer; - return (GSourceHandle)gdriverGetInstance(GDRIVER_TYPE_KEYBOARD, instance); + return (GSourceHandle)gdriverGetInstance(GDRIVER_TYPE_KEYBOARD, instance); } bool_t ginputGetKeyboardStatus(unsigned instance, GEventKeyboard *pe) { diff --git a/src/ginput/ginput_rules.h b/src/ginput/ginput_rules.h index 6d997f90..5825e2f0 100644 --- a/src/ginput/ginput_rules.h +++ b/src/ginput/ginput_rules.h @@ -19,14 +19,22 @@ #if GFX_USE_GINPUT #if !GFX_USE_GEVENT #if GFX_DISPLAY_RULE_WARNINGS - #warning "GINPUT: GFX_USE_GEVENT is required if GFX_USE_GINPUT is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GINPUT: GFX_USE_GEVENT is required if GFX_USE_GINPUT is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GINPUT: GFX_USE_GEVENT is required if GFX_USE_GINPUT is TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GEVENT #define GFX_USE_GEVENT TRUE #endif #if !GFX_USE_GTIMER #if GFX_DISPLAY_RULE_WARNINGS - #warning "GINPUT: GFX_USE_GTIMER is required if GFX_USE_GINPUT is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GINPUT: GFX_USE_GTIMER is required if GFX_USE_GINPUT is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GINPUT: GFX_USE_GTIMER is required if GFX_USE_GINPUT is TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GTIMER #define GFX_USE_GTIMER TRUE diff --git a/src/gos/gos.h b/src/gos/gos.h index ddca0d94..dedfcdda 100644 --- a/src/gos/gos.h +++ b/src/gos/gos.h @@ -403,27 +403,6 @@ void gfxSemSignalI(gfxSem *psem); /** - * @brief Get the current semaphore count - * @return The current semaphore count - * - * @param[in] psem A pointer to the semaphore - * - * @api - */ - semcount_t gfxSemCounter(gfxSem *psem); - - /** - * @brief Get the current semaphore count - * @return The current semaphore count - * - * @param[in] psem A pointer to the semaphore - * - * @iclass - * @api - */ - semcount_t gfxSemCounterI(gfxSem *psem); - - /** * @brief Start a new thread. * @return Returns a thread handle if the thread was started, NULL on an error * @@ -497,8 +476,12 @@ #include "gos_arduino.h" #elif GFX_USE_OS_CMSIS #include "gos_cmsis.h" +#elif GFX_USE_OS_CMSIS2 + #include "gos_cmsis2.h" #elif GFX_USE_OS_KEIL #include "gos_keil.h" +#elif GFX_USE_OS_RTX5 + #include "gos_rtx5.h" #elif GFX_USE_OS_NIOS #include "gos_nios.h" #elif GFX_USE_OS_QT diff --git a/src/gos/gos_arduino.c b/src/gos/gos_arduino.c index 2e0e4b53..0eec8957 100644 --- a/src/gos/gos_arduino.c +++ b/src/gos/gos_arduino.c @@ -25,7 +25,11 @@ void _gosInit(void) * getting here! */ #if !GFX_OS_INIT_NO_WARNING - #warning "GOS: Arduino - Make sure you initialize your hardware and the C runtime before calling gfxInit() in your application!" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Arduino - Make sure you initialize your hardware and the C runtime before calling gfxInit() in your application!" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Arduino - Make sure you initialize your hardware and the C runtime before calling gfxInit() in your application!") + #endif #endif // Start the heap allocator diff --git a/src/gos/gos_chibios.c b/src/gos/gos_chibios.c index 72b91dfc..8bad8ed6 100644 --- a/src/gos/gos_chibios.c +++ b/src/gos/gos_chibios.c @@ -49,7 +49,11 @@ void _gosInit(void) } #endif #elif !GFX_OS_INIT_NO_WARNING - #warning "GOS: Operating System initialization has been turned off. Make sure you call halInit() and chSysInit() before gfxInit() in your application!" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Operating System initialization has been turned off. Make sure you call halInit() and chSysInit() before gfxInit() in your application!" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call halInit() and chSysInit() before gfxInit() in your application!") + #endif #endif } @@ -135,8 +139,13 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) bool_t gfxSemWaitI(gfxSem *psem) { - if (chSemGetCounterI(&psem->sem) <= 0) - return FALSE; + #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + if (psem->sem.s_cnt <= 0) + return GFalse; + #elif (CH_KERNEL_MAJOR == 4) + if (psem->sem.cnt <= 0) + return GFalse; + #endif chSemFastWaitI(&psem->sem); return TRUE; } @@ -145,8 +154,13 @@ void gfxSemSignal(gfxSem *psem) { chSysLock(); - if (gfxSemCounterI(psem) < psem->limit) - chSemSignalI(&psem->sem); + #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + if (psem->sem.s_cnt < psem->limit) + chSemSignalI(&psem->sem); + #elif (CH_KERNEL_MAJOR == 4) + if (psem->sem.cnt < psem->limit) + chSemSignalI(&psem->sem); + #endif chSchRescheduleS(); chSysUnlock(); @@ -154,19 +168,24 @@ void gfxSemSignal(gfxSem *psem) void gfxSemSignalI(gfxSem *psem) { - if (gfxSemCounterI(psem) < psem->limit) - chSemSignalI(&psem->sem); + #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + if (psem->sem.s_cnt < psem->limit) + chSemSignalI(&psem->sem); + #elif (CH_KERNEL_MAJOR == 4) + if (psem->sem.cnt < psem->limit) + chSemSignalI(&psem->sem); + #endif } gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) { if (!stackarea) { if (!stacksz) stacksz = 256; -#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) - return chThdCreateFromHeap(0, stacksz, prio, (tfunc_t)fn, param); -#elif CH_KERNEL_MAJOR == 4 - return chThdCreateFromHeap(0, stacksz, "ugfx", prio, (tfunc_t)fn, param); -#endif + #if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) + return chThdCreateFromHeap(0, stacksz, prio, (tfunc_t)fn, param); + #elif CH_KERNEL_MAJOR == 4 + return chThdCreateFromHeap(0, stacksz, "ugfx", prio, (tfunc_t)fn, param); + #endif } if (!stacksz) diff --git a/src/gos/gos_chibios.h b/src/gos/gos_chibios.h index c3fc9d36..aedfb492 100644 --- a/src/gos/gos_chibios.h +++ b/src/gos/gos_chibios.h @@ -120,13 +120,6 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); bool_t gfxSemWaitI(gfxSem *psem); void gfxSemSignal(gfxSem *psem); void gfxSemSignalI(gfxSem *psem); -#if (CH_KERNEL_MAJOR == 2) || (CH_KERNEL_MAJOR == 3) -#define gfxSemCounterI(psem) ((psem)->sem.s_cnt) -#define gfxSemCounter(psem) ((psem)->sem.s_cnt) -#elif (CH_KERNEL_MAJOR == 4) -#define gfxSemCounterI(psem) ((psem)->sem.cnt) -#define gfxSemCounter(psem) ((psem)->sem.cnt) -#endif gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); #define gfxThreadWait(thread) chThdWait(thread) #define gfxThreadMe() chThdSelf() diff --git a/src/gos/gos_cmsis.c b/src/gos/gos_cmsis.c index 5bb10dbd..2798dcba 100644 --- a/src/gos/gos_cmsis.c +++ b/src/gos/gos_cmsis.c @@ -19,7 +19,11 @@ void _gosInit(void) if (!osKernelRunning()) osKernelStart(); #elif !GFX_OS_INIT_NO_WARNING - #warning "GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize() and osKernelStart() before gfxInit() in your application!" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize() and osKernelStart() before gfxInit() in your application!" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize() and osKernelStart() before gfxInit() in your application!") + #endif #endif // Set up the heap allocator diff --git a/src/gos/gos_cmsis2.c b/src/gos/gos_cmsis2.c new file mode 100644 index 00000000..abbea6b2 --- /dev/null +++ b/src/gos/gos_cmsis2.c @@ -0,0 +1,110 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "../../gfx.h" +#include <string.h> + +#if GFX_USE_OS_CMSIS2 + +#if !GFX_OS_NO_INIT && !GFX_OS_CALL_UGFXMAIN + #error "GOS: Either GFX_OS_NO_INIT or GFX_OS_CALL_UGFXMAIN must be defined for CMSIS V2" +#endif + +void _gosHeapInit(void); + +void _gosInit(void) +{ + #if GFX_OS_NO_INIT && !GFX_OS_INIT_NO_WARNING + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize()." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize().") + #endif + #endif + + // Set up the heap allocator + _gosHeapInit(); +} + +#if !GFX_OS_NO_INIT && GFX_OS_CALL_UGFXMAIN + static DECLARE_THREAD_FUNCTION(startUGFX_CMSIS2, p) { + (void) p; + uGFXMain(); + } +#endif +void _gosPostInit(void) +{ + #if !GFX_OS_NO_INIT && GFX_OS_CALL_UGFXMAIN + switch(osKernelGetState()) { + case osKernelInactive: + osKernelInitialize(); + /* Fall Through */ + case osKernelReady: + gfxThreadCreate(0, GFX_OS_UGFXMAIN_STACKSIZE, NORMAL_PRIORITY, startUGFX_CMSIS2, 0); + osKernelStart(); + gfxHalt("Unable to start CMSIS V2 scheduler. Out of memory?"); + break; + default: + gfxThreadCreate(0, GFX_OS_UGFXMAIN_STACKSIZE, NORMAL_PRIORITY, startUGFX_CMSIS2, 0); + break; + } + #endif +} + +void _gosDeinit(void) +{ +} + +void gfxMutexInit(gfxMutex* pmutex) +{ + *pmutex = osMutexNew(NULL); +} + +void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit) +{ + *pmutex = osSemaphoreNew(limit, val, NULL); +} + +bool_t gfxSemWait(gfxSem* psem, delaytime_t ms) +{ + if (osSemaphoreAcquire(*psem, gfxMillisecondsToTicks(ms)) == osOK) + return TRUE; + return FALSE; +} + +gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param) +{ + osThreadAttr_t def; + + (void)stackarea; + + memset(&def, 0, sizeof(def)); + def.name = "uGFX"; + def.attr_bits = osThreadDetached; // osThreadJoinable + def.stack_mem = 0; + def.stack_size = stacksz; + def.priority = prio; + //def.tz_module = ????; + + return osThreadNew((osThreadFunc_t)fn, param, &def); +} + +threadreturn_t gfxThreadWait(gfxThreadHandle thread) { + while(1) { + switch(osThreadGetState(thread)) { + case osThreadReady: + case osThreadRunning: + case osThreadBlocked: + gfxYield(); + break; + default: + return; + } + } +} + +#endif /* GFX_USE_OS_CMSIS2 */ diff --git a/src/gos/gos_cmsis2.h b/src/gos/gos_cmsis2.h new file mode 100644 index 00000000..06d5da04 --- /dev/null +++ b/src/gos/gos_cmsis2.h @@ -0,0 +1,99 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gos/gos_cmsis2.h + * @brief GOS - Operating System Support header file for CMSIS 2.0 RTOS. + */ + +#ifndef _GOS_CMSIS2_H +#define _GOS_CMSIS2_H + +#if GFX_USE_OS_CMSIS2 + +#include <stdbool.h> +#include "cmsis_os2.h" + +#ifndef GFX_OS_HEAP_SIZE + #define GFX_OS_HEAP_SIZE 10240 +#endif + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +typedef bool bool_t; + +#define TIME_IMMEDIATE 0 +#define TIME_INFINITE osWaitForever +typedef uint32_t delaytime_t; +typedef uint32_t systemticks_t; +typedef uint16_t semcount_t; +typedef void threadreturn_t; +typedef osPriority_t threadpriority_t; + +#define MAX_SEMAPHORE_COUNT osFeature_Semaphore +#define LOW_PRIORITY osPriorityLow +#define NORMAL_PRIORITY osPriorityNormal +#define HIGH_PRIORITY osPriorityHigh + +typedef osSemaphoreId_t gfxSem; + +typedef osMutexId_t gfxMutex; + +typedef osThreadId_t gfxThreadHandle; + +#define DECLARE_THREAD_STACK(name, sz) uint8_t name[1]; // Some compilers don't allow zero sized arrays. Let's waste one byte +#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(void* param) +#define THREAD_RETURN(retval) + +/*===========================================================================*/ +/* Function declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#define gfxExit() os_error(0) +#define gfxHalt(msg) os_error(1) +#define gfxSystemTicks() osKernelGetSysTimerCount() +#define gfxMillisecondsToTicks(ms) (1000*(ms)/osKernelGetTickFreq()) +#define gfxSystemLock() osKernelLock() +#define gfxSystemUnlock() osKernelUnlock() +#define gfxSleepMilliseconds(ms) osDelay(ms) + +void gfxMutexInit(gfxMutex* pmutex); +#define gfxMutexDestroy(pmutex) osMutexDelete(*(pmutex)) +#define gfxMutexEnter(pmutex) osMutexAcquire(*(pmutex), TIME_INFINITE) +#define gfxMutexExit(pmutex) osMutexRelease(*(pmutex)) + +void gfxSemInit(gfxSem* psem, semcount_t val, semcount_t limit); +#define gfxSemDestroy(psem) osSemaphoreDelete(*(psem)) +bool_t gfxSemWait(gfxSem* psem, delaytime_t ms); +#define gfxSemWaitI(psem) gfxSemWait((psem), 0) +#define gfxSemSignal(psem) osSemaphoreRelease(*(psem)) +#define gfxSemSignalI(psem) osSemaphoreRelease(*(psem)) + +gfxThreadHandle gfxThreadCreate(void* stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void* param); +#define gfxYield() osThreadYield() +#define gfxThreadMe() osThreadGetId() +#define gfxThreadClose(thread) {} + +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Use the generic heap handling */ +/*===========================================================================*/ + +#define GOS_NEED_X_HEAP TRUE +#include "gos_x_heap.h" + +#endif /* GFX_USE_OS_CMSIS */ +#endif /* _GOS_CMSIS_H */ diff --git a/src/gos/gos_ecos.c b/src/gos/gos_ecos.c index 5ca5748f..a55773d9 100644 --- a/src/gos/gos_ecos.c +++ b/src/gos/gos_ecos.c @@ -15,7 +15,11 @@ void _gosInit(void) #error "GOS: Operating System initialization for eCos is not yet implemented in uGFX. Please set GFX_OS_NO_INIT to TRUE in your gfxconf.h" #endif #if !GFX_OS_INIT_NO_WARNING - #warning "GOS: Operating System initialization has been turned off. Make sure you call cyg_scheduler_start() before gfxInit() in your application!" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Operating System initialization has been turned off. Make sure you call cyg_scheduler_start() before gfxInit() in your application!" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call cyg_scheduler_start() before gfxInit() in your application!") + #endif #endif } @@ -80,7 +84,7 @@ void gfxSemSignal(gfxSem *psem) cyg_semaphore_post(&psem->sem); else { cyg_scheduler_lock(); - if (gfxSemCounterI(psem) < psem->limit) + if (cyg_semaphore_peek(&psem->sem, &cnt) < psem->limit) cyg_semaphore_post(&psem->sem); cyg_scheduler_unlock(); } @@ -88,17 +92,10 @@ void gfxSemSignal(gfxSem *psem) void gfxSemSignalI(gfxSem *psem) { - if (psem->limit == MAX_SEMAPHORE_COUNT || gfxSemCounterI(psem) < psem->limit) + if (psem->limit == MAX_SEMAPHORE_COUNT || cyg_semaphore_peek(&psem->sem, &cnt) < psem->limit) cyg_semaphore_post(&psem->sem); } -semcount_t gfxSemCounterI(gfxSem *psem) { - semcount_t cnt; - - cyg_semaphore_peek(&psem->sem, &cnt); - return cnt; -} - gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) { gfxThreadHandle th; diff --git a/src/gos/gos_ecos.h b/src/gos/gos_ecos.h index 6aa55a3a..0e438fb0 100644 --- a/src/gos/gos_ecos.h +++ b/src/gos/gos_ecos.h @@ -91,8 +91,6 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); bool_t gfxSemWaitI(gfxSem *psem); void gfxSemSignal(gfxSem *psem); void gfxSemSignalI(gfxSem *psem); -semcount_t gfxSemCounterI(gfxSem *psem); -#define gfxSemCounter(psem) gfxSemCounterI(psem) gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); #define gfxThreadWait(thread) NOTIMPLEMENTED_YET diff --git a/src/gos/gos_freertos.c b/src/gos/gos_freertos.c index 7c47aa40..ff424e70 100644 --- a/src/gos/gos_freertos.c +++ b/src/gos/gos_freertos.c @@ -33,7 +33,11 @@ void _gosInit(void) { #if GFX_OS_NO_INIT && !GFX_OS_INIT_NO_WARNING - #warning "GOS: Operating System initialization has been turned off. Make sure you call vTaskStartScheduler()." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Operating System initialization has been turned off. Make sure you call vTaskStartScheduler()." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call vTaskStartScheduler().") + #endif #endif } diff --git a/src/gos/gos_linux.c b/src/gos/gos_linux.c index dac3838f..43371443 100644 --- a/src/gos/gos_linux.c +++ b/src/gos/gos_linux.c @@ -165,15 +165,12 @@ threadreturn_t gfxThreadWait(gfxThreadHandle thread) { } } void gfxSemSignal(gfxSem *pSem) { - if (gfxSemCounter(pSem) < pSem->max) - sem_post(&pSem->sem); - } - semcount_t gfxSemCounter(gfxSem *pSem) { int res; res = 0; sem_getvalue(&pSem->sem, &res); - return res; + if (res < pSem->max) + sem_post(&pSem->sem); } #else void gfxSemInit(gfxSem *pSem, semcount_t val, semcount_t limit) { @@ -239,17 +236,6 @@ threadreturn_t gfxThreadWait(gfxThreadHandle thread) { pthread_mutex_unlock(&pSem->mtx); } - semcount_t gfxSemCounter(gfxSem *pSem) { - semcount_t res; - - // The locking is really only required if obtaining the count is a divisible operation - // which it might be on a 8/16 bit processor with a 32 bit semaphore count. - pthread_mutex_lock(&pSem->mtx); - res = pSem->cnt; - pthread_mutex_unlock(&pSem->mtx); - - return res; - } #endif // GFX_USE_POSIX_SEMAPHORES #endif /* GFX_USE_OS_LINUX */ diff --git a/src/gos/gos_linux.h b/src/gos/gos_linux.h index fe406cb6..b9bfe82e 100644 --- a/src/gos/gos_linux.h +++ b/src/gos/gos_linux.h @@ -65,7 +65,6 @@ typedef pthread_mutex_t gfxMutex; sem_t sem; semcount_t max; } gfxSem; - #define gfxSemCounterI(psem) gfxSemCounter(psem) #else typedef struct gfxSem { pthread_mutex_t mtx; @@ -73,7 +72,6 @@ typedef pthread_mutex_t gfxMutex; semcount_t cnt; semcount_t max; } gfxSem; - #define gfxSemCounterI(psem) ((psem)->cnt) #endif /*===========================================================================*/ @@ -95,7 +93,6 @@ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit); void gfxSemDestroy(gfxSem *psem); bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); void gfxSemSignal(gfxSem *psem); -semcount_t gfxSemCounter(gfxSem *pSem); gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); threadreturn_t gfxThreadWait(gfxThreadHandle thread); diff --git a/src/gos/gos_options.h b/src/gos/gos_options.h index e8ce12e7..1c6dc8b1 100644 --- a/src/gos/gos_options.h +++ b/src/gos/gos_options.h @@ -91,13 +91,27 @@ #define GFX_USE_OS_CMSIS FALSE #endif /** - * @brief Use Keil CMSIS + * @brief Use CMSIS2 RTOS compatible OS + * @details Defaults to FALSE + */ + #ifndef GFX_USE_OS_CMSIS2 + #define GFX_USE_OS_CMSIS2 FALSE + #endif + /** + * @brief Use Keil CMSIS 1.x (RTOS, RTX4) * @details Defaults to FALSE */ #ifndef GFX_USE_OS_KEIL #define GFX_USE_OS_KEIL FALSE #endif /** + * @brief Use Keil RTX5 + * @details Defaults to FALSE + */ + #ifndef GFX_USE_OS_RTX5 + #define GFX_USE_OS_RTX5 FALSE + #endif + /** * @brief Use NIOS-II * @details Defaults to FALSE */ diff --git a/src/gos/gos_osx.c b/src/gos/gos_osx.c index f06685d7..56d64d98 100644 --- a/src/gos/gos_osx.c +++ b/src/gos/gos_osx.c @@ -180,15 +180,4 @@ void gfxSemSignal(gfxSem *pSem) { pthread_mutex_unlock(&pSem->mtx); } -semcount_t gfxSemCounter(gfxSem *pSem) { - semcount_t res; - - // The locking is really only required if obtaining the count is a divisible operation - // which it might be on a 8/16 bit processor with a 32 bit semaphore count. - pthread_mutex_lock(&pSem->mtx); - res = pSem->cnt; - pthread_mutex_unlock(&pSem->mtx); - return res; -} - #endif /* GFX_USE_OS_OSX */ diff --git a/src/gos/gos_osx.h b/src/gos/gos_osx.h index 9a8e10d9..94c67eab 100644 --- a/src/gos/gos_osx.h +++ b/src/gos/gos_osx.h @@ -44,7 +44,6 @@ typedef pthread_mutex_t gfxMutex; #define gfxMutexExit(pmtx) pthread_mutex_unlock(pmtx) #define gfxSemWaitI(psem) gfxSemWait(psem, TIME_IMMEDIATE) #define gfxSemSignalI(psem) gfxSemSignal(psem) -#define gfxSemCounterI(pSem) ((pSem)->cnt) #define TIME_IMMEDIATE 0 #define TIME_INFINITE ((delaytime_t)-1) @@ -78,7 +77,6 @@ void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit); void gfxSemDestroy(gfxSem *psem); bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); void gfxSemSignal(gfxSem *psem); -semcount_t gfxSemCounter(gfxSem *pSem); gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); threadreturn_t gfxThreadWait(gfxThreadHandle thread); diff --git a/src/gos/gos_qt.cpp b/src/gos/gos_qt.cpp index 422f1535..e7480dd2 100644 --- a/src/gos/gos_qt.cpp +++ b/src/gos/gos_qt.cpp @@ -178,16 +178,6 @@ void gfxSemSignalI(gfxSem *psem) static_cast<QSemaphore*>(*psem)->release(1); } -semcount_t gfxSemCounter(gfxSem *psem) -{ - return static_cast<QSemaphore*>(*psem)->available(); -} - -semcount_t gfxSemCounterI(gfxSem *psem) -{ - return static_cast<QSemaphore*>(*psem)->available(); -} - gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) { Q_UNUSED(stackarea) diff --git a/src/gos/gos_qt.h b/src/gos/gos_qt.h index 9986d7f2..45d743f5 100644 --- a/src/gos/gos_qt.h +++ b/src/gos/gos_qt.h @@ -63,8 +63,6 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); bool_t gfxSemWaitI(gfxSem *psem); void gfxSemSignal(gfxSem *psem); void gfxSemSignalI(gfxSem *psem); -semcount_t gfxSemCounter(gfxSem *psem); -semcount_t gfxSemCounterI(gfxSem *psem); gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); threadreturn_t gfxThreadWait(gfxThreadHandle thread); gfxThreadHandle gfxThreadMe(void); diff --git a/src/gos/gos_raw32.c b/src/gos/gos_raw32.c index af9a2442..72edbb83 100644 --- a/src/gos/gos_raw32.c +++ b/src/gos/gos_raw32.c @@ -26,7 +26,11 @@ void _gosInit(void) * getting here! */ #if !GFX_OS_INIT_NO_WARNING - #warning "GOS: Raw32 - Make sure you initialize your hardware and the C runtime before calling gfxInit() in your application!" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Raw32 - Make sure you initialize your hardware and the C runtime before calling gfxInit() in your application!" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Raw32 - Make sure you initialize your hardware and the C runtime before calling gfxInit() in your application!") + #endif #endif // Set up the heap allocator diff --git a/src/gos/gos_rawrtos.c b/src/gos/gos_rawrtos.c index ad646a7d..23b0c6c1 100644 --- a/src/gos/gos_rawrtos.c +++ b/src/gos/gos_rawrtos.c @@ -28,7 +28,11 @@ void _gosInit(void) #error "GOS: Operating System initialization for RawRTOS is not yet implemented in uGFX. Please set GFX_OS_NO_INIT to TRUE in your gfxconf.h" #endif #if !GFX_OS_INIT_NO_WARNING - #warning "GOS: Operating System initialization has been turned off. Make sure you call raw_os_start() before gfxInit() in your application!" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Operating System initialization has been turned off. Make sure you call raw_os_start() before gfxInit() in your application!" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call raw_os_start() before gfxInit() in your application!") + #endif #endif } diff --git a/src/gos/gos_rawrtos.h b/src/gos/gos_rawrtos.h index e7778d15..d1026c9d 100644 --- a/src/gos/gos_rawrtos.h +++ b/src/gos/gos_rawrtos.h @@ -47,7 +47,6 @@ typedef RAW_TASK_OBJ* gfxThreadHandle; #define gfxSemDestroy(psem) raw_semaphore_delete(psem) #define gfxSemSignal(psem) raw_semaphore_put((psem)) #define gfxSemSignalI(psem) raw_semaphore_put_all((psem)) -#define gfxSemCounterI(psem) ((psem)->count) #define gfxThreadMe() {(unsigned int)raw_task_identify()} #define gfxThreadClose(thread) {} diff --git a/src/gos/gos_rtx5.h b/src/gos/gos_rtx5.h new file mode 100644 index 00000000..b07a2164 --- /dev/null +++ b/src/gos/gos_rtx5.h @@ -0,0 +1,32 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gos/gos_rtx5.h + * @brief GOS - Operating System Support header file for Keil RTX + */ + +#ifndef _GOS_RTX5_H +#define _GOS_RTX5_H + +#if GFX_USE_OS_RTX5 + +/* + * Keil RTX uses the CMSIS RTOS interface. Therefore, just use the CMSIS2 RTOS port + */ + +// Disable KEIL to avoid error: "GOS: More than one operation system has been defined as TRUE." +#undef GFX_USE_OS_RTX5 +#define GFX_USE_OS_RTX5 FALSE + +// Enable generic CMSIS RTOS implementation +#undef GFX_USE_OS_CMSIS2 +#define GFX_USE_OS_CMSIS2 TRUE +#include "gos_cmsis2.h" + +#endif /* GFX_USE_OS_RTX5 */ +#endif /* _GOS_RTX5_H */ diff --git a/src/gos/gos_rules.h b/src/gos/gos_rules.h index b4b8e445..08de1f3f 100644 --- a/src/gos/gos_rules.h +++ b/src/gos/gos_rules.h @@ -16,11 +16,11 @@ #ifndef _GOS_RULES_H #define _GOS_RULES_H -#if !GFX_USE_OS_CHIBIOS && !GFX_USE_OS_WIN32 && !GFX_USE_OS_LINUX && !GFX_USE_OS_OSX && !GFX_USE_OS_RAW32 && !GFX_USE_OS_FREERTOS && !GFX_USE_OS_ECOS && !GFX_USE_OS_RAWRTOS && !GFX_USE_OS_ARDUINO && !GFX_USE_OS_CMSIS && !GFX_USE_OS_KEIL && !GFX_USE_OS_NIOS && !GFX_USE_OS_QT +#if !GFX_USE_OS_CHIBIOS && !GFX_USE_OS_WIN32 && !GFX_USE_OS_LINUX && !GFX_USE_OS_OSX && !GFX_USE_OS_RAW32 && !GFX_USE_OS_FREERTOS && !GFX_USE_OS_ECOS && !GFX_USE_OS_RAWRTOS && !GFX_USE_OS_ARDUINO && !GFX_USE_OS_CMSIS && !GFX_USE_OS_CMSIS2 && !GFX_USE_OS_KEIL && !GFX_USE_OS_RTX5 && !GFX_USE_OS_NIOS && !GFX_USE_OS_QT #error "GOS: No operating system has been defined." #endif -#if GFX_USE_OS_CHIBIOS + GFX_USE_OS_WIN32 + GFX_USE_OS_LINUX + GFX_USE_OS_OSX + GFX_USE_OS_RAW32 + GFX_USE_OS_FREERTOS + GFX_USE_OS_ECOS + GFX_USE_OS_RAWRTOS + GFX_USE_OS_ARDUINO + GFX_USE_OS_CMSIS + GFX_USE_OS_KEIL + GFX_USE_OS_NIOS + GFX_USE_OS_QT != 1 * TRUE +#if GFX_USE_OS_CHIBIOS + GFX_USE_OS_WIN32 + GFX_USE_OS_LINUX + GFX_USE_OS_OSX + GFX_USE_OS_RAW32 + GFX_USE_OS_FREERTOS + GFX_USE_OS_ECOS + GFX_USE_OS_RAWRTOS + GFX_USE_OS_ARDUINO + GFX_USE_OS_CMSIS + GFX_USE_OS_CMSIS2 + GFX_USE_OS_KEIL + GFX_USE_OS_RTX5 + GFX_USE_OS_NIOS + GFX_USE_OS_QT != 1 * TRUE #error "GOS: More than one operation system has been defined as TRUE." #endif @@ -30,9 +30,13 @@ #if GFX_EMULATE_MALLOC #if GFX_USE_OS_WIN32 || GFX_USE_OS_LINUX || GFX_USE_OS_OSX || GFX_USE_OS_ECOS || \ - (GFX_OS_HEAP_SIZE == 0 && (GFX_USE_OS_RAW32 || GFX_USE_OS_ARDUINO || GFX_USE_OS_CMSIS || GFX_USE_OS_KEIL)) + (GFX_OS_HEAP_SIZE == 0 && (GFX_USE_OS_RAW32 || GFX_USE_OS_ARDUINO || GFX_USE_OS_CMSIS || GFX_USE_OS_CMSIS2 || GFX_USE_OS_KEIL || GFX_USE_OS_RTX5)) #if GFX_DISPLAY_RULE_WARNINGS - #warning "GOS: Cannot emulate malloc as gfxAlloc() internally uses malloc on this platform" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS: Cannot emulate malloc as gfxAlloc() internally uses malloc on this platform" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS: Cannot emulate malloc as gfxAlloc() internally uses malloc on this platform") + #endif #endif #undef GFX_EMULATE_MALLOC #define GFX_EMULATE_MALLOC FALSE diff --git a/src/gos/gos_win32.c b/src/gos/gos_win32.c index 5eecca88..1aa13dd6 100644 --- a/src/gos/gos_win32.c +++ b/src/gos/gos_win32.c @@ -78,7 +78,7 @@ bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) { return WaitForSingleObject(*psem, ms) == WAIT_OBJECT_0; } -typedef LONG __stdcall (*_NtQuerySemaphore)( +typedef LONG (__stdcall *_NtQuerySemaphore)( HANDLE SemaphoreHandle, DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */ PVOID SemaphoreInformation, /* but this is to much to dump here */ @@ -86,6 +86,7 @@ typedef LONG __stdcall (*_NtQuerySemaphore)( PULONG ReturnLength OPTIONAL ); +/* - Left here simply because of its undocumented cleverness... semcount_t gfxSemCounter(gfxSem *pSem) { static _NtQuerySemaphore NtQuerySemaphore; struct _SEMAPHORE_BASIC_INFORMATION { @@ -100,8 +101,9 @@ semcount_t gfxSemCounter(gfxSem *pSem) { return BasicInfo.CurrentCount; } +*/ -gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param) { +gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION(*fn,p), void *param) { (void) stackarea; HANDLE thd; diff --git a/src/gos/gos_win32.h b/src/gos/gos_win32.h index bac74d46..62602ad3 100644 --- a/src/gos/gos_win32.h +++ b/src/gos/gos_win32.h @@ -46,8 +46,8 @@ typedef LONG semcount_t; typedef DWORD threadreturn_t; typedef int threadpriority_t; -#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t WINAPI fnName(void *param) -#define DECLARE_THREAD_STACK(name, sz) uint8_t name[0]; +#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t (WINAPI fnName)(void *param) +#define DECLARE_THREAD_STACK(name, sz) uint8_t name[1]; #define THREAD_RETURN(retval) return retval #define TIME_IMMEDIATE 0 @@ -78,7 +78,6 @@ typedef HANDLE gfxThreadHandle; #define gfxSemWaitI(psem) gfxSemWait((psem), TIME_IMMEDIATE) #define gfxSemSignal(psem) ReleaseSemaphore(*(psem), 1, 0) #define gfxSemSignalI(psem) ReleaseSemaphore(*(psem), 1, 0) -#define gfxSemCounterI(psem) gfxSemCounter(psem) #define gfxThreadMe() GetCurrentThread() #define gfxThreadClose(thread) CloseHandle(thread) @@ -93,10 +92,9 @@ extern "C" { void gfxHalt(const char *msg); void gfxSleepMicroseconds(delaytime_t ms); bool_t gfxSemWait(gfxSem *psem, delaytime_t ms); -semcount_t gfxSemCounter(gfxSem *pSem); void gfxSystemLock(void); void gfxSystemUnlock(void); -gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); +gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION(*fn,p), void *param); threadreturn_t gfxThreadWait(gfxThreadHandle thread); #ifdef __cplusplus diff --git a/src/gos/gos_x_threads.h b/src/gos/gos_x_threads.h index 05a08cc2..546e9e13 100644 --- a/src/gos/gos_x_threads.h +++ b/src/gos/gos_x_threads.h @@ -80,10 +80,6 @@ extern "C" { void gfxSemSignal(gfxSem *psem); void gfxSemSignalI(gfxSem *psem); - // Deprecated Semaphore functions (they still work here) - #define gfxSemCounter(psem) ((psem)->cnt) - #define gfxSemCounterI(psem) ((psem)->cnt) - // Threads gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param); #define gfxThreadClose(thread) diff --git a/src/gos/gos_x_threads_cortexm01.h b/src/gos/gos_x_threads_cortexm01.h index 15a90b2a..8afe1864 100644 --- a/src/gos/gos_x_threads_cortexm01.h +++ b/src/gos/gos_x_threads_cortexm01.h @@ -13,7 +13,11 @@ */ #if CORTEX_USE_FPU - #warning "GOS Threads: You have specified GFX_CPU=GFX_CPU_CORTX_M? with no hardware floating point support but CORTEX_USE_FPU is TRUE. Try using GFX_CPU_GFX_CPU_CORTEX_M?_FP instead" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS Threads: You have specified GFX_CPU=GFX_CPU_CORTX_M? with no hardware floating point support but CORTEX_USE_FPU is TRUE. Try using GFX_CPU_GFX_CPU_CORTEX_M?_FP instead" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS Threads: You have specified GFX_CPU=GFX_CPU_CORTX_M? with no hardware floating point support but CORTEX_USE_FPU is TRUE. Try using GFX_CPU_GFX_CPU_CORTEX_M?_FP instead") + #endif #endif #if GFX_COMPILER == GFX_COMPILER_GCC || GFX_COMPILER == GFX_COMPILER_CYGWIN || GFX_COMPILER == GFX_COMPILER_MINGW32 || GFX_COMPILER == GFX_COMPILER_MINGW64 @@ -128,5 +132,9 @@ } #else - #warning "GOS: Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching") + #endif #endif diff --git a/src/gos/gos_x_threads_cortexm347.h b/src/gos/gos_x_threads_cortexm347.h index 40d30138..8e9ece61 100644 --- a/src/gos/gos_x_threads_cortexm347.h +++ b/src/gos/gos_x_threads_cortexm347.h @@ -14,7 +14,11 @@ #if CORTEX_USE_FPU - #warning "GOS Threads: You have specified GFX_CPU=GFX_CPU_CORTX_M? with no hardware floating point support but CORTEX_USE_FPU is TRUE. Try using GFX_CPU_GFX_CPU_CORTEX_M?_FP instead" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS Threads: You have specified GFX_CPU=GFX_CPU_CORTX_M? with no hardware floating point support but CORTEX_USE_FPU is TRUE. Try using GFX_CPU_GFX_CPU_CORTEX_M?_FP instead" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS Threads: You have specified GFX_CPU=GFX_CPU_CORTX_M? with no hardware floating point support but CORTEX_USE_FPU is TRUE. Try using GFX_CPU_GFX_CPU_CORTEX_M?_FP instead") + #endif #endif #if GFX_COMPILER == GFX_COMPILER_GCC || GFX_COMPILER == GFX_COMPILER_CYGWIN || GFX_COMPILER == GFX_COMPILER_MINGW32 || GFX_COMPILER == GFX_COMPILER_MINGW64 @@ -91,5 +95,9 @@ } #else - #warning "GOS: Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching") + #endif #endif diff --git a/src/gos/gos_x_threads_cortexm47fp.h b/src/gos/gos_x_threads_cortexm47fp.h index f5eeff80..a85615c6 100644 --- a/src/gos/gos_x_threads_cortexm47fp.h +++ b/src/gos/gos_x_threads_cortexm47fp.h @@ -92,5 +92,9 @@ } #else - #warning "GOS: Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GOS Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GOS Threads: You have specified a specific CPU but your compiler is not supported. Defaulting to CLIB switching") + #endif #endif diff --git a/src/gqueue/gqueue_rules.h b/src/gqueue/gqueue_rules.h index 0bccb196..ecdea7a9 100644 --- a/src/gqueue/gqueue_rules.h +++ b/src/gqueue/gqueue_rules.h @@ -19,7 +19,11 @@ #if GFX_USE_GQUEUE #if GQUEUE_NEED_BUFFERS && !GQUEUE_NEED_GSYNC #if GFX_DISPLAY_RULE_WARNINGS - #warning "GQUEUE: GQUEUE_NEED_GSYNC is required if GQUEUE_NEED_BUFFERS is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GQUEUE: GQUEUE_NEED_GSYNC is required if GQUEUE_NEED_BUFFERS is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GQUEUE: GQUEUE_NEED_GSYNC is required if GQUEUE_NEED_BUFFERS is TRUE. It has been turned on for you.") + #endif #endif #undef GQUEUE_NEED_GSYNC #define GQUEUE_NEED_GSYNC TRUE diff --git a/src/gtimer/gtimer_rules.h b/src/gtimer/gtimer_rules.h index ff966d38..f2b4304e 100644 --- a/src/gtimer/gtimer_rules.h +++ b/src/gtimer/gtimer_rules.h @@ -19,8 +19,11 @@ #if GFX_USE_GTIMER #if GFX_USE_GDISP && !GDISP_NEED_MULTITHREAD #if GFX_DISPLAY_RULE_WARNINGS - #warning "GTIMER: GDISP_NEED_MULTITHREAD has not been specified." - #warning "GTIMER: Make sure you are not performing any GDISP/GWIN drawing operations in the timer callback!" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GTIMER: GDISP_NEED_MULTITHREAD has not been specified. Make sure you are not performing any GDISP/GWIN drawing operations in the timer callback!" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GTIMER: GDISP_NEED_MULTITHREAD has not been specified. Make sure you are not performing any GDISP/GWIN drawing operations in the timer callback!") + #endif #endif #endif #endif diff --git a/src/gwin/gwin_list.c b/src/gwin/gwin_list.c index 754e062b..5866603c 100644 --- a/src/gwin/gwin_list.c +++ b/src/gwin/gwin_list.c @@ -747,7 +747,11 @@ void gwinListDefaultDraw(GWidgetObject* gw, void* param) { gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+(LST_ARROW_SZ/2+1), upArrow, 3, ps->fill); gdispGFillConvexPoly(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+gw->g.height-(LST_ARROW_SZ+LST_ARROW_SZ/2+1), downArrow, 3, ps->fill); #else - #warning "GWIN: Lists display better when GDISP_NEED_CONVEX_POLYGON is turned on" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: Lists display better when GDISP_NEED_CONVEX_POLYGON is turned on" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: Lists display better when GDISP_NEED_CONVEX_POLYGON is turned on") + #endif gdispGFillArea(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+(LST_ARROW_SZ/2+1), LST_ARROW_SZ, LST_ARROW_SZ, ps->fill); gdispGFillArea(gw->g.display, gw->g.x+iwidth+((LST_SCROLLWIDTH-LST_ARROW_SZ)/2+2), gw->g.y+gw->g.height-(LST_ARROW_SZ+LST_ARROW_SZ/2+1), LST_ARROW_SZ, LST_ARROW_SZ, ps->fill); #endif diff --git a/src/gwin/gwin_rules.h b/src/gwin/gwin_rules.h index ea35a426..5d9c8745 100644 --- a/src/gwin/gwin_rules.h +++ b/src/gwin/gwin_rules.h @@ -23,7 +23,11 @@ #endif #if !GDISP_NEED_CLIP #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: Drawing can occur outside the defined windows as GDISP_NEED_CLIP is FALSE") + #endif #endif #endif @@ -31,7 +35,11 @@ #if GWIN_NEED_TABSET || GWIN_NEED_FRAME || GWIN_NEED_CONTAINER #if !GWIN_NEED_CONTAINERS #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GWIN_NEED_CONTAINERS is required when a container is enabled. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GWIN_NEED_CONTAINERS is required when a container is enabled. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GWIN_NEED_CONTAINERS is required when a container is enabled. It has been turned on for you.") + #endif #endif #undef GWIN_NEED_CONTAINERS #define GWIN_NEED_CONTAINERS TRUE @@ -41,7 +49,11 @@ GWIN_NEED_IMAGE || GWIN_NEED_CHECKBOX || GWIN_NEED_PROGRESSBAR || GWIN_NEED_KEYBOARD || GWIN_NEED_TEXTEDIT #if !GWIN_NEED_WIDGET #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GWIN_NEED_WIDGET is required when a widget is used. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GWIN_NEED_WIDGET is required when a widget is used. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GWIN_NEED_WIDGET is required when a widget is used. It has been turned on for you.") + #endif #endif #undef GWIN_NEED_WIDGET #define GWIN_NEED_WIDGET TRUE @@ -52,7 +64,11 @@ #if GWIN_NEED_CONTAINERS #if !GWIN_NEED_WIDGET #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GWIN_NEED_WIDGET is required when GWIN_NEED_CONTAINERS is enabled. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GWIN_NEED_WIDGET is required when GWIN_NEED_CONTAINERS is enabled. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GWIN_NEED_WIDGET is required when GWIN_NEED_CONTAINERS is enabled. It has been turned on for you.") + #endif #endif #undef GWIN_NEED_WIDGET #define GWIN_NEED_WIDGET TRUE @@ -68,14 +84,22 @@ #endif #if !GWIN_NEED_WINDOWMANAGER #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GWIN_NEED_WINDOWMANAGER is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GWIN_NEED_WINDOWMANAGER is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GWIN_NEED_WINDOWMANAGER is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you.") + #endif #endif #undef GWIN_NEED_WINDOWMANAGER #define GWIN_NEED_WINDOWMANAGER TRUE #endif #if !GDISP_NEED_MULTITHREAD #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GDISP_NEED_MULTITHREAD is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you" + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GDISP_NEED_MULTITHREAD is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you" + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GDISP_NEED_MULTITHREAD is required if GWIN_NEED_WIDGET is TRUE. It has been turned on for you") + #endif #endif #undef GDISP_NEED_MULTITHREAD #define GDISP_NEED_MULTITHREAD TRUE @@ -84,7 +108,11 @@ #if GWIN_NEED_WINDOWMANAGER #if !GFX_USE_GQUEUE || !GQUEUE_NEED_ASYNC #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GFX_USE_GQUEUE and GQUEUE_NEED_ASYNC is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GFX_USE_GQUEUE and GQUEUE_NEED_ASYNC is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GFX_USE_GQUEUE and GQUEUE_NEED_ASYNC is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GQUEUE #undef GQUEUE_NEED_ASYNC @@ -93,7 +121,11 @@ #endif #if !GFX_USE_GTIMER #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GFX_USE_GTIMER is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GFX_USE_GTIMER is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GFX_USE_GTIMER is required if GWIN_NEED_WINDOWMANAGER is TRUE. It has been turned on for you.") + #endif #endif #undef GFX_USE_GTIMER #define GFX_USE_GTIMER TRUE @@ -109,7 +141,11 @@ #if GWIN_NEED_RADIO #if !GDISP_NEED_CIRCLE #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GDISP_NEED_CIRCLE should be set to TRUE for much nicer radio button widgets." + #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT + #warning "GWIN: GDISP_NEED_CIRCLE should be set to TRUE for much nicer radio button widgets." + #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO + COMPILER_WARNING("GWIN: GDISP_NEED_CIRCLE should be set to TRUE for much nicer radio button widgets.") + #endif #endif #endif #endif diff --git a/src/gwin/gwin_textedit.c b/src/gwin/gwin_textedit.c index ec67365e..8e639300 100644 --- a/src/gwin/gwin_textedit.c +++ b/src/gwin/gwin_textedit.c @@ -26,22 +26,58 @@ #define gh2obj ((GTexteditObject *)gh) #define gw2obj ((GTexteditObject *)gw) -static bool_t resizeText(GWidgetObject* gw, size_t pos, int32_t diff) { - char *p, *q; - size_t sz; - - p = (char *)gw->text; - sz = strlen(p)+1; - if (diff < 0) - memcpy(p+pos, p+pos-diff, sz-pos+diff); - if (!(p = gfxRealloc(p, sz, sz+diff))) - return FALSE; +static void TextEditRemoveChar(GWidgetObject* gw) { + char *p; + const char *q; + unsigned sz; + unsigned pos; + + sz = strlen(gw->text); + pos = gw2obj->cursorPos; + q = gw->text+pos; + + if (!(gw->g.flags & GWIN_FLG_ALLOCTXT)) { + // Allocate and then copy + if (!(p = gfxAlloc(sz))) + return; + if (pos) + memcpy(p, gw->text, pos); + memcpy(p+pos, q+1, sz-pos); + gw->g.flags |= GWIN_FLG_ALLOCTXT; + } else { + // Copy and then reallocate + memcpy((char *)q, q+1, sz-pos); + if (!(p = gfxRealloc((char *)gw->text, sz+1, sz))) // This should never fail as we are making it smaller + return; + } gw->text = p; - if (diff > 0) { - q = p + sz; - p += pos; - while(--q >= p) - q[diff] = q[0]; +} + +static bool_t TextEditAddChars(GWidgetObject* gw, unsigned cnt) { + char *p; + const char *q; + unsigned sz; + unsigned pos; + + // Get the size of the text buffer + sz = strlen(gw->text)+1; + pos = gw2obj->cursorPos; + + if (!(gw->g.flags & GWIN_FLG_ALLOCTXT)) { + if (!(p = gfxAlloc(sz+cnt))) + return FALSE; + memcpy(p, gw->text, pos); + memcpy(p+pos+cnt, gw->text+pos, sz-pos); + gw->g.flags |= GWIN_FLG_ALLOCTXT; + gw->text = p; + } else { + if (!(p = gfxRealloc((char *)gw->text, sz, sz+cnt))) + return FALSE; + gw->text = p; + q = p+pos; + p += sz; + while(--p >= q) + p[cnt] = p[0]; } return TRUE; } @@ -117,7 +153,7 @@ static void TextEditMouseDown(GWidgetObject* gw, coord_t x, coord_t y) { if (!gw2obj->cursorPos) return; gw2obj->cursorPos--; - resizeText(gw, gw2obj->cursorPos, -1); + TextEditRemoveChar(gw); break; case GKEY_TAB: case GKEY_LF: @@ -129,7 +165,7 @@ static void TextEditMouseDown(GWidgetObject* gw, coord_t x, coord_t y) { // Delete if (!gw->text[gw2obj->cursorPos]) return; - resizeText(gw, gw2obj->cursorPos, -1); + TextEditRemoveChar(gw); break; default: // Ignore any other control characters @@ -137,15 +173,15 @@ static void TextEditMouseDown(GWidgetObject* gw, coord_t x, coord_t y) { return; // Keep the edit length to less than the maximum - if (gw2obj->maxSize && gw2obj->cursorPos+pke->bytecount > gw2obj->maxSize) + if (gw2obj->maxSize && strlen(gw->text)+pke->bytecount > gw2obj->maxSize) return; // Make space - resizeText(gw, gw2obj->cursorPos, pke->bytecount); - - // Insert the character - memcpy((char *)gw->text+gw2obj->cursorPos, pke->c, pke->bytecount); - gw2obj->cursorPos += pke->bytecount; + if (TextEditAddChars(gw, pke->bytecount)) { + // Insert the characters + memcpy((char *)gw->text+gw2obj->cursorPos, pke->c, pke->bytecount); + gw2obj->cursorPos += pke->bytecount; + } break; } } @@ -196,24 +232,13 @@ static const gwidgetVMT texteditVMT = { GHandle gwinGTexteditCreate(GDisplay* g, GTexteditObject* wt, GWidgetInit* pInit, size_t maxSize) { - char *p; - // Create the underlying widget if (!(wt = (GTexteditObject*)_gwidgetCreate(g, &wt->w, pInit, &texteditVMT))) return 0; wt->maxSize = maxSize; - // Reallocate the text (if necessary) - if (!(wt->w.g.flags & GWIN_FLG_ALLOCTXT)) { - if (!(p = gfxAlloc(wt->maxSize+1))) - return 0; - strncpy(p, wt->w.text, wt->maxSize); - wt->w.text = p; - wt->w.g.flags |= GWIN_FLG_ALLOCTXT; - } - - // Set text and cursor position + // Set cursor position wt->cursorPos = strlen(wt->w.text); gwinSetVisible(&wt->w.g, pInit->g.show); |