Revision 1304b12b

View differences:

README.txt
93 93
The files are structured as follows:
94 94
./
95 95
│ The project root directory contains this file, a license.html file as well as
96
│ a Makefile that allows to easily integrate the project. Furthermore, two
96
│ a makefile that allows to easily integrate the project. Furthermore, two
97 97
│ interface headers are provided: amiro-lld.h and periphALtypes.h. These are
98 98
│ entry points for any utilizing superproject, so it is not required (and not
99 99
│ recommended) to include each driver individually.
100 100
101
├── include/
101
├── docs/
102
│     UML graphs (using PlantUML; see plantuml.com for further information)
103
│     visualize the structure of the AMiRo-LLD project. Doxygen related files
104
│     can be used to gererate a documentation of the whole project (wip).
105
106
├── drivers/
102 107
│     For each supported hardware device, there is exactly one directory in this
103 108
│     folder. Further subfolders may contain various versions of a driver (e.g.
104 109
│     'v1/', 'v2/', etc.). By convention the root directory of a driver is named
......
107 112
│     <product_name> is a placeholder for the exact name of the according
108 113
│     hardware, or the product familiy, if the driver is compatible with all
109 114
│     parts.
110
│     The root header consequently follows the naming scheme
111
│     "alld_<product_name>.h"
112
│     and header files within the version folders shall be named like
113
│     "alld<product_name>_<driver_version>.h"
114
115
├── source/
116
│     Any source files are placed in this directory. Naming conventions for
117
│     folders and files are the same as described before for the include
118
│     directory, as is the file structure. There is a dedicated folder for each
119
│     device and further subfolders for multiple driver versions. Source files
120
│     should only be put in these version folders.
115
│     Each driver must provide a makefile script, which adds the required
116
│     include folders to the AMIROLLD_INC variable and all C source files to the
117
│     AMIROLLD_CSRC variable.
121 118
122 119
└── templates/
123
      AMiRo-LLD requires an implementation of the defined interface and an
124
      configuration header to be accessible in the include paths at compile
125
      time. Template files for both can be found in this folder. It is
126
      recommended to place according implementations of these templated not in
127
      the AMiRo-LLD project, but the superproject which includes AMiRo-LLD.
120
      AMiRo-LLD expects a configuration header "alldconf.h" to be found in the
121
      include paths. An according template for such file can be found here.
122
      There is no template for an implementation of periphAL, though. The
123
      provided interface header in the root directory (periphAL.h) should give
124
      you all required information for such an implementation anyway.
128 125

  
129 126

  
130 127

  
......
137 134
descriptions of the guides provide additional information about the underlying
138 135
concepts and mechanisms, a short summary is provided at the end of each chapter.
139 136

  
137

  
140 138
3.1  Adding a Device
141 139
--------------------
142 140

  
143 141
When adding new device to the project, the very first step is to create the
144
according folders in the include/ and source/ directories. For this guide, we
145
will add the fictional DEVICE1234. For this example the folders to be created
146
are "include/DEVICE1234/" and "source/DEVICE1234/".
147

  
148
The first file should be the root header: "include/DEVICE1234/alld_DEVICE1234.h"
149
Have a look at existing drivers and use one of those as template. This header
150
should introduce a new configuration to be set in the alldconf.h file and check
151
it using the preprocessor. Eventually, another header is included, pointing to
152
the selected driver version/implementation.
153

  
154
Such implementations are to be put in further subfolders, e.g.
155
"include/DEVICE1234/v1/" and "source/DEVICE1234/v1/". The header and C-source
156
files in those folders do not follow a strict scheme, although there are some
157
conventions to consider (i.e. naming conventions, cf. chapter 2).
142
according folder in the drivers/ directory. For this guide, we will add the
143
fictional DEVICE1234. For this example the folders to be created are
144
"drivers/DEVICE1234/" and "drivers/DEVICE1234/v1/". In case there already exists
145
a driver implementation for this device, but you want to implement another
146
version from scratch (not just an update), the version subfolder must be named
147
accordingly (e.g. "drivers/DEVICE1234/v42/").
148

  
149
Most drivers will consist of exactly three files:
150
 - alld_DEVICE1234.mk
151
 - alld_DEVICE1234.h
152
 - alld_DEVICE1234.c
153
However, some drivers may feature multiple .h and/or .c files or even come with
154
additional subfolders. In any case, all those required folders, including the
155
driver root folder (i.e. "drivers/DEVICE1234/v1/"), as well as all C source
156
files must be added to the according makefile variables AMIROLLD_INC and
157
AMIROLLD_CSRC by the makefile script.
158
It is highly recommended that files in the driver root directory (i.e.
159
"drivers/DEVICE1234/v1/") use the prefix "alld_" in their names. This not only
160
helps to achieve an easy to understand file structure, but also prevents
161
compilation issues due to naming conflicts of header files.
158 162

  
159 163
Summing up, you have to
160
1) create device folders.
161
2) add a root header.
162
3) add further subfolders and implement the driver there.
164
1) create device and version folders.
165
2) add a makefile script.
166
3) add header- and source files as well as subfulders, implementing the diver
163 167

  
164 168

  
165 169
3.2  Implementing a Driver
166 170
--------------------------
167 171

  
168
Implementation of a new driver usually is very straight-forward. You most
172
Implementation of a new driver usually is very straightforward. You most
169 173
probably have a comprehensive datasheet of the device, or the manufacturer even
170 174
provides a reference driver implementation.
171 175

  
172 176
For the former case, you should first write a comprehensive header, containing
173 177
all information like constants, register maps, etc. and according abstract
174 178
access functions (e.g. for reading and writing registers, and convenient access
175
to common functionalities). Only the you implement those functions, using
176
periphAL to interface any hardware interfaces (e.g. I2C, SPI, etc.).
179
to common functionalities). Only then you implement those functions, using
180
periphAL to interface any hardware interfaces (e.g. I2C, SPI, etc.) in a
181
separate C source file, or 'inline' in the header file itself.
177 182

  
178 183
For the latter case, the reference implementation will specify some interface
179 184
functions to interact with the hardware (e.g. I2C, SPI etc.). Even though all
180 185
functionality should be covered by the reference driver, you still need to
181
implement those interface functions.
186
implement those interface functions and map them to periphAL.
182 187

  
183 188
Since AMiRo-LLD does not rely on specific hardware or operating system, the only
184 189
valid way to interact with both is through periphAL. Under no circumstances you
185 190
must use any function of your operating system and directly or indirectly access
186 191
the hardware of your platform. For your driver, there is no knowledge about the
187 192
world beyond periphAL! If periphAL does not provide the function you need, you
188
can do the following: 1) Think again if you really need that funcionality or
189
whether it can be replicated by existing functions. 2) File a feature request
190
to extend periphAL. 3) Write a custom patch that modifies periphAL to meet your
191
requirements.
193
can do one of the following:
194
1) Think again if you really need that funcionality or whether it can be
195
   replicated by the existing API.
196
2) File a feature request to extend periphAL.
197
3) Write a custom patch that modifies periphAL to meet your requirements.
192 198

  
193 199
Summing up, you have to
194 200
1) Get and read the datasheet of the device (A) or
amiro-lld.h
24 24
 */
25 25
#define _AMIRO_LLD_
26 26

  
27
/*===========================================================================*/
27 28
/**
28 29
 * @name   AMiRo-LLD version and relase information.
29 30
 * @{
30 31
 */
32
/*===========================================================================*/
31 33

  
32 34
/**
33 35
 * @brief   Realease type of this version.
34 36
 * @note    Possible values are "pre-alpha", "alpha", "beta", "release candidate", and "release".
35 37
 */
36
#define AMIRO_LLD_RELEASE_TYPE     "beta"
38
#define AMIROLLD_RELEASE_TYPE                   "beta"
37 39

  
38 40
/**
39 41
 * @brief   The AMiRo-LLD major version.
40 42
 * @note    Changes of the major version imply incompatibilities.
41 43
 */
42
#define AMIRO_LLD_VERSION_MAJOR    1
44
#define AMIROLLD_VERSION_MAJOR                  1
43 45

  
44 46
/**
45 47
 * @brief   The AMiRo-LLD minor version.
46 48
 * @note    A higher minor version implies new functionalty, but all old interfaces are still available.
47 49
 */
48
#define AMIRO_LLD_VERSION_MINOR    0
50
#define AMIROLLD_VERSION_MINOR                  1
49 51

  
50 52
/**
51 53
 * @brief   The AMiRo-LLD patch level.
52 54
 */
53
#define AMIRO_LLD_VERSION_PATCH    2
54

  
55
/**
56
 * @brief   The periphery abstraction layer interface required major version.
57
 * @note    Any other major version is assumed to be incompatible.
58
 */
59
#define PERIPHAL_REQUIRED_MAJOR    1
60

  
61
/**
62
 * @brief   The periphery abstraction layer interface required minor version.
63
 * @note    Higher minor version values are assumed to be compatible, too.
64
 */
65
#define PERIPHAL_REQUIRED_MINOR    1
55
#define AMIROLLD_VERSION_PATCH                  0
66 56

  
67 57
/** @} */
68 58

  
59
/******************************************************************************/
60
/* CONFIGURATION & VERIFICATION                                               */
61
/******************************************************************************/
62

  
69 63
#include <alldconf.h>
64

  
70 65
#if !defined(_AMIRO_LLD_CFG_)
71
#error "invalid AMiRo-LLD configuration file"
72
#elif (AMIRO_LLD_CFG_VERSION_MAJOR != AMIRO_LLD_VERSION_MAJOR) || (AMIRO_LLD_CFG_VERSION_MINOR < AMIRO_LLD_VERSION_MINOR)
73
#error "incompatible AMiRo-LLD configuration file"
66
  #error "invalid AMiRo-LLD configuration file"
67
#elif (AMIRO_LLD_CFG_VERSION_MAJOR != AMIROLLD_VERSION_MAJOR) || (AMIRO_LLD_CFG_VERSION_MINOR < AMIROLLD_VERSION_MINOR)
68
  #error "incompatible AMiRo-LLD configuration file"
74 69
#endif
75 70

  
76
#include "periphALtypes.h"
77
#include <periphAL.h>
78
#if !defined(PERIPHAL_VERSION_MAJOR) || !defined(PERIPHAL_VERSION_MINOR)
79
#error "invalid periphAL implementation"
80
#elif (PERIPHAL_VERSION_MAJOR != PERIPHAL_REQUIRED_MAJOR) || (PERIPHAL_VERSION_MINOR < PERIPHAL_REQUIRED_MINOR)
81
#error "incompatible periphAL implementation"
71
#if !defined(AMIROLLD_CFG_TIME_SIZE)
72
  #error "AMIROLLD_CFG_TIME_SIZE not defined in alldconf.h"
73
#endif /* !defined(AMIROLLD_CFG_TIME_SIZE) */
74

  
75
#if !defined(AMIROLLD_CFG_DBG)
76
  #error "AMIROLLD_CFG_DBG not defined in alldconf.h"
77
#endif /* !defined(AMIROLLD_CFG_DBG) */
78

  
79
#if !defined(AMIROLLD_CFG_GPIO)
80
  #error "AMIROLLD_CFG_GPIO not defined in alldconf.h"
81
#endif /* !defined(AMIROLLD_CFG_GPIO) */
82

  
83
#if !defined(AMIROLLD_CFG_PWM)
84
  #error "AMIROLLD_CFG_PWM not defined in alldconf.h"
85
#endif /* !defined(AMIROLLD_CFG_PWM) */
86

  
87
#if !defined(AMIROLLD_CFG_QEI)
88
  #error "AMIROLLD_CFG_QEI not defined in alldconf.h"
89
#endif /* !defined(AMIROLLD_CFG_QEI) */
90

  
91
#if !defined(AMIROLLD_CFG_I2C)
92
  #error "AMIROLLD_CFG_I2C not defined in alldconf.h"
93
#endif /* !defined(AMIROLLD_CFG_I2C) */
94

  
95
#if !defined(AMIROLLD_CFG_SPI)
96
  #error "AMIROLLD_CFG_SPI not defined in alldconf.h"
97
#endif /* !defined(AMIROLLD_CFG_SPI) */
98

  
99
#if ((AMIROLLD_CFG_GPIO == true) || \
100
     (AMIROLLD_CFG_PWM == true)  || \
101
     (AMIROLLD_CFG_QEI == true)  || \
102
     (AMIROLLD_CFG_I2C == true)  || \
103
     (AMIROLLD_CFG_SPI == true)) && \
104
    !defined(AMIROLLD_CFG_PERIPHAL_HEADER)
105
  #error "AMIROLLD_CFG_PERIPHAL_HEADER required but not defined in alldconf.h"
82 106
#endif
83 107

  
108
/******************************************************************************/
109
/* PERIPHERY ABSTRACTION LAYER (periphAL)                                     */
110
/******************************************************************************/
111

  
112
#if defined(AMIROLLD_CFG_PERIPHAL_HEADER)
113
#include AMIROLLD_CFG_PERIPHAL_HEADER
114
#endif
115

  
116
#include <periphAL.h>
117

  
84 118
#endif /* AMIROLLD_H */
periphAL.h
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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 */
periphALtypes.h
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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_PERIPHALTYPES_H
20
#define AMIROLLD_PERIPHALTYPES_H
21

  
22
/*============================================================================*/
23
/* DEPENDENCIES                                                               */
24
/*============================================================================*/
25

  
26
#include <amiro-lld.h>
27
#include <stdint.h>
28

  
29
/*============================================================================*/
30
/* GENERAL                                                                    */
31
/*============================================================================*/
32

  
33
/**
34
 * @brief Time measurement type (in microseconds).
35
 */
36
#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

  
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
/* 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
typedef uint8_t apalGpioState_t;
102

  
103
/**
104
 * @brief   GPIO physical low state.
105
 */
106
#define APAL_GPIO_LOW                           ((apalGpioState_t)0)
107

  
108
/**
109
 * @brief   GPIO physical high state.
110
 */
111
#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

  
139
/**
140
 * @brief   Polarity state of the control GPIO.
141
 */
142
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

  
180
/**
181
 * @brief   Signal direction for the control GPIO.
182
 */
183
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

  
210
/**
211
 * @brief   No edges indicate an interrupt or trigger an action.
212
 */
213
#define APAL_GPIO_EDGE_NONE                     ((apalGpioEdge_t)0)
214

  
215
/**
216
 * @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
 * @details Rising edge is inverted to falling and vice versa.
233
 *          If none or both edges are enabled, the identical value is returned.
234
 */
235
#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

  
242
/**
243
 * @brief Control GPIO meta information
244
 */
245
typedef struct {
246
  apalGpioDirection_t direction : 2;  /**< Direction configuration for according signals */
247
  apalGpioActive_t active       : 2;  /**< Active state of the GPIO */
248
  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
 * @brief   PWM width to turn off the PWM.
285
 */
286
#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

  
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
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

  
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
/* nothing defined for SPI */
336

  
337
#endif /* AMIROLLD_PERIPHALTYPES_H */
templates/alldconf.h
19 19
#ifndef ALLDCONF_H
20 20
#define ALLDCONF_H
21 21

  
22
/*
23
 * compatibility guards
24
 */
25 22
#define _AMIRO_LLD_CFG_
26 23
#define AMIRO_LLD_CFG_VERSION_MAJOR         1
27
#define AMIRO_LLD_CFG_VERSION_MINOR         0
24
#define AMIRO_LLD_CFG_VERSION_MINOR         1
28 25

  
29 26
/**
30 27
 * @brief   Width of the apalTime_t data type.
......
32 29
 * @details Possible values are 8, 16, 32, and 64 bits.
33 30
 *          By definition time is represented ot a microsecond precision.
34 31
 */
35
#define AMIROLLD_CFG_TIME_SIZE          32
32
#define AMIROLLD_CFG_TIME_SIZE                  32
33

  
34
/**
35
 * @brief   Flag to enable/disable DBG API.
36
 */
37
#define AMIROLLD_CFG_DBG                        true
38

  
39
/**
40
 * @brief   Flag to enable/disable GPIO API.
41
 */
42
#define AMIROLLD_CFG_GPIO                       true
43

  
44
/**
45
 * @brief   Flag to enable/disable PWM API.
46
 */
47
#define AMIROLLD_CFG_PWM                        true
48

  
49
/**
50
 * @brief   Flag to enable/disable QEI API.
51
 */
52
#define AMIROLLD_CFG_QEI                        true
53

  
54
/**
55
 * @brief   Flag to enable/disable I2C API.
56
 */
57
#define AMIROLLD_CFG_I2C                        true
58

  
59
/**
60
 * @brief   Flag to enable/disable SPI API.
61
 */
62
#define AMIROLLD_CFG_SPI                        true
63

  
64
/**
65
 * @brief   Hook macro to insert a custom header to periphAL.h file.
66
 */
67
#define AMIROLLD_CFG_PERIPHAL_HEADER            <custom_periphAL.h>
36 68

  
37 69
#endif /* ALLDCONF_H */
templates/periphAL.h
1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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.
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff