andrewm@0: /* andrewm@0: * Utilities.h andrewm@0: * andrewm@0: * Created on: Oct 27, 2014 andrewm@0: * Author: parallels andrewm@0: */ andrewm@0: andrewm@0: #ifndef UTILITIES_H_ andrewm@0: #define UTILITIES_H_ andrewm@0: andrewm@45: #include "BeagleRT.h" andrewm@45: andrewm@45: #define setBit(word,bit) ((word) | (1 << (bit))) andrewm@45: #define clearBit(word,bit) ((word) &~ (1 << (bit))) andrewm@45: #define getBit(word,bit) (((word) >> (bit)) & 1) andrewm@45: #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value) << (bit))) andrewm@45: andrewm@45: #if 1 andrewm@45: // Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from initialise_render() andrewm@45: // Likewise, thread launch should be able to be called from initialise_render() andrewm@45: // Also, make volume change functions callable from render() thread -- as an aux task? andrewm@45: andrewm@45: float analogReadFrame(BeagleRTContext *context, int frame, int channel); andrewm@45: void analogWriteFrame(BeagleRTContext *context, int frame, int channel, float value); andrewm@45: void analogWriteFrameOnce(BeagleRTContext *context, int frame, int channel, float value); andrewm@45: andrewm@45: int digitalReadFrame(BeagleRTContext *context, int frame, int channel); andrewm@45: void digitalWriteFrame(BeagleRTContext *context, int frame, int channel, int value); andrewm@45: void digitalWriteFrameOnce(BeagleRTContext *context, int frame, int channel, int value); andrewm@45: andrewm@45: void pinModeFrame(BeagleRTContext *context, int frame, int channel, int mode); andrewm@45: void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode); andrewm@45: andrewm@45: #else andrewm@13: giuliomoro@19: // Macros for accessing the analog values: usable _only_ within render() andrewm@5: giuliomoro@19: // Read an Analog input from input pin p at frame f giuliomoro@23: #define analogRead(p, f) (analogIn[(f)*gNumAnalogChannels + (p)]) giuliomoro@19: // Write an Analog output frame at output pin p, frame f, to value v giuliomoro@23: #define analogWriteFrame(p, f, v) (analogOut[(f)*gNumAnalogChannels + (p)] = (v)) giuliomoro@23: #define analogWrite(pin, frame, value) \ giuliomoro@18: (({do {\ giuliomoro@19: for (int _privateI=(frame); _privateI