conditionnaly compile accumulator overflow notification

This commit is contained in:
Stephane D'Alu 2016-06-29 21:27:56 +02:00
parent a8b2364267
commit e1e600b5ad
2 changed files with 32 additions and 4 deletions

View File

@ -155,6 +155,7 @@ QEIDriver QEID1;
static void serve_interrupt(QEIDriver *qeip) { static void serve_interrupt(QEIDriver *qeip) {
NRF_QDEC_Type *qdec = qeip->qdec; NRF_QDEC_Type *qdec = qeip->qdec;
#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE
/* Accumulator overflowed /* Accumulator overflowed
*/ */
if (qdec->EVENTS_ACCOF) { if (qdec->EVENTS_ACCOF) {
@ -164,6 +165,7 @@ static void serve_interrupt(QEIDriver *qeip) {
if (qeip->config->overflowed_cb) if (qeip->config->overflowed_cb)
qeip->config->overflowed_cb(qeip); qeip->config->overflowed_cb(qeip);
} }
#endif
/* Report ready /* Report ready
*/ */
@ -241,8 +243,13 @@ void qei_lld_start(QEIDriver *qeip) {
#endif #endif
// Set interrupt masks and enable interrupt // Set interrupt masks and enable interrupt
#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE
qdec->INTENSET = QDEC_INTENSET_REPORTRDY_Msk | qdec->INTENSET = QDEC_INTENSET_REPORTRDY_Msk |
QDEC_INTENSET_ACCOF_Msk; QDEC_INTENSET_ACCOF_Msk;
#else
qdec->INTENSET = QDEC_INTENSET_REPORTRDY_Msk;
#endif
#if NRF51_QEI_USE_QDEC0 == TRUE #if NRF51_QEI_USE_QDEC0 == TRUE
if (&QEID1 == qeip) { if (&QEID1 == qeip) {
nvicEnableVector(QDEC_IRQn, NRF51_QEI_QDEC0_IRQ_PRIORITY); nvicEnableVector(QDEC_IRQn, NRF51_QEI_QDEC0_IRQ_PRIORITY);
@ -307,8 +314,13 @@ void qei_lld_stop(QEIDriver *qeip) {
nvicDisableVector(QDEC_IRQn); nvicDisableVector(QDEC_IRQn);
} }
#endif #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 // Return pins to reset state
palSetLineMode(cfg->phase_a, PAL_MODE_RESET); palSetLineMode(cfg->phase_a, PAL_MODE_RESET);
@ -329,7 +341,9 @@ void qei_lld_stop(QEIDriver *qeip) {
* @notapi * @notapi
*/ */
void qei_lld_enable(QEIDriver *qeip) { void qei_lld_enable(QEIDriver *qeip) {
#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE
qeip->overflowed = 0; qeip->overflowed = 0;
#endif
qeip->qdec->EVENTS_SAMPLERDY = 0; qeip->qdec->EVENTS_SAMPLERDY = 0;
qeip->qdec->EVENTS_REPORTRDY = 0; qeip->qdec->EVENTS_REPORTRDY = 0;

View File

@ -60,6 +60,16 @@
#define NRF51_QEI_USE_LED FALSE #define NRF51_QEI_USE_LED FALSE
#endif #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. * @brief QEID1 driver enable switch.
* @details If set to @p TRUE the support for QEID1 is included. * @details If set to @p TRUE the support for QEID1 is included.
@ -263,6 +273,7 @@ typedef struct {
* @details Default to QEI_REPORT_10 * @details Default to QEI_REPORT_10
*/ */
qeireport_t report; qeireport_t report;
#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE
/** /**
* @brief Notify of internal accumulator overflowed * @brief Notify of internal accumulator overflowed
* *
@ -270,6 +281,7 @@ typedef struct {
* @note Called from ISR context. * @note Called from ISR context.
*/ */
qeicallback_t overflowed_cb; qeicallback_t overflowed_cb;
#endif
} QEIConfig; } QEIConfig;
/** /**
@ -296,11 +308,13 @@ struct QEIDriver {
* @brief Counter * @brief Counter
*/ */
qeicnt_t count; qeicnt_t count;
#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE
/** /**
* @brief Number of time the MCU discarded updates due to * @brief Number of time the MCU discarded updates due to
* accumulator overflow * accumulator overflow
*/ */
uint32_t overflowed; uint32_t overflowed;
#endif
/** /**
* @brief Pointer to the QDECx registers block. * @brief Pointer to the QDECx registers block.
*/ */