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) {
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;

View File

@ -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.
*/