amiro-lld / templates / periphAL.h @ a5507edc
History | View | Annotate | Download (12.142 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_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 1 |
| 39 |
|
| 40 |
/*============================================================================*/
|
| 41 |
/* DEPENDENCIES */
|
| 42 |
/*============================================================================*/
|
| 43 |
|
| 44 |
/*============================================================================*/
|
| 45 |
/* GENERAL */
|
| 46 |
/*============================================================================*/
|
| 47 |
|
| 48 |
#ifdef __cplusplus
|
| 49 |
extern "C" { |
| 50 |
#endif
|
| 51 |
|
| 52 |
/**
|
| 53 |
* @brief Delay execution by a specific number of microseconds.
|
| 54 |
*
|
| 55 |
* @param[in] us Time to sleep until execution continues in microseconds.
|
| 56 |
*/
|
| 57 |
void apalSleep(apalTime_t us);
|
| 58 |
|
| 59 |
#ifdef __cplusplus
|
| 60 |
} |
| 61 |
#endif
|
| 62 |
|
| 63 |
/*============================================================================*/
|
| 64 |
/* GPIO */
|
| 65 |
/*============================================================================*/
|
| 66 |
|
| 67 |
typedef osGpio_t apalGpio_t;
|
| 68 |
|
| 69 |
#ifdef __cplusplus
|
| 70 |
extern "C" { |
| 71 |
#endif
|
| 72 |
|
| 73 |
/**
|
| 74 |
* @brief Read the current value of a GPIO pin.
|
| 75 |
*
|
| 76 |
* @param[in] gpio GPIO to read.
|
| 77 |
* @param[out] val Current value of the GPIO.
|
| 78 |
*
|
| 79 |
* @return The status indicates whether the function call was successful.
|
| 80 |
*/
|
| 81 |
apalExitStatus_t apalGpioRead(apalGpio_t* gpio, apalGpioState_t* const val);
|
| 82 |
|
| 83 |
/**
|
| 84 |
* @brief Set the value of a GPIO pin.
|
| 85 |
*
|
| 86 |
* @param[in] gpio GPIO to write.
|
| 87 |
* @param[in] val Value to set for the GPIO.
|
| 88 |
*
|
| 89 |
* @return The status indicates whether the function call was successful.
|
| 90 |
*/
|
| 91 |
apalExitStatus_t apalGpioWrite(apalGpio_t* gpio, const apalGpioState_t val);
|
| 92 |
|
| 93 |
/**
|
| 94 |
* @brief Toggle the output of a GPIO.
|
| 95 |
*
|
| 96 |
* @param[in] gpio GPIO to toggle.
|
| 97 |
*
|
| 98 |
* @return The status indicates whether the function call was successful.
|
| 99 |
*/
|
| 100 |
apalExitStatus_t apalGpioToggle(apalGpio_t* gpio); |
| 101 |
|
| 102 |
/**
|
| 103 |
* @brief Return the interrupt enable status of the GPIO.
|
| 104 |
*
|
| 105 |
* @param[in] gpio GPIO to check.
|
| 106 |
* @param[out] enabled Flag, indicating whether interrupt is enabled for the GPIO.
|
| 107 |
*
|
| 108 |
* @return The status indicates whether the function call was successful.
|
| 109 |
*/
|
| 110 |
static inline apalExitStatus_t apalGpioIsInterruptEnabled(apalGpio_t* gpio, bool* const enabled) |
| 111 |
|
| 112 |
/**
|
| 113 |
* @brief Get the current on/off state of a control GPIO.
|
| 114 |
*
|
| 115 |
* @param[in] gpio Control GPIO to read.
|
| 116 |
* @param[out] val Current activation status of the control GPIO.
|
| 117 |
*
|
| 118 |
* @return The status indicates whether the function call was successful.
|
| 119 |
*/
|
| 120 |
apalExitStatus_t apalControlGpioGet(const apalControlGpio_t* const cgpio, apalControlGpioState_t* const val); |
| 121 |
|
| 122 |
/**
|
| 123 |
* @brief Turn a control GPIO 'on' or 'off' respectively.
|
| 124 |
*
|
| 125 |
* @param[in] gpio Control GPIO to set.
|
| 126 |
* @param[in] val Activation value to set for the control GPIO.
|
| 127 |
*
|
| 128 |
* @return The status indicates whether the function call was successful.
|
| 129 |
*/
|
| 130 |
apalExitStatus_t apalControlGpioSet(const apalControlGpio_t* const cgpio, const apalControlGpioState_t val); |
| 131 |
|
| 132 |
/**
|
| 133 |
* @brief Enable or disable the interrupt event functionality.
|
| 134 |
*
|
| 135 |
* @param[in] cgpio Control GPIO to set.
|
| 136 |
* @param[in] enable Flag, indicating whether the interrupt shall be activated (true) or deactivated (false).
|
| 137 |
*
|
| 138 |
* @return The status indicates whether the function call was successful.
|
| 139 |
*/
|
| 140 |
apalExitStatus_t apalControlGpioSetInterrupt(apalControlGpio_t* const cgpio, const bool enable); |
| 141 |
|
| 142 |
#ifdef __cplusplus
|
| 143 |
} |
| 144 |
#endif
|
| 145 |
|
| 146 |
/*============================================================================*/
|
| 147 |
/* PWM */
|
| 148 |
/*============================================================================*/
|
| 149 |
|
| 150 |
/**
|
| 151 |
* @brief PWM driver type.
|
| 152 |
*/
|
| 153 |
typedef osPWMDriver_t apalPWMDriver_t;
|
| 154 |
|
| 155 |
#ifdef __cplusplus
|
| 156 |
extern "C" { |
| 157 |
#endif
|
| 158 |
|
| 159 |
/**
|
| 160 |
* @brief Set the PWM with given parameters.
|
| 161 |
*
|
| 162 |
* @param[in] pwm PWM driver to set.
|
| 163 |
* @param[in] channel Channel of the PWM driver to set.
|
| 164 |
* @param[in] width Width to set the channel to.
|
| 165 |
*
|
| 166 |
* @return The status indicates whether the function call was successful.
|
| 167 |
*/
|
| 168 |
apalExitStatus_t apalPWMSet(apalPWMDriver_t* pwm, const apalPWMchannel_t channel, const apalPWMwidth_t width); |
| 169 |
|
| 170 |
/**
|
| 171 |
* @brief Retrieve the current frequency of the PWM.
|
| 172 |
*
|
| 173 |
* @param[in] pwm PWM driver to read.
|
| 174 |
* @param[out] frequency The currently set frequency.
|
| 175 |
*
|
| 176 |
* @return The status indicates whether the function call was successful.
|
| 177 |
*/
|
| 178 |
apalExitStatus_t apalPWMGetFrequency(apalPWMDriver_t* pwm, apalPWMfrequency_t* const frequency);
|
| 179 |
|
| 180 |
/**
|
| 181 |
* @brief Retrieve the current period of the PWM.
|
| 182 |
*
|
| 183 |
* @param[in] pwm PWM driver to read.
|
| 184 |
* @param[out] period The currently set period.
|
| 185 |
*
|
| 186 |
* @return The status indicates whether the function call was successful.
|
| 187 |
*/
|
| 188 |
apalExitStatus_t apalPWMGetPeriod(apalPWMDriver_t* pwm, apalPWMperiod_t* const period);
|
| 189 |
|
| 190 |
#ifdef __cplusplus
|
| 191 |
} |
| 192 |
#endif
|
| 193 |
|
| 194 |
/*============================================================================*/
|
| 195 |
/* QEI */
|
| 196 |
/*============================================================================*/
|
| 197 |
|
| 198 |
/**
|
| 199 |
* @brief QEI driver type.
|
| 200 |
*/
|
| 201 |
typedef osQEIDriver_t apaQEIDriver_t;
|
| 202 |
|
| 203 |
#ifdef __cplusplus
|
| 204 |
extern "C" { |
| 205 |
#endif
|
| 206 |
|
| 207 |
/**
|
| 208 |
* @brief Gets the direction of the last transition.
|
| 209 |
*
|
| 210 |
* @param[in] qei The QEI driver to use.
|
| 211 |
* @param[out] direction The direction of the last transition.
|
| 212 |
*
|
| 213 |
* @return The status indicates whether the function call was successful.
|
| 214 |
*/
|
| 215 |
apalExitStatus_t apalQEIGetDirection(apalQEIDriver_t* qei, apalQEIDirection_t* const direction);
|
| 216 |
|
| 217 |
/**
|
| 218 |
* @brief Gets the current position of the ecnoder.
|
| 219 |
*
|
| 220 |
* @param[in] qei The QEI driver to use.
|
| 221 |
* @param[out] position The current position of the encoder.
|
| 222 |
*
|
| 223 |
* @return The status indicates whether the function call was successful.
|
| 224 |
*/
|
| 225 |
apalExitStatus_t apalQEIGetPosition(apalQEIDriver_t* qei, apalQEICount_t* const position);
|
| 226 |
|
| 227 |
/**
|
| 228 |
* @brief Gets the value range of the encoder.
|
| 229 |
*
|
| 230 |
* @param[in] qei The QEI driver to use.
|
| 231 |
* @param[out] range The value range of the encoder.
|
| 232 |
*
|
| 233 |
* @return The status indicates whether the function call was successful.
|
| 234 |
*/
|
| 235 |
apalExitStatus_t apalQEIGetRange(apalQEIDriver_t* qei, apalQEICount_t* const range);
|
| 236 |
|
| 237 |
#ifdef __cplusplus
|
| 238 |
} |
| 239 |
#endif
|
| 240 |
|
| 241 |
/*============================================================================*/
|
| 242 |
/* I2C */
|
| 243 |
/*============================================================================*/
|
| 244 |
|
| 245 |
/**
|
| 246 |
* @brief I2C driver type.
|
| 247 |
*/
|
| 248 |
typedef osI2CDriver_t apalI2CDriver_t;
|
| 249 |
|
| 250 |
#ifdef __cplusplus
|
| 251 |
extern "C" { |
| 252 |
#endif
|
| 253 |
|
| 254 |
/**
|
| 255 |
* @brief Transmit data and receive a response.
|
| 256 |
*
|
| 257 |
* @param[in] i2cd The I2C driver to use.
|
| 258 |
* @param[in] addr Address to write to.
|
| 259 |
* @param[in] txbuf Buffer containing data to send.
|
| 260 |
* @param[in] txbytes Number of bytes to send.
|
| 261 |
* @param[out] rxbuf Buffer to store a response to.
|
| 262 |
* @param[in] rxbytes Number of bytes to receive.
|
| 263 |
* @param[in] timeout Timeout for the function to return (in microseconds).
|
| 264 |
*
|
| 265 |
* @return The status indicates whether the function call was succesful or a timeout occurred.
|
| 266 |
*/
|
| 267 |
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); |
| 268 |
|
| 269 |
/**
|
| 270 |
* @brief Read data from a specific address.
|
| 271 |
*
|
| 272 |
* @param[in] i2cd The I2C driver to use.
|
| 273 |
* @param[in] addr Address to read.
|
| 274 |
* @param[out] rxbuf Buffer to store the response to.
|
| 275 |
* @param[in] rxbytes Number of bytes to receive.
|
| 276 |
* @param[in] timeout Timeout for the function to return (in microseconds).
|
| 277 |
*
|
| 278 |
* @return The status indicates whether the function call was succesful or a timeout occurred.
|
| 279 |
*/
|
| 280 |
apalExitStatus_t apalI2CMasterReceive(apalI2CDriver_t* i2cd, const apalI2Caddr_t addr, uint8_t* const rxbuf, const size_t rxbytes, const apalTime_t timeout); |
| 281 |
|
| 282 |
#ifdef __cplusplus
|
| 283 |
} |
| 284 |
#endif
|
| 285 |
|
| 286 |
/*============================================================================*/
|
| 287 |
/* SPI */
|
| 288 |
/*============================================================================*/
|
| 289 |
|
| 290 |
/**
|
| 291 |
* @brief SPI driver type.
|
| 292 |
*/
|
| 293 |
typedef osSPIDriver_t apalSPIDriver_t;
|
| 294 |
|
| 295 |
#ifdef __cplusplus
|
| 296 |
extern "C" { |
| 297 |
#endif
|
| 298 |
|
| 299 |
/**
|
| 300 |
* @brief Transmit and receive data from SPI
|
| 301 |
*
|
| 302 |
* @param[in] spid The SPI driver to use.
|
| 303 |
* @param[in] txData Buffer containing data to send.
|
| 304 |
* @param[out] rxData Buffer to store.
|
| 305 |
* @param[in] length Number of bytes to send.
|
| 306 |
*
|
| 307 |
* @return The status indicates whether the function call was succesful.
|
| 308 |
*/
|
| 309 |
apalExitStatus_t apalSPIExchange(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t length); |
| 310 |
|
| 311 |
/**
|
| 312 |
* @brief Receive data from SPI
|
| 313 |
*
|
| 314 |
* @param[in] spid The SPI driver to use.
|
| 315 |
* @param[out] data Buffer to store.
|
| 316 |
* @param[in] length Number of bytes to send.
|
| 317 |
*
|
| 318 |
* @return The status indicates whether the function call was succesful.
|
| 319 |
*/
|
| 320 |
apalExitStatus_t apalSPIReceive(apalSPIDriver_t* spid, uint8_t* const data, const size_t length); |
| 321 |
|
| 322 |
/**
|
| 323 |
* @brief Transmit data to SPI
|
| 324 |
*
|
| 325 |
* @param[in] spid The SPI driver to use.
|
| 326 |
* @param[in] data Buffer containing data to send.
|
| 327 |
* @param[in] length Number of bytes to send.
|
| 328 |
*
|
| 329 |
* @return The status indicates whether the function call was succesful.
|
| 330 |
*/
|
| 331 |
apalExitStatus_t apalSPITransmit(apalSPIDriver_t* spid, const uint8_t* const data, const size_t length); |
| 332 |
|
| 333 |
/**
|
| 334 |
* @brief Transmit data to SPI and receive data afterwards without releasing the bus in between.
|
| 335 |
*
|
| 336 |
* @param[in] spid The SPI driver to use.
|
| 337 |
* @param[in] txData Transmit data buffer.
|
| 338 |
* @param[in] rxData Receive data buffer.
|
| 339 |
* @param[in] txLength Number of bytes to send.
|
| 340 |
* @param[in] rxLength Number of bytes to receive.
|
| 341 |
*
|
| 342 |
* @return The status indicates whether the function call was succesful.
|
| 343 |
*/
|
| 344 |
static inline apalExitStatus_t apalSPITransmitAndReceive(apalSPIDriver_t* spid, const uint8_t* const txData , uint8_t* const rxData, const size_t txLength, const size_t rxLength); |
| 345 |
|
| 346 |
#ifdef __cplusplus
|
| 347 |
} |
| 348 |
#endif
|
| 349 |
|
| 350 |
/*============================================================================*/
|
| 351 |
/* DEBUG */
|
| 352 |
/*============================================================================*/
|
| 353 |
|
| 354 |
#ifdef __cplusplus
|
| 355 |
extern "C" { |
| 356 |
#endif
|
| 357 |
|
| 358 |
/**
|
| 359 |
* @brief Assert function to check a given condition.
|
| 360 |
* @note Using a macro is preferable.
|
| 361 |
*
|
| 362 |
* @param[in] c The condition to check.
|
| 363 |
*/
|
| 364 |
void apalDbgAssert(bool c); |
| 365 |
|
| 366 |
/**
|
| 367 |
* @brief Printf function for messages printed only in debug builds.
|
| 368 |
*
|
| 369 |
* @param[in] fmt Formatted string to print.
|
| 370 |
*/
|
| 371 |
void apalDbgPrintf(fmt, ...);
|
| 372 |
|
| 373 |
#ifdef __cplusplus
|
| 374 |
} |
| 375 |
#endif
|
| 376 |
|
| 377 |
#endif /* AMIROOS_PERIPHAL_H */ |
| 378 |
|