Statistics
| Branch: | Tag: | Revision:

amiro-lld / periphALtypes.h @ 7021191e

History | View | Annotate | Download (10.305 KB)

1 d6728c5b Thomas Schöpping
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3 f125ae07 Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 d6728c5b Thomas Schöpping

5
This program is free software: you can redistribute it and/or modify
6 f0ca400f Thomas Schöpping
it under the terms of the GNU Lesser General Public License as published by
7 d6728c5b Thomas Schöpping
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 f0ca400f Thomas Schöpping
GNU Lesser General Public License for more details.
14 d6728c5b Thomas Schöpping

15 f0ca400f Thomas Schöpping
You should have received a copy of the GNU Lesser General Public License
16 d6728c5b Thomas Schöpping
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19 8c47f14b Thomas Schöpping
#ifndef AMIROLLD_PERIPHALTYPES_H
20
#define AMIROLLD_PERIPHALTYPES_H
21 d6728c5b Thomas Schöpping
22
/*============================================================================*/
23
/* DEPENDENCIES                                                               */
24
/*============================================================================*/
25
26 a627f4dd Thomas Schöpping
#include <amiro-lld.h>
27 d6728c5b Thomas Schöpping
#include <stdint.h>
28
29
/*============================================================================*/
30
/* GENERAL                                                                    */
31
/*============================================================================*/
32
33
/**
34
 * @brief Time measurement type (in microseconds).
35
 */
36 cf1f756b Thomas Schöpping
#if !defined(AMIROLLD_CFG_TIME_SIZE)
37
  #error "AMIROLLD_CFG_TIME_SIZE not defined in alldconf.h"
38
#elif (AMIROLLD_CFG_TIME_SIZE == 8)
39
  typedef uint8_t     apalTime_t;
40
#elif (AMIROLLD_CFG_TIME_SIZE == 16)
41
  typedef uint16_t    apalTime_t;
42
#elif (AMIROLLD_CFG_TIME_SIZE == 32)
43
  typedef uint32_t    apalTime_t;
44
#elif (AMIROLLD_CFG_TIME_SIZE == 64)
45
  typedef uint64_t    apalTime_t;
46
#else
47
  #error "AMIROLLD_CFG_TIME_SIZE must be 8, 16, 32 or 64!"
48
#endif
49 d6728c5b Thomas Schöpping
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 7021191e Thomas Schöpping
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 d6728c5b Thomas Schöpping
88
/*============================================================================*/
89
/* GPIO                                                                       */
90
/*============================================================================*/
91
92
/**
93
 * @brief   Forward declaration.
94
 * @details Struct must be defined in 'periphAL.h'.
95
 */
96
typedef struct apalGpio_t apalGpio_t;
97
98
/**
99
 * @brief Status values to read/write a GPIO port.
100
 */
101 7021191e Thomas Schöpping
typedef uint8_t apalGpioState_t;
102
103
/**
104
 * @brief   GPIO physical low state.
105
 */
106
#define APAL_GPIO_LOW                           ((apalGpioState_t)0)
107 d6728c5b Thomas Schöpping
108
/**
109 7021191e Thomas Schöpping
 * @brief   GPIO physical high state.
110 d6728c5b Thomas Schöpping
 */
111 7021191e Thomas Schöpping
#define APAL_GPIO_HIGH                          ((apalGpioState_t)1)
112
113
/**
114
 * @brief   Invert a physical GPIO state.
115
 *
116
 * @param[in] state   GPIO state to invert.
117
 *
118
 * @return  Inverted physical GPIO state.
119
 */
120
#define APAL_GPIO_STATE_INVERT(state) (                                       \
121
  (apalGpioState_t)state ^ APAL_GPIO_HIGH                                     \
122
)
123
124
/**
125
 * @brief Logical status values to turn a control GPIO 'on' and 'off'.
126
 */
127
typedef uint8_t apalControlGpioState_t;
128
129
/**
130
 * @brief   GPIO logical off state.
131
 */
132
#define APAL_GPIO_OFF                           ((apalControlGpioState_t)0)
133
134
/**
135
 * @brief   GPIO logical on state.
136
 */
137
#define APAL_GPIO_ON                            ((apalControlGpioState_t)1)
138 d6728c5b Thomas Schöpping
139
/**
140
 * @brief   Polarity state of the control GPIO.
141
 */
142 7021191e Thomas Schöpping
typedef uint8_t apalGpioActive_t;
143
144
/**
145
 * @brief   The control GPIO is never defined to be 'on' (does not apply).
146
 */
147
#define APAL_GPIO_ACTIVE_NONE                   ((apalGpioActive_t)0)
148
149
/**
150
 * @brief   The control GPIO is defined to be 'on' when it is phsically low.
151
 */
152
#define APAL_GPIO_ACTIVE_LOW                    ((apalGpioActive_t)1)
153
154
/**
155
 * @brief   The control GPIO is defined to be 'on' when it is physically high.
156
 */
157
#define APAL_GPIO_ACTIVE_HIGH                   ((apalGpioActive_t)2)
158
159
/**
160
 * @brief   The control GPIO is defined to be always 'on'.
161
 */
162
#define APAL_GPIO_ACTIVE_ANY                    ((apalGpioActive_t)3)
163
164
/**
165
 * @brief   Invert a GPIO active state.
166
 * @details The active state is inverted only if it was either low or high.
167
 *          In case it was set to none or any, the value is not modified.
168
 *
169
 * @param[in] active  Active state to be inverted.
170
 *
171
 * @return  Inverted active state.
172
 */
173
#define APAL_GPIO_ACTIVE_INVERT(active) (                                     \
174
  (((apalGpioActive_t)active & APAL_GPIO_ACTIVE_LOW) ^                        \
175
   ((apalGpioActive_t)active & APAL_GPIO_ACTIVE_HIGH)) ?                      \
176
  ((apalGpioActive_t)active ^ APAL_GPIO_ACTIVE_ANY) :                         \
177
  ((apalGpioActive_t)active)                                                  \
178
)
179 d6728c5b Thomas Schöpping
180
/**
181 cf1f756b Thomas Schöpping
 * @brief   Signal direction for the control GPIO.
182
 */
183 7021191e Thomas Schöpping
typedef uint8_t apalGpioDirection_t;
184
185
/**
186
 * @brief   Signal direction for the control GPIO is undefined.
187
 */
188
#define APAL_GPIO_DIRECTION_UNDEFINED           ((apalGpioDirection_t)0)
189
190
/**
191
 * @brief   Signal direction for the control GPIO is input only.
192
 */
193
#define APAL_GPIO_DIRECTION_INPUT               ((apalGpioDirection_t)1)
194
195
/**
196
 * @brief   Signal direction for the control GPIO is output only.
197
 */
198
#define APAL_GPIO_DIRECTION_OUTPUT              ((apalGpioDirection_t)2)
199
200
/**
201
 * @brief   Signal direction for the control GPIO is didirectional.
202
 */
203
#define APAL_GPIO_DIRECTION_BIDIRECTIONAL       ((apalGpioDirection_t)3)
204
205
/**
206
 * @brief   Informative or effective signal edge for control GPIOs.
207
 */
208
typedef uint8_t apalGpioEdge_t;
209 cf1f756b Thomas Schöpping
210
/**
211 7021191e Thomas Schöpping
 * @brief   No edges indicate an interrupt or trigger an action.
212 d6728c5b Thomas Schöpping
 */
213 7021191e Thomas Schöpping
#define APAL_GPIO_EDGE_NONE                     ((apalGpioEdge_t)0)
214 d6728c5b Thomas Schöpping
215
/**
216 7021191e Thomas Schöpping
 * @brief   Rising edges indicate an interrupt or trigger an action.
217
 */
218
#define APAL_GPIO_EDGE_RISING                   ((apalGpioEdge_t)1)
219
220
/**
221
 * @brief   Falling edges indicate an interrupt or trigger an action.
222
 */
223
#define APAL_GPIO_EDGE_FALLING                  ((apalGpioEdge_t)2)
224
225
/**
226
 * @brief   Both rising and falling edges indicate an interrupt or trigger an action.
227
 */
228
#define APAL_GPIO_EDGE_BOTH                     ((apalGpioEdge_t)3)
229
230
/**
231
 * @brief   Inverts the value of the informative or effective signal edge for interrupts.
232 cf1f756b Thomas Schöpping
 * @details Rising edge is inverted to falling and vice versa.
233
 *          If none or both edges are enabled, the identical value is returned.
234 d6728c5b Thomas Schöpping
 */
235 7021191e Thomas Schöpping
#define APAL_GPIO_EDGE_INVERT(edge) (                                         \
236
  (((apalGpioEdge_t)edge & APAL_GPIO_EDGE_RISING) ^                           \
237
   ((apalGpioEdge_t)edge & APAL_GPIO_EDGE_FALLING)) ?                         \
238
  ((apalGpioEdge_t)edge ^ APAL_GPIO_EDGE_BOTH) :                              \
239
  ((apalGpioEdge_t)edge)                                                      \
240
)
241 d6728c5b Thomas Schöpping
242
/**
243
 * @brief Control GPIO meta information
244
 */
245
typedef struct {
246 cf1f756b Thomas Schöpping
  apalGpioDirection_t direction : 2;  /**< Direction configuration for according signals */
247 7021191e Thomas Schöpping
  apalGpioActive_t active       : 2;  /**< Active state of the GPIO */
248 d6728c5b Thomas Schöpping
  apalGpioEdge_t edge           : 2;  /**< Edge configuration for according signals */
249
} apalGpioMeta_t;
250
251
/**
252
 * @brief Control GPIO type.
253
 */
254
typedef struct {
255
  apalGpio_t* gpio;     /**< The GPIO to use.                 */
256
  apalGpioMeta_t meta;  /**< Meta information about the GPIO. */
257
} apalControlGpio_t;
258
259
/*============================================================================*/
260
/* PWM                                                                        */
261
/*============================================================================*/
262
263
/**
264
 * @brief PWM channel type.
265
 */
266
typedef uint8_t   apalPWMchannel_t;
267
268
/**
269
 * @brief PWM width type.
270
 */
271
typedef uint16_t  apalPWMwidth_t;
272
273
/**
274
 * @brief PWM frequency type.
275
 */
276
typedef uint32_t  apalPWMfrequency_t;
277
278
/**
279
 * @brief PWM period time.
280
 */
281
typedef uint32_t  apalPWMperiod_t;
282
283
/**
284 7021191e Thomas Schöpping
 * @brief   PWM width to turn off the PWM.
285 d6728c5b Thomas Schöpping
 */
286 7021191e Thomas Schöpping
#define APAL_PWM_WIDTH_OFF                      ((apalPWMwidth_t)0x0000u)
287
288
/**
289
 * @brief   Minimum allowed PWM width.
290
 */
291
#define APAL_PWM_WIDTH_MIN                      ((apalPWMwidth_t)0x0000u)
292
293
/**
294
 * @brief   Maximum allowed PWM width.
295
 */
296
#define APAL_PWM_WIDTH_MAX                      ((apalPWMwidth_t)0xFFFFu)
297 d6728c5b Thomas Schöpping
298
/*============================================================================*/
299
/* QEI                                                                        */
300
/*============================================================================*/
301
302
/**
303
 * @brief QEI counter type.
304
 */
305
typedef uint32_t  apalQEICount_t;
306
307
/**
308
 * @brief Direction of the QEI.
309
 */
310 7021191e Thomas Schöpping
typedef uint8_t apalQEIDirection_t;
311
312
/*
313
 * @brief   QEI counts upwards.
314
 */
315
#define APAL_QEI_DIRECTION_UP                   ((apalQEIDirection_t)0)
316
317
/*
318
 * @brief   QEI counts downwards.
319
 */
320
#define APAL_QEI_DIRECTION_DOWN                 ((apalQEIDirection_t)1)
321 d6728c5b Thomas Schöpping
322
/*============================================================================*/
323
/* I2C                                                                        */
324
/*============================================================================*/
325
326
/**
327
 * @brief I2C address type.
328
 */
329
typedef uint16_t apalI2Caddr_t;
330
331
/*============================================================================*/
332
/* SPI                                                                        */
333
/*============================================================================*/
334
335 7021191e Thomas Schöpping
/* nothing defined for SPI */
336 d6728c5b Thomas Schöpping
337 8c47f14b Thomas Schöpping
#endif /* AMIROLLD_PERIPHALTYPES_H */