Mercurial > hg > beaglert
comparison include/PRU.h @ 307:ff5f346a293e prerelease
Changed BelaContext fields to be const where appropriate; there's now an InternalBelaContext used for setting the values within the core code. These need to stay aligned.
author | andrewm |
---|---|
date | Fri, 27 May 2016 18:12:15 +0100 |
parents | 421a69d42943 |
children | 493a07f6ec09 |
comparison
equal
deleted
inserted
replaced
306:132fc61893af | 307:ff5f346a293e |
---|---|
10 | 10 |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 #include <native/intr.h> | 12 #include <native/intr.h> |
13 #include "../include/Bela.h" | 13 #include "../include/Bela.h" |
14 | 14 |
15 /** | |
16 * Internal version of the BelaContext struct which does not have const | |
17 * elements, so it can be modified by the code. When it's passed to the user | |
18 * code, it is typecast to the standard BelaContext. | |
19 * | |
20 * Important: make sure this retains the same structure as BelaContext! | |
21 */ | |
22 typedef struct { | |
23 /// \brief Buffer holding audio input samples | |
24 /// | |
25 /// This buffer may be in either interleaved or non-interleaved format, | |
26 /// depending on the contents of the BelaInitSettings structure. | |
27 /// \b Note: this element is available in render() only. | |
28 float *audioIn; | |
29 | |
30 /// \brief Buffer holding audio output samples | |
31 /// | |
32 /// This buffer may be in either interleaved or non-interleaved format, | |
33 /// depending on the contents of the BelaInitSettings structure. | |
34 /// \b Note: this element is available in render() only. | |
35 float *audioOut; | |
36 | |
37 /// \brief Buffer holding analog input samples | |
38 /// | |
39 /// This buffer may be in either interleaved or non-interleaved format, | |
40 /// depending on the contents of the BelaInitSettings structure. | |
41 /// \b Note: this element is available in render() only. | |
42 float *analogIn; | |
43 | |
44 /// \brief Buffer holding analog output samples | |
45 /// | |
46 /// This buffer may be in either interleaved or non-interleaved format, | |
47 /// depending on the contents of the BelaInitSettings structure. | |
48 /// \b Note: this element is available in render() only. | |
49 float *analogOut; | |
50 | |
51 /// \brief Buffer holding digital input/output samples | |
52 /// | |
53 /// \b Note: this element is available in render() only. | |
54 uint32_t *digital; | |
55 | |
56 /// Number of audio frames per period | |
57 uint32_t audioFrames; | |
58 /// Number of audio channels (currently always 2) | |
59 uint32_t audioChannels; | |
60 /// Audio sample rate in Hz (currently always 44100.0) | |
61 float audioSampleRate; | |
62 | |
63 /// \brief Number of analog frames per period | |
64 /// | |
65 /// This will be 0 if analog I/O is disabled. | |
66 uint32_t analogFrames; | |
67 | |
68 /// \brief Number of analog channels | |
69 /// | |
70 /// This could take a value of 8, 4 or 2. This will be 0 if analog I/O is disabled. | |
71 uint32_t analogChannels; | |
72 | |
73 /// \brief Analog sample rate in Hz | |
74 /// | |
75 /// The analog sample rate depends on the number of analog channels used. If | |
76 /// 8 channels are used, the sample rate is 22050. If 4 channels are used, the sample | |
77 /// rate is 44100. If 2 channels are used, the sample rate is 88200. If analog I/O | |
78 /// is disabled, the sample rate is 0. | |
79 float analogSampleRate; | |
80 | |
81 /// Number of digital frames per period | |
82 uint32_t digitalFrames; | |
83 /// \brief Number of digital channels | |
84 /// | |
85 /// Currently this will always be 16, unless digital I/O is disabled, in which case it will be 0. | |
86 uint32_t digitalChannels; | |
87 /// Digital sample rate in Hz (currently always 44100.0) | |
88 float digitalSampleRate; | |
89 | |
90 /// \brief Number of elapsed audio samples since the start of rendering. | |
91 /// | |
92 /// This holds the total number of audio samples as of the beginning of the current period. To | |
93 /// find the current number of analog or digital samples elapsed, multiply by the ratio of the | |
94 /// sample rates (e.g. half the number of analog samples will have elapsed if the analog sample | |
95 /// rate is 22050). | |
96 uint64_t audioSampleCount; | |
97 | |
98 /// \brief Other audio/sensor settings | |
99 /// | |
100 /// Binary combination of flags including: | |
101 /// | |
102 /// BELA_FLAG_INTERLEAVED: indicates the audio and analog buffers are interleaved | |
103 /// | |
104 /// BELA_FLAG_ANALOG_OUTPUTS_PERSIST: indicates that writes to the analog outputs will | |
105 /// persist for future frames. If not set, writes affect one frame only. | |
106 uint32_t flags; | |
107 } InternalBelaContext; | |
108 | |
109 | |
15 class PRU | 110 class PRU |
16 { | 111 { |
17 private: | 112 private: |
18 static const unsigned int kPruGPIODACSyncPin; | 113 static const unsigned int kPruGPIODACSyncPin; |
19 static const unsigned int kPruGPIOADCSyncPin; | 114 static const unsigned int kPruGPIOADCSyncPin; |
21 static const unsigned int kPruGPIOTestPin2; | 116 static const unsigned int kPruGPIOTestPin2; |
22 static const unsigned int kPruGPIOTestPin3; | 117 static const unsigned int kPruGPIOTestPin3; |
23 | 118 |
24 public: | 119 public: |
25 // Constructor | 120 // Constructor |
26 PRU(BelaContext *input_context); | 121 PRU(InternalBelaContext *input_context); |
27 | 122 |
28 // Destructor | 123 // Destructor |
29 ~PRU(); | 124 ~PRU(); |
30 | 125 |
31 // Prepare the GPIO pins needed for the PRU | 126 // Prepare the GPIO pins needed for the PRU |
54 // For debugging: | 149 // For debugging: |
55 void setGPIOTestPin(); | 150 void setGPIOTestPin(); |
56 void clearGPIOTestPin(); | 151 void clearGPIOTestPin(); |
57 | 152 |
58 private: | 153 private: |
59 BelaContext *context; // Overall settings | 154 InternalBelaContext *context; // Overall settings |
60 | 155 |
61 int pru_number; // Which PRU we use | 156 int pru_number; // Which PRU we use |
62 bool running; // Whether the PRU is running | 157 bool running; // Whether the PRU is running |
63 bool analog_enabled; // Whether SPI ADC and DAC are used | 158 bool analog_enabled; // Whether SPI ADC and DAC are used |
64 bool digital_enabled; // Whether digital is used | 159 bool digital_enabled; // Whether digital is used |