comparison include/Utilities.h @ 33:83baffda5786 matrix_gpio

Fixed bug in Digital macros and in example project
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 11 May 2015 18:58:47 +0100
parents 182ae9367104
children 579c86316008
comparison
equal deleted inserted replaced
31:06fd2ffee605 33:83baffda5786
27 #define setBit(word,bit) ((word)|(1<<(bit))) 27 #define setBit(word,bit) ((word)|(1<<(bit)))
28 #define clearBit(word,bit) ((word)&~(1<<(bit))) 28 #define clearBit(word,bit) ((word)&~(1<<(bit)))
29 #define getBit(word,bit) (((word)>>(bit))&1) 29 #define getBit(word,bit) (((word)>>(bit))&1)
30 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) 30 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit)))
31 //digital API: 31 //digital API:
32 #define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)) 32 #define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)),void(0)
33 #define setDigitalDirection(pin,frame,direction) (for(int _privateI=(frame);_privateI<gNumGpioFrames;_privateI++) digital[_privateI]=changeBit(digital[(_privateI)],(pin),(direction))),void(0) 33 #define setDigitalDirection(pin,frame,direction)\
34 (({do {\
35 for(int _privateI=(frame); _privateI<numDigitalFrames; _privateI++)\
36 setDigitalDirectionFrame(pin,_privateI,direction);\
37 } while (0);}), (void)0)
34 #define digitalWriteAll(frame,value) digital[(frame)]=0xffff0000*(!(!value)); 38 #define digitalWriteAll(frame,value) digital[(frame)]=0xffff0000*(!(!value));
35 //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set) 39 //sets the bit in the high word, clears the bit in the low word (just in case the direction was not previously set)
36 #define digitalWriteFrame(pin, frame, value) digital[(frame)]=( changeBit(digital[(frame)], (pin+16), (value)) & (0xffffffff-(1<<(pin))) ) //could have been done with two subsequent assignments 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
37 #define digitalWrite(pin, frame, value) \ 41 #define digitalWrite(pin, frame, value) \
38 (({do {\ 42 (({do {\
39 for (int _privateI=(frame); _privateI<gNumDigitalFrames; _privateI++) \ 43 for (int _privateI=(frame); _privateI<numDigitalFrames; _privateI++) \
40 digitalWriteFrame(pin,_privateI,value); \ 44 digitalWriteFrame(pin,_privateI,value); \
41 } while (0);}),(void)0)\ 45 } while (0);}),(void)0)\
42 46
43 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) ) 47 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) )
44 48