Mercurial > hg > beaglert
changeset 308:1feb9c23ac57 prerelease
Renamed read/write functions to remove the Frame --> e.g. analogWriteFrameOnce -> analogWriteOnce, digitalReadFrame -> digitalRead
line wrap: on
line diff
--- a/core/PulseIn.cpp Fri May 27 18:12:15 2016 +0100 +++ b/core/PulseIn.cpp Fri May 27 18:21:21 2016 +0100 @@ -25,12 +25,12 @@ } for(unsigned int n = 0; n < context->digitalFrames; n++){ if(_pulseIsOn == false){ // look for start edge - if(digitalReadFrame(context, n, _digitalInput) == _pulseOnState){ + if(digitalRead(context, n, _digitalInput) == _pulseOnState){ _pulseStart = context->audioSampleCount + n; // store location of start edge _pulseIsOn = true; } } else { // _pulseIsOn == true; - if(digitalReadFrame(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge + if(digitalRead(context, n, _digitalInput) == !_pulseOnState){ // look for stop edge _array[n] = context->audioSampleCount + n - _pulseStart; // compute and store pulse duration _pulseIsOn = false; }
--- a/examples/7segment/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/7segment/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -80,25 +80,25 @@ // Write the currently displaying digit low and the rest high for(int i = 0; i < 4; i++) - digitalWriteFrameOnce(context, n, kPins[kDigits[i]], HIGH); - digitalWriteFrameOnce(context, n, kPins[kDigits[gCurrentlyDisplayingDigit]], LOW); + digitalWriteOnce(context, n, kPins[kDigits[i]], HIGH); + digitalWriteOnce(context, n, kPins[kDigits[gCurrentlyDisplayingDigit]], LOW); // Write the digit to the other outputs - digitalWriteFrameOnce(context, n, kPins[11], + digitalWriteOnce(context, n, kPins[11], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x01); // a - digitalWriteFrameOnce(context, n, kPins[6], + digitalWriteOnce(context, n, kPins[6], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x02); // b - digitalWriteFrameOnce(context, n, kPins[4], + digitalWriteOnce(context, n, kPins[4], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x04); // c - digitalWriteFrameOnce(context, n, kPins[1], + digitalWriteOnce(context, n, kPins[1], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x08); // d - digitalWriteFrameOnce(context, n, kPins[0], + digitalWriteOnce(context, n, kPins[0], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x10); // e - digitalWriteFrameOnce(context, n, kPins[10], + digitalWriteOnce(context, n, kPins[10], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x20); // f - digitalWriteFrameOnce(context, n, kPins[5], + digitalWriteOnce(context, n, kPins[5], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x40); // g - digitalWriteFrameOnce(context, n, kPins[2], + digitalWriteOnce(context, n, kPins[2], gCharacterToDisplay[gCurrentlyDisplayingDigit] & 0x80); // . // Check for changing state
--- a/examples/analogDigitalDemo/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/analogDigitalDemo/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -38,24 +38,24 @@ */ if((context->audioSampleCount&31)==0){ //every 32 frames... //ANALOG channels - analogWriteFrame(context, 0, 0, analogReadFrame(context, 0,0)); + analogWrite(context, 0, 0, analogRead(context, 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 // The value at the last frame will persist through the successive buffers until is set again. // This effectively is a pass-through with downsampling by 32 times - analogWriteFrame(context, 0, 3, 1.0); // write 1.0 to channel3 from frame0 to the end of the buffer - analogWriteFrame(context, 4, 3, 0.1); // write 0.1 to channel3 from frame4 to the end of the buffer - analogWriteFrameOnce(context, 6, 3, 0.2); //write 0.2 to channel3 only on frame 6 + analogWrite(context, 0, 3, 1.0); // write 1.0 to channel3 from frame0 to the end of the buffer + analogWrite(context, 4, 3, 0.1); // write 0.1 to channel3 from frame4 to the end of the buffer + analogWriteOnce(context, 6, 3, 0.2); //write 0.2 to channel3 only on frame 6 //this buffer for channel 3 will look like this: 1 1 1 1 0.1 0.1 0.2 0.1 //the next buffers for channel 3 will be filled up with 0.1 .... //DIGITAL channels - digitalWriteFrame(context, 0, P8_07, GPIO_HIGH); //sets all the frames to HIGH for channel 0 - digitalWriteFrameOnce(context, 4, P8_07, GPIO_LOW); //only frame 4 will be LOW for channel 0 + digitalWrite(context, 0, P8_07, GPIO_HIGH); //sets all the frames to HIGH for channel 0 + digitalWriteOnce(context, 4, P8_07, GPIO_LOW); //only frame 4 will be LOW for channel 0 // in this buffer the frames of channel 0 will look like this: 1 1 1 1 0 1 1 1 ...... 1 // in the next buffer each frame of channel 0 will be initialized to 1 (the last value of this buffer) - digitalWriteFrame(context, 0, P8_08, GPIO_HIGH); - digitalWriteFrame(context, 2, P8_08, GPIO_LOW); - digitalWriteFrame(context, 4, P8_08, GPIO_HIGH); - digitalWriteFrame(context, 5, P8_08, GPIO_LOW); + digitalWrite(context, 0, P8_08, GPIO_HIGH); + digitalWrite(context, 2, P8_08, GPIO_LOW); + digitalWrite(context, 4, P8_08, GPIO_HIGH); + digitalWrite(context, 5, P8_08, GPIO_LOW); pinModeFrame(context, 0, P9_16, 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) @@ -68,14 +68,14 @@ context->digital[n]=context->digital[n] & (~0b111111100); // set to zero (GPIO_OUTPUT) the bits in the lower word context->digital[n]=context->digital[n] & ((~0b111111100<<16) | 0xffff ); //initialize to zero the bits in the higher word (output value) context->digital[n]=context->digital[n] | ( ((context->audioSampleCount&0b1111111)<<(16+2)) ) ; // set the bits in the higher word to the desired output value, keeping the lower word unchanged - digitalWriteFrame(context, n, P8_29, digitalReadFrame(context, n, P8_30)); // echo the input from from channel 15 to channel 14 - digitalWriteFrame(context, n, P8_28, digitalReadFrame(context, n, P9_16)); // echo the input from from channel 10 to channel 13 + digitalWrite(context, n, P8_29, digitalRead(context, n, P8_30)); // echo the input from from channel 15 to channel 14 + digitalWrite(context, n, P8_28, digitalRead(context, n, P9_16)); // echo the input from from channel 10 to channel 13 pinModeFrame(context, 0, P8_30, 0); //set channel 15 to input } for(unsigned int n=0; n<context->analogFrames; n++){ - analogWriteFrame(context, n, 1, (context->audioSampleCount&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames - analogWriteFrame(context, n, 2, analogReadFrame(context, n, 2)); // writes a single frame. channel2 is just a passthrough + analogWrite(context, n, 1, (context->audioSampleCount&8191)/8192.0); // writes a single frame. channel 1 is a ramp that follows gCountFrames + analogWrite(context, n, 2, analogRead(context, n, 2)); // writes a single frame. channel2 is just a passthrough // rt_printf("Analog out frame %d :",n); // for(int c=0; c<gNumAnalogChannels; c++) // rt_printf("%.1f ",analogOut[n*gNumAnalogChannels + c]);
--- a/examples/basic/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -55,7 +55,7 @@ // context->audioOut[n * context->audioChannels + channel] = out; // Or using the macros: - audioWriteFrame(context, n, channel, out); + audioWrite(context, n, channel, out); } } }
--- a/examples/basic_FFT_phase_vocoder/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_FFT_phase_vocoder/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -216,7 +216,7 @@ for(int n = 0; n < numAudioFrames; n++) { if(gReadPtr < gSampleData.sampleLen) audioIn[2*n] = audioIn[2*n+1] = gSampleData.samples[gReadPtr]*(1-gPlaybackLive) + - gPlaybackLive*0.5f*(audioReadFrame(context,n,0)+audioReadFrame(context,n,1)); + gPlaybackLive*0.5f*(audioRead(context,n,0)+audioRead(context,n,1)); else audioIn[2*n] = audioIn[2*n+1] = 0; if(++gReadPtr >= gSampleData.sampleLen)
--- a/examples/basic_analog_input/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_analog_input/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -61,8 +61,8 @@ for(unsigned int n = 0; n < context->audioFrames; n++) { if(!(n % gAudioFramesPerAnalogFrame)) { // Even audio samples: update frequency and amplitude from the matrix - frequency = map(analogReadFrame(context, n/gAudioFramesPerAnalogFrame, gSensorInputFrequency), 0, 1, 100, 1000); - amplitude = analogReadFrame(context, n/gAudioFramesPerAnalogFrame, gSensorInputAmplitude); + frequency = map(analogRead(context, n/gAudioFramesPerAnalogFrame, gSensorInputFrequency), 0, 1, 100, 1000); + amplitude = analogRead(context, n/gAudioFramesPerAnalogFrame, gSensorInputAmplitude); } float out = amplitude * sinf(gPhase);
--- a/examples/basic_analog_output/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_analog_output/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -57,7 +57,7 @@ for(unsigned int channel = 0; channel < context->analogChannels; channel++) { float out = kMinimumAmplitude + kAmplitudeRange * 0.5f * (1.0f + sinf(gPhase + relativePhase)); - analogWriteFrame(context, n, channel, out); + analogWrite(context, n, channel, out); // Advance by pi/4 (1/8 of a full rotation) for each channel relativePhase += M_PI * 0.25;
--- a/examples/basic_blink/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_blink/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -36,13 +36,13 @@ for(unsigned int n=0; n<context->digitalFrames; n++){ if(count==context->digitalSampleRate*interval){ //if enough samples have elapsed count=0; //reset the counter - // status=digitalReadFrame(context, 0, P8_07); + // status=digitalRead(context, 0, P8_07); if(status==GPIO_LOW) { //toggle the status - digitalWriteFrame(context, n, P8_07, status); //write the status to the LED + digitalWrite(context, n, P8_07, status); //write the status to the LED status=GPIO_HIGH; } else { - digitalWriteFrame(context, n, P8_07, status); //write the status to the LED + digitalWrite(context, n, P8_07, status); //write the status to the LED status=GPIO_LOW; } }
--- a/examples/basic_button/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_button/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -42,11 +42,11 @@ void render(BelaContext *context, void *userData) { for(unsigned int n=0; n<context->digitalFrames; n++){ - int status=digitalReadFrame(context, 0, P8_08); //read the value of the button - digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED + int status=digitalRead(context, 0, P8_08); //read the value of the button + digitalWriteOnce(context, n, P8_07, status); //write the status to the LED float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button for(unsigned int j = 0; j < context->audioChannels; j++){ - audioWriteFrame(context, n, j, out); //write the audio output + audioWrite(context, n, j, out); //write the audio output } } }
--- a/examples/basic_libpd/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_libpd/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -115,21 +115,21 @@ // rt_printf("channelsInUse: %d, analogChannels in Use: %d\n", gChannelsInUse, analogChannelsInUse); for(unsigned int n = 0; n < context->audioFrames; ++n){ //pd buffers are interleaved for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ //first two channels are audio - gInBuf[inW++] = audioReadFrame(context, n, ch); + gInBuf[inW++] = audioRead(context, n, ch); } // then analogs // this loop resamples by ZOH, as needed, using m if(context->analogChannels == 8 ){ //hold the value for two frames for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ - gInBuf[inW++] = analogReadFrame(context, n/2, analogCh); // n/2 wil be the same for n and n+1 when n is even + gInBuf[inW++] = analogRead(context, n/2, analogCh); // n/2 wil be the same for n and n+1 when n is even } } else if(context->analogChannels == 4){ //write every frame for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ - gInBuf[inW++] = analogReadFrame(context, n, analogCh); + gInBuf[inW++] = analogRead(context, n, analogCh); } } else if(context->analogChannels == 2){ //drop every other frame for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ - gInBuf[inW++] = analogReadFrame(context, n*2, analogCh); + gInBuf[inW++] = analogRead(context, n*2, analogCh); } } if(inW == gBufLength * gChannelsInUse){ @@ -145,14 +145,14 @@ for(unsigned int n = 0; n < context->audioFrames; n++){ //pd buffers are interleaved for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ - audioWriteFrame(context, n, ch, gOutBuf[outR++]); + audioWrite(context, n, ch, gOutBuf[outR++]); } //and analogs if(context->analogChannels == 8){ for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ float analogOut = gOutBuf[outR++]; if((n&1) == 0){//write every two frames - analogWriteFrame(context, n/2, analogCh, analogOut); + analogWrite(context, n/2, analogCh, analogOut); } else { // discard this sample } @@ -160,13 +160,13 @@ } else if(context->analogChannels == 4){ //write every frame for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ float analogOut = gOutBuf[outR++]; - analogWriteFrame(context, n, analogCh, analogOut); + analogWrite(context, n, analogCh, analogOut); } } else if(context->analogChannels == 2){ //write twice every frame for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ float analogOut = gOutBuf[outR++]; - analogWriteFrame(context, 2*n, analogCh, analogOut); - analogWriteFrame(context, 2*n + 1, analogCh, analogOut); + analogWrite(context, 2*n, analogCh, analogOut); + analogWrite(context, 2*n + 1, analogCh, analogOut); } } if(outR == gBufLength * gChannelsInUse){
--- a/examples/basic_midi/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_midi/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -133,7 +133,7 @@ for(unsigned int n = 0; n < context->analogFrames; n++){ static int count = 0; static bool state = 0; - analogWriteFrameOnce(context, n, 1, state); + analogWriteOnce(context, n, 1, state); if(count % 40000 == 0){ state = !state; midi_byte_t bytes[6] = {176, 30, (char)(state*127), 176, 67, 30}; // toggle the OWL led and ask for the led status @@ -148,11 +148,11 @@ if(phase > 2 * M_PI) phase -= 2 * M_PI; float value = sinf(phase) * gVelocity/128.0f; - audioWriteFrame(context, n, 0, value); - audioWriteFrame(context, n, 1, value); + audioWrite(context, n, 0, value); + audioWrite(context, n, 1, value); } else { - audioWriteFrame(context, n, 0, 0); - audioWriteFrame(context, n, 1, 0); + audioWrite(context, n, 0, 0); + audioWrite(context, n, 1, 0); } } }
--- a/examples/basic_network/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_network/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -56,7 +56,7 @@ float in; int ret = receive.getSamplesSrc(&in, 1, 1); for(unsigned int channel = 0; channel < context->audioChannels; channel++){ - audioWriteFrame(context, n, channel, in); + audioWrite(context, n, channel, in); } } }
--- a/examples/basic_passthru/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_passthru/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -42,7 +42,7 @@ // context->audioIn[n * context->audioChannels + ch]; // Or using the macros: - audioWriteFrame(context, n, ch, audioReadFrame(context, n, ch)); + audioWrite(context, n, ch, audioRead(context, n, ch)); } } @@ -55,7 +55,7 @@ // context->analogOut[n * context->analogChannels + ch] = context->analogIn[n * context->analogChannels + ch]; // Or using the macros: - analogWriteFrame(context, n, ch, analogReadFrame(context, n, ch)); + analogWrite(context, n, ch, analogRead(context, n, ch)); } } }
--- a/examples/basic_pulseIn/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/basic_pulseIn/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -59,7 +59,7 @@ pulseOut = true; count = 0; } - digitalWriteFrame(context, n, gDigitalOutPin, pulseOut); + digitalWrite(context, n, gDigitalOutPin, pulseOut); count++; } }
--- a/examples/bucket_brigade_chorus/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/bucket_brigade_chorus/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -93,11 +93,11 @@ for(unsigned int n = 0; n < context->audioFrames; n++) { feedback = 0.4; - float input = audioReadFrame(context, n, 0) + audioReadFrame(context, n, 1); + float input = audioRead(context, n, 0) + audioRead(context, n, 1); delay[writePointer++] = input + delay[readPointer]*feedback; float output = (input + 0.9*delay[readPointer++] ) * 0.5; - audioWriteFrame(context, n, 0, output); - audioWriteFrame(context, n, 1, output); + audioWrite(context, n, 0, output); + audioWrite(context, n, 1, output); if(writePointer>=delayLength) writePointer-=delayLength; if(readPointer>=delayLength)
--- a/examples/gpioAnalogLoopbackTest/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/gpioAnalogLoopbackTest/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -99,20 +99,20 @@ static int count = 0; bool doReadWrite = context->analogChannels<=4 ? true : ((context->analogChannels == 8) && (n&1)==0); if(doReadWrite){ - digitalAIn = digitalReadFrame(context, n, gDigitalInACh); + digitalAIn = digitalRead(context, n, gDigitalInACh); switch(context->analogChannels){ case 8: - analog0In = analogReadFrame(context, n/2, 0) > 0.5; - analogWriteFrame(context, n/2, analogOut, writePattern[outPointer]); + analog0In = analogRead(context, n/2, 0) > 0.5; + analogWrite(context, n/2, analogOut, writePattern[outPointer]); break; case 4: - analog0In = analogReadFrame(context, n, 0) > 0.5; - analogWriteFrame(context, n, analogOut, writePattern[outPointer]); + analog0In = analogRead(context, n, 0) > 0.5; + analogWrite(context, n, analogOut, writePattern[outPointer]); break; case 2: - analog0In = analogReadFrame(context, n * 2 + 1, 0) > 0.5; - analogWriteFrame(context, 2 * n, analogOut, writePattern[outPointer]); - analogWriteFrame(context, 2 * n + 1, analogOut, writePattern[outPointer]); + analog0In = analogRead(context, n * 2 + 1, 0) > 0.5; + analogWrite(context, 2 * n, analogOut, writePattern[outPointer]); + analogWrite(context, 2 * n + 1, analogOut, writePattern[outPointer]); break; } gAnalogOutLoopDelay--; @@ -150,24 +150,24 @@ */ bool doReadWrite = false; static bool pastAnalog1In = false; - digitalWriteFrameOnce(context, n, gDigitalOutCh, writePattern[digitalOutPointer]); + digitalWriteOnce(context, n, gDigitalOutCh, writePattern[digitalOutPointer]); if(context->analogChannels == 8){ if((n&1) == 0){ //do it every other sample - pastAnalog1In = analogReadFrame(context, n/2, 1) > 0.5; - digitalDIn = digitalReadFrame(context, n, gDigitalInDCh); + pastAnalog1In = analogRead(context, n/2, 1) > 0.5; + digitalDIn = digitalRead(context, n, gDigitalInDCh); doReadWrite = true; } } if(context->analogChannels == 4){ - pastAnalog1In = analogReadFrame(context, n, 1) > 0.5; - digitalDIn = digitalReadFrame(context, n, gDigitalInDCh); - digitalWriteFrameOnce(context, n, gDigitalOutCh, writePattern[digitalOutPointer]); + pastAnalog1In = analogRead(context, n, 1) > 0.5; + digitalDIn = digitalRead(context, n, gDigitalInDCh); + digitalWriteOnce(context, n, gDigitalOutCh, writePattern[digitalOutPointer]); doReadWrite = true; } if(context->analogChannels == 2){ - pastAnalog1In = analogReadFrame(context, n * 2, 1) > 0.5; - digitalDIn = digitalReadFrame(context, n, gDigitalInDCh); - digitalWriteFrameOnce(context, n, gDigitalOutCh, writePattern[digitalOutPointer]); + pastAnalog1In = analogRead(context, n * 2, 1) > 0.5; + digitalDIn = digitalRead(context, n, gDigitalInDCh); + digitalWriteOnce(context, n, gDigitalOutCh, writePattern[digitalOutPointer]); doReadWrite = true; } bool expectedDigitalIn = writePattern[digitalInPointer];
--- a/examples/level_meter/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/level_meter/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -126,7 +126,7 @@ state = HIGH; // Write LED - digitalWriteFrameOnce(context, n, led, state); + digitalWriteOnce(context, n, led, state); } } }
--- a/examples/scope_analogue/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/scope_analogue/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -30,8 +30,8 @@ for(unsigned int n = 0; n < context->audioFrames; n++) { // read analogIn channels 0 and 1 - float in1 = analogReadFrame(context, n, 0); - float in2 = analogReadFrame(context, n, 1); + float in1 = analogRead(context, n, 0); + float in2 = analogRead(context, n, 1); // map in1 to amplitude and in2 to frequency float amplitude = in1 * 0.8f;
--- a/examples/stepper/render.cpp Fri May 27 18:12:15 2016 +0100 +++ b/examples/stepper/render.cpp Fri May 27 18:21:21 2016 +0100 @@ -76,27 +76,27 @@ { for(unsigned int n = 0; n < context->audioFrames; n++) { if(gPhase == 0 || gPhase == 1) { - digitalWriteFrameOnce(context, n, gPinB1, HIGH); - digitalWriteFrameOnce(context, n, gPinB2, LOW); + digitalWriteOnce(context, n, gPinB1, HIGH); + digitalWriteOnce(context, n, gPinB2, LOW); } else { - digitalWriteFrameOnce(context, n, gPinB1, LOW); - digitalWriteFrameOnce(context, n, gPinB2, HIGH); + digitalWriteOnce(context, n, gPinB1, LOW); + digitalWriteOnce(context, n, gPinB2, HIGH); } if(gPhase == 1 || gPhase == 2) { - digitalWriteFrameOnce(context, n, gPinA1, HIGH); - digitalWriteFrameOnce(context, n, gPinA2, LOW); + digitalWriteOnce(context, n, gPinA1, HIGH); + digitalWriteOnce(context, n, gPinA2, LOW); } else { - digitalWriteFrameOnce(context, n, gPinA1, LOW); - digitalWriteFrameOnce(context, n, gPinA2, HIGH); + digitalWriteOnce(context, n, gPinA1, LOW); + digitalWriteOnce(context, n, gPinA2, HIGH); } if(--gServoCounter > 0) - digitalWriteFrameOnce(context, n, gPinServo, HIGH); + digitalWriteOnce(context, n, gPinServo, HIGH); else - digitalWriteFrameOnce(context, n, gPinServo, LOW); + digitalWriteOnce(context, n, gPinServo, LOW); if(++gStepCounter >= gStepLengthSamples) { gStateCounter++;
--- a/include/Utilities.h Fri May 27 18:12:15 2016 +0100 +++ b/include/Utilities.h Fri May 27 18:21:21 2016 +0100 @@ -67,7 +67,6 @@ * @{ */ -#if 1 // Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from setup() // Likewise, thread launch should be able to be called from setup() // Also, make volume change functions callable from render() thread -- as an aux task? @@ -85,7 +84,7 @@ * (context->audioChannels - 1), typically 0 to 1 by default. * \return Value of the analog input, range to 1. */ -static inline float audioReadFrame(BelaContext *context, int frame, int channel); +static inline float audioRead(BelaContext *context, int frame, int channel); /** * \brief Write an audio output, specifying the frame number (when to write) and the channel. @@ -100,7 +99,7 @@ * (context->audioChannels - 1), typically 0 to 1 by default. * \param value Value to write to the output, range -1 to 1. */ -static inline void audioWriteFrame(BelaContext *context, int frame, int channel, float value); +static inline void audioWrite(BelaContext *context, int frame, int channel, float value); /** * \brief Read an analog input, specifying the frame number (when to read) and the channel. @@ -115,7 +114,7 @@ * (context->analogChannels - 1), typically 0 to 7 by default. * \return Value of the analog input, range 0 to 1. */ -static inline float analogReadFrame(BelaContext *context, int frame, int channel); +static inline float analogRead(BelaContext *context, int frame, int channel); /** * \brief Write an analog output, specifying the frame number (when to write) and the channel. @@ -133,7 +132,7 @@ * (context->analogChannels - 1), typically 0 to 7 by default. * \param value Value to write to the output, range 0 to 1. */ -static inline void analogWriteFrame(BelaContext *context, int frame, int channel, float value); +static inline void analogWrite(BelaContext *context, int frame, int channel, float value); /** * \brief Write an analog output, specifying the frame number (when to write) and the channel. @@ -141,11 +140,11 @@ * This function sets the value of an analog output, at the time indicated by \c frame. Valid * values are between 0 and 1, corresponding to the range 0 to 5V. * - * Unlike analogWriteFrame(), the value written will affect \b only the frame specified, with - * future values unchanged. This is faster than analogWriteFrame() so is better suited + * Unlike analogWrite(), the value written will affect \b only the frame specified, with + * future values unchanged. This is faster than analogWrite() so is better suited * to applications where every frame will be written to a different value. If * BELA_FLAG_ANALOG_OUTPUTS_PERSIST is not set within context->flags, then - * analogWriteFrameOnce() and analogWriteFrame() are equivalent. + * analogWriteOnce() and analogWrite() are equivalent. * * \param context The I/O data structure which is passed by Bela to render(). * \param frame Which frame (i.e. what time) to write the analog output. Valid values range @@ -154,7 +153,7 @@ * (context->analogChannels - 1), typically 0 to 7 by default. * \param value Value to write to the output, range 0 to 1. */ -static inline void analogWriteFrameOnce(BelaContext *context, int frame, int channel, float value); +static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value); /** * \brief Read a digital input, specifying the frame number (when to read) and the pin. @@ -170,7 +169,7 @@ * digital_gpio_mapping.h. * \return Value of the digital input. */ -static inline int digitalReadFrame(BelaContext *context, int frame, int channel); +static inline int digitalRead(BelaContext *context, int frame, int channel); /** * \brief Write a digital output, specifying the frame number (when to write) and the pin. @@ -188,7 +187,7 @@ * digital_gpio_mapping.h. * \param value Value to write to the output. */ -static inline void digitalWriteFrame(BelaContext *context, int frame, int channel, int value); +static inline void digitalWrite(BelaContext *context, int frame, int channel, int value); /** * \brief Write a digital output, specifying the frame number (when to write) and the pin. @@ -196,8 +195,8 @@ * This function sets the value of a digital output, at the time indicated by \c frame. * A value of 0 sets the pin low; any other value sets the pin high (3.3V). * - * Unlike digitalWriteFrame(), the value written will affect \b only the frame specified, with - * future values unchanged. This is faster than digitalWriteFrame() so is better suited + * Unlike digitalWrite(), the value written will affect \b only the frame specified, with + * future values unchanged. This is faster than digitalWrite() so is better suited * to applications where every frame will be written to a different value. * * \param context The I/O data structure which is passed by Bela to render(). @@ -208,7 +207,7 @@ * digital_gpio_mapping.h. * \param value Value to write to the output. */ -static inline void digitalWriteFrameOnce(BelaContext *context, int frame, int channel, int value); +static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value); /** * \brief Set the direction of a digital pin to input or output. @@ -248,42 +247,6 @@ /** @} */ -#else - -// Macros for accessing the analog values: usable _only_ within render() - -// Read an Analog input from input pin p at frame f -#define analogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)]) -// Write an Analog output frame at output pin p, frame f, to value v -#define analogWriteFrame(p, f, v) (analogOut[(f)*gNumAnalogChannels + (p)] = (v)) -#define analogWrite(pin, frame, value) \ -(({do {\ - for (int _privateI=(frame); _privateI<numAnalogFrames; _privateI++){ \ - analogWriteFrame(pin,_privateI,value); \ - }\ - } while (0);}),(void)0)\ - - -//digital API: -#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<numDigitalFrames; _privateI++) \ - digitalWriteFrame(pin,_privateI,value); \ - } while (0);}),(void)0)\ - -#define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) ) - -#endif - /** * \defgroup wiring Wiring language support * @@ -332,32 +295,32 @@ static inline float constrain(float x, float min_val, float max_val); /** @} */ -// audioReadFrame() +// audioRead() // // Returns the value of the given audio input at the given frame number. -static inline float audioReadFrame(BelaContext *context, int frame, int channel) { +static inline float audioRead(BelaContext *context, int frame, int channel) { return context->audioIn[frame * context->audioChannels + channel]; } -// audioWriteFrame() +// audioWrite() // // Sets a given audio output channel to a value for the current frame -static inline void audioWriteFrame(BelaContext *context, int frame, int channel, float value) { +static inline void audioWrite(BelaContext *context, int frame, int channel, float value) { context->audioOut[frame * context->audioChannels + channel] = value; } -// analogReadFrame() +// analogRead() // // Returns the value of the given analog input at the given frame number. -static inline float analogReadFrame(BelaContext *context, int frame, int channel) { +static inline float analogRead(BelaContext *context, int frame, int channel) { return context->analogIn[frame * context->analogChannels + channel]; } -// analogWriteFrame() +// analogWrite() // // Sets a given analog output channel to a value for the current frame and, if persistent outputs are // enabled, for all subsequent frames -static inline void analogWriteFrame(BelaContext *context, int frame, int channel, float value) { +static inline void analogWrite(BelaContext *context, int frame, int channel, float value) { if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) { for(unsigned int f = frame; f < context->analogFrames; f++) context->analogOut[frame * context->analogChannels + channel] = value; @@ -366,24 +329,24 @@ context->analogOut[frame * context->analogChannels + channel] = value; } -// analogWriteFrameOnce() +// analogWriteOnce() // // Sets a given channel to a value for only the current frame -static inline void analogWriteFrameOnce(BelaContext *context, int frame, int channel, float value) { +static inline void analogWriteOnce(BelaContext *context, int frame, int channel, float value) { context->analogOut[frame * context->analogChannels + channel] = value; } -// digitalReadFrame() +// digitalRead() // // Returns the value of a given digital input at the given frame number -static inline int digitalReadFrame(BelaContext *context, int frame, int channel) { +static inline int digitalRead(BelaContext *context, int frame, int channel) { return getBit(context->digital[frame], channel + 16); } -// digitalWriteFrame() +// digitalWrite() // // Sets a given digital output channel to a value for the current frame and all subsequent frames -static inline void digitalWriteFrame(BelaContext *context, int frame, int channel, int value) { +static inline void digitalWrite(BelaContext *context, int frame, int channel, int value) { for(unsigned int f = frame; f < context->digitalFrames; f++) { if(value) context->digital[f] |= 1 << (channel + 16); @@ -392,10 +355,10 @@ } } -// digitalWriteFrameOnce() +// digitalWriteOnce() // // Sets a given digital output channel to a value for the current frame only -static inline void digitalWriteFrameOnce(BelaContext *context, int frame, int channel, int value) { +static inline void digitalWriteOnce(BelaContext *context, int frame, int channel, int value) { if(value) context->digital[frame] |= 1 << (channel + 16); else