annotate include/Utilities.h @ 39:638bc1ae2500 staging

Improved readibility of the DIGITAL code in the PRU, using register names instead of aliases and expanding some of the macros, removing unused macros. Binaries were not modified
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 13 May 2015 12:18:10 +0100
parents 83baffda5786
children 579c86316008
rev   line source
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
giuliomoro@19 12 extern int gNumAnalogChannels; // How many analog channels are present
andrewm@13 13
giuliomoro@19 14 // Macros for accessing the analog values: usable _only_ within render()
andrewm@5 15
giuliomoro@19 16 // Read an Analog input from input pin p at frame f
giuliomoro@23 17 #define analogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)])
giuliomoro@19 18 // Write an Analog output frame at output pin p, frame f, to value v
giuliomoro@23 19 #define analogWriteFrame(p, f, v) (analogOut[(f)*gNumAnalogChannels + (p)] = (v))
giuliomoro@23 20 #define analogWrite(pin, frame, value) \
giuliomoro@18 21 (({do {\
giuliomoro@19 22 for (int _privateI=(frame); _privateI<numAnalogFrames; _privateI++){ \
giuliomoro@23 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@19 31 //digital API:
giuliomoro@33 32 #define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)),void(0)
giuliomoro@33 33 #define setDigitalDirection(pin,frame,direction)\
giuliomoro@33 34 (({do {\
giuliomoro@33 35 for(int _privateI=(frame); _privateI<numDigitalFrames; _privateI++)\
giuliomoro@33 36 setDigitalDirectionFrame(pin,_privateI,direction);\
giuliomoro@33 37 } while (0);}), (void)0)
giuliomoro@19 38 #define digitalWriteAll(frame,value) digital[(frame)]=0xffff0000*(!(!value));
giuliomoro@16 39 //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set)
giuliomoro@19 40 #define digitalWriteFrame(pin, frame, value) digital[(frame)]=( changeBit(digital[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments
giuliomoro@18 41 #define digitalWrite(pin, frame, value) \
giuliomoro@18 42 (({do {\
giuliomoro@33 43 for (int _privateI=(frame); _privateI<numDigitalFrames; _privateI++) \
giuliomoro@18 44 digitalWriteFrame(pin,_privateI,value); \
giuliomoro@18 45 } while (0);}),(void)0)\
giuliomoro@18 46
giuliomoro@19 47 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) )
giuliomoro@16 48
andrewm@0 49 float map(float x, float in_min, float in_max, float out_min, float out_max);
andrewm@0 50 float constrain(float x, float min_val, float max_val);
andrewm@0 51
andrewm@0 52 #endif /* UTILITIES_H_ */