aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal
diff options
context:
space:
mode:
authorStephane D'Alu <sdalu@sdalu.com>2016-06-28 22:31:24 +0200
committerStephane D'Alu <sdalu@sdalu.com>2016-06-28 22:31:24 +0200
commit7cb533cd20720b48c882261922cb12b572bcbf9b (patch)
treebfe14893095f608230283b118fee784498f66c9c /os/hal
parent3cdd1360d4e71edabad003f7652a0abc0b1aaad1 (diff)
downloadChibiOS-Contrib-7cb533cd20720b48c882261922cb12b572bcbf9b.tar.gz
ChibiOS-Contrib-7cb533cd20720b48c882261922cb12b572bcbf9b.tar.bz2
ChibiOS-Contrib-7cb533cd20720b48c882261922cb12b572bcbf9b.zip
cleanup
Diffstat (limited to 'os/hal')
-rw-r--r--os/hal/ports/NRF51/NRF51822/hal_qei_lld.c92
-rw-r--r--os/hal/ports/NRF51/NRF51822/hal_qei_lld.h32
2 files changed, 61 insertions, 63 deletions
diff --git a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c
index 0f8043d..7d78f1d 100644
--- a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c
+++ b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2016 Martino Migliavacca
+ ChibiOS - Copyright (C) 2016..2016 Stéphane D'Alu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -15,8 +15,8 @@
*/
/**
- * @file TIMv1/hal_qei_lld.c
- * @brief STM32 QEI subsystem low level driver header.
+ * @file NRF51/hal_qei_lld.c
+ * @brief NRF51 QEI subsystem low level driver header.
*
* @addtogroup QEI
* @{
@@ -31,46 +31,14 @@
/* Driver local definitions. */
/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver exported variables. */
-/*===========================================================================*/
-
-/**
- * @brief QEID1 driver identifier.
- */
-#if NRF51_QEI_USE_QDEC1 || defined(__DOXYGEN__)
-QEIDriver QEID1;
-#endif
-
-
-/*===========================================================================*/
-/* Driver local variables and types. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver local functions. */
-/*===========================================================================*/
-
-/*===========================================================================*/
-/* Driver interrupt handlers. */
-/*===========================================================================*/
-
-#if NRF51_QEI_USE_QDEC1 == TRUE
/**
- * @brief Quadrature decoder vector (QDEC)
+ * @brief Common IRQ handler.
*
- * @isr
+ * @param[in] qeip pointer to an QEIDriver
*/
-OSAL_IRQ_HANDLER(Vector88) {
- QEIDriver *qeip = &QEID1;
+static void serve_interrupt(QEIDriver *qeip) {
NRF_QDEC_Type *qdec = qeip->qdec;
- OSAL_IRQ_PROLOGUE();
-
-
- osalSysLockFromISR();
-
if (qdec->EVENTS_ACCOF) {
qdec->EVENTS_ACCOF = 0;
qeip->overflowed++;
@@ -152,10 +120,43 @@ OSAL_IRQ_HANDLER(Vector88) {
if (overflowed && qeip->config->overflow_cb)
qeip->config->overflow_cb(qeip, delta);
}
+}
-
- osalSysUnlockFromISR();
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/**
+ * @brief QEID1 driver identifier.
+ */
+#if NRF51_QEI_USE_QDEC1 || defined(__DOXYGEN__)
+QEIDriver QEID1;
+#endif
+
+
+/*===========================================================================*/
+/* Driver local variables and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+#if NRF51_QEI_USE_QDEC1 == TRUE
+/**
+ * @brief Quadrature decoder vector (QDEC)
+ *
+ * @isr
+ */
+OSAL_IRQ_HANDLER(Vector88) {
+
+ OSAL_IRQ_PROLOGUE();
+ serve_interrupt(&QEID1);
OSAL_IRQ_EPILOGUE();
}
#endif
@@ -263,6 +264,13 @@ void qei_lld_stop(QEIDriver *qeip) {
#endif
qdec->INTENCLR = QDEC_INTENSET_REPORTRDY_Msk |
QDEC_INTENSET_ACCOF_Msk;
+
+ // Return pins to reset state
+ palSetLineMode(cfg->phase_a, PAL_MODE_RESET);
+ palSetLineMode(cfg->phase_b, PAL_MODE_RESET);
+ if (cfg->led != PAL_NOLINE) {
+ palSetLineMode(cfg->led, PAL_MODE_RESET);
+ }
}
}
@@ -294,10 +302,6 @@ void qei_lld_disable(QEIDriver *qeip) {
}
-
-
-
-
#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 f07a60a..40c751c 100644
--- a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h
+++ b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2016 Martino Migliavacca
+ ChibiOS - Copyright (C) 2016..2016 Stéphane D'Alu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -15,8 +15,8 @@
*/
/**
- * @file TIMv1/hal_qei_lld.h
- * @brief STM32 QEI subsystem low level driver header.
+ * @file NRF51/hal_qei_lld.h
+ * @brief NRF51 QEI subsystem low level driver header.
*
* @addtogroup QEI
* @{
@@ -28,7 +28,6 @@
#if (HAL_USE_QEI == TRUE) || defined(__DOXYGEN__)
-
/*===========================================================================*/
/* Driver constants. */
/*===========================================================================*/
@@ -40,8 +39,6 @@
#define QEI_COUNT_MAX 65535
-
-
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
@@ -104,7 +101,7 @@ typedef enum {
} qeiresolution_t;
/**
- *
+ * @brief Clusters of samples.
*/
typedef enum {
QEI_REPORT_10 = 0x00UL, /**< 10 samples per report. */
@@ -117,9 +114,8 @@ typedef enum {
QEI_REPORT_280 = 0x07UL, /**< 280 samples per report. */
} qeireport_t;
-
/**
- * @brief Handling of counter overflow/underflow
+ * @brief Handling of counter overflow/underflow.
*/
typedef enum {
QEI_OVERFLOW_WRAP = 0, /**< Counter value will wrap around. */
@@ -167,11 +163,8 @@ typedef struct {
/**
* @brief Handling of counter overflow/underflow
*
- * @details When overflow callback is called, the counter value
- * is not updated, the decision on how to update is left
- * to the callback.
- *
- * Three implementation are provided
+ * @details When overflow accours, the counter value is updated
+ * according to:
* - QEI_OVERFLOW_DISCARD:
* discard the update value, counter doesn't change
* - QEI_OVERFLOW_MINMAX
@@ -183,17 +176,19 @@ typedef struct {
/**
* @brief Min count value.
*
- * @note If min == max, the QEI_COUNT_MIN is used as default
+ * @note If min == max, then QEI_COUNT_MIN is used.
*/
qeicnt_t min;
/**
* @brief Max count value.
*
- * @note If min == max, the QEI_COUNT_MAX is used as default
+ * @note If min == max, then QEI_COUNT_MAX is used.
*/
qeicnt_t max;
/**
* @brief Notify of value change
+ *
+ * @note Called from ISR context.
*/
qeicallback_t notify_cb;
/**
@@ -201,6 +196,7 @@ typedef struct {
*
* @note Overflow notification is performed after
* value changed notification.
+ * @note Called from ISR context.
*/
void (*overflow_cb)(QEIDriver *qeip, qeidelta_t delta);
/* End of the mandatory fields.*/
@@ -251,6 +247,7 @@ typedef struct {
* @brief Notify of internal accumulator overflowed
*
* @note MCU has discarded some of the samples.
+ * @note Called from ISR context.
*/
qeicallback_t overflowed_cb;
} QEIConfig;
@@ -277,9 +274,6 @@ struct QEIDriver {
/* End of the mandatory fields.*/
/**
*/
- qeidelta_t delta;
- /**
- */
qeicnt_t count;
/**
* @brief Number of time the MCU discarded updates due to