amiro-lld / periphAL.h @ master
History | View | Annotate | Download (23.6 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2020 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
#ifndef AMIROLLD_PERIPHAL_H
|
20 |
#define AMIROLLD_PERIPHAL_H
|
21 |
|
22 |
#include <amiro-lld.h> |
23 |
|
24 |
/*============================================================================*/
|
25 |
/* VERSION */
|
26 |
/*============================================================================*/
|
27 |
|
28 |
/**
|
29 |
* @brief The periphery abstraction layer interface major version.
|
30 |
* @note Changes of the major version imply incompatibilities.
|
31 |
*/
|
32 |
#define PERIPHAL_VERSION_MAJOR 1 |
33 |
|
34 |
/**
|
35 |
* @brief The periphery abstraction layer interface minor version.
|
36 |
* @note A higher minor version implies new functionalty, but all old interfaces are still available.
|
37 |
*/
|
38 |
#define PERIPHAL_VERSION_MINOR 2 |
39 |
|
40 |
/*============================================================================*/
|
41 |
/* DEPENDENCIES */
|
42 |
/*============================================================================*/
|
43 |
|
44 |
#include <stdint.h> |
45 |
|
46 |
/*============================================================================*/
|
47 |
/* GENERAL */
|
48 |
/*============================================================================*/
|
49 |
|
50 |
/**
|
51 |
* @brief Status values used as return value for all (or most) function calls.
|
52 |
* @note The status can be used as mask of flags.
|
53 |
*/
|
54 |
typedef int8_t apalExitStatus_t;
|
55 |
|
56 |
/**
|
57 |
* @brief Status value for success (no error or warning occurred).
|
58 |
*/
|
59 |
#define APAL_STATUS_OK ((apalExitStatus_t)0) |
60 |
#define APAL_STATUS_SUCCESS ((apalExitStatus_t)0) |
61 |
|
62 |
/**
|
63 |
* @brief Status value for unspecified failure.
|
64 |
*/
|
65 |
#define APAL_STATUS_ERROR ((apalExitStatus_t)-1) |
66 |
#define APAL_STATUS_FAILURE ((apalExitStatus_t)-1) |
67 |
|
68 |
/**
|
69 |
* @brief Status value for timeout failure.
|
70 |
*/
|
71 |
#define APAL_STATUS_TIMEOUT ((apalExitStatus_t)-2) |
72 |
|
73 |
/**
|
74 |
* @brief Status value for failure because of invalid arguments.
|
75 |
*/
|
76 |
#define APAL_STATUS_INVALIDARGUMENTS ((apalExitStatus_t)-4) |
77 |
|
78 |
/**
|
79 |
* @brief Status value for failure because the function is not available/implemented.
|
80 |
*/
|
81 |
#define APAL_STATUS_UNAVAILABLE ((apalExitStatus_t)-8) |
82 |
|
83 |
/**
|
84 |
* @brief Status value for unspecified warning.
|
85 |
*/
|
86 |
#define APAL_STATUS_WARNING ((apalExitStatus_t)1) |
87 |
|
88 |
/*============================================================================*/
|
89 |
/* DEBUG */
|
90 |
/*============================================================================*/
|
91 |
|
92 |
#if (AMIROLLD_CFG_DBG == true) || defined(__DOXYGEN__) |
93 |
|
94 |
#if defined(__cplusplus)
|
95 |
extern "C" { |
96 |
#endif /* defined(__cplusplus) */ |
97 |
|
98 |
#if !defined(apalDbgAssertMsg) || defined(__DOXYGEN__)
|
99 |
/**
|
100 |
* @brief Assert function to check a given condition and print a message string.
|
101 |
*
|
102 |
* @param[in] c The condition to check.
|
103 |
* @param[in] fmt Formatted message string to print.
|
104 |
*/
|
105 |
void apalDbgAssertMsg(const bool c, const char* fmt, ...); |
106 |
#endif
|
107 |
|
108 |
#if !defined(apalDbgPrintf) || defined(__DOXYGEN__)
|
109 |
/**
|
110 |
* @brief Printf function for messages printed only in debug builds.
|
111 |
*
|
112 |
* @param[in] fmt Formatted string to print.
|
113 |
*
|
114 |
* return Number of printed characters.
|
115 |
*/
|
116 |
int apalDbgPrintf(const char* fmt, ...); |
117 |
#endif
|
118 |
|
119 |
#if defined(__cplusplus)
|
120 |
} |
121 |
#endif /* defined(__cplusplus) */ |
122 |
|
123 |
/**
|
124 |
* @brief Assert function to check a given condition.
|
125 |
*
|
126 |
* @param[in] c The condition to check.
|
127 |
*/
|
128 |
#define apalDbgAssert(c) apalDbgAssertMsg(c, "%s(%u): apalDbgAssert failed", __FILE__, __LINE__) |
129 |
|
130 |
#endif /* (AMIROLLD_CFG_DBG == true) */ |
131 |
|
132 |
/*============================================================================*/
|
133 |
/* TIMING */
|
134 |
/*============================================================================*/
|
135 |
|
136 |
/**
|
137 |
* @brief Time measurement type (in microseconds).
|
138 |
*/
|
139 |
#if (AMIROLLD_CFG_TIME_SIZE == 8) |
140 |
typedef uint8_t apalTime_t;
|
141 |
#elif (AMIROLLD_CFG_TIME_SIZE == 16) |
142 |
typedef uint16_t apalTime_t;
|
143 |
#elif (AMIROLLD_CFG_TIME_SIZE == 32) |
144 |
typedef uint32_t apalTime_t;
|
145 |
#elif (AMIROLLD_CFG_TIME_SIZE == 64) |
146 |
typedef uint64_t apalTime_t;
|
147 |
#else
|
148 |
#error "AMIROLLD_CFG_TIME_SIZE must be 8, 16, 32 or 64" |
149 |
#endif
|
150 |
|
151 |
#ifdef __cplusplus
|
152 |
extern "C" { |
153 |
#endif
|
154 |
|
155 |
#if !defined(apalSleep) || defined(__DOXYGEN__)
|
156 |
/**
|
157 |
* @brief Delay execution by a specific number of microseconds.
|
158 |
*
|
159 |
* @param[in] us Time to sleep until execution continues in microseconds.
|
160 |
*/
|
161 |
void apalSleep(apalTime_t us);
|
162 |
#endif
|
163 |
|
164 |
#ifdef __cplusplus
|
165 |
} |
166 |
#endif
|
167 |
|
168 |
/*============================================================================*/
|
169 |
/* GPIO */
|
170 |
/*============================================================================*/
|
171 |
|
172 |
#if (AMIROLLD_CFG_GPIO == true) || defined(__DOXYGEN__) |
173 |
|
174 |
/*
|
175 |
* The following type must be defined by the implementation:
|
176 |
*
|
177 |
* apalGpio_t
|
178 |
* Type to represent a GPIO object.
|
179 |
* Is only used via pointer by the API.
|
180 |
*/
|
181 |
|
182 |
/**
|
183 |
* @brief Status values to read/write a GPIO port.
|
184 |
*/
|
185 |
typedef uint8_t apalGpioState_t;
|
186 |
|
187 |
/**
|
188 |
* @brief GPIO physical low state.
|
189 |
*/
|
190 |
#define APAL_GPIO_LOW ((apalGpioState_t)0) |
191 |
|
192 |
/**
|
193 |
* @brief GPIO physical high state.
|
194 |
*/
|
195 |
#define APAL_GPIO_HIGH ((apalGpioState_t)1) |
196 |
|
197 |
/**
|
198 |
* @brief Invert a physical GPIO state.
|
199 |
*
|
200 |
* @param[in] state GPIO state to invert.
|
201 |
*
|
202 |
* @return Inverted physical GPIO state.
|
203 |
*/
|
204 |
#define APAL_GPIO_STATE_INVERT(state) ( \
|
205 |
(apalGpioState_t)state ^ APAL_GPIO_HIGH \ |
206 |
) |
207 |
|
208 |
/**
|
209 |
* @brief Logical status values to turn a control GPIO 'on' and 'off'.
|
210 |
*/
|
211 |
typedef uint8_t apalControlGpioState_t;
|
212 |
|
213 |
/**
|
214 |
* @brief GPIO logical off state.
|
215 |
*/
|
216 |
#define APAL_GPIO_OFF ((apalControlGpioState_t)0) |
217 |
|
218 |
/**
|
219 |
* @brief GPIO logical on state.
|
220 |
*/
|
221 |
#define APAL_GPIO_ON ((apalControlGpioState_t)1) |
222 |
|
223 |
/**
|
224 |
* @brief Polarity state of the control GPIO.
|
225 |
*/
|
226 |
typedef uint8_t apalGpioActive_t;
|
227 |
|
228 |
/**
|
229 |
* @brief The control GPIO is never defined to be 'on' (does not apply).
|
230 |
*/
|
231 |
#define APAL_GPIO_ACTIVE_NONE ((apalGpioActive_t)0) |
232 |
|
233 |
/**
|
234 |
* @brief The control GPIO is defined to be 'on' when it is phsically low.
|
235 |
*/
|
236 |
#define APAL_GPIO_ACTIVE_LOW ((apalGpioActive_t)1) |
237 |
|
238 |
/**
|
239 |
* @brief The control GPIO is defined to be 'on' when it is physically high.
|
240 |
*/
|
241 |
#define APAL_GPIO_ACTIVE_HIGH ((apalGpioActive_t)2) |
242 |
|
243 |
/**
|
244 |
* @brief The control GPIO is defined to be always 'on'.
|
245 |
*/
|
246 |
#define APAL_GPIO_ACTIVE_ANY ((apalGpioActive_t)3) |
247 |
|
248 |
/**
|
249 |
* @brief Invert a GPIO active state.
|
250 |
* @details The active state is inverted only if it was either low or high.
|
251 |
* In case it was set to none or any, the value is not modified.
|
252 |
*
|
253 |
* @param[in] active Active state to be inverted.
|
254 |
*
|
255 |
* @return Inverted active state.
|
256 |
*/
|
257 |
#define APAL_GPIO_ACTIVE_INVERT(active) ( \
|
258 |
(((apalGpioActive_t)active & APAL_GPIO_ACTIVE_LOW) ^ \ |
259 |
((apalGpioActive_t)active & APAL_GPIO_ACTIVE_HIGH)) ? \ |
260 |
((apalGpioActive_t)active ^ APAL_GPIO_ACTIVE_ANY) : \ |
261 |
((apalGpioActive_t)active) \ |
262 |
) |
263 |
|
264 |
/**
|
265 |
* @brief Signal direction for the control GPIO.
|
266 |
*/
|
267 |
typedef uint8_t apalGpioDirection_t;
|
268 |
|
269 |
/**
|
270 |
* @brief Signal direction for the control GPIO is undefined.
|
271 |
*/
|
272 |
#define APAL_GPIO_DIRECTION_UNDEFINED ((apalGpioDirection_t)0) |
273 |
|
274 |
/**
|
275 |
* @brief Signal direction for the control GPIO is input only.
|
276 |
*/
|
277 |
#define APAL_GPIO_DIRECTION_INPUT ((apalGpioDirection_t)1) |
278 |
|
279 |
/**
|
280 |
* @brief Signal direction for the control GPIO is output only.
|
281 |
*/
|
282 |
#define APAL_GPIO_DIRECTION_OUTPUT ((apalGpioDirection_t)2) |
283 |
|
284 |
/**
|
285 |
* @brief Signal direction for the control GPIO is didirectional.
|
286 |
*/
|
287 |
#define APAL_GPIO_DIRECTION_BIDIRECTIONAL ((apalGpioDirection_t)3) |
288 |
|
289 |
/**
|
290 |
* @brief Informative or effective signal edge for control GPIOs.
|
291 |
*/
|
292 |
typedef uint8_t apalGpioEdge_t;
|
293 |
|
294 |
/**
|
295 |
* @brief No edges indicate an interrupt or trigger an action.
|
296 |
*/
|
297 |
#define APAL_GPIO_EDGE_NONE ((apalGpioEdge_t)0) |
298 |
|
299 |
/**
|
300 |
* @brief Rising edges indicate an interrupt or trigger an action.
|
301 |
*/
|
302 |
#define APAL_GPIO_EDGE_RISING ((apalGpioEdge_t)1) |
303 |
|
304 |
/**
|
305 |
* @brief Falling edges indicate an interrupt or trigger an action.
|
306 |
*/
|
307 |
#define APAL_GPIO_EDGE_FALLING ((apalGpioEdge_t)2) |
308 |
|
309 |
/**
|
310 |
* @brief Both rising and falling edges indicate an interrupt or trigger an action.
|
311 |
*/
|
312 |
#define APAL_GPIO_EDGE_BOTH ((apalGpioEdge_t)3) |
313 |
|
314 |
/**
|
315 |
* @brief Inverts the value of the informative or effective signal edge for interrupts.
|
316 |
* @details Rising edge is inverted to falling and vice versa.
|
317 |
* If none or both edges are enabled, the identical value is returned.
|
318 |
*/
|
319 |
#define APAL_GPIO_EDGE_INVERT(edge) ( \
|
320 |
(((apalGpioEdge_t)edge & APAL_GPIO_EDGE_RISING) ^ \ |
321 |
((apalGpioEdge_t)edge & APAL_GPIO_EDGE_FALLING)) ? \ |
322 |
((apalGpioEdge_t)edge ^ APAL_GPIO_EDGE_BOTH) : \ |
323 |
((apalGpioEdge_t)edge) \ |
324 |
) |
325 |
|
326 |
/**
|
327 |
* @brief Control GPIO meta information
|
328 |
*/
|
329 |
typedef struct { |
330 |
apalGpioDirection_t direction : 2; /**< Direction configuration for according signals */ |
331 |
apalGpioActive_t active : 2; /**< Active state of the GPIO */ |
332 |
apalGpioEdge_t edge : 2; /**< Edge configuration for according signals */ |
333 |
} apalGpioMeta_t; |
334 |
|
335 |
/**
|
336 |
* @brief Control GPIO type.
|
337 |
*/
|
338 |
typedef struct { |
339 |
apalGpio_t* gpio; /**< The GPIO to use. */
|
340 |
apalGpioMeta_t meta; /**< Meta information about the GPIO. */
|
341 |
} apalControlGpio_t; |
342 |
|
343 |
#ifdef __cplusplus
|
344 |
extern "C" { |
345 |
#endif
|
346 |
|
347 |
#if !defined(apalGpioRead) || defined(__DOXYGEN__)
|
348 |
/**
|
349 |
* @brief Read the current value of a GPIO pin.
|
350 |
*
|
351 |
* @param[in] gpio GPIO to read.
|
352 |
* @param[out] val Current value of the GPIO.
|
353 |
*
|
354 |
* @return The status indicates whether the function call was successful.
|
355 |
*/
|
356 |
apalExitStatus_t apalGpioRead(apalGpio_t* gpio, apalGpioState_t* const val);
|
357 |
#endif
|
358 |
|
359 |
#if !defined(apalGpioWrite) || defined(__DOXYGEN__)
|
360 |
/**
|
361 |
* @brief Set the value of a GPIO pin.
|
362 |
*
|
363 |
* @param[in] gpio GPIO to write.
|
364 |
* @param[in] val Value to set for the GPIO.
|
365 |
*
|
366 |
* @return The status indicates whether the function call was successful.
|
367 |
*/
|
368 |
apalExitStatus_t apalGpioWrite(apalGpio_t* gpio, const apalGpioState_t val);
|
369 |
#endif
|
370 |
|
371 |
#if !defined(apalGpioToggle) || defined(__DOXYGEN__)
|
372 |
/**
|
373 |
* @brief Toggle the output of a GPIO.
|
374 |
*
|
375 |
* @param[in] gpio GPIO to toggle.
|
376 |
*
|
377 |
* @return The status indicates whether the function call was successful.
|
378 |
*/
|
379 |
apalExitStatus_t apalGpioToggle(apalGpio_t* gpio); |
380 |
#endif
|
381 |
|
382 |
#if !defined(apalGpioIsInterruptEnabled) || defined(__DOXYGEN__)
|
383 |
/**
|
384 |
* @brief Return the interrupt enable status of the GPIO.
|
385 |
*
|
386 |
* @param[in] gpio GPIO to check.
|
387 |
* @param[out] enabled Flag, indicating whether interrupt is enabled for the GPIO.
|
388 |
*
|
389 |
* @return The status indicates whether the function call was successful.
|
390 |
*/
|
391 |
apalExitStatus_t apalGpioIsInterruptEnabled(apalGpio_t* gpio, bool* const enabled); |
392 |
#endif
|
393 |
|
394 |
#if !defined(apalControlGpioGet) || defined(__DOXYGEN__)
|
395 |
/**
|
396 |
* @brief Get the current on/off state of a control GPIO.
|
397 |
*
|
398 |
* @param[in] gpio Control GPIO to read.
|
399 |
* @param[out] val Current activation status of the control GPIO.
|
400 |
*
|
401 |
* @return The status indicates whether the function call was successful.
|
402 |
*/
|
403 |
apalExitStatus_t apalControlGpioGet(const apalControlGpio_t* const cgpio, apalControlGpioState_t* const val); |
404 |
#endif
|
405 |
|
406 |
#if !defined(apalControlGpioSet) || defined(__DOXYGEN__)
|
407 |
/**
|
408 |
* @brief Turn a control GPIO 'on' or 'off' respectively.
|
409 |
*
|
410 |
* @param[in] gpio Control GPIO to set.
|
411 |
* @param[in] val Activation value to set for the control GPIO.
|
412 |
*
|
413 |
* @return The status indicates whether the function call was successful.
|
414 |
*/
|
415 |
apalExitStatus_t apalControlGpioSet(const apalControlGpio_t* const cgpio, const apalControlGpioState_t val); |
416 |
#endif
|
417 |
|
418 |
#if !defined(apalControlGpioSetInterrupt) || defined(__DOXYGEN__)
|
419 |
/**
|
420 |
* @brief Enable or disable the interrupt event functionality.
|
421 |
*
|
422 |
* @param[in] cgpio Control GPIO to set.
|
423 |
* @param[in] enable Flag, indicating whether the interrupt shall be activated (true) or deactivated (false).
|
424 |
*
|
425 |
* @return The status indicates whether the function call was successful.
|
426 |
*/
|
427 |
apalExitStatus_t apalControlGpioSetInterrupt(const apalControlGpio_t* const cgpio, const bool enable); |
428 |
#endif
|
429 |
|
430 |
#ifdef __cplusplus
|
431 |
} |
432 |
#endif
|
433 |
|
434 |
#endif /* (AMIROLLD_CFG_GPIO == true) */ |
435 |
|
436 |
/*============================================================================*/
|
437 |
/* PWM */
|
438 |
/*============================================================================*/
|
439 |
|
440 |
#if (AMIROLLD_CFG_PWM == true) || defined(__DOXYGEN__) |
441 |
|
442 |
/*
|
443 |
* The following type must be defined by the implementation:
|
444 |
*
|
445 |
* apalPWMDriver_t
|
446 |
* Type to represent a PWM driver object.
|
447 |
* Is only used via pointer by the API.
|
448 |
*/
|
449 |
|
450 |
/**
|
451 |
* @brief PWM channel type.
|
452 |
*/
|
453 |
typedef uint8_t apalPWMchannel_t;
|
454 |
|
455 |
/**
|
456 |
* @brief PWM width type.
|
457 |
*/
|
458 |
typedef uint16_t apalPWMwidth_t;
|
459 |
|
460 |
/**
|
461 |
* @brief PWM frequency type.
|
462 |
*/
|
463 |
typedef uint32_t apalPWMfrequency_t;
|
464 |
|
465 |
/**
|
466 |
* @brief PWM period time.
|
467 |
*/
|
468 |
typedef uint32_t apalPWMperiod_t;
|
469 |
|
470 |
/**
|
471 |
* @brief PWM width to turn off the PWM.
|
472 |
*/
|
473 |
#define APAL_PWM_WIDTH_OFF ((apalPWMwidth_t)0x0000u) |
474 |
|
475 |
/**
|
476 |
* @brief Minimum allowed PWM width.
|
477 |
*/
|
478 |
#define APAL_PWM_WIDTH_MIN ((apalPWMwidth_t)0x0000u) |
479 |
|
480 |
/**
|
481 |
* @brief Maximum allowed PWM width.
|
482 |
*/
|
483 |
#define APAL_PWM_WIDTH_MAX ((apalPWMwidth_t)0xFFFFu) |
484 |
|
485 |
#ifdef __cplusplus
|
486 |
extern "C" { |
487 |
#endif
|
488 |
|
489 |
#if !defined(apalPWMSet) || defined(__DOXYGEN__)
|
490 |
/**
|
491 |
* @brief Set the PWM with given parameters.
|
492 |
*
|
493 |
* @param[in] pwm PWM driver to set.
|
494 |
* @param[in] channel Channel of the PWM driver to set.
|
495 |
* @param[in] width Width to set the channel to.
|
496 |
*
|
497 |
* @return The status indicates whether the function call was successful.
|
498 |
*/
|
499 |
apalExitStatus_t apalPWMSet(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const apalPWMwidth_t width); |
500 |
#endif
|
501 |
|
502 |
#if !defined(apalPWMGetFrequency) || defined(__DOXYGEN__)
|
503 |
/**
|
504 |
* @brief Retrieve the current frequency of the PWM.
|
505 |
*
|
506 |
* @param[in] pwm PWM driver to read.
|
507 |
* @param[out] frequency The currently set frequency.
|
508 |
*
|
509 |
* @return The status indicates whether the function call was successful.
|
510 |
*/
|
511 |
apalExitStatus_t apalPWMGetFrequency(apalPWMDriver_t* pwm, apalPWMfrequency_t* const frequency);
|
512 |
#endif
|
513 |
|
514 |
#if !defined(apalPWMGetPeriod) || defined(__DOXYGEN__)
|
515 |
/**
|
516 |
* @brief Retrieve the current period of the PWM.
|
517 |
*
|
518 |
* @param[in] pwm PWM driver to read.
|
519 |
* @param[out] period The currently set period.
|
520 |
*
|
521 |
* @return The status indicates whether the function call was successful.
|
522 |
*/
|
523 |
apalExitStatus_t apalPWMGetPeriod(apalPWMDriver_t* pwm, apalPWMperiod_t* const period);
|
524 |
#endif
|
525 |
|
526 |
#ifdef __cplusplus
|
527 |
} |
528 |
#endif
|
529 |
|
530 |
#endif /* (AMIROLLD_CFG_PWM == true) */ |
531 |
|
532 |
/*============================================================================*/
|
533 |
/* QEI */
|
534 |
/*============================================================================*/
|
535 |
|
536 |
#if (AMIROLLD_CFG_QEI == true) || defined(__DOXYGEN__) |
537 |
|
538 |
/*
|
539 |
* The following type must be defined by the implementation:
|
540 |
*
|
541 |
* apalQEIDriver_t
|
542 |
* Type to represent a QEI driver object.
|
543 |
* Is only used via pointer by the API.
|
544 |
*/
|
545 |
|
546 |
/**
|
547 |
* @brief QEI counter type.
|
548 |
*/
|
549 |
typedef uint32_t apalQEICount_t;
|
550 |
|
551 |
/**
|
552 |
* @brief Direction of the QEI.
|
553 |
*/
|
554 |
typedef uint8_t apalQEIDirection_t;
|
555 |
|
556 |
/*
|
557 |
* @brief QEI counts upwards.
|
558 |
*/
|
559 |
#define APAL_QEI_DIRECTION_UP ((apalQEIDirection_t)0) |
560 |
|
561 |
/*
|
562 |
* @brief QEI counts downwards.
|
563 |
*/
|
564 |
#define APAL_QEI_DIRECTION_DOWN ((apalQEIDirection_t)1) |
565 |
|
566 |
#ifdef __cplusplus
|
567 |
extern "C" { |
568 |
#endif
|
569 |
|
570 |
#if !defined(apalQEIGetDirection) || defined(__DOXYGEN__)
|
571 |
/**
|
572 |
* @brief Gets the direction of the last transition.
|
573 |
*
|
574 |
* @param[in] qei The QEI driver to use.
|
575 |
* @param[out] direction The direction of the last transition.
|
576 |
*
|
577 |
* @return The status indicates whether the function call was successful.
|
578 |
*/
|
579 |
apalExitStatus_t apalQEIGetDirection(apalQEIDriver_t* qei, apalQEIDirection_t* const direction);
|
580 |
#endif
|
581 |
|
582 |
#if !defined(apalQEIGetPosition) || defined(__DOXYGEN__)
|
583 |
/**
|
584 |
* @brief Gets the current position of the ecnoder.
|
585 |
*
|
586 |
* @param[in] qei The QEI driver to use.
|
587 |
* @param[out] position The current position of the encoder.
|
588 |
*
|
589 |
* @return The status indicates whether the function call was successful.
|
590 |
*/
|
591 |
apalExitStatus_t apalQEIGetPosition(apalQEIDriver_t* qei, apalQEICount_t* const position);
|
592 |
#endif
|
593 |
|
594 |
#if !defined(apalQEIGetRange) || defined(__DOXYGEN__)
|
595 |
/**
|
596 |
* @brief Gets the value range of the encoder.
|
597 |
*
|
598 |
* @param[in] qei The QEI driver to use.
|
599 |
* @param[out] range The value range of the encoder.
|
600 |
*
|
601 |
* @return The status indicates whether the function call was successful.
|
602 |
*/
|
603 |
apalExitStatus_t apalQEIGetRange(apalQEIDriver_t* qei, apalQEICount_t* const range);
|
604 |
#endif
|
605 |
|
606 |
#ifdef __cplusplus
|
607 |
} |
608 |
#endif
|
609 |
|
610 |
#endif /* (AMIROLLD_CFG_QEI == true) */ |
611 |
|
612 |
/*============================================================================*/
|
613 |
/* I2C */
|
614 |
/*============================================================================*/
|
615 |
|
616 |
#if (AMIROLLD_CFG_I2C == true) || defined(__DOXYGEN__) |
617 |
|
618 |
/*
|
619 |
* The following type must be defined by the implementation:
|
620 |
*
|
621 |
* apalI2CDriver_t
|
622 |
* Type to represent a I2C driver object.
|
623 |
* Is only used via pointer by the API.
|
624 |
*/
|
625 |
|
626 |
/**
|
627 |
* @brief I2C address type.
|
628 |
*/
|
629 |
typedef uint16_t apalI2Caddr_t;
|
630 |
|
631 |
#ifdef __cplusplus
|
632 |
extern "C" { |
633 |
#endif
|
634 |
|
635 |
#if !defined(apalI2CMasterTransmit) || defined(__DOXYGEN__)
|
636 |
/**
|
637 |
* @brief Transmit data and receive a response.
|
638 |
*
|
639 |
* @param[in] i2cd The I2C driver to use.
|
640 |
* @param[in] addr Address to write to.
|
641 |
* @param[in] txbuf Buffer containing data to send.
|
642 |
* @param[in] txbytes Number of bytes to send.
|
643 |
* @param[out] rxbuf Buffer to store a response to.
|
644 |
* @param[in] rxbytes Number of bytes to receive.
|
645 |
* @param[in] timeout Timeout for the function to return (in microseconds).
|
646 |
*
|
647 |
* @return The status indicates whether the function call was succesful or a timeout occurred.
|
648 |
*/
|
649 |
apalExitStatus_t apalI2CMasterTransmit(apalI2CDriver_t* i2cd, const apalI2Caddr_t addr, const uint8_t* const txbuf, const size_t txbytes, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout); |
650 |
#endif
|
651 |
|
652 |
#if !defined(apalI2CMasterReceive) || defined(__DOXYGEN__)
|
653 |
/**
|
654 |
* @brief Read data from a specific address.
|
655 |
*
|
656 |
* @param[in] i2cd The I2C driver to use.
|
657 |
* @param[in] addr Address to read.
|
658 |
* @param[out] rxbuf Buffer to store the response to.
|
659 |
* @param[in] rxbytes Number of bytes to receive.
|
660 |
* @param[in] timeout Timeout for the function to return (in microseconds).
|
661 |
*
|
662 |
* @return The status indicates whether the function call was succesful or a timeout occurred.
|
663 |
*/
|
664 |
apalExitStatus_t apalI2CMasterReceive(apalI2CDriver_t* i2cd, const apalI2Caddr_t addr, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout); |
665 |
#endif
|
666 |
|
667 |
#ifdef __cplusplus
|
668 |
} |
669 |
#endif
|
670 |
|
671 |
#endif /* (AMIROLLD_CFG_I2C == true) */ |
672 |
|
673 |
/*============================================================================*/
|
674 |
/* SPI */
|
675 |
/*============================================================================*/
|
676 |
|
677 |
#if (AMIROLLD_CFG_SPI == true) || defined(__DOXYGEN__) |
678 |
|
679 |
/*
|
680 |
* The following types must be defined by the implementation:
|
681 |
*
|
682 |
* apalSPIDriver_t
|
683 |
* Type to represent a SPI driver object.
|
684 |
* Is only used via pointer by the API.
|
685 |
*
|
686 |
* apalSPIConfig_t
|
687 |
* Type to represent SPI a configuration object.
|
688 |
* Is only used via pointer by the API.
|
689 |
*/
|
690 |
|
691 |
#ifdef __cplusplus
|
692 |
extern "C" { |
693 |
#endif
|
694 |
|
695 |
#if !defined(apalSPITransmit) || defined(__DOXYGEN__)
|
696 |
/**
|
697 |
* @brief Transmit data to SPI.
|
698 |
*
|
699 |
* @param[in] spid The SPI driver to use.
|
700 |
* @param[in] data Buffer containing data to send.
|
701 |
* @param[in] length Number of bytes to send.
|
702 |
*
|
703 |
* @return The status indicates whether the function call was succesful.
|
704 |
*/
|
705 |
apalExitStatus_t apalSPITransmit(apalSPIDriver_t* spid, const uint8_t* const data, const size_t length); |
706 |
#endif
|
707 |
|
708 |
#if !defined(apalSPIReceive) || defined(__DOXYGEN__)
|
709 |
/**
|
710 |
* @brief Receive data from SPI.
|
711 |
*
|
712 |
* @param[in] spid The SPI driver to use.
|
713 |
* @param[out] data Buffer to store receied data.
|
714 |
* @param[in] length Number of bytes to receive.
|
715 |
*
|
716 |
* @return The status indicates whether the function call was succesful.
|
717 |
*/
|
718 |
apalExitStatus_t apalSPIReceive(apalSPIDriver_t* spid, uint8_t* const data, const size_t length); |
719 |
#endif
|
720 |
|
721 |
#if !defined(apalSPITransmitAndReceive) || defined(__DOXYGEN__)
|
722 |
/**
|
723 |
* @brief Transmit data to SPI and receive data afterwards without releasing the bus in between.
|
724 |
*
|
725 |
* @param[in] spid The SPI driver to use.
|
726 |
* @param[in] txData Transmit data buffer.
|
727 |
* @param[in] rxData Receive data buffer.
|
728 |
* @param[in] txLength Number of bytes to send.
|
729 |
* @param[in] rxLength Number of bytes to receive.
|
730 |
*
|
731 |
* @return The status indicates whether the function call was succesful.
|
732 |
*/
|
733 |
apalExitStatus_t apalSPITransmitAndReceive(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t txLength, const size_t rxLength); |
734 |
#endif
|
735 |
|
736 |
#if !defined(apalSPIExchange) || defined(__DOXYGEN__)
|
737 |
/**
|
738 |
* @brief Transmit and receive data from SPI simultaneously.
|
739 |
*
|
740 |
* @param[in] spid The SPI driver to use.
|
741 |
* @param[in] txData Buffer containing data to send.
|
742 |
* @param[out] rxData Buffer to store received data.
|
743 |
* @param[in] length Number of bytes to send and receive.
|
744 |
*
|
745 |
* @return The status indicates whether the function call was succesful.
|
746 |
*/
|
747 |
apalExitStatus_t apalSPIExchange(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t length); |
748 |
#endif
|
749 |
|
750 |
#if !defined(apalSPIReconfigure) || defined(__DOXYGEN__)
|
751 |
/**
|
752 |
* @brief Reconfigure an SPI driver.
|
753 |
*
|
754 |
* @param[in] spid The SPI driver to be reconfigured.
|
755 |
* @param[in] config Configuration to apply.
|
756 |
*
|
757 |
* @return The status indicates whether the function call was succesful.
|
758 |
*/
|
759 |
apalExitStatus_t apalSPIReconfigure(apalSPIDriver_t* spid, const apalSPIConfig_t* config);
|
760 |
#endif
|
761 |
|
762 |
#ifdef __cplusplus
|
763 |
} |
764 |
#endif
|
765 |
|
766 |
#endif /* (AMIROLLD_CFG_SPI == true) */ |
767 |
|
768 |
#endif /* AMIROOS_PERIPHAL_H */ |