Mercurial > hg > beaglert
comparison include/Utilities.h @ 19:c98863e63174 matrix_gpio
Renamed matrixGpio to digital and matrix to analog
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 30 Apr 2015 16:58:41 +0100 |
parents | 31503d9de101 |
children | 182ae9367104 |
comparison
equal
deleted
inserted
replaced
18:31503d9de101 | 19:c98863e63174 |
---|---|
7 | 7 |
8 #ifndef UTILITIES_H_ | 8 #ifndef UTILITIES_H_ |
9 #define UTILITIES_H_ | 9 #define UTILITIES_H_ |
10 | 10 |
11 extern int gNumAudioChannels; // How many audio channels are present | 11 extern int gNumAudioChannels; // How many audio channels are present |
12 extern int gNumMatrixChannels; // How many matrix channels are present | 12 extern int gNumAnalogChannels; // How many analog channels are present |
13 | 13 |
14 // Macros for accessing the matrix values: usable _only_ within render() | 14 // Macros for accessing the analog values: usable _only_ within render() |
15 | 15 |
16 // Read an analog input from input pin p at frame f | 16 // Read an Analog input from input pin p at frame f |
17 #define analogRead(p, f) (matrixIn[(f)*gNumMatrixChannels + (p)]) | 17 #define AnalogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)]) |
18 // Write an analog output frame at output pin p, frame f, to value v | 18 // Write an Analog output frame at output pin p, frame f, to value v |
19 #define analogWriteFrame(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (v)) | 19 #define AnalogWriteFrame(p, f, v) (analogOut[(f)*gNumAnalogChannels + (p)] = (v)) |
20 #define analogWrite(pin, frame, value) \ | 20 #define AnalogWrite(pin, frame, value) \ |
21 (({do {\ | 21 (({do {\ |
22 for (int _privateI=(frame); _privateI<numMatrixFrames; _privateI++){ \ | 22 for (int _privateI=(frame); _privateI<numAnalogFrames; _privateI++){ \ |
23 analogWriteFrame(pin,_privateI,value); \ | 23 AnalogWriteFrame(pin,_privateI,value); \ |
24 }\ | 24 }\ |
25 } while (0);}),(void)0)\ | 25 } while (0);}),(void)0)\ |
26 | 26 |
27 #define setBit(word,bit) ((word)|(1<<(bit))) | 27 #define setBit(word,bit) ((word)|(1<<(bit))) |
28 #define clearBit(word,bit) ((word)&~(1<<(bit))) | 28 #define clearBit(word,bit) ((word)&~(1<<(bit))) |
29 #define getBit(word,bit) (((word)>>(bit))&1) | 29 #define getBit(word,bit) (((word)>>(bit))&1) |
30 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) | 30 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) |
31 //matrixGpio API: | 31 //digital API: |
32 #define setDigitalDirectionFrame(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction)) | 32 #define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)) |
33 #define setDigitalDirection(pin,frame,direction) (for(int _privateI=(frame);_privateI<gNumGpioFrames;_privateI++) matrixGpio[_privateI]=changeBit(matrixGpio[(_privateI)],(pin),(direction))),void(0) | 33 #define setDigitalDirection(pin,frame,direction) (for(int _privateI=(frame);_privateI<gNumGpioFrames;_privateI++) digital[_privateI]=changeBit(digital[(_privateI)],(pin),(direction))),void(0) |
34 #define digitalWriteAll(frame,value) matrixGpio[(frame)]=0xffff0000*(!(!value)); | 34 #define digitalWriteAll(frame,value) digital[(frame)]=0xffff0000*(!(!value)); |
35 //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set) | 35 //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set) |
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 | 36 #define digitalWriteFrame(pin, frame, value) digital[(frame)]=( changeBit(digital[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments |
37 #define digitalWrite(pin, frame, value) \ | 37 #define digitalWrite(pin, frame, value) \ |
38 (({do {\ | 38 (({do {\ |
39 for (int _privateI=(frame); _privateI<gNumMatrixGpioFrames; _privateI++) \ | 39 for (int _privateI=(frame); _privateI<gNumDigitalFrames; _privateI++) \ |
40 digitalWriteFrame(pin,_privateI,value); \ | 40 digitalWriteFrame(pin,_privateI,value); \ |
41 } while (0);}),(void)0)\ | 41 } while (0);}),(void)0)\ |
42 | 42 |
43 #define digitalRead(pin, frame) ( getBit(matrixGpio[(frame)], pin+16) ) | 43 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) ) |
44 | 44 |
45 float map(float x, float in_min, float in_max, float out_min, float out_max); | 45 float map(float x, float in_min, float in_max, float out_min, float out_max); |
46 float constrain(float x, float min_val, float max_val); | 46 float constrain(float x, float min_val, float max_val); |
47 | 47 |
48 #endif /* UTILITIES_H_ */ | 48 #endif /* UTILITIES_H_ */ |