andrewm@0
|
1 /*
|
andrewm@0
|
2 * Utilities.h
|
andrewm@0
|
3 *
|
andrewm@0
|
4 * Created on: Oct 27, 2014
|
andrewm@0
|
5 * Author: parallels
|
andrewm@0
|
6 */
|
andrewm@0
|
7
|
andrewm@0
|
8 #ifndef UTILITIES_H_
|
andrewm@0
|
9 #define UTILITIES_H_
|
andrewm@0
|
10
|
andrewm@13
|
11 extern int gNumAudioChannels; // How many audio channels are present
|
andrewm@13
|
12 extern int gNumMatrixChannels; // How many matrix channels are present
|
andrewm@13
|
13
|
andrewm@5
|
14 // Macros for accessing the matrix values: usable _only_ within render()
|
andrewm@5
|
15
|
andrewm@5
|
16 // Read an analog input from input pin p at frame f
|
andrewm@13
|
17 #define analogRead(p, f) (matrixIn[(f)*gNumMatrixChannels + (p)])
|
andrewm@5
|
18 // Write an analog output frame at output pin p, frame f, to value v
|
giuliomoro@18
|
19 #define analogWriteFrame(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (v))
|
giuliomoro@18
|
20 #define analogWrite(pin, frame, value) \
|
giuliomoro@18
|
21 (({do {\
|
giuliomoro@18
|
22 for (int _privateI=(frame); _privateI<numMatrixFrames; _privateI++){ \
|
giuliomoro@18
|
23 analogWriteFrame(pin,_privateI,value); \
|
giuliomoro@18
|
24 }\
|
giuliomoro@18
|
25 } while (0);}),(void)0)\
|
andrewm@5
|
26
|
giuliomoro@16
|
27 #define setBit(word,bit) ((word)|(1<<(bit)))
|
giuliomoro@16
|
28 #define clearBit(word,bit) ((word)&~(1<<(bit)))
|
giuliomoro@16
|
29 #define getBit(word,bit) (((word)>>(bit))&1)
|
giuliomoro@16
|
30 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit)))
|
giuliomoro@16
|
31 //matrixGpio API:
|
giuliomoro@18
|
32 #define setDigitalDirectionFrame(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction))
|
giuliomoro@18
|
33 #define setDigitalDirection(pin,frame,direction) (for(int _privateI=(frame);_privateI<gNumGpioFrames;_privateI++) matrixGpio[_privateI]=changeBit(matrixGpio[(_privateI)],(pin),(direction))),void(0)
|
giuliomoro@16
|
34 #define digitalWriteAll(frame,value) matrixGpio[(frame)]=0xffff0000*(!(!value));
|
giuliomoro@16
|
35 //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set)
|
giuliomoro@18
|
36 #define digitalWriteFrame(pin, frame, value) matrixGpio[(frame)]=( changeBit(matrixGpio[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments
|
giuliomoro@18
|
37 #define digitalWrite(pin, frame, value) \
|
giuliomoro@18
|
38 (({do {\
|
giuliomoro@18
|
39 for (int _privateI=(frame); _privateI<gNumMatrixGpioFrames; _privateI++) \
|
giuliomoro@18
|
40 digitalWriteFrame(pin,_privateI,value); \
|
giuliomoro@18
|
41 } while (0);}),(void)0)\
|
giuliomoro@18
|
42
|
giuliomoro@18
|
43 #define digitalRead(pin, frame) ( getBit(matrixGpio[(frame)], pin+16) )
|
giuliomoro@16
|
44
|
andrewm@0
|
45 float map(float x, float in_min, float in_max, float out_min, float out_max);
|
andrewm@0
|
46 float constrain(float x, float min_val, float max_val);
|
andrewm@0
|
47
|
andrewm@0
|
48 #endif /* UTILITIES_H_ */
|