aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane D'Alu <sdalu@sdalu.com>2016-06-29 21:11:38 +0200
committerStephane D'Alu <sdalu@sdalu.com>2016-06-29 21:11:38 +0200
commita8b2364267be59dd2bc9d02bc6923a629bcecd72 (patch)
tree3e635348eaaccbd9199e0f39c025bb0cf6852114
parentb20bf874d044c67bf72e6a054718e75531dc434a (diff)
downloadChibiOS-Contrib-a8b2364267be59dd2bc9d02bc6923a629bcecd72.tar.gz
ChibiOS-Contrib-a8b2364267be59dd2bc9d02bc6923a629bcecd72.tar.bz2
ChibiOS-Contrib-a8b2364267be59dd2bc9d02bc6923a629bcecd72.zip
cleanup
-rw-r--r--os/hal/ports/NRF51/NRF51822/hal_qei_lld.c116
-rw-r--r--os/hal/ports/NRF51/NRF51822/hal_qei_lld.h5
2 files changed, 68 insertions, 53 deletions
diff --git a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c
index 66694dc..9b1b6bb 100644
--- a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c
+++ b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c
@@ -28,7 +28,7 @@
/*===========================================================================*/
-/* Driver local definitions. */
+/* To be moved in hal_qei */
/*===========================================================================*/
static inline
@@ -84,35 +84,6 @@ bool qei_adjust_count(qeicnt_t *count, qeidelta_t *delta,
}
}
-qeidelta_t qei_lld_adjust_count(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;
- }
-
- // Snapshot counter for later comparison
- qeicnt_t count = qeip->count;
-
- // Adjust counter value
- bool overflowed = qei_adjust_count(&qeip->count, &delta,
- min, max, qeip->config->overflow);
-
- // Notify for value change
- if ((qeip->count != count) && qeip->config->notify_cb)
- qeip->config->notify_cb(qeip);
-
- // Notify for overflow (passing the remaining delta)
- if (overflowed && qeip->config->overflow_cb)
- qeip->config->overflow_cb(qeip, delta);
-
- // Remaining delta
- return delta;
-}
-
-
/**
* @brief Adjust the counter by delta.
*
@@ -152,9 +123,30 @@ void qeiSetCount(QEIDriver *qeip, qeicnt_t value) {
}
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/**
+ * @brief QEID1 driver identifier.
+ */
+#if NRF51_QEI_USE_QDEC0 || defined(__DOXYGEN__)
+QEIDriver QEID1;
+#endif
+/*===========================================================================*/
+/* Driver local variables and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
/**
* @brief Common IRQ handler.
*
@@ -191,27 +183,6 @@ static void serve_interrupt(QEIDriver *qeip) {
}
}
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/**
- * @brief QEID1 driver identifier.
- */
-#if NRF51_QEI_USE_QDEC0 || defined(__DOXYGEN__)
-QEIDriver QEID1;
-#endif
-
-
-/*===========================================================================*/
-/* Driver local variables and types. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
@@ -265,7 +236,7 @@ void qei_lld_start(QEIDriver *qeip) {
palSetLineMode(cfg->phase_b, PAL_MODE_INPUT);
#if NRF51_QEI_USE_LED == TRUE
if (cfg->led != PAL_NOLINE) {
- palSetLineMode(cfg->led, PAL_MODE_INPUT);
+ palSetLineMode(cfg->led, PAL_MODE_INPUT);
}
#endif
@@ -344,7 +315,7 @@ void qei_lld_stop(QEIDriver *qeip) {
palSetLineMode(cfg->phase_b, PAL_MODE_RESET);
#if NRF51_QEI_USE_LED == TRUE
if (cfg->led != PAL_NOLINE) {
- palSetLineMode(cfg->led, PAL_MODE_RESET);
+ palSetLineMode(cfg->led, PAL_MODE_RESET);
}
#endif
}
@@ -378,6 +349,45 @@ void qei_lld_disable(QEIDriver *qeip) {
}
+/**
+ * @brief Adjust counter
+ *
+ * @param[in] qeip pointer to the @p QEIDriver object
+ * @param[in] delta value to use for adjustement
+ * @return remaining adjustement that were not applied
+ *
+ * @notapi
+ */
+qeidelta_t qei_lld_adjust_count(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;
+ }
+
+ // Snapshot counter for later comparison
+ qeicnt_t count = qeip->count;
+
+ // Adjust counter value
+ bool overflowed = qei_adjust_count(&qeip->count, &delta,
+ min, max, qeip->config->overflow);
+
+ // Notify for value change
+ if ((qeip->count != count) && qeip->config->notify_cb)
+ qeip->config->notify_cb(qeip);
+
+ // Notify for overflow (passing the remaining delta)
+ if (overflowed && qeip->config->overflow_cb)
+ qeip->config->overflow_cb(qeip, delta);
+
+ // Remaining delta
+ return delta;
+}
+
+
+
#endif /* HAL_USE_QEI */
/** @} */
diff --git a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h
index 813d169..ed5d9ae 100644
--- a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h
+++ b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h
@@ -354,10 +354,15 @@ extern "C" {
void qei_lld_stop(QEIDriver *qeip);
void qei_lld_enable(QEIDriver *qeip);
void qei_lld_disable(QEIDriver *qeip);
+ qeidelta_t qei_lld_adjust_count(QEIDriver *qeip, qeidelta_t delta);
#ifdef __cplusplus
}
#endif
+/*===========================================================================*/
+/* To be moved in hal_qei */
+/*===========================================================================*/
+
void qeiSetCount(QEIDriver *qeip, qeicnt_t value);
qeidelta_t qeiAdjust(QEIDriver *qeip, qeidelta_t delta);