conditionally add support for overflow variant
This commit is contained in:
parent
01874bedf4
commit
af18f7d43f
|
@ -47,14 +47,18 @@ bool qei_adjust_count(qeicnt_t *count, qeidelta_t *delta,
|
|||
*delta = 0;
|
||||
*count = (min + (_count - (max - _delta))) - 1;
|
||||
break;
|
||||
#if HAL_QEI_SUPPORT_OVERFLOW_DISCARD == TRUE
|
||||
case QEI_OVERFLOW_DISCARD:
|
||||
*delta = _delta;
|
||||
*count = _count;
|
||||
break;
|
||||
#endif
|
||||
#if HAL_QEI_SUPPORT_OVERFLOW_MINMAX == TRUE
|
||||
case QEI_OVERFLOW_MINMAX:
|
||||
*delta = _count - (max - _delta);
|
||||
*count = max;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
|
||||
|
@ -65,14 +69,18 @@ bool qei_adjust_count(qeicnt_t *count, qeidelta_t *delta,
|
|||
*delta = 0;
|
||||
*count = (max + (_count - (min - _delta))) + 1;
|
||||
break;
|
||||
#if HAL_QEI_SUPPORT_OVERFLOW_DISCARD == TRUE
|
||||
case QEI_OVERFLOW_DISCARD:
|
||||
*delta = _delta;
|
||||
*count = _count;
|
||||
break;
|
||||
#endif
|
||||
#if HAL_QEI_SUPPORT_OVERFLOW_MINMAX == TRUE
|
||||
case QEI_OVERFLOW_MINMAX:
|
||||
*delta = _count - (min - _delta);
|
||||
*count = min;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
|
||||
|
@ -249,7 +257,6 @@ void qei_lld_start(QEIDriver *qeip) {
|
|||
#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);
|
||||
|
@ -309,12 +316,13 @@ void qei_lld_stop(QEIDriver *qeip) {
|
|||
if (qeip->state == QEI_READY) {
|
||||
qdec->TASKS_STOP = 1;
|
||||
qdec->ENABLE = 0;
|
||||
|
||||
// Unset interrupt masks and disable interrupt
|
||||
#if NRF51_QEI_USE_QDEC0 == TRUE
|
||||
if (&QEID1 == qeip) {
|
||||
nvicDisableVector(QDEC_IRQn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NRF51_QEI_USE_ACC_OVERFLOW_CB == TRUE
|
||||
qdec->INTENCLR = QDEC_INTENCLR_REPORTRDY_Msk |
|
||||
QDEC_INTENCLR_ACCOF_Msk;
|
||||
|
@ -362,7 +370,6 @@ void qei_lld_disable(QEIDriver *qeip) {
|
|||
qeip->qdec->TASKS_STOP = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adjust counter
|
||||
*
|
||||
|
@ -399,8 +406,6 @@ qeidelta_t qei_lld_adjust_count(QEIDriver *qeip, qeidelta_t delta) {
|
|||
// Remaining delta
|
||||
return delta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* HAL_USE_QEI */
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
#define QEI_COUNT_MIN (-2147483648)
|
||||
#define QEI_COUNT_MAX (2147483647)
|
||||
|
||||
#define HAL_QEI_SUPPORT_OVERFLOW_MINMAX TRUE
|
||||
#define HAM_QEI_SUPPORT_OVERFLOW_DISCARD TRUE
|
||||
|
||||
|
||||
/*===========================================================================*/
|
||||
/* Driver pre-compile time settings. */
|
||||
|
@ -105,8 +108,6 @@
|
|||
/* Driver data structures and types. */
|
||||
/*===========================================================================*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief QEI count mode.
|
||||
*/
|
||||
|
@ -118,41 +119,45 @@ typedef enum {
|
|||
* @brief QEI resolution.
|
||||
*/
|
||||
typedef enum {
|
||||
QEI_RESOLUTION_128us = 0x00UL, /**< 128us sample period. */
|
||||
QEI_RESOLUTION_256us = 0x01UL, /**< 256us sample period. */
|
||||
QEI_RESOLUTION_512us = 0x02UL, /**< 512us sample period. */
|
||||
QEI_RESOLUTION_1024us = 0x03UL, /**< 1024us sample period. */
|
||||
QEI_RESOLUTION_2048us = 0x04UL, /**< 2048us sample period. */
|
||||
QEI_RESOLUTION_4096us = 0x05UL, /**< 4096us sample period. */
|
||||
QEI_RESOLUTION_8192us = 0x06UL, /**< 8192us sample period. */
|
||||
QEI_RESOLUTION_16384us = 0x07UL, /**< 16384us sample period. */
|
||||
QEI_RESOLUTION_128us = 0x00UL, /**< 128us sample period. */
|
||||
QEI_RESOLUTION_256us = 0x01UL, /**< 256us sample period. */
|
||||
QEI_RESOLUTION_512us = 0x02UL, /**< 512us sample period. */
|
||||
QEI_RESOLUTION_1024us = 0x03UL, /**< 1024us sample period. */
|
||||
QEI_RESOLUTION_2048us = 0x04UL, /**< 2048us sample period. */
|
||||
QEI_RESOLUTION_4096us = 0x05UL, /**< 4096us sample period. */
|
||||
QEI_RESOLUTION_8192us = 0x06UL, /**< 8192us sample period. */
|
||||
QEI_RESOLUTION_16384us = 0x07UL, /**< 16384us sample period. */
|
||||
} qeiresolution_t;
|
||||
|
||||
/**
|
||||
* @brief Clusters of samples.
|
||||
*/
|
||||
typedef enum {
|
||||
QEI_REPORT_10 = 0x00UL, /**< 10 samples per report. */
|
||||
QEI_REPORT_40 = 0x01UL, /**< 40 samples per report. */
|
||||
QEI_REPORT_80 = 0x02UL, /**< 80 samples per report. */
|
||||
QEI_REPORT_120 = 0x03UL, /**< 120 samples per report. */
|
||||
QEI_REPORT_160 = 0x04UL, /**< 160 samples per report. */
|
||||
QEI_REPORT_200 = 0x05UL, /**< 200 samples per report. */
|
||||
QEI_REPORT_240 = 0x06UL, /**< 240 samples per report. */
|
||||
QEI_REPORT_280 = 0x07UL, /**< 280 samples per report. */
|
||||
QEI_REPORT_10 = 0x00UL, /**< 10 samples per report. */
|
||||
QEI_REPORT_40 = 0x01UL, /**< 40 samples per report. */
|
||||
QEI_REPORT_80 = 0x02UL, /**< 80 samples per report. */
|
||||
QEI_REPORT_120 = 0x03UL, /**< 120 samples per report. */
|
||||
QEI_REPORT_160 = 0x04UL, /**< 160 samples per report. */
|
||||
QEI_REPORT_200 = 0x05UL, /**< 200 samples per report. */
|
||||
QEI_REPORT_240 = 0x06UL, /**< 240 samples per report. */
|
||||
QEI_REPORT_280 = 0x07UL, /**< 280 samples per report. */
|
||||
} qeireport_t;
|
||||
|
||||
|
||||
// XXX: to be moved in hal_qei
|
||||
/**
|
||||
* @brief Handling of counter overflow/underflow.
|
||||
*/
|
||||
typedef enum {
|
||||
QEI_OVERFLOW_WRAP = 0, /**< Counter value will wrap around. */
|
||||
QEI_OVERFLOW_DISCARD = 1, /**< Counter doesn't change. */
|
||||
QEI_OVERFLOW_MINMAX = 2, /**< Counter will be updated to min or max. */
|
||||
QEI_OVERFLOW_WRAP = 0, /**< Counter value will wrap around. */
|
||||
#if HAL_QEI_SUPPORT_OVERFLOW_DISCARD == TRUE
|
||||
QEI_OVERFLOW_DISCARD = 1, /**< Counter doesn't change. */
|
||||
#endif
|
||||
#if HAL_QEI_SUPPORT_OVERFLOW_MINMAX == TRUE
|
||||
QEI_OVERFLOW_MINMAX = 2, /**< Counter will be updated to min or max. */
|
||||
#endif
|
||||
} qeioverflow_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief QEI direction inversion.
|
||||
*/
|
||||
|
@ -191,7 +196,7 @@ typedef struct {
|
|||
/**
|
||||
* @brief Handling of counter overflow/underflow
|
||||
*
|
||||
* @details When overflow accours, the counter value is updated
|
||||
* @details When overflow occurs, the counter value is updated
|
||||
* according to:
|
||||
* - QEI_OVERFLOW_DISCARD:
|
||||
* discard the update value, counter doesn't change
|
||||
|
|
Loading…
Reference in New Issue