diff options
Diffstat (limited to 'demos/modules')
-rw-r--r-- | demos/modules/gadc/gfxconf.h | 1 | ||||
-rw-r--r-- | demos/modules/gadc/gwinosc.c | 34 | ||||
-rw-r--r-- | demos/modules/gadc/gwinosc.h | 5 | ||||
-rw-r--r-- | demos/modules/gadc/main.c | 14 | ||||
-rw-r--r-- | demos/modules/gaudio/oscilloscope/gfxconf.h | 1 | ||||
-rw-r--r-- | demos/modules/gaudio/oscilloscope/gwinosc.c | 8 | ||||
-rw-r--r-- | demos/modules/gaudio/oscilloscope/main.c | 13 | ||||
-rw-r--r-- | demos/modules/gaudio/play-wave/main.c | 20 |
8 files changed, 53 insertions, 43 deletions
diff --git a/demos/modules/gadc/gfxconf.h b/demos/modules/gadc/gfxconf.h index 297265b5..d0da3943 100644 --- a/demos/modules/gadc/gfxconf.h +++ b/demos/modules/gadc/gfxconf.h @@ -51,7 +51,6 @@ #define GDISP_NEED_VALIDATION TRUE #define GDISP_NEED_CLIP TRUE #define GDISP_NEED_TEXT TRUE -#define GDISP_NEED_CONTROL TRUE #define GDISP_NEED_MULTITHREAD TRUE /* GDISP - builtin fonts */ 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 } diff --git a/demos/modules/gadc/gwinosc.h b/demos/modules/gadc/gwinosc.h index 56de0f11..0c687a4f 100644 --- a/demos/modules/gadc/gwinosc.h +++ b/demos/modules/gadc/gwinosc.h @@ -43,7 +43,7 @@ /* The extent of scaling for our audio data - fixed scale at the moment */ #ifndef SCOPE_Y_BITS - #define SCOPE_Y_BITS 7 // 7 bits = 0..128 + #define SCOPE_Y_BITS 7 // 7 bits = 0..128 #endif /* Trigger methods */ @@ -64,9 +64,6 @@ typedef struct GScopeObject_t { GWindowObject g; // Base Class coord_t *lastscopetrace; // To store last scope trace - gfxSem bsem; // We get signalled on this - adcsample_t *audiobuf; // To store audio samples - GEventADC myEvent; // Information on received samples coord_t nextx; // Where we are up to #if TRIGGER_METHOD == TRIGGER_POSITIVERAMP coord_t lasty; // The last y value - used for trigger slope detection diff --git a/demos/modules/gadc/main.c b/demos/modules/gadc/main.c index 928635fa..7db14c82 100644 --- a/demos/modules/gadc/main.c +++ b/demos/modules/gadc/main.c @@ -167,6 +167,20 @@ int main(void) { gtimerStart(&lsTimer, LowSpeedTimer, ghText, TRUE, MY_LS_DELAY); #endif + /** + * Allocate buffers for the high speed GADC device - eg. 4 x 128 byte buffers. + * You may need to increase this for slower cpu's. + * You may be able to decrease this for low latency operating systems. + * 4 x 128 seems to work on the really slow Olimex SAM7EX256 board (display speed limitation) + * If your oscilloscope display stops but the low speed reading keep going then it is likely that + * your high speed timer has stalled due to running out of free buffers. Increase the number + * of buffers.. + * If you make the buffers too large with a slow sample rate you may not allow enough time for all + * the low speed items to occur in which case your memory will fill up with low speed requests until + * you run out of memory. + */ + gfxBufferAlloc(4, 128); + /* Set up the scope window in the top right on the screen */ { GWindowInit wi; diff --git a/demos/modules/gaudio/oscilloscope/gfxconf.h b/demos/modules/gaudio/oscilloscope/gfxconf.h index 2caa1da9..8e20ce0b 100644 --- a/demos/modules/gaudio/oscilloscope/gfxconf.h +++ b/demos/modules/gaudio/oscilloscope/gfxconf.h @@ -45,7 +45,6 @@ #define GFX_USE_GDISP TRUE #define GFX_USE_GWIN TRUE #define GFX_USE_GTIMER TRUE -//#define GFX_USE_GADC TRUE #define GFX_USE_GAUDIO TRUE /* Features for the GDISP sub-system. */ diff --git a/demos/modules/gaudio/oscilloscope/gwinosc.c b/demos/modules/gaudio/oscilloscope/gwinosc.c index 21a83760..6b51232b 100644 --- a/demos/modules/gaudio/oscilloscope/gwinosc.c +++ b/demos/modules/gaudio/oscilloscope/gwinosc.c @@ -96,7 +96,7 @@ GHandle gwinGScopeCreate(GDisplay *g, GScopeObject *gs, GWindowInit *pInit, uint void gwinScopeWaitForTrace(GHandle gh) { #define gs ((GScopeObject *)(gh)) - GAudioData *paud; + GDataBuffer *paud; int i; coord_t x, y; coord_t yoffset; @@ -144,10 +144,10 @@ void gwinScopeWaitForTrace(GHandle gh) { scopemin = 0; #endif - for(i = paud->len/(gfxSampleFormatBits(gs->format)/8); i; i--) { + for(i = paud->len/((gfxSampleFormatBits(gs->format)+7)/8); i; i--) { /* Calculate the new scope value - re-scale using simple shifts for efficiency, re-center and y-invert */ - if (gs->format <= 8) + if (gfxSampleFormatBits(gs->format) <= 8) y = yoffset - (((coord_t)(*pa8++ ) << shr) >> (16-SCOPE_Y_BITS)); else y = yoffset - (((coord_t)(*pa16++) << shr) >> (16-SCOPE_Y_BITS)); @@ -216,6 +216,6 @@ void gwinScopeWaitForTrace(GHandle gh) { gs->scopemin = scopemin; #endif - gaudioReleaseBuffer(paud); + gfxBufferRelease(paud); #undef gs } diff --git a/demos/modules/gaudio/oscilloscope/main.c b/demos/modules/gaudio/oscilloscope/main.c index b44b5a02..3636e8f9 100644 --- a/demos/modules/gaudio/oscilloscope/main.c +++ b/demos/modules/gaudio/oscilloscope/main.c @@ -55,10 +55,15 @@ int main(void) { gfxInit(); - // Allocate audio buffers - 4 x 128 byte buffers. - // You may need to increase this for slower cpu's. - // You may be able to decrease this for low latency operating systems. - gaudioAllocBuffers(4, 128); + /** + * Allocate audio buffers - eg. 4 x 128 byte buffers. + * You may need to increase this for slower cpu's. + * You may be able to decrease this for low latency operating systems. + * 8 x 256 seems to work on the really slow Olimex SAM7EX256 board (display speed limitation) @8kHz + * If your oscilloscope display stops then it is likely that your driver has stalled due to running + * out of free buffers. Increase the number of buffers.. + */ + gfxBufferAlloc(8, 256); /* Get the screen dimensions */ swidth = gdispGetWidth(); diff --git a/demos/modules/gaudio/play-wave/main.c b/demos/modules/gaudio/play-wave/main.c index f15ec7a1..888e4c8e 100644 --- a/demos/modules/gaudio/play-wave/main.c +++ b/demos/modules/gaudio/play-wave/main.c @@ -52,7 +52,7 @@ int main(void) { uint32_t frequency; ArrayDataFormat datafmt; uint32_t len; - GAudioData *paud; + GDataBuffer *pd; // Initialise everything gfxInit(); @@ -64,11 +64,12 @@ int main(void) { // Allocate audio buffers - 4 x 512 byte buffers. // You may need to increase this for slower cpu's. // You may be able to decrease this for low latency operating systems. - if (!gaudioAllocBuffers(4, 512)) { + if (!gfxBufferAlloc(4, 512)) { errmsg = "Err: No Memory"; goto theend; } +repeatplay: // Open the wave file if (!(f = gfileOpen("allwrong.wav", "r"))) { errmsg = "Err: Open WAV"; @@ -164,20 +165,20 @@ int main(void) { gdispDrawString(0, gdispGetHeight()/2, "Playing...", font, Yellow); while(toplay) { // Get a buffer to put the data into - paud = gaudioGetBuffer(TIME_INFINITE); // This should never fail as we are waiting forever + pd = gfxBufferGet(TIME_INFINITE); // This should never fail as we are waiting forever // How much data can we put in - len = toplay > paud->size ? paud->size : toplay; - paud->len = len; + len = toplay > pd->size ? pd->size : toplay; + pd->len = len; toplay -= len; // Read the data - if (gfileRead(f, paud+1, len) != len) { + if (gfileRead(f, pd+1, len) != len) { errmsg = "Err: Read fail"; goto theend; } - gaudioPlay(paud); + gaudioPlay(pd); } gfileClose(f); @@ -185,6 +186,11 @@ int main(void) { gaudioPlayWait(TIME_INFINITE); gdispDrawString(0, gdispGetHeight()/2+10, "Done", font, Green); + // Repeat the whole thing + gfxSleepMilliseconds(1500); + gdispClear(Black); + goto repeatplay; + // The end theend: if (errmsg) |