diff include/Utilities.h @ 308:1feb9c23ac57 prerelease

Renamed read/write functions to remove the Frame --> e.g. analogWriteFrameOnce -> analogWriteOnce, digitalReadFrame -> digitalRead
author andrewm
date Fri, 27 May 2016 18:21:21 +0100
parents 421a69d42943
children 02c4ca0e3718
line wrap: on
line diff
--- 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