Mercurial > hg > beaglert
changeset 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 | 06fd2ffee605 |
children | 46d87f680da5 |
files | include/Utilities.h projects/analogDigitalDemo/render.cpp |
diffstat | 2 files changed, 17 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/include/Utilities.h Mon May 11 11:45:03 2015 +0100 +++ b/include/Utilities.h Mon May 11 18:58:47 2015 +0100 @@ -29,14 +29,18 @@ #define getBit(word,bit) (((word)>>(bit))&1) #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) //digital API: -#define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)) -#define setDigitalDirection(pin,frame,direction) (for(int _privateI=(frame);_privateI<gNumGpioFrames;_privateI++) digital[_privateI]=changeBit(digital[(_privateI)],(pin),(direction))),void(0) +#define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)),void(0) +#define setDigitalDirection(pin,frame,direction)\ + (({do {\ + for(int _privateI=(frame); _privateI<numDigitalFrames; _privateI++)\ + setDigitalDirectionFrame(pin,_privateI,direction);\ + } while (0);}), (void)0) #define digitalWriteAll(frame,value) digital[(frame)]=0xffff0000*(!(!value)); //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set) #define digitalWriteFrame(pin, frame, value) digital[(frame)]=( changeBit(digital[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments #define digitalWrite(pin, frame, value) \ (({do {\ - for (int _privateI=(frame); _privateI<gNumDigitalFrames; _privateI++) \ + for (int _privateI=(frame); _privateI<numDigitalFrames; _privateI++) \ digitalWriteFrame(pin,_privateI,value); \ } while (0);}),(void)0)\
--- 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;