From dc0f291350e8f44ceaf889c559f05342feacf6c9 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 25 Jun 2014 00:51:05 +1000 Subject: First cut eCos port --- src/gos/ecos.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gos/ecos.h | 106 +++++++++++++++++++++++++++++++++++++++++++++++ src/gos/sys_defs.h | 2 + src/gos/sys_options.h | 7 ++++ src/gos/sys_rules.h | 4 +- 5 files changed, 229 insertions(+), 2 deletions(-) create mode 100644 src/gos/ecos.c create mode 100644 src/gos/ecos.h (limited to 'src') diff --git a/src/gos/ecos.c b/src/gos/ecos.c new file mode 100644 index 00000000..5b94497a --- /dev/null +++ b/src/gos/ecos.c @@ -0,0 +1,112 @@ +/* + * 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" + +#if GFX_USE_OS_ECOS + +void _gosInit(void) +{ + /* Don't initialise if the user already has */ + //cyg_scheduler_start(); +} + +void _gosDeinit(void) +{ + /* ToDo */ +} + +void gfxSleepMilliseconds(delaytime_t ms) +{ + switch(ms) { + case TIME_IMMEDIATE: cyg_thread_yield(); return; + case TIME_INFINITE: cyg_thread_suspend(cyg_thread_self()); return; + default: cyg_thread_delay(gfxMillisecondsToTicks(ms)); return; + } +} + +void gfxSleepMicroseconds(delaytime_t ms) +{ + switch(ms) { + case TIME_IMMEDIATE: return; + case TIME_INFINITE: cyg_thread_suspend(cyg_thread_self()); return; + default: cyg_thread_delay(gfxMillisecondsToTicks(ms/1000)); return; + } +} + +void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit) +{ + if (val > limit) + val = limit; + + psem->limit = limit; + cyg_semaphore_init(&psem->sem, val); +} + +void gfxSemDestroy(gfxSem *psem) +{ + cyg_semaphore_destroy(&psem->sem); +} + +bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) +{ + switch(ms) { + case TIME_IMMEDIATE: return cyg_semaphore_trywait(&psem->sem); + case TIME_INFINITE: return cyg_semaphore_wait(&psem->sem); + default: return cyg_semaphore_timed_wait(&psem->sem, gfxMillisecondsToTicks(ms)+cyg_current_time()); + } +} + +bool_t gfxSemWaitI(gfxSem *psem) +{ + return cyg_semaphore_trywait(&psem->sem); +} + +void gfxSemSignal(gfxSem *psem) +{ + if (psem->limit == MAX_SEMAPHORE_COUNT) + cyg_semaphore_post(&psem->sem); + else { + cyg_scheduler_lock(); + if (gfxSemCounterI(psem) < psem->limit) + cyg_semaphore_post(&psem->sem); + cyg_scheduler_unlock(); + } +} + +void gfxSemSignalI(gfxSem *psem) +{ + if (psem->limit == MAX_SEMAPHORE_COUNT || gfxSemCounterI(psem) < 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; + + if (!stackarea) { + if (!stacksz) stacksz = CYGNUM_HAL_STACK_SIZE_TYPICAL; + if (!(stackarea = gfxAlloc(stacksz+sizeof(cyg_thread)))) + return 0; + } + + if (!stacksz) + return 0; + + cyg_thread_create(prio, fn, param, "uGFX", (((cyg_thread *)stackarea)+1), stacksz, &th, (cyg_thread *)stackarea); + cyg_thread_resume(th); + return th; +} + +#endif /* GFX_USE_OS_ECOS */ diff --git a/src/gos/ecos.h b/src/gos/ecos.h new file mode 100644 index 00000000..c24f3824 --- /dev/null +++ b/src/gos/ecos.h @@ -0,0 +1,106 @@ +/* + * 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 + */ + +#ifndef _GOS_ECOS_H +#define _GOS_ECOS_H + +#if GFX_USE_OS_ECOS + +#include +#include +#include + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +typedef cyg_bool_t bool_t; +typedef cyg_int8 int8_t; +typedef cyg_uint8 uint8_t; +typedef cyg_int16 int16_t; +typedef cyg_uint16 uint16_t; +typedef cyg_int32 int32_t; +typedef cyg_uint32 uint32_t; +typedef cyg_uint32 size_t; + +#define TRUE -1 +#define FALSE 0 +#define TIME_IMMEDIATE 0 +#define TIME_INFINITE 0xFFFFFFFF + +typedef cyg_ucount32 delaytime_t; +typedef cyg_tick_count_t systemticks_t; +typedef cyg_count32 semcount_t; +typedef void threadreturn_t; +typedef cyg_addrword_t threadpriority_t; +typedef cyg_handle_t gfxThreadHandle; + +#define MAX_SEMAPHORE_COUNT 0x7FFFFFFF +#define LOW_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES-2) +#define NORMAL_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES/2) +#define HIGH_PRIORITY 0 + +#define DECLARE_THREAD_STACK(name, sz) struct { cyg_thread t; unsigned char stk[sz]; } name[1] +#define DECLARE_THREAD_FUNCTION(fnName, param) threadreturn_t fnName(cyg_addrword_t param) + +typedef struct { + cyg_sem_t sem; + semcount_t limit; + } gfxSem; + +typedef cyg_mutex_t gfxMutex; + + +/*===========================================================================*/ +/* Function declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#define gfxSystemTicks() cyg_current_time() +#define gfxExit() exit(0) +#define gfxHalt(msg) exit(-1) +#define gfxYield() cyg_thread_yield() + +#define gfxMillisecondsToTicks(ms) (((ms)*(CYGNUM_HAL_RTC_DENOMINATOR*1000))/(CYGNUM_HAL_RTC_NUMERATOR/1000)) +void gfxSleepMilliseconds(delaytime_t ms); +void gfxSleepMicroseconds(delaytime_t ms); + +#define gfxAlloc(sz) malloc(sz) +#define gfxFree(ptr) free(sz) +#define gfxRealloc(ptr, oldsz, newsz) realloc(ptr, newsz) + +#define gfxSystemLock() cyg_scheduler_lock() +#define gfxSystemUnlock() cyg_scheduler_unlock() + +#define gfxMutexInit(pmutex) cyg_mutex_init(pmutex) +#define gfxMutexExit(pmutex) cyg_mutex_unlock(pmutex) +#define gfxMutexDestroy(pmutex) cyg_mutex_destroy(pmutex) +#define gfxMutexEnter(pmutex) cyg_mutex_lock(pmutex) + +void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit); +void gfxSemDestroy(gfxSem *psem); +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 +#define gfxThreadMe() cyg_thread_self() +#define gfxThreadClose(thread) (void)thread + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_OS_ECOS */ +#endif /* _GOS_ECOS_H */ diff --git a/src/gos/sys_defs.h b/src/gos/sys_defs.h index c55cdf73..9da9dff0 100644 --- a/src/gos/sys_defs.h +++ b/src/gos/sys_defs.h @@ -451,6 +451,8 @@ #include "src/gos/osx.h" #elif GFX_USE_OS_RAW32 #include "src/gos/raw32.h" +#elif GFX_USE_OS_ECOS + #include "src/gos/ecos.h" #else #error "Your operating system is not supported yet" #endif diff --git a/src/gos/sys_options.h b/src/gos/sys_options.h index cfbed057..c0cce08f 100644 --- a/src/gos/sys_options.h +++ b/src/gos/sys_options.h @@ -62,6 +62,13 @@ #ifndef GFX_USE_OS_RAW32 #define GFX_USE_OS_RAW32 FALSE #endif + /** + * @brief Use a eCos + * @details Defaults to FALSE + */ + #ifndef GFX_USE_OS_ECOS + #define GFX_USE_OS_ECOS FALSE + #endif /** * @} * diff --git a/src/gos/sys_rules.h b/src/gos/sys_rules.h index f23d330b..0da01ff2 100644 --- a/src/gos/sys_rules.h +++ b/src/gos/sys_rules.h @@ -16,7 +16,7 @@ #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 +#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 #if GFX_DISPLAY_RULE_WARNINGS #warning "GOS: No Operating System has been defined. ChibiOS (GFX_USE_OS_CHIBIOS) has been turned on for you." #endif @@ -24,7 +24,7 @@ #define GFX_USE_OS_CHIBIOS TRUE #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 != 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 != 1 * TRUE #error "GOS: More than one operation system has been defined as TRUE." #endif -- cgit v1.2.3 From 7f9a894587ab881ff47b6dddb17e0f441a7cfa59 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 3 Jul 2014 17:28:20 +1000 Subject: Missing gfxconf definitions for the RAW32 port --- src/gos/sys_options.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src') diff --git a/src/gos/sys_options.h b/src/gos/sys_options.h index cfbed057..c7376878 100644 --- a/src/gos/sys_options.h +++ b/src/gos/sys_options.h @@ -75,6 +75,19 @@ #ifndef GFX_FREERTOS_USE_TRACE #define GFX_FREERTOS_USE_TRACE FALSE #endif + /** + * @brief How much RAM should uGFX use for the heap + * @details Defaults to 0. Only valid with GFX_USE_OS_RAW32 + * @note If 0 then the standard C runtime malloc(), free() and realloc() + * are used. + * @note If it is non-zero then this is the number of bytes of RAM + * to use for the heap (gfxAlloc() and gfxFree()). No C + * runtime routines will be used and a new routine @p gfxAddHeapBlock() + * is added allowing the user to add extra memory blocks to the heap. + */ + #ifndef GOS_RAW_HEAP_SIZE + #define GOS_RAW_HEAP_SIZE 0 + #endif /** @} */ #endif /* _GOS_OPTIONS_H */ -- cgit v1.2.3 From 54a0387bd47df37d7f2e17bdeff4a99ea6d94163 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 4 Jul 2014 00:23:12 +0200 Subject: fixing doxygen typo --- src/gfile/sys_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gfile/sys_defs.h b/src/gfile/sys_defs.h index 4280f7fe..0c5bac0c 100644 --- a/src/gfile/sys_defs.h +++ b/src/gfile/sys_defs.h @@ -73,7 +73,7 @@ extern "C" { /** * @brief Get the size of a file - * @note Please use @p gfileGetSize() if the file is not opened + * @note Please use @p gfileGetSize() if the file is opened * * @param[in] fname The file name * -- cgit v1.2.3 From e4eba63f95b5abfad46dc45390e5709cf3ee61c4 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 4 Jul 2014 23:53:50 +0200 Subject: Frame widget doxygen fix --- src/gwin/frame.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gwin/frame.h b/src/gwin/frame.h index bf7cd2d8..fc5daf8e 100644 --- a/src/gwin/frame.h +++ b/src/gwin/frame.h @@ -45,8 +45,7 @@ typedef struct GFrameObject { /** * @brief Create a frame widget * - * @details This widget provides a window like we know it from desktop systems. You usually use this together with - * gwinAddChild(). + * @details This widget provides a window like we know it from desktop systems. * * @param[in] g The GDisplay to display this window on * @param[in] fo The GFrameObject structure to initialize. If this is NULL the structure is dynamically allocated. @@ -54,7 +53,7 @@ typedef struct GFrameObject { * @param[in] flags Some flags, see notes. * * @note Possible flags are: GWIN_FRAME_BORDER, GWIN_FRAME_CLOSE_BTN, GWIN_FRAME_MINMAX_BTN. - * Whether the close or the minimize maximize buttons are used, the boarder is automatically invoked. + * When the close or the minimize/maximize buttons are used, the boarder is automatically invoked. * @note These frame buttons are processed internally. The close button will invoke a gwinDestroy() which will * destroy the window itself and EVERY child it contains (also children of children). * -- cgit v1.2.3 From 2cc1dd96ea455f1f8e6d6b1e73ed19406eb629d2 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 5 Jul 2014 15:55:45 +0200 Subject: doxygen fix --- src/gwin/gimage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gwin/gimage.h b/src/gwin/gimage.h index 670a9ec4..0052f024 100644 --- a/src/gwin/gimage.h +++ b/src/gwin/gimage.h @@ -9,7 +9,7 @@ * @file src/gwin/gimage.h * @brief GWIN image widget header file. * - * @defgroup Image Image + * @defgroup ImageBox ImageBox * @ingroup Widgets * * @details GWIN allos it to create an image widget. The widget -- cgit v1.2.3 From 326e246b77a9260c17a002863fccb9b9da7748cb Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 11 Jul 2014 19:06:42 +0200 Subject: adding ecos port to makefile --- src/gos/sys_make.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gos/sys_make.mk b/src/gos/sys_make.mk index 8ef22121..9e24f875 100644 --- a/src/gos/sys_make.mk +++ b/src/gos/sys_make.mk @@ -4,4 +4,5 @@ GFXSRC += $(GFXLIB)/src/gos/chibios.c \ $(GFXLIB)/src/gos/linux.c \ $(GFXLIB)/src/gos/osx.c \ $(GFXLIB)/src/gos/raw32.c \ + $(GFXLIB)/src/gos/ecos.c -- cgit v1.2.3 From c8342a0d25ee62643a77727624d155e3dc1142de Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 11 Jul 2014 19:07:47 +0200 Subject: eCos: fixing gfxFree() routine --- src/gos/ecos.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gos/ecos.h b/src/gos/ecos.h index c24f3824..be9037b6 100644 --- a/src/gos/ecos.h +++ b/src/gos/ecos.h @@ -73,7 +73,7 @@ void gfxSleepMilliseconds(delaytime_t ms); void gfxSleepMicroseconds(delaytime_t ms); #define gfxAlloc(sz) malloc(sz) -#define gfxFree(ptr) free(sz) +#define gfxFree(ptr) free(ptr) #define gfxRealloc(ptr, oldsz, newsz) realloc(ptr, newsz) #define gfxSystemLock() cyg_scheduler_lock() -- cgit v1.2.3 From 1fe4bcde39507769255080b5e98c1c09119902f2 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 11 Jul 2014 20:41:50 +0200 Subject: Added gwinDrawThickLine() wrapper for corresponding GDISP call --- src/gwin/gwin.c | 6 ++++++ src/gwin/sys_defs.h | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index e1625b13..ab2e2981 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -226,6 +226,12 @@ void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1) { _gwinDrawEnd(gh); } +void gwinDrawThickLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1, coord_t width, bool_t round) { + if (!_gwinDrawStart(gh)) return; + gdispGDrawThickLine(gh->display, gh->x+x0, gh->y+y0, gh->x+x1, gh->y+y1, gh->color, width, round); + _gwinDrawEnd(gh); +} + void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { if (!_gwinDrawStart(gh)) return; gdispGDrawBox(gh->display, gh->x+x, gh->y+y, cx, cy, gh->color); diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index 830827b2..169b4498 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -600,6 +600,24 @@ extern "C" { */ void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1); + /** + * @brief Draw a thick line in the window + * @details The line thickness is specified in pixels. The line ends can + * be selected to be either flat or round. + * @note Uses gdispGFillConvexPoly() internally to perform the drawing. + * @note Uses the current foreground color to draw the line + * + * @param[in] gh The window handle + * @param[in] x0,y0 The start position + * @param[in] x1,y1 The end position + * @param[in] color The color to use + * @param[in] width The width of the line + * @param[in] round Use round ends for the line + * + * @api + */ + void gwinDrawThickLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1, coord_t width, bool_t round); + /** * @brief Draw a box in the window * @note Uses the current foreground color to draw the box -- cgit v1.2.3 From fdb3b86ee088ed4b263664f388742099c1210edb Mon Sep 17 00:00:00 2001 From: inmarket Date: Tue, 15 Jul 2014 12:40:43 +1000 Subject: Thick line support is only available if Polygon drawing is available --- src/gwin/gwin.c | 11 +++++------ src/gwin/sys_defs.h | 35 +++++++++++++++++------------------ 2 files changed, 22 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index ab2e2981..ee0a7222 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -226,12 +226,6 @@ void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1) { _gwinDrawEnd(gh); } -void gwinDrawThickLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1, coord_t width, bool_t round) { - if (!_gwinDrawStart(gh)) return; - gdispGDrawThickLine(gh->display, gh->x+x0, gh->y+y0, gh->x+x1, gh->y+y1, gh->color, width, round); - _gwinDrawEnd(gh); -} - void gwinDrawBox(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy) { if (!_gwinDrawStart(gh)) return; gdispGDrawBox(gh->display, gh->x+x, gh->y+y, cx, cy, gh->color); @@ -350,6 +344,11 @@ void gwinBlitArea(GHandle gh, coord_t x, coord_t y, coord_t cx, coord_t cy, coor gdispGFillConvexPoly(gh->display, tx+gh->x, ty+gh->y, pntarray, cnt, gh->color); _gwinDrawEnd(gh); } + void gwinDrawThickLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1, coord_t width, bool_t round) { + if (!_gwinDrawStart(gh)) return; + gdispGDrawThickLine(gh->display, gh->x+x0, gh->y+y0, gh->x+x1, gh->y+y1, gh->color, width, round); + _gwinDrawEnd(gh); + } #endif #if GDISP_NEED_IMAGE diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index 169b4498..4b103d11 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -600,24 +600,6 @@ extern "C" { */ void gwinDrawLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1); - /** - * @brief Draw a thick line in the window - * @details The line thickness is specified in pixels. The line ends can - * be selected to be either flat or round. - * @note Uses gdispGFillConvexPoly() internally to perform the drawing. - * @note Uses the current foreground color to draw the line - * - * @param[in] gh The window handle - * @param[in] x0,y0 The start position - * @param[in] x1,y1 The end position - * @param[in] color The color to use - * @param[in] width The width of the line - * @param[in] round Use round ends for the line - * - * @api - */ - void gwinDrawThickLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1, coord_t width, bool_t round); - /** * @brief Draw a box in the window * @note Uses the current foreground color to draw the box @@ -910,6 +892,23 @@ extern "C" { * @api */ void gwinFillConvexPoly(GHandle gh, coord_t tx, coord_t ty, const point *pntarray, unsigned cnt); + + /** + * @brief Draw a thick line in the window + * @details The line thickness is specified in pixels. The line ends can + * be selected to be either flat or round. + * @note Uses gdispGFillConvexPoly() internally to perform the drawing. + * @note Uses the current foreground color to draw the line + * + * @param[in] gh The window handle + * @param[in] x0,y0 The start position + * @param[in] x1,y1 The end position + * @param[in] width The width of the line + * @param[in] round Use round ends for the line + * + * @api + */ + void gwinDrawThickLine(GHandle gh, coord_t x0, coord_t y0, coord_t x1, coord_t y1, coord_t width, bool_t round); #endif /*------------------------------------------------- -- cgit v1.2.3