Mercurial > hg > beaglert
view 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 source
/* * Utilities.h * * Created on: Oct 27, 2014 * Author: parallels */ #ifndef UTILITIES_H_ #define UTILITIES_H_ extern int gNumAudioChannels; // How many audio channels are present extern int gNumMatrixChannels; // How many matrix channels are present // Macros for accessing the matrix values: usable _only_ within render() // Read an analog input from input pin p at frame f #define analogRead(p, f) (matrixIn[(f)*gNumMatrixChannels + (p)]) // 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); #endif /* UTILITIES_H_ */