amiro-os / kernel / patches / QEI-driver.patch @ ad8a2568
History | View | Annotate | Download (28.646 KB)
| 1 | 20a4e01c | Marc Rothmann | diff --git a/os/hal/hal.mk b/os/hal/hal.mk
|
|---|---|---|---|
| 2 | --- a/os/hal/hal.mk
|
||
| 3 | +++ b/os/hal/hal.mk
|
||
| 4 | 732a4657 | Thomas Schöpping | @@ -54,6 +54,9 @@ endif
|
| 5 | ifneq ($(findstring HAL_USE_PWM TRUE,$(HALCONF)),) |
||
| 6 | HALSRC += $(CHIBIOS)/os/hal/src/hal_pwm.c |
||
| 7 | eedb8e58 | Thomas Schöpping | endif |
| 8 | +ifneq ($(findstring HAL_USE_QEI TRUE,$(HALCONF)),)
|
||
| 9 | +HALSRC += $(CHIBIOS)/os/hal/src/hal_qei.c
|
||
| 10 | +endif
|
||
| 11 | 732a4657 | Thomas Schöpping | ifneq ($(findstring HAL_USE_RTC TRUE,$(HALCONF)),) |
| 12 | HALSRC += $(CHIBIOS)/os/hal/src/hal_rtc.c |
||
| 13 | eedb8e58 | Thomas Schöpping | endif |
| 14 | 732a4657 | Thomas Schöpping | @@ -104,6 +107,7 @@ HALSRC = $(CHIBIOS)/os/hal/src/hal.c \
|
| 15 | eedb8e58 | Thomas Schöpping | $(CHIBIOS)/os/hal/src/hal_mmc_spi.c \ |
| 16 | $(CHIBIOS)/os/hal/src/hal_pal.c \ |
||
| 17 | 732a4657 | Thomas Schöpping | $(CHIBIOS)/os/hal/src/hal_pwm.c \ |
| 18 | + $(CHIBIOS)/os/hal/src/hal_qei.c \
|
||
| 19 | $(CHIBIOS)/os/hal/src/hal_rtc.c \ |
||
| 20 | $(CHIBIOS)/os/hal/src/hal_sdc.c \ |
||
| 21 | $(CHIBIOS)/os/hal/src/hal_serial.c \ |
||
| 22 | eedb8e58 | Thomas Schöpping | diff --git a/os/hal/include/hal.h b/os/hal/include/hal.h
|
| 23 | --- a/os/hal/include/hal.h
|
||
| 24 | +++ b/os/hal/include/hal.h
|
||
| 25 | 732a4657 | Thomas Schöpping | @@ -74,6 +74,10 @@
|
| 26 | eedb8e58 | Thomas Schöpping | #define HAL_USE_PWM FALSE
|
| 27 | #endif
|
||
| 28 | |||
| 29 | +#if !defined(HAL_USE_QEI)
|
||
| 30 | +#define HAL_USE_QEI FALSE
|
||
| 31 | +#endif
|
||
| 32 | +
|
||
| 33 | 732a4657 | Thomas Schöpping | #if !defined(HAL_USE_RTC)
|
| 34 | #define HAL_USE_RTC FALSE
|
||
| 35 | eedb8e58 | Thomas Schöpping | #endif
|
| 36 | 732a4657 | Thomas Schöpping | @@ -142,6 +146,7 @@
|
| 37 | eedb8e58 | Thomas Schöpping | #include "hal_icu.h" |
| 38 | #include "hal_mac.h" |
||
| 39 | #include "hal_pwm.h" |
||
| 40 | +#include "hal_qei.h"
|
||
| 41 | #include "hal_rtc.h" |
||
| 42 | #include "hal_serial.h" |
||
| 43 | 732a4657 | Thomas Schöpping | #include "hal_sdc.h" |
| 44 | 20a4e01c | Marc Rothmann | diff --git a/os/hal/include/hal_qei.h b/os/hal/include/hal_qei.h
|
| 45 | new file mode 100644
|
||
| 46 | --- /dev/null
|
||
| 47 | +++ b/os/hal/include/hal_qei.h
|
||
| 48 | @@ -0,0 +1,148 @@
|
||
| 49 | +/*
|
||
| 50 | +AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 51 | 732a4657 | Thomas Schöpping | +Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 52 | 20a4e01c | Marc Rothmann | +
|
| 53 | +This program is free software: you can redistribute it and/or modify
|
||
| 54 | +it under the terms of the GNU General Public License as published by
|
||
| 55 | +the Free Software Foundation, either version 3 of the License, or
|
||
| 56 | +(at your option) any later version.
|
||
| 57 | +
|
||
| 58 | +This program is distributed in the hope that it will be useful,
|
||
| 59 | +but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 60 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 61 | +GNU General Public License for more details.
|
||
| 62 | +
|
||
| 63 | +You should have received a copy of the GNU General Public License
|
||
| 64 | +along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
| 65 | +*/
|
||
| 66 | +
|
||
| 67 | +/**
|
||
| 68 | + * @file hal_qei.h
|
||
| 69 | + * @brief QEI Driver macros and structures.
|
||
| 70 | + *
|
||
| 71 | + * @addtogroup QEI
|
||
| 72 | + * @{
|
||
| 73 | + */
|
||
| 74 | +
|
||
| 75 | eedb8e58 | Thomas Schöpping | +#ifndef HAL_QEI_H
|
| 76 | +#define HAL_QEI_H
|
||
| 77 | 20a4e01c | Marc Rothmann | +
|
| 78 | eedb8e58 | Thomas Schöpping | +#if (HAL_USE_QEI == TRUE) || defined(__DOXYGEN__)
|
| 79 | 20a4e01c | Marc Rothmann | +
|
| 80 | +/*===========================================================================*/
|
||
| 81 | +/* Driver constants. */
|
||
| 82 | +/*===========================================================================*/
|
||
| 83 | +
|
||
| 84 | +/*===========================================================================*/
|
||
| 85 | +/* Driver pre-compile time settings. */
|
||
| 86 | +/*===========================================================================*/
|
||
| 87 | +
|
||
| 88 | +/*===========================================================================*/
|
||
| 89 | +/* Derived constants and error checks. */
|
||
| 90 | +/*===========================================================================*/
|
||
| 91 | +
|
||
| 92 | +/*===========================================================================*/
|
||
| 93 | +/* Driver data structures and types. */
|
||
| 94 | +/*===========================================================================*/
|
||
| 95 | +
|
||
| 96 | +/**
|
||
| 97 | + * @brief Driver state machine possible states.
|
||
| 98 | + */
|
||
| 99 | +typedef enum {
|
||
| 100 | + QEI_UNINIT = 0, /**< Not initialized. */
|
||
| 101 | + QEI_STOP = 1, /**< Stopped. */
|
||
| 102 | + QEI_READY = 2, /**< Ready. */
|
||
| 103 | + QEI_ACTIVE = 4, /**< Active. */
|
||
| 104 | +} qeistate_t;
|
||
| 105 | +
|
||
| 106 | +/**
|
||
| 107 | + * @brief Type of a structure representing an QEI driver.
|
||
| 108 | + */
|
||
| 109 | +typedef struct QEIDriver QEIDriver;
|
||
| 110 | +
|
||
| 111 | +#include "hal_qei_lld.h"
|
||
| 112 | +
|
||
| 113 | +/*===========================================================================*/
|
||
| 114 | +/* Driver macros. */
|
||
| 115 | +/*===========================================================================*/
|
||
| 116 | +
|
||
| 117 | +/**
|
||
| 118 | + * @name Macro Functions
|
||
| 119 | + * @{
|
||
| 120 | + */
|
||
| 121 | +/**
|
||
| 122 | + * @brief Enables the quadrature encoder.
|
||
| 123 | + *
|
||
| 124 | + * @param[in] qeip pointer to the @p QEIDriver object
|
||
| 125 | + *
|
||
| 126 | + * @iclass
|
||
| 127 | + */
|
||
| 128 | +#define qeiEnableI(qeip) qei_lld_enable(qeip)
|
||
| 129 | +
|
||
| 130 | +/**
|
||
| 131 | + * @brief Disables the quadrature encoder.
|
||
| 132 | + *
|
||
| 133 | + * @param[in] qeip pointer to the @p QEIDriver object
|
||
| 134 | + *
|
||
| 135 | + * @iclass
|
||
| 136 | + */
|
||
| 137 | +#define qeiDisableI(qeip) qei_lld_disable(qeip)
|
||
| 138 | +
|
||
| 139 | +/**
|
||
| 140 | + * @brief Returns the direction of the last transition.
|
||
| 141 | + * @details The direction is defined as boolean and is
|
||
| 142 | + * calculated at each transition on any input.
|
||
| 143 | + *
|
||
| 144 | + * @param[in] qeip pointer to the @p QEIDriver object
|
||
| 145 | + * @return The request direction.
|
||
| 146 | + * @retval FALSE Position counted up.
|
||
| 147 | + * @retval TRUE Position counted down.
|
||
| 148 | + * @iclass
|
||
| 149 | + */
|
||
| 150 | +#define qeiGetDirectionI(qeip) qei_lld_get_direction(qeip)
|
||
| 151 | +
|
||
| 152 | +/**
|
||
| 153 | + * @brief Returns the position of the encoder.
|
||
| 154 | + * @details The position is defined as number of pulses since last reset.
|
||
| 155 | + *
|
||
| 156 | + * @param[in] qeip pointer to the @p QEIDriver object
|
||
| 157 | + * @return The number of pulses.
|
||
| 158 | + *
|
||
| 159 | + * @iclass
|
||
| 160 | + */
|
||
| 161 | +#define qeiGetPositionI(qeip) qei_lld_get_position(qeip)
|
||
| 162 | +
|
||
| 163 | +/**
|
||
| 164 | + * @brief Returns the range of the encoder.
|
||
| 165 | + * @details The range is defined as number of maximum pulse count.
|
||
| 166 | + *
|
||
| 167 | + * @param[in] qeip pointer to the @p QEIDriver object
|
||
| 168 | + * @return The number of pulses.
|
||
| 169 | + *
|
||
| 170 | + * @iclass
|
||
| 171 | + */
|
||
| 172 | +#define qeiGetRangeI(qeip) qei_lld_get_range(qeip)
|
||
| 173 | +/** @} */
|
||
| 174 | +
|
||
| 175 | +/*===========================================================================*/
|
||
| 176 | +/* External declarations. */
|
||
| 177 | +/*===========================================================================*/
|
||
| 178 | +
|
||
| 179 | +#ifdef __cplusplus
|
||
| 180 | +extern "C" {
|
||
| 181 | +#endif
|
||
| 182 | + void qeiInit(void);
|
||
| 183 | + void qeiObjectInit(QEIDriver *qeip);
|
||
| 184 | + void qeiStart(QEIDriver *qeip, const QEIConfig *config);
|
||
| 185 | + void qeiStop(QEIDriver *qeip);
|
||
| 186 | + void qeiEnable(QEIDriver *qeip);
|
||
| 187 | + void qeiDisable(QEIDriver *qeip);
|
||
| 188 | +#ifdef __cplusplus
|
||
| 189 | +}
|
||
| 190 | +#endif
|
||
| 191 | +
|
||
| 192 | 732a4657 | Thomas Schöpping | +#endif /* HAL_USE_QEI == TRUE */
|
| 193 | 20a4e01c | Marc Rothmann | +
|
| 194 | eedb8e58 | Thomas Schöpping | +#endif /* HAL_QEI_H */
|
| 195 | 20a4e01c | Marc Rothmann | +
|
| 196 | +/** @} */
|
||
| 197 | diff --git a/os/hal/ports/STM32/LLD/TIMv1/driver.mk b/os/hal/ports/STM32/LLD/TIMv1/driver.mk
|
||
| 198 | --- a/os/hal/ports/STM32/LLD/TIMv1/driver.mk
|
||
| 199 | +++ b/os/hal/ports/STM32/LLD/TIMv1/driver.mk
|
||
| 200 | @@ -10,10 +10,14 @@ endif
|
||
| 201 | eedb8e58 | Thomas Schöpping | ifneq ($(findstring HAL_USE_PWM TRUE,$(HALCONF)),) |
| 202 | PLATFORMSRC += $(CHIBIOS)/os/hal/ports/STM32/LLD/TIMv1/hal_pwm_lld.c |
||
| 203 | endif |
||