From e1e600b5ada75fe1bd77e13cb799433898cb848a Mon Sep 17 00:00:00 2001 From: Stephane D'Alu Date: Wed, 29 Jun 2016 21:27:56 +0200 Subject: conditionnaly compile accumulator overflow notification --- os/hal/ports/NRF51/NRF51822/hal_qei_lld.c | 22 ++++++++++++++++++---- os/hal/ports/NRF51/NRF51822/hal_qei_lld.h | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) (limited to 'os/hal/ports/NRF51/NRF51822') diff --git a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c index 9b1b6bb..595df89 100644 --- a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c +++ b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.c @@ -155,6 +155,7 @@ QEIDriver QEID1; static void serve_interrupt(QEIDriver *qeip) { NRF_QDEC_Type *qdec = qeip->qdec; +#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE /* Accumulator overflowed */ if (qdec->EVENTS_ACCOF) { @@ -164,7 +165,8 @@ static void serve_interrupt(QEIDriver *qeip) { if (qeip->config->overflowed_cb) qeip->config->overflowed_cb(qeip); } - +#endif + /* Report ready */ if (qdec->EVENTS_REPORTRDY) { @@ -241,8 +243,13 @@ void qei_lld_start(QEIDriver *qeip) { #endif // Set interrupt masks and enable interrupt +#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE qdec->INTENSET = QDEC_INTENSET_REPORTRDY_Msk | QDEC_INTENSET_ACCOF_Msk; +#else + qdec->INTENSET = QDEC_INTENSET_REPORTRDY_Msk; +#endif + #if NRF51_QEI_USE_QDEC0 == TRUE if (&QEID1 == qeip) { nvicEnableVector(QDEC_IRQn, NRF51_QEI_QDEC0_IRQ_PRIORITY); @@ -307,9 +314,14 @@ void qei_lld_stop(QEIDriver *qeip) { nvicDisableVector(QDEC_IRQn); } #endif - qdec->INTENCLR = QDEC_INTENSET_REPORTRDY_Msk | - QDEC_INTENSET_ACCOF_Msk; +#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE + qdec->INTENCLR = QDEC_INTENCLR_REPORTRDY_Msk | + QDEC_INTENCLR_ACCOF_Msk; +#else + qdec->INTENCLR = QDEC_INTENCLR_REPORTRDY_Msk; +#endif + // Return pins to reset state palSetLineMode(cfg->phase_a, PAL_MODE_RESET); palSetLineMode(cfg->phase_b, PAL_MODE_RESET); @@ -329,8 +341,10 @@ void qei_lld_stop(QEIDriver *qeip) { * @notapi */ void qei_lld_enable(QEIDriver *qeip) { +#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE qeip->overflowed = 0; - +#endif + qeip->qdec->EVENTS_SAMPLERDY = 0; qeip->qdec->EVENTS_REPORTRDY = 0; qeip->qdec->EVENTS_ACCOF = 0; diff --git a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h index ed5d9ae..aa3d1e8 100644 --- a/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h +++ b/os/hal/ports/NRF51/NRF51822/hal_qei_lld.h @@ -60,6 +60,16 @@ #define NRF51_QEI_USE_LED FALSE #endif +/** + * @brief Accumulator overflow notification enable switch. + * @details If set to @p TRUE the support for accumulator overflow + * is included. + * @note The default is @p FALSE. + */ +#if !defined(NRF51_QEI_USE_ACC_OVERFLOW_CB) || defined(__DOXYGEN__) +#define NRF51_QEI_USE_ACC_OVERFLOW_CB FALSE +#endif + /** * @brief QEID1 driver enable switch. * @details If set to @p TRUE the support for QEID1 is included. @@ -263,6 +273,7 @@ typedef struct { * @details Default to QEI_REPORT_10 */ qeireport_t report; +#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE /** * @brief Notify of internal accumulator overflowed * @@ -270,6 +281,7 @@ typedef struct { * @note Called from ISR context. */ qeicallback_t overflowed_cb; +#endif } QEIConfig; /** @@ -296,11 +308,13 @@ struct QEIDriver { * @brief Counter */ qeicnt_t count; +#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE /** * @brief Number of time the MCU discarded updates due to * accumulator overflow */ uint32_t overflowed; +#endif /** * @brief Pointer to the QDECx registers block. */ -- cgit v1.2.3