From e4d6884bca6ca422115765dab60039bd6296ccab Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 20 Mar 2014 23:31:10 +1000 Subject: Cause the gaudio/gadc driver (currently broken) to include the GADC framework if it is included in the make. --- demos/modules/gaudio/oscilloscope/gfxconf.h | 1 - 1 file changed, 1 deletion(-) (limited to 'demos/modules') 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. */ -- cgit v1.2.3 From 8b9d31ef902b80c27065ab542c4783d6194f420f Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 20 Mar 2014 23:33:32 +1000 Subject: Move queued buffer code from gaudio into gqueue --- demos/modules/gaudio/oscilloscope/gwinosc.c | 4 ++-- demos/modules/gaudio/oscilloscope/main.c | 2 +- demos/modules/gaudio/play-wave/main.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'demos/modules') diff --git a/demos/modules/gaudio/oscilloscope/gwinosc.c b/demos/modules/gaudio/oscilloscope/gwinosc.c index 21a83760..9d095c86 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; @@ -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..a0b9320e 100644 --- a/demos/modules/gaudio/oscilloscope/main.c +++ b/demos/modules/gaudio/oscilloscope/main.c @@ -58,7 +58,7 @@ int main(void) { // 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); + gfxBufferAlloc(4, 128); /* 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..855c39ff 100644 --- a/demos/modules/gaudio/play-wave/main.c +++ b/demos/modules/gaudio/play-wave/main.c @@ -64,7 +64,7 @@ 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; } @@ -164,7 +164,7 @@ 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 + paud = 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; -- cgit v1.2.3 From 271f0c743f31d3ae21ede35909e1f14845c6d338 Mon Sep 17 00:00:00 2001 From: inmarket Date: Thu, 20 Mar 2014 23:41:27 +1000 Subject: Updates to GADC to use new simpler gfx queued bufferring. NOTE: code is still buggy (or the one and only driver is buggy). --- demos/modules/gadc/gfxconf.h | 1 - demos/modules/gadc/gwinosc.c | 34 ++++++++++++---------------------- demos/modules/gadc/gwinosc.h | 3 --- demos/modules/gadc/main.c | 5 +++++ 4 files changed, 17 insertions(+), 26 deletions(-) (limited to 'demos/modules') 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<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..8f5c1be3 100644 --- a/demos/modules/gadc/gwinosc.h +++ b/demos/modules/gadc/gwinosc.h @@ -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..8e5ecaa4 100644 --- a/demos/modules/gadc/main.c +++ b/demos/modules/gadc/main.c @@ -167,6 +167,11 @@ int main(void) { gtimerStart(&lsTimer, LowSpeedTimer, ghText, TRUE, MY_LS_DELAY); #endif + // Allocate buffers for the high speed GADC device - 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. + gfxBufferAlloc(4, 128); + /* Set up the scope window in the top right on the screen */ { GWindowInit wi; -- cgit v1.2.3 From c354639f7b8ab1c33866b3d57a243de95a75decc Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 24 Mar 2014 10:08:15 +1000 Subject: Update GADC --- demos/modules/gadc/main.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'demos/modules') diff --git a/demos/modules/gadc/main.c b/demos/modules/gadc/main.c index 8e5ecaa4..67eed456 100644 --- a/demos/modules/gadc/main.c +++ b/demos/modules/gadc/main.c @@ -167,10 +167,19 @@ int main(void) { gtimerStart(&lsTimer, LowSpeedTimer, ghText, TRUE, MY_LS_DELAY); #endif - // Allocate buffers for the high speed GADC device - 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. - gfxBufferAlloc(4, 128); + /** + * 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. + * 10 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(10, 128); /* Set up the scope window in the top right on the screen */ { -- cgit v1.2.3 From 9919aeac899e0044549c75be849aaf6b1e2456ab Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 24 Mar 2014 10:08:51 +1000 Subject: Bug fixes and comments in audio recording demo --- demos/modules/gaudio/oscilloscope/gwinosc.c | 4 ++-- demos/modules/gaudio/oscilloscope/main.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'demos/modules') diff --git a/demos/modules/gaudio/oscilloscope/gwinosc.c b/demos/modules/gaudio/oscilloscope/gwinosc.c index 9d095c86..6b51232b 100644 --- a/demos/modules/gaudio/oscilloscope/gwinosc.c +++ b/demos/modules/gaudio/oscilloscope/gwinosc.c @@ -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)); diff --git a/demos/modules/gaudio/oscilloscope/main.c b/demos/modules/gaudio/oscilloscope/main.c index a0b9320e..9b53de8e 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. - gfxBufferAlloc(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. + * 16 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(16, 256); /* Get the screen dimensions */ swidth = gdispGetWidth(); -- cgit v1.2.3 From 343ddd7158a5f102767d93598c8cba21121d6bcb Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 24 Mar 2014 16:49:17 +1000 Subject: Final updates to GADC recording after fixing bugs in the ChibiOS AT91SAM7X ADC driver --- demos/modules/gadc/gwinosc.h | 2 +- demos/modules/gadc/main.c | 4 ++-- demos/modules/gaudio/oscilloscope/main.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'demos/modules') diff --git a/demos/modules/gadc/gwinosc.h b/demos/modules/gadc/gwinosc.h index 8f5c1be3..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 */ diff --git a/demos/modules/gadc/main.c b/demos/modules/gadc/main.c index 67eed456..7db14c82 100644 --- a/demos/modules/gadc/main.c +++ b/demos/modules/gadc/main.c @@ -171,7 +171,7 @@ int main(void) { * 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. - * 10 x 128 seems to work on the really slow Olimex SAM7EX256 board (display speed limitation) + * 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.. @@ -179,7 +179,7 @@ int main(void) { * 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(10, 128); + gfxBufferAlloc(4, 128); /* Set up the scope window in the top right on the screen */ { diff --git a/demos/modules/gaudio/oscilloscope/main.c b/demos/modules/gaudio/oscilloscope/main.c index 9b53de8e..3636e8f9 100644 --- a/demos/modules/gaudio/oscilloscope/main.c +++ b/demos/modules/gaudio/oscilloscope/main.c @@ -59,11 +59,11 @@ int main(void) { * 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. - * 16 x 256 seems to work on the really slow Olimex SAM7EX256 board (display speed limitation) @8kHz + * 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(16, 256); + gfxBufferAlloc(8, 256); /* Get the screen dimensions */ swidth = gdispGetWidth(); -- cgit v1.2.3 From cd5abc421d3d129983479c9dda8a5fec24506e47 Mon Sep 17 00:00:00 2001 From: inmarket Date: Sun, 30 Mar 2014 19:07:17 +1000 Subject: Update audio play demo to play in a loop (easier for testing) --- demos/modules/gaudio/play-wave/main.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'demos/modules') diff --git a/demos/modules/gaudio/play-wave/main.c b/demos/modules/gaudio/play-wave/main.c index 855c39ff..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(); @@ -69,6 +69,7 @@ int main(void) { 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 = gfxBufferGet(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) -- cgit v1.2.3