Revision 891
Moved comments to headers. That was painful.
analog.h | ||
---|---|---|
45 | 45 |
#include <inttypes.h> |
46 | 46 |
|
47 | 47 |
/** |
48 |
* @addtogroup analog |
|
48 |
* @defgroup analog Analog |
|
49 |
* Functions for manipulation the ADC on the dragonfly board. |
|
50 |
* All definitions may be found in analog.h. |
|
51 |
* |
|
49 | 52 |
* @{ |
50 | 53 |
**/ |
51 | 54 |
|
... | ... | |
94 | 97 |
#define ADC_START 1 |
95 | 98 |
#define ADC_STOP 0 |
96 | 99 |
|
97 |
#define ADMUX_OPT 0x60 |
|
100 |
/** |
|
101 |
* @brief Initialize analog ports. Will start running a loop |
|
102 |
* if start_conversion is ADC_START. |
|
103 |
* |
|
104 |
* Initializes the ADC. |
|
105 |
* Call analog_init before reading from the analog ports. |
|
106 |
* |
|
107 |
* @see analog8, analog10, analog_get8, analog_get10 |
|
108 |
**/ |
|
109 |
void analog_init(int start_conversion); |
|
98 | 110 |
|
99 |
/** @brief Struct to hold the value of a particular analog port **/ |
|
100 |
typedef struct { |
|
101 |
uint8_t adc8; |
|
102 |
uint16_t adc10; |
|
103 |
} adc_t; |
|
111 |
/** |
|
112 |
* @brief starts the analog loop. Doesn't do anything if the loop is already running. |
|
113 |
* |
|
114 |
* Starts the analog update loop. Will continue to run |
|
115 |
* until analog_stop_loop is called. |
|
116 |
* |
|
117 |
* @see analog_stop_loop |
|
118 |
**/ |
|
119 |
void analog_start_loop(void); |
|
104 | 120 |
|
121 |
/** |
|
122 |
* @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. |
|
123 |
* |
|
124 |
* Stops the analog update loop. If there is a current |
|
125 |
* read, it will finish up and be stored before the loop |
|
126 |
* is interrupted. No further updates will be made until |
|
127 |
* the loop is started again. |
|
128 |
* |
|
129 |
* @see analog_start_loop |
|
130 |
**/ |
|
131 |
void analog_stop_loop(void); |
|
105 | 132 |
|
106 |
/** @brief Initialize analog ports. Will start running a loop |
|
107 |
if start_conversion is ADC_START.**/ |
|
108 |
void analog_init(int start_conversion); |
|
109 |
/** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/ |
|
110 |
void analog_start_loop(void); |
|
111 |
/** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/ |
|
112 |
void analog_stop_loop(void); |
|
113 |
/** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8. **/ |
|
133 |
/** |
|
134 |
* @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8. |
|
135 |
* |
|
136 |
* Returns the 8-bit analog conversion of which from |
|
137 |
* the lookup table. If the requested port is the BOM_PORT |
|
138 |
* you will get an automatic 0 since the BOM_PORT is not |
|
139 |
* read in the loop and not stored. If you need that port |
|
140 |
* you should use the functions in bom.c. There is an analog_get8 |
|
141 |
* function which for instant lookups but should be avoided unless |
|
142 |
* you know what you're doing. |
|
143 |
* |
|
144 |
* @param which the port that you want to read |
|
145 |
* |
|
146 |
* @bug may cause a seg fault if which is a larger value |
|
147 |
* than exists in an_val table. Not sure if we should fix |
|
148 |
* this or not since it would add overhead. |
|
149 |
* |
|
150 |
* @return 8-bit analog value for the which port requested |
|
151 |
* |
|
152 |
* @see analog10, analog_get8, analog_get10 |
|
153 |
**/ |
|
114 | 154 |
unsigned int analog8(int which); |
115 |
/** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10. **/ |
|
155 |
|
|
156 |
/** |
|
157 |
* @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10. |
|
158 |
* |
|
159 |
* Returns the 10-bit analog conversion of which from |
|
160 |
* the lookup table. If the requested port is the BOM_PORT |
|
161 |
* you will get an automatic 0 since the BOM_PORT is not |
|
162 |
* read in the loop and not stored. If you need that port |
|
163 |
* you should use the functions in bom.c. There is an analog_get10 |
|
164 |
* function which for instant lookups but should be avoided unless |
|
165 |
* you know what you are doing. |
|
166 |
* |
|
167 |
* @param which the port that you want to read |
|
168 |
* |
|
169 |
* @bug may cause a seg fault if which is a larger value |
|
170 |
* than exists in an_val table. Not sure if we should fix |
|
171 |
* this or not since it would add overhead. |
|
172 |
* |
|
173 |
* @return 10-bit analog value for the which port requested |
|
174 |
* |
|
175 |
* @see analog8, analog_get8, analog_get10 |
|
176 |
**/ |
|
116 | 177 |
unsigned int analog10(int which); |
117 |
/** @brief Read the position of the wheel. **/ |
|
178 |
|
|
179 |
/** |
|
180 |
* @brief Read the position of the wheel. |
|
181 |
* |
|
182 |
* Returns the current position of the wheel, as an integer |
|
183 |
* in the range 0 - 255. |
|
184 |
* analog_init must be called before using this function. |
|
185 |
* |
|
186 |
* @return the orientation of the wheel, as an integer in |
|
187 |
* the range 0 - 255. |
|
188 |
* |
|
189 |
* @see analog_init |
|
190 |
**/ |
|
118 | 191 |
int wheel(void); |
119 |
/** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/ |
|
192 |
|
|
193 |
/** |
|
194 |
* @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. |
|
195 |
* |
|
196 |
* Reads an 8-bit number from an analog port. |
|
197 |
* analog_init must be called before using this function. |
|
198 |
* The analog loop must also be stopped before using this |
|
199 |
* function or you will mess up the lookup table. You |
|
200 |
* must also reenabled the loop when you are done unless |
|
201 |
* you are doing more instant reads. See analog_stop_loop |
|
202 |
* and analog_start_loop for more information about the loop. |
|
203 |
* |
|
204 |
* @param which the analog port to read from. One of |
|
205 |
* the constants AN0 - AN7. |
|
206 |
* |
|
207 |
* @return the 8-bit input to the specified port |
|
208 |
* |
|
209 |
* @see analog_init, analog_get10, analog8, analog_stop_loop, |
|
210 |
* analog_start_loop |
|
211 |
**/ |
|
120 | 212 |
unsigned int analog_get8(int which); |
121 |
/** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/ |
|
213 |
|
|
214 |
/** |
|
215 |
* @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. |
|
216 |
* |
|
217 |
* Reads an 10-bit number from an analog port. |
|
218 |
* analog_init must be called before using this function. |
|
219 |
* The analog loop must also be stopped before using this |
|
220 |
* function or you will mess up the lookup table. You |
|
221 |
* must also reenabled the loop when you are done unless |
|
222 |
* you are doing more instant reads. See analog_stop_loop |
|
223 |
* and analog_start_loop for more information about the loop. |
|
224 |
* |
|
225 |
* |
|
226 |
* @param which the analog port to read from. Typically |
|
227 |
* a constant, one of AN0 - AN7. |
|
228 |
* |
|
229 |
* @return the 10-bit number input to the specified port |
|
230 |
* |
|
231 |
* @see analog_init, analog_get8, analog10, analog_stop_loop, |
|
232 |
* analog_start_loop |
|
233 |
**/ |
|
122 | 234 |
unsigned int analog_get10(int which); |
123 | 235 |
|
124 |
|
|
125 | 236 |
/**@}**/ //end group |
126 | 237 |
|
127 | 238 |
#endif |
Also available in: Unified diff