Statistics
| Branch: | Tag: | Revision:

amiro-lld / periphALtypes.h @ 8c47f14b

History | View | Annotate | Download (7.61 KB)

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 <alldconf.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 enum {
55
  APAL_STATUS_OK                = 0x00u, /**< success, no error occurred                          */
56
  APAL_STATUS_SUCCESS           = 0x00u, /**< success, no error occurred                          */
57
  APAL_STATUS_ERROR             = 0x01u, /**< failed, some unspecified error occured              */
58
  APAL_STATUS_FAILURE           = 0x01u, /**< failed, some unspecified error occured              */
59
  APAL_STATUS_TIMEOUT           = 0x02u, /**< failed, timeout occurred                            */
60
  APAL_STATUS_INVALIDARGUMENTS  = 0x04u, /**< failed, invalid arguments                           */
61
  APAL_STATUS_UNAVAILABLE       = 0x08u, /**< failed, function unavailable                        */
62
  APAL_STATUS_WARNING           = 0x10u, /**< success, but the result is probably not as expected */
63
} apalExitStatus_t;
64

    
65
/*============================================================================*/
66
/* GPIO                                                                       */
67
/*============================================================================*/
68

    
69
/**
70
 * @brief   Forward declaration.
71
 * @details Struct must be defined in 'periphAL.h'.
72
 */
73
typedef struct apalGpio_t apalGpio_t;
74

    
75
/**
76
 * @brief Status values to read/write a GPIO port.
77
 */
78
typedef enum {
79
  APAL_GPIO_LOW   = 0,  /**< logical low state  */
80
  APAL_GPIO_HIGH  = 1,  /**< logical high state */
81
} apalGpioState_t;
82

    
83
/**
84
 * @brief Status values to turn a control GPIO 'on' and 'off'.
85
 */
86
typedef enum {
87
  APAL_GPIO_OFF = 0,  /**< logical 'turned off' state */
88
  APAL_GPIO_ON  = 1,  /**< logical 'turned on' state  */
89
} apalControlGpioState_t;
90

    
91
/**
92
 * @brief   Polarity state of the control GPIO.
93
 */
94
typedef enum {
95
  APAL_GPIO_ACTIVE_LOW  = 0x00,   /**< A logically low state is defined as 'on'.  */
96
  APAL_GPIO_ACTIVE_HIGH = 0x01,   /**< A locically high state is defined as 'on'. */
97
} apalGpioActive_t;
98

    
99
/**
100
 * @brief   Signal direction for the control GPIO.
101
 */
102
typedef enum {
103
  APAL_GPIO_DIRECTION_UNDEFINED     = 0x00,   /**< Signal direction is undefined.     */
104
  APAL_GPIO_DIRECTION_INPUT         = 0x01,   /**< Signal direction is input only.    */
105
  APAL_GPIO_DIRECTION_OUTPUT        = 0x02,   /**< Signal direction is output only    */
106
  APAL_GPIO_DIRECTION_BIDIRECTIONAL = 0x03,   /**< Signal direction is bidirectional. */
107
} apalGpioDirection_t;
108

    
109
/**
110
 * @brief   Informative signal edge for input control GPIOs.
111
 */
112
typedef enum {
113
  APAL_GPIO_EDGE_NONE     = 0x00,   /**< No edge indicates an interrupt.                      */
114
  APAL_GPIO_EDGE_RISING   = 0x01,   /**< Rising edges indicate an interrupt.                  */
115
  APAL_GPIO_EDGE_FALLING  = 0x02,   /**< Falling edges indicate an interrupt.                 */
116
  APAL_GPIO_EDGE_BOTH     = 0x03,   /**< Both rising and falling edges indicate an interrupt. */
117
} apalGpioEdge_t;
118

    
119
/**
120
 * @brief   Inverts the value of the informative signal edge for interrupts.
121
 * @details Rising edge is inverted to falling and vice versa.
122
 *          If none or both edges are enabled, the identical value is returned.
123
 */
124
#define APAL_GPIO_EDGE_INVERT(edge)                                 \
125
  ((edge == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_EDGE_FALLING :       \
126
   (edge == APAL_GPIO_EDGE_FALLING) ? APAL_GPIO_EDGE_RISING : edge) \
127

    
128
/**
129
 * @brief Control GPIO meta information
130
 */
131
typedef struct {
132
  apalGpioDirection_t direction : 2;  /**< Direction configuration for according signals */
133
  apalGpioActive_t active       : 1;  /**< Active state of the GPIO */
134
  apalGpioEdge_t edge           : 2;  /**< Edge configuration for according signals */
135
} apalGpioMeta_t;
136

    
137
/**
138
 * @brief Control GPIO type.
139
 */
140
typedef struct {
141
  apalGpio_t* gpio;     /**< The GPIO to use.                 */
142
  apalGpioMeta_t meta;  /**< Meta information about the GPIO. */
143
} apalControlGpio_t;
144

    
145
/*============================================================================*/
146
/* PWM                                                                        */
147
/*============================================================================*/
148

    
149
/**
150
 * @brief PWM channel type.
151
 */
152
typedef uint8_t   apalPWMchannel_t;
153

    
154
/**
155
 * @brief PWM width type.
156
 */
157
typedef uint16_t  apalPWMwidth_t;
158

    
159
/**
160
 * @brief PWM frequency type.
161
 */
162
typedef uint32_t  apalPWMfrequency_t;
163

    
164
/**
165
 * @brief PWM period time.
166
 */
167
typedef uint32_t  apalPWMperiod_t;
168

    
169
/**
170
 * @brief PWM width limits and special values.
171
 */
172
typedef enum {
173
  APAL_PWM_WIDTH_OFF  = 0x0000u,  /**< PWM off            */
174
  APAL_PWM_WIDTH_MIN  = 0x0000u,  /**< PWM minimum width  */
175
  APAL_PWM_WIDTH_MAX  = 0xFFFFu,  /**< PWM maximum width  */
176
} apalPWMWidthLimit_t;
177

    
178
/*============================================================================*/
179
/* QEI                                                                        */
180
/*============================================================================*/
181

    
182
/**
183
 * @brief QEI counter type.
184
 */
185
typedef uint32_t  apalQEICount_t;
186

    
187
/**
188
 * @brief Direction of the QEI.
189
 */
190
typedef enum {
191
  APAL_QEI_DIRECTION_UP   = 0,  /**< QEI counted up   */
192
  APAL_QEI_DIRECTION_DOWN = 1,  /**< QEI counted down */
193
} apalQEIDirection_t;
194

    
195
/*============================================================================*/
196
/* I2C                                                                        */
197
/*============================================================================*/
198

    
199
/**
200
 * @brief I2C address type.
201
 */
202
typedef uint16_t apalI2Caddr_t;
203

    
204
/*============================================================================*/
205
/* SPI                                                                        */
206
/*============================================================================*/
207

    
208

    
209
#endif /* AMIROLLD_PERIPHALTYPES_H */