diff include/Utilities.h @ 16:670be80463a3 matrix_gpio

- analog matrixIn/matrixOut are now mapped as floats from 0 to 1 - use of an external PRU code can be enabled with -P <filename> - 16 channels of programmable GPIO can be accessed straight from render() either writing directly to the matrixGpio[] array or using digitalWrite(), digitalRead(), setDigitalDirection() macros from Utilities.h .
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 27 Apr 2015 13:01:57 +0100
parents 6adb088196a7
children 31503d9de101
line wrap: on
line diff
--- a/include/Utilities.h	Sat Feb 07 16:41:56 2015 +0000
+++ b/include/Utilities.h	Mon Apr 27 13:01:57 2015 +0100
@@ -18,6 +18,17 @@
 // 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 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 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) )
+
 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);