diff include/Utilities.h @ 18:31503d9de101 matrix_gpio

- digitalWrite and analogWrite macros are now persistent: they write a value on the given channel from the current frame to the end of the buffer. When this is not needed you can use digitalWriteFrame and analogWriteFrame instead. - included the matrix_gpio_demo code - the Eclipe project is somehow broken
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 30 Apr 2015 16:02:47 +0100
parents 670be80463a3
children c98863e63174
line wrap: on
line diff
--- a/include/Utilities.h	Mon Apr 27 18:27:04 2015 +0100
+++ b/include/Utilities.h	Thu Apr 30 16:02:47 2015 +0100
@@ -16,18 +16,31 @@
 // Read an analog input from input pin p at frame f
 #define analogRead(p, f) (matrixIn[(f)*gNumMatrixChannels + (p)])
 // Write an analog output frame at output pin p, frame f, to value v
-#define analogWrite(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (uint16_t)(v))
+#define analogWriteFrame(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (v))
+#define analogWrite(pin, frame, value) \
+(({do {\
+	for (int _privateI=(frame); _privateI<numMatrixFrames; _privateI++){ \
+		analogWriteFrame(pin,_privateI,value); \
+	}\
+	} while (0);}),(void)0)\
 
 #define setBit(word,bit) ((word)|(1<<(bit)))
 #define clearBit(word,bit) ((word)&~(1<<(bit)))
 #define getBit(word,bit) (((word)>>(bit))&1)
 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit)))
 //matrixGpio API:
-#define setDigitalDirection(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction))
+#define setDigitalDirectionFrame(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction))
+#define setDigitalDirection(pin,frame,direction) (for(int _privateI=(frame);_privateI<gNumGpioFrames;_privateI++) matrixGpio[_privateI]=changeBit(matrixGpio[(_privateI)],(pin),(direction))),void(0)
 #define digitalWriteAll(frame,value) matrixGpio[(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 digitalWrite(pin, frame, value) matrixGpio[(frame)]=( changeBit(matrixGpio[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments
-#define digitalRead(pin, frame) (   getBit(matrixGpio[(frame)], pin+16) )
+#define digitalWriteFrame(pin, frame, value) matrixGpio[(frame)]=( changeBit(matrixGpio[(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<gNumMatrixGpioFrames; _privateI++) \
+			digitalWriteFrame(pin,_privateI,value); \
+		} while (0);}),(void)0)\
+
+#define digitalRead(pin, frame) ( getBit(matrixGpio[(frame)], pin+16) )
 
 float map(float x, float in_min, float in_max, float out_min, float out_max);
 float constrain(float x, float min_val, float max_val);