diff options
author | Joel Bodenmann <joel@unormal.org> | 2014-04-30 13:41:34 +0200 |
---|---|---|
committer | Joel Bodenmann <joel@unormal.org> | 2014-04-30 13:41:34 +0200 |
commit | 33c721c009465dd30d4e96e055a051480c567b57 (patch) | |
tree | 5a6744a79b7469d80bae474d4314b47d4cd6d44d /demos/modules/gadc/gwinosc.c | |
parent | 58cf2d2b35542166f1a4e50a83bcf28ff33574a5 (diff) | |
parent | a394e2c35dde67241bea69409bcae9f46dcfc089 (diff) | |
download | uGFX-33c721c009465dd30d4e96e055a051480c567b57.tar.gz uGFX-33c721c009465dd30d4e96e055a051480c567b57.tar.bz2 uGFX-33c721c009465dd30d4e96e055a051480c567b57.zip |
Merge branch 'master' into freertos
Diffstat (limited to 'demos/modules/gadc/gwinosc.c')
-rw-r--r-- | demos/modules/gadc/gwinosc.c | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/demos/modules/gadc/gwinosc.c b/demos/modules/gadc/gwinosc.c index afa12bfc..84e7d645 100644 --- a/demos/modules/gadc/gwinosc.c +++ b/demos/modules/gadc/gwinosc.c @@ -38,9 +38,6 @@ /* Include internal GWIN routines so we can build our own superset class */ #include "src/gwin/class_gwin.h" -/* The size of our dynamically allocated audio buffer */ -#define AUDIOBUFSZ 64*2 - /* How many flat-line sample before we trigger */ #define FLATLINE_SAMPLES 8 @@ -50,10 +47,6 @@ static void _destroy(GHandle gh) { gfxFree(((GScopeObject *)gh)->lastscopetrace); ((GScopeObject *)gh)->lastscopetrace = 0; } - if (((GScopeObject *)gh)->audiobuf) { - gfxFree(((GScopeObject *)gh)->audiobuf); - ((GScopeObject *)gh)->audiobuf = 0; - } } static const gwinVMT scopeVMT = { @@ -68,12 +61,9 @@ GHandle gwinGScopeCreate(GDisplay *g, GScopeObject *gs, GWindowInit *pInit, uint /* Initialise the base class GWIN */ if (!(gs = (GScopeObject *)_gwindowCreate(g, &gs->g, pInit, &scopeVMT, 0))) return 0; - gfxSemInit(&gs->bsem, 0, 1); gs->nextx = 0; if (!(gs->lastscopetrace = gfxAlloc(gs->g.width * sizeof(coord_t)))) return 0; - if (!(gs->audiobuf = gfxAlloc(AUDIOBUFSZ * sizeof(adcsample_t)))) - return 0; #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP gs->lasty = gs->g.height/2; #elif TRIGGER_METHOD == TRIGGER_MINVALUE @@ -82,8 +72,7 @@ GHandle gwinGScopeCreate(GDisplay *g, GScopeObject *gs, GWindowInit *pInit, uint #endif /* Start the GADC high speed converter */ - gadcHighSpeedInit(physdev, frequency, gs->audiobuf, AUDIOBUFSZ, AUDIOBUFSZ/2); - gadcHighSpeedSetBSem(&gs->bsem, &gs->myEvent); + gadcHighSpeedInit(physdev, frequency); gadcHighSpeedStart(); gwinSetVisible((GHandle)gs, pInit->show); @@ -97,6 +86,8 @@ void gwinScopeWaitForTrace(GHandle gh) { coord_t yoffset; adcsample_t *pa; coord_t *pc; + GDataBuffer *pd; + uint8_t shr; #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP bool_t rdytrigger; int flsamples; @@ -109,20 +100,21 @@ void gwinScopeWaitForTrace(GHandle gh) { if (gh->vmt != &scopeVMT) return; - /* Wait for a set of audio conversions */ - gfxSemWait(&gs->bsem, TIME_INFINITE); + /* Wait for a set of conversions */ + pd = gadcHighSpeedGetData(TIME_INFINITE); /* Ensure we are drawing in the right area */ #if GDISP_NEED_CLIP gdispGSetClip(gh->display, gh->x, gh->y, gh->width, gh->height); #endif + shr = 16 - gfxSampleFormatBits(GADC_SAMPLE_FORMAT); yoffset = gh->height/2; - if (!(GADC_SAMPLE_FORMAT & 1)) + if (!gfxSampleFormatIsSigned(GADC_SAMPLE_FORMAT)) yoffset += (1<<SCOPE_Y_BITS)/2; x = gs->nextx; pc = gs->lastscopetrace+x; - pa = gs->myEvent.buffer; + pa = (adcsample_t *)(pd+1); #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP rdytrigger = FALSE; flsamples = 0; @@ -132,14 +124,10 @@ void gwinScopeWaitForTrace(GHandle gh) { scopemin = 0; #endif - for(i = gs->myEvent.count; i; i--) { + for(i = pd->len/sizeof(adcsample_t); i; i--) { /* Calculate the new scope value - re-scale using simple shifts for efficiency, re-center and y-invert */ - #if GADC_BITS_PER_SAMPLE > SCOPE_Y_BITS - y = yoffset - (*pa++ >> (GADC_BITS_PER_SAMPLE - SCOPE_Y_BITS)); - #else - y = yoffset - (*pa++ << (SCOPE_Y_BITS - GADC_BITS_PER_SAMPLE)); - #endif + y = yoffset - (((coord_t)(*pa++) << shr) >> (16-SCOPE_Y_BITS)); #if TRIGGER_METHOD == TRIGGER_MINVALUE /* Calculate the scopemin ready for the next trace */ @@ -205,5 +193,7 @@ void gwinScopeWaitForTrace(GHandle gh) { gs->scopemin = scopemin; #endif + gfxBufferRelease(pd); + #undef gs } |