andrewm@0: /* andrewm@0: * Utilities.h andrewm@0: * andrewm@0: * Created on: Oct 27, 2014 andrewm@0: * Author: parallels andrewm@0: */ andrewm@0: andrewm@0: #ifndef UTILITIES_H_ andrewm@0: #define UTILITIES_H_ andrewm@0: andrewm@13: extern int gNumAudioChannels; // How many audio channels are present andrewm@13: extern int gNumMatrixChannels; // How many matrix channels are present andrewm@13: andrewm@5: // Macros for accessing the matrix values: usable _only_ within render() andrewm@5: andrewm@5: // Read an analog input from input pin p at frame f andrewm@13: #define analogRead(p, f) (matrixIn[(f)*gNumMatrixChannels + (p)]) andrewm@5: // Write an analog output frame at output pin p, frame f, to value v andrewm@13: #define analogWrite(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (uint16_t)(v)) andrewm@5: giuliomoro@16: #define setBit(word,bit) ((word)|(1<<(bit))) giuliomoro@16: #define clearBit(word,bit) ((word)&~(1<<(bit))) giuliomoro@16: #define getBit(word,bit) (((word)>>(bit))&1) giuliomoro@16: #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) giuliomoro@16: //matrixGpio API: giuliomoro@16: #define setDigitalDirection(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction)) giuliomoro@16: #define digitalWriteAll(frame,value) matrixGpio[(frame)]=0xffff0000*(!(!value)); giuliomoro@16: //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set) giuliomoro@16: #define digitalWrite(pin, frame, value) matrixGpio[(frame)]=( changeBit(matrixGpio[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments giuliomoro@16: #define digitalRead(pin, frame) ( getBit(matrixGpio[(frame)], pin+16) ) giuliomoro@16: andrewm@0: float map(float x, float in_min, float in_max, float out_min, float out_max); andrewm@0: float constrain(float x, float min_val, float max_val); andrewm@0: andrewm@0: #endif /* UTILITIES_H_ */