diff options
Diffstat (limited to 'src')
33 files changed, 948 insertions, 454 deletions
diff --git a/src/gadc/gadc.c b/src/gadc/gadc.c index ff1903c8..36f4db6d 100644 --- a/src/gadc/gadc.c +++ b/src/gadc/gadc.c @@ -12,8 +12,6 @@ * @addtogroup GADC * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GADC @@ -33,16 +31,15 @@ volatile bool_t GADC_Timer_Missed; -static SEMAPHORE_DECL(gadcsem, GADC_MAX_LOWSPEED_DEVICES); -static MUTEX_DECL(gadcmutex); -static GTIMER_DECL(LowSpeedGTimer); +static gfxSem gadcsem; +static gfxMutex gadcmutex; +static GTimer LowSpeedGTimer; #if GFX_USE_GEVENT - static GTIMER_DECL(HighSpeedGTimer); + static GTimer HighSpeedGTimer; #endif static volatile uint16_t gflags = 0; - #define GADC_GFLG_INITDONE 0x0001 - #define GADC_GFLG_ISACTIVE 0x0002 + #define GADC_GFLG_ISACTIVE 0x0001 #define GADC_FLG_ISACTIVE 0x0001 #define GADC_FLG_ISDONE 0x0002 @@ -64,11 +61,11 @@ static struct hsdev { adcsample_t *lastbuffer; uint16_t lastflags; - // Other stuff we need to track progress and for signalling + // Other stuff we need to track progress and for signaling GadcLldTimerData lld; size_t samplesPerConversion; size_t remaining; - BinarySemaphore *bsem; + gfxSem *bsem; GEventADC *pEvent; GADCISRCallbackFunction isrfn; } hs; @@ -175,7 +172,7 @@ void GADC_ISR_CompleteI(ADCDriver *adcp, adcsample_t *buffer, size_t n) { hs.isrfn(buffer, n); if (hs.bsem) - chBSemSignalI(hs.bsem); + gfxSemSignalI(hs.bsem); #if GFX_USE_GEVENT if (hs.flags & GADC_FLG_GTIMER) @@ -238,25 +235,29 @@ void GADC_ISR_ErrorI(ADCDriver *adcp, adcerror_t err) { FindNextConversionI(); } -static inline void DoInit(void) { - if (!(gflags & GADC_GFLG_INITDONE)) { - gflags |= GADC_GFLG_INITDONE; - gadc_lld_init(); - } +/* Our module initialiser */ +void _gadcInit(void) { + gadc_lld_init(); + gfxSemInit(&gadcsem, GADC_MAX_LOWSPEED_DEVICES, GADC_MAX_LOWSPEED_DEVICES); + gfxMutexInit(&gadcmutex); + gtimerInit(&LowSpeedGTimer); + #if GFX_USE_GEVENT + gtimerInit(&HighSpeedGTimer); + #endif } static inline void StartADC(bool_t onNoHS) { - chSysLock(); + gfxSystemLock(); if (!(gflags & GADC_GFLG_ISACTIVE) || (onNoHS && !curlsdev)) FindNextConversionI(); - chSysUnlock(); + gfxSystemUnlock(); } static void BSemSignalCallback(adcsample_t *buffer, void *param) { (void) buffer; /* Signal the BinarySemaphore parameter */ - chBSemSignal((BinarySemaphore *)param); + gfxSemSignal((gfxSem *)param); } #if GFX_USE_GEVENT @@ -310,7 +311,7 @@ static void LowSpeedGTimerCallback(void *param) { p->param = 0; // Needed to prevent the compiler removing the local variables p->lld.buffer = 0; // Needed to prevent the compiler removing the local variables p->flags = 0; // The slot is available (indivisible operation) - chSemSignal(&gadcsem); // Tell everyone + gfxSemSignal(&gadcsem); // Tell everyone fn(buffer, prm); // Perform the callback } } @@ -342,7 +343,6 @@ void gadcHighSpeedInit(uint32_t physdev, uint32_t frequency, adcsample_t *buffer #if GFX_USE_GEVENT GSourceHandle gadcHighSpeedGetSource(void) { - DoInit(); if (!gtimerIsActive(&HighSpeedGTimer)) gtimerStart(&HighSpeedGTimer, HighSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE); hs.flags |= GADC_FLG_GTIMER; @@ -354,19 +354,15 @@ void gadcHighSpeedSetISRCallback(GADCISRCallbackFunction isrfn) { hs.isrfn = isrfn; } -void gadcHighSpeedSetBSem(BinarySemaphore *pbsem, GEventADC *pEvent) { - DoInit(); - +void gadcHighSpeedSetBSem(gfxSem *pbsem, GEventADC *pEvent) { /* Use the system lock to ensure they occur atomically */ - chSysLock(); + gfxSystemLock(); hs.pEvent = pEvent; hs.bsem = pbsem; - chSysUnlock(); + gfxSystemUnlock(); } void gadcHighSpeedStart(void) { - DoInit(); - /* If its already going we don't need to do anything */ if (hs.flags & GADC_FLG_ISACTIVE) return; @@ -377,8 +373,6 @@ void gadcHighSpeedStart(void) { } void gadcHighSpeedStop(void) { - DoInit(); - if (hs.flags & GADC_FLG_ISACTIVE) { /* No more from us */ hs.flags = 0; @@ -392,21 +386,22 @@ void gadcHighSpeedStop(void) { } void gadcLowSpeedGet(uint32_t physdev, adcsample_t *buffer) { - struct lsdev *p; - BSEMAPHORE_DECL(mysem, TRUE); + struct lsdev *p; + gfxSem mysem; /* Start the Low Speed Timer */ - chMtxLock(&gadcmutex); + gfxSemInit(&mysem, 1, 1); + gfxMutexEnter(&gadcmutex); if (!gtimerIsActive(&LowSpeedGTimer)) gtimerStart(&LowSpeedGTimer, LowSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE); - chMtxUnlock(); + gfxMutexExit(&gadcmutex); while(1) { /* Wait for an available slot */ - chSemWait(&gadcsem); + gfxSemWait(&gadcsem, TIME_INFINITE); /* Find a slot */ - chMtxLock(&gadcmutex); + gfxMutexEnter(&gadcmutex); for(p = ls; p < &ls[GADC_MAX_LOWSPEED_DEVICES]; p++) { if (!(p->flags & GADC_FLG_ISACTIVE)) { p->lld.physdev = physdev; @@ -414,13 +409,13 @@ void gadcLowSpeedGet(uint32_t physdev, adcsample_t *buffer) { p->fn = BSemSignalCallback; p->param = &mysem; p->flags = GADC_FLG_ISACTIVE; - chMtxUnlock(); + gfxMutexExit(&gadcmutex); StartADC(FALSE); - chBSemWait(&mysem); + gfxSemWait(&mysem, TIME_INFINITE); return; } } - chMtxUnlock(); + gfxMutexExit(&gadcmutex); /** * We should never get here - the count semaphore must be wrong. @@ -432,10 +427,8 @@ void gadcLowSpeedGet(uint32_t physdev, adcsample_t *buffer) { bool_t gadcLowSpeedStart(uint32_t physdev, adcsample_t *buffer, GADCCallbackFunction fn, void *param) { struct lsdev *p; - DoInit(); - /* Start the Low Speed Timer */ - chMtxLock(&gadcmutex); + gfxMutexEnter(&gadcmutex); if (!gtimerIsActive(&LowSpeedGTimer)) gtimerStart(&LowSpeedGTimer, LowSpeedGTimerCallback, NULL, TRUE, TIME_INFINITE); @@ -443,18 +436,18 @@ bool_t gadcLowSpeedStart(uint32_t physdev, adcsample_t *buffer, GADCCallbackFunc for(p = ls; p < &ls[GADC_MAX_LOWSPEED_DEVICES]; p++) { if (!(p->flags & GADC_FLG_ISACTIVE)) { /* We know we have a slot - this should never wait anyway */ - chSemWaitTimeout(&gadcsem, TIME_IMMEDIATE); + gfxSemWait(&gadcsem, TIME_IMMEDIATE); p->lld.physdev = physdev; p->lld.buffer = buffer; p->fn = fn; p->param = param; p->flags = GADC_FLG_ISACTIVE; - chMtxUnlock(); + gfxMutexExit(&gadcmutex); StartADC(FALSE); return TRUE; } } - chMtxUnlock(); + gfxMutexExit(&gadcmutex); return FALSE; } diff --git a/src/gaudin/gaudin.c b/src/gaudin/gaudin.c index 3a9d23b8..2e87c628 100644 --- a/src/gaudin/gaudin.c +++ b/src/gaudin/gaudin.c @@ -12,8 +12,6 @@ * @addtogroup GAUDIN * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GAUDIN @@ -22,7 +20,7 @@ #include "gaudin/lld/gaudin_lld.h" static gaudin_params aud; -static BinarySemaphore *paudSem; +static gfxSem *paudSem; static GEventAudioIn *paudEvent; static audin_sample_t *lastbuffer; static size_t lastcount; @@ -31,7 +29,7 @@ static uint16_t audFlags; #define AUDFLG_USE_EVENTS 0x0002 #if GFX_USE_GEVENT - static GTIMER_DECL(AudGTimer); + static GTimer AudGTimer; static void AudGTimerCallback(void *param) { (void) param; @@ -75,7 +73,7 @@ void GAUDIN_ISR_CompleteI(audin_sample_t *buffer, size_t n) { /* Our two signalling mechanisms */ if (paudSem) - chBSemSignalI(paudSem); + gfxSemSignalI(paudSem); #if GFX_USE_GEVENT if (audFlags & AUDFLG_USE_EVENTS) @@ -87,6 +85,13 @@ void GAUDIN_ISR_ErrorI(void) { /* Ignore any errors for now */ } +/* The module initialiser */ +void _gaudinInit(void) { + #if GFX_USE_GEVENT + gtimerInit(&AudGTimer); + #endif +} + bool_t gaudinInit(uint16_t channel, uint32_t frequency, audin_sample_t *buffer, size_t bufcount, size_t samplesPerEvent) { /* Check the channel is valid */ if (channel >= GAUDIN_NUM_CHANNELS || frequency > GAUDIN_MAX_SAMPLE_FREQUENCY) @@ -120,11 +125,11 @@ bool_t gaudinInit(uint16_t channel, uint32_t frequency, audin_sample_t *buffer, } #endif -void gaudinSetBSem(BinarySemaphore *pbsem, GEventAudioIn *pEvent) { - chSysLock(); +void gaudinSetBSem(gfxSem *pbsem, GEventAudioIn *pEvent) { + gfxSystemLock(); paudSem = pbsem; paudEvent = pEvent; - chSysUnlock(); + gfxSystemUnlock(); } void gaudinStart(void) { diff --git a/src/gaudout/gaudout.c b/src/gaudout/gaudout.c index 3b4051ff..b418b158 100644 --- a/src/gaudout/gaudout.c +++ b/src/gaudout/gaudout.c @@ -12,8 +12,6 @@ * @addtogroup GAUDOUT * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GAUDOUT || defined(__DOXYGEN__) diff --git a/src/gdisp/fonts.c b/src/gdisp/fonts.c index 3d29e50c..175828c6 100644 --- a/src/gdisp/fonts.c +++ b/src/gdisp/fonts.c @@ -10,12 +10,9 @@ * @brief GDISP Font Handling. * * @addtogroup GDISP - * * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GDISP && GDISP_NEED_TEXT diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c index 069bc577..b316be49 100644 --- a/src/gdisp/gdisp.c +++ b/src/gdisp/gdisp.c @@ -12,8 +12,6 @@ * @addtogroup GDISP * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GDISP @@ -26,44 +24,22 @@ #include "gdisp/lld/gdisp_lld.h" /*===========================================================================*/ -/* Driver local definitions. */ -/*===========================================================================*/ - -#if GDISP_NEED_MULTITHREAD - #if !CH_USE_MUTEXES - #error "GDISP: CH_USE_MUTEXES must be defined in chconf.h because GDISP_NEED_MULTITHREAD is defined" - #endif -#endif - -#if GDISP_NEED_ASYNC - #if !CH_USE_MAILBOXES || !CH_USE_MUTEXES || !CH_USE_SEMAPHORES - #error "GDISP: CH_USE_MAILBOXES, CH_USE_SEMAPHORES and CH_USE_MUTEXES must be defined in chconf.h because GDISP_NEED_ASYNC is defined" - #endif -#endif - -/*===========================================================================*/ -/* Driver exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ /* Driver local variables. */ /*===========================================================================*/ #if GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC - static Mutex gdispMutex; + static gfxMutex gdispMutex; #endif #if GDISP_NEED_ASYNC - #define GDISP_THREAD_STACK_SIZE 512 /* Just a number - not yet a reflection of actual use */ + #define GDISP_THREAD_STACK_SIZE 256 /* Just a number - not yet a reflection of actual use */ #define GDISP_QUEUE_SIZE 8 /* We only allow a short queue */ - static Thread * lldThread; - static Mailbox gdispMailbox; - static msg_t gdispMailboxQueue[GDISP_QUEUE_SIZE]; - static Semaphore gdispMsgsSem; - static Mutex gdispMsgsMutex; + static gfxQueue gdispQueue; + static gfxMutex gdispMsgsMutex; + static gfxSem gdispMsgsSem; static gdisp_lld_msg_t gdispMsgs[GDISP_QUEUE_SIZE]; - static WORKING_AREA(waGDISPThread, GDISP_THREAD_STACK_SIZE); + static DECLARESTACK(waGDISPThread, GDISP_THREAD_STACK_SIZE); #endif /*===========================================================================*/ @@ -71,26 +47,23 @@ /*===========================================================================*/ #if GDISP_NEED_ASYNC - static msg_t GDISPThreadHandler(void *arg) { + static threadreturn_t GDISPThreadHandler(void *arg) { (void)arg; gdisp_lld_msg_t *pmsg; - #if CH_USE_REGISTRY - chRegSetThreadName("GDISPAsyncAPI"); - #endif - while(1) { /* Wait for msg with work to do. */ - chMBFetch(&gdispMailbox, (msg_t *)&pmsg, TIME_INFINITE); + pmsg = (gdisp_lld_msg_t *)gfxQueueGet(&gdispQueue, TIME_INFINITE); /* OK - we need to obtain the mutex in case a synchronous operation is occurring */ - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); + gdisp_lld_msg_dispatch(pmsg); - chMtxUnlock(); /* Mark the message as free */ pmsg->action = GDISP_LLD_MSG_NOP; - chSemSignal(&gdispMsgsSem); + + gfxMutexExit(&gdispMutex); } return 0; } @@ -101,22 +74,22 @@ while(1) { /* To be sure, to be sure */ /* Wait for a slot */ - chSemWait(&gdispMsgsSem); + gfxSemWait(&gdispMsgsSem, TIME_INFINITE); /* Find the slot */ - chMtxLock(&gdispMsgsMutex); + gfxMutexEnter(&gdispMsgsMutex); for(p=gdispMsgs; p < &gdispMsgs[GDISP_QUEUE_SIZE]; p++) { if (p->action == GDISP_LLD_MSG_NOP) { /* Allocate it */ p->action = action; - chMtxUnlock(); + gfxMutexExit(&gdispMsgsMutex); return p; } } - chMtxUnlock(); + gfxMutexExit(&gdispMsgsMutex); /* Oops - none found, try again */ - chSemSignal(&gdispMsgsSem); + gfxSemSignal(&gdispMsgsSem); } } #endif @@ -125,46 +98,40 @@ /* Driver exported functions. */ /*===========================================================================*/ +/* Our module initialiser */ #if GDISP_NEED_MULTITHREAD - bool_t gdispInit(void) { - bool_t res; - + void _gdispInit(void) { /* Initialise Mutex */ - chMtxInit(&gdispMutex); + gfxMutexInit(&gdispMutex); /* Initialise driver */ - chMtxLock(&gdispMutex); - res = gdisp_lld_init(); - chMtxUnlock(); - - return res; + gfxMutexEnter(&gdispMutex); + gdisp_lld_init(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ASYNC - bool_t gdispInit(void) { - bool_t res; + void _gdispInit(void) { unsigned i; /* Mark all the Messages as free */ for(i=0; i < GDISP_QUEUE_SIZE; i++) gdispMsgs[i].action = GDISP_LLD_MSG_NOP; - /* Initialise our Mailbox, Mutex's and Counting Semaphore. - * A Mutex is required as well as the Mailbox and Thread because some calls have to be synchronous. + /* Initialise our Queue, Mutex's and Counting Semaphore. + * A Mutex is required as well as the Queue and Thread because some calls have to be synchronous. * Synchronous calls get handled by the calling thread, asynchronous by our worker thread. */ - chMBInit(&gdispMailbox, gdispMailboxQueue, sizeof(gdispMailboxQueue)/sizeof(gdispMailboxQueue[0])); - chMtxInit(&gdispMutex); - chMtxInit(&gdispMsgsMutex); - chSemInit(&gdispMsgsSem, GDISP_QUEUE_SIZE); + gfxQueueInit(&gdispQueue); + gfxMutexInit(&gdispMutex); + gfxMutexInit(&gdispMsgsMutex); + gfxSemInit(&gdispMsgsSem, GDISP_QUEUE_SIZE, GDISP_QUEUE_SIZE); - lldThread = chThdCreateStatic(waGDISPThread, sizeof(waGDISPThread), NORMALPRIO, GDISPThreadHandler, NULL); + gfxCreateThread(waGDISPThread, sizeof(waGDISPThread), NORMAL_PRIORITY, GDISPThreadHandler, NULL); /* Initialise driver - synchronous */ - chMtxLock(&gdispMutex); - res = gdisp_lld_init(); - chMtxUnlock(); - - return res; + gfxMutexEnter(&gdispMutex); + gdisp_lld_init(); + gfxMutexExit(&gdispMutex); } #endif @@ -174,29 +141,29 @@ } #elif GDISP_NEED_ASYNC bool_t gdispIsBusy(void) { - return chMBGetUsedCountI(&gdispMailbox) != FALSE; + return !gfxQueueIsEmpty(&gdispQueue); } #endif #if GDISP_NEED_MULTITHREAD void gdispClear(color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_clear(color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ASYNC void gdispClear(color_t color) { gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_CLEAR); p->clear.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if GDISP_NEED_MULTITHREAD void gdispDrawPixel(coord_t x, coord_t y, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_draw_pixel(x, y, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ASYNC void gdispDrawPixel(coord_t x, coord_t y, color_t color) { @@ -204,15 +171,15 @@ p->drawpixel.x = x; p->drawpixel.y = y; p->drawpixel.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if GDISP_NEED_MULTITHREAD void gdispDrawLine(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_draw_line(x0, y0, x1, y1, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ASYNC void gdispDrawLine(coord_t x0, coord_t y0, coord_t x1, coord_t y1, color_t color) { @@ -222,15 +189,15 @@ p->drawline.x1 = x1; p->drawline.y1 = y1; p->drawline.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if GDISP_NEED_MULTITHREAD void gdispFillArea(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_fill_area(x, y, cx, cy, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ASYNC void gdispFillArea(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { @@ -240,15 +207,15 @@ p->fillarea.cx = cx; p->fillarea.cy = cy; p->fillarea.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if GDISP_NEED_MULTITHREAD void gdispBlitAreaEx(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_blit_area_ex(x, y, cx, cy, srcx, srcy, srccx, buffer); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ASYNC void gdispBlitAreaEx(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t srcx, coord_t srcy, coord_t srccx, const pixel_t *buffer) { @@ -261,15 +228,15 @@ p->blitarea.srcy = srcy; p->blitarea.srccx = srccx; p->blitarea.buffer = buffer; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_CLIP && GDISP_NEED_MULTITHREAD) void gdispSetClip(coord_t x, coord_t y, coord_t cx, coord_t cy) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_set_clip(x, y, cx, cy); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_CLIP && GDISP_NEED_ASYNC void gdispSetClip(coord_t x, coord_t y, coord_t cx, coord_t cy) { @@ -278,15 +245,15 @@ p->setclip.y = y; p->setclip.cx = cx; p->setclip.cy = cy; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_CIRCLE && GDISP_NEED_MULTITHREAD) void gdispDrawCircle(coord_t x, coord_t y, coord_t radius, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_draw_circle(x, y, radius, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_CIRCLE && GDISP_NEED_ASYNC void gdispDrawCircle(coord_t x, coord_t y, coord_t radius, color_t color) { @@ -295,15 +262,15 @@ p->drawcircle.y = y; p->drawcircle.radius = radius; p->drawcircle.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_CIRCLE && GDISP_NEED_MULTITHREAD) void gdispFillCircle(coord_t x, coord_t y, coord_t radius, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_fill_circle(x, y, radius, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_CIRCLE && GDISP_NEED_ASYNC void gdispFillCircle(coord_t x, coord_t y, coord_t radius, color_t color) { @@ -312,15 +279,15 @@ p->fillcircle.y = y; p->fillcircle.radius = radius; p->fillcircle.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_ELLIPSE && GDISP_NEED_MULTITHREAD) void gdispDrawEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_draw_ellipse(x, y, a, b, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ELLIPSE && GDISP_NEED_ASYNC void gdispDrawEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { @@ -330,15 +297,15 @@ p->drawellipse.a = a; p->drawellipse.b = b; p->drawellipse.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_ELLIPSE && GDISP_NEED_MULTITHREAD) void gdispFillEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_fill_ellipse(x, y, a, b, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ELLIPSE && GDISP_NEED_ASYNC void gdispFillEllipse(coord_t x, coord_t y, coord_t a, coord_t b, color_t color) { @@ -348,15 +315,15 @@ p->fillellipse.a = a; p->fillellipse.b = b; p->fillellipse.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD) void gdispDrawArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_draw_arc(x, y, radius, start, end, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ARC && GDISP_NEED_ASYNC void gdispDrawArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) { @@ -367,15 +334,15 @@ p->drawarc.start = start; p->drawarc.end = end; p->drawarc.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_ARC && GDISP_NEED_MULTITHREAD) void gdispFillArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_fill_arc(x, y, radius, start, end, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_ARC && GDISP_NEED_ASYNC void gdispFillArc(coord_t x, coord_t y, coord_t radius, coord_t start, coord_t end, color_t color) { @@ -386,7 +353,7 @@ p->fillarc.start = start; p->fillarc.end = end; p->fillarc.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif @@ -428,9 +395,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r #if (GDISP_NEED_TEXT && GDISP_NEED_MULTITHREAD) void gdispDrawChar(coord_t x, coord_t y, char c, font_t font, color_t color) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_draw_char(x, y, c, font, color); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_TEXT && GDISP_NEED_ASYNC void gdispDrawChar(coord_t x, coord_t y, char c, font_t font, color_t color) { @@ -440,15 +407,15 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r p->drawchar.c = c; p->drawchar.font = font; p->drawchar.color = color; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_TEXT && GDISP_NEED_MULTITHREAD) void gdispFillChar(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_fill_char(x, y, c, font, color, bgcolor); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_TEXT && GDISP_NEED_ASYNC void gdispFillChar(coord_t x, coord_t y, char c, font_t font, color_t color, color_t bgcolor) { @@ -459,7 +426,7 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r p->fillchar.font = font; p->fillchar.color = color; p->fillchar.bgcolor = bgcolor; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif @@ -468,9 +435,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r color_t c; /* Always synchronous as it must return a value */ - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); c = gdisp_lld_get_pixel_color(x, y); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); return c; } @@ -478,9 +445,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r #if (GDISP_NEED_SCROLL && GDISP_NEED_MULTITHREAD) void gdispVerticalScroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_vertical_scroll(x, y, cx, cy, lines, bgcolor); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_SCROLL && GDISP_NEED_ASYNC void gdispVerticalScroll(coord_t x, coord_t y, coord_t cx, coord_t cy, int lines, color_t bgcolor) { @@ -491,23 +458,22 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r p->verticalscroll.cy = cy; p->verticalscroll.lines = lines; p->verticalscroll.bgcolor = bgcolor; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif #if (GDISP_NEED_CONTROL && GDISP_NEED_MULTITHREAD) void gdispControl(unsigned what, void *value) { - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); gdisp_lld_control(what, value); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); } #elif GDISP_NEED_CONTROL && GDISP_NEED_ASYNC void gdispControl(unsigned what, void *value) { gdisp_lld_msg_t *p = gdispAllocMsg(GDISP_LLD_MSG_CONTROL); p->control.what = what; p->control.value = value; - chMBPost(&gdispMailbox, (msg_t)p, TIME_INFINITE); - chThdSleepMilliseconds(100); + gfxQueuePut(&gdispQueue, &p->qi, TIME_IMMEDIATE); } #endif @@ -515,9 +481,9 @@ void gdispFillRoundedBox(coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t r void *gdispQuery(unsigned what) { void *res; - chMtxLock(&gdispMutex); + gfxMutexEnter(&gdispMutex); res = gdisp_lld_query(what); - chMtxUnlock(); + gfxMutexExit(&gdispMutex); return res; } #endif @@ -564,7 +530,7 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { void gdispFillConvexPoly(coord_t tx, coord_t ty, const point *pntarray, unsigned cnt, color_t color) { const point *lpnt, *rpnt, *epnts; - fpcoord_t lx, rx, lk, rk; + fixed lx, rx, lk, rk; coord_t y, ymax, lxc, rxc; epnts = &pntarray[cnt-1]; @@ -575,13 +541,13 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { if (lpnt->y < rpnt->y) rpnt = lpnt; } - lx = rx = rpnt->x<<16; + lx = rx = FIXED(rpnt->x); y = rpnt->y; /* Work out the slopes of the two attached line segs */ lpnt = rpnt <= pntarray ? epnts : rpnt-1; while (lpnt->y == y) { - lx = lpnt->x<<16; + lx = FIXED(lpnt->x); lpnt = lpnt <= pntarray ? epnts : lpnt-1; if (!cnt--) return; } @@ -591,8 +557,8 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { rpnt = rpnt >= epnts ? pntarray : rpnt+1; if (!cnt--) return; } - lk = (((fpcoord_t)(lpnt->x)<<16) - lx) / (lpnt->y - y); - rk = (((fpcoord_t)(rpnt->x)<<16) - rx) / (rpnt->y - y); + lk = (FIXED(lpnt->x) - lx) / (lpnt->y - y); + rk = (FIXED(rpnt->x) - rx) / (rpnt->y - y); while(1) { /* Determine our boundary */ @@ -600,8 +566,8 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { /* Scan down the line segments until we hit a boundary */ for(; y < ymax; y++) { - lxc = lx>>16; - rxc = rx>>16; + lxc = NONFIXED(lx); + rxc = NONFIXED(rx); /* * Doesn't print the right hand point in order to allow polygon joining. * Also ensures that we draw from left to right with the minimum number @@ -629,19 +595,19 @@ void gdispDrawBox(coord_t x, coord_t y, coord_t cx, coord_t cy, color_t color) { if (ymax == lpnt->y) { lpnt = lpnt <= pntarray ? epnts : lpnt-1; while (lpnt->y == y) { - lx = lpnt->x<<16; + lx = FIXED(lpnt->x); lpnt = lpnt <= pntarray ? epnts : lpnt-1; if (!cnt--) return; } - lk = (((fpcoord_t)(lpnt->x)<<16) - lx) / (lpnt->y - y); + lk = (FIXED(lpnt->x) - lx) / (lpnt->y - y); } else { rpnt = rpnt >= epnts ? pntarray : rpnt+1; while (rpnt->y == y) { - rx = rpnt->x<<16; + rx = FIXED(rpnt->x); rpnt = rpnt >= epnts ? pntarray : rpnt+1; if (!cnt--) return; } - rk = (((fpcoord_t)(rpnt->x)<<16) - rx) / (rpnt->y - y); + rk = (FIXED(rpnt->x) - rx) / (rpnt->y - y); } } } diff --git a/src/gdisp/image.c b/src/gdisp/image.c index 2a648e59..50b641b6 100644 --- a/src/gdisp/image.c +++ b/src/gdisp/image.c @@ -12,8 +12,6 @@ * @defgroup Image Image * @ingroup GDISP */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GDISP && GDISP_NEED_IMAGE @@ -27,7 +25,7 @@ typedef struct gdispImageHandlers { coord_t x, coord_t y, coord_t cx, coord_t cy, coord_t sx, coord_t sy); /* The draw function */ - systime_t (*next)(gdispImage *img); /* The next frame function */ + delaytime_t (*next)(gdispImage *img); /* The next frame function */ } gdispImageHandlers; static gdispImageHandlers ImageHandlers[] = { @@ -85,72 +83,79 @@ bool_t gdispImageSetMemoryReader(gdispImage *img, const void *memimage) { return TRUE; } -static size_t ImageBaseFileStreamRead(struct gdispImageIO *pio, void *buf, size_t len) { - if (pio->fd == (void *)-1) return 0; - len = chSequentialStreamRead(((BaseFileStream *)pio->fd), (uint8_t *)buf, len); - pio->pos += len; - return len; -} +#if GFX_USE_OS_CHIBIOS + static size_t ImageBaseFileStreamRead(struct gdispImageIO *pio, void *buf, size_t len) { + if (pio->fd == (void *)-1) return 0; + len = chSequentialStreamRead(((BaseFileStream *)pio->fd), (uint8_t *)buf, len); + pio->pos += len; + return len; + } -static void ImageBaseFileStreamSeek(struct gdispImageIO *pio, size_t pos) { - if (pio->fd == (void *)-1) return; - if (pio->pos != pos) { - chFileStreamSeek(((BaseFileStream *)pio->fd), pos); - pio->pos = pos; + static void ImageBaseFileStreamSeek(struct gdispImageIO *pio, size_t pos) { + if (pio->fd == (void *)-1) return; + if (pio->pos != pos) { + chFileStreamSeek(((BaseFileStream *)pio->fd), pos); + pio->pos = pos; + } } -} -static void ImageBaseFileStreamClose(struct gdispImageIO *pio) { - if (pio->fd == (void *)-1) return; - chFileStreamClose(((BaseFileStream *)pio->fd)); - pio->fd = (void *)-1; - pio->pos = 0; -} + static void ImageBaseFileStreamClose(struct gdispImageIO *pio) { + if (pio->fd == (void *)-1) return; + chFileStreamClose(((BaseFileStream *)pio->fd)); + pio->fd = (void *)-1; + pio->pos = 0; + } -static const gdispImageIOFunctions ImageBaseFileStreamFunctions = - { ImageBaseFileStreamRead, ImageBaseFileStreamSeek, ImageBaseFileStreamClose }; + static const gdispImageIOFunctions ImageBaseFileStreamFunctions = + { ImageBaseFileStreamRead, ImageBaseFileStreamSeek, ImageBaseFileStreamClose }; -bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr) { - img->io.fns = &ImageBaseFileStreamFunctions; - img->io.pos = 0; - img->io.fd = BaseFileStreamPtr; - return TRUE; -} + bool_t gdispImageSetBaseFileStreamReader(gdispImage *img, void *BaseFileStreamPtr) { + img->io.fns = &ImageBaseFileStreamFunctions; + img->io.pos = 0; + img->io.fd = BaseFileStreamPtr; + return TRUE; + } +#endif -#if defined(WIN32) - #include <fcntl.h> +#if defined(WIN32) || GFX_USE_OS_WIN32 || GFX_USE_OS_POSIX + #include <stdio.h> - static size_t ImageSimulFileRead(struct gdispImageIO *pio, void *buf, size_t len) { - if (pio->fd == (void *)-1) return 0; - len = read((int)pio->fd, buf, len); + static size_t ImageFileRead(struct gdispImageIO *pio, void *buf, size_t len) { + if (!pio->fd) return 0; + len = fread(buf, 1, len, (FILE *)pio->fd); if ((int)len < 0) len = 0; pio->pos += len; return len; } - static void ImageSimulFileSeek(struct gdispImageIO *pio, size_t pos) { - if (pio->fd == (void *)-1) return; + static void ImageFileSeek(struct gdispImageIO *pio, size_t pos) { + if (!pio->fd) return; if (pio->pos != pos) { - lseek((int)pio->fd, pos, SEEK_SET); + fseek((FILE *)pio->fd, pos, SEEK_SET); pio->pos = pos; } } - static void ImageSimulFileClose(struct gdispImageIO *pio) { - if (pio->fd == (void *)-1) return; - close((int)pio->fd); - pio->fd = (void *)-1; + static void ImageFileClose(struct gdispImageIO *pio) { + if (!pio->fd) return; + fclose((FILE *)pio->fd); + pio->fd = 0; pio->pos = 0; } - static const gdispImageIOFunctions ImageSimulFileFunctions = - { ImageSimulFileRead, ImageSimulFileSeek, ImageSimulFileClose }; + static const gdispImageIOFunctions ImageFileFunctions = + { ImageFileRead, ImageFileSeek, ImageFileClose }; - bool_t gdispImageSetSimulFileReader(gdispImage *img, const char *filename) { - img->io.fns = &ImageSimulFileFunctions; + bool_t gdispImageSetFileReader(gdispImage *img, const char *filename) { + img->io.fns = &ImageFileFunctions; img->io.pos = 0; - img->io.fd = (void *)open(filename, O_RDONLY|O_BINARY); - return img->io.fd != (void *)-1; + #if defined(WIN32) || GFX_USE_OS_WIN32 + img->io.fd = (void *)fopen(filename, "rb"); + #else + img->io.fd = (void *)fopen(filename, "r"); + #endif + + return img->io.fd != 0; } #endif @@ -195,7 +200,7 @@ gdispImageError gdispImageDraw(gdispImage *img, coord_t x, coord_t y, coord_t cx return img->fns->draw(img, x, y, cx, cy, sx, sy); } -systime_t gdispImageNext(gdispImage *img) { +delaytime_t gdispImageNext(gdispImage *img) { if (!img->fns) return GDISP_IMAGE_ERR_BADFORMAT; return img->fns->next(img); } @@ -205,7 +210,7 @@ void *gdispImageAlloc(gdispImage *img, size_t sz) { #if GDISP_NEED_IMAGE_ACCOUNTING void *ptr; - ptr = chHeapAlloc(NULL, sz); + ptr = gfxAlloc(sz); if (ptr) { img->memused += sz; if (img->memused > img->maxmemused) @@ -214,18 +219,18 @@ void *gdispImageAlloc(gdispImage *img, size_t sz) { return ptr; #else (void) img; - return chHeapAlloc(NULL, sz); + return gfxAlloc(sz); #endif } void gdispImageFree(gdispImage *img, void *ptr, size_t sz) { #if GDISP_NEED_IMAGE_ACCOUNTING - chHeapFree(ptr); + gfxFree(ptr); img->memused -= sz; #else (void) img; (void) sz; - chHeapFree(ptr); + gfxFree(ptr); #endif } diff --git a/src/gdisp/image_bmp.c b/src/gdisp/image_bmp.c index 830ee327..51d1ce91 100644 --- a/src/gdisp/image_bmp.c +++ b/src/gdisp/image_bmp.c @@ -12,8 +12,6 @@ * @defgroup Image Image * @ingroup GDISP */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_BMP @@ -895,7 +893,7 @@ gdispImageError gdispImageDraw_BMP(gdispImage *img, coord_t x, coord_t y, coord_ return GDISP_IMAGE_ERR_OK; } -systime_t gdispImageNext_BMP(gdispImage *img) { +delaytime_t gdispImageNext_BMP(gdispImage *img) { (void) img; /* No more frames/pages */ diff --git a/src/gdisp/image_gif.c b/src/gdisp/image_gif.c index 6c61219a..e8f4f422 100644 --- a/src/gdisp/image_gif.c +++ b/src/gdisp/image_gif.c @@ -12,8 +12,6 @@ * @defgroup Image Image * @ingroup GDISP */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_GIF @@ -1161,15 +1159,15 @@ baddatacleanup: return GDISP_IMAGE_ERR_BADDATA; } -systime_t gdispImageNext_GIF(gdispImage *img) { +delaytime_t gdispImageNext_GIF(gdispImage *img) { gdispImagePrivate * priv; - systime_t delay; + delaytime_t delay; uint8_t blocksz; priv = img->priv; // Save the delay and convert to millisecs - delay = (systime_t)priv->frame.delay * 10; + delay = (delaytime_t)priv->frame.delay * 10; // We need to get to the end of this frame if (!priv->frame.posend) { diff --git a/src/gdisp/image_jpg.c b/src/gdisp/image_jpg.c index 05c9ef37..3a51ea5f 100644 --- a/src/gdisp/image_jpg.c +++ b/src/gdisp/image_jpg.c @@ -9,8 +9,6 @@ * @file src/gdisp/image_jpg.c * @brief GDISP native image code. */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_JPG diff --git a/src/gdisp/image_native.c b/src/gdisp/image_native.c index 6da4e862..8cc15817 100644 --- a/src/gdisp/image_native.c +++ b/src/gdisp/image_native.c @@ -8,12 +8,7 @@ /** * @file src/gdisp/image_native.c * @brief GDISP native image code. - * - * @defgroup Image Image - * @ingroup GDISP */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_NATIVE @@ -139,7 +134,7 @@ gdispImageError gdispImageDraw_NATIVE(gdispImage *img, coord_t x, coord_t y, coo return GDISP_IMAGE_ERR_OK; } -systime_t gdispImageNext_NATIVE(gdispImage *img) { +delaytime_t gdispImageNext_NATIVE(gdispImage *img) { (void) img; /* No more frames/pages */ diff --git a/src/gdisp/image_png.c b/src/gdisp/image_png.c index 1cfba97f..76e8f652 100644 --- a/src/gdisp/image_png.c +++ b/src/gdisp/image_png.c @@ -8,12 +8,7 @@ /** * @file src/gdisp/image_png.c * @brief GDISP native image code. - * - * @defgroup Image Image - * @ingroup GDISP -*/ -#include "ch.h" -#include "hal.h" + */ #include "gfx.h" #if GFX_USE_GDISP && GDISP_NEED_IMAGE && GDISP_NEED_IMAGE_PNG diff --git a/src/gevent/gevent.c b/src/gevent/gevent.c index a8c7a63a..676fc8cb 100644 --- a/src/gevent/gevent.c +++ b/src/gevent/gevent.c @@ -12,8 +12,6 @@ * @addtogroup GEVENT * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GEVENT || defined(__DOXYGEN__) @@ -25,7 +23,7 @@ #endif /* This mutex protects access to our tables */ -static MUTEX_DECL(geventMutex); +static gfxMutex geventMutex; /* Our table of listener/source pairs */ static GSourceListener Assignments[GEVENT_MAX_SOURCE_LISTENERS]; @@ -37,22 +35,26 @@ static void deleteAssignments(GListener *pl, GSourceHandle gsh) { for(psl = Assignments; psl < Assignments+GEVENT_MAX_SOURCE_LISTENERS; psl++) { if ((!pl || psl->pListener == pl) && (!gsh || psl->pSource == gsh)) { - if (chSemGetCounterI(&psl->pListener->waitqueue) < 0) { - chBSemWait(&psl->pListener->eventlock); // Obtain the buffer lock - psl->pListener->event.type = GEVENT_EXIT; // Set up the EXIT event - chSemSignal(&psl->pListener->waitqueue); // Wake up the listener - chBSemSignal(&psl->pListener->eventlock); // Release the buffer lock + if (gfxSemCounter(&psl->pListener->waitqueue) < 0) { + gfxSemWait(&psl->pListener->eventlock, TIME_INFINITE); // Obtain the buffer lock + psl->pListener->event.type = GEVENT_EXIT; // Set up the EXIT event + gfxSemSignal(&psl->pListener->waitqueue); // Wake up the listener + gfxSemSignal(&psl->pListener->eventlock); // Release the buffer lock } psl->pListener = 0; } } } +void _geventInit(void) { + gfxMutexInit(&geventMutex); +} + void geventListenerInit(GListener *pl) { - chSemInit(&pl->waitqueue, 0); // Next wait'er will block - chBSemInit(&pl->eventlock, FALSE); // Only one thread at a time looking at the event buffer - pl->callback = 0; // No callback active - pl->event.type = GEVENT_NULL; // Always safety + gfxSemInit(&pl->waitqueue, 0, MAX_SEMAPHORE_COUNT); // Next wait'er will block + gfxSemInit(&pl->eventlock, 1, 1); // Only one thread at a time looking at the event buffer + pl->callback = 0; // No callback active + pl->event.type = GEVENT_NULL; // Always safety } bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) { @@ -64,7 +66,7 @@ bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) { return FALSE; } - chMtxLock(&geventMutex); + gfxMutexEnter(&geventMutex); // Check if this pair is already in the table (scan for a free slot at the same time) pslfree = 0; @@ -72,10 +74,10 @@ bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) { if (pl == psl->pListener && gsh == psl->pSource) { // Just update the flags - chBSemWait(&pl->eventlock); // Safety first - just in case a source is using it + gfxSemWait(&pl->eventlock, TIME_INFINITE); // Safety first - just in case a source is using it psl->listenflags = flags; - chBSemSignal(&pl->eventlock); // Release this lock - chMtxUnlock(); + gfxSemSignal(&pl->eventlock); // Release this lock + gfxMutexExit(&geventMutex); return TRUE; } if (!pslfree && !psl->pListener) @@ -89,43 +91,43 @@ bool_t geventAttachSource(GListener *pl, GSourceHandle gsh, unsigned flags) { pslfree->listenflags = flags; pslfree->srcflags = 0; } - chMtxUnlock(); + gfxMutexExit(&geventMutex); GEVENT_ASSERT(pslfree != 0); return pslfree != 0; } void geventDetachSource(GListener *pl, GSourceHandle gsh) { if (pl) { - chMtxLock(&geventMutex); + gfxMutexEnter(&geventMutex); deleteAssignments(pl, gsh); - if (!gsh && chSemGetCounterI(&pl->waitqueue) < 0) { - chBSemWait(&pl->eventlock); // Obtain the buffer lock - pl->event.type = GEVENT_EXIT; // Set up the EXIT event - chSemSignal(&pl->waitqueue); // Wake up the listener - chBSemSignal(&pl->eventlock); // Release the buffer lock + if (!gsh && gfxSemCounter(&pl->waitqueue) < 0) { + gfxSemWait(&pl->eventlock, TIME_INFINITE); // Obtain the buffer lock + pl->event.type = GEVENT_EXIT; // Set up the EXIT event + gfxSemSignal(&pl->waitqueue); // Wake up the listener + gfxSemSignal(&pl->eventlock); // Release the buffer lock } - chMtxUnlock(); + gfxMutexExit(&geventMutex); } } -GEvent *geventEventWait(GListener *pl, systime_t timeout) { - if (pl->callback || chSemGetCounterI(&pl->waitqueue) < 0) +GEvent *geventEventWait(GListener *pl, delaytime_t timeout) { + if (pl->callback || gfxSemCounter(&pl->waitqueue) < 0) return 0; - return chSemWaitTimeout(&pl->waitqueue, timeout) == RDY_OK ? &pl->event : 0; + return gfxSemWait(&pl->waitqueue, timeout) ? &pl->event : 0; } void geventRegisterCallback(GListener *pl, GEventCallbackFn fn, void *param) { if (pl) { - chMtxLock(&geventMutex); - chBSemWait(&pl->eventlock); // Obtain the buffer lock - pl->param = param; // Set the param - pl->callback = fn; // Set the callback function - if (chSemGetCounterI(&pl->waitqueue) < 0) { + gfxMutexEnter(&geventMutex); + gfxSemWait(&pl->eventlock, TIME_INFINITE); // Obtain the buffer lock + pl->param = param; // Set the param + pl->callback = fn; // Set the callback function + if (gfxSemCounter(&pl->waitqueue) < 0) { pl->event.type = GEVENT_EXIT; // Set up the EXIT event - chSemSignal(&pl->waitqueue); // Wake up the listener + gfxSemSignal(&pl->waitqueue); // Wake up the listener } - chBSemSignal(&pl->eventlock); // Release the buffer lock - chMtxUnlock(); + gfxSemSignal(&pl->eventlock); // Release the buffer lock + gfxMutexExit(&geventMutex); } } @@ -136,48 +138,48 @@ GSourceListener *geventGetSourceListener(GSourceHandle gsh, GSourceListener *las if (!gsh) return 0; - chMtxLock(&geventMutex); + gfxMutexEnter(&geventMutex); // Unlock the last listener event buffer if (lastlr) - chBSemSignal(&lastlr->pListener->eventlock); + gfxSemSignal(&lastlr->pListener->eventlock); // Loop through the table looking for attachments to this source for(psl = lastlr ? (lastlr+1) : Assignments; psl < Assignments+GEVENT_MAX_SOURCE_LISTENERS; psl++) { if (gsh == psl->pSource) { - chBSemWait(&psl->pListener->eventlock); // Obtain a lock on the listener event buffer - chMtxUnlock(); + gfxSemWait(&psl->pListener->eventlock, TIME_INFINITE); // Obtain a lock on the listener event buffer + gfxMutexExit(&geventMutex); return psl; } } - chMtxUnlock(); + gfxMutexExit(&geventMutex); return 0; } GEvent *geventGetEventBuffer(GSourceListener *psl) { // We already know we have the event lock - return &psl->pListener->callback || chSemGetCounterI(&psl->pListener->waitqueue) < 0 ? &psl->pListener->event : 0; + return &psl->pListener->callback || gfxSemCounter(&psl->pListener->waitqueue) < 0 ? &psl->pListener->event : 0; } void geventSendEvent(GSourceListener *psl) { - chMtxLock(&geventMutex); + gfxMutexEnter(&geventMutex); if (psl->pListener->callback) { // This test needs to be taken inside the mutex - chMtxUnlock(); + gfxMutexExit(&geventMutex); // We already know we have the event lock psl->pListener->callback(psl->pListener->param, &psl->pListener->event); } else { // Wake up the listener - if (chSemGetCounterI(&psl->pListener->waitqueue) < 0) - chSemSignal(&psl->pListener->waitqueue); - chMtxUnlock(); + if (gfxSemCounter(&psl->pListener->waitqueue) < 0) + gfxSemSignal(&psl->pListener->waitqueue); + gfxMutexExit(&geventMutex); } } void geventDetachSourceListeners(GSourceHandle gsh) { - chMtxLock(&geventMutex); + gfxMutexEnter(&geventMutex); deleteAssignments(0, gsh); - chMtxUnlock(); + gfxMutexExit(&geventMutex); } #endif /* GFX_USE_GEVENT */ diff --git a/src/gfx.c b/src/gfx.c new file mode 100644 index 00000000..c14dffb0 --- /dev/null +++ b/src/gfx.c @@ -0,0 +1,107 @@ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu <joel@unormal.org> + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/** + * @file src/gfx.c + * @brief GFX common routines. + */ + +/* Display various warnings from gfx_rules.h */ +#define GFX_DISPLAY_RULE_WARNINGS TRUE + +#include "gfx.h" + +/* These init functions are defined by each module but not published */ +extern void _gosInit(void); +#if GFX_USE_GDISP && (GDISP_NEED_MULTITHREAD || GDISP_NEED_ASYNC) + extern void _gdispInit(void); +#endif +#if GFX_USE_TDISP + extern void _tdispInit(void); +#endif +#if GFX_USE_GWIN + extern void _gwinInit(void); +#endif +#if GFX_USE_GEVENT + extern void _geventInit(void); +#endif +#if GFX_USE_GTIMER + extern void _gtimerInit(void); +#endif +#if GFX_USE_GINPUT + extern void _ginputInit(void); +#endif +#if GFX_USE_GADC + extern void _gadcInit(void); +#endif +#if GFX_USE_GAUDIN + extern void _gaudinInit(void); +#endif +#if GFX_USE_GAUDOUT + extern void _gaudoutInit(void); +#endif +#if GFX_USE_GMISC + extern void _gmiscInit(void); +#endif + +void gfxInit(void) { + static bool_t initDone = FALSE; + + /* Ensure we only initialise once */ + if (initDone) + return; + initDone = TRUE; + + /* These must be initialised in the order of their dependancies */ + _gosInit(); + #if GFX_USE_GMISC + _gmiscInit(); + #endif + #if GFX_USE_GEVENT + _geventInit(); + #endif + #if GFX_USE_GTIMER + _gtimerInit(); + #endif + #if GFX_USE_GDISP + _gdispInit(); + gdispClear(Black); + #endif + #if GFX_USE_GWIN + _gwinInit(); + #endif + #if GFX_USE_GINPUT + _ginputInit(); + #endif + #if GFX_USE_TDISP + _tdispInit(); + tdispHome(); + tdispClear(); + #endif + #if GFX_USE_GADC + _gadcInit(); + #endif + #if GFX_USE_GAUDIN + _gaudinInit(); + #endif + #if GFX_USE_GAUDOUT + _gaudoutInit(); + #endif +} diff --git a/src/ginput/dial.c b/src/ginput/dial.c index c8bc7d0f..24836910 100644 --- a/src/ginput/dial.c +++ b/src/ginput/dial.c @@ -13,8 +13,6 @@ * @ingroup GINPUT * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GINPUT && GINPUT_NEED_DIAL diff --git a/src/ginput/ginput.c b/src/ginput/ginput.c new file mode 100644 index 00000000..96fa1449 --- /dev/null +++ b/src/ginput/ginput.c @@ -0,0 +1,26 @@ +/* + * This file is subject to the terms of the GFX License, v1.0. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://chibios-gfx.com/license.html + */ + +/** + * @file src/ginput/ginput.c + * @brief GINPUT subsystem common code. + * + * @addtogroup GINPUT + * @{ + */ +#include "gfx.h" + +#if GFX_USE_GINPUT + +/** + * This should really call an init routine for each ginput sub-system. + * Maybe we'll do this later. + */ +void _ginputInit(void) {} + +#endif /* GFX_USE_GINPUT */ +/** @} */ diff --git a/src/ginput/ginput.mk b/src/ginput/ginput.mk index 06bcfc07..ed34d46d 100644 --- a/src/ginput/ginput.mk +++ b/src/ginput/ginput.mk @@ -1,4 +1,5 @@ -GFXSRC += $(GFXLIB)/src/ginput/mouse.c \
+GFXSRC += $(GFXLIB)/src/ginput/ginput.c \
+ $(GFXLIB)/src/ginput/mouse.c \
$(GFXLIB)/src/ginput/keyboard.c \
$(GFXLIB)/src/ginput/toggle.c \
$(GFXLIB)/src/ginput/dial.c
diff --git a/src/ginput/keyboard.c b/src/ginput/keyboard.c index 26d90ba9..99aa90e8 100644 --- a/src/ginput/keyboard.c +++ b/src/ginput/keyboard.c @@ -1,9 +1,9 @@ -/* - * This file is subject to the terms of the GFX License, v1.0. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://chibios-gfx.com/license.html - */ +/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/ginput/keyboard.c
@@ -15,8 +15,6 @@ * @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_KEYBOARD) || defined(__DOXYGEN__)
diff --git a/src/ginput/mouse.c b/src/ginput/mouse.c index 7320cf2d..334fdb6c 100644 --- a/src/ginput/mouse.c +++ b/src/ginput/mouse.c @@ -13,8 +13,6 @@ * @ingroup GINPUT * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) || defined(__DOXYGEN__) @@ -58,7 +56,7 @@ static struct MouseConfig_t { MouseReading t; MousePoint movepos; MousePoint clickpos; - systime_t clicktime; + systemticks_t clicktime; uint16_t last_buttons; uint16_t flags; #define FLG_INIT_DONE 0x8000 @@ -253,7 +251,7 @@ static void MousePoll(void *param) { if ((tbtns & (GINPUT_MOUSE_BTN_LEFT|GINPUT_MOUSE_BTN_RIGHT))) { MouseConfig.clickpos.x = MouseConfig.t.x; MouseConfig.clickpos.y = MouseConfig.t.y; - MouseConfig.clicktime = chTimeNow(); + MouseConfig.clicktime = gfxSystemTicks(); MouseConfig.flags |= FLG_CLICK_TIMER; } @@ -265,7 +263,7 @@ static void MousePoll(void *param) { if ((MouseConfig.flags & FLG_CLICK_TIMER)) { if ((tbtns & GINPUT_MOUSE_BTN_LEFT) #if GINPUT_MOUSE_CLICK_TIME != TIME_INFINITE - && chTimeNow() - MouseConfig.clicktime < MS2ST(GINPUT_MOUSE_CLICK_TIME) + && gfxSystemTicks() - MouseConfig.clicktime < gfxMillisecondsToTicks(GINPUT_MOUSE_CLICK_TIME) #endif ) meta |= GMETA_MOUSE_CLICK; @@ -338,7 +336,7 @@ GSourceHandle ginputGetMouse(uint16_t instance) { MouseConfig.caldata = pc[0]; MouseConfig.flags |= (FLG_CAL_OK|FLG_CAL_SAVED); if ((MouseConfig.flags & FLG_CAL_FREE)) - chHeapFree((void *)pc); + gfxFree((void *)pc); } else if (instance == 9999) { MouseConfig.caldata.ax = 1; MouseConfig.caldata.bx = 0; @@ -367,7 +365,7 @@ GSourceHandle ginputGetMouse(uint16_t instance) { bool_t ginputGetMouseStatus(uint16_t instance, GEventMouse *pe) { // Win32 threads don't seem to recognise priority and/or pre-emption // so we add a sleep here to prevent 100% polled applications from locking up. - chThdSleepMilliseconds(1); + gfxSleepMilliseconds(1); if (instance || (MouseConfig.flags & (FLG_INIT_DONE|FLG_IN_CAL)) != FLG_INIT_DONE) return FALSE; @@ -443,11 +441,11 @@ bool_t ginputCalibrateMouse(uint16_t instance) { /* Wait for the mouse to be pressed */ while(get_raw_reading(&MouseConfig.t), !(MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT)) - chThdSleepMilliseconds(20); + gfxSleepMilliseconds(20); /* Average all the samples while the mouse is down */ for(px = py = 0, j = 0; - chThdSleepMilliseconds(20), /* Settling time between readings */ + gfxSleepMilliseconds(20), /* Settling time between readings */ get_raw_reading(&MouseConfig.t), (MouseConfig.t.buttons & GINPUT_MOUSE_BTN_LEFT); j++) { @@ -464,7 +462,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { if (i >= 1 && pt->x == (pt-1)->x && pt->y == (pt-1)->y) { gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_SAME_TEXT, font2, Red, Yellow, justifyCenter); - chThdSleepMilliseconds(5000); + gfxSleepMilliseconds(5000); gdispFillArea(0, 35, width, 40, Blue); } @@ -492,7 +490,7 @@ bool_t ginputCalibrateMouse(uint16_t instance) { break; gdispFillStringBox(0, 35, width, 40, GINPUT_MOUSE_CALIBRATION_ERROR_TEXT, font2, Red, Yellow, justifyCenter); - chThdSleepMilliseconds(5000); + gfxSleepMilliseconds(5000); } #endif diff --git a/src/ginput/toggle.c b/src/ginput/toggle.c index a2474c3e..2784a6ef 100644 --- a/src/ginput/toggle.c +++ b/src/ginput/toggle.c @@ -1,9 +1,9 @@ -/* - * This file is subject to the terms of the GFX License, v1.0. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://chibios-gfx.com/license.html - */ +/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/ginput/toggle.c
@@ -13,8 +13,6 @@ * @ingroup GINPUT
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) || defined(__DOXYGEN__)
@@ -134,7 +132,7 @@ void ginputInvertToggle(uint16_t instance, bool_t invert) { bool_t ginputGetToggleStatus(uint16_t instance, GEventToggle *ptoggle) {
// Win32 threads don't seem to recognise priority and/or pre-emption
// so we add a sleep here to prevent 100% polled applications from locking up.
- chThdSleepMilliseconds(1);
+ gfxSleepMilliseconds(1);
if (instance >= GINPUT_TOGGLE_NUM_PORTS)
return FALSE;
diff --git a/src/gmisc/arrayops.c b/src/gmisc/arrayops.c index e5f06072..460387f6 100644 --- a/src/gmisc/arrayops.c +++ b/src/gmisc/arrayops.c @@ -1,9 +1,9 @@ -/* - * This file is subject to the terms of the GFX License, v1.0. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://chibios-gfx.com/license.html - */ +/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/gmisc/arrayops.c
@@ -12,11 +12,9 @@ * @addtogroup GMISC
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
-#if (GFX_USE_GMISC && GMISC_NEED_ARRAYOPS) || defined(__DOXYGEN__)
+#if GFX_USE_GMISC && GMISC_NEED_ARRAYOPS
void gmiscArrayConvert(ArrayDataFormat srcfmt, void *src, ArrayDataFormat dstfmt, void *dst, size_t cnt) {
uint8_t *src8, *dst8;
diff --git a/src/gmisc/gmisc.mk b/src/gmisc/gmisc.mk index 7e4caea8..a4ec787e 100644 --- a/src/gmisc/gmisc.mk +++ b/src/gmisc/gmisc.mk @@ -1 +1,2 @@ -GFXSRC += $(GFXLIB)/src/gmisc/arrayops.c
+GFXSRC += $(GFXLIB)/src/gmisc/arrayops.c \
+ $(GFXLIB)/src/gmisc/trig.c
diff --git a/src/gmisc/trig.c b/src/gmisc/trig.c new file mode 100644 index 00000000..2cd90a53 --- /dev/null +++ b/src/gmisc/trig.c @@ -0,0 +1,159 @@ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu <joel@unormal.org> + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/** + * @file src/gmisc/trig.c + * @brief GMISC Trig Functions. + * + * @addtogroup GMISC + * @{ + */ +#include "gfx.h" + +#if GFX_USE_GMISC + +#if GMISC_NEED_FASTTRIG + const double sintabledouble[] = { + 0.000000, 0.017452, 0.034899, 0.052336, 0.069756, 0.087156, 0.104528, 0.121869, + 0.139173, 0.156434, 0.173648, 0.190809, 0.207912, 0.224951, 0.241922, 0.258819, + 0.275637, 0.292372, 0.309017, 0.325568, 0.342020, 0.358368, 0.374607, 0.390731, + 0.406737, 0.422618, 0.438371, 0.453990, 0.469472, 0.484810, 0.500000, 0.515038, + 0.529919, 0.544639, 0.559193, 0.573576, 0.587785, 0.601815, 0.615661, 0.629320, + 0.642788, 0.656059, 0.669131, 0.681998, 0.694658, 0.707107, 0.719340, 0.731354, + 0.743145, 0.754710, 0.766044, 0.777146, 0.788011, 0.798636, 0.809017, 0.819152, + 0.829038, 0.838671, 0.848048, 0.857167, 0.866025, 0.874620, 0.882948, 0.891007, + 0.898794, 0.906308, 0.913545, 0.920505, 0.927184, 0.933580, 0.939693, 0.945519, + 0.951057, 0.956305, 0.961262, 0.965926, 0.970296, 0.974370, 0.978148, 0.981627, + 0.984808, 0.987688, 0.990268, 0.992546, 0.994522, 0.996195, 0.997564, 0.998630, + 0.999391, 0.999848, 1.000000, 0.999848, 0.999391, 0.998630, 0.997564, 0.996195, + 0.994522, 0.992546, 0.990268, 0.987688, 0.984808, 0.981627, 0.978148, 0.974370, + 0.970296, 0.965926, 0.961262, 0.956305, 0.951057, 0.945519, 0.939693, 0.933580, + 0.927184, 0.920505, 0.913545, 0.906308, 0.898794, 0.891007, 0.882948, 0.874620, + 0.866025, 0.857167, 0.848048, 0.838671, 0.829038, 0.819152, 0.809017, 0.798636, + 0.788011, 0.777146, 0.766044, 0.754710, 0.743145, 0.731354, 0.719340, 0.707107, + 0.694658, 0.681998, 0.669131, 0.656059, 0.642788, 0.629320, 0.615661, 0.601815, + 0.587785, 0.573576, 0.559193, 0.544639, 0.529919, 0.515038, 0.500000, 0.484810, + 0.469472, 0.453990, 0.438371, 0.422618, 0.406737, 0.390731, 0.374607, 0.358368, + 0.342020, 0.325568, 0.309017, 0.292372, 0.275637, 0.258819, 0.241922, 0.224951, + 0.207912, 0.190809, 0.173648, 0.156434, 0.139173, 0.121869, 0.104528, 0.087156, + 0.069756, 0.052336, 0.034899, 0.017452, 0.000000, -0.017452, -0.034899, -0.052336, + -0.069756, -0.087156, -0.104528, -0.121869, -0.139173, -0.156434, -0.173648, -0.190809, + -0.207912, -0.224951, -0.241922, -0.258819, -0.275637, -0.292372, -0.309017, -0.325568, + -0.342020, -0.358368, -0.374607, -0.390731, -0.406737, -0.422618, -0.438371, -0.453990, + -0.469472, -0.484810, -0.500000, -0.515038, -0.529919, -0.544639, -0.559193, -0.573576, + -0.587785, -0.601815, -0.615661, -0.629320, -0.642788, -0.656059, -0.669131, -0.681998, + -0.694658, -0.707107, -0.719340, -0.731354, -0.743145, -0.754710, -0.766044, -0.777146, + -0.788011, -0.798636, -0.809017, -0.819152, -0.829038, -0.838671, -0.848048, -0.857167, + -0.866025, -0.874620, -0.882948, -0.891007, -0.898794, -0.906308, -0.913545, -0.920505, + -0.927184, -0.933580, -0.939693, -0.945519, -0.951057, -0.956305, -0.961262, -0.965926, + -0.970296, -0.974370, -0.978148, -0.981627, -0.984808, -0.987688, -0.990268, -0.992546, + -0.994522, -0.996195, -0.997564, -0.998630, -0.999391, -0.999848, -1.000000, -0.999848, + -0.999391, -0.998630, -0.997564, -0.996195, -0.994522, -0.992546, -0.990268, -0.987688, + -0.984808, -0.981627, -0.978148, -0.974370, -0.970296, -0.965926, -0.961262, -0.956305, + -0.951057, -0.945519, -0.939693, -0.933580, -0.927184, -0.920505, -0.913545, -0.906308, + -0.898794, -0.891007, -0.882948, -0.874620, -0.866025, -0.857167, -0.848048, -0.838671, + -0.829038, -0.819152, -0.809017, -0.798636, -0.788011, -0.777146, -0.766044, -0.754710, + -0.743145, -0.731354, -0.719340, -0.707107, -0.694658, -0.681998, -0.669131, -0.656059, + -0.642788, -0.629320, -0.615661, -0.601815, -0.587785, -0.573576, -0.559193, -0.544639, + -0.529919, -0.515038, -0.500000, -0.484810, -0.469472, -0.453990, -0.438371, -0.422618, + -0.406737, -0.390731, -0.374607, -0.358368, -0.342020, -0.325568, -0.309017, -0.292372, + -0.275637, -0.258819, -0.241922, -0.224951, -0.207912, -0.190809, -0.173648, -0.156434, + -0.139173, -0.121869, -0.104528, -0.087156, -0.069756, -0.052336, -0.034899, -0.017452 + }; + + double fsin(int degrees) { + if (degrees < 0) + degrees -= (degrees/360-1)*360; + else if (degrees >= 360) + degrees %= 360; + return sintabledouble[degrees]; + } + + double fcos(int degrees) { + return fsin(degrees+90); + } + +#endif + +#if GMISC_NEED_FIXEDTRIG + const fixed sintablefixed[] = { + 0, 1143, 2287, 3429, 4571, 5711, 6850, 7986, + 9120, 10252, 11380, 12504, 13625, 14742, 15854, 16961, + 18064, 19160, 20251, 21336, 22414, 23486, 24550, 25606, + 26655, 27696, 28729, 29752, 30767, 31772, 32767, 33753, + 34728, 35693, 36647, 37589, 38521, 39440, 40347, 41243, + 42125, 42995, 43852, 44695, 45525, 46340, 47142, 47929, + 48702, 49460, 50203, 50931, 51643, 52339, 53019, 53683, + 54331, 54963, 55577, 56175, 56755, 57319, 57864, 58393, + 58903, 59395, 59870, 60326, 60763, 61183, 61583, 61965, + 62328, 62672, 62997, 63302, 63589, 63856, 64103, 64331, + 64540, 64729, 64898, 65047, 65176, 65286, 65376, 65446, + 65496, 65526, 65536, 65526, 65496, 65446, 65376, 65286, + 65176, 65047, 64898, 64729, 64540, 64331, 64103, 63856, + 63589, 63302, 62997, 62672, 62328, 61965, 61583, 61183, + 60763, 60326, 59870, 59395, 58903, 58393, 57864, 57319, + 56755, 56175, 55577, 54963, 54331, 53683, 53019, 52339, + 51643, 50931, 50203, 49460, 48702, 47929, 47142, 46340, + 45525, 44695, 43852, 42995, 42125, 41243, 40347, 39440, + 38521, 37589, 36647, 35693, 34728, 33753, 32767, 31772, + 30767, 29752, 28729, 27696, 26655, 25606, 24550, 23486, + 22414, 21336, 20251, 19160, 18064, 16961, 15854, 14742, + 13625, 12504, 11380, 10252, 9120, 7986, 6850, 5711, + 4571, 3429, 2287, 1143, 0, -1143, -2287, -3429, + -4571, -5711, -6850, -7986, -9120, -10252, -11380, -12504, + -13625, -14742, -15854, -16961, -18064, -19160, -20251, -21336, + -22414, -23486, -24550, -25606, -26655, -27696, -28729, -29752, + -30767, -31772, -32768, -33753, -34728, -35693, -36647, -37589, + -38521, -39440, -40347, -41243, -42125, -42995, -43852, -44695, + -45525, -46340, -47142, -47929, -48702, -49460, -50203, -50931, + -51643, -52339, -53019, -53683, -54331, -54963, -55577, -56175, + -56755, -57319, -57864, -58393, -58903, -59395, -59870, -60326, + -60763, -61183, -61583, -61965, -62328, -62672, -62997, -63302, + -63589, -63856, -64103, -64331, -64540, -64729, -64898, -65047, + -65176, -65286, -65376, -65446, -65496, -65526, -65536, -65526, + -65496, -65446, -65376, -65286, -65176, -65047, -64898, -64729, + -64540, -64331, -64103, -63856, -63589, -63302, -62997, -62672, + -62328, -61965, -61583, -61183, -60763, -60326, -59870, -59395, + -58903, -58393, -57864, -57319, -56755, -56175, -55577, -54963, + -54331, -53683, -53019, -52339, -51643, -50931, -50203, -49460, + -48702, -47929, -47142, -46340, -45525, -44695, -43852, -42995, + -42125, -41243, -40347, -39440, -38521, -37589, -36647, -35693, + -34728, -33753, -32768, -31772, -30767, -29752, -28729, -27696, + -26655, -25606, -24550, -23486, -22414, -21336, -20251, -19160, + -18064, -16961, -15854, -14742, -13625, -12504, -11380, -10252, + -9120, -7986, -6850, -5711, -4571, -3429, -2287, -1143 + }; + + fixed ffsin(int degrees) { + if (degrees < 0) + degrees -= (degrees/360-1)*360; + else if (degrees >= 360) + degrees %= 360; + return sintablefixed[degrees]; + } + + fixed ffcos(int degrees) { + return ffsin(degrees+90); + } + +#endif + +#endif /* GFX_USE_GMISC */ +/** @} */ diff --git a/src/gos/chibios.c b/src/gos/chibios.c new file mode 100644 index 00000000..6e63a2a4 --- /dev/null +++ b/src/gos/chibios.c @@ -0,0 +1,207 @@ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu <joel@unormal.org> + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/** + * @file src/gos/chibios.c + * @brief GOS ChibiOS Operating System support. + */ +#include "gfx.h" + +#if GFX_USE_OS_CHIBIOS + +#if !CH_USE_MUTEXES + #error "GOS: CH_USE_MUTEXES must be defined in chconf.h" +#endif +#if !CH_USE_SEMAPHORES + #error "GOS: CH_USE_SEMAPHORES must be defined in chconf.h" +#endif + +/* Our module initialiser */ +void _gosInit(void) { + /* Don't initialise if the user already has */ + if (!chThdSelf()) { + halInit(); + chSysInit(); + } +} + +void gfxSleepMilliseconds(delaytime_t ms) { + switch(ms) { + case TIME_IMMEDIATE: chThdYield(); return; + case TIME_INFINITE: chThdSleep(TIME_INFINITE); return; + default: chThdSleepMilliseconds(ms); return; + } +} + +void gfxSleepMicroseconds(delaytime_t ms) { + switch(ms) { + case TIME_IMMEDIATE: return; + case TIME_INFINITE: chThdSleep(TIME_INFINITE); return; + default: chThdSleepMicroseconds(ms); return; + } +} + +void gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit) { + if (val > limit) val = limit; + psem->limit = limit; + chSemInit(&psem->sem, val); +} + +bool_t gfxSemWait(gfxSem *psem, delaytime_t ms) { + if (ms == TIME_INFINITE) { + chSemWait(&psem->sem); + return TRUE; + } + return chSemWaitTimeout(&psem->sem, MS2ST(ms)) != RDY_TIMEOUT; +} + +void gfxSemSignal(gfxSem *psem) { + chSysLock(); + if (gfxSemCounterI(psem) < psem->limit) + chSemSignalI(&psem->sem); + chSchRescheduleS(); + chSysUnlock(); +} + +void gfxSemSignalI(gfxSem *psem) { + if (gfxSemCounterI(psem) < psem->limit) + chSemSignalI(&psem->sem); +} + +void gfxQueueInit(gfxQueue *pqueue) { + pqueue->head = pqueue->tail = 0; + chSemInit(&pqueue->sem, 0); +} + +gfxQueueItem * gfxQueueGet(gfxQueue *pqueue, delaytime_t ms) { + gfxQueueItem *pi; + + chSysLock(); + /* If someone else is waiting or if the queue is empty - wait ourselves */ + if (pqueue->sem.s_cnt < 0 || !pqueue->head) { + if (chSemWaitTimeoutS(&pqueue->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) == RDY_TIMEOUT) { + chSysUnlock(); + return NULL; + } + } + /* We can now get the head element */ + pi = pqueue->head; + pqueue->head = pi; + chSemSignalI(&pi->sem); + chSysUnlock(); + return pi; +} + +bool_t gfxQueuePut(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms) { + chSemInit(&pitem->sem, 0); + chSysLock(); + pitem->next = 0; + if (!pqueue->head) { + pqueue->head = pqueue->tail = pitem; + } else { + pqueue->tail->next = pitem; + pqueue->tail = pitem; + } + /* Wake up someone who is waiting */ + if (chSemGetCounterI(&pqueue->sem) < 0) + chSemSignalI(&pqueue->sem); + chSysUnlock(); + return chSemWaitTimeout(&pitem->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) != RDY_TIMEOUT; +} + +bool_t gfxQueuePush(gfxQueue *pqueue, gfxQueueItem *pitem, delaytime_t ms) { + chSemInit(&pitem->sem, 0); + chSysLock(); + pitem->next = pqueue->head; + pqueue->head = pitem; + if (!pitem->next) + pqueue->tail = pitem; + /* Wake up someone who is waiting */ + if (chSemGetCounterI(&pqueue->sem) < 0) + chSemSignalI(&pqueue->sem); + chSysUnlock(); + return chSemWaitTimeout(&pitem->sem, ms == TIME_INFINITE ? TIME_INFINITE : MS2ST(ms)) != RDY_TIMEOUT; +} + +void gfxQueueRemove(gfxQueue *pqueue, gfxQueueItem *pitem) { + gfxQueueItem *pi; + + chSysLock(); + if (pqueue->head) { + if (pqueue->head == pitem) { + pqueue->head = pitem->next; + chSemSignalI(&pitem->sem); + } else { + for(pi = pqueue->head; pi->next; pi = pi->next) { + if (pi->next == pitem) { + pi->next = pitem->next; + if (pqueue->tail == pitem) + pqueue->tail = pi; + chSemSignalI(&pitem->sem); + break; + } + } + } + } + chSysUnlock(); +} + +bool_t gfxQueueIsEmpty(gfxQueue *pqueue) { + return pqueue->head == NULL; +} + +bool_t gfxQueueIsIn(gfxQueue *pqueue, gfxQueueItem *pitem) { + gfxQueueItem *pi; + + chSysLock(); + for(pi = pqueue->head; pi; pi = pi->next) { + if (pi == pitem) { + chSysUnlock(); + return TRUE; + } + } + chSysUnlock(); + return FALSE; +} + +/** + * @brief Start a new thread. + * @return Return TRUE if the thread was started, FALSE on an error + * + * @param[in] stackarea A pointer to the area for the new threads stack or NULL to dynamically allocate it + * @param[in] stacksz The size of the thread stack. 0 means the default operating system size although this + * is only valid when stackarea is dynamically allocated. + * @param[in] prio The priority of the new thread + * @param[in] fn The function the new thread will run + * @param[in] param A parameter to pass the thread function. + * + * @api + */ +bool_t gfxCreateThread(void *stackarea, size_t stacksz, threadpriority_t prio, gfxThreadFunction fn, void *param) { + if (!stackarea) { + if (!stacksz) stacksz = 256; + return chThdCreateFromHeap(0, stacksz, prio, fn, param) != 0; + } + + return stacksz && chThdCreateStatic(stackarea, stacksz, prio, fn, param) != NULL; +} + +#endif /* GFX_USE_OS_CHIBIOS */ +/** @} */ diff --git a/src/gos/gos.mk b/src/gos/gos.mk new file mode 100644 index 00000000..d963eea8 --- /dev/null +++ b/src/gos/gos.mk @@ -0,0 +1,3 @@ +GFXSRC += $(GFXLIB)/src/gos/chibios.c \ + $(GFXLIB)/src/gos/win32.c \ + $(GFXLIB)/src/gos/posix.c diff --git a/src/gos/posix.c b/src/gos/posix.c new file mode 100644 index 00000000..9f6fe430 --- /dev/null +++ b/src/gos/posix.c @@ -0,0 +1,32 @@ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu <joel@unormal.org> + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/** + * @file src/gos/chibios.c + * @brief GOS ChibiOS Operating System support. + */ +#include "gfx.h" + +#if GFX_USE_OS_POSIX + +#error "GOS: POSIX not supported yet" + +#endif /* GFX_USE_OS_POSIX */ +/** @} */ diff --git a/src/gos/win32.c b/src/gos/win32.c new file mode 100644 index 00000000..6cf803a2 --- /dev/null +++ b/src/gos/win32.c @@ -0,0 +1,32 @@ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu <joel@unormal.org> + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/** + * @file src/gos/chibios.c + * @brief GOS ChibiOS Operating System support. + */ +#include "gfx.h" + +#if GFX_USE_OS_WIN32 + +#error "GOS: WIN32 not supported yet" + +#endif /* GFX_USE_OS_WIN32 */ +/** @} */ diff --git a/src/gtimer/gtimer.c b/src/gtimer/gtimer.c index 8d9fc073..366ca4a9 100644 --- a/src/gtimer/gtimer.c +++ b/src/gtimer/gtimer.c @@ -1,9 +1,9 @@ -/* - * This file is subject to the terms of the GFX License, v1.0. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://chibios-gfx.com/license.html - */ +/*
+ * This file is subject to the terms of the GFX License, v1.0. If a copy of
+ * the license was not distributed with this file, you can obtain one at:
+ *
+ * http://chibios-gfx.com/license.html
+ */
/**
* @file src/gtimer/gtimer.c
@@ -12,16 +12,10 @@ * @addtogroup GTIMER
* @{
*/
-#include "ch.h"
-#include "hal.h"
#include "gfx.h"
#if GFX_USE_GTIMER || defined(__DOXYGEN__)
-#if !CH_USE_MUTEXES || !CH_USE_SEMAPHORES
- #error "GTIMER: CH_USE_MUTEXES and CH_USE_SEMAPHORES must be defined in chconf.h"
-#endif
-
#define GTIMER_FLG_PERIODIC 0x0001
#define GTIMER_FLG_INFINITE 0x0002
#define GTIMER_FLG_JABBED 0x0004
@@ -31,44 +25,40 @@ #define TimeIsWithin(x, start, end) ((end >= start && x >= start && x <= end) || (end < start && (x >= start || x <= end)))
/* This mutex protects access to our tables */
-static MUTEX_DECL(mutex);
-static Thread *pThread = 0;
+static gfxMutex mutex;
+static bool_t haveThread = 0;
static GTimer *pTimerHead = 0;
-static BSEMAPHORE_DECL(waitsem, TRUE);
-static WORKING_AREA(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
+static gfxSem waitsem;
+static DECLARESTACK(waTimerThread, GTIMER_THREAD_WORKAREA_SIZE);
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
-static msg_t GTimerThreadHandler(void *arg) {
+static threadreturn_t GTimerThreadHandler(void *arg) {
(void)arg;
GTimer *pt;
- systime_t tm;
- systime_t nxtTimeout;
- systime_t lastTime;
+ systemticks_t tm;
+ systemticks_t nxtTimeout;
+ systemticks_t lastTime;
GTimerFunction fn;
void *param;
- #if CH_USE_REGISTRY
- chRegSetThreadName("GTimer");
- #endif
-
nxtTimeout = TIME_INFINITE;
lastTime = 0;
while(1) {
/* Wait for work to do. */
- chThdYield(); // Give someone else a go no matter how busy we are
- chBSemWaitTimeout(&waitsem, nxtTimeout);
+ gfxYield(); // Give someone else a go no matter how busy we are
+ gfxSemWait(&waitsem, nxtTimeout);
restartTimerChecks:
// Our reference time
- tm = chTimeNow();
+ tm = gfxSystemTicks();
nxtTimeout = TIME_INFINITE;
/* We need to obtain the mutex */
- chMtxLock(&mutex);
+ gfxMutexEnter(&mutex);
if (pTimerHead) {
pt = pTimerHead;
@@ -106,7 +96,7 @@ static msg_t GTimerThreadHandler(void *arg) { // Call the callback function
fn = pt->fn;
param = pt->param;
- chMtxUnlock();
+ gfxMutexExit(&mutex);
fn(param);
// We no longer hold the mutex, the callback function may have taken a while
@@ -123,21 +113,26 @@ static msg_t GTimerThreadHandler(void *arg) { // Ready for the next loop
lastTime = tm;
- chMtxUnlock();
+ gfxMutexExit(&mutex);
}
return 0;
}
+void _gtimerInit(void) {
+ gfxSemInit(&waitsem, 0, 1);
+ gfxMutexInit(&mutex);
+}
+
void gtimerInit(GTimer *pt) {
pt->flags = 0;
}
-void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, systime_t millisec) {
- chMtxLock(&mutex);
+void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, delaytime_t millisec) {
+ gfxMutexEnter(&mutex);
// Start our thread if not already going
- if (!pThread)
- pThread = chThdCreateStatic(waTimerThread, sizeof(waTimerThread), HIGHPRIO, GTimerThreadHandler, NULL);
+ if (!haveThread)
+ haveThread = gfxCreateThread(waTimerThread, sizeof(waTimerThread), HIGH_PRIORITY, GTimerThreadHandler, NULL);
// Is this already scheduled?
if (pt->flags & GTIMER_FLG_SCHEDULED) {
@@ -162,8 +157,8 @@ void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, sy pt->flags |= GTIMER_FLG_INFINITE;
pt->period = TIME_INFINITE;
} else {
- pt->period = MS2ST(millisec);
- pt->when = chTimeNow() + pt->period;
+ pt->period = gfxMillisecondsToTicks(millisec);
+ pt->when = gfxSystemTicks() + pt->period;
}
// Just pop it on the end of the queue
@@ -177,12 +172,12 @@ void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, bool_t periodic, sy // Bump the thread
if (!(pt->flags & GTIMER_FLG_INFINITE))
- chBSemSignal(&waitsem);
- chMtxUnlock();
+ gfxSemSignal(&waitsem);
+ gfxMutexExit(&mutex);
}
void gtimerStop(GTimer *pt) {
- chMtxLock(&mutex);
+ gfxMutexEnter(&mutex);
if (pt->flags & GTIMER_FLG_SCHEDULED) {
// Cancel it!
if (pt->next == pt->prev)
@@ -196,7 +191,7 @@ void gtimerStop(GTimer *pt) { // Make sure we know the structure is dead!
pt->flags = 0;
}
- chMtxUnlock();
+ gfxMutexExit(&mutex);
}
bool_t gtimerIsActive(GTimer *pt) {
@@ -204,14 +199,14 @@ bool_t gtimerIsActive(GTimer *pt) { }
void gtimerJab(GTimer *pt) {
- chMtxLock(&mutex);
+ gfxMutexEnter(&mutex);
// Jab it!
pt->flags |= GTIMER_FLG_JABBED;
// Bump the thread
- chBSemSignal(&waitsem);
- chMtxUnlock();
+ gfxSemSignal(&waitsem);
+ gfxMutexExit(&mutex);
}
void gtimerJabI(GTimer *pt) {
@@ -219,7 +214,7 @@ void gtimerJabI(GTimer *pt) { pt->flags |= GTIMER_FLG_JABBED;
// Bump the thread
- chBSemSignalI(&waitsem);
+ gfxSemSignalI(&waitsem);
}
#endif /* GFX_USE_GTIMER */
diff --git a/src/gwin/button.c b/src/gwin/button.c index 8d77b8ba..19301698 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -15,8 +15,6 @@ * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if (GFX_USE_GWIN && GWIN_NEED_BUTTON) || defined(__DOXYGEN__) @@ -204,7 +202,7 @@ void gwinSetButtonText(GHandle gh, const char *txt, bool_t useAlloc) { if ((gh->flags & GBTN_FLG_ALLOCTXT)) { gh->flags &= ~GBTN_FLG_ALLOCTXT; if (gbw->txt) { - chHeapFree((void *)gbw->txt); + gfxFree((void *)gbw->txt); gbw->txt = ""; } } @@ -212,7 +210,7 @@ void gwinSetButtonText(GHandle gh, const char *txt, bool_t useAlloc) { if (txt && useAlloc) { char *str; - if ((str = (char *)chHeapAlloc(NULL, strlen(txt)+1))) { + if ((str = (char *)gfxAlloc(strlen(txt)+1))) { gh->flags |= GBTN_FLG_ALLOCTXT; strcpy(str, txt); } diff --git a/src/gwin/console.c b/src/gwin/console.c index 6abb18dc..a01ed79d 100644 --- a/src/gwin/console.c +++ b/src/gwin/console.c @@ -15,8 +15,6 @@ * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if (GFX_USE_GWIN && GWIN_NEED_CONSOLE) || defined(__DOXYGEN__) @@ -32,48 +30,54 @@ * Stream interface implementation. The interface is write only */ -#define Stream2GWindow(ip) ((GHandle)(((char *)(ip)) - (size_t)(&(((GConsoleObject *)0)->stream)))) - -static size_t GWinStreamWrite(void *ip, const uint8_t *bp, size_t n) { gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; } -static size_t GWinStreamRead(void *ip, uint8_t *bp, size_t n) { (void)ip; (void)bp; (void)n; return 0; } -static msg_t GWinStreamPut(void *ip, uint8_t b) { gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; } -static msg_t GWinStreamGet(void *ip) {(void)ip; return RDY_OK; } -static msg_t GWinStreamPutTimed(void *ip, uint8_t b, systime_t time) { (void)time; gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; } -static msg_t GWinStreamGetTimed(void *ip, systime_t timeout) { (void)ip; (void)timeout; return RDY_OK; } -static size_t GWinStreamWriteTimed(void *ip, const uint8_t *bp, size_t n, systime_t time) { (void)time; gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; } -static size_t GWinStreamReadTimed(void *ip, uint8_t *bp, size_t n, systime_t time) { (void)ip; (void)bp; (void)n; (void)time; return 0; } - -struct GConsoleWindowVMT_t { - _base_asynchronous_channel_methods -}; - -static const struct GConsoleWindowVMT_t GWindowConsoleVMT = { - GWinStreamWrite, - GWinStreamRead, - GWinStreamPut, - GWinStreamGet, - GWinStreamPutTimed, - GWinStreamGetTimed, - GWinStreamWriteTimed, - GWinStreamReadTimed -}; +#if GFX_USE_OS_CHIBIOS + #define Stream2GWindow(ip) ((GHandle)(((char *)(ip)) - (size_t)(&(((GConsoleObject *)0)->stream)))) + + static size_t GWinStreamWrite(void *ip, const uint8_t *bp, size_t n) { gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; } + static size_t GWinStreamRead(void *ip, uint8_t *bp, size_t n) { (void)ip; (void)bp; (void)n; return 0; } + static msg_t GWinStreamPut(void *ip, uint8_t b) { gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; } + static msg_t GWinStreamGet(void *ip) {(void)ip; return RDY_OK; } + static msg_t GWinStreamPutTimed(void *ip, uint8_t b, systime_t time) { (void)time; gwinPutChar(Stream2GWindow(ip), (char)b); return RDY_OK; } + static msg_t GWinStreamGetTimed(void *ip, systime_t timeout) { (void)ip; (void)timeout; return RDY_OK; } + static size_t GWinStreamWriteTimed(void *ip, const uint8_t *bp, size_t n, systime_t time) { (void)time; gwinPutCharArray(Stream2GWindow(ip), (const char *)bp, n); return RDY_OK; } + static size_t GWinStreamReadTimed(void *ip, uint8_t *bp, size_t n, systime_t time) { (void)ip; (void)bp; (void)n; (void)time; return 0; } + + struct GConsoleWindowVMT_t { + _base_asynchronous_channel_methods + }; + + static const struct GConsoleWindowVMT_t GWindowConsoleVMT = { + GWinStreamWrite, + GWinStreamRead, + GWinStreamPut, + GWinStreamGet, + GWinStreamPutTimed, + GWinStreamGetTimed, + GWinStreamWriteTimed, + GWinStreamReadTimed + }; +#endif GHandle gwinCreateConsole(GConsoleObject *gc, coord_t x, coord_t y, coord_t width, coord_t height, font_t font) { if (!(gc = (GConsoleObject *)_gwinInit((GWindowObject *)gc, x, y, width, height, sizeof(GConsoleObject)))) return 0; gc->gwin.type = GW_CONSOLE; gwinSetFont(&gc->gwin, font); - gc->stream.vmt = &GWindowConsoleVMT; + #if GFX_USE_OS_CHIBIOS + gc->stream.vmt = &GWindowConsoleVMT; + #endif gc->cx = 0; gc->cy = 0; return (GHandle)gc; } -BaseSequentialStream *gwinGetConsoleStream(GHandle gh) { - if (gh->type != GW_CONSOLE) - return 0; - return (BaseSequentialStream *)&(((GConsoleObject *)(gh))->stream); -} +#if GFX_USE_OS_CHIBIOS + BaseSequentialStream *gwinGetConsoleStream(GHandle gh) { + if (gh->type != GW_CONSOLE) + return 0; + return (BaseSequentialStream *)&(((GConsoleObject *)(gh))->stream); + } +#endif void gwinPutChar(GHandle gh, char c) { uint8_t width; diff --git a/src/gwin/graph.c b/src/gwin/graph.c index dd4506a3..287deba9 100644 --- a/src/gwin/graph.c +++ b/src/gwin/graph.c @@ -15,8 +15,6 @@ * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if (GFX_USE_GWIN && GWIN_NEED_GRAPH) || defined(__DOXYGEN__) diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index b6340c2d..c01c8a90 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -5,8 +5,6 @@ * http://chibios-gfx.com/license.html */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_GWIN @@ -29,7 +27,7 @@ GHandle _gwinInit(GWindowObject *gw, coord_t x, coord_t y, coord_t width, coord_ // Allocate the structure if necessary if (!gw) { - if (!(gw = (GWindowObject *)chHeapAlloc(NULL, size))) + if (!(gw = (GWindowObject *)gfxAlloc(size))) return 0; gw->flags = GWIN_FLG_DYNAMIC; } else @@ -56,7 +54,8 @@ GHandle gwinCreateWindow(GWindowObject *gw, coord_t x, coord_t y, coord_t width, } void gwinSetEnabled(GHandle gh, bool_t enabled) { - + (void)gh; + (void)enabled; } void gwinDestroyWindow(GHandle gh) { @@ -66,7 +65,7 @@ void gwinDestroyWindow(GHandle gh) { case GW_BUTTON: if ((gh->flags & GBTN_FLG_ALLOCTXT)) { gh->flags &= ~GBTN_FLG_ALLOCTXT; // To be sure, to be sure - chHeapFree((void *)((GButtonObject *)gh)->txt); + gfxFree((void *)((GButtonObject *)gh)->txt); } geventDetachSource(&((GButtonObject *)gh)->listener, 0); geventDetachSourceListeners((GSourceHandle)gh); @@ -85,7 +84,7 @@ void gwinDestroyWindow(GHandle gh) { // Clean up the structure if (gh->flags & GWIN_FLG_DYNAMIC) { gh->flags = 0; // To be sure, to be sure - chHeapFree((void *)gh); + gfxFree((void *)gh); } } diff --git a/src/gwin/slider.c b/src/gwin/slider.c index 26555f33..7f1e36bc 100644 --- a/src/gwin/slider.c +++ b/src/gwin/slider.c @@ -15,8 +15,6 @@ * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if (GFX_USE_GWIN && GWIN_NEED_SLIDER) || defined(__DOXYGEN__) diff --git a/src/tdisp/tdisp.c b/src/tdisp/tdisp.c index 42b22cd5..c7931995 100644 --- a/src/tdisp/tdisp.c +++ b/src/tdisp/tdisp.c @@ -12,8 +12,6 @@ * @addtogroup TDISP * @{ */ -#include "ch.h" -#include "hal.h" #include "gfx.h" #if GFX_USE_TDISP || defined(__DOXYGEN__) @@ -21,15 +19,11 @@ #include "tdisp/lld/tdisp_lld.h" #if TDISP_NEED_MULTITHREAD - #if !CH_USE_MUTEXES - #error "TDISP: CH_USE_MUTEXES must be defined in chconf.h because TDISP_NEED_MULTITHREAD is defined" - #endif + static gfxMutex tdispMutex; - static Mutex tdispMutex; - - #define MUTEX_INIT() chMtxInit(&tdispMutex) - #define MUTEX_ENTER() chMtxLock(&tdispMutex) - #define MUTEX_LEAVE() chMtxUnlock() + #define MUTEX_INIT() gfxMutexInit(&tdispMutex) + #define MUTEX_ENTER() gfxMutexEnter(&tdispMutex) + #define MUTEX_LEAVE() gfxMutexExit(&tdispMutex) #else |