Mercurial > hg > beaglert
comparison include/Utilities.h @ 45:579c86316008 newapi
Major API overhaul. Moved to a single data structure for handling render functions. Functionally, generally similar except for scheduling within PRU loop function, which now uses interrupts from the PRU rather than polling. This requires an updated kernel.
author | andrewm |
---|---|
date | Thu, 28 May 2015 14:35:55 -0400 |
parents | 83baffda5786 |
children | 3c3a1357657d |
comparison
equal
deleted
inserted
replaced
40:419ce4ebfc4c | 45:579c86316008 |
---|---|
6 */ | 6 */ |
7 | 7 |
8 #ifndef UTILITIES_H_ | 8 #ifndef UTILITIES_H_ |
9 #define UTILITIES_H_ | 9 #define UTILITIES_H_ |
10 | 10 |
11 extern int gNumAudioChannels; // How many audio channels are present | 11 #include "BeagleRT.h" |
12 extern int gNumAnalogChannels; // How many analog channels are present | 12 |
13 #define setBit(word,bit) ((word) | (1 << (bit))) | |
14 #define clearBit(word,bit) ((word) &~ (1 << (bit))) | |
15 #define getBit(word,bit) (((word) >> (bit)) & 1) | |
16 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value) << (bit))) | |
17 | |
18 #if 1 | |
19 // Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from initialise_render() | |
20 // Likewise, thread launch should be able to be called from initialise_render() | |
21 // Also, make volume change functions callable from render() thread -- as an aux task? | |
22 | |
23 float analogReadFrame(BeagleRTContext *context, int frame, int channel); | |
24 void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value); | |
25 void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value); | |
26 | |
27 int digitalReadFrame(BeagleRTContext *context, int frame, int channel); | |
28 void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value); | |
29 void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value); | |
30 | |
31 void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode); | |
32 void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode); | |
33 | |
34 #else | |
13 | 35 |
14 // Macros for accessing the analog values: usable _only_ within render() | 36 // Macros for accessing the analog values: usable _only_ within render() |
15 | 37 |
16 // Read an Analog input from input pin p at frame f | 38 // Read an Analog input from input pin p at frame f |
17 #define analogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)]) | 39 #define analogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)]) |
22 for (int _privateI=(frame); _privateI<numAnalogFrames; _privateI++){ \ | 44 for (int _privateI=(frame); _privateI<numAnalogFrames; _privateI++){ \ |
23 analogWriteFrame(pin,_privateI,value); \ | 45 analogWriteFrame(pin,_privateI,value); \ |
24 }\ | 46 }\ |
25 } while (0);}),(void)0)\ | 47 } while (0);}),(void)0)\ |
26 | 48 |
27 #define setBit(word,bit) ((word)|(1<<(bit))) | 49 |
28 #define clearBit(word,bit) ((word)&~(1<<(bit))) | |
29 #define getBit(word,bit) (((word)>>(bit))&1) | |
30 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value)<<(bit))) | |
31 //digital API: | 50 //digital API: |
32 #define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)),void(0) | 51 #define setDigitalDirectionFrame(pin,frame,direction) digital[(frame)]=changeBit(digital[(frame)],(pin),(direction)),void(0) |
33 #define setDigitalDirection(pin,frame,direction)\ | 52 #define setDigitalDirection(pin,frame,direction)\ |
34 (({do {\ | 53 (({do {\ |
35 for(int _privateI=(frame); _privateI<numDigitalFrames; _privateI++)\ | 54 for(int _privateI=(frame); _privateI<numDigitalFrames; _privateI++)\ |
44 digitalWriteFrame(pin,_privateI,value); \ | 63 digitalWriteFrame(pin,_privateI,value); \ |
45 } while (0);}),(void)0)\ | 64 } while (0);}),(void)0)\ |
46 | 65 |
47 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) ) | 66 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) ) |
48 | 67 |
68 #endif | |
69 | |
49 float map(float x, float in_min, float in_max, float out_min, float out_max); | 70 float map(float x, float in_min, float in_max, float out_min, float out_max); |
50 float constrain(float x, float min_val, float max_val); | 71 float constrain(float x, float min_val, float max_val); |
51 | 72 |
52 #endif /* UTILITIES_H_ */ | 73 #endif /* UTILITIES_H_ */ |