Mercurial > hg > beaglert
comparison 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 |
comparison
equal
deleted
inserted
replaced
15:901d205d1a3c | 16:670be80463a3 |
---|---|
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) (matrixIn[(f)*gNumMatrixChannels + (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 analogWrite(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (uint16_t)(v)) | 19 #define analogWrite(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (uint16_t)(v)) |
20 | 20 |
21 #define setBit(word,bit) ((word)|(1<<(bit))) | |
22 #define clearBit(word,bit) ((word)&~(1<<(bit))) | |
23 #define getBit(word,bit) (((word)>>(bit))&1) | |
24 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) | |
25 //matrixGpio API: | |
26 #define setDigitalDirection(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction)) | |
27 #define digitalWriteAll(frame,value) matrixGpio[(frame)]=0xffff0000*(!(!value)); | |
28 //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set) | |
29 #define digitalWrite(pin, frame, value) matrixGpio[(frame)]=( changeBit(matrixGpio[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments | |
30 #define digitalRead(pin, frame) ( getBit(matrixGpio[(frame)], pin+16) ) | |
31 | |
21 float map(float x, float in_min, float in_max, float out_min, float out_max); | 32 float map(float x, float in_min, float in_max, float out_min, float out_max); |
22 float constrain(float x, float min_val, float max_val); | 33 float constrain(float x, float min_val, float max_val); |
23 | 34 |
24 #endif /* UTILITIES_H_ */ | 35 #endif /* UTILITIES_H_ */ |