aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src
diff options
context:
space:
mode:
authorStephane D'Alu <sdalu@sdalu.com>2016-07-07 21:25:51 +0200
committerStephane D'Alu <sdalu@sdalu.com>2016-07-07 21:25:51 +0200
commitf75abd1037a5c2eb119533eb2f4c7c16d874abf2 (patch)
tree0c2af621c9380d1cea37df8cdddd55eccd3b6088 /os/hal/src
parent9c88423d66e9b4eafecc658058f25f79e08ff120 (diff)
downloadChibiOS-Contrib-f75abd1037a5c2eb119533eb2f4c7c16d874abf2.tar.gz
ChibiOS-Contrib-f75abd1037a5c2eb119533eb2f4c7c16d874abf2.tar.bz2
ChibiOS-Contrib-f75abd1037a5c2eb119533eb2f4c7c16d874abf2.zip
added qeiAdjustI. added new field and checking in STM32
Diffstat (limited to 'os/hal/src')
-rw-r--r--os/hal/src/hal_qei.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/os/hal/src/hal_qei.c b/os/hal/src/hal_qei.c
index abecdf8..eb6223e 100644
--- a/os/hal/src/hal_qei.c
+++ b/os/hal/src/hal_qei.c
@@ -42,10 +42,6 @@
/* Driver local functions. */
/*===========================================================================*/
-/*===========================================================================*/
-/* Driver exported functions. */
-/*===========================================================================*/
-
/**
* @brief Helper for correclty handling overflow/underflow
*
@@ -66,6 +62,7 @@
* was due to occur
*
*/
+static inline
bool qei_adjust_count(qeicnt_t *count, qeidelta_t *delta,
qeicnt_t min, qeicnt_t max, qeioverflow_t mode) {
/* For information on signed integer overflow see:
@@ -131,6 +128,10 @@ bool qei_adjust_count(qeicnt_t *count, qeidelta_t *delta,
}
}
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
/**
* @brief QEI Driver initialization.
* @note This function is implicitly invoked by @p halInit(), there is
@@ -284,13 +285,50 @@ qeidelta_t qeiAdjust(QEIDriver *qeip, qeidelta_t delta) {
osalDbgAssert((qeip->state == QEI_ACTIVE), "invalid state");
osalSysLock();
- delta = qei_lld_adjust_count(qeip, delta);
+ delta = qeiAdjustI(qeip, delta);
osalSysUnlock();
return delta;
}
/**
+ * @brief Adjust the counter by delta.
+ *
+ * @param[in] qeip pointer to the @p QEIDriver object.
+ * @param[in] delta the adjustement value.
+ * @return the remaining delta (can occur during overflow).
+ *
+ * @api
+ */
+qeidelta_t qeiAdjustI(QEIDriver *qeip, qeidelta_t delta) {
+ /* Get boundaries */
+ qeicnt_t min = QEI_COUNT_MIN;
+ qeicnt_t max = QEI_COUNT_MAX;
+ if (qeip->config->min != qeip->config->max) {
+ min = qeip->config->min;
+ max = qeip->config->max;
+ }
+
+ /* Get counter */
+ qeicnt_t count = qei_lld_get_count(qeip);
+
+ /* Adjust counter value */
+ bool overflowed = qei_adjust_count(&count, &delta,
+ min, max, qeip->config->overflow);
+
+ /* Notify for value change */
+ qei_lld_set_count(qeip, count);
+
+ /* Notify for overflow (passing the remaining delta) */
+ if (overflowed && qeip->config->overflow_cb)
+ qeip->config->overflow_cb(qeip, delta);
+
+ /* Remaining delta */
+ return delta;
+}
+
+
+/**
* @brief Returns the counter delta from last reading.
*
* @param[in] qeip pointer to the @p QEIDriver object