diff --git a/demos/3rdparty/notepad-2/gfxconf.h b/demos/3rdparty/notepad-2/gfxconf.h index 0768ca22..7f436596 100644 --- a/demos/3rdparty/notepad-2/gfxconf.h +++ b/demos/3rdparty/notepad-2/gfxconf.h @@ -9,6 +9,11 @@ #ifndef _GFXCONF_H #define _GFXCONF_H +/* GFX operating system to use */ +#define GFX_USE_OS_CHIBIOS TRUE +//#define GFX_USE_OS_WIN32 TRUE +//#define GFX_USE_OS_POSIX TRUE + /* GFX sub-systems to turn on */ #define GFX_USE_GDISP TRUE #define GFX_USE_GWIN TRUE diff --git a/demos/3rdparty/notepad-2/main.c b/demos/3rdparty/notepad-2/main.c index bd79d574..e4649146 100644 --- a/demos/3rdparty/notepad-2/main.c +++ b/demos/3rdparty/notepad-2/main.c @@ -28,10 +28,10 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Modified by InMarket to allow it to compile on any GFX supported operating system. */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #include "notepadApp.h" @@ -69,6 +69,7 @@ const NColorScheme schemeDefault2 = { const char *tsCalibRead(uint16_t instance) { // This will perform a on-spot calibration // Unless you read and add the co-efficients here + (void) instance; return NULL; } @@ -77,12 +78,7 @@ int main(void) { font_t font = gdispOpenFont("UI2"); /* initialize the hardware and the OS */ - halInit(); - chSysInit(); - - /* initialize the LCD */ gfxInit(); - gdispClear(Black); /* Calibrate the touchscreen */ ginputSetMouseCalibrationRoutines(0, NULL, tsCalibRead, FALSE); @@ -92,16 +88,14 @@ int main(void) { nSetColorScheme(schemeDefault); while (TRUE) { + gfxThreadWait(nLaunchNotepadApp()); - chThdWait(nLaunchNotepadApp()); - - gdispClear(Black); gdispSetClip(0, 0, gdispGetWidth(), gdispGetHeight()); + gdispClear(Black); gdispDrawString(3, 3, "Notepad Terminated.", font, White); gdispDrawString(3, 20, "Relaunching Notepad App...", font, White); - chThdSleepMilliseconds(1000); - + gfxSleepMilliseconds(1000); } return 0; diff --git a/demos/3rdparty/notepad-2/notepadApp.c b/demos/3rdparty/notepad-2/notepadApp.c index a89b7bf0..83186d38 100644 --- a/demos/3rdparty/notepad-2/notepadApp.c +++ b/demos/3rdparty/notepad-2/notepadApp.c @@ -28,14 +28,12 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Modified by InMarket to allow it to compile on any GFX supported operating system. */ -#include "ch.h" -#include "hal.h" #include "gfx.h" -#include "chprintf.h" - #include "notepadApp.h" #include "toolbarIcons.h" @@ -45,7 +43,7 @@ // Static objects static GListener gl; // Event listener object static GHandle nDrawingArea; // GWindow Drawing Area -static BaseSequentialStream *gstatusConsole; // GConsole Handle to the Status Bar +static GHandle gstatusConsole; // GConsole Handle to the Status Bar static GEventMouse curPtr; // Holder for current pointer location @@ -72,7 +70,7 @@ static int selColorIndex = 0, selPenWidth = 1, tbMode = 1; static NColorScheme nCurColorScheme; -static msg_t notepadThread(void *param); +static DECLARE_THREAD_FUNCTION(notepadThread, param); // Custom drawing functions for the buttons static void nbtnColorBarDraw(GHandle gh, bool_t enabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param) { @@ -94,7 +92,7 @@ static void nbtnColorBarDraw(GHandle gh, bool_t enabled, bool_t isdown, const ch for (i = 0; i < 8; i++) { j = gh->x + (NPAD_TOOLBAR_BTN_WIDTH / 2) + NPAD_TOOLBAR_BTN_WIDTH * i; - if (isdown == TRUE) { + if (isdown) { // Update selection - this is like lazy release. if (k >= 0 && k <= 7) { selPenWidth = k + 1; @@ -124,7 +122,7 @@ static void nbtnColorBarDraw(GHandle gh, bool_t enabled, bool_t isdown, const ch for (i = 0; i < 8; i++) { j = gh->x + (NPAD_TOOLBAR_BTN_WIDTH / 2) + NPAD_TOOLBAR_BTN_WIDTH * i; - if (isdown == TRUE) { + if (isdown) { // Update selection - this is like lazy release. if (k >= 0 && k <= 7) { selColorIndex = k; @@ -176,7 +174,7 @@ static void nbtnColorBarSelDraw(GHandle gh, bool_t enabled, bool_t isdown, const gdispDrawBox(gh->x + 1, gh->y + 1, gh->width - 2, gh->height - 2, ccs.toolbarBgUnsel); for (i = 0; i < 2; i++) { - if (isdown == TRUE) { + if (isdown) { // Update selection - this is like lazy release. if (k == 0 || k == 1) { tbMode = k; @@ -231,6 +229,11 @@ static void nToolbarImageButtonDraw(GHandle gh, bool_t isenabled, bool_t isdown, } static void nCloseButtonDraw(GHandle gh, bool_t isenabled, bool_t isdown, const char *txt, const GButtonDrawStyle *pstyle, void *param) { + (void) isenabled; + (void) isdown; + (void) txt; + (void) pstyle; + (void) param; gwinImageDraw(gh, &toolbarImageFilmstrip, 0, 0, NPAD_ICON_WIDTH, NPAD_ICON_HEIGHT, NPAD_ICON_START(8), 0); } @@ -308,8 +311,8 @@ static void drawVButtons(void) { gwinButtonDraw(H(btnFill)); } -static WORKING_AREA(waNotepadThread, NPAD_THD_WA_SIZE); -static msg_t notepadThread(void *param) { +static DECLARE_THREAD_STACK(waNotepadThread, NPAD_THD_WA_SIZE); +static DECLARE_THREAD_FUNCTION(notepadThread, param) { GEventMouse *pem; GEventGWinButton *peb; @@ -382,7 +385,7 @@ static msg_t notepadThread(void *param) { gwinSetBgColor(ghc, nCurColorScheme.winBgColor); gwinSetColor(ghc, Black); - gstatusConsole = gwinGetConsoleStream(ghc); + gstatusConsole = ghc; /* draw the buttons */ gwinSetColor(nDrawingArea, Black); @@ -394,7 +397,7 @@ static msg_t notepadThread(void *param) { drawButtons(); drawVButtons(); - chprintf(gstatusConsole, "Welcome to ChibiOS/GFX Notepad demo."); + gwinPrintf(gstatusConsole, "Welcome to ChibiOS/GFX Notepad demo."); ncoreSpawnDrawThread(nDrawingArea, gstatusConsole); @@ -419,28 +422,28 @@ static msg_t notepadThread(void *param) { drawVButtons(); gwinClear(nDrawingArea); - chprintf(gstatusConsole, "\nScreen Cleared."); + gwinPrintf(gstatusConsole, "\nScreen Cleared."); } else if (peb->button == H(btnOpen)) { - chprintf(gstatusConsole, "\nFile Open not implemented."); + gwinPrintf(gstatusConsole, "\nFile Open not implemented."); } else if (peb->button == H(btnSave)) { - chprintf(gstatusConsole, "\nFile Save not implemented."); + gwinPrintf(gstatusConsole, "\nFile Save not implemented."); } else if (peb->button == H(btnPencil)) { ncoreSetMode(NCORE_MODE_DRAW); drawVButtons(); - chprintf(gstatusConsole, "\nPencil Tool Selected."); + gwinPrintf(gstatusConsole, "\nPencil Tool Selected."); } else if (peb->button == H(btnEraser)) { ncoreSetMode(NCORE_MODE_ERASE); drawVButtons(); - chprintf(gstatusConsole, "\nEraser Tool Selected."); + gwinPrintf(gstatusConsole, "\nEraser Tool Selected."); } else if (peb->button == H(btnFill)) { ncoreSetMode(NCORE_MODE_FILL); drawVButtons(); - chprintf(gstatusConsole, "\nFill Tool Selected."); + gwinPrintf(gstatusConsole, "\nFill Tool Selected."); } else if (peb->button == H(btnClose)) { break; @@ -461,11 +464,10 @@ static msg_t notepadThread(void *param) { void nSetColorScheme(NColorScheme sch) { nCurColorScheme = sch; } NColorScheme nGetColorScheme(void) { return nCurColorScheme; } -Thread *nLaunchNotepadApp(void) { +gfxThreadHandle nLaunchNotepadApp(void) { - return chThdCreateStatic(waNotepadThread, + return gfxThreadCreate(waNotepadThread, sizeof(waNotepadThread), NPAD_THD_PRIO, notepadThread, NULL); - } diff --git a/demos/3rdparty/notepad-2/notepadApp.h b/demos/3rdparty/notepad-2/notepadApp.h index bae5f59c..04405223 100644 --- a/demos/3rdparty/notepad-2/notepadApp.h +++ b/demos/3rdparty/notepad-2/notepadApp.h @@ -28,6 +28,8 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Modified by InMarket to allow it to compile on any GFX supported operating system. */ #ifndef NOTEPADAPP_H_ @@ -36,13 +38,13 @@ #include "notepadCore.h" #include "notepadUIDefines.h" -#define NPAD_THD_PRIO (NORMALPRIO + 2) +#define NPAD_THD_PRIO NORMAL_PRIORITY #define NPAD_THD_WA_SIZE 512 void nSetColorScheme(NColorScheme sch); NColorScheme nGetColorScheme(void); -Thread *nLaunchNotepadApp(void); +gfxThreadHandle nLaunchNotepadApp(void); #endif /* NOTEPADAPP_H_ */ diff --git a/demos/3rdparty/notepad-2/notepadCore.c b/demos/3rdparty/notepad-2/notepadCore.c index abb189bc..931ec331 100644 --- a/demos/3rdparty/notepad-2/notepadCore.c +++ b/demos/3rdparty/notepad-2/notepadCore.c @@ -28,12 +28,12 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Modified by InMarket to allow it to compile on any GFX supported operating system. */ #include -#include "ch.h" -#include "hal.h" #include "gfx.h" #include "notepadCore.h" @@ -43,15 +43,17 @@ (ev.y >= ncoreDrawingArea->y) && (ev.y <= (ncoreDrawingArea->y + ncoreDrawingArea->height))) /* This is the drawing core */ -static WORKING_AREA(waDrawThread, NCORE_THD_STACK_SIZE); +static DECLARE_THREAD_STACK(waDrawThread, NCORE_THD_STACK_SIZE); static uint8_t nPenWidth = 1; static uint8_t nMode = NCORE_MODE_DRAW; -static Thread *nThd; +static gfxThreadHandle nThd; static GHandle ncoreDrawingArea = NULL; -static BaseSequentialStream *nStatusConsole = NULL; +static GHandle nStatusConsole = NULL; + +static volatile bool_t doExit; static void draw_point(coord_t x, coord_t y) { color_t c = ncoreDrawingArea->color; @@ -125,7 +127,7 @@ static void draw_line(coord_t x0, coord_t y0, coord_t x1, coord_t y1) { } /* Core thread */ -static msg_t ncoreDrawThread(void *msg) { +static DECLARE_THREAD_FUNCTION(ncoreDrawThread, msg) { GEventMouse ev, evPrev; coord_t dx, dy; @@ -136,11 +138,7 @@ static msg_t ncoreDrawThread(void *msg) { ginputGetMouseStatus(0, &evPrev); - while (1) { - - // Exit signal received? If yes, terminate. - if (chThdShouldTerminate()) - return 0; + while (!doExit) { ginputGetMouseStatus(0, &ev); switch(state) { @@ -153,13 +151,13 @@ static msg_t ncoreDrawThread(void *msg) { } } else - chThdYield(); + gfxYield(); break; case 1: if (ev.meta == GMETA_MOUSE_UP) { state = 0; - //chprintf(nStatusConsole, "\nPen Up: (%d, %d)", ev.x, ev.y); + //gwinPrintf(nStatusConsole, "\nPen Up: (%d, %d)", ev.x, ev.y); break; } @@ -191,7 +189,7 @@ static msg_t ncoreDrawThread(void *msg) { } } - //chprintf(nStatusConsole, "\nPen Down: (%d, %d)", ev.x, ev.y); + //gwinPrintf(nStatusConsole, "\nPen Down: (%d, %d)", ev.x, ev.y); } break; } @@ -202,12 +200,13 @@ static msg_t ncoreDrawThread(void *msg) { } /* Spawn the core thread */ -void ncoreSpawnDrawThread(GHandle drawingArea, BaseSequentialStream *statusConsole) { +void ncoreSpawnDrawThread(GHandle drawingArea, GHandle statusConsole) { ncoreDrawingArea = drawingArea; nStatusConsole = statusConsole; + doExit = FALSE; - nThd = chThdCreateStatic(waDrawThread, + nThd = gfxThreadCreate(waDrawThread, sizeof(waDrawThread), NCORE_THD_PRIO, ncoreDrawThread, @@ -217,8 +216,9 @@ void ncoreSpawnDrawThread(GHandle drawingArea, BaseSequentialStream *statusConso /* Terminate the core thread, wait for control release */ void ncoreTerminateDrawThread(void) { - chThdTerminate(nThd); - chThdWait(nThd); + doExit = TRUE; + gfxThreadWait(nThd); + nThd = 0; } /* Get and set the pen width diff --git a/demos/3rdparty/notepad-2/notepadCore.h b/demos/3rdparty/notepad-2/notepadCore.h index b4f1b185..937a023b 100644 --- a/demos/3rdparty/notepad-2/notepadCore.h +++ b/demos/3rdparty/notepad-2/notepadCore.h @@ -28,6 +28,8 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Modified by InMarket to allow it to compile on any GFX supported operating system. */ #ifndef NOTEPADCORE_H_ @@ -35,17 +37,17 @@ /* Configuration */ #define NCORE_THD_STACK_SIZE 256 -#define NCORE_THD_PRIO (NORMALPRIO + 1) +#define NCORE_THD_PRIO NORMAL_PRIORITY #define NCORE_MODE_DRAW 0 #define NCORE_MODE_ERASE 1 #define NCORE_MODE_FILL 2 -#define MAX_DX 500 -#define MAX_DY 500 +#define MAX_DX 5000 +#define MAX_DY 5000 /* Spawn the notepad core thread */ -void ncoreSpawnDrawThread(GHandle drawingArea, BaseSequentialStream *statusConsole); +void ncoreSpawnDrawThread(GHandle drawingArea, GHandle statusConsole); /* Terminate the core thread, wait for control release */ void ncoreTerminateDrawThread(void); diff --git a/demos/3rdparty/notepad-2/notepadUIDefines.h b/demos/3rdparty/notepad-2/notepadUIDefines.h index 5ed08d00..4d3aef9b 100644 --- a/demos/3rdparty/notepad-2/notepadUIDefines.h +++ b/demos/3rdparty/notepad-2/notepadUIDefines.h @@ -28,6 +28,8 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Modified by InMarket to allow it to compile on any GFX supported operating system. */ #ifndef NOTEPADUIDEFINES_H_ diff --git a/demos/3rdparty/notepad-2/toolbarIcons.gif b/demos/3rdparty/notepad-2/toolbarIcons.gif index 8a8518b2..fb9e7cc9 100644 Binary files a/demos/3rdparty/notepad-2/toolbarIcons.gif and b/demos/3rdparty/notepad-2/toolbarIcons.gif differ