diff projects/analogDigitalDemo/render.cpp @ 33:83baffda5786 matrix_gpio

Fixed bug in Digital macros and in example project
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 11 May 2015 18:58:47 +0100
parents 182ae9367104
children a6d223473ea2
line wrap: on
line diff
--- a/projects/analogDigitalDemo/render.cpp	Mon May 11 11:45:03 2015 +0100
+++ b/projects/analogDigitalDemo/render.cpp	Mon May 11 18:58:47 2015 +0100
@@ -26,7 +26,7 @@
 					   int numAnalogFramesPerPeriod,
 					   int numAudioFramesPerPeriod,
 					   float analogSampleRate, float audioSampleRate,
-					   void *userData)
+					   void *userData, RTAudioSettings* settings)
 {
 	gNumAnalogChannels=numAnalogChannels;
     gNumDigitalChannels=numDigitalChannels;
@@ -45,8 +45,6 @@
 we assume that gNumAnalogChannels=8, numAnalogFrames==8 and  numDigitalFrames==numAudioFrames
  * */
 {
-	gNumDigitalFrames=numDigitalFrames;
-
 	if((gCountFrames&31)==0){ //every 32 frames...
         //ANALOG channels
 		analogWrite(0, 0, analogRead(0,0)); // read the input0 at frame0  and write it to output0 frame0. Using analogWrite will fill the rest of the buffer with the same value
@@ -66,6 +64,7 @@
         digitalWrite(P8_08,2,GPIO_LOW);
         digitalWrite(P8_08,4,GPIO_HIGH);
         digitalWrite(P8_08,5,GPIO_LOW);
+        setDigitalDirection(P9_16,0,GPIO_INPUT); // set channel 10 to input
         // in this buffer the frames of channel 1 will look like this: 1 1 0 0 1 0 0 0 .... 0
         // in the next buffer each frame of channel 1 will be initialized to 0 (the last value of this buffer)
 	}
@@ -73,10 +72,14 @@
 		for(int c=0; c<gNumAudioChannels; c++){
 			audioOut[n*gNumAudioChannels + c]=audioIn[n*gNumAudioChannels + c];
 		}
-        //use digital channels 2-5 to create a 4 bit binary counter
-        digital[n]=digital[n] & (~0b111100); // set to zero (GPIO_OUTPUT) the bits in the lower word
-        digital[n]=digital[n] & (~0b111100<<16); //initialize to zero the bits in the higher word (output value)
-        digital[n]=digital[n] | (n<<(16+2));  // set the bits in the higher word to the desired output value
+        //use digital channels 2-8 to create a 7 bit binary counter
+        digital[n]=digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word
+        digital[n]=digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value)
+        digital[n]=digital[n] | ( ((gCountFrames&0b1111111)<<(16+2)) ) ;  // set the bits in the higher word to the desired output value, keeping the lower word unchanged
+        digitalWriteFrame(P8_29,n,digitalRead(P8_30,n)); // echo the input from from channel 15 to channel 14
+        digitalWriteFrame(P8_28,n,digitalRead(P9_16,n)); // echo the input from from channel 10 to channel 13
+        setDigitalDirection(P8_30,0,GPIO_INPUT); //set channel 15 to input
+		gCountFrames++;
 	}
 
 	for(int n=0; n<numAnalogFrames; n++){
@@ -86,7 +89,6 @@
 //		for(int c=0; c<gNumAnalogChannels; c++)
 //			rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]);
 //		rt_printf("\n");
-		gCountFrames++;
 	}
 	return;