Mercurial > hg > beaglert
comparison include/Utilities.h @ 18:31503d9de101 matrix_gpio
- digitalWrite and analogWrite macros are now persistent: they write a value on the given channel from the current frame to the end of the buffer. When
this is not needed you can use digitalWriteFrame and analogWriteFrame instead.
- included the matrix_gpio_demo code
- the Eclipe project is somehow broken
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 30 Apr 2015 16:02:47 +0100 |
parents | 670be80463a3 |
children | c98863e63174 |
comparison
equal
deleted
inserted
replaced
17:85e8b08a7471 | 18:31503d9de101 |
---|---|
14 // Macros for accessing the matrix values: usable _only_ within render() | 14 // Macros for accessing the matrix 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) (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 analogWriteFrame(p, f, v) (matrixOut[(f)*gNumMatrixChannels + (p)] = (v)) |
20 #define analogWrite(pin, frame, value) \ | |
21 (({do {\ | |
22 for (int _privateI=(frame); _privateI<numMatrixFrames; _privateI++){ \ | |
23 analogWriteFrame(pin,_privateI,value); \ | |
24 }\ | |
25 } while (0);}),(void)0)\ | |
20 | 26 |
21 #define setBit(word,bit) ((word)|(1<<(bit))) | 27 #define setBit(word,bit) ((word)|(1<<(bit))) |
22 #define clearBit(word,bit) ((word)&~(1<<(bit))) | 28 #define clearBit(word,bit) ((word)&~(1<<(bit))) |
23 #define getBit(word,bit) (((word)>>(bit))&1) | 29 #define getBit(word,bit) (((word)>>(bit))&1) |
24 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) | 30 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) |
25 //matrixGpio API: | 31 //matrixGpio API: |
26 #define setDigitalDirection(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(frame)],(pin),(direction)) | 32 #define setDigitalDirectionFrame(pin,frame,direction) matrixGpio[(frame)]=changeBit(matrixGpio[(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) | |
27 #define digitalWriteAll(frame,value) matrixGpio[(frame)]=0xffff0000*(!(!value)); | 34 #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) | 35 //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 | 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 |
30 #define digitalRead(pin, frame) ( getBit(matrixGpio[(frame)], pin+16) ) | 37 #define digitalWrite(pin, frame, value) \ |
38 (({do {\ | |
39 for (int _privateI=(frame); _privateI<gNumMatrixGpioFrames; _privateI++) \ | |
40 digitalWriteFrame(pin,_privateI,value); \ | |
41 } while (0);}),(void)0)\ | |
42 | |
43 #define digitalRead(pin, frame) ( getBit(matrixGpio[(frame)], pin+16) ) | |
31 | 44 |
32 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); |
33 float constrain(float x, float min_val, float max_val); | 46 float constrain(float x, float min_val, float max_val); |
34 | 47 |
35 #endif /* UTILITIES_H_ */ | 48 #endif /* UTILITIES_H_ */ |