Mercurial > hg > beaglert
comparison include/Utilities.h @ 95:c529505203ee
Updated doxygen for Utilities.h
author | andrewm |
---|---|
date | Thu, 23 Jul 2015 23:32:47 +0100 |
parents | d837fb676977 |
children | f1012082f142 |
comparison
equal
deleted
inserted
replaced
94:2fe6690fcab7 | 95:c529505203ee |
---|---|
13 #ifndef UTILITIES_H_ | 13 #ifndef UTILITIES_H_ |
14 #define UTILITIES_H_ | 14 #define UTILITIES_H_ |
15 | 15 |
16 #include "BeagleRT.h" | 16 #include "BeagleRT.h" |
17 | 17 |
18 /** | |
19 * \defgroup iofunctions I/O functions and constants | |
20 * | |
21 * These functions and macros are used for audio, analog and digital I/O. All the | |
22 * I/O functions require the BeagleRTContext data structure from render() to be passed | |
23 * in. This means that these functions are, by design, \b only usable from within | |
24 * the rendering thread. | |
25 * | |
26 * The naming conventions are loosely derived from the Arduino environment, and the | |
27 * syntax is similar. Unlike Arduino, the I/O functions require the frame number at which | |
28 * the read or write should take place, since all I/O happens synchronously with the | |
29 * audio clock. | |
30 * | |
31 * @{ | |
32 */ | |
33 | |
18 #define HIGH 0x1 | 34 #define HIGH 0x1 |
19 #define LOW 0x0 | 35 #define LOW 0x0 |
20 | 36 |
21 #define INPUT 0x0 | 37 #define INPUT 0x0 |
22 #define OUTPUT 0x1 | 38 #define OUTPUT 0x1 |
23 | 39 |
40 /** @} */ | |
41 | |
42 /** | |
43 * \ingroup wiring | |
44 * | |
45 * @{ | |
46 */ | |
47 | |
24 /// Set the given bit in \c word to 1. | 48 /// Set the given bit in \c word to 1. |
25 #define setBit(word,bit) ((word) | (1 << (bit))) | 49 #define setBit(word,bit) ((word) | (1 << (bit))) |
26 | 50 |
27 /// Clear the given bit in \c word to 0. | 51 /// Clear the given bit in \c word to 0. |
28 #define clearBit(word,bit) ((word) &~ (1 << (bit))) | 52 #define clearBit(word,bit) ((word) &~ (1 << (bit))) |
30 /// Check if the given bit in \c word is 1 (returns nonzero) or 0 (returns zero). | 54 /// Check if the given bit in \c word is 1 (returns nonzero) or 0 (returns zero). |
31 #define getBit(word,bit) (((word) >> (bit)) & 1) | 55 #define getBit(word,bit) (((word) >> (bit)) & 1) |
32 | 56 |
33 /// Set/clear the given bit in \c word to \c value. | 57 /// Set/clear the given bit in \c word to \c value. |
34 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value) << (bit))) | 58 #define changeBit(word,bit,value) ((clearBit((word),(bit))) | ((value) << (bit))) |
59 | |
60 /** @} */ | |
61 | |
62 /** | |
63 * \ingroup iofunctions | |
64 * | |
65 * @{ | |
66 */ | |
35 | 67 |
36 #if 1 | 68 #if 1 |
37 // Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from setup() | 69 // Note: pinMode(), analogWrite() and digitalWrite() should be able to be called from setup() |
38 // Likewise, thread launch should be able to be called from setup() | 70 // Likewise, thread launch should be able to be called from setup() |
39 // Also, make volume change functions callable from render() thread -- as an aux task? | 71 // Also, make volume change functions callable from render() thread -- as an aux task? |
179 * BeagleBone Black are available. See the constants P8_xx and P9_xx defined in | 211 * BeagleBone Black are available. See the constants P8_xx and P9_xx defined in |
180 * digital_gpio_mapping.h. | 212 * digital_gpio_mapping.h. |
181 * \param value Direction of the pin (\c INPUT or \c OUTPUT). | 213 * \param value Direction of the pin (\c INPUT or \c OUTPUT). |
182 */ | 214 */ |
183 void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode); | 215 void pinModeFrameOnce(BeagleRTContext *context, int frame, int channel, int mode); |
216 | |
217 /** @} */ | |
184 | 218 |
185 #else | 219 #else |
186 | 220 |
187 // Macros for accessing the analog values: usable _only_ within render() | 221 // Macros for accessing the analog values: usable _only_ within render() |
188 | 222 |
217 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) ) | 251 #define digitalRead(pin, frame) ( getBit(digital[(frame)], pin+16) ) |
218 | 252 |
219 #endif | 253 #endif |
220 | 254 |
221 /** | 255 /** |
256 * \defgroup wiring Wiring language support | |
257 * | |
258 * These are functions found in the Wiring (Arduino) language which are not directly | |
259 * related to I/O but are provided as a convenience. | |
260 * | |
261 * @{ | |
262 */ | |
263 | |
264 /** | |
222 * \brief Linearly rescale a number from one range of values to another. | 265 * \brief Linearly rescale a number from one range of values to another. |
223 * | 266 * |
224 * This function linearly scales values of \c x such that the range in_min to | 267 * This function linearly scales values of \c x such that the range in_min to |
225 * in_max at the input corresponds to the range out_min to out_max | 268 * in_max at the input corresponds to the range out_min to out_max |
226 * at the output. Values outside this range are extrapolated. | 269 * at the output. Values outside this range are extrapolated. |
254 * \param max_val Maximum possible value. | 297 * \param max_val Maximum possible value. |
255 * \return Constrained value. | 298 * \return Constrained value. |
256 */ | 299 */ |
257 float constrain(float x, float min_val, float max_val); | 300 float constrain(float x, float min_val, float max_val); |
258 | 301 |
302 /** @} */ | |
303 | |
259 #endif /* UTILITIES_H_ */ | 304 #endif /* UTILITIES_H_ */ |